@@ -9,133 +9,6 @@ external tool. In some configurations, ``west sign`` is also used to invoke
99an external, post-processing tool that "stitches" the final components of
1010the image together. Run ``west sign -h `` for command line help.
1111
12- MCUboot / imgtool
13- *****************
14-
15- The Zephyr build system has special support for signing binaries for use with
16- the `MCUboot `_ bootloader using the `imgtool `_ program provided by its
17- developers. You can both build and sign this type of application binary in one
18- step by setting some Kconfig options. If you do, ``west flash `` will use the
19- signed binaries.
20-
21- If you use this feature, you don't need to run ``west sign `` yourself; the
22- build system will do it for you.
23-
24- Here is an example workflow, which builds and flashes MCUboot, as well as the
25- :zephyr:code-sample: `hello_world ` application for chain-loading by MCUboot. Run these commands
26- from the :file: `zephyrproject ` workspace you created in the
27- :ref: `getting_started `.
28-
29- .. code-block :: console
30-
31- west build -b YOUR_BOARD bootloader/mcuboot/boot/zephyr -d build-mcuboot
32- west build -b YOUR_BOARD zephyr/samples/hello_world -d build-hello-signed -- \
33- -DCONFIG_BOOTLOADER_MCUBOOT=y \
34- -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"bootloader/mcuboot/root-rsa-2048.pem\"
35-
36- west flash -d build-mcuboot
37- west flash -d build-hello-signed
38-
39- Notes on the above commands:
40-
41- - ``YOUR_BOARD `` should be changed to match your board
42- - The ``CONFIG_MCUBOOT_SIGNATURE_KEY_FILE `` value is the insecure default
43- provided and used by MCUboot for development and testing
44- - You can change the ``hello_world `` application directory to any other
45- application that can be loaded by MCUboot, such as the :zephyr:code-sample: `smp-svr ` sample.
46-
47- For more information on these and other related configuration options, see:
48-
49- - :kconfig:option: `CONFIG_BOOTLOADER_MCUBOOT `: build the application for loading by
50- MCUboot
51- - :kconfig:option: `CONFIG_MCUBOOT_SIGNATURE_KEY_FILE `: the key file to use with ``west
52- sign ``. If you have your own key, change this appropriately
53- - :kconfig:option: `CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS `: optional additional command line
54- arguments for ``imgtool ``
55- - :kconfig:option: `CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE `: also generate a confirmed
56- image, which may be more useful for flashing in production environments than
57- the OTA-able default image
58- - On Windows, if you get "Access denied" issues, the recommended fix is
59- to run ``pip3 install imgtool ``, then retry with a pristine build directory.
60-
61- If your ``west flash `` :ref: `runner <west-runner >` uses an image format
62- supported by imgtool, you should see something like this on your device's
63- serial console when you run ``west flash -d build-mcuboot ``:
64-
65- .. code-block :: none
66-
67- *** Booting Zephyr OS build zephyr-v2.3.0-2310-gcebac69c8ae1 ***
68- [00:00:00.004,669] <inf> mcuboot: Starting bootloader
69- [00:00:00.011,169] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
70- [00:00:00.021,636] <inf> mcuboot: Boot source: none
71- [00:00:00.027,313] <wrn> mcuboot: Failed reading image headers; Image=0
72- [00:00:00.035,064] <err> mcuboot: Unable to find bootable image
73-
74- Then, you should see something like this when you run ``west flash -d
75- build-hello-signed ``:
76-
77- .. code-block :: none
78-
79- *** Booting Zephyr OS build zephyr-v2.3.0-2310-gcebac69c8ae1 ***
80- [00:00:00.004,669] <inf> mcuboot: Starting bootloader
81- [00:00:00.011,169] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
82- [00:00:00.021,636] <inf> mcuboot: Boot source: none
83- [00:00:00.027,374] <inf> mcuboot: Swap type: none
84- [00:00:00.115,142] <inf> mcuboot: Bootloader chainload address offset: 0xc000
85- [00:00:00.123,168] <inf> mcuboot: Jumping to the first image slot
86- *** Booting Zephyr OS build zephyr-v2.3.0-2310-gcebac69c8ae1 ***
87- Hello World! nrf52840dk_nrf52840
88-
89- Whether ``west flash `` supports this feature depends on your runner. The
90- ``nrfjprog `` and ``pyocd `` runners work with the above flow. If your runner
91- does not support this flow and you would like it to, please send a patch or
92- file an issue for adding support.
93-
94- .. _west-extending-signing :
95-
96- Extending signing externally
97- ****************************
98-
99- The signing script used when running ``west flash `` can be extended or replaced
100- to change features or introduce different signing mechanisms. By default with
101- MCUboot enabled, signing is setup by the :file: `cmake/mcuboot.cmake ` file in
102- Zephyr which adds extra post build commands for generating the signed images.
103- The file used for signing can be replaced from a sysbuild scope (if being used)
104- or from a zephyr/zephyr module scope, the priority of which is:
105-
106- * Sysbuild
107- * Zephyr property
108- * Default MCUboot script (if enabled)
109-
110- From sysbuild, ``-D<target>_SIGNING_SCRIPT `` can be used to set a signing script
111- for a specific image or ``-DSIGNING_SCRIPT `` can be used to set a signing script
112- for all images, for example:
113-
114- .. code-block :: console
115-
116- west build -b <board> <application> -DSIGNING_SCRIPT=<file>
117-
118- The zephyr property method is achieved by adjusting the ``SIGNING_SCRIPT `` property
119- on the ``zephyr_property_target ``, ideally from by a module by using:
120-
121- .. code-block :: cmake
122-
123- if(CONFIG_BOOTLOADER_MCUBOOT)
124- set_target_properties(zephyr_property_target PROPERTIES SIGNING_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/custom_signing.cmake)
125- endif()
126-
127- This will include the custom signing CMake file instead of the default Zephyr
128- one when projects are built with MCUboot signing support enabled. The base
129- Zephyr MCUboot signing file can be used as a reference for creating a new
130- signing system or extending the default behaviour.
131-
132- .. _MCUboot :
133- https://mcuboot.com/
134-
135- .. _imgtool :
136- https://pypi.org/project/imgtool/
137-
138-
13912rimage
14013******
14114
0 commit comments