blob: ecfd4b442b790acd476b76f82ebd7732c8a64537 [file] [log] [blame]
David Brownada28e12017-07-05 13:36:37 -06001###########################################################################
2# Sample multi-part application Makefile
3#
4# Copyright (c) 2017 Linaro Limited
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17###########################################################################
18
19# This is an example Makefile to demonstrate how to use mcuboot to
20# deploy and upgrade images. The image building should work on any
21# supported target, however flashing will likely require changes to
22# the flash addresses, depending on the partition layout of the device
23# in question.
24#
25# running
Marti Bolivar71354102017-08-01 15:09:44 -040026#
David Brownada28e12017-07-05 13:36:37 -060027# make BOARD=frdm_k64f all
28#
29# should generate three "*.bin" files in this directory:
30#
31# mcuboot.bin: The bootloader itself
32# signed-hello1.bin: A signed sample.
33# signed-hello2.bin: An upgrade image, signed and marked for
34# upgrade.
35#
36# "make flash_boot" should flash the bootloader into the flash,
37# erasing the rest of the device. If you examine the device at this
38# time, you should see a message about the bootloader not being able
39# to find a bootable image.
40#
41# "make flash_hello1" will then flash the first application into
42# "slot0". This should boot into this app, print a small message, and
43# give the zephyr console.
44#
45# "make flash_hello2" will flash hello2 into the second slot. The
46# reset should upgrade and run the new image. Resetting again should
47# then revert back to the first app, since we did not mark this image
48# as good.
49
50BOARD ?=
51
David Brown1d3f67d2017-09-14 15:10:24 -060052# We can override the Zephyr configuration for the bootloader by
53# setting this.
54BOOTLOADER_CONFIG ?=
55
David Brownada28e12017-07-05 13:36:37 -060056.PHONY: check boot hello1 clean_boot clean_hello1 \
57 hello2 clean_hello2 flash_boot flash_hello1 flash_hello2
58
59# For signing, use the default RSA demo key, to match the default in
60# the mcuboot Makefile.
David Brown1d3f67d2017-09-14 15:10:24 -060061SIGNING_KEY ?= ../../root-rsa-2048.pem
David Brownada28e12017-07-05 13:36:37 -060062
63# The header size should match that in hello1/prj.conf
64# CONFIG_TEXT_SECTION_OFFSET. This value needs to be a power of two
65# that is at least as large as the size of the vector table. The
66# value given here of 0x200 should be sufficient for any supported
67# devices, but it can be made smaller, as long as this value matches
68# that used to build the app.
69BOOT_HEADER_LEN = 0x200
70
71# For upgrades, the signing tool needs to know the device alignment.
72# This requirement will be going away soon.
73FLASH_ALIGNMENT = 8
74
75IMGTOOL = ../../scripts/imgtool.py
David Browndbc57272017-07-17 15:38:54 -060076ASSEMBLE = ../../scripts/assemble.py
David Brownada28e12017-07-05 13:36:37 -060077PYOCD_FLASHTOOL = pyocd-flashtool
78
79help:
80 @echo "make <target> BOARD=<board>"
David Browndbc57272017-07-17 15:38:54 -060081 @echo "<target>: all, boot, hello1, full.bin"
David Brownada28e12017-07-05 13:36:37 -060082 @echo "<board>: frdm_k64f, 96b_carbon, etc."
83
84all: boot hello1 hello2
85
David Browndbc57272017-07-17 15:38:54 -060086full.bin: boot hello1 hello2
87 $(ASSEMBLE) -b ../../outdir/$(BOARD) \
88 -p signed-hello1.bin \
89 -s signed-hello2.bin \
90 -o full.bin
91
David Brownada28e12017-07-05 13:36:37 -060092clean: clean_boot clean_hello1 clean_hello2
93 @rm -f signed-hello1.bin
94 @rm -f signed-hello2.bin
95 @rm -f mcuboot.bin
96
97boot: check
98 @rm -f mcuboot.bin
David Brown1d3f67d2017-09-14 15:10:24 -060099 $(MAKE) -C ../.. BOARD=$(BOARD) -j$(nproc) $(BOOTLOADER_CONFIG)
David Brownada28e12017-07-05 13:36:37 -0600100 cp ../../outdir/$(BOARD)/zephyr.bin mcuboot.bin
101
102clean_boot: check
103 rm -rf ../../outdir/$(BOARD)
104
105# Build and sign "hello1".
106hello1: check
Marti Bolivarb9f5a682017-08-01 15:41:05 -0400107 $(MAKE) -C hello-world FROM_WHO="hello1" O=outdir/hello1/$(BOARD) BOARD=$(BOARD) -j$(nproc)
David Brownada28e12017-07-05 13:36:37 -0600108 $(IMGTOOL) sign \
109 --key $(SIGNING_KEY) \
110 --header-size $(BOOT_HEADER_LEN) \
111 --align $(FLASH_ALIGNMENT) \
112 --version 1.2 \
113 --included-header \
Marti Bolivarb9f5a682017-08-01 15:41:05 -0400114 hello-world/outdir/hello1/$(BOARD)/zephyr.bin \
David Brownada28e12017-07-05 13:36:37 -0600115 signed-hello1.bin
116
117clean_hello1: check
Marti Bolivarb9f5a682017-08-01 15:41:05 -0400118 rm -rf hello-world/outdir/hello1/$(BOARD)
David Brownada28e12017-07-05 13:36:37 -0600119
120# Build and sign "hello2".
121# This is the same signing command as above, except that it adds the
122# "--pad" argument. This will also add the trailer that indicates
123# this image is intended to be an upgrade. It should be flashed into
124# slot1 instead of slot0.
125hello2: check
Marti Bolivarb9f5a682017-08-01 15:41:05 -0400126 $(MAKE) -C hello-world FROM_WHO="hello2" O=outdir/hello2/$(BOARD) BOARD=$(BOARD) -j$(nproc)
David Brownada28e12017-07-05 13:36:37 -0600127 $(IMGTOOL) sign \
128 --key $(SIGNING_KEY) \
129 --header-size $(BOOT_HEADER_LEN) \
130 --align $(FLASH_ALIGNMENT) \
131 --version 1.2 \
132 --included-header \
133 --pad 0x60000 \
Marti Bolivarb9f5a682017-08-01 15:41:05 -0400134 hello-world/outdir/hello2/$(BOARD)/zephyr.bin \
David Brownada28e12017-07-05 13:36:37 -0600135 signed-hello2.bin
136
137clean_hello2: check
Marti Bolivarb9f5a682017-08-01 15:41:05 -0400138 rm -rf hello-world/outdir/hello2/$(BOARD)
David Brownada28e12017-07-05 13:36:37 -0600139
David Brown1d3f67d2017-09-14 15:10:24 -0600140# These flash_* targets use pyocd to flash the images. The addresses
141# are hardcoded at this time.
142
David Brownada28e12017-07-05 13:36:37 -0600143flash_boot:
144 $(PYOCD_FLASHTOOL) -ce -a 0 mcuboot.bin
145
146flash_hello1:
147 $(PYOCD_FLASHTOOL) -a 0x20000 signed-hello1.bin
148
149flash_hello2:
150 $(PYOCD_FLASHTOOL) -a 0x80000 signed-hello2.bin
151
David Brown84a67af2017-07-26 00:36:02 -0600152flash_full:
153 $(PYOCD_FLASHTOOL) -ce -a 0 full.bin
154
David Brown1d3f67d2017-09-14 15:10:24 -0600155# These test- targets reinvoke make with the configuration set to test
156# various configurations. This will generally be followed by using
157# the above flash targets.
158
159# Test a good image, with a good upgrade, using RSA signatures.
160# flash_boot: Unable to find bootable image
161# flash_hello1: hello1 runs
162# flash_hello2: hello2 runs
163# reset: hello1 runs
164test-good-rsa:
165 $(MAKE) \
166 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
167 clean
168 $(MAKE) \
169 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
170 all
171
172# Test a good image, with a good upgrade, using ECDSA signatures.
173# flash_boot: Unable to find bootable image
174# flash_hello1: hello1 runs
175# flash_hello2: hello2 runs
176# reset: hello1 runs
177test-good-ecdsa:
178 $(MAKE) \
179 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
180 SIGNING_KEY=../../root-ec-p256.pem \
181 clean
182 $(MAKE) \
183 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
184 SIGNING_KEY=../../root-ec-p256.pem \
185 all
186
187# Test (with RSA) that overwrite-only works. This should boot,
188# upgrade correctly, but not revert once the upgrade has been done.
189# flash_boot: Unable to find bootable image
190# flash_hello1: hello1 runs
191# flash_hello2: hello2 runs
192# reset: hello2 runs
193test-overwrite:
194 $(MAKE) \
195 BOOTLOADER_CONFIG="CONF_UPGRADE_ONLY=YES" \
196 clean
197 $(MAKE) \
198 BOOTLOADER_CONFIG="CONF_UPGRADE_ONLY=YES" \
199 all
200
201# Test that when configured for RSA, a wrong signature in the upgrade
202# image will fail to upgrade.
203# flash_boot: Unable to find bootable image
204# flash_hello1: hello1 runs
205# flash_hello2: hello1 runs
206# reset: hello1 runs
207test-bad-rsa-upgrade:
208 $(MAKE) \
209 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
210 clean
211 $(MAKE) \
212 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
213 boot hello1
214 $(MAKE) \
215 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
216 SIGNING_KEY=../../root-ec-p256.pem \
217 hello2
218
219# Test that when configured for ECDSA, a wrong signature in the upgrade
220# image will fail to upgrade.
221# flash_boot: Unable to find bootable image
222# flash_hello1: hello1 runs
223# flash_hello2: hello1 runs
224# reset: hello1 runs
225test-bad-ecdsa-upgrade:
226 $(MAKE) \
227 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
228 clean
229 $(MAKE) \
230 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
231 SIGNING_KEY=../../root-ec-p256.pem \
232 boot hello1
233 $(MAKE) \
234 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
235 SIGNING_KEY=../../root-rsa-2048.pem \
236 hello2
237
238# Test that when configured to not validate slot0, we still boot, but
239# don't upgrade.
240# flash_boot: tries to boot and resets
241# flash_hello1: hello1 runs
242# flash_hello2: hello1 runs
243# reset: hello1 runs
244test-no-bootcheck:
245 $(MAKE) \
246 BOOTLOADER_CONFIG="CONF_VALIDATE_SLOT0=NO" \
247 clean
248 $(MAKE) \
249 BOOTLOADER_CONFIG="CONF_VALIDATE_SLOT0=NO" \
250 SIGNING_KEY=../../root-ec-p256.pem \
251 all
252
253# Test a good image, with a wrong-signature upgrade, using RSA signatures.
254# flash_boot: Unable to find bootable image
255# flash_hello1: hello1 runs
256# flash_hello2: hello1 runs
257# reset: hello1 runs
258test-wrong-rsa:
259 $(MAKE) \
260 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
261 clean
262 $(MAKE) \
263 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
264 boot hello1
265 $(MAKE) \
266 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=RSA" \
267 SIGNING_KEY=bad-keys/bad-rsa-2048.pem \
268 hello2
269
270# Test a good image, with a wrong-signature upgrade, using ECDSA signatures.
271# flash_boot: Unable to find bootable image
272# flash_hello1: hello1 runs
273# flash_hello2: hello1 runs
274# reset: hello1 runs
275test-wrong-ecdsa:
276 $(MAKE) \
277 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
278 clean
279 $(MAKE) \
280 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
281 SIGNING_KEY=../../root-ec-p256.pem \
282 boot hello1
283 $(MAKE) \
284 BOOTLOADER_CONFIG="CONF_SIGNATURE_TYPE=ECDSA_P256" \
285 SIGNING_KEY=bad-keys/bad-ec-p256.pem \
286 hello2
287
David Brownada28e12017-07-05 13:36:37 -0600288check:
289 @if [ -z "$$ZEPHYR_BASE" ]; then echo "Zephyr environment not set up"; false; fi
Marti Bolivar71354102017-08-01 15:09:44 -0400290 @if [ -z "$(BOARD)" ]; then echo "You must specify BOARD=<board>"; false; fi