Re: MCUboot - Signing image for slot 1 #mcuboot

Adam Podogrocki

Hi Brenton,

The only images you should flash are MCUboot and an image that goes to Slot#0. Any further operations should be conducted with the mcumgr tool. At least I used to do that. This tool gives you options to upload the new image (the first uploaded image should obviously be the one dedicated to slot#1), list already uploaded images, to check which slot is the current one, to boot from specified slot in test mode and finally to confirm, that the currently run image should become the active one.

This tool performs swapping of images, so this is why you should also have a scratch_partition in your layout, e.g. 
partitions {
  boot_partition {};
  slot0_partition {};
  slot1_partition {};
  scratch_partition {};
  data_partition{}; // remaining space for application data purposes, optional
When the image is confirmed, then swapping takes place and always the image from slot#0 is booted.

At the time I used that tool UART and Bluetooth protocol were available.


On Thu, 28 Oct 2021 at 08:57, Brenton Chetty <brent7984@...> wrote:
Hi Adam

Thank you for your reply. Sorry for the late response, as I have been getting sporadic results, i.e. sometimes the image upgrade works and most of the time it doesn't.

I have been using the following commands to sign and flash the image:
     rm -r build && west build -p auto -b nrf52840dk_nrf52840 samples/zephyr/hello-world/ -DCONFIG_BOOTLOADER_MCUBOOT=y -DDTC_OVERLAY_FILE="boards/nrf52840dk_nrf52840.overlay"
     west sign -t imgtool -- --key ~/zephyrproject/bootloader/mcuboot/root-rsa-2048.pem --header-size 0x200 --align 8 --version 3.0.2+1 --slot-size 0x67000 --pad && west flash --skip-rebuild -- --hex-file build/zephyr/zephyr.signed.hex

where the overlay file contains:
/ {
   chosen {
      zephyr,code-partition = &slot1_partition;

I used --pad for both slots. I've noticed that sometimes when I flash to slot 1, sometimes the primary image swap_type=0x2 (test) and sometimes it's 0x4 (revert).
I have confirmed that I am flashing my slot0 and slot1 images to the correct addresses (with padding).

I am not sure if the Version number plays a role in my error. Do you have any suggestions on the top of your mind as to why I am getting sporadic results with the firmware upgrades?

With thanks

On Tue, Oct 26, 2021 at 6:54 PM Adam Podogrocki <a.podogrocki@...> wrote:
Hi Brenton,

please try similar command: sign --key root-rsa-2048.pem --header-size 0x200 --align 8 --version <YOUR_VERSION> --slot-size <YOUR_SLOT_SIZE_IN_HEX> ZEPHYR_BIN_FILE NAME_OF_THE_SIGNED_FILE


On Mon, 25 Oct 2021 at 13:40, Brenton Chetty <brent7984@...> wrote:
1. Hi, how do I go about signing an image for slot1 usage.

I used the following command for flashing into slot0 successfully:
    west sign -t imgtool -- --key ~/zephyrproject/bootloader/mcuboot/root-rsa-2048.pem && west flash --skip-rebuild -- --hex-file build/zephyr/zephyr.signed.hex

I adjusted my nrf52840dk_nrf52840 config as follows to flash into slot1:
    chosen {
        zephyr,code-partition = &slot1_partition;

however when signing the image after this change, the offsets remain the same as it should be for slot 0
     === image configuration:
     partition offset: 49152 (0xc000)                     (slot 1 should start at 0x73000)
     partition size: 421888 (0x67000)
     rom start offset: 512 (0x200)

2. Is there any tutorials online for MCUboot usage on Zephyr?
I am attempting to get OTA firmware upgrade on my dev kit and I am not sure about the basic commands (Config Variables) to utilize mcuboot on zephyr.


Join to automatically receive all group messages.