Signing image and CONFIG_ROM_START_OFFSET parameter.

Im working with nrf52840DK and nrf Connect SDK 2.2.0. 

My goal is running this sample. (SMP server sample). Let's check the described steps:

1º) I have installed the MCUMGR CLI

2º) I have built and flashed the MCUBoot

3º) I have built the sample application with the next command:

west build -b nrf52840dk_nrf52840 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DOVERLAY_CONFIG='overlay-serial.conf;overlay-fs.conf;overlay-shell-mgmt.conf'

4º) This step is where I got stucked... Trying to signing the image. When I run the next command:

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

I get the next prompt:

D:\ncs\v2.2.0>west sign -t imgtool -- --key bootloader/mcuboot/root-rsa-2048.pem
=== image configuration:
partition offset: 49152 (0xc000)
partition size: 421888 (0x67000)
rom start offset: 0 (0x0)
=== signing binaries
unsigned bin: D:\ncs\v2.2.0\build\zephyr\zephyr.bin
signed bin:   D:\ncs\v2.2.0\build\zephyr\zephyr.signed.bin
Usage: python -m imgtool sign [OPTIONS] INFILE OUTFILE
Try 'python -m imgtool sign -h' for help.

Error: Invalid value for '-H' / '--header-size': Minimum value for -H/--header-size is 32
FATAL ERROR: command exited with status 2: 'C:\Users\juan.martinez\AppData\Local\Programs\Python\Python38\Scripts\imgtool.EXE' sign --version 0.0.0+0 --align 4 --header-size 0 --slot-size 421888 --key bootloader/mcuboot/root-rsa-2048.pem 'D:\ncs\v2.2.0\build\zephyr\zephyr.bin' 'D:\ncs\v2.2.0\build\zephyr\zephyr.signed.bin'

I noticed the --header-size is 0 and it should be (the prompt says it) minimun 32... What is the exactly minimun value for it? How can I change it?

Parents
  • Hi Juan, 

    As the log suggested the minimum header size should be 32. 
    Could you please try: 

    west sign -t imgtool -- --key bootloader/mcuboot/root-rsa-2048.pem --header-size 32 --pad-header

    Please note that by default if you build the image that has MCUBoot, the image is signed automatically and you can find the binary that signed and ready for DFU transferring. Please look for app_update.bin in the build folder. You don't have to call west sign to sign the image. You can also change the key if you want by modify the config option. 

    Please see here: developer.nordicsemi.com/.../readme-ncs.html

  • Nice! Now it can be signed correctly and zephyr.signed.bin has been generated and flashed!

    But now appears a new problem, I cant echo nothing:

     

    root@gcu1:~# mcumgr --conntype serial --connstring "/dev/ttyACM0,baud=115200" echo hello
    Error: NMP timeout
    
    root@gcu1:~# mcumgr --conntype serial --connstring "/dev/ttyACM1,baud=115200" echo hello
    Error: NMP timeout
    
    
    

    ACM0 and ACM1 are the ports that appears when I connect the nrf52840DK. I have disables Mass Storage Device.

  • Ok, what test do you suggest?

    PD: I think we wrote at the same time and maybe you didnt notice my previous message to your last reply. =)

  • Have you tried to test with any UART example ? Please use the uart sample in the SDK. 

    Regarding your last question, could you please try confirm instead of test ? 
    Could you check the RTT log when you do confirm / test ? 

    I would suggest to try putting some LED blink in the application so that you know when the new firmware is running you can detect it with the LED (you can change the blink rate for example, or change the LED pin on the new image that you update) 

  • I have tried the sample echo_bot and it's working perfectly, connected via Visual Studio Code in windows.

    I have noticed that there is problems when I echo something with the Serial_DFU_hello_world but SMP server sample works like a charm:

    If I try to confirm, it works correctly:

    root@gcu1:~# mcumgr --conntype serial --connstring "/dev/ttyACM0,baud=115200" image confirm 9c2a99413194f11d9a4e00ff7396854e5dae14220bac5f1786e6a2f73d8fa143
    Images:
     image=0 slot=0
        version: 0.0.0
        bootable: true
        flags: active confirmed
        hash: 8893d1a1fccdb1719a0d937eb9fffdd98d809c3baa3c6dd2f946fab9ebf4dd84
     image=0 slot=1
        version: 0.0.0
        bootable: true
        flags: pending permanent
        hash: 9c2a99413194f11d9a4e00ff7396854e5dae14220bac5f1786e6a2f73d8fa143

    But after the reset, the board doesnt work... I will put the led to blink for detecting the board is working...

    Have I to check the key file to sign the file to update¿? Maybe its not the same than the MCUBoot has?

  • Let's resume this:

    Im trying this example you shared me following the next steps:

    1º) I have created the "serial_dfu_hello_world" project with Visual Studio Code in Windows and modified it like the example shows and adding the LED blinking. I attach the project here. serial_dfu_hello_world.zip

    After it, I have builded and flashed with the next command: (Note that building this I have not selected any overlay, so our last discussion about UART or Shell maybe has no sense)

     

    west build -b nrf52840dk_nrf52840 -p -s D:\nRF52_ot_ble\serial_dfu_hello_world && west flash --erase

    Getting the next prompt:

    D:\ncs\v2.2.0>west build -b nrf52840dk_nrf52840 -p -s D:\nRF52_ot_ble\serial_dfu_hello_world && west flash --erase
    -- west build: making build dir D:\ncs\v2.2.0\build pristine
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: D:/nRF52_ot_ble/serial_dfu_hello_world
    -- Using NCS Toolchain 2.2.0 for building. (D:/ncs/toolchains/v2.2.0/cmake)
    -- Found Python3: D:/ncs/toolchains/v2.2.0/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
    -- Cache files will be written to: D:/ncs/v2.2.0/zephyr/.cache
    -- Zephyr version: 3.2.99 (D:/ncs/v2.2.0/zephyr)
    -- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Found host-tools: zephyr 0.15.1 (D:/ncs/toolchains/v2.2.0/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.15.1 (D:/ncs/toolchains/v2.2.0/opt/zephyr-sdk)
    -- Found Dtc: D:/ncs/toolchains/v2.2.0/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: D:/ncs/v2.2.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Generated zephyr.dts: D:/ncs/v2.2.0/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: D:/ncs/v2.2.0/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: D:/ncs/v2.2.0/build/zephyr/dts.cmake
    Parsing D:/ncs/v2.2.0/zephyr/Kconfig
    Loaded configuration 'D:/ncs/v2.2.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration 'D:/nRF52_ot_ble/serial_dfu_hello_world/prj.conf'
    Configuration saved to 'D:/ncs/v2.2.0/build/zephyr/.config'
    Kconfig header saved to 'D:/ncs/v2.2.0/build/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 12.1.0
    -- The CXX compiler identification is GNU 12.1.0
    -- The ASM compiler identification is GNU
    -- Found assembler: D:/ncs/toolchains/v2.2.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    -- Found Python3: D:/ncs/toolchains/v2.2.0/opt/bin/python.exe (found version "3.8.2") found components: Interpreter
    
    === child image mcuboot -  begin ===
    loading initial cache file D:/ncs/v2.2.0/build/mcuboot/child_image_preload.cmake
    Loading Zephyr default modules (Zephyr base).
    -- Application: D:/ncs/v2.2.0/bootloader/mcuboot/boot/zephyr
    -- Using NCS Toolchain 2.2.0 for building. (D:/ncs/toolchains/v2.2.0/cmake)
    -- Found Python3: D:/ncs/toolchains/v2.2.0/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
    -- Cache files will be written to: D:/ncs/v2.2.0/zephyr/.cache
    -- Zephyr version: 3.2.99 (D:/ncs/v2.2.0/zephyr)
    -- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Found host-tools: zephyr 0.15.1 (D:/ncs/toolchains/v2.2.0/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.15.1 (D:/ncs/toolchains/v2.2.0/opt/zephyr-sdk)
    -- Found Dtc: D:/ncs/toolchains/v2.2.0/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: D:/ncs/v2.2.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: D:/ncs/v2.2.0/nrf/modules/mcuboot/usb.overlay
    -- Found devicetree overlay: D:/ncs/v2.2.0/bootloader/mcuboot/boot/zephyr/dts.overlay
    -- Generated zephyr.dts: D:/ncs/v2.2.0/build/mcuboot/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: D:/ncs/v2.2.0/build/mcuboot/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: D:/ncs/v2.2.0/build/mcuboot/zephyr/dts.cmake
    Parsing D:/ncs/v2.2.0/bootloader/mcuboot/boot/zephyr/Kconfig
    Loaded configuration 'D:/ncs/v2.2.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration 'D:/ncs/v2.2.0/bootloader/mcuboot/boot/zephyr/prj.conf'
    Merged configuration 'D:/ncs/v2.2.0/bootloader/mcuboot/boot/zephyr/boards/nrf52840dk_nrf52840.conf'
    Merged configuration 'D:/ncs/v2.2.0/nrf/subsys/partition_manager/partition_manager_enabled.conf'
    Merged configuration 'D:/ncs/v2.2.0/build/mcuboot/zephyr/misc/generated/extra_kconfig_options.conf'
    Configuration saved to 'D:/ncs/v2.2.0/build/mcuboot/zephyr/.config'
    Kconfig header saved to 'D:/ncs/v2.2.0/build/mcuboot/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 12.1.0
    -- The CXX compiler identification is GNU 12.1.0
    -- The ASM compiler identification is GNU
    -- Found assembler: D:/ncs/toolchains/v2.2.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    CMake Warning at D:/ncs/v2.2.0/nrf/lib/flash_patch/CMakeLists.txt:8 (message):
    
    
            ----------------------------------------------------------
            --- WARNING: To maintain the integrity of secure boot, ---
            --- enable CONFIG_DISABLE_FLASH_PATCH in production.   ---
            ----------------------------------------------------------
    
    
    MCUBoot bootloader key file: D:/ncs/v2.2.0/bootloader/mcuboot/root-ec-p256.pem
    -- Configuring done
    -- Generating done
    -- Build files have been written to: D:/ncs/v2.2.0/build/mcuboot
    === child image mcuboot -  end ===
    
    CMake Warning at D:/ncs/v2.2.0/nrf/modules/mcuboot/CMakeLists.txt:286 (message):
    
    
              ---------------------------------------------------------
              --- WARNING: Using default MCUBoot key, it should not ---
              --- be used for production.                           ---
              ---------------------------------------------------------
    
    
    
    
    -- Configuring done
    -- Generating done
    -- Build files have been written to: D:/ncs/v2.2.0/build
    -- west build: building application
    [2/222] Generating include/generated/version.h
    -- Zephyr version: 3.2.99 (D:/ncs/v2.2.0/zephyr), build: v3.2.99-ncs1
    [6/222] Performing build step for 'mcuboot_subimage'
    [1/188] Generating include/generated/version.h
    -- Zephyr version: 3.2.99 (D:/ncs/v2.2.0/zephyr), build: v3.2.99-ncs1
    [178/188] Linking C executable zephyr\zephyr_pre0.elf
    
    [182/188] Linking C executable zephyr\zephyr_pre1.elf
    
    [188/188] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       33676 B        48 KB     68.51%
                 RAM:       17792 B       256 KB      6.79%
            IDT_LIST:          0 GB         2 KB      0.00%
    [201/222] Linking C executable zephyr\zephyr_pre0.elf
    
    [205/222] Linking C executable zephyr\zephyr_pre1.elf
    
    [214/222] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       43044 B     499200 B      8.62%
                 RAM:       17264 B       256 KB      6.59%
            IDT_LIST:          0 GB         2 KB      0.00%
    [217/222] Generating ../../zephyr/app_update.bin
    sign the payload
    [218/222] Generating ../../zephyr/app_signed.hex
    sign the payload
    [220/222] Generating ../../zephyr/app_test_update.hex
    sign the payload
    [222/222] Generating zephyr/merged.hex
    -- west flash: rebuilding
    [0/4] Performing build step for 'mcuboot_subimage'
    ninja: no work to do.
    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: mass erase requested
    Using board 1050291266
    -- runners.nrfjprog: Flashing file: D:\ncs\v2.2.0\build\zephyr\merged.hex
    Parsing image file.
    Verifying programming.
    Verified OK.
    Enabling pin reset.
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 1050291266 flashed successfully.

    So I tried to connect to my board with RTT in my windows and I get the correct message printed WHILE I see the led is blinking correctly.

    My next step was connecting the board to my RaspberryPi, where I tried to echo something with no results:

    root@gcu1:~# mcumgr --conntype serial --connstring "/dev/ttyACM0,baud=115200" echo hello
    Error: NMP timeout
    root@gcu1:~# mcumgr --conntype serial --connstring "/dev/ttyACM0,baud=115200" echo hello
    Error: NMP timeout
    root@gcu1:~# mcumgr --conntype serial --connstring "/dev/ttyACM0,baud=115200" echo hello
    Error: NMP timeout
    root@gcu1:~#

    But I can see the led is blinking. RTT is not printing nothing...

  • Ok, solved the problem. 

    I have to upload the app_update.bin and not the image.signed.bin, now its updating correctly.

    The problem of lack of communication persists, When I type "mcumgr [..args..]" usually I receive  "Error: NMP timeout", but if I push "ctrl+c" and type again, it usually works.

Reply Children
  • Hi Juan, 

    Could you clarify if you can use dfu with serial or you need to use dfu with shell to be able to make it work  ? 

    I think it's worth it to verify that UART is working normally. So you should try to test only uart, no DFU to be sure that the connection is OK. 

    There isn't a simple UART example in the SDK but you can try to test using the BLE UART example. Please look at the peripheral_uart example. 
    Other example also uses UART for logging that you may want to test. 

Related