Closed microbit-sam closed 6 years ago
How about the following? It stores the address where the magic is found in the MakeCode region start address.
` /*
Function to fetch the hashes from a PXT generated build */ void MicroBitMemoryMap::findHashes() { uint8_t magic[16] = { 0x70, 0x8E, 0x3B, 0x92, 0xC6, 0x15, 0xA8, 0x41, 0xC4, 0x98, 0x66, 0xC9, 0x75, 0xEE, 0x51, 0x97 };
// Iterate through pages to find magic uint32_t add = FLASH_PROGRAM_END; uint32_t rem = add % PAGE_SIZE; if ( rem) add += PAGE_SIZE - rem; for( ; add < DEFAULT_SCRATCH_PAGE; add += PAGE_SIZE) { uint32_t magicAddress = (uint32_t )add;
// Check for 16 byte Magic
if ( memcmp( magicAddress, magic, 16)) {
// If the magic has been found use the address and the hashes that follow
memoryMapStore.memoryMap[2].startAddress = magicAddress;
memcpy( memoryMapStore.memoryMap[1].hash, magicAddress + 4, 8);
memcpy( memoryMapStore.memoryMap[2].hash, magicAddress + 6, 8);
return;
}
} }
`
Yep this looks like the right idea - thanks Martin!
I'll have a go at implementing this, maybe with the mumur hash instead? How fast could you hash the DAL when you used it? Originally chose to use the embedded hashes to avoid having to hash the flash on the device
The thing about the code above is that it provides the correct makecode region start address rather than the one calculated by rounding FLASH_PROGRAM_END.
Calculating the hash is the way we need to go. Is there a need to check the embedded one as well? The suggestion was that we check the embedded hashes before calculating one.
The above code has several problems, not least that it embeds the MakeCode magic in the DAL, which causes the old code to fail! I have created a PR with code that I have compiled and tested.
@microbit-sam @martinwork
Looks like we can safely close this issue off now?
Yep, Martin's fixed these for me :)
The address stored in the memory map don't make sense!
@finneyj I'll fix this against the dal-integration branch