From 78c9bd121b09399823b67ee7ea89003ca0d3315f Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 12 Nov 2024 17:26:33 +0000 Subject: [PATCH] Update abs_block Add RP2 ignored extension to errata E10 abs_block, to make it more identifiable --- elf2uf2/elf2uf2.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/elf2uf2/elf2uf2.cpp b/elf2uf2/elf2uf2.cpp index edc5ee5..63ce372 100644 --- a/elf2uf2/elf2uf2.cpp +++ b/elf2uf2/elf2uf2.cpp @@ -129,7 +129,7 @@ uf2_block gen_abs_block(uint32_t abs_block_loc) { uf2_block block; block.magic_start0 = UF2_MAGIC_START0; block.magic_start1 = UF2_MAGIC_START1; - block.flags = UF2_FLAG_FAMILY_ID_PRESENT; + block.flags = UF2_FLAG_FAMILY_ID_PRESENT | UF2_FLAG_EXTENSION_FLAGS_PRESENT; block.payload_size = UF2_PAGE_SIZE; block.num_blocks = 2; block.file_size = ABSOLUTE_FAMILY_ID; @@ -138,6 +138,7 @@ uf2_block gen_abs_block(uint32_t abs_block_loc) { block.block_no = 0; memset(block.data, 0, sizeof(block.data)); memset(block.data, 0xef, UF2_PAGE_SIZE); + *(uint32_t*)&(block.data[UF2_PAGE_SIZE]) = UF2_EXTENSION_RP2_IGNORE_BLOCK; return block; } @@ -145,12 +146,13 @@ bool check_abs_block(uf2_block block) { return std::all_of(block.data, block.data + UF2_PAGE_SIZE, [](uint8_t i) { return i == 0xef; }) && block.magic_start0 == UF2_MAGIC_START0 && block.magic_start1 == UF2_MAGIC_START1 && - block.flags == UF2_FLAG_FAMILY_ID_PRESENT && + (block.flags & ~UF2_FLAG_EXTENSION_FLAGS_PRESENT) == UF2_FLAG_FAMILY_ID_PRESENT && block.payload_size == UF2_PAGE_SIZE && block.num_blocks == 2 && block.file_size == ABSOLUTE_FAMILY_ID && block.magic_end == UF2_MAGIC_END && - block.block_no == 0; + block.block_no == 0 && + !(block.flags & UF2_FLAG_EXTENSION_FLAGS_PRESENT && *(uint32_t*)&(block.data[UF2_PAGE_SIZE]) != UF2_EXTENSION_RP2_IGNORE_BLOCK); } int pages2uf2(std::map>& pages, std::shared_ptr in, std::shared_ptr out, uint32_t family_id, uint32_t abs_block_loc=0) {