MCUboot for nRF52840

Hi. I am trying to figure out how to be able to flash my custom board with chip nRF52840 using USB. I have found out sample which can solve my problem: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/usb/dfu/README.html. I need to flash MCUboot as my 1st stage bootloader. I have found out that I need to use this code: https://github.com/mcu-tools/MCUboot/tree/master/boot/zephyr. But I need to adjust this code to my case, using DFU and be able to flash with USB. Also my board doesnt have any button (so I cant entering bootloader with button like nrf52840dongle). I dont know which Kconfig to use and also how to adjust it, also which .conf and .overlay files to use. I couldnt find any topics related to it, Is there someone who did something like this before or someone who can help me how to start? Thanks for your help.

  • Hi,

    A colleague of mine has made an example for DFU over USB with serial recovery and wait for DFU. When the device is turned on, it will wait for 5 seconds. If it receives mcumgr commands during this time, it will enter serial recovery mode, and you can perform DFU. This means you do not need a button to set the device in bootloader mode as with the dongle. The example can be found here: MCUboot Serial Recovery Sample over USB CDC with Wait For DFU. This code is not thoroughly tested or qualified and should be considered provided “as-is”.

    Since you do not have a bootloader, you will need an external debugger to program the custom board. After you have programmed the board with a bootloader, you can use the bootloader and DFU to program it.

    Best regards,
    Marte

  • Hi. Thanks for your answer, but I have some questions :). I have studied the example which you provided for me and also README files. Do I understand it correctly?

    1. The sample which you provide (serial recovery) is my bootloader? This code I should build and flash to my board to partition, in my case boot_partition label="mcuboot". This code will be my bootloader. The image below is from one of the README files, SMP server (serial recovery) is bootloader.

    2. If point 1. is true, which .conf file should I use? There are two .conf files in this sample, mcuboot.conf and prj.conf. I think that mcuboot.conf is for SMP server (serial recovery) and prj.conf is for the app which I want to flash via mcumgr (app which will be flashed to primary slot).

    3. After I flash the sample serial recovery as my bootloader, I will be able to use mcumgr to flash new app to my board via USB. I dont need to flash DFU sample code to image-slot1 or something.

    4. As I can see from mcuboot.conf, I need to use only one app slot to be able to flash my board via USB. What type of flash partition configuration should I use (I think about 1 image partition but also I want to use internal memory of chip).

    5. To be able to flash new app images, I need to use signed binary images. 

    I am sorry for so many questions, but this is probably the third possible solution to my problem so I am a little bit confused right now. Thanks for your help.

  • Hi,

    I will continue helping with this case.

    I will cover some of the definitions here. These are specific for MCUboot

    • MCUboot
      • The bootloader
      • Will run before the application.
      • Will swap slots to update the application (if pending)
      • The above are the basic functionality, but you can add more
    • DFU
      • Sending an image from from an external device to the cip
      • New Image is saved in secondary slot
      • Using the SMP Protocol
    • SMP Protocol
      • Can be run on top of different transports, such as UART or BLE
    • SMP Client:
      • Uses the SMP Protocol to send firmware updates to an SMP Server.
      • Running on external device, such as PC, android or host MCU
    • SMP Server:
      • Receives firmware updates
      • Runs on the Nordic SoC (or other chip)
    • SMP Server in application:
      • The SMP Server runs in your application
      • Requires multiple image slots
    • Serial Recovery
      • MCUboot specific name for "SMP Server runs inside MCUboot"
      • Need single image slot, as the update can overwrite application
    domko99 said:
    1. The sample which you provide (serial recovery) is my bootloader? This code I should build and flash to my board to partition, in my case boot_partition label="mcuboot". This code will be my bootloader. The image below is from one of the README files, SMP server (serial recovery) is bootloader.

    In my example, you build both the bootloader and the application.
    MCUboot is built as a child image.

    When you flash, both the application and MCUboot is flashed to your device.
    Code and configurations for the application are inside serial recovery. (prj.conf, src/main.c, CMakeLists.txt, etc.)
    Code and configurations for MCUboot are inside mcuboot/boot/zephyr. However, you should not change this.
    To configure MCUboot, you can use image specific variables to overlay the configurations for MCUboot. This would be child_image/mcuboot.conf.

    domko99 said:
    2. If point 1. is true, which .conf file should I use? There are two .conf files in this sample, mcuboot.conf and prj.conf. I think that mcuboot.conf is for SMP server (serial recovery) and prj.conf is for the app which I want to flash via mcumgr (app which will be flashed to primary slot).

    1. was corrected. You use both as explained above.

    domko99 said:
    3. After I flash the sample serial recovery as my bootloader, I will be able to use mcumgr to flash new app to my board via USB. I dont need to flash DFU sample code to image-slot1 or something.

    The application is already a part of the example above, so no need to program it additionally.
    When you want to update the application, you can use the pre-generated build/zephyr/app_update.bin for sending to the SMP Server.

    domko99 said:
    4. As I can see from mcuboot.conf, I need to use only one app slot to be able to flash my board via USB. What type of flash partition configuration should I use (I think about 1 image partition but also I want to use internal memory of chip).

    Partitioning is handeled automatically in the sample above.
    You can have a look at build/partitions.yml to see the finished partition table.

    domko99 said:
    5. To be able to flash new app images, I need to use signed binary images. 

    Yes.
    When you want to update the application, you can use the pre-generated build/zephyr/app_update.bin for sending to the SMP Server. You can read more about these under MCUboot output build files.

    Also see our official bootloader documentation at Bootloaders and Device Firmware Updates.

    Regards,
    Sigurd Hellesvik

Related