Hi,
I need to add to my project that uses NRF5340 a bootloader that reads new firmware from SDCard. Is there an example where I can find information? Someone has just encountered this kind of issue and can tell me some tips?
Thanks
Marco
Hi,
I need to add to my project that uses NRF5340 a bootloader that reads new firmware from SDCard. Is there an example where I can find information? Someone has just encountered this kind of issue and can tell me some tips?
Thanks
Marco
Hello Marco,
I'm not aware of any SDK examples that demonstrate DFU via a SD card, unfortunately. Have you considered other supported alternatives such as DFU through BLE or USB?
Best regards,
Vidar
Hi Vidar,
thanks for the reply. The customer wants to maintain the same behaviour of the previous version of the project (without Nordic device), where the new firmware was stored into SDCard and at reset, the bootloader read the hex from the sdcard, copies the application, removes the file and reboot the device with the new application. Some tips?
Best regards,
Marco
Dear Marco,
The magic word should be set to "good", not "unset", if the secondary image has been stored correctly.
As a test, can you try to program the 'app_moved_test_update.hex' with nrfjprog without going through the SD?
$ nrfjprog --program build/zephyr/app_moved_test_update.hex --sectorerase --verify --reset
Another thing is to check if the start address used to store the update candidate in flash matches the secondary address shown in the 'memory report'.
Best,
Vidar
Hi Vidar,
By using the nrfjprog the update works:
*** Booting Zephyr OS build v3.1.99-ncs1-1 *** I: Starting bootloader I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x3 I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Boot source: none I: Swap type: revert I: Starting swap using move algorithm. I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Bootloader chainload address offset: 0xc000 *** Booting Zephyr OS build v3.1.99-ncs1-1 *** Hello from AM Microsystems!
I also checked the address and it is correct. Why doesn't work with SD? Maybe need I to enable some flag after copy the firmware?
Best
Marco
Hi Marco,
Can you read the memory content in the secondary slot after loading it from the sd card and after programming the .hex to see if there is any difference?
$ nrfjprog --memrd <secondary slot start address> --n <size of secondary slot in bytes > secondary_slot.txt
Best,
Vidar
Hi Vidar,
sorry, I need to fix my last answer: yes, I can send the new firmware by using your command into the second partition and mcuboot recognize it (the code of my last answer), but the firmware is not updated!
Anyway, I try to read the secondary partition and the two version differ only on the last 256Byte. But I don't know why!
Best,
Marco
Hi Vidar,
Sorry again, but there is something strange: after a firmware update correct (only with your method, not by SD), the microcontroller start with a string that print the new version value... but after a reset a new firmware update was performed without my command and turn back to the first version. What is it wrong? The log is the following.
*** Booting Zephyr OS build v3.1.99-ncs1-1 *** 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.1.99-ncs1-1 *** Hello from AM Microsystems! Version: 1.0.1 update from usb by using nrfjprog *** Booting Zephyr OS build v3.1.99-ncs1-1 *** I: Starting bootloader I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Secondary image: magic=good, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Boot source: none I: Swap type: test I: Starting swap using move algorithm. I: Bootloader chainload address offset: 0xc000 *** Booting Zephyr OS build v3.1.99-ncs1-1 *** Hello from AM Microsystems! Version: 1.0.5 ... application running *** Booting Zephyr OS build v3.1.99-ncs1-1 *** I: Starting bootloader I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x3 I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Boot source: none I: Swap type: revert I: Starting swap using move algorithm. I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Bootloader chainload address offset: 0xc000 *** Booting Zephyr OS build v3.1.99-ncs1-1 *** Hello from AM Microsystems! Starting SGuideV3 from VOX Version: 1.0.1 application running
By SD no magic word was set!
Best,
Marco
Hi Vidar,
Sorry again, but there is something strange: after a firmware update correct (only with your method, not by SD), the microcontroller start with a string that print the new version value... but after a reset a new firmware update was performed without my command and turn back to the first version. What is it wrong? The log is the following.
*** Booting Zephyr OS build v3.1.99-ncs1-1 *** 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.1.99-ncs1-1 *** Hello from AM Microsystems! Version: 1.0.1 update from usb by using nrfjprog *** Booting Zephyr OS build v3.1.99-ncs1-1 *** I: Starting bootloader I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Secondary image: magic=good, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Boot source: none I: Swap type: test I: Starting swap using move algorithm. I: Bootloader chainload address offset: 0xc000 *** Booting Zephyr OS build v3.1.99-ncs1-1 *** Hello from AM Microsystems! Version: 1.0.5 ... application running *** Booting Zephyr OS build v3.1.99-ncs1-1 *** I: Starting bootloader I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x3 I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Boot source: none I: Swap type: revert I: Starting swap using move algorithm. I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Bootloader chainload address offset: 0xc000 *** Booting Zephyr OS build v3.1.99-ncs1-1 *** Hello from AM Microsystems! Starting SGuideV3 from VOX Version: 1.0.1 application running
By SD no magic word was set!
Best,
Marco
Hi Marco,
After the image was copied from the SD card to the secondary slot, did you run boot_set_pending()? This marks the image as a pending update, which includes writing of the magic word.
warcomeb-am said:but after a reset a new firmware update was performed without my command and turn back to the first version.
MCUBoot will revert the update if the image is not confirmed as the hex file contains a "test" image. You can read more about the different swap types here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/design.html#boot-swap-types.
To make a "test" image permanent, you can call boot_set_confirmed() from the new app.
Best,
Vidar
Hi Vidar,
good news: thanks to your help, now the firmware is updated. I added boot_set_pending() after the copy of the new firmware into image_1 from the SD and at the reboot the new firmware is active. But I have some doubts. The log is the following:
Connected via Serial Port with settings COM3 115200 8n1 rtscts:off *** Booting Zephyr OS build v3.1.99-ncs1-1 *** 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.1.99-ncs1-1 *** Hello from AM Microsystems! Version: 1.0.1 SDCARD Block count 15267840 SDCARD Sector size 512 SDCARD Memory Size(MB) 7455 DISK mounted! UPDATE: delete image_1 UPDATE: write firmware, packet 0, addr 0x84000 - OK UPDATE: write firmware, packet 1, addr 0x84400 - OK UPDATE: write firmware, packet 2, addr 0x84800 - OK UPDATE: write firmware, packet 3, addr 0x84c00 - OK UPDATE: write firmware, packet 4, addr 0x85000 - OK UPDATE: write firmware, packet 5, addr 0x85400 - OK UPDATE: write firmware, packet 6, addr 0x85800 - OK UPDATE: write firmware, packet 7, addr 0x85c00 - OK UPDATE: write firmware, packet 8, addr 0x86000 - OK UPDATE: write firmware, packet 9, addr 0x86400 - OK UPDATE: write firmware, packet 10, addr 0x86800 - OK UPDATE: write firmware, packet 11, addr 0x86c00 - OK UPDATE: write firmware, packet 12, addr 0x87000 - OK UPDATE: write firmware, packet 13, addr 0x87400 - OK UPDATE: write firmware, packet 14, addr 0x87800 - OK UPDATE: write firmware, packet 15, addr 0x87c00 - OK UPDATE: write firmware, packet 16, addr 0x88000 - OK UPDATE: write firmware, packet 17, addr 0x88400 - OK UPDATE: write firmware, packet 18, addr 0x88800 - OK UPDATE: write firmware, packet 19, addr 0x88c00 - OK UPDATE: write firmware, packet 20, addr 0x89000 - OK UPDATE: write firmware, packet 21, addr 0x89400 - OK UPDATE: write firmware, packet 22, addr 0x89800 - OK UPDATE: write firmware, packet 23, addr 0x89c00 - OK UPDATE: write firmware, packet 24, addr 0x8a000 - OK UPDATE: write firmware, packet 25, addr 0x8a400 - OK UPDATE: write firmware, packet 26, addr 0x8a800 - OK UPDATE: write firmware, packet 27, addr 0x8ac00 - OK UPDATE: write firmware, packet 28, addr 0x8b000 - OK UPDATE: write firmware, packet 29, addr 0x8b400 - OK UPDATE: write firmware, packet 30, addr 0x8b800 - OK UPDATE: write firmware, packet 31, addr 0x8bc00 - OK UPDATE: write firmware, packet 32, addr 0x8c000 - OK UPDATE: write firmware, packet 33, addr 0x8c400 - OK UPDATE: write firmware, packet 34, addr 0x8c800 - OK UPDATE: write firmware, packet 35, addr 0x8cc00 - OK UPDATE: write firmware, packet 36, addr 0x8d000 - OK UPDATE: write firmware, packet 37, addr 0x8d400 - OK UPDATE: write firmware, packet 38, addr 0x8d800 - OK UPDATE: write firmware, packet 39, addr 0x8dc00 - OK UPDATE: write firmware, packet 40, addr 0x8e000 - OK UPDATE: write firmware, packet 41, addr 0x8e400 - OK UPDATE: write firmware, packet 42, addr 0x8e800 - OK UPDATE: write firmware, packet 43, addr 0x8ec00 - OK UPDATE: write firmware, packet 44, addr 0x8f000 - OK UPDATE: write firmware, packet 45, addr 0x8f400 - OK UPDATE: write firmware, packet 46, addr 0x8f800 - OK UPDATE: write firmware, packet 47, addr 0x8fc00 - OK UPDATE: write firmware, packet 48, addr 0x90000 - OK UPDATE: write firmware, packet 49, addr 0x90400 - OK UPDATE: write firmware, packet 50, addr 0x90800 - OK UPDATE: write firmware, packet 51, addr 0x90c00 - OK UPDATE: write firmware, packet 52, addr 0x91000 - OK UPDATE: write firmware, packet 53, addr 0x91400 - OK UPDATE: write firmware, packet 54, addr 0x91800 - OK UPDATE: write firmware, packet 55, addr 0x91c00 - OK UPDATE: write firmware, packet 56, addr 0x92000 - OK UPDATE: write firmware, packet 57, addr 0x92400 - OK UPDATE: write firmware, packet 58, addr 0x92800 - OK UPDATE: write firmware, packet 59, addr 0x92c00 - OK UPDATE: write firmware, packet 60, addr 0x93000 - OK UPDATE: write firmware, packet 61, addr 0x93400 - OK UPDATE: write firmware, packet 62, addr 0x93800 - OK UPDATE: write firmware, packet 63, addr 0x93c00 - OK UPDATE: write firmware, packet 64, addr 0x94000 - OK UPDATE: write firmware, packet 65, addr 0x94400 - OK UPDATE: write firmware, packet 66, addr 0x94800 - OK UPDATE: write firmware, packet 67, addr 0x94c00 - OK UPDATE: write firmware, packet 68, addr 0x95000 - OK UPDATE: write firmware, packet 69, addr 0x95400 - OK UPDATE: write firmware, packet 70, addr 0x95800 - OK UPDATE: write firmware, packet 71, addr 0x95c00 - OK UPDATE: write firmware, packet 72, addr 0x96000 - OK UPDATE: write firmware, packet 73, addr 0x96400 - OK UPDATE: write firmware, packet 74, addr 0x96800 - OK UPDATE: write firmware, packet 75, addr 0x96c00 - OK UPDATE: write firmware, packet 76, addr 0x97000 - OK UPDATE: write firmware, packet 77, addr 0x97400 - OK UPDATE: write firmware, packet 78, addr 0x97800 - OK UPDATE: write firmware, packet 79, addr 0x97c00 - OK UPDATE: write firmware, packet 80, addr 0x98000 - OK UPDATE: write firmware, packet 81, addr 0x98400 - OK UPDATE: write firmware, packet 82, addr 0x98800 - OK UPDATE: write firmware, packet 83, addr 0x98c00 - OK UPDATE: write firmware, packet 84, addr 0x99000 - OK UPDATE: write firmware, packet 85, addr 0x99400 - OK UPDATE: write firmware, packet 86, addr 0x99800 - OK UPDATE: write firmware, packet 87, addr 0x99c00 - OK UPDATE: write firmware, packet 88, addr 0x9a000 - OK UPDATE: write firmware, packet 89, addr 0x9a400 - OK UPDATE: write firmware, packet 90, addr 0x9a800 - OK UPDATE: write firmware, packet 91, addr 0x9ac00 - OK UPDATE: write firmware, packet 92, addr 0x9b000 - OK UPDATE: write firmware, packet 93, addr 0x9b400 - OK UPDATE: write firmware, packet 94, addr 0x9b800 - OK UPDATE: write firmware, packet 95, addr 0x9bc00 - OK UPDATE: write firmware, packet 96, addr 0x9c000 - OK UPDATE: write firmware, packet 97, addr 0x9c400 - OK UPDATE: write firmware, packet 98, addr 0x9c800 - OK UPDATE: write firmware, packet 99, addr 0x9cc00 - OK UPDATE: write firmware, packet 100, addr 0x9d000 - OK UPDATE: write firmware, packet 101, addr 0x9d400 - OK UPDATE: write firmware, packet 102, addr 0x9d800 - OK UPDATE: write firmware, packet 103, addr 0x9dc00 - OK UPDATE: write firmware, packet 104, addr 0x9e000 - OK UPDATE: write firmware, packet 105, addr 0x9e400 - OK UPDATE: write firmware, packet 106, addr 0x9e800 - OK UPDATE: write firmware, packet 107, addr 0x9ec00 - OK UPDATE: write firmware, packet 108, addr 0x9f000 - OK UPDATE: write firmware, packet 109, addr 0x9f400 - OK UPDATE: write firmware, packet 110, addr 0x9f800 - OK UPDATE: write firmware, packet 111, addr 0x9fc00 - OK UPDATE: write firmware, packet 112, addr 0xa0000 - OK UPDATE: write firmware, packet 113, addr 0xa0400 - OK UPDATE: write firmware, packet 114, addr 0xa0800 - OK UPDATE: write firmware, packet 115, addr 0xa0c00 - OK UPDATE: write firmware, packet 116, addr 0xa1000 - OK UPDATE: write firmware, packet 117, addr 0xa1400 - OK UPDATE: write firmware, packet 118, addr 0xa1800 - OK UPDATE: write firmware, packet 119, addr 0xa1c00 - OK UPDATE: write firmware, packet 120, addr 0xa2000 - OK UPDATE: write firmware, packet 121, addr 0xa2400 - OK UPDATE: write firmware, packet 122, addr 0xa2800 - OK UPDATE: write firmware, packet 123, addr 0xa2c00 - OK UPDATE: write firmware, packet 124, addr 0xa3000 - OK UPDATE: write firmware, packet 125, addr 0xa3400 - OK UPDATE: write firmware, packet 126, addr 0xa3800 - OK UPDATE: write firmware, packet 127, addr 0xa3c00 - OK UPDATE: write firmware, packet 128, addr 0xa4000 - OK UPDATE: write firmware, packet 129, addr 0xa4400 - OK UPDATE: write firmware, packet 130, addr 0xa4800 - OK UPDATE: write firmware, packet 131, addr 0xa4c00 - OK UPDATE: write firmware, packet 132, addr 0xa5000 - OK UPDATE: write firmware, packet 133, addr 0xa5400 - OK UPDATE: write firmware, packet 134, addr 0xa5800 - OK UPDATE: write firmware, packet 135, addr 0xa5c00 - OK UPDATE: write firmware, packet 136, addr 0xa6000 - OK UPDATE: write firmware, packet 137, addr 0xa6400 - OK UPDATE: write firmware, packet 138, addr 0xa6800 - OK UPDATE: write firmware, packet 139, addr 0xa6c00 - OK UPDATE: write firmware, packet 140, addr 0xa7000 - OK UPDATE: write firmware, packet 141, addr 0xa7400 - OK UPDATE: write firmware, packet 142, addr 0xa7800 - OK UPDATE: write firmware, packet 143, addr 0xa7c00 - OK UPDATE: write firmware, packet 144, addr 0xa8000 - OK UPDATE: write firmware, packet 145, addr 0xa8400 - OK UPDATE: write firmware, packet 146, addr 0xa8800 - OK UPDATE: write firmware, packet 147, addr 0xa8c00 - OK UPDATE: write firmware, packet 148, addr 0xa9000 - OK UPDATE: write firmware, packet 149, addr 0xa9400 - OK UPDATE: write firmware, packet 150, addr 0xa9800 - OK UPDATE: write firmware, packet 151, addr 0xa9c00 - OK UPDATE: write firmware, packet 152, addr 0xaa000 - OK UPDATE: write firmware, packet 153, addr 0xaa400 - OK UPDATE: write firmware, packet 154, addr 0xaa800 - OK UPDATE: write firmware, packet 155, addr 0xaac00 - OK UPDATE: write firmware, packet 156, addr 0xab000 - OK UPDATE: write firmware, packet 157, addr 0xab400 - OK UPDATE: write firmware, packet 158, addr 0xab800 - OK UPDATE: write firmware, packet 159, addr 0xabc00 - OK UPDATE: write firmware, packet 160, addr 0xac000 - OK UPDATE: write firmware, packet 161, addr 0xac400 - OK UPDATE: write firmware, packet 162, addr 0xac800 - OK UPDATE: write firmware, packet 163, addr 0xacc00 - OK UPDATE: write firmware, packet 164, addr 0xad000 - OK UPDATE: write firmware, packet 165, addr 0xad400 - OK UPDATE: write firmware, packet 166, addr 0xad800 - OK UPDATE: write firmware, packet 167, addr 0xadc00 - OK UPDATE: write firmware, packet 168, addr 0xae000 - OK UPDATE: write firmware, packet 169, addr 0xae400 - OK UPDATE: write firmware, packet 170, addr 0xae800 - OK UPDATE: write firmware, packet 171, addr 0xaec00 - OK UPDATE: write firmware, packet 172, addr 0xaf000 - OK UPDATE: write firmware, packet 173, addr 0xaf400 - OK UPDATE: write firmware, packet 174, addr 0xaf800 - OK UPDATE: Complete! UPDATE: File deleted... *** Booting Zephyr OS build v3.1.99-ncs1-1 *** 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: Starting swap using move algorithm. I: Bootloader chainload address offset: 0xc000 *** Booting Zephyr OS build v3.1.99-ncs1-1 *** Hello from AM Microsystems! Version: 1.0.5 SDCARD Block count 15267840 SDCARD Sector size 512 SDCARD Memory Size(MB) 7455 DISK mounted! UPDATE: No file! PRESS RESET BUTTON... *** Booting Zephyr OS build v3.1.99-ncs1-1 *** I: Starting bootloader I: Primary image: magic=good, swap_type=0x3, copy_done=0x1, image_ok=0x1 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.1.99-ncs1-1 *** Hello from AM Microsystems! Version: 1.0.5 PRESS RESET BUTTON...
I read the documentation that you suggest to me, but I don't understand the change of word and status during the three reboots.
Anyway, I don't add boot_set_confirmed() and the swap it is not happen.
I am a little bit confused.
Best
Marco
Hi Marco,
I am glad to hear that it worked. I forgot to mention the boot_set_pending() function when asked earlier about the DFU steps. Anyway, the swap is set to "perm" for permanent, not "test" like earlier. This means the image is already confirmed so there is no need to call boot_set_confirmed() to avoid rollback.
Best
Vidar
Hi Vidar Berg ,
after some months I came back to you. The update works, but the compiler told me that can't find boot_set_pending() function [implicit declaration]. Witch file I can include to avoid this warning?
Best
Marco
Hi Marco,
Please try to enable CONFIG_MCUBOOT_IMG_MANAGER=y in your application project.
Best regards,
Vidar