EK-RA8D1 MCUboot swap with OSPI

Hello everyone,

Some context: 

The objective is to get a firmware update from MCUboot. I'd like to use the swap mechanism (with the scratch region to swap slots). As the image is bigger than 50% of the flash, I can't have the dual slot on the flash directly, so I wanted to use the OSPI for the updated firmware image.

I added the OSPI support, and I tested the OSPI with my application (to store the images/fonts etc...) and I can confirm the OSPI is running as expected.

I'll try to give as much information as I can on the process I followed to try to get MCUboot running: 

The next steps I'll describe are done from E2S FSP configuration view

1. Add MCUboot to the stack

THe following image shows the stack in the HAL/Common thread

And this one shows MCUboot stack itself: 

I followed different guides I could found and they all provided similar information about how to setup MCUboot and the properties to change.

Nothing fancy, only the minimal setup to get it work with slot 0 in the flash and slot 1 in the OSPI.

2. Change the properties

Now I need to configure MCUboot and the OSPI

Here is MCUboot common config:

The image 1 flash area is 0x10 0000 (1MB). So this value should be ok, but I already have a problem when setting this value: 


"Error: Attempting using more internal flash than exists on the MCU" -> Internal Flash is supposed to be 2MB.

"Error: The Flash Area Sizes must be multiples of the minimum erase size (0x80000)" -> 0x100000 is a multiple of 0x80000.

3. Configure OSPI

Then I had to configure the OSPI, but this doesn't provide any error message so I guess my only issue right now is the section 2.

Maybe I am missing something, but I don't understand how I am supposed to configure MCUboot to be able to get a swap setup that retrieves the image to swap in the OSPI. I don't mind it being slow by the way.

I used to worked a lot with Zephyr (NRF), so MCUboot setup is a concept I am familiar with. If there is any hint/help about this problem, it would save me a lot of time! 

Thank you very much.

GabrielC

Parents
  • Hello,

    The application image cannot be 1MB on a device which has 2MB code flash because it must also accomodate teh bootloader and scratch area. Please refer to the silde below:

  • Thanks for the answer. I saw this slide while configuring MCUboot. But I expected to be able to have the bootloader an primary slot on the flash, then the secondary slot and scratch area in the OSPI. or at least only the secondary slot on the OSPI. I understand that having everything on the Flash can't work with the firmware image size I have. 

    As the FSP allows me to configure the OSPI to target the secondary slot, I thought I could have a bigger image size to swap. Maybe did I understand something wrong ?

  • Unfortunately there is a limitation of MCUboot for using swap mode and external storage:

    If you select other upgrade method than swap, you would be able to use external storage in OSPI and also allow bigger application image size (see the slide above)

  • Oh, ok. Using another method might be acceptable, I'll try that, thanks for the answer. I'll test it as soon as possible! 

  • On Zephyr, I’ve successfully set up swap mode using SPI flash for slot 1. I was also able to configure the scratch area to reside either on the SPI flash or in internal flash, depending on the use case.

    This makes me wonder:
    Why is it possible to use OSPI with the overwrite strategy, but not with the swap strategy?
    Is there a technical reason, hardware constraint, or limitation in MCUboot's design that prevents this?

    Also, if anyone has a link to the original documentation or screenshot that explains this limitation, I’d really appreciate it. I'm very interested in understanding this at a deeper level.

    Thanks in advance!

  • Does it come from a lack of atomic writes or protected interruptions in the OSPI?

  • I tried to modify the FSP configuration. Instead of using swap mode, I'm using Overwrite only.I still have the same issue. When I configure MCUboot without any external memory, I can specify an image size of maximum 0xE0000. This seems correct as 2*0xE0000 + 0x20000 is pretty much the size of the internal flash. Here is the configuration :

    As you can see, there is no external memory implementation added. and not any error. If I set the image size to 0xF0000, error about lacking internal flash appears. That is totally expected.

    Then, when I'm adding the OSPI, no errors to report, but I expect to be able to change the image size to 0xF0000 without any errors as I'm now using the OSPI: 


    2 things are bothering me: 
    - MCU: Attempting to use more internal flash than exists on the MCU. 
    - Region FLASH overflowed by 1286868 bytes, and this is more or less the size of my application.

    I'd like to mention that I do not have a bootloader project, I'd like my application to start MCUboot when a firmware update is required. I followed this: 
    https://www.renesas.com/en/document/apn/booting-encrypted-image-ra4-using-mcuboot-and-qspi-application-project
    Section 5 (page 24). I followed it step by step.

    I can see the generated files in ra_cfg/mcu-tools/mcuboot_config and ra_cfg/mcu-tools/sysflash. I can see that it's configured correctly: 

    #if (RA_NOT_DEFINED > 0)

    #define RM_MCUBOOT_PORT_CFG_SECONDARY_USE_QSPI

    #endif

    #if (1 > 0)

    #define RM_MCUBOOT_PORT_CFG_SECONDARY_USE_OSPI_B

    #endif

    #if ((RA_NOT_DEFINED > 0) || (1 > 0))

    #define RM_MCUBOOT_PORT_CFG_SECONDARY_USE_XSPI

    #endif

    Also this is in sysflash.h

    #ifndef FLASH_AREA_2_ID

    #define FLASH_AREA_2_ID (FLASH_AREA_IMAGE_2)

    #endif

    #ifndef FLASH_AREA_2_OFFSET

    #ifdef RM_MCUBOOT_PORT_CFG_SECONDARY_USE_QSPI

    #define FLASH_AREA_2_OFFSET (BSP_FEATURE_QSPI_DEVICE_START_ADDRESS + XSPI_AREA_MCUBOOT_OFFSET)

    #elif defined(RM_MCUBOOT_PORT_CFG_SECONDARY_USE_OSPI_B)

    #if (RM_MCUBOOT_PORT_CFG_OSPI_B_CHANNEL == 1)

    #define FLASH_AREA_2_OFFSET (BSP_FEATURE_OSPI_B_DEVICE_1_START_ADDRESS + XSPI_AREA_MCUBOOT_OFFSET)

    #elif (RM_MCUBOOT_PORT_CFG_OSPI_B_CHANNEL == 0)

    #define FLASH_AREA_2_OFFSET (BSP_FEATURE_OSPI_B_DEVICE_0_START_ADDRESS + XSPI_AREA_MCUBOOT_OFFSET)

    #endif

    #else

    #define FLASH_AREA_2_OFFSET (FLASH_AREA_SCRATCH_OFFSET + FLASH_AREA_SCRATCH_SIZE)

    #endif

    #endif

    #ifndef FLASH_AREA_2_SIZE

    #define FLASH_AREA_2_SIZE (RM_MCUBOOT_PORT_CFG_S_PARTITION_SIZE)

    #endif

    I feel like everything is configured exactly the way I'd like it to be, but I might have a small problem in my configuration...

    If any idea, I'll be glad to read it! 

    Thank you for your time.

Reply
  • I tried to modify the FSP configuration. Instead of using swap mode, I'm using Overwrite only.I still have the same issue. When I configure MCUboot without any external memory, I can specify an image size of maximum 0xE0000. This seems correct as 2*0xE0000 + 0x20000 is pretty much the size of the internal flash. Here is the configuration :

    As you can see, there is no external memory implementation added. and not any error. If I set the image size to 0xF0000, error about lacking internal flash appears. That is totally expected.

    Then, when I'm adding the OSPI, no errors to report, but I expect to be able to change the image size to 0xF0000 without any errors as I'm now using the OSPI: 


    2 things are bothering me: 
    - MCU: Attempting to use more internal flash than exists on the MCU. 
    - Region FLASH overflowed by 1286868 bytes, and this is more or less the size of my application.

    I'd like to mention that I do not have a bootloader project, I'd like my application to start MCUboot when a firmware update is required. I followed this: 
    https://www.renesas.com/en/document/apn/booting-encrypted-image-ra4-using-mcuboot-and-qspi-application-project
    Section 5 (page 24). I followed it step by step.

    I can see the generated files in ra_cfg/mcu-tools/mcuboot_config and ra_cfg/mcu-tools/sysflash. I can see that it's configured correctly: 

    #if (RA_NOT_DEFINED > 0)

    #define RM_MCUBOOT_PORT_CFG_SECONDARY_USE_QSPI

    #endif

    #if (1 > 0)

    #define RM_MCUBOOT_PORT_CFG_SECONDARY_USE_OSPI_B

    #endif

    #if ((RA_NOT_DEFINED > 0) || (1 > 0))

    #define RM_MCUBOOT_PORT_CFG_SECONDARY_USE_XSPI

    #endif

    Also this is in sysflash.h

    #ifndef FLASH_AREA_2_ID

    #define FLASH_AREA_2_ID (FLASH_AREA_IMAGE_2)

    #endif

    #ifndef FLASH_AREA_2_OFFSET

    #ifdef RM_MCUBOOT_PORT_CFG_SECONDARY_USE_QSPI

    #define FLASH_AREA_2_OFFSET (BSP_FEATURE_QSPI_DEVICE_START_ADDRESS + XSPI_AREA_MCUBOOT_OFFSET)

    #elif defined(RM_MCUBOOT_PORT_CFG_SECONDARY_USE_OSPI_B)

    #if (RM_MCUBOOT_PORT_CFG_OSPI_B_CHANNEL == 1)

    #define FLASH_AREA_2_OFFSET (BSP_FEATURE_OSPI_B_DEVICE_1_START_ADDRESS + XSPI_AREA_MCUBOOT_OFFSET)

    #elif (RM_MCUBOOT_PORT_CFG_OSPI_B_CHANNEL == 0)

    #define FLASH_AREA_2_OFFSET (BSP_FEATURE_OSPI_B_DEVICE_0_START_ADDRESS + XSPI_AREA_MCUBOOT_OFFSET)

    #endif

    #else

    #define FLASH_AREA_2_OFFSET (FLASH_AREA_SCRATCH_OFFSET + FLASH_AREA_SCRATCH_SIZE)

    #endif

    #endif

    #ifndef FLASH_AREA_2_SIZE

    #define FLASH_AREA_2_SIZE (RM_MCUBOOT_PORT_CFG_S_PARTITION_SIZE)

    #endif

    I feel like everything is configured exactly the way I'd like it to be, but I might have a small problem in my configuration...

    If any idea, I'll be glad to read it! 

    Thank you for your time.

Children
No Data