MCUBoot and RA6M4

I am using the EK RA6M4 and have tested the application note R11AN0570 to use the MCUBoot with the dual flash bank. In the application note the UART is used to transfer a secondary image to the EK using the XModem protocol. I am able to update the firmware over the uart. A small tweak is that I am not using the RTOS but a single main loop.

Now we have created a custom PCB using the Renesas R7FA6M4AF3CFB and I am testing the same application note on the new PCB but this fails. I am reusing the bootloader project (ra_mcuboot_ra6m4_dualbank) and running the app_primary_uart binary. After connecting and transfering the app_secondary_uart binary, the debugger is indicating an error. The microcontroller is crashing after the system reset after swapping the images. It can not start up with the secondary image.

So why is this project running on the EK RA6M4 but not on my custom PCB with the R7FA6M4AF3CFB microcontroller?

The pimary application was running and I started a file transfer of the secondary application. This goes well until the point of the function R_FLASH_HP_BankSwap in RM_MCUBOOT_PORT_BootApp. After the call to __NVIC_SystemReset();, the debugger is jumping to break at address 0xfffffffe

These are the regions for the dual bank images.

#define PRIMARY_IMAGE_START_ADDRESS 0x00020000
#define SECONDARY_IMAGE_START_ADDRESS 0x0220000

If I look at the start address of the secondary image, I see that it is located there after the file transfer over the uart. The version number is 1.1.0 

Does anybody has an idea why the microcontroller can not boot with the secondary image?

  • Hello,

    So you are following the same process with same bootloader project and application projects on EK-RA6M4 and on your custom board and it fails only on the 2nd case ? 

  • Correct. The debugger stops on this screen. Any ideas what I can check?

  • Hello sir,

    Thanks for reaching out Renesas Engineering Community.

    First of all you are using the same MCU package and part number as EK-RA6M4 which means that the total code flash is the same and it is 1MB.

    The RA6M4 as described in the application note you shared has the feature that the code flash can be divided in 2 seperate banks of 512KB in your case.

    So initially when being in linear mode the code flash looks like this:

    And when dual bank mode is enabled for 1MB code flash size products the code flash divided like this:

    Bank 0 : 0x0000_0000 to 0x0007_FFFF which is 512KB

    Bank 1: 0x0020_0000 to 0x0027_FFFF which is also 512KB.

    In the bootloader project the dual bank mode in BSP tab properties is enabled so the bootloader will handle the internal flash in two seperate banks.

    The layout of the default project which is the project, that I see you are also using is:

    Which means that for the first bank starting from address 0x0000_0000

    0x10000 bytes have been allocated for bootloader area.

    And the primary image in bank 0 starts from 0x10000 and has size 0x70000 which has been declared and allocated in the flash layout.

    Now in the second bank where start address is 0x0020_0000:

    Again 0x10000 have been allocated for bootloader area. So the secondary image starts from:

    0x00210000 adress.

    This is shown also in figure 26 of the application note:

    Summary:

    Bank 0:

    Bootloader area: 0x0000_0000 to 0x0000_FFFF (size for boot allocated 0x10000)

    Primary application area: 0x0001_0000 to 0x0007_ffff (size is set to 0x70000)

    Bank 1: 

    Bootloader area: 0x0020_0000 to 0x0020_FFFF (size for boot 0x10000)

    Secondary application area: 0x0021_0000 to 0x0027_ffff

    So the regions you have declared in your application image do no correspond to the flash layout the bootloader has and are incorrect.

    #define PRIMARY_IMAGE_START_ADDRESS 0x00020000
    #define SECONDARY_IMAGE_START_ADDRESS 0x0220000

    Unless you have modified the flash layout in the bootloader project and you didn't mention.

    In case the flash layout is the same these macros in your application image to correspond to the layout should be:

    #define PRIMARY_IMAGE_START_ADDRESS 0x00010000
    #define PRIMARY_IMAGE_END_ADDRESS 0x0007FFFF
    #define SECONDARY_IMAGE_START_ADDRESS 0x0210000
    #define SECONDARY_IMAGE_END_ADDRESS 0x027FFFF

    Also it is very important that in your bootloader project you have a builder to run this batch script which basically offsets the bootloader 0x80000 in linear flash mode so that it will know where the bootloader area is for the secondary application image:

    The same should be done also in the primary application image:

    Best Regards,

    IK

  • I am using application note r11an0570eu0100-ra6-flash-dual-bank-mcuboot which uses different addresses as described in your reply.

    The bootloader has this flash layout

    The addresses of the images in the dual bank are:

    #define PRIMARY_IMAGE_START_ADDRESS 0x00020000
    #define PRIMARY_IMAGE_END_ADDRESS 0x0003FFFF
    #define SECONDARY_IMAGE_START_ADDRESS 0x0220000
    #define SECONDARY_IMAGE_END_ADDRESS 0x023FFFF

    The command to generate the bootloader offset file is:

    srec_cat Debug\ra_mcuboot_ra6m4_dualbank.srec -crop 0 0x80000 -offset 0x80000 -o ra_mcuboot_ra6m4_dualbank_offset.srec

    The command to generate the primary application offset file is:

    srec_cat Debug\FirmwareUpdate_primary_application.bin.signed -binary -offset 0x20000 -o FirmwareUpdate_primary_application_signed_offset.srec

    The primary application is started up by the debugger using these settings:

    The primary application is loaded using the load ancillary file:

    This is the result in the serial terminal:

    After sending the secondary_app.bin.signed, the device crashes at it can not start with the new image.

    I don't see any thing wrong so far.

    I tried the addresses you suggested but I could not startup the primary application. That's why I later tested the settings above and they were working correctly on the EK.

  • Hello sir,

    Would be possible to share all three projects for bootloader, primary application and secondary image to check and replicate exactly your issue?

    Thanks and Regards,

    IK

  • I added the source code of the projects. The source code of the primary and secondary application have been modified to use the UART0 on channel 1 (pins 709 and 708) while the demo code for the RA6M4 EK uses channel 0 (pins 101 and 100). 

    Regards

    FirmwareUpdater_sources.zip

  • Were you able to test the provided source code?

  • Hello sir,

    Apologies for coming late to you due to the big amount of requests we receive per daily basis.

    Yes I checked your projects and it looks like you do not follow the instructions of the app note:

    www.renesas.com/.../ra6-mcu-advanced-secure-bootloader-design-using-mcuboot-and-code-flash-dualbank-mode

    The debug configurations in your primary and secondary application project are not set as shown in the app note. You should set them with similar way according to the flash layout you have decided to set.

    Best Regards,

    IK

  • Thanks for the info. I managed to set the bootloader and firmware correctly on our custom device. Don't know exactly what I changed, just looked over the settings a couple of times and did not trial and error attempts. I can conclude that the documentation was complete to update the firmware over a UART for a dualbank memory.

    I did not found the application guideline in the previous reply. It is a good appendix certainly to create a single combined binary for production.