From 4560d6901005d93149af47db51ef147d5c87f53a Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 20 Jun 2018 13:18:14 +0700 Subject: [PATCH] clean up --- src/uf2/ghostfat.c | 32 +++++++++++++++++++++++++++----- src/uf2/uf2.h | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/uf2/ghostfat.c b/src/uf2/ghostfat.c index 845b1ab..ff0a5c7 100644 --- a/src/uf2/ghostfat.c +++ b/src/uf2/ghostfat.c @@ -1,12 +1,8 @@ #include "uf2.h" - -#include "nrf_log.h" #include "nrf_nvmc.h" -#include "nrf_sdh.h" -#include "nrf_dfu_settings.h" - #include +#include "tusb.h" typedef struct { uint8_t JumpInstruction[3]; @@ -115,11 +111,14 @@ static const FAT_BootBlock BootBlock = { #define NO_CACHE 0xffffffff +#define NRF_LOG_DEBUG(...) + uint32_t flashAddr = NO_CACHE; uint8_t flashBuf[FLASH_PAGE_SIZE] __attribute__((aligned(4))); bool firstFlush = true; bool hadWrite = false; +#if 0 void flushFlash() { if (flashAddr == NO_CACHE) return; @@ -186,6 +185,7 @@ void uf2_timer(void *p_context) { } void uf2_timer_start(int ms); +#endif void padded_memcpy(char *dst, const char *src, int len) { for (int i = 0; i < len; ++i) { @@ -197,6 +197,7 @@ void padded_memcpy(char *dst, const char *src, int len) { } } + void read_block(uint32_t block_no, uint8_t *data) { memset(data, 0, 512); uint32_t sectionIdx = block_no; @@ -258,6 +259,27 @@ void read_block(uint32_t block_no, uint8_t *data) { } } +int32_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) +{ + (void) rhport; (void) lun; + + // since we return block size each, offset should always be zero + TU_ASSERT(offset == 0, -1); + + uint32_t count = 0; + + while ( count < bufsize ) + { + read_block(lba, buffer); + + lba++; + buffer += 512; + count += 512; + } + + return count; +} + void write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state) { UF2_Block *bl = (void *)data; diff --git a/src/uf2/uf2.h b/src/uf2/uf2.h index 81c635a..21e0fb1 100644 --- a/src/uf2/uf2.h +++ b/src/uf2/uf2.h @@ -8,7 +8,7 @@ #include "app_util.h" -#include "nrf_bootloader_info.h" +#include "dfu_types.h" #define SD_MAGIC_NUMBER 0x51b1e5db #define SD_MAGIC_OK() (*((uint32_t*)(SOFTDEVICE_INFO_STRUCT_ADDRESS+4)) == 0x51b1e5db)