blob: d58eb288e8912d01b23557039aa4cf4b47b404e8 [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
David Browndbc57272017-07-17 15:38:54 -060072ASSEMBLE = ../../scripts/assemble.py
David Brownada28e12017-07-05 13:36:37 -060073PYOCD_FLASHTOOL = pyocd-flashtool
74
75help:
76 @echo "make <target> BOARD=<board>"
David Browndbc57272017-07-17 15:38:54 -060077 @echo "<target>: all, boot, hello1, full.bin"
David Brownada28e12017-07-05 13:36:37 -060078 @echo "<board>: frdm_k64f, 96b_carbon, etc."
79
80all: boot hello1 hello2
81
David Browndbc57272017-07-17 15:38:54 -060082full.bin: boot hello1 hello2
83 $(ASSEMBLE) -b ../../outdir/$(BOARD) \
84 -p signed-hello1.bin \
85 -s signed-hello2.bin \
86 -o full.bin
87
David Brownada28e12017-07-05 13:36:37 -060088clean: clean_boot clean_hello1 clean_hello2
89 @rm -f signed-hello1.bin
90 @rm -f signed-hello2.bin
91 @rm -f mcuboot.bin
92
93boot: check
94 @rm -f mcuboot.bin
95 $(MAKE) -C ../.. BOARD=$(BOARD) -j$(nproc)
96 cp ../../outdir/$(BOARD)/zephyr.bin mcuboot.bin
97
98clean_boot: check
99 rm -rf ../../outdir/$(BOARD)
100
101# Build and sign "hello1".
102hello1: check
103 $(MAKE) -C hello1 BOARD=$(BOARD) -j$(nproc)
104 $(IMGTOOL) sign \
105 --key $(SIGNING_KEY) \
106 --header-size $(BOOT_HEADER_LEN) \
107 --align $(FLASH_ALIGNMENT) \
108 --version 1.2 \
109 --included-header \
110 hello1/outdir/$(BOARD)/zephyr.bin \
111 signed-hello1.bin
112
113clean_hello1: check
114 rm -rf hello1/outdir/$(BOARD)
115
116# Build and sign "hello2".
117# This is the same signing command as above, except that it adds the
118# "--pad" argument. This will also add the trailer that indicates
119# this image is intended to be an upgrade. It should be flashed into
120# slot1 instead of slot0.
121hello2: check
122 $(MAKE) -C hello2 BOARD=$(BOARD) -j$(nproc)
123 $(IMGTOOL) sign \
124 --key $(SIGNING_KEY) \
125 --header-size $(BOOT_HEADER_LEN) \
126 --align $(FLASH_ALIGNMENT) \
127 --version 1.2 \
128 --included-header \
129 --pad 0x60000 \
130 hello2/outdir/$(BOARD)/zephyr.bin \
131 signed-hello2.bin
132
133clean_hello2: check
134 rm -rf hello2/outdir/$(BOARD)
135
136flash_boot:
137 $(PYOCD_FLASHTOOL) -ce -a 0 mcuboot.bin
138
139flash_hello1:
140 $(PYOCD_FLASHTOOL) -a 0x20000 signed-hello1.bin
141
142flash_hello2:
143 $(PYOCD_FLASHTOOL) -a 0x80000 signed-hello2.bin
144
145check:
146 @if [ -z "$$ZEPHYR_BASE" ]; then echo "Zephyr environment not set up"; false; fi
147 @if [ -z "$(BOARD)" ]; then echo "You must specity BOARD=<board>"; false; fi