nrf52840 + Zephyr: Custom bootloader base

Hello

I'm wondering what base I should use to build a custom Bootloader for the nRF52840 (the concept should also work for nRF5340, thus nRF5 SDK is no solution).

The custom Bootloader needs to implement LittleFS and a custom crypto Library. On boot, it should check if there is a verified Update, if yes it should start to decrypt it and load it into the nRF flash. This process is already implemented for some other MCU. I don't need any RTOS or other things, except SPI/FLASH Library.

What should be used as base? Is there an example? Should this Bootloader also be a Zephyr application?

Parents
  • Hi,

    Why do you wantt to make a custom bootloader instead of using one of the bootloaders we provide in the nRF Connect SDK (MCUboot and the nRF secure immutable bootloader). These can be used separately, or often, as a combination (typically the secure immutable bootloader is used to provide secure boot and valdiate and activate MCUboot in case you want an upgradable second stage bootloader, which is more often than not the case). See Bootloaders and Device Firmware Updates for more on these.

    That said, if you want to make a simple custom bootloader, I would suggest basing it on the immutable bootloader, as that is a very small and simple bootloader.

    What should be used as base? Is there an example? Should this Bootloader also be a Zephyr application?

    These two booltoaders when used in the nRF Connect SDK will also be Zephyr applications.

Reply
  • Hi,

    Why do you wantt to make a custom bootloader instead of using one of the bootloaders we provide in the nRF Connect SDK (MCUboot and the nRF secure immutable bootloader). These can be used separately, or often, as a combination (typically the secure immutable bootloader is used to provide secure boot and valdiate and activate MCUboot in case you want an upgradable second stage bootloader, which is more often than not the case). See Bootloaders and Device Firmware Updates for more on these.

    That said, if you want to make a simple custom bootloader, I would suggest basing it on the immutable bootloader, as that is a very small and simple bootloader.

    What should be used as base? Is there an example? Should this Bootloader also be a Zephyr application?

    These two booltoaders when used in the nRF Connect SDK will also be Zephyr applications.

Children
  • Ok, MCUboot might be indeed a good solution, as it seems to provide an API to supply the update from within the Application.

    Is there a guide on how to implement MCUboot into an already existing nRF Connect Project? Also, is there an example/guide on how to use the MCUboot API from within the nRF Connect Project application?

  • Hi,

    Generally, adding a SMP server to your application and adding MCUboot is quite straigt-forward as long as you have enough avilable flash memory (you will need to fit both the bootloder, and the application two times (a primary and secondary slot of equal size).

    To do the update from the application (which is what is normally done with MCUboot in nRF Connect SDK), you should have a SMP server in your application. That is demonstrated by the SMP server sample. I would also recomend this set of unoficcial samples that a colleague of me have made that demonstrates most aspects of DFU. We are also working on a more comprahensive guide but for now, the documentation together with these samples (particularily the second link) is probably the best way to get started.

  • I have now tried to implement MCUBoot with SMP. I see the Service and can start a DFU with the Android App. But it goes from "VALIDATING..." to "UPLOAD COMPLETE" within seconds. Without properly updating the OTA and resetting the MCU.

    This is my prj.conf:

    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_SMP=y
    CONFIG_BT_GATT_CLIENT=y
    CONFIG_BT_DEVICE_NAME="EnteEnteMachine"
    
    CONFIG_BT_BUF_ACL_RX_SIZE=255
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_BUF_CMD_TX_SIZE=255
    CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255
    
    CONFIG_BT_L2CAP_TX_MTU=498
    
    CONFIG_LOG=y
    
    CONFIG_SPI=y
    CONFIG_NRFX_SPIM3=y
    
    CONFIG_I2S=y
    CONFIG_NRFX_I2S0=y
    
    CONFIG_NRFX_RNG=y
    
    CONFIG_MAIN_STACK_SIZE=8192
    
    CONFIG_BT_RX_STACK_SIZE=8192
    
    CONFIG_HEAP_MEM_POOL_SIZE=8192
    
    
    # SMP
    # Enable Bootloader
    CONFIG_BOOTLOADER_MCUBOOT=y
    # Enable SMP Server
    CONFIG_MCUMGR=y
    CONFIG_MCUMGR_GRP_IMG=y
    # CONFIG_MCUMGR_GRP_IMG dependencies
    CONFIG_FLASH=y
    CONFIG_IMG_MANAGER=y
    # CONFIG_IMG_MANAGER dependencies
    CONFIG_STREAM_FLASH=y
    # CONFIG_MCUMGR dependencies
    CONFIG_NET_BUF=y
    CONFIG_ZCBOR=y
    # Required for CONFIG_IMG_MANAGER
    CONFIG_FLASH_MAP=y
    # Enable BLE transfer
    CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
    CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
    CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP=y
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096



    I suspect that the issue is that I use this common file for my GATT Services. Do I need to modify this first to be comatible with SMP?

    github.com/.../gatt_write_common.c

  • Hi,

    You should not need anything other than the configs you have here? Are you able to successfully update with this sample, just so we have a working reference for the process? And what are the differences when you compare with testing your own project?

  • Not sure why it wasn't working, but now it is working great Thumbsup

Related