Adding mcuboot to BLE peripheral fails to link properly on nRF52840 dongle

Several have asked about this basic situation but I have found no definitive answer.

I erased a dongle with a Segger J-link, and compiled the zephyr samples using CONFIG_BOARD_HAS_NRF5_BOOTLOADER=n in the prj.conf file.
This tells KConfig there is no nrf bootloader, so the application gets placed at 0x00 and runs properly.

But now I need MCUboot so I added CONFIG_BOOTLOADER_MCUBOOT=y to the prj.conf file. 
It appears the system ignores the fact I told it there is no nrf bootloader, because I get "region `FLASH' overflowed by 7556 bytes" because the build system thinks the NRF Bootloader is in the first 0x1000 bytes of flash given the partitions.yml file:

EMPTY_0:
  address: 0xff000
  end_address: 0x100000
  placement:
    after:
    - mcuboot_secondary
  region: flash_primary
  size: 0x1000
app:
  address: 0xd200
  end_address: 0x86000
  region: flash_primary
  size: 0x78e00
mcuboot:
  address: 0x1000
  end_address: 0xd000
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0xc000
mcuboot_pad:
  address: 0xd000
  end_address: 0xd200
  placement:
    align:
      start: 0x1000
    before:
    - mcuboot_primary_app
  region: flash_primary
  size: 0x200
mcuboot_primary:
  address: 0xd000
  end_address: 0x86000
  orig_span: &id001
  - app
  - mcuboot_pad
  region: flash_primary
  sharers: 0x1
  size: 0x79000
  span: *id001
mcuboot_primary_app:
  address: 0xd200
  end_address: 0x86000
  orig_span: &id002
  - app
  region: flash_primary
  size: 0x78e00
  span: *id002
mcuboot_secondary:
  address: 0x86000
  end_address: 0xff000
  placement:
    after:
    - mcuboot_primary
    align:
      start: 0x1000
    align_next: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_primary
  size: 0x79000
nrf5_mbr:
  address: 0x0
  end_address: 0x1000
  placement:
    after:
    - start
  region: flash_primary
  size: 0x1000
sram_primary:
  address: 0x20000000
  end_address: 0x20040000
  region: sram_primary
  size: 0x40000

Even variations on this overlay don't seem to help:

/delete-node/ &boot_partition;
/delete-node/ &slot0_partition;
/delete-node/ &slot1_partition;
/delete-node/ &scratch_partition;
/delete-node/ &storage_partition;

&flash0 {
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		/* The size of this partition ensures that MCUBoot can be built
		 * with an RTT console, CDC ACM support, and w/o optimizations.
		 */
		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x000000000 0x0000c000>;
		};

		slot0_partition: partition@c000 {
			label = "image-0";
			reg = <0x0000c000 0x000067000>;
		};
		slot1_partition: partition@73000 {
			label = "image-1";
			reg = <0x00073000 0x000067000>;
		};
		scratch_partition: partition@da000 {
			label = "image-scratch";
			reg = <0x000da000 0x0001e000>;
		};
		storage_partition: partition@f8000 {
			label = "storage";
			reg = <0x000f8000 0x00008000>;
		};
	};
};

Can you come up with a solution to getting a simple peripheral example WITH MCUboot enabled to build an run on a dongle with the NRF Bootloader erased?

  • This is working for me on my custom app:

    west build \
    --pristine \
    --build-dir=build \
    --board nrf52840dongle_nrf52840 \
    -- \
    -DPM_STATIC_YML_FILE=pm_ota.yml \
    -D"mcuboot_CONFIG_BOARD_HAS_NRF5_BOOTLOADER=n" \
    -D"CONFIG_BOARD_HAS_NRF5_BOOTLOADER=n" \
    -D"mcuboot_CONFIG_USB_DEVICE_STACK=n" \
    -D"mcuboot_CONFIG_MCUBOOT_SERIAL=n" \
    -D"mcuboot_CONFIG_DISABLE_FLASH_PATCH=y" \
    -D"mcuboot_CONFIG_BOOT_SIGNATURE_KEY_FILE=\"/foo/bar/key.pem\"" \
    -D"CONFIG_MCUBOOT_IMAGE_VERSION=\"1.2.3\"

    Part of the problem is that the default mcuboot build will include the USB serial recovery code, which makes the bootloader image much larger.  I had to turn it off to get below 0xc000 bytes.

    Also had to patch NCS with https://github.com/nrfconnect/sdk-nrf/pull/7997

    pm_ota.yml uses this static map:

    mcuboot:
    address: 0x0
    size: 0xc000

    mcuboot_primary:
    address: 0xc000
    size: 0x74000
    mcuboot_pad:
    address: 0xc000
    size: 0x200
    app:
    address: 0xc200
    size: 0x73e00
    mcuboot_primary_app:
    address: 0xc200
    size: 0x73e00
    span: [ app ]

    mcuboot_secondary:
    address: 0x80000
    size: 0x74000

    zboss_nvram:
    address: 0xf5000
    size: 0x8000
    zboss_product_config:
    address: 0xfd000
    size: 0x1000
    settings_storage:
    address: 0xfe000
    size: 0x2000

    sram_primary:
    address: 0x20000000
    size: 0x40000
    region: sram_primary
  • After patching multi_image.cmake and then modifying the command line for my particulars, this DOES work. 

    I'd prefer to do the same in VSCode where I have my other projects. I have to 'Debug' the unit from VSCode to flash the dongle since running 'Flash' from there does a rebuilds and fails.

    But at least I have a path forward for the moment. 

  • I put my mcuboot config options in the west command line because a couple of them are computed dynamically at build time.  But I think you can stuff the static ones into child_image/mcuboot/prj.conf as some of the samples do.  I haven't tried this and I don't know what the VSCode plugin will/won't pick up.

    Also, if you don't support a non-OTA configuration, you could just rename pm_ota.yml to pm_static_nrf52840dongle_nrf52840.yml .  I used the override because I do most of my everyday development on non-OTA-enabled images (simpler, quicker build/flash time) and then switch to OTA builds when I'm ready to deploy them in the lab.

    I think that if you're debugging the device, you probably want mcuboot_CONFIG_DISABLE_FLASH_PATCH=n

Related