DFU using USB file system (not serial emulation)?

My project has a nrf5340+external flash, and an external USB-C connector. The device exposes a USB file system (FAT) which is hosted on the external flash partition, and appears as an external disk when connected to a host. This all works well and is used to update config, image files etc for the device to use.

I would like to be able to do application / network firmware updates by simply copying the new image (hex or bin) to this file system and rebooting. Has anyone done this? I'm guessing it involves using MCUBoot bootloader and copying the image into the secondary image slot somehow? I also want to put the secondard image slot on my external flash as won't have space on the internal flash - even better would be if MCUBoot could take the image directly from the file in the FS....

by the way, to be clear, I do NOT want to use the 'DFU over USB serial emulation' method, as this requires the user to install the specific tool to the host machine, which may not be available for their host or may not be allowed by IT policy (or by their level of expertise...). 

thanks for any pointers!

Parents
  • Hi Brian, 
    Have you located flash space for MCUBoot it self? It should be located at address 0x0 and the application should be located after the MCUBoot partition. Please try to compile a sample with MCUboot included. You can check the partitions.yml generated to have an idea. 
    I attached here an example, it was from SDK v2.3 but it shouldn't be much change for the new SDK.
    https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/partitions.yml

  • that partitions.yml looks similar to what my PM generates. I use a pm_static.yml file for the external flash, and let the PM do the internal one. Partition sizes look the same, for mcu boot and for app..

    It seems the problem is not the cpunet : this gets generated ok and fits in its flash partitions (generated by PM or by magic...)

    [11/666] Performing build step for 'hci_ipc_subimage'
    [0/222] Generating signing key
    [2/222] Creating public key from private key used for signing
    [6/222] Creating data to be provisioned to the Bootloader, storing to provision.hex
    [9/222] Performing build step for 'b0n_subimage'
    [2/137] Generating include/generated/version.h
    -- Zephyr version: 3.5.99 (C:/work/dev/nordic_connect/zephyr), build: 3758bcbfa5cd
    [137/137] Linking C executable zephyr\zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 23710 B 34176 B 69.38%
    RAM: 3528 B 64 KB 5.38%
    SRAM1: 0 GB 64 KB 0.00%
    IDT_LIST: 0 GB 32 KB 0.00%
    [10/222] Generating include/generated/version.h
    -- Zephyr version: 3.5.99 (C:/work/dev/nordic_connect/zephyr), build: 3758bcbfa5cd
    [218/222] Linking C executable zephyr\zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 181952 B 222 KB 80.04%
    RAM: 48700 B 64 KB 74.31%
    SRAM1: 0 GB 64 KB 0.00%
    IDT_LIST: 0 GB 32 KB 0.00%
    [219/222] Creating signature of application
    [220/222] Creating validation for zephyr.hex, storing to
    [222/222] Generating zephyr/merged_CPUNET.hex

    So I guess the problem is with the main app flash size... it complains twice:

    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr\zephyr_pre0.elf section `rodata' will not fit in region `FLASH'
    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: region `FLASH' overflowed by 4552 bytes

    ... and then ...

    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: warning: orphan section `.fonts' from `app/libapp.a(u8g2_fonts.c.obj)' being placed in section `.fonts'
    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr\zephyr_pre0.elf section `.fonts' will not fit in region `FLASH'
    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: region `FLASH' overflowed by 21223 bytes

    I'm kind of surprised but maybe my main app is too large for the 'app' partition now its squeezed by mcuboot (but only about 50kb from 990kB, so thats unlikely??)

Reply Children
  • If I rebuild with CONFIG_DEBUG=n and CONFIG_DEBUG_INFO=n, then the main app seems to fit:

    [655/666] Linking C executable zephyr\zephyr.elf
    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: warning: orphan section `.fonts' from `app/libapp.a(u8g2_fonts.c.obj)' being placed in section `.fonts'
    Memory region Used Size Region Size %age Used
    FLASH: 909678 B 998912 B 91.07%
    RAM: 219104 B 440 KB 48.63%
    IDT_LIST: 0 GB 32 KB 0.00%

    But some other section doesn't 

    [274/279] Linking C executable zephyr\zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map C:/work/dev/if-device-nrf53/cc1-med/build/mcuboot/zephyr/zephyr_pre0.map
    ...
    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr\zephyr_pre0.elf section `rodata' will not fit in region `FLASH'
    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: region `FLASH' overflowed by 4552 bytes

    Is this mcuboot itself? Is there a way to build a 'minimal' mcuboot image?

  • Hi Brian, 

    The MCUBoot would take about 48kB. I don't think you can reduce the size more. Please double check if you turn off UART log, turn off serial recovery on MCUBoot (CONFIG_MCUBOOT_SERIAL=n). 

    Could you do a test to reduce the application flash size so that the application can be build and we can take a look at the partitions.yml to see how all the partitions allocated ? 


    I assume you have put the app to start address 0xc200 ? and the mcuboot is at 0x00 ? 

  • Well, according to NCS, CONFIG_MCUBOOT_SERIAL is not a valid key. 

    C:/work/dev/if-device-nrf53/cc1-med/prj.conf:253: warning: attempt to assign the value 'n' to the undefined symbol MCUBOOT_SERIALParsing C:/work/dev/nordic_connect/zephyr/Kconfig
    Loaded configuration 'C:/work/dev/if-device-nrf53/cc1-med/boards/arm/cc1medv1_nrf5340/cc1medv1_nrf5340_cpuapp_defconfig'
    Merged configuration 'C:/work/dev/if-device-nrf53/cc1-med/prj.conf'
    error: Aborting due to Kconfig warnings

    The documentation refers to CONFIG_MCUBOOT_USB_SUPPORT instead, but if I set this to 'n' then it also fails...

    error: MCUBOOT_USB_SUPPORT (defined at C:/work/dev/nordic_connect/nrf/modules/mcuboot/Kconfig:89) is
    assigned in a configuration file, but is not directly user-configurable (has no prompt). It gets its
    value indirectly from other symbols. See
    docs.zephyrproject.org/.../kconfig.html and/or look up
    MCUBOOT_USB_SUPPORT in the menuconfig/guiconfig interface. The Application Development Primer,
    Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be
    helpful too.

    And it won't let me disable mcuboot logs either.

    my prj.conf bit that fails

    CONFIG_BOOTLOADER_MCUBOOT=y
    # put slot2 in external flash
    CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH=y
    CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE=y
    CONFIG_MCUBOOT_BOOTUTIL_LIB=n
    CONFIG_MCUBOOT_IMG_MANAGER=n
    CONFIG_MCUBOOT_SHELL=n
    CONFIG_MCUBOOT_SERIAL=n
    CONFIG_MCUBOOT_UTIL_LOG_LEVEL_ERR=n
  • I have tried to reduce the mcuboot itself, but still get exactly the same error:

    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr\zephyr_pre0.elf section `rodata' will not fit in region `FLASH'
    c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: region `FLASH' overflowed by 4552 bytes

    I get this errpr before it has finished compiling the application source files (or at least warnings related to there appear after this error...), and its always the same size of overflow despite removing debug etc from my app...

    The partition manager generates an internal partition for mcuboot (0-c000) plus a mcuboot 'pad' (c000-c200) and the 'app' partition at c200-100000 (which seems reasonable). Here's the generated partitions.yml:

    app:
      address: 0xc200
      end_address: 0x100000
      region: flash_primary
      size: 0xf3e00
    external_flash:
      address: 0x744000
      end_address: 0x800000
      region: external_flash
      size: 0xbc000
    fatfs_storage:
      address: 0x0
      affiliation:
      - disk
      end_address: 0x600000
      extra_params:
        disk_cache_size: 0x1000
        disk_name: NAND
        disk_read_only: 0x0
        disk_sector_size: 0x200
      placement:
        after:
        - start
        align:
          start: 0x1000
      region: external_flash
      size: 0x600000
    mcuboot:
      address: 0x0
      end_address: 0xc000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0xc000
    mcuboot_pad:
      address: 0xc000
      end_address: 0xc200
      placement:
        align:
          start: 0x4000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0xc000
      end_address: 0x100000
      orig_span: &id001
      - mcuboot_pad
      - app
      region: flash_primary
      size: 0xf4000
      span: *id001
    mcuboot_primary_app:
      address: 0xc200
      end_address: 0x100000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0xf3e00
      span: *id002
    mcuboot_secondary:
      address: 0x650000
      affiliation:
      - mcuboot
      end_address: 0x744000
      region: external_flash
      size: 0xf4000
    mcuboot_secondary_1:
      address: 0x610000
      affiliation:
      - mcuboot
      end_address: 0x650000
      region: external_flash
      size: 0x40000
    nvs_storage:
      address: 0x600000
      affiliation:
      - nvs
      end_address: 0x610000
      region: external_flash
      size: 0x10000
    otp:
      address: 0xff8100
      end_address: 0xff83fc
      region: otp
      size: 0x2fc
    pcd_sram:
      address: 0x20000000
      end_address: 0x20002000
      placement:
        after:
        - start
      region: sram_primary
      size: 0x2000
    rpmsg_nrf53_sram:
      address: 0x20070000
      end_address: 0x20080000
      placement:
        before:
        - end
      region: sram_primary
      size: 0x10000
    sram_primary:
      address: 0x20002000
      end_address: 0x20070000
      region: sram_primary
      size: 0x6e000
     
Related