Bootloader from SDCard

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

Parents Reply
  • Dear  ,

    During this time I worked on the other parts of the applications, but now it's time for me to finish the application with the bootloader! Sweat smile

    Just to understand better, the code that I need to add to my application is:

    • the user copies the file app_update.bin into SDCard
    • the application copies the contents of the file into the image_1 region by using the flash_* function
    • At the reboot, the bootloader copies the contents of image_1 into image_0 by itself

    now the application is updated, right?

    Best

    Marco

Children
  • Dear Marco,

    Yes, this should work. The bootloader will check if a new FW update is available in the secondary slot on boot. If there is, it will proceed to copy the image into the primary slot and boot the new application.

    Best,

    Vidar

  • Dear Vidar,

    Yesterday I implemented this solution but seems not work.
    The firmware copy the file into image_1 without any errors, but when the microcontroller reboots the firmware is not updated. The output is:

    *** 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!

    Do I need to add something to notify the new firmware to mcuboot? 

    Best

    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

Related