forked from u-root/u-bmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
336 lines (293 loc) · 11.7 KB
/
Makefile
File metadata and controls
336 lines (293 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# Copyright 2018 u-root Authors
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file
PLATFORM ?= quanta-f06-leopard-ddr3
LEB := 65408
CROSS_COMPILE ?= arm-none-eabi-
QEMU ?= qemu-system-arm
# Some useful debug flags:
# - in_asm, show ASM as it's being fed into QEMU
# - unimp, show things that the VM tries to do but isn't implemented in QEMU
# Run "make QEMUDEBUGFLAGS='-d help' sim" for more flags
QEMUDEBUGFLAGS ?= -d guest_errors
QEMUFLAGS ?= -display none \
-drive file=flash.sim.img,format=raw,if=mtd \
-chardev socket,id=host,path=host.uart,server,nowait \
-nic user,hostfwd=udp::6053-:53,hostfwd=tcp::6443-:443,hostfwd=tcp::9370-:9370 \
${QEMUDEBUGFLAGS}
MAKE_JOBS ?= -j8
ABS_ROOT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/
# This is used to include garbage in the signing process to test verification
# errors in the integration test. It should not be used for any real builds.
TEST_EXTRA_SIGN ?= /dev/null
# Flash image size in MiB
ROM_SIZE ?= 16
# Since the DTB needs to contains the partitions, and the bootloader contains
# the DTB, we have to guess the size of the DTB + the bootloader ahead of time.
# The bootloader for ast2400 is something like 10KiB, and the DTB is 25 KiB.
# Here we give the extra space a total of 100 KiB to have some space.
EXTRA_BOOT_SPACE ?= 102400
GIT_VERSION=$(shell (cd $(ABS_ROOT_DIR); git describe --tags --long --always))
# This is to allow integration tests that build new root filesystems outside
# of the source root
ifeq ($(ABS_ROOT_DIR),$(PWD)/)
ROOT_DIR :=
else
ROOT_DIR := $(ABS_ROOT_DIR)
endif
all: flash.img
include $(ROOT_DIR)platform/$(PLATFORM)/Makefile.inc
include $(ROOT_DIR)platform/$(SOC)/Makefile.inc
.PHONY: sim all linux-menuconfig-% test vars pebble
u-bmc:
go get
go build
# Linux tree comes from the OpenBMC branch, not the official kernel.org
LINUX_VERSION := 5.10.53
LINUX_DIR := linux-$(LINUX_VERSION)
LINUX_TAR := linux-$(LINUX_VERSION).tar.gz
LINUX_URL := https://github.com/openbmc/linux/archive/refs/tags/v$(LINUX_VERSION).tar.gz
LINUX_HASH := 159c8d1a29e7080020ac83497f78458d9c91da9d16144a3d6dd5eb615a62ad1f
# Make considers these files as intermediate files and removes them.
# Tell make they are important.
.SECONDARY: $(LINUX_DIR)/build/full/.config $(LINUX_DIR)/build/boot/.config
$(LINUX_TAR):
wget -O "$@" "$(LINUX_URL)"
$(LINUX_DIR)/.valid: $(LINUX_TAR)
echo "$(LINUX_HASH) $<" | sha256sum --check
mkdir -p "$(LINUX_DIR)"
tar xf "$<" --strip 1 -C "$(LINUX_DIR)"
touch "$@"
$(LINUX_DIR)/.patched: $(LINUX_DIR)/.valid
cd $(LINUX_DIR) ; \
for patch in ../patches/*.patch ; do \
echo "=> Applying `basename $$patch`" ; \
git apply "$$patch" || exit 1 ; \
done
touch "$@"
boot/boot.bin: boot/zImage.boot boot/loader.cpio.gz boot/platform.dtb.boot boot/boot-config.auto.h $(shell find $(ROOT_DIR)platform/$(SOC)/ -name \*.S -type f) $(ROOT_DIR)platform/$(PLATFORM)/boot/config.h
$(MAKE) -C platform/$(SOC)/boot boot.bin PLATFORM=$(PLATFORM) CROSS_COMPILE=$(CROSS_COMPILE)
ln -sf ../platform/$(SOC)/boot/boot.bin $@
boot/kexec:
# TODO(bluecmd): https://github.com/u-root/u-root/issues/401
wget https://github.com/bluecmd/tools/raw/master/arm/kexec -O $@
echo "cda9f2ded9c068be69f95dea11fdbab013de6c6c785a3d2ab259028378c06653 $@" | \
sha256sum -c
chmod 755 boot/kexec
u-bmc.img: $(ROOT_DIR)boot/boot.bin ubi.img $(ROOT_DIR)platform/ubmc-flash-layout.dtsi
dd if=/dev/zero | tr '\000' '\377' | dd iflag=fullblock bs=64k of=$@ \
count=$$(($$(grep SIZE= platform/ubmc-flash-layout.dtsi | cut -d= -f2) / 65536))
dd conv=notrunc if=$< of=$@
cat ubi.img >>$@
flash.img: u-bmc.img
dd if=/dev/zero | tr '\000' '\377' | dd iflag=fullblock bs=1M count=$(ROM_SIZE) of=$@
dd conv=notrunc if=$< of=$@
boot/signer/signer: boot/signer/main.go
go get ./boot/signer/
go build -o $@ ./boot/signer/
boot/loader/loader: boot/loader/main.go
go get ./boot/loader/
GOARM=5 GOARCH=$(ARCH) go build -ldflags="-s -w" -o $@ ./boot/loader/
boot/keys/u-bmc.pub: boot/signer/signer boot/keys/u-bmc.key
# Run signer to make sure the pub file is created
echo | boot/signer/signer > /dev/null
touch boot/keys/u-bmc.pub
platform/ubmc-flash-layout.dtsi: boot/zImage.boot boot/loader.cpio.gz
go run platform/cmd/flash-layout/main.go --extra $(EXTRA_BOOT_SPACE) $^ > $@
module/%.ko: $(shell find $(ROOT_DIR)module -name \*.c -type f) boot/zImage.boot
$(MAKE) $(MAKE_JOBS) \
-C "$(LINUX_DIR)" \
O=build/boot \
CROSS_COMPILE=$(CROSS_COMPILE) \
ARCH=$(ARCH) \
M=$(ABS_ROOT_DIR)/module \
modules
$(LINUX_DIR)/build/boot/scripts/sign-file sha256 \
$(LINUX_DIR)/build/boot/certs/signing_key.pem \
$(LINUX_DIR)/build/boot/certs/signing_key.x509 \
$@
boot/loader.cpio.gz: boot/loader/loader boot/keys/u-bmc.pub module/bootlock.ko boot/kexec
rm -f boot/loader.cpio.gz
sh -c "cd boot/loader/; echo loader | cpio -H newc -ov -F ../loader.cpio"
sh -c "cd boot/keys/; echo u-bmc.pub | cpio -H newc -oAv -F ../loader.cpio"
sh -c "cd module/; echo bootlock.ko | cpio -H newc -oAv -F ../boot/loader.cpio"
sh -c "cd boot/; echo kexec | cpio -H newc -oAv -F loader.cpio"
gzip boot/loader.cpio
# TODO(bluecmd): Change to ECDSA now when u-boot is gone
boot/keys/u-bmc.key:
mkdir -p boot/keys/
chmod 700 boot/keys/
openssl genrsa -out $@ 2048
# Rebuild the Linux config from the one in the platform directory.
# If you change $(SOC) it is probably best to blow away the Linux directory
$(LINUX_DIR)/build/%/.config: platform/$(SOC)/linux.config.% $(LINUX_DIR)/.patched
@mkdir -p "$(dir $@)"
cp "$<" "$@"
$(MAKE) \
-C "$(LINUX_DIR)" \
O="../$(dir $@)" \
CROSS_COMPILE=$(CROSS_COMPILE) \
ARCH=$(ARCH) \
olddefconfig
boot/zImage.%: $(LINUX_DIR)/build/%/.config
$(MAKE) $(MAKE_JOBS) \
-C "$(LINUX_DIR)" \
O="../$(dir $<)" \
CROSS_COMPILE=$(CROSS_COMPILE) \
ARCH=$(ARCH) \
all
cp "$(dir $<)arch/$(ARCH)/boot/zImage" "$@"
# Interactively edit a Linux config. Don't forget to save it afterwards
linux-menuconfig.%: $(LINUX_DIR)/build/%/.config
$(MAKE) $(MAKE_JOBS) \
-C "$(LINUX_DIR)" \
O="../$(dir $<)" \
CROSS_COMPILE=$(CROSS_COMPILE) \
ARCH=$(ARCH) \
menuconfig
rm -f $<.old
# After editing the real .config file, run `make linux-saveconfig.full` to store the
# default (stripped down) configuration file back into the source tree
linux-saveconfig.%: $(LINUX_DIR)/build/%/.config
$(MAKE) $(MAKE_JOBS) \
-C "$(LINUX_DIR)" \
O="../$(dir $<)" \
CROSS_COMPILE=$(CROSS_COMPILE) \
ARCH=$(ARCH) \
savedefconfig
mv "$(dir $<)defconfig" "platform/$(SOC)/linux.config$(suffix $@)"
integration/bzImage: integration/linux.config
$(MAKE) $(MAKE_JOBS) \
-C $(LINUX_DIR) O=build/$@/ \
KCONFIG_CONFIG="$(ABS_ROOT_DIR)$<"
rm -f $<.old
cp $(LINUX_DIR)/build/$@/arch/x86/boot/bzImage $@
linux-integration-menuconfig: integration/linux.config
$(MAKE) $(MAKE_JOBS) \
-C $(LINUX_DIR)/ O=build/$@/ \
KCONFIG_CONFIG="$(ABS_ROOT_DIR)$<" \
menuconfig
rm -f $<.old
boot/%.dtb.boot.dummy: platform/$(PLATFORM)/%.dts platform/ubmc-flash-layout.dtsi platform/$(PLATFORM)/boot/config.h boot/loader.cpio.gz
# Construct the DTB first with dummy addresses, and then again with the real
# ones. This assumes the DTB does not grow, but since it's only addresses
# that should be fine.
go run platform/cmd/boot-config/main.go \
--ram-start $(RAM_START) \
--ram-size $(RAM_SIZE) \
--initrd /dev/null \
--dtb /dev/null > boot/boot-config.auto.h
cpp \
-nostdinc \
-I $(LINUX_DIR)/arch/$(ARCH)/boot/dts/ \
-I $(LINUX_DIR)/include \
-I platform/ \
-I platform/$(PLATFORM)/boot/ \
-I boot/ \
-DBOOTLOADER \
-undef \
-x assembler-with-cpp \
$< \
| dtc -O dtb -o $@ -
boot/%.dtb.boot: platform/$(PLATFORM)/%.dts boot/%.dtb.boot.dummy
go run platform/cmd/boot-config/main.go \
--ram-start $(RAM_START) \
--ram-size $(RAM_SIZE) \
--initrd boot/loader.cpio.gz \
--dtb $@.dummy > boot/boot-config.auto.h
rm -f $@
cpp \
-nostdinc \
-I $(LINUX_DIR)/arch/$(ARCH)/boot/dts/ \
-I $(LINUX_DIR)/include \
-I platform/ \
-I platform/$(PLATFORM)/boot/ \
-I boot/ \
-DBOOTLOADER \
-undef \
-x assembler-with-cpp \
$< \
| dtc -O dtb -o $@.tmp -
# Verify that the size in fact didn't change
bash -c '[[ \
$$(stat --printf="%s" $@.tmp) == \
$$(stat --printf="%s" $@.dummy) ]]' || \
(echo DTB changed size, cannot continue! Please file a bug about this; exit 1)
mv $@.tmp $@
boot/%.dtb.full: platform/$(PLATFORM)/%.dts boot/%.dtb.boot
cpp \
-nostdinc \
-I $(LINUX_DIR)/arch/$(ARCH)/boot/dts/ \
-I $(LINUX_DIR)/include \
-I platform/ \
-I platform/$(PLATFORM)/boot/ \
-I boot/ \
-undef \
-x assembler-with-cpp \
$< \
| dtc -O dtb -o $@ -
root.ubifs.img: initramfs.cpio $(ROOT_DIR)boot/zImage.full $(ROOT_DIR)boot/signer/signer $(ROOT_DIR)boot/platform.dtb.full $(ROOT_DIR)proto/system.textpb.default
rm -fr root/
mkdir -p root/root root/etc root/boot
# TOOD(bluecmd): Move to u-bmc system startup
echo "nameserver 2001:4860:4860::8888" > root/etc/resolv.conf
echo "nameserver 2606:4700:4700::1111" >> root/etc/resolv.conf
echo "nameserver 8.8.8.8" >> root/etc/resolv.conf
echo "::1 localhost" >> root/etc/hosts
cp -v $(ROOT_DIR)boot/zImage.full root/boot/zImage-$(GIT_VERSION)
cat $(ROOT_DIR)boot/zImage.full | $(ROOT_DIR)boot/signer/signer > root/boot/zImage-$(GIT_VERSION).gpg
cp -v $(ROOT_DIR)boot/platform.dtb.full root/boot/platform-$(GIT_VERSION).dtb
cat $(ROOT_DIR)boot/platform.dtb.full | $(ROOT_DIR)boot/signer/signer > root/boot/platform-$(GIT_VERSION).dtb.gpg
ln -sf zImage-$(GIT_VERSION) root/boot/zImage
ln -sf zImage-$(GIT_VERSION).gpg root/boot/zImage.gpg
ln -sf platform-$(GIT_VERSION).dtb root/boot/platform.dtb
ln -sf platform-$(GIT_VERSION).dtb.gpg root/boot/platform.dtb.gpg
cp -v $(ROOT_DIR)boot/keys/u-bmc.pub root/etc/
ln -sf bbin/bb.gpg root/init.gpg
mkdir root/config
cp $(ROOT_DIR)proto/system.textpb.default root/config/system.textpb
# Rewrite the symlink to a non-absolute to allow non-chrooted following.
# This is a workaround for the fact that the loader cannot chroot currently.
ln -sf bbin/bb root/init
fakeroot sh -c "(cd root/; cpio -idv < ../$(<)) && \
cat root/bbin/bb $(TEST_EXTRA_SIGN) | \
$(ROOT_DIR)boot/signer/signer > root/bbin/bb.gpg && \
mkfs.ubifs -x zlib -r root -R0 -m 1 -e ${LEB} -c 2047 -o $(@)"
ubi.img: root.ubifs.img $(ROOT_DIR)ubi.cfg
ubinize -vv -o ubi.img -m 1 -p64KiB $(ROOT_DIR)ubi.cfg
flash.sim.img: flash.img
dd if=/dev/zero | tr '\000' '\377' | dd iflag=fullblock bs=1M count=32 of=$@
dd conv=notrunc if=$< of=$@
initramfs.cpio: u-bmc ssh_keys.pub config/config.go $(shell find $(ROOT_DIR)cmd $(ROOT_DIR)platform/$(PLATFORM) $(ROOT_DIR)pkg $(ROOT_DIR)proto -name \*.go -type f)
go generate ./config/
rm -r vendor/github.com/u-root/u-root
ln -sf ../../../../u-root vendor/github.com/u-root
GOARM=5 GOARCH=$(ARCH) ./u-bmc -o "$@.tmp" -p "$(PLATFORM)"
mv "$@.tmp" "$@"
test:
go test $(TESTFLAGS) \
$(shell find */ -name \*.go | grep -v vendor | cut -f -1 -d '/' | sort -u | xargs -n1 -I{} echo ./{}/... | xargs)
get:
go get -t $(GETFLAGS) \
$(shell find */ -name \*.go | grep -v vendor | cut -f -1 -d '/' | sort -u | xargs -n1 -I{} echo ./{}/... | xargs)
vars:
$(foreach var,$(.VARIABLES),$(info $(var)=$($(var))))
clean:
\rm -f initramfs.cpio u-root \
flash.img flash.sim.img boot/boot-config.auto.h \
root.ubifs.img boot/zImage* boot/platform.dtb* \
ubi.img boot/loader/loader boot/signer/signer boot/loader.cpio.gz \
module/*.o module/*.mod.c module/*.ko module/.*.cmd module/modules.order \
module/Module.symvers config/ssh_keys.go config/version.go
\rm -fr root/ boot/modules/ module/.tmp_versions/ boot/out
pebble:
go run github.com/letsencrypt/pebble/cmd/pebble \
-dnsserver 127.0.0.1:6053 \
-config config/sim-pebble.json
run-ovmf:
qemu-system-x86_64 -bios $(ROOT_DIR)integration/ovmf.rom \
-display none \
-chardev socket,id=host,path=host.uart \
-serial chardev:host \
-net none