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

west build fails when trying to sign MCUboot application

I have a custom MCUboot boot loader working.  Now I'm trying to build an application to be updated by MCUboot.  I've added the following to prj.conf:

CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/<my full path>/root-rsa-2048.pem"

When I try to build the application, it compiles, but then there is a signing error:

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

Any idea why this would be happening?

If I try to sign manually with:

$ west --verbose sign -t imgtool -- --key /<my full path>/root-rsa-2048.pem -H 32

Then I get a different error:

west --verbose sign -t imgtool -- --key ~/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/app_bootloader/root-rsa-2048.pem -H 32

Should NCS be padding with zeros for the header?  And how much padding does NCS use?  Where is this configured?

Full output of west build:

$ west build --pristine

-- west build: making build dir /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build pristine

WARNING: This looks like a fresh build and BOARD is unknown; so it probably won't work. To fix, use --board=<your-board>.

Note: to silence the above message, run 'west config build.board_warn false'

-- west build: generating a build system

Including boilerplate (Zephyr base): /Users/denis/sandbox/itamar/workspace/zephyr/cmake/app/boilerplate.cmake

CMake Warning at /Users/denis/sandbox/itamar/workspace/zephyr/cmake/app/boilerplate.cmake:76 (message):

  CMake 3.19.0/3.19.1 contains a bug regarding Toolchain/compiler testing.

  Consider switching to a different CMake version.

  See more here:

  - github.com/.../30232

  - gitlab.kitware.com/.../21497

Call Stack (most recent call first):

  /Users/denis/sandbox/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)

  /Users/denis/sandbox/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)

  CMakeLists.txt:6 (find_package)

-- Application: /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello

-- Zephyr version: 2.4.99 (/Users/denis/sandbox/itamar/workspace/zephyr)

-- Found Python3: /usr/local/opt/[email protected]/bin/python3.8 (found suitable exact version "3.8.7") found components: Interpreter 

-- Found west (found suitable version "0.9.0", minimum required is "0.7.1")

-- Board: nrf5340dk_nrf5340_cpuapp

-- Cache files will be written to: /Users/denis/Library/Caches/zephyr

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

-- Found toolchain: gnuarmemb (/Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major)

-- Found BOARD.dts: /Users/denis/sandbox/itamar/workspace/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts

-- Found devicetree overlay: ../../../dts/nrf5340dk_nrf5340_cpuapp.overlay

nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:61.42-73.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@50000000/flash-controller@39000: duplicate unit-address (also used in node /soc/peripheral@50000000/kmu@39000)

nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:348.19-354.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@50000000/clock@5000: duplicate unit-address (also used in node /soc/peripheral@50000000/power@5000)

nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:631.31-632.5: Warning (unique_unit_address_if_enabled): /reserved-memory/image@20000000: duplicate unit-address (also used in node /reserved-memory/image_s@20000000)

  also defined at nrf5340dk_nrf5340_cpuapp.dts.pre.tmp:651.14-653.3

warning: unit address and first address in 'reg' (0x40000) don't match for /soc/peripheral@50000000/flash-controller@39000/flash@0/partitions/partition@10000

-- Generated zephyr.dts: /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/zephyr.dts

-- Generated devicetree_unfixed.h: /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/include/generated/devicetree_unfixed.h

-- Generated device_extern.h: /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/include/generated/device_extern.h

Parsing /Users/denis/sandbox/itamar/workspace/zephyr/Kconfig

Loaded configuration '/Users/denis/sandbox/itamar/workspace/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'

Merged configuration '/Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/prj.conf'

Configuration saved to '/Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/.config'

Kconfig header saved to '/Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/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: /Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc

CMake Deprecation Warning at /Users/denis/sandbox/itamar/workspace/modules/lib/civetweb/CMakeLists.txt:2 (cmake_minimum_required):

  Compatibility with CMake < 2.8.12 will be removed from a future version of

  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell

  CMake that the project does not need compatibility with older versions.

CMake Warning at /Users/denis/sandbox/itamar/workspace/zephyr/CMakeLists.txt:1357 (message):

  __ASSERT() statements are globally ENABLED

-- Configuring done

-- Generating done

-- Build files have been written to: /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build

-- west build: building application

[1/141] Preparing syscall dependency handling

[136/141] Linking C executable zephyr/zephyr_prebuilt.elf

Memory region         Used Size  Region Size  %age Used

           FLASH:       99444 B       704 KB     13.79%

            SRAM:        8936 B       448 KB      1.95%

        IDT_LIST:          72 B         2 KB      3.52%

[141/141] Linking C executable zephyr/zephyr.elf

FAILED: zephyr/zephyr.elf zephyr/zephyr.hex zephyr/zephyr.bin zephyr/zephyr.lst zephyr/zephyr.stat zephyr/zephyr.signed.bin zephyr/zephyr.signed.hex 

: && ccache /Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc   zephyr/CMakeFiles/zephyr_final.dir/misc/empty_file.c.obj zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj -o zephyr/zephyr.elf  -Wl,-T  zephyr/linker_pass_final.cmd  -Wl,-Map=/Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/zephyr_final.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/mpu/libarch__arm__core__aarch32__cortex_m__mpu.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.a  zephyr/lib/libc/newlib/liblib__libc__newlib.a  zephyr/lib/posix/liblib__posix.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/serial/libdrivers__serial.a  modules/nrf/lib/dk_buttons_and_leds/lib..__nrf__lib__dk_buttons_and_leds.a  modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a  modules/hal_nordic/libmodules__hal_nordic.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -L"/Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v8-m.main/nofp"  -L/Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  /Users/denis/sandbox/itamar/workspace/nrfxlib/crypto/nrf_cc312_platform/lib/cortex-m33/soft-float/no-interrupts/libnrf_cc312_platform_0.9.7.a  -mcpu=cortex-m33  -mthumb  -mabi=aapcs  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -no-pie  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -lm  -Wl,-lc  -L"/Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/arm-none-eabi"/lib/thumb/v8-m.main/nofp  -u_printf_float  -Wl,-lgcc  -lc  -specs=nano.specs && cd /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr && /usr/local/Cellar/cmake/3.19.1/bin/cmake -E rename zephyr_final.map zephyr.map && /Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-objcopy --gap-fill 0xff --output-target=ihex --remove-section=.comment --remove-section=COMMON --remove-section=.eh_frame zephyr.elf zephyr.hex && /Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-objcopy --gap-fill 0xff --output-target=binary --remove-section=.comment --remove-section=COMMON --remove-section=.eh_frame zephyr.elf zephyr.bin && /Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-objdump -d -S zephyr.elf > zephyr.lst && /Users/denis/sandbox/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-readelf -e zephyr.elf > zephyr.stat && /usr/local/opt/[email protected]/bin/python3.8 -m west sign --quiet --tool imgtool --tool-path /usr/local/bin/imgtool --build-dir /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build --bin --sbin /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/zephyr.signed.bin --hex --shex /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/zephyr.signed.hex -- --key /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/app_bootloader/root-rsa-2048.pem

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: /usr/local/bin/imgtool sign --version 0.0.0+0 --align 4 --header-size 0 --slot-size 720896 --key /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/app_bootloader/root-rsa-2048.pem /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/zephyr.bin /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build/zephyr/zephyr.signed.bin

ninja: build stopped: subcommand failed.

FATAL ERROR: command exited with status 1: /usr/local/bin/cmake --build /Users/denis/sandbox/itamar/workspace/itamar/foundation/samples/bootloader/hello/build

Related