DFU sample, missing boot_set_pending or boot_request_upgrade

Hi, I want to update an existing image in slot 1 with a new image in slot 2.

Both are flashed on the device and in my image 1 I want to initiate the DFU process, as mentioned in https://interrupt.memfault.com/blog/mcuboot-overview#triggering-firmware-upgrades-from-main-application. Also found some info in https://devzone.nordicsemi.com/f/nordic-q-a/78575/upgraded-firmware-image-not-confirmed-by-mcuboot-dfu

However the call boot_set_pending and/or boot_request_upgrade are not defined.
Is there some setting that will enable updating the image by the program itself?

Parents
  • Hello,

    If the update image has already been flashed to the second 2 slot, then it should be become activated (i.e. copied from slot 2 to 1) on next reboot. Calling boot_set_pending and/or boot_request_upgrade should not be necessary.

    Are you sure the image in slot 2 is a valid update image? And do you have logging enabled in the MCUboot to see if it detects the new update in slot 2?

    I would also recommend you have a look at this guide here:  Add DFU support to your applicationas it is written specifically for the Zephyr / nRF connect SDK port of the MCUboot bootloader unlike the memfault article.

    Best regards,

    Vidar

Reply
  • Hello,

    If the update image has already been flashed to the second 2 slot, then it should be become activated (i.e. copied from slot 2 to 1) on next reboot. Calling boot_set_pending and/or boot_request_upgrade should not be necessary.

    Are you sure the image in slot 2 is a valid update image? And do you have logging enabled in the MCUboot to see if it detects the new update in slot 2?

    I would also recommend you have a look at this guide here:  Add DFU support to your applicationas it is written specifically for the Zephyr / nRF connect SDK port of the MCUboot bootloader unlike the memfault article.

    Best regards,

    Vidar

Children
  • Hi Vidar,

    Thanks for your reply.

    I am a bit lost here. I build the MCuboot and flashed it on the development kit. It shows

    *** Booting Zephyr OS build v3.0.99-ncs1 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    W: Failed reading image headers; Image=0
    E: Unable to find bootable image

    Next I flash my blinky_slot0 application. 
    After a reset it shows:
    *** Booting Zephyr OS build v3.0.99-ncs1 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0xc000
    *** Booting Zephyr OS build v3.0.99-ncs1 ***
    [00:00:00.004,241] <inf> Blinky_slot1: Led ports initialized
    [00:00:00.010,559] <inf> Blinky_slot1: Led pins configured
    [00:00:00.016,906] <inf> mcuboot_util: Swap type: none
    [00:00:00.022,735] <inf> Blinky_slot1: Next action on the next reboot = NONE

    When I understand you correctly, flashing a second variant of the Blinky application in slot 1 (address 0x00067000) should result in a swap after a reset? What about the mcumgr command image test? I tried the proces mentioned in your link before. That one worked fine.
    As we do not add the mcumgr stuff, I hoped to initiate the swapping by the  boot_request_upgrade command. 

    So when the second Blinky (blinky_slot1) was flashed a reset did not start the second variant, but again the first.
    Activating the boot_request_upgrade and reset shows:

    *** Booting Zephyr OS build v3.0.99-ncs1 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=good, swap_type=0x3, copy_done=0x3, image_ok=0x1
    I: Boot source: none
    I: Swap type: perm
    I: Bootloader chainload address offset: 0xc000
    *** Booting Zephyr OS build v3.0.99-ncs1 ***
    [00:00:00.004,241] <inf> Blinky_slot1: Led ports initialized
    [00:00:00.010,528] <inf> Blinky_slot1: Led pins configured
    [00:00:00.016,876] <inf> mcuboot_util: Swap type: none
    [00:00:00.022,705] <inf> Blinky_slot1: Next action on the next reboot = NONE

    It looks like something is gong on?
    But still the first image is running. A next rest will show the previous output.

    ( Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3).

    Do I miss something here?

  • Some update:

    I flashed the second Blinky at address 073000, not 067000

    When calling boot_request_upgrade I see

    [00:00:05.784,973] <dbg> mcuboot_util: boot_write_magic: writing magic; fa_id=5 off=0x79ff0 (0xffff0)
    [00:00:05.795,257] <dbg> mcuboot_util: boot_write_swap_info: writing swap_info; fa_id=5 off=0x79fd8 (0xfffd8), swap_type=0x2 image_num=0x0
    [00:00:05.808,746] <inf> Blinky_slot1: Button 1 pressed, boot_request_upgrade
    [00:00:05.816,711] <inf> mcuboot_util: Swap type: test
    [00:00:05.822,509] <inf> Blinky_slot1: Next action on the next reboot = TEST

  • Looks like the new image is being copied to the primary slot based on the log output. Do you see if the new application starts up?

    Note that you can flash the app_moved_test_update.hex.hex from the <build dir>/zephyr/ if you are building the app with the CONFIG_BOOTLOADER_MCUBOOT setting enabled. Then you don't have to specify the start address.

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/readme-ncs.html#using-mcuboot-in-nrf-connect-sdk

  • Hi Vidar,

    The second application is not starting. Only the first one is always running. 

    I am aware of the setting you mentioned. That is how I flash the first image. Only the second one is done by jflash. My goal is to toggle between the first and second image.

  • Hi Vidar,

    My concept if finally working! I was able to use the smp_svr and foud out what was wrong in my setup.

    I took the following steps:

    1. Build the MCUboot (mcuboot\boot\zephyr)
    2. Flash the MCUboot on the nRF52840DK with VSCode
    3. Created a blinky1, building it and flash it with VSCode
      The application will flash all leds.
      The application will call boot_request_upgrade(BOOT_UPGRADE_TEST); when button 1 is pressed
      The application will reboot when button2 is pressed.
      The application will call boot_write_img_confirmed(); when button 3 is pressed.
    4. Created a blinky2, building it and flashed it with JFlash to address 00086000!!
    5. The application will flash 2 leds.
      The application will call boot_request_upgrade(BOOT_UPGRADE_TEST); when button 1 is pressed
      The application will reboot when button2 is pressed
      The application will call boot_write_img_confirmed(); when button 3 is pressed.

     Now I am able to switch from blinky1 to blinky2 as planned.

    Still one important question. Why do I need to flash the second blinky to address 00086000 while the dts file stated:

    slot1_partition: partition@73000 {
          label = "image-1";
          reg = <0x00073000 0x00067000>;
        };

     I was expecting the address to be 0x00073000 ...

Related