cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 6 MCU

JeHu_3414236
Contributor II

How do I combine the bootloader and application so I can program both at once on a blank device using PSoC Programmer?  I don't want to use a separate host program to load the application during production.

0 Likes
1 Solution
ShipingW_81
Moderator
Moderator

It's illegal to set different sizes for flash_app1_core1 for app0 and app1 in dfu_cm4.ld.

The metadata line of combined hex file is identical with the one of app0/bootloader. In Cy_DFU_ValidateApp(), app0 always calculates the checksum of app1 using the start address and app length defined in the metadata line, and compares the computed checksum with the value lying in address (app1 start address + app1 length).

Normally, the app1 data is followed by app1 data checksum in a new flash row. If the flash_app1_core1 length set in app0 and app1 are different, the value lying in address (app1 start address + app1 length) actually has nothing to do with the app1 data checksum. Then it fails to validate the app1 and not be able to switch the execution to it.

View solution in original post

0 Likes
15 Replies
ShipingW_81
Moderator
Moderator

In, PSoC Creator 4.2, you need to add post_build_core1.bat and line post_build_core1.bat creator ${OutputDir} ${ProjectShortName} to user commands under project Build Settings in app0, to copy the resulting ELF file into the project’s root folder for merging with app1.

Then add below code snippet to the ending of file app1->post_building_core1.bat. This command line enables merging the ELF file copied from app0 into hex file generated for app1.

@rem Merges App0 and App1 into a single hex file for easier programming

%CY_MCU_ELF_TOOL% -M %OUTPUT_DIR%\%PRJ_NAME%%ELF_EXT% ..\App0%ELF_EXT% --

output %OUTPUT_DIR%\%PRJ_NAME%_merged%ELF_EXT% --hex %OUTPUT_DIR%\%PRJ_NAME%.hex

You can refer to ce220960 for details of merging the bootloader and application files.

0 Likes
JeHu_3414236
Contributor II

How do I do this for the secure encrypted example CE222802?  I merged the signed files App0_RSA.elf and App1_RSA.elf and when I load it only the bootloader runs.

0 Likes
JeHu_3414236
Contributor II

The bootloader should automatically run app1 if it is valid but it is not running it.

0 Likes
ShipingW_81
Moderator
Moderator

I just tried this method on CE216767. app1 runs correctly after downloading whole merged hex file.

Have you ever tried the original CE222802? The app1 runs finely after bootloading?

0 Likes
JeHu_3414236
Contributor II

app1 only runs if I program it using the host tool.  I don't see how merging app0 and app1 can work.  After app1 is uploaded using the host tool, app0 calls Cy_Bootload_SetAppMetadata() to set correct checksum and app1 info.  This metadata is not generated by just building the hex file.  Does Cypress have a tool that generates correct metadata when merging signed apps?

0 Likes
ShipingW_81
Moderator
Moderator

How about trying to set Macro CY_BOOTLOAD_METADATA_WRITABLE as 0? Just skip the step setting the metadata info.

0 Likes
JeHu_3414236
Contributor II

I need to change the app1 image length in metadata.  I don't want to use the same length set in app0.  I set the metadata in app0 to use the largest size app1 can be, which is almost the entire flash in case I need it someday.  For now app1 is very small.  If I set the same app1 length in app0 metadata then the merge works.

0 Likes
JaSi_1632926
New Contributor II

I have the same issue - I want to flash a combined hex file in production. Is there a tool to generate a merged hex file including the required metadata?

Thanks, Jacob

0 Likes
ShipingW_81
Moderator
Moderator

MarkA_91

Any input on the combined hex file and the required metadata?

0 Likes
JaSi_1632926
New Contributor II

I got it working by using a bat script similar to the one above, together with example CE213903 ( https://www.cypress.com/documentation/code-examples/ce213903-psoc-6-mcu-basic-device-firmware-upd...

0 Likes
JeHu_3414236
Contributor II

Does the merge still work if you use different sizes for flash_app1_core1 for app0 and app1 in dfu_cm4.ld?

0 Likes
JaSi_1632926
New Contributor II

This is my common .ld file:

    flash_app0_core0  (rx)  : ORIGIN = 0x10000000, LENGTH = 0x5000

    flash_app0_core1  (rx)  : ORIGIN = 0x10005000, LENGTH = 0x5000

    flash_app1_core0  (rx)  : ORIGIN = 0x10010000, LENGTH = 0x20000

    flash_app1_core1  (rx)  : ORIGIN = 0x10030000, LENGTH = 0x90000

0 Likes
ShipingW_81
Moderator
Moderator

It's illegal to set different sizes for flash_app1_core1 for app0 and app1 in dfu_cm4.ld.

The metadata line of combined hex file is identical with the one of app0/bootloader. In Cy_DFU_ValidateApp(), app0 always calculates the checksum of app1 using the start address and app length defined in the metadata line, and compares the computed checksum with the value lying in address (app1 start address + app1 length).

Normally, the app1 data is followed by app1 data checksum in a new flash row. If the flash_app1_core1 length set in app0 and app1 are different, the value lying in address (app1 start address + app1 length) actually has nothing to do with the app1 data checksum. Then it fails to validate the app1 and not be able to switch the execution to it.

View solution in original post

0 Likes
JaSi_1632926
New Contributor II

My recommendation is to create a common .ld file that is included from the app specific .ld files ("INCLUDE common.ld"), to avoid duplicating data and reduce risk.

0 Likes
JeHu_3414236
Contributor II

It is quickest for me right now just to build both app0 and app1 every time I update app1 size for merging.  I have CY_BOOTLOAD_METADATA_WRITABLE enabled so the value built into app0 doesn't mean anything except for merging.  The reason I don't have a fixed size for app1 is because the cyacd2 image size is based on cy_app1_verify_length and not on the length of the actual code size.  My app is 100KB but if cy_app1_verify_length is 900KB, it will generate a 900KB image to update.  I adjust cy_app1_verify_length to the exact size of the code every time to reduce the update image size.

0 Likes
Top labels