mcuboot with custom key

Hi,

I have the exact problem in this issue: https://devzone.nordicsemi.com/f/nordic-q-a/60609/problem-with-mcuboot

NCS version: 1.9

Board: nrf52840dk_nrf52840

The output:

-- Configuring incomplete, errors occurred!
CMake Error at <ncs_root>/nrf/cmake/multi_image.cmake:409 (message):
  CMake generation for mcuboot failed, aborting.  Command: 1
Call Stack (most recent call first):
  <ncs_root>/nrf/cmake/multi_image.cmake:150 (add_child_image_from_source)
  <ncs_root>/nrf/modules/mcuboot/CMakeLists.txt:216 (add_child_image)


-- Configuring incomplete, errors occurred!
See also "<replaced_prj_source>/d2mul_bootloader/build/CMakeFiles/CMakeOutput.log".
See also "<replaced_prj_source>/d2mul_bootloader/build/CMakeFiles/CMakeError.log".
FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/home/ozan/.pyenv/versions/3.6.8/bin/python3 -B<replaced_prj_source>/d2mul_bootloader/build -S<replaced_prj_source>/d2mul_bootloader -GNinja -DBOARD=nrf52840dk_nrf52840 -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING=NONE -DCONF_FILE:STRING=<replaced_prj_source>/d2mul_bootloader/prj.conf -Dmcuboot_OVERLAY_CONFIG=mcuboot.conf

There are different suggestions in the accepted solution:

"Try to delete the build folder in ncs\mcuboot\boot\zephyr"  -> didn't work

"git clean -fxd in ncs\mcuboot" -> didn't work

"try to clean your "/home/voja/.cache/zephyr" folder." -> didn't work

Any other suggestions are highly welcome.

Many thanks,

Ozan

Parents
  • Hi Vidar,

    I've just noticed that I can use "child_image/mcuboot" folder for the purpose as you mentioned in your reply. I thought providing "-Dmcuboot_CONF_FILE=mcuboot_prj.conf" would suffice but it is not. I learnt something new, thanks for that.

    Here is the full log for the record (successful compile):

    $ west build --pristine -b nrf52840dk_nrf52840
    -- west build: making build dir /home/ozan/projects/tmp/smp_svr_t1/build pristine
    -- west build: generating a build system
    Including boilerplate (Zephyr base): /home/ozan/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    -- Application: /home/ozan/projects/tmp/smp_svr_t1
    -- Zephyr version: 2.7.99 (/home/ozan/projects/ncs/zephyr), build: v2.7.99-ncs1
    -- Found Python3: /home/ozan/.pyenv/versions/3.6.8/bin/python3.6 (found suitable exact version "3.6.8") found components: Interpreter 
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Cache files will be written to: /home/ozan/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major)
    -- Found BOARD.dts: /home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Generated zephyr.dts: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/dts.cmake
    Parsing /home/ozan/projects/ncs/zephyr/Kconfig
    Loaded configuration '/home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration '/home/ozan/projects/tmp/smp_svr_t1/prj.conf'
    Configuration saved to '/home/ozan/projects/tmp/smp_svr_t1/build/zephyr/.config'
    Kconfig header saved to '/home/ozan/projects/tmp/smp_svr_t1/build/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 9.2.1
    -- The CXX compiler identification is GNU 9.2.1
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc
    
    === child image mcuboot -  begin ===
    loading initial cache file /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/child_image_preload.cmake
    Including boilerplate (Zephyr base): /home/ozan/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    -- Application: /home/ozan/projects/ncs/bootloader/mcuboot/boot/zephyr
    -- Zephyr version: 2.7.99 (/home/ozan/projects/ncs/zephyr), build: v2.7.99-ncs1
    -- Found Python3: /home/ozan/.pyenv/shims/python3.6 (found suitable exact version "3.6.8") found components: Interpreter 
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Cache files will be written to: /home/ozan/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major)
    -- Found BOARD.dts: /home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: /home/ozan/projects/ncs/nrf/modules/mcuboot/usb.overlay
    -- Found devicetree overlay: /home/ozan/projects/ncs/bootloader/mcuboot/boot/zephyr/dts.overlay
    -- Generated zephyr.dts: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/dts.cmake
    Parsing /home/ozan/projects/ncs/bootloader/mcuboot/boot/zephyr/Kconfig
    Loaded configuration '/home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration '/home/ozan/projects/tmp/smp_svr_t1/child_image/mcuboot/prj.conf'
    Merged configuration '/home/ozan/projects/ncs/nrf/subsys/partition_manager/partition_manager_enabled.conf'
    Merged configuration '/home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/misc/generated/extra_kconfig_options.conf'
    Configuration saved to '/home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/.config'
    Kconfig header saved to '/home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 9.2.1
    -- The CXX compiler identification is GNU 9.2.1
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc
    CMake Warning at /home/ozan/projects/ncs/nrf/lib/flash_patch/CMakeLists.txt:9 (message):
      
    
            ----------------------------------------------------------
            --- WARNING: To maintain the integrity of secure boot, ---
            --- enable CONFIG_DISABLE_FLASH_PATCH in production.   ---
            ----------------------------------------------------------
    
    
    MCUBoot bootloader key file: /home/ozan/projects/tmp/smp_svr_t1/child_image/mcuboot/mcuboot_private.pem
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot
    === child image mcuboot -  end ===
    
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/ozan/projects/tmp/smp_svr_t1/build
    -- west build: building application
    [1/226] Preparing syscall dependency handling
    
    [7/226] Performing build step for 'mcuboot_subimage'
    [1/247] Preparing syscall dependency handling
    
    [237/247] Linking C executable zephyr/zephyr_pre0.elf
    
    [241/247] Linking C executable zephyr/zephyr_pre1.elf
    
    [247/247] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       21200 B        24 KB     86.26%
                SRAM:       23456 B       256 KB      8.95%
            IDT_LIST:          0 GB         2 KB      0.00%
    [205/226] Linking C executable zephyr/zephyr_pre0.elf
    
    [209/226] Linking C executable zephyr/zephyr_pre1.elf
    
    [218/226] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       44468 B     511488 B      8.69%
                SRAM:       15904 B       256 KB      6.07%
            IDT_LIST:          0 GB         2 KB      0.00%
    [226/226] Generating zephyr/merged.hex

    And the directory structure after extracting the zip file that you've attached:

    $ tree -I build
    .
    ├── 6011.child_image.zip
    ├── child_image
    │   └── mcuboot
    │       ├── mcuboot_private.pem
    │       └── prj.conf
    ├── CMakeLists.txt
    ├── overlay-bt.conf
    ├── overlay-bt-tiny.conf
    ├── overlay-cdc.conf
    ├── overlay-fs.conf
    ├── overlay-serial.conf
    ├── overlay-serial-console.conf
    ├── overlay-shell.conf
    ├── overlay-shell-mgmt.conf
    ├── overlay-udp.conf
    ├── prj.conf
    ├── README.rst
    ├── sample.yaml
    ├── src
    │   ├── bluetooth.c
    │   ├── common.h
    │   ├── main.c
    │   └── udp.c
    └── usb.overlay

    Related doc: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_multi_image.html

    I hope this helps to others who faces a similar problem.

    Many thanks.

    Ozan

Reply
  • Hi Vidar,

    I've just noticed that I can use "child_image/mcuboot" folder for the purpose as you mentioned in your reply. I thought providing "-Dmcuboot_CONF_FILE=mcuboot_prj.conf" would suffice but it is not. I learnt something new, thanks for that.

    Here is the full log for the record (successful compile):

    $ west build --pristine -b nrf52840dk_nrf52840
    -- west build: making build dir /home/ozan/projects/tmp/smp_svr_t1/build pristine
    -- west build: generating a build system
    Including boilerplate (Zephyr base): /home/ozan/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    -- Application: /home/ozan/projects/tmp/smp_svr_t1
    -- Zephyr version: 2.7.99 (/home/ozan/projects/ncs/zephyr), build: v2.7.99-ncs1
    -- Found Python3: /home/ozan/.pyenv/versions/3.6.8/bin/python3.6 (found suitable exact version "3.6.8") found components: Interpreter 
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Cache files will be written to: /home/ozan/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major)
    -- Found BOARD.dts: /home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Generated zephyr.dts: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: /home/ozan/projects/tmp/smp_svr_t1/build/zephyr/dts.cmake
    Parsing /home/ozan/projects/ncs/zephyr/Kconfig
    Loaded configuration '/home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration '/home/ozan/projects/tmp/smp_svr_t1/prj.conf'
    Configuration saved to '/home/ozan/projects/tmp/smp_svr_t1/build/zephyr/.config'
    Kconfig header saved to '/home/ozan/projects/tmp/smp_svr_t1/build/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 9.2.1
    -- The CXX compiler identification is GNU 9.2.1
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc
    
    === child image mcuboot -  begin ===
    loading initial cache file /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/child_image_preload.cmake
    Including boilerplate (Zephyr base): /home/ozan/projects/ncs/zephyr/cmake/app/boilerplate.cmake
    -- Application: /home/ozan/projects/ncs/bootloader/mcuboot/boot/zephyr
    -- Zephyr version: 2.7.99 (/home/ozan/projects/ncs/zephyr), build: v2.7.99-ncs1
    -- Found Python3: /home/ozan/.pyenv/shims/python3.6 (found suitable exact version "3.6.8") found components: Interpreter 
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Cache files will be written to: /home/ozan/.cache/zephyr
    -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major)
    -- Found BOARD.dts: /home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: /home/ozan/projects/ncs/nrf/modules/mcuboot/usb.overlay
    -- Found devicetree overlay: /home/ozan/projects/ncs/bootloader/mcuboot/boot/zephyr/dts.overlay
    -- Generated zephyr.dts: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/dts.cmake
    Parsing /home/ozan/projects/ncs/bootloader/mcuboot/boot/zephyr/Kconfig
    Loaded configuration '/home/ozan/projects/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration '/home/ozan/projects/tmp/smp_svr_t1/child_image/mcuboot/prj.conf'
    Merged configuration '/home/ozan/projects/ncs/nrf/subsys/partition_manager/partition_manager_enabled.conf'
    Merged configuration '/home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/misc/generated/extra_kconfig_options.conf'
    Configuration saved to '/home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/.config'
    Kconfig header saved to '/home/ozan/projects/tmp/smp_svr_t1/build/mcuboot/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 9.2.1
    -- The CXX compiler identification is GNU 9.2.1
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/ozan/Downloads/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc
    CMake Warning at /home/ozan/projects/ncs/nrf/lib/flash_patch/CMakeLists.txt:9 (message):
      
    
            ----------------------------------------------------------
            --- WARNING: To maintain the integrity of secure boot, ---
            --- enable CONFIG_DISABLE_FLASH_PATCH in production.   ---
            ----------------------------------------------------------
    
    
    MCUBoot bootloader key file: /home/ozan/projects/tmp/smp_svr_t1/child_image/mcuboot/mcuboot_private.pem
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/ozan/projects/tmp/smp_svr_t1/build/mcuboot
    === child image mcuboot -  end ===
    
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/ozan/projects/tmp/smp_svr_t1/build
    -- west build: building application
    [1/226] Preparing syscall dependency handling
    
    [7/226] Performing build step for 'mcuboot_subimage'
    [1/247] Preparing syscall dependency handling
    
    [237/247] Linking C executable zephyr/zephyr_pre0.elf
    
    [241/247] Linking C executable zephyr/zephyr_pre1.elf
    
    [247/247] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       21200 B        24 KB     86.26%
                SRAM:       23456 B       256 KB      8.95%
            IDT_LIST:          0 GB         2 KB      0.00%
    [205/226] Linking C executable zephyr/zephyr_pre0.elf
    
    [209/226] Linking C executable zephyr/zephyr_pre1.elf
    
    [218/226] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       44468 B     511488 B      8.69%
                SRAM:       15904 B       256 KB      6.07%
            IDT_LIST:          0 GB         2 KB      0.00%
    [226/226] Generating zephyr/merged.hex

    And the directory structure after extracting the zip file that you've attached:

    $ tree -I build
    .
    ├── 6011.child_image.zip
    ├── child_image
    │   └── mcuboot
    │       ├── mcuboot_private.pem
    │       └── prj.conf
    ├── CMakeLists.txt
    ├── overlay-bt.conf
    ├── overlay-bt-tiny.conf
    ├── overlay-cdc.conf
    ├── overlay-fs.conf
    ├── overlay-serial.conf
    ├── overlay-serial-console.conf
    ├── overlay-shell.conf
    ├── overlay-shell-mgmt.conf
    ├── overlay-udp.conf
    ├── prj.conf
    ├── README.rst
    ├── sample.yaml
    ├── src
    │   ├── bluetooth.c
    │   ├── common.h
    │   ├── main.c
    │   └── udp.c
    └── usb.overlay

    Related doc: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_multi_image.html

    I hope this helps to others who faces a similar problem.

    Many thanks.

    Ozan

Children
  • Hi Ozan,

    Thank you for the update. The difference between these two approaches is that "-Dmcuboot_CONF_FILE=mcuboot_prj.conf" (kconfig fragment) will cause the mcuboot_prj.conf symbols to become merged with the default prj.conf file in /ncs/bootloader/mcuboot/boot/zephyr/prj.conf rather than replacing it like the child_image->mcuboot->prj.conf file does.

    From the multi-image build chapter you linked to above:

    Both methods should work, but it's important you include the absolute path to your key file when merging the CONFIG_BOOT_SIGNATURE_KEY_FILE symbol with /ncs/bootloader/mcuboot/boot/zephyr/prj.conf. Otherwise, the build system will fail to locate your key.

    Best regards,

    Vidar

Related