zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.48k stars 6.41k forks source link

mcuboot image not confirmed on nrf5340dk #41722

Closed youssefchei-xite closed 2 years ago

youssefchei-xite commented 2 years ago

Describe the bug

I'm developing an nrf5340 application and I'm trying to add DFU via updatehub over modem transport. I'm following the documentation, it seems like the binary is signed and loaded correctly. The problem is I always get the error "The current image is not confirmed"

I tested on zephyr v2.6.99-ncs1 and v2.7.0-ncs1 on Macos. I tested with nrf5340dk and nrf52833dk with the same error

What is this config option supposed to be, and how can I get it to work? Am I missing another config option?

To Reproduce

west build --board=nrf5340dk_nrf5340_cpuapp -d build zephyr/samples/subsys/mgmt/updatehub -- -DOVERLAY_CONFIG="overlay-modem.conf" west flash -d build

### Build output:

> -- west build: generating a build system
> Including boilerplate (Zephyr base (cached)): /opt/nordic/ncs/v1.7.0/zephyr/cmake/app/boilerplate.cmake
> CMake Deprecation Warning at /opt/nordic/ncs/v1.7.0/zephyr/cmake/app/boilerplate.cmake:37 (cmake_policy):
>   The OLD behavior for policy CMP0079 will be removed from a future version
>   of CMake.
> 
>   The cmake-policies(7) manual explains that the OLD behaviors of all
>   policies are deprecated and that a policy should be set to OLD only under
>   specific short-term circumstances.  Projects should be ported to the NEW
>   behavior and not rely on setting a policy to OLD.
> Call Stack (most recent call first):
>   /opt/nordic/ncs/v1.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
>   /opt/nordic/ncs/v1.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
>   CMakeLists.txt:10 (find_package)
> 
> 
> -- Application: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin
> -- Using NCS Toolchain 1.8.0 for building. (/opt/nordic/ncs/v1.8.0/toolchain/cmake)
> -- Zephyr version: 2.6.99 (/opt/nordic/ncs/v1.7.0/zephyr), build: v2.6.99-ncs1
> -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
> -- Board: nrf5340dk_nrf5340_cpuapp
> -- Cache files will be written to: /Users/youssefchei/Library/Caches/zephyr
> -- Found dtc: /opt/nordic/ncs/v1.8.0/toolchain/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
> -- Found toolchain: gnuarmemb (/opt/nordic/ncs/v1.8.0/toolchain)
> -- Found BOARD.dts: /opt/nordic/ncs/v1.7.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
> -- Found devicetree overlay: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/boards/nrf5340dk_nrf5340_cpuapp.overlay
> nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:15.39-20.5: Warning (interrupt_provider): /soc/interrupt-controller@e000e100: Missing #address-cells in interrupt provider
>   also defined at nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:467.7-469.3
> -- Generated zephyr.dts: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/zephyr/zephyr.dts
> -- Generated devicetree_unfixed.h: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/zephyr/include/generated/devicetree_unfixed.h
> -- Generated device_extern.h: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/zephyr/include/generated/device_extern.h
> -- Including generated dts.cmake file: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/zephyr/dts.cmake
> Parsing /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/Kconfig
> Loaded configuration '/opt/nordic/ncs/v1.7.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
> Merged configuration '/opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/prj.conf'
> Merged configuration 'overlay-modem.conf'
> Configuration saved to '/opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/zephyr/.config'
> Kconfig header saved to '/opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/zephyr/include/generated/autoconf.h'
> 
> === child image mcuboot -  begin ===
> Including boilerplate (Zephyr base (cached)): /opt/nordic/ncs/v1.7.0/zephyr/cmake/app/boilerplate.cmake
> CMake Deprecation Warning at /opt/nordic/ncs/v1.7.0/zephyr/cmake/app/boilerplate.cmake:37 (cmake_policy):
>   The OLD behavior for policy CMP0079 will be removed from a future version
>   of CMake.
> 
>   The cmake-policies(7) manual explains that the OLD behaviors of all
>   policies are deprecated and that a policy should be set to OLD only under
>   specific short-term circumstances.  Projects should be ported to the NEW
>   behavior and not rely on setting a policy to OLD.
> Call Stack (most recent call first):
>   /opt/nordic/ncs/v1.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
>   /opt/nordic/ncs/v1.7.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
>   CMakeLists.txt:44 (find_package)
> 
> 
> -- Application: /opt/nordic/ncs/v1.7.0/bootloader/mcuboot/boot/zephyr
> -- Using NCS Toolchain 1.8.0 for building. (/opt/nordic/ncs/v1.8.0/toolchain/cmake)
> -- Zephyr version: 2.6.99 (/opt/nordic/ncs/v1.7.0/zephyr), build: v2.6.99-ncs1
> -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
> -- Board: nrf5340dk_nrf5340_cpuapp
> -- Cache files will be written to: /Users/youssefchei/Library/Caches/zephyr
> -- Found dtc: /opt/nordic/ncs/v1.8.0/toolchain/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
> -- Found toolchain: gnuarmemb (/opt/nordic/ncs/v1.8.0/toolchain)
> -- Found BOARD.dts: /opt/nordic/ncs/v1.7.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
> -- Found devicetree overlay: /opt/nordic/ncs/v1.7.0/bootloader/mcuboot/boot/zephyr/dts.overlay
> -- Found devicetree overlay: /opt/nordic/ncs/v1.7.0/bootloader/mcuboot/boot/zephyr/dts.overlay
> -- Found devicetree overlay: /opt/nordic/ncs/v1.7.0/bootloader/mcuboot/boot/zephyr/dts.overlay
> nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:15.39-20.5: Warning (interrupt_provider): /soc/interrupt-controller@e000e100: Missing #address-cells in interrupt provider
>   also defined at nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:467.7-469.3
> -- Generated zephyr.dts: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot/zephyr/zephyr.dts
> -- Generated devicetree_unfixed.h: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot/zephyr/include/generated/devicetree_unfixed.h
> -- Generated device_extern.h: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot/zephyr/include/generated/device_extern.h
> -- Including generated dts.cmake file: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot/zephyr/dts.cmake
> Parsing /opt/nordic/ncs/v1.7.0/bootloader/mcuboot/boot/zephyr/Kconfig
> Loaded configuration '/opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot/zephyr/.config'
> No change to configuration in '/opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot/zephyr/.config'
> No change to Kconfig header in '/opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot/zephyr/include/generated/autoconf.h'
> MCUBoot bootloader key file: /opt/nordic/ncs/_keys/rsa2048_priv.pem
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build/mcuboot
> === child image mcuboot -  end ===
> 
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /opt/nordic/ncs/v1.7.0/zephyr/samples/subsys/mgmt/updatehub_origin/build
> -- west build: building application
> [0/237] Performing build step for 'mcuboot_subimage'
> [120/126] Linking C executable zephyr/zephyr_prebuilt.elf
> 
> [123/126] Generating dev_handles.c
> /opt/nordic/ncs/v1.7.0/zephyr/scripts/gen_handles.py:46: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
>   if LooseVersion(elftools.__version__) < LooseVersion('0.24'):
> [126/126] Linking C executable zephyr/zephyr.elf
> Memory region         Used Size  Region Size  %age Used
>            FLASH:       34828 B        48 KB     70.86%
>             SRAM:       22656 B       504 KB      4.39%
>         IDT_LIST:          0 GB         2 KB      0.00%
> [223/235] Linking C executable zephyr/zephyr_prebuilt.elf
> 
> [226/235] Generating dev_handles.c
> /opt/nordic/ncs/v1.7.0/zephyr/scripts/gen_handles.py:46: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
>   if LooseVersion(elftools.__version__) < LooseVersion('0.24'):
> [230/235] Linking C executable zephyr/zephyr.elf
> Memory region         Used Size  Region Size  %age Used
>            FLASH:      148904 B     491008 B     30.33%
>             SRAM:       71975 B       504 KB     13.95%
>         IDT_LIST:          0 GB         2 KB      0.00%
> [235/235] Generating zephyr/merged.hex

### nRF5340 output:

> *** Booting Zephyr OS build v2.6.99-ncs1  ***
> I: Starting bootloader
> I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
> I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
> I: Boot source: none
> I: Swap type: none
> I: Bootloader chainload address offset: 0xc000
> *** Booting Zephyr OS build v2.6.99-ncs1  ***
> 
> 
> [00:00:00.002,838] <wrn> modem_gsm:  gsm_ppp_start()
> [00:00:00.008,270] <inf> main: UpdateHub sample app started
> [00:00:00.008,300] <inf> main: Confirming the boot image
> [00:00:00.008,361] <inf> main: APN 'web.pt.lu' UART 'UART_3' device 0x29944
> [00:00:00.008,392] <inf> main: Network disconnected
> [00:00:22.007,080] <err> modem_gsm: modem setup returned -116, retrying...
> [00:00:23.170,928] <inf> modem_gsm: Manufacturer: Quectel
> [00:00:23.223,663] <inf> modem_gsm: Model: BG95-M3
> [00:00:23.276,977] <inf> modem_gsm: Revision: BG95M3LAR02A04
> [00:00:23.330,780] <inf> modem_gsm: IMSI: 270011001938505
> [00:00:23.385,375] <inf> modem_gsm: ICCID: 8935201910309385058F
> [00:00:23.438,995] <inf> modem_gsm: IMEI: 867730051140394
> [00:00:23.548,706] <inf> modem_gsm: Attached to packet service!
> [00:00:25.553,100] <inf> modem_gsm: RSSI: -69
> [00:00:25.553,863] <inf> net_ppp: Initializing PPP to use UART_3
> [00:00:35.589,965] <inf> main: Network connected
> [00:00:35.589,996] <inf> main: Starting UpdateHub polling mode
> [00:00:35.589,996] <inf> updatehub: SHA-256 verification on download and from flash
> [00:00:35.590,087] <err> updatehub: The current image is not confirmed
> �*** Booting Zephyr OS build v2.6.99-ncs1  ***nconfirmed. Rebooting to revert back to previousconfirmed image.
> I: Starting bootloader
> I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
> I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
> I: Boot source: none
> I: Swap type: none
> I: Bootloader chainload address offset: 0xc000
> *** Booting Zephyr OS build v2.6.99-ncs1  ***
> 
> 
> [00:00:00.002,807] <wrn> modem_gsm:  gsm_ppp_start()
> [00:00:00.008,239] <inf> main: UpdateHub sample app started
> [00:00:00.008,270] <inf> main: Confirming the boot image
> [00:00:00.008,331] <inf> main: APN 'web.pt.lu' UART 'UART_3' device 0x29944
> [00:00:00.008,331] <inf> main: Network disconnected

I tried to confirm the image with the shell command, is seems like the image is not confirmed

> *** Booting Zephyr OS build v2.6.99-ncs1  ***
> I: Starting bootloader
> I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
> I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
> I: Boot source: none
> I: Swap type: none
> I: Bootloader chainload address offset: 0xc000
> *** Booting Zephyr OS build v2.6.99-ncs1  ***
> 
> 
> [00:00:00.002,838] <wrn> modem_gsm:  gsm_ppp_start()
> [00:00:00.008,270] <inf> main: UpdateHub sample app started
> [00:00:00.008,270] <inf> main: Confirming the boot image
> [00:00:00.008,361] <inf> main: APN 'web.pt.lu' UART 'UART_3' device 0x29944
> [00:00:00.008,361] <inf> main: Network disconnected
> uart:~$ mcuboot confirm
> uart:~$ mcuboot
> swap type: none
> confirmed: 0
> 
> primary area (2):
>   version: 0.0.0+0
>   image size: 148904
>   magic: unset
>   swap type: none
>   copy done: unset
>   image ok: unset
> 
> failed to read secondary area (5) header: -5
> [00:00:13.204,986] <inf> mcuboot_util: Swap type: none
> uart:~$
> 
nvlsianpu commented 2 years ago

@youssefchei-xite As I see you are using the NCS environment (which is fine). You can follow configuration of NCS machine_learning sample for nRF53.

The NCS build system and its configuration differs from the pure zephy-rtos. This ticket should be opened in the Nordic devzone. That why I'm closing the issue here.