blob: 3c0b58eb7f652ea8acfe07f1637318f2c5c5fd06 [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
26#
27# 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
52.PHONY: check boot hello1 clean_boot clean_hello1 \
53 hello2 clean_hello2 flash_boot flash_hello1 flash_hello2
54
55# For signing, use the default RSA demo key, to match the default in
56# the mcuboot Makefile.
57SIGNING_KEY = ../../root-rsa-2048.pem
58
59# The header size should match that in hello1/prj.conf
60# CONFIG_TEXT_SECTION_OFFSET. This value needs to be a power of two
61# that is at least as large as the size of the vector table. The
62# value given here of 0x200 should be sufficient for any supported
63# devices, but it can be made smaller, as long as this value matches
64# that used to build the app.
65BOOT_HEADER_LEN = 0x200
66
67# For upgrades, the signing tool needs to know the device alignment.
68# This requirement will be going away soon.
69FLASH_ALIGNMENT = 8
70
71IMGTOOL = ../../scripts/imgtool.py
72PYOCD_FLASHTOOL = pyocd-flashtool
73
74help:
75 @echo "make <target> BOARD=<board>"
76 @echo "<target>: all, boot, hello1"
77 @echo "<board>: frdm_k64f, 96b_carbon, etc."
78
79all: boot hello1 hello2
80
81clean: clean_boot clean_hello1 clean_hello2
82 @rm -f signed-hello1.bin
83 @rm -f signed-hello2.bin
84 @rm -f mcuboot.bin
85
86boot: check
87 @rm -f mcuboot.bin
88 $(MAKE) -C ../.. BOARD=$(BOARD) -j$(nproc)
89 cp ../../outdir/$(BOARD)/zephyr.bin mcuboot.bin
90
91clean_boot: check
92 rm -rf ../../outdir/$(BOARD)
93
94# Build and sign "hello1".
95hello1: check
96 $(MAKE) -C hello1 BOARD=$(BOARD) -j$(nproc)
97 $(IMGTOOL) sign \
98 --key $(SIGNING_KEY) \
99 --header-size $(BOOT_HEADER_LEN) \
100 --align $(FLASH_ALIGNMENT) \
101 --version 1.2 \
102 --included-header \
103 hello1/outdir/$(BOARD)/zephyr.bin \
104 signed-hello1.bin
105
106clean_hello1: check
107 rm -rf hello1/outdir/$(BOARD)
108
109# Build and sign "hello2".
110# This is the same signing command as above, except that it adds the
111# "--pad" argument. This will also add the trailer that indicates
112# this image is intended to be an upgrade. It should be flashed into
113# slot1 instead of slot0.
114hello2: check
115 $(MAKE) -C hello2 BOARD=$(BOARD) -j$(nproc)
116 $(IMGTOOL) sign \
117 --key $(SIGNING_KEY) \
118 --header-size $(BOOT_HEADER_LEN) \
119 --align $(FLASH_ALIGNMENT) \
120 --version 1.2 \
121 --included-header \
122 --pad 0x60000 \
123 hello2/outdir/$(BOARD)/zephyr.bin \
124 signed-hello2.bin
125
126clean_hello2: check
127 rm -rf hello2/outdir/$(BOARD)
128
129flash_boot:
130 $(PYOCD_FLASHTOOL) -ce -a 0 mcuboot.bin
131
132flash_hello1:
133 $(PYOCD_FLASHTOOL) -a 0x20000 signed-hello1.bin
134
135flash_hello2:
136 $(PYOCD_FLASHTOOL) -a 0x80000 signed-hello2.bin
137
138check:
139 @if [ -z "$$ZEPHYR_BASE" ]; then echo "Zephyr environment not set up"; false; fi
140 @if [ -z "$(BOARD)" ]; then echo "You must specity BOARD=<board>"; false; fi