Hello
I am sharing a function I have created to compute the CRC of the bootloader and firmware sections of my openmv H7 plus. For my project I need these values to be verifiable at bootup by another device to make sure that neither bootloader nor firmware are specific ones for which my product is certified. I am uncertain of the memory regions. Hope this function can be useful for someone. I need to make sure these are the memory regions which are written to when loading firmware / bootloader to the device.
def get_prog_mem_crc():
# Define memory boundaries for bootloader and firmware only
bootloader_start_address = 0x08000000 # Bootloader start
bootloader_size = 128 * 1024 # 128 KB bootloader size
firmware_start_address = 0x08040000 # Firmware start, skipping FFS
firmware_size = 1792 * 1024 # 1792 KB firmware size
block_size = 512 # Size of each block to read
crc = 0xFFFFFFFF # Initialize CRC
flash = pyb.Flash()
# Calculate the blocks for the bootloader
bootloader_block_start = (bootloader_start_address - 0x08000000) // block_size
bootloader_block_end = bootloader_block_start + (bootloader_size // block_size)
# Calculate the blocks for the firmware
firmware_block_start = (firmware_start_address - 0x08000000) // block_size
firmware_block_end = firmware_block_start + (firmware_size // block_size)
# Read and process the bootloader area
for block in range(bootloader_block_start, bootloader_block_end):
memory_data = bytearray(block_size)
flash.readblocks(block, memory_data)
crc = crc32_mod.crc_update(memory_data, crc)
# Read and process the firmware area
for block in range(firmware_block_start, firmware_block_end):
memory_data = bytearray(block_size)
flash.readblocks(block, memory_data)
crc = crc32_mod.crc_update(memory_data, crc)
print("CRC32 of bootloader and firmware: 0x{:08X}".format(crc))
return crc