This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Problem with signing images for OTA DFU

I have had several problems with signing images, so I'll start with something simple, and I hope you can bear with me as I get to my final goal which is to OTA (which I am already doing, but not signed) with the project we are working on.

I am testing everything on a nrf52dk_nrf52832 using both windows 10 and ubuntu 20 VM's and I have had similar problems with both of them. I am using NCS v1.3.2 in both cases. I am not a beginner in Zephyr, or Nordic in general for that matter, but I feel like one with the whole signing, mcumgr cli using the 840 as HCI_USB in ubuntu, etc

Firstly, there are two "how to " pages that do not work following directions, so if you would kindly tell me what is wrong with the instructions.

Please advice.


The first page is "Signing Binaries

Following instructions, the first line has no problem...

antonio@ubuntu:~/ncs$ west build -b nrf52dk_nrf52832 -s bootloader/mcuboot/boot/zephyr -d build-mcuboot

But then the next command line...

antonio@ubuntu:~/ncs$ west build -b nrf52dk_nrf52832 -s zephyr/samples/hello_world -d build-hello-signed -- -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"bootloader/mcuboot/root-rsa-2048.pem\"

Comes with errors...

antonio@ubuntu:~/ncs$ west build -b nrf52dk_nrf52832 -s zephyr/samples/hello_world -d build-hello-signed -- -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"bootloader/mcuboot/root-rsa-2048.pem\"

-- west build: generating a build system

Including boilerplate (Zephyr base): /home/antonio/ncs/zephyr/cmake/app/boilerplate.cmake

-- Application: /home/antonio/ncs/zephyr/samples/hello_world

-- Zephyr version: 2.3.0-rc1 (/home/antonio/ncs/zephyr)

-- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.5") found components: Interpreter

-- Board: nrf52dk_nrf52832

-- Found west: /home/antonio/.local/bin/west (found suitable version "0.8.0", minimum required is "0.7.1")

-- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")

-- Found toolchain: gnuarmemb (/opt/gnuarmemb)

-- Found BOARD.dts: /home/antonio/ncs/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts

-- Generated zephyr.dts: /home/antonio/ncs/build-hello-signed/zephyr/zephyr.dts

-- Generated devicetree_unfixed.h: /home/antonio/ncs/build-hello-signed/zephyr/include/generated/devicetree_unfixed.h

Parsing /home/antonio/ncs/zephyr/Kconfig

Loaded configuration '/home/antonio/ncs/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig'

Merged configuration '/home/antonio/ncs/zephyr/samples/hello_world/prj.conf'

Merged configuration '/home/antonio/ncs/build-hello-signed/zephyr/misc/generated/extra_kconfig_options.conf'

/home/antonio/ncs/build-hello-signed/zephyr/misc/generated/extra_kconfig_options.conf:3: warning: attempt to assign the value '"bootloader/mcuboot/root-rsa-2048.pem"' to the undefined symbol MCUBOOT_SIGNATURE_KEY_FILE

error: Aborting due to Kconfig warnings

CMake Error at /home/antonio/ncs/zephyr/cmake/kconfig.cmake:217 (message):

  command failed with return code: 1

Call Stack (most recent call first):

  /home/antonio/ncs/zephyr/cmake/app/boilerplate.cmake:506 (include)

  /home/antonio/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)

  /home/antonio/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)

  CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred!

FATAL ERROR: command exited with status 1: /usr/bin/cmake -B/home/antonio/ncs/build-hello-signed -S/home/antonio/ncs/zephyr/samples/hello_world -GNinja -DBOARD=nrf52dk_nrf52832 -DCONFIG_BOOTLOADER_MCUBOOT=y '-DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"'


The second page is "SMP Server Sample"

Which, again, the build and flash for the mcu_boot works ok

west build -b <board> -d build_mcuboot bootloader/mcuboot/boot/zephyr

west flash -d build_mcuboot

But when you try the sample application…

west build \

   -b nrf52dk_nrf52832 \

   samples/subsys/mgmt/mcumgr/smp_svr \

   -- \

   -DOVERLAY_CONFIG=overlay-bt.conf

Works ok if you change your directory to zephyr, or if you alter the command to build fom ./ncs

 

But the signing has an error:

west sign -t imgtool -- --key bootloader/mcuboot/root-rsa-2048.pem

antonio@ubuntu:~/ncs$ west sign -t imgtool -- --key bootloader/mcuboot/root-rsa-2048.pem

=== image configuration:

partition offset: 49152 (0xc000)

partition size: 204800 (0x32000)

text section offset: 0 (0x0)

=== signed binaries:

bin: /home/antonio/ncs/build/zephyr/zephyr.signed.bin

Usage: imgtool sign [OPTIONS] INFILE OUTFILE

Error: Invalid value for "-H" / "--header-size": Minimum value for -H/--header-size is 32

FATAL ERROR: command exited with status 2: /home/antonio/.local/bin/imgtool sign --version 0.0.0+0 --align 4 --header-size 0 --slot-size 204800 --key bootloader/mcuboot/root-rsa-2048.pem /home/antonio/ncs/build/zephyr/zephyr.bin /home/antonio/ncs/build/zephyr/zephyr.signed.bin

Parents
  • Updated request now that v1.4.0 is official

    I am using the just released v1.4.0, the sample which I started with smp_srv, with the board nrf52dk_nrf52832, but since now it does not loads BL automatically, I added to the pro.conf:

    CONFIG_MCUMGR_SMP_BT=y

    CONFIG_MCUMGR_SMP_BT_AUTHEN=n

    This compiles and runs as expected, but does not OTA (as expected) since the new rule is that if no valid key is presented, you have to sign yourself afterwards. If you try to do an OTA, y connects, then you select “Test and verify” with the android app nRF Connect, and it keeps at “Validating” for like a minute, and then disconnects. The logger does not show any error, other that disconnecting…

    If introduce a key, that in my case is:

    CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="~/Documents/tracker_sensor/Tools/psl-rsa-2048.pem"

    The behavior is exactly the same as when I did not include any key.

    And finally, if, as per last instructions, I modify CMakeLists.txt after minimum_required with:

    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf")

      set(mcuboot_CONF_FILE prj.conf ${CMAKE_CURRENT_LIST_DIR}/mcuboot.conf)

    endif()

    And I include such file with:

    CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="~/Documents/tracker_sensor/Tools/psl-rsa-2048.pem"

    Or:

    CONFIG_BOOT_SIGNATURE_KEY_FILE="~/Documents/tracker_sensor/Tools/psl-rsa-2048.pem"

    When I reload the project it responds with the following error:


    CMake Warning at /home/antonio/ncs/zephyr/kernel/CMakeLists.txt:54 (message):

      Single threaded mode (CONFIG_MULTITHREADING=n) is deprecated

    MCUBoot bootloader key file: ~/Documents/tracker_sensor/Tools/psl-rsa-2048.pem

    -- Configuring done

    -- Generating done

    -- Build files have been written to: /home/antonio/Documents/tests/smp_svr/build_nrf52dk_nrf52832/mcuboot

    === child image mcuboot -  end ===

    CMake Error at /home/antonio/ncs/nrf/cmake/mcuboot.cmake:112 (get_filename_component):

      get_filename_component unknown component

      /home/antonio/Documents/tests/smp_svr/mcuboot.conf

    Call Stack (most recent call first):

      /home/antonio/ncs/bootloader/mcuboot/zephyr/CMakeLists.txt:1 (include)

    CMake Warning at /home/antonio/ncs/nrf/cmake/mcuboot.cmake:120 (message):

      

            ---------------------------------------------------------

            --- WARNING: Using default MCUBoot key, it should not ---

            --- be used for production.                           ---

            ---------------------------------------------------------

            

    Call Stack (most recent call first):

      /home/antonio/ncs/bootloader/mcuboot/zephyr/CMakeLists.txt:1 (include)

    CMake Warning at /home/antonio/ncs/nrf/cmake/mcuboot.cmake:303 (message):

      CONFIG_MCUBOOT_SIGNATURE_KEY_FILE is set to

      "~/Documents/tracker_sensor/Tools/psl-rsa-2048.pem".

      You are using the NCS Mcuboot signing, which means this option will be

      ignored.

      Image signing in NCS is done via the MCUboot image's

      CONFIG_BOOT_SIGNATURE_KEY_FILE option.

      Consider setting CONFIG_MCUBOOT_SIGNATURE_KEY_FILE in your application

      image back to its default value, the empty string.

    Call Stack (most recent call first):

      /home/antonio/ncs/bootloader/mcuboot/zephyr/CMakeLists.txt:1 (include)

    -- Configuring incomplete, errors occurred!

    See also "/home/antonio/Documents/tests/smp_svr/build_nrf52dk_nrf52832/CMakeFiles/CMakeOutput.log".

    See also "/home/antonio/Documents/tests/smp_svr/build_nrf52dk_nrf52832/CMakeFiles/CMakeError.log".

    Project load failed

    Reported error: solution load command failed (1)


    Please advise…

  • Hi Antonio,

    There is a bug in NCS 1.4 that causes problems in this case. BOOT_SIGNATURE_KEY_FILE needs to be duplicated in bootloader/mcuboot/zephyr/Kconfig, but that was removed from NCS 1.4. So you should put it back as done in this PR.

  • Hi Einar,

    I tried again with the sample app smp_svr from the v1.4.1-rc1, using the default keys, not even mine, and could not make it work. It would keep reseting, I imagine because it is not accepting the primary image.

    Can you make it work with that sample code in the BLE configuration, flash the first image, create another and OTA it, and send me a step by step of how to do it? 

    Or, if you prefer, copy the smp_svr folder outside ncs, like ~/Documents, make it work in the BLE configuration, flash the first image, create another and OTA it, and attach here the folder? I can just check what you did in the config files.

    At this point I am feeling helpless and I already tried everything.

    Thanks.

  • Hi,

    I am sorry for the delay with this. I do not have a proper way of handling this yet, but the R&D team responsible has it on their list.

    There is a dirty but very simple workaround you can do though, which is to simply replace the path to the default key with the path to your key in ncs/bootloader/mcuboot/boot/zephyr/Kconfig:

    diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig
    index f283e67..8028726 100644
    --- a/boot/zephyr/Kconfig
    +++ b/boot/zephyr/Kconfig
    @@ -153,7 +153,7 @@ config BOOT_SIGNATURE_KEY_FILE
     	default "root-ec-p256.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256
     	default "root-ed25519.pem" if BOOT_SIGNATURE_TYPE_ED25519
     	default "root-rsa-3072.pem" if BOOT_SIGNATURE_TYPE_RSA && BOOT_SIGNATURE_TYPE_RSA_LEN=3072
    -	default "root-rsa-2048.pem" if BOOT_SIGNATURE_TYPE_RSA && BOOT_SIGNATURE_TYPE_RSA_LEN=2048
    +	default "/Users/eith/src/smp_svr_test/test_keyfile.pem" if BOOT_SIGNATURE_TYPE_RSA && BOOT_SIGNATURE_TYPE_RSA_LEN=2048
     	help
     	  You can use either absolute or relative path.
     	  In case relative path is used, the build system assumes that it starts
    

    This is not ideal, but it is a simple workaround that works.

  • Hi Einar,

    My request is more basic right now. I cannot get the smp_svr sample working on the BT configuration not even with the default signature. I have tried 1.4.0, 1.4.1-rc1 and 1.4.99-dev1.

    We already know that the manual west instructions for smp_svr sample do not work for the BT configuration, since they have the header size problem, so I opted for the Segger Studio option by including the CONFIGs from overlay-bt.conf to prj.conf and compiled-flashed, as is, to a nrf52dk_nrf52832 board, and the result in the serial terminal is a continuous re-boot from mcuboot with no error or warning, maybe rejecting the image in slot-0.

    Can you tell me how to make work the smp_svr sample with the BT configuration, as is?

    Thanks!

  • I also am having the exact same issue currently that I program the smp_svr example and no matter what I seem to do, it just continues in the same reboot loop as shown above.  Since I see that it is not just me, I guess I'll go work on something else and monitor this thread. Also I am trying to get this to work on the nrf52840dk_nrf52840 dev board.

  • Hi,

    There is unfortunately an issue with too little stack in the sample. You can fix this by adding CONFIG_MAIN_STACK_SIZE=4096 to prj.conf.

    As a general tip you can often find these problems by testing with CONFIG_DEBUG=y (though in this case that would not work on the nRF52832 without removing a few things, as the app would be too large to fit in flash).

Reply Children
Related