diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index de49f38..ce8c297 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -297,6 +297,11 @@ int write_block(uint32_t block_no, uint8_t *data, bool quiet/*, WriteState *stat return -1; } + // only accept block with same family id + if ( UF2_FAMILY_ID && !((bl->flags & UF2_FLAG_FAMILYID) && (bl->familyID == UF2_FAMILY_ID)) ) { + return -1; + } + if ((bl->flags & UF2_FLAG_NOFLASH) || bl->payloadSize > 256 || (bl->targetAddr & 0xff) || bl->targetAddr < USER_FLASH_START || bl->targetAddr + bl->payloadSize > USER_FLASH_END) { #if USE_DBG_MSC diff --git a/src/usb/uf2/uf2.h b/src/usb/uf2/uf2.h index f909c24..6edbb4f 100644 --- a/src/usb/uf2/uf2.h +++ b/src/usb/uf2/uf2.h @@ -51,6 +51,7 @@ extern bool sdRunning; // If set, the block is "comment" and should not be flashed to the device #define UF2_FLAG_NOFLASH 0x00000001 +#define UF2_FLAG_FAMILYID 0x00002000 #define MAX_BLOCKS (FLASH_SIZE / 256 + 100) typedef struct { @@ -68,7 +69,7 @@ typedef struct { uint32_t payloadSize; uint32_t blockNo; uint32_t numBlocks; - uint32_t reserved; + uint32_t familyID; // raw data; uint8_t data[476]; diff --git a/src/usb/uf2/uf2cfg.h b/src/usb/uf2/uf2cfg.h index 815efe2..fe8f08e 100644 --- a/src/usb/uf2/uf2cfg.h +++ b/src/usb/uf2/uf2cfg.h @@ -13,3 +13,5 @@ #define USER_FLASH_END 0xAD000 // Fat Fs start here #define FLASH_PAGE_SIZE 4096 + +#define UF2_FAMILY_ID 0xADA52840