add uf2 actual application size

This commit is contained in:
hathach 2018-06-24 01:28:02 +07:00
parent 2303f5da07
commit cef0d2a962

View File

@ -4,7 +4,10 @@
#include <string.h> #include <string.h>
#include "tusb.h" #include "tusb.h"
#if 1 // to determine application size
#include "bootloader_settings.h"
#include "bootloader.h"
typedef struct { typedef struct {
uint8_t JumpInstruction[3]; uint8_t JumpInstruction[3];
uint8_t OEMInfo[8]; uint8_t OEMInfo[8];
@ -78,7 +81,7 @@ static const struct TextFile info[] = {
}; };
#define NUM_INFO (sizeof(info) / sizeof(info[0])) #define NUM_INFO (sizeof(info) / sizeof(info[0]))
#define UF2_SIZE (FLASH_SIZE * 2) #define UF2_SIZE (get_flash_size() * 2)
#define UF2_SECTORS (UF2_SIZE / 512) #define UF2_SECTORS (UF2_SIZE / 512)
#define UF2_FIRST_SECTOR (NUM_INFO + 1) #define UF2_FIRST_SECTOR (NUM_INFO + 1)
#define UF2_LAST_SECTOR (UF2_FIRST_SECTOR + UF2_SECTORS - 1) #define UF2_LAST_SECTOR (UF2_FIRST_SECTOR + UF2_SECTORS - 1)
@ -120,6 +123,18 @@ uint8_t flashBuf[FLASH_PAGE_SIZE] __attribute__((aligned(4)));
bool firstFlush = true; bool firstFlush = true;
bool hadWrite = false; bool hadWrite = false;
static uint32_t get_flash_size(void)
{
// return 1 block of 256 bytes
if ( !bootloader_app_is_valid(DFU_BANK_0_REGION_START) ) return 256;
const bootloader_settings_t * boot_setting;
bootloader_util_settings_get(&boot_setting);
return boot_setting->bank_0_size;
}
#if 0 #if 0
void flushFlash() { void flushFlash() {
if (flashAddr == NO_CACHE) if (flashAddr == NO_CACHE)
@ -322,5 +337,3 @@ void write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state
} }
} }
#endif #endif
#endif