MCUBoot’s secondary image on external flash on nrf9160

I am using nrf9160 custom board with an external flash memory mx25l6433f. I first tested the external flash with the example 'sdk-zephyr/samples/drivers/spi_flash_at45' and for it to work was added an '.overlay'

 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
&spi3 {
status = "okay";
sck-pin = <8>;
mosi-pin = <11>;
miso-pin = <10>;
cs-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
mx25l64: mx25l6433f@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <8000000>;
label = "MX25L64";
jedec-id = [c2 20 17];
sfdp-bfp = [
e5 20 f1 ff ff ff ff 03 44 eb 08 6b 08 3b 04 bb
ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52
10 d8 00 ff 23 72 f5 00 82 ed 04 cc 44 83 68 44
30 b0 30 b0 f7 c4 d5 5c 00 be 29 ff f0 d0 ff ff
];
size = <67108864>;
has-dpd;
t-enter-dpd = <10000>;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and on my 'proj.conf' added

Fullscreen
1
2
3
4
5
# Test ext Flash
CONFIG_SPI=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_SPI_NOR=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compiled and tested. The external flash is working.

After this i tried to implement 'MCUBOOT secondary on external flash', after reading several posts i ended with this configurations:

nrf9160dk_nrf9160_ns.overlay

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
&spi3 {
status = "okay";
sck-pin = <8>;
mosi-pin = <11>;
miso-pin = <10>;
cs-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
mx25l64: mx25l6433f@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <8000000>;
label = "MX25L64";
jedec-id = [c2 20 17];
sfdp-bfp = [
e5 20 f1 ff ff ff ff 03 44 eb 08 6b 08 3b 04 bb
ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52
10 d8 00 ff 23 72 f5 00 82 ed 04 cc 44 83 68 44
30 b0 30 b0 f7 c4 d5 5c 00 be 29 ff f0 d0 ff ff
];
size = <67108864>;
has-dpd;
t-enter-dpd = <10000>;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

prj.conf

Fullscreen
1
2
3
4
5
6
7
8
9
# Test ext Flash
CONFIG_SPI=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_SPI_NOR=y
# set mcuboot_secondary on external flash
# This value must match the size of the MCUboot primary partition
CONFIG_PM_PARTITION_SIZE_MCUBOOT_SECONDARY=0xe0000
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

mcuboot.conf

Fullscreen
1
2
3
4
5
6
7
8
# Enable flash operations
CONFIG_FLASH=y
# This value must match the size of the MCUboot primary partition.
CONFIG_PM_PARTITION_SIZE_MCUBOOT_SECONDARY=0xe0000
# This must be increased to accommodate the bigger images.
CONFIG_BOOT_MAX_IMG_SECTORS=256
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In the end, after applying the changes my flash space doubled the amount and on 'build\build_nrf9160dk_nrf9160_ns\partitions.yml' we can see the external flash and mcuboot secondary on external flash

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
external_flash:
address: 0xe0000
end_address: 0x800000
region: external_flash
size: 0x720000
mcuboot:
address: 0x8200
end_address: 0x10000
placement:
before:
- mcuboot_primary
region: flash_primary
sharers: 0x1
size: 0x7e00
mcuboot_pad:
address: 0x18000
end_address: 0x18200
placement:
align:
start: 0x8000
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Then i programmed it to nrf9160 and it doesn't boot.

In one of the attempts to put it to work i removed the line 'CONFIG_PM_PARTITION_SIZE_MCUBOOT_SECONDARY=0xe0000' from mcuboot.conf and programmed it to nrf9160, this time it booted and started the program, but when i tried to update the firmware through DFU it says there is not enough space to store the update

Is this a bug, or did I simply went off track somewhere? Thanks.