Bootloader does not appear to be honoring checksum exclude section

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaMa_1439756
Level 1
Level 1

Bootloader does not appear to be honoring checksum exclude section

 

In the PSoC Creator workspace I have two projects. 1. The bootloader 2. The Application. The bootloader has the ‘Bootloader’ component on the schematic and the Application has the Bootloadable component. The Bootloadable component declares a Checksum exclude section size of 2048 bytes. This 2048 is intended to cover the 512 bytes of EEPROM data and the 64 bytes of Bootloadable Meta Data. EEPROM Component has 512 bytes reserved but seems to want 1024 bytes. So, I played safe and reserved more than required. I have a custom linker script that locates the EEPROM starting at address 0x3F800 (i.e. 2048 bytes from the top of flash).

The Bootloader is implemented over UART.

To facilitate debugging and to simplify the problem. I have initialized the EEPROM contents to zeros. The  EEPROM calls have been replaced e.g. EEPROM_Write replaced by MyEEPROM_Write. MyEEPROM_Write does nothing i.e. it’s empty. The MyEEPROM_Read calls have been modified to return sensible default values rather than values from the EEPROM.

When I compile the code and download it to the device, I read it back using the Cypress Programmer tool. If I read and analyze the hex file uploaded from the device, I see that the exclude size is correctly stored in the meta data. I also see that the checksum (0xDE) is stored correctly.

When I download the project firmware, the application fails to execute. If I try to use a host app to download the cyad file, then it downloads but fails on an invalid checksum. It consistently fails every time I try to download.

I added debug code to the bootloader to interrogate the checksums. The meta data checksum is as expected (0xDE). The calculated checksum is different (0xAF).

Using the hex file read from the Cypress Programmer, if I calculate the checksum from the start of the application to the very end of flash memory then I get 0xAF. i.e. this is the same value that the firmware is calculating in Bootloader_ValidateBootloadable. To eliminate coincidence, I modified the firmware to force different checksums. It seems that the calculated checksum always calculates from the start of the application to the top of flash and does not honor the exclude section. In every case, if I calculate the checksum from the start of the application to the beginning of the exclude section, my checksum matches the value stored by the Bootloader Meta Data.

I modified the Bootloader_ValidateBootloadable source code to subtract 2048 bytes from the ‘end’ and now the bootload validation passes.

The meta data contains a length value of 0x3E700 which maybe in error since the bootloadable app starts at 0x6400 and the 0x3E700 would take it past the EEPROM section to the top flash address.

Is this a bug in the library or am I missing a step? How do I fix this? Modifying the generated source code to subtract the 2040 bytes is not a good solution.

PSoC Creator 4.2

Bootloader/Bootloadable Component 1.60

EEPROM Component 2.20

Device CYBLE-214009-00

0 Likes
1 Solution
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Please verify the <ProjectName>.map file to confirm the start address and size details of the Em_EEPROM section and Checksum exclude section. Also clarify, following;

This 2048 is intended to cover the 512 bytes of EEPROM data and the 64 bytes of Bootloadable Meta Data.

Are you creating custom metadata for your bootloadable application? Checksum exclude section does not include cypress bootloadable metadata.

checksum.PNG

Follow these steps and let me know if it helps;

  1. Start with Em_EEPROM code example available in PSoC Creator. File > Code Example ; select PSoC_EmEEPROM_PSoC401
  2. Configure Em_EEPROM component to store 512 bytes as per your requirement
  3. Add bootloadable component in schematic, provide dependency to appropriate bootloader.hex file and configure checksum exclude size of 2048 bytes.
  4. Force Em_EEPROM data storage to .cy_checksum_exclude memory section. Modify main.c line #70-76 as appended.
  5. Program the bootloadable.hex file and you can observe that bootloadable gets validated successfully on subsequent resets.

const uint8_t Em_EEPROM_em_EepromStorage[Em_EEPROM_PHYSICAL_SIZE]

CY_SECTION(".cy_checksum_exclude") __ALIGNED(CY_FLASH_SIZEOF_ROW) = {0u};

If you check map file, you can observe that Em_EEPROM content is stored in checksum exclude section.

.cy_checksum_exclude

                0x0003f700      0x400

*(.cy_checksum_exclude)

.cy_checksum_exclude

                0x0003f700      0x400 .\CortexM0\ARM_GCC_541\Debug\main.o

                0x0003f700                Em_EEPROM_em_EepromStorage

                0x00000400                cy_checksum_exclude_size = (CY_APPL_LOADABLE == 0x1)?SIZEOF (.cy_checksum_exclude):0x0

                0x00000001                ASSERT ((cy_checksum_exclude_size <= CY_CHECKSUM_EXCLUDE_SIZE), CY_BOOT: Section .cy_checksum_exclude size exceedes specified limit.)

                0xf0000000                cyloadermeta_start = (cy_project_type_bootloader || cy_project_type_app_for_stack_and_copier)?(LENGTH (rom) - CY_METADATA_SIZE):0xf0000000

Note that metadata section is not part of checksum exclude region. Checksum exclude region starts at;

0x40000 (top of 256kB flash) - 0x100 (one flash row for metadata) - 0x800 (size of checksum exclude section) = 0x‭3F700‬

View solution in original post

0 Likes
2 Replies
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Please verify the <ProjectName>.map file to confirm the start address and size details of the Em_EEPROM section and Checksum exclude section. Also clarify, following;

This 2048 is intended to cover the 512 bytes of EEPROM data and the 64 bytes of Bootloadable Meta Data.

Are you creating custom metadata for your bootloadable application? Checksum exclude section does not include cypress bootloadable metadata.

checksum.PNG

Follow these steps and let me know if it helps;

  1. Start with Em_EEPROM code example available in PSoC Creator. File > Code Example ; select PSoC_EmEEPROM_PSoC401
  2. Configure Em_EEPROM component to store 512 bytes as per your requirement
  3. Add bootloadable component in schematic, provide dependency to appropriate bootloader.hex file and configure checksum exclude size of 2048 bytes.
  4. Force Em_EEPROM data storage to .cy_checksum_exclude memory section. Modify main.c line #70-76 as appended.
  5. Program the bootloadable.hex file and you can observe that bootloadable gets validated successfully on subsequent resets.

const uint8_t Em_EEPROM_em_EepromStorage[Em_EEPROM_PHYSICAL_SIZE]

CY_SECTION(".cy_checksum_exclude") __ALIGNED(CY_FLASH_SIZEOF_ROW) = {0u};

If you check map file, you can observe that Em_EEPROM content is stored in checksum exclude section.

.cy_checksum_exclude

                0x0003f700      0x400

*(.cy_checksum_exclude)

.cy_checksum_exclude

                0x0003f700      0x400 .\CortexM0\ARM_GCC_541\Debug\main.o

                0x0003f700                Em_EEPROM_em_EepromStorage

                0x00000400                cy_checksum_exclude_size = (CY_APPL_LOADABLE == 0x1)?SIZEOF (.cy_checksum_exclude):0x0

                0x00000001                ASSERT ((cy_checksum_exclude_size <= CY_CHECKSUM_EXCLUDE_SIZE), CY_BOOT: Section .cy_checksum_exclude size exceedes specified limit.)

                0xf0000000                cyloadermeta_start = (cy_project_type_bootloader || cy_project_type_app_for_stack_and_copier)?(LENGTH (rom) - CY_METADATA_SIZE):0xf0000000

Note that metadata section is not part of checksum exclude region. Checksum exclude region starts at;

0x40000 (top of 256kB flash) - 0x100 (one flash row for metadata) - 0x800 (size of checksum exclude section) = 0x‭3F700‬

0 Likes

Thank you. I had been trying to locate the EEPROM data at a fixed location using a custom linker script. When I changed the CY_SECTION to CY_SECTION(".cy_checksum_exclude") instead of my custom one, then it performs as expected. Issue is now resolved and checksums are validating.

0 Likes