-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
178 lines (140 loc) · 4.57 KB
/
Makefile
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
#
# Copyright © 2017-2020 Samuel Holland <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause
#
# File locations
ATF = arm-trusted-firmware
ATF_URL = https://github.com/crust-firmware/arm-trusted-firmware
SCP = crust
SCP_URL = https://github.com/crust-firmware/crust
U-BOOT = u-boot
U-BOOT_URL = https://github.com/u-boot/u-boot
BUILDDIR ?= build
OUTDIR = $(BUILDDIR)/$(BOARD)
# Cross compiler
CROSS_aarch32 = arm-linux-musleabi-
CROSS_aarch64 = aarch64-linux-musl-
CROSS_or1k = or1k-linux-musl-
# General options
DEBUG ?= 0
REPRODUCIBLE ?= 1
# Board selection
BOARD ?= pinebook
# Board-specific options
ARCH = $(or $(ARCH_$(BOARD)),aarch64)
PLAT = $(or $(PLAT_$(BOARD)),sun50i_a64)
FLASH_SIZE_KB = $(or $(FLASH_SIZE_KB_$(BOARD)),2048)
SPL_SIZE_KB = $(or $(SPL_SIZE_KB_$(BOARD)),32)
# Board-specific overrides
PLAT_orangepi_3 = sun50i_h6
PLAT_pine_h64 = sun50i_h6
FLASH_SIZE_KB_pine_h64 = 16384
###############################################################################
BUILD_TYPE = $(if $(filter-out 0,$(DEBUG)),debug,release)
BL3X = $(if $(findstring aarch64,$(ARCH)),bl31,bl32).bin
DATE = $(if $(filter-out 0,$(REPRODUCIBLE)),0,$(shell stat -c '%Y' .config))
M := @$(if $(filter-out 0,$(V)),:,printf ' %-7s %s\n')
Q := $(if $(filter-out 0,$(V)),,@)
all: $(OUTDIR)/sha256sums $(OUTDIR)/sha512sums
$(M) DONE
clean:
$(Q) $(MAKE) -C $(ATF) clean
$(Q) $(MAKE) -C $(SCP) clean
$(Q) $(MAKE) -C $(U-BOOT) clean
$(Q) rm -fr $(OUTDIR)
$(Q) rmdir $(BUILDDIR) 2>/dev/null || true
distclean:
$(Q) $(MAKE) -C $(ATF) distclean
$(Q) $(MAKE) -C $(SCP) distclean
$(Q) $(MAKE) -C $(U-BOOT) distclean
$(Q) rm -fr .config $(BUILDDIR)
.config: FORCE
$(M) CHECK board
$(Q) grep -Fqsx BOARD=$(BOARD) $@ || printf 'BOARD=%s\n' $(BOARD) >$@
$(ATF):
$(M) CLONE $@
$(Q) git clone $(ATF_URL) $@
$(SCP):
$(M) CLONE $@
$(Q) git clone $(SCP_URL) $@
$(U-BOOT):
$(M) CLONE $@
$(Q) git clone $(U-BOOT_URL) $@
%_defconfig:;
%/.config: .config %/configs/$(BOARD)_defconfig | %
$(M) CONFIG $|
$(Q) $(MAKE) -C $| $(BOARD)_defconfig
$(ATF)/build/$(PLAT)/$(BUILD_TYPE)/$(BL3X): .config FORCE | $(ATF)
$(M) MAKE $@
$(Q) $(MAKE) -C $| CROSS_COMPILE=$(CROSS_$(ARCH)) \
ARCH=$(ARCH) \
BUILD_MESSAGE_TIMESTAMP='"$(DATE)"' \
DEBUG=$(DEBUG) \
PLAT=$(PLAT) \
$(basename $(BL3X))
$(SCP)/build/scp/scp.bin: $(SCP)/.config FORCE | $(SCP)
$(M) MAKE $@
$(Q) $(MAKE) -C $| CROSS_COMPILE=$(CROSS_or1k) \
HOST_COMPILE=$(CROSS_$(ARCH)) \
build/scp/scp.bin
$(U-BOOT)/spl/sunxi-spl.bin: $(U-BOOT)/u-boot-sunxi-with-spl.bin;
$(U-BOOT)/u-boot-sunxi-with-spl.bin: $(U-BOOT)/.config \
$(OUTDIR)/$(BL3X) $(OUTDIR)/scp.bin FORCE | $(U-BOOT)
$(M) MAKE $@
$(Q) $(MAKE) -C $| CROSS_COMPILE=$(CROSS_$(ARCH)) \
BL31=$(abspath $(OUTDIR)/$(BL3X)) \
SCP=$(abspath $(OUTDIR)/scp.bin) \
SOURCE_DATE_EPOCH=$(DATE) \
all
$(U-BOOT)/u-boot-sunxi-with-spl.fit.fit: $(U-BOOT)/u-boot-sunxi-with-spl.bin;
$(BUILDDIR) $(OUTDIR):
$(M) MKDIR $@
$(Q) mkdir -p $@
$(OUTDIR)/$(BL3X): $(ATF)/build/$(PLAT)/$(BUILD_TYPE)/$(BL3X) | $(OUTDIR)
$(M) CP $@
$(Q) cp -f $< $@
$(OUTDIR)/scp.bin: $(SCP)/build/scp/scp.bin | $(OUTDIR)
$(M) CP $@
$(Q) cp -f $< $@
$(OUTDIR)/scp.config: $(SCP)/.config | $(OUTDIR)
$(M) CP $@
$(Q) cp -f $< $@
$(OUTDIR)/sunxi-spl.bin: $(U-BOOT)/spl/sunxi-spl.bin | $(OUTDIR)
$(M) CP $@
$(Q) cp -f $< $@
$(OUTDIR)/u-boot.config: $(U-BOOT)/.config | $(OUTDIR)
$(M) CP $@
$(Q) cp -f $< $@
$(OUTDIR)/u-boot.itb: $(U-BOOT)/u-boot-sunxi-with-spl.fit.fit | $(OUTDIR)
$(M) CP $@
$(Q) cp -f $< $@
$(OUTDIR)/u-boot-sunxi-spi.img: \
$(OUTDIR)/sunxi-spl.bin $(OUTDIR)/u-boot.itb | $(OUTDIR)
$(M) DD $@
$(Q) dd bs=$(FLASH_SIZE_KB)k count=1 if=/dev/zero 2>/dev/null | \
tr '\0' '\377' >[email protected]
$(Q) dd bs=$(SPL_SIZE_KB)k conv=notrunc \
if=$(OUTDIR)/sunxi-spl.bin [email protected] 2>/dev/null
$(Q) dd bs=$(SPL_SIZE_KB)k conv=notrunc \
if=$(OUTDIR)/u-boot.itb [email protected] seek=1 2>/dev/null
$(Q) mv -f [email protected] $@
$(OUTDIR)/u-boot-sunxi-with-spl.bin: $(U-BOOT)/u-boot-sunxi-with-spl.bin | \
$(OUTDIR)
$(M) CP $@
$(Q) cp -f $< $@
%/sha256sums: %/$(BL3X) %/scp.bin %/scp.config \
%/sunxi-spl.bin %/u-boot.config %/u-boot.itb \
%/u-boot-sunxi-spi.img %/u-boot-sunxi-with-spl.bin
$(M) SHA256 $@
$(Q) cd $(dir $@) && sha256sum -b $(notdir $^) > $(notdir $@).tmp
$(Q) mv -f [email protected] $@
%/sha512sums: %/$(BL3X) %/scp.bin %/scp.config \
%/sunxi-spl.bin %/u-boot.config %/u-boot.itb \
%/u-boot-sunxi-spi.img %/u-boot-sunxi-with-spl.bin
$(M) SHA512 $@
$(Q) cd $(dir $@) && sha512sum -b $(notdir $^) > $(notdir $@).tmp
$(Q) mv -f [email protected] $@
FORCE:
.PHONY: all clean distclean FORCE
.SECONDARY:
.SUFFIXES: