Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
609 lines (520 loc) · 22.5 KB
/
Copy pathMakefile
File metadata and controls
609 lines (520 loc) · 22.5 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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# SPDX-License-Identifier: GPL-2.0+
VERSION := 0
PATCHLEVEL := 5
SUBLEVEL := 0
.DEFAULT_GOAL := all
MAKEFLAGS += --no-print-directory --silent
srctree := $(CURDIR)
ifneq ($(O),)
objtree := $(abspath $(O))
else
objtree := $(srctree)
endif
KCONFIG_CONFIG := $(objtree)/.config
auto_conf := $(objtree)/include/config/auto.conf
auto_header := $(objtree)/include/generated/autoconf.h
kconfig_out := $(objtree)/.kconfig
conf := $(kconfig_out)/conf
mconf := $(kconfig_out)/mconf
kconfig_sources := $(wildcard $(srctree)/scripts/kconfig/*.[ch] \
$(srctree)/scripts/kconfig/*.y $(srctree)/scripts/kconfig/*.l \
$(srctree)/scripts/kconfig/*.sh \
$(srctree)/scripts/kconfig/lxdialog/*.[ch]) \
$(srctree)/scripts/kconfig/Makefile
board_kconfig_list := $(kconfig_out)/boards.Kconfig
board_kconfigs := $(sort $(wildcard $(srctree)/boards/*/Kconfig))
defconfig_files := $(sort $(wildcard $(srctree)/configs/*/*_defconfig))
BOARD_KCONFIG_LIST := $(board_kconfig_list)
kconfig_env := KCONFIG_CONFIG=$(KCONFIG_CONFIG) \
KCONFIG_AUTOCONFIG=$(auto_conf) KCONFIG_AUTOHEADER=$(auto_header) \
BOARD_KCONFIG_LIST=$(BOARD_KCONFIG_LIST)
no_dot_config_targets := config menuconfig olddefconfig syncconfig defconfig \
savedefconfig %_defconfig release clean mrproper help list-defconfigs check tools \
utilities list-utilities test docs
ifeq ($(strip $(MAKECMDGOALS)),)
-include $(auto_conf)
-include $(auto_conf).cmd
else ifneq ($(strip $(filter-out $(no_dot_config_targets),$(MAKECMDGOALS))),)
-include $(auto_conf)
-include $(auto_conf).cmd
endif
unquote = $(subst ",,$(1))
board := $(call unquote,$(CONFIG_SYS_BOARD))
arch_dir := $(if $(CONFIG_ARCH_ARM32),arm,riscv)
arch_inc := arch/$(arch_dir)/include
include_dirs := include $(arch_inc)
KBUILD_CPPFLAGS := -I$(objtree)/include/generated \
$(addprefix -I$(srctree)/,$(include_dirs)) \
-I$(srctree)/dts/include -include $(auto_header)
KBUILD_CFLAGS := -nostdlib -nostdinc -ffreestanding -fno-builtin \
-fno-common -fno-stack-protector -ffunction-sections -fdata-sections \
-Wall
KBUILD_AFLAGS := $(KBUILD_CFLAGS)
ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
KBUILD_CFLAGS += -Os
else
KBUILD_CFLAGS += -O2
endif
ifeq ($(CONFIG_BUILD_DEBUG),y)
KBUILD_CFLAGS += -g -ggdb
KBUILD_AFLAGS += -g -ggdb
KBUILD_CPPFLAGS += -DDEBUG_MODE
endif
ifeq ($(CONFIG_BUILD_TRACE),y)
KBUILD_CPPFLAGS += -DTRACE_MODE
endif
ifneq ($(board),)
include $(srctree)/arch/$(arch_dir)/Makefile
include $(srctree)/boards/$(board)/Makefile
endif
ifeq ($(origin CC),default)
CC := $(CROSS_COMPILE)gcc
endif
ifeq ($(origin AR),default)
AR := $(CROSS_COMPILE)ar
endif
ifeq ($(origin LD),default)
LD := $(CROSS_COMPILE)ld
endif
NM ?= $(CROSS_COMPILE)nm
OBJCOPY ?= $(CROSS_COMPILE)objcopy
OBJDUMP ?= $(CROSS_COMPILE)objdump
SIZE ?= $(CROSS_COMPILE)size
HOSTCC ?= cc
DOXYGEN ?= doxygen
include $(srctree)/scripts/Makefile.dt2c
FIRMWARE_CROSS_COMPILE ?= riscv64-unknown-elf-
BL33_CROSS_COMPILE ?= arm-none-eabi-
ifneq ($(board),)
board_dts := $(srctree)/boards/$(board)/board.dts
dt2c_bindings := $(srctree)/dts/bindings
dt2c_out := $(objtree)/.obj/boards/$(board)/dt2c
dt2c_driver_manifest := $(dt2c_out)/selected-drivers
dt2c_driver_inputs := $(shell find $(srctree)/drivers -type f \
\( -name '*.c' -o -name Makefile -o -name Kbuild \) -print)
dt2c_include := $(dt2c_out)/include
dt2c_header := $(dt2c_include)/generated/fdt_generated.h
dt2c_depfile := $(dt2c_out)/devicetree.d
dt2c_report := $(dt2c_out)/devicetree.json
KBUILD_CPPFLAGS += -I$(dt2c_include)
KBUILD_CPPFLAGS += -I$(DT2C_INCLUDE)
dt2c_recorded_deps := $(filter-out %:,\
$(filter /%,$(file <$(dt2c_depfile))))
dt2c_missing_deps := $(filter-out $(wildcard $(dt2c_recorded_deps)),\
$(dt2c_recorded_deps))
ifneq ($(strip $(dt2c_missing_deps)),)
# Let the manifest/header rules regenerate stale depfiles after source removal.
$(dt2c_missing_deps):
endif
-include $(dt2c_depfile)
endif
ifeq ($(CONFIG_EFEX),y)
app_mode := app_efex
apps := $(apps-efex-y)
else ifeq ($(CONFIG_APP_DRAM),y)
app_mode := app_dram
apps := $(apps-dram-y)
else
app_mode := app_sram
apps := $(apps-sram-y)
endif
include $(srctree)/scripts/Makefile.rust
export srctree objtree CC AR LD NM OBJCOPY OBJDUMP SIZE HOSTCC DT2C DT2C_INCLUDE
export KBUILD_CPPFLAGS KBUILD_CFLAGS KBUILD_AFLAGS KBUILD_LDFLAGS
.PHONY: all artifacts image images prepare tools utilities firmware check config \
menuconfig olddefconfig syncconfig defconfig savedefconfig release list-defconfigs \
list-apps list-firmware list-utilities test docs rust-ffi help clean mrproper \
board-kconfig dt2c-check FORCE
ifneq ($(wildcard $(auto_conf)),)
all: images
else
all:
@echo "No configuration found. Run 'make <board>[_<variant>]_defconfig' or 'make menuconfig'."
@false
endif
$(conf) $(mconf): $(kconfig_sources)
@$(MAKE) -C $(srctree)/scripts/kconfig O=$(kconfig_out) \
HOSTCC="$(HOSTCC)" all
board-kconfig:
@set -e; \
mkdir -p $(dir $(board_kconfig_list)); \
tmp=$(board_kconfig_list).tmp.$$$$; \
{ for file in $(board_kconfigs); do \
printf 'source "%s"\n' "$${file#$(srctree)/}"; \
done; } > "$$tmp"; \
if ! cmp -s "$$tmp" $(board_kconfig_list); then \
mv "$$tmp" $(board_kconfig_list); \
else \
$(RM) "$$tmp"; \
fi
config: $(conf) | board-kconfig
@mkdir -p $(objtree)
@$(kconfig_env) $(conf) $(srctree)/Kconfig
@$(MAKE) O=$(O) syncconfig
menuconfig: $(mconf) | board-kconfig
@mkdir -p $(objtree)
@$(kconfig_env) $(mconf) $(srctree)/Kconfig
@$(MAKE) O=$(O) syncconfig
olddefconfig: $(conf) | board-kconfig
@$(kconfig_env) $(conf) --olddefconfig $(srctree)/Kconfig
@$(MAKE) O=$(O) syncconfig
release: $(conf) | board-kconfig
@test -f $(KCONFIG_CONFIG) || { echo "No configuration found. Run 'make <board>_defconfig' first." >&2; exit 1; }
@set -e; \
tmp="$(KCONFIG_CONFIG).release.$$$$"; \
trap '$(RM) "$$tmp"' EXIT; \
$(srctree)/scripts/release-config.sh "$(KCONFIG_CONFIG)" "$$tmp"; \
$(kconfig_env) $(conf) --defconfig="$$tmp" $(srctree)/Kconfig; \
$(MAKE) O=$(O) syncconfig
syncconfig: $(conf) | board-kconfig
@mkdir -p $(dir $(auto_conf)) $(dir $(auto_header))
@$(kconfig_env) $(conf) --syncconfig $(srctree)/Kconfig
$(auto_conf) $(auto_header) &: $(KCONFIG_CONFIG) $(conf) | board-kconfig
@mkdir -p $(dir $(auto_conf)) $(dir $(auto_header))
@$(kconfig_env) $(conf) --syncconfig $(srctree)/Kconfig
defconfig: tinyvision_defconfig
defconfig_board = $(word 1,$(subst /, ,$(patsubst $(srctree)/configs/%,%,$(1))))
defconfig_variant = $(patsubst %_defconfig,%,$(notdir $(1)))
defconfig_public_variant = $(if $(filter sram,$(call defconfig_variant,$(1))),,$(patsubst %_sram,%,$(call defconfig_variant,$(1))))
defconfig_target = $(call defconfig_board,$(1))$(if $(call defconfig_public_variant,$(1)),_$(call defconfig_public_variant,$(1)))_defconfig
defconfig_targets := $(sort $(foreach config,$(defconfig_files),$(call defconfig_target,$(config))))
.PHONY: $(defconfig_targets)
define defconfig_template
$(call defconfig_target,$(1)): $(conf) | board-kconfig
@mkdir -p $(objtree)
@echo " DEFCONFIG $$@"
@$(kconfig_env) $(conf) \
--defconfig=$(1) $(srctree)/Kconfig
@$(MAKE) O=$(O) syncconfig
endef
$(foreach config,$(defconfig_files),$(eval $(call defconfig_template,$(config))))
%_defconfig:
@echo "Unknown defconfig: $@"
@false
savedefconfig: $(conf) | board-kconfig
@$(kconfig_env) $(conf) \
--savedefconfig=$(objtree)/defconfig $(srctree)/Kconfig
list-defconfigs:
@printf '%s\n' $(defconfig_targets)
list-apps:
@$(if $(apps),printf '%s\n' $(apps),:)
list-firmware:
@$(if $(firmware-y),printf '%s\n' $(firmware-y),:)
utility_dirs := bl33 bl33_t527
utility_root := $(objtree)/utilities
utility_rel_root := utilities
list-utilities:
@printf '%s\n' $(utility_dirs)
prepare: $(objtree)/include/generated/config.h $(dt2c_header)
git_hash := $(shell git -C $(srctree) rev-parse --short HEAD 2>/dev/null || echo unknown)
$(objtree)/include/generated/config.h: $(auto_header) $(srctree)/Makefile
@mkdir -p $(dir $@)
@echo " GEN $(patsubst $(objtree)/%,%,$@)"
@{ \
echo '/* SPDX-License-Identifier: GPL-2.0+ */'; \
echo '#ifndef __GENERATED_CONFIG_H__'; \
echo '#define __GENERATED_CONFIG_H__'; \
echo '#define PROJECT_NAME "SyterKit"'; \
echo '#define PROJECT_VERSION "$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)"'; \
echo '#define PROJECT_GIT_HASH "$(git_hash)"'; \
echo '#define PROJECT_C_COMPILER "$(notdir $(CC))"'; \
echo '#define PROJECT_C_COMPILER_VERSION "'$$($(CC) -dumpfullversion -dumpversion)'"'; \
echo '#endif'; \
} > $@
ifneq ($(board),)
$(dt2c_driver_manifest): $(dt2c_driver_inputs) $(auto_conf) \
$(srctree)/Makefile $(srctree)/scripts/Makefile.build FORCE
@mkdir -p $(dir $@)
@tmp=$@.tmp; \
$(MAKE) -f $(srctree)/scripts/Makefile.build obj=drivers \
dt2c-manifest > $$tmp; \
if cmp -s $$tmp $@; then \
$(RM) $$tmp; \
else \
mv $$tmp $@; \
fi
$(dt2c_header): $(board_dts) $(dt2c_driver_manifest) $(dt2c_path) \
| dt2c-check
@mkdir -p $(dir $@)
@echo " DT2C boards/$(board)/board.dts"
@$(dt2c_path) generate \
--dts $(board_dts) \
--bindings $(dt2c_bindings) \
--drivers $(dt2c_driver_manifest) \
--header $(dt2c_header) \
--depfile $(dt2c_depfile) \
--report $(dt2c_report) \
-I $(srctree)/dts/include \
-I $(srctree)/include
endif
build_dirs := core lib drivers arch/$(arch_dir) boards/$(board)
common_builtins := $(addprefix $(objtree)/.obj/,$(addsuffix /built-in.o,$(build_dirs)))
$(objtree)/.obj/%/built-in.o: prepare FORCE
@$(MAKE) -f $(srctree)/scripts/Makefile.build obj=$*
$(objtree)/.obj/apps/$(board)/$(app_mode)/%/built-in.o: prepare FORCE
@$(MAKE) -f $(srctree)/scripts/Makefile.app board=$(board) mode=$(app_mode) app=$*
board_libs := $(addprefix $(srctree)/boards/$(board)/,$(board-libs-y))
image_root := $(objtree)/build/$(board)/$(app_mode)
image_rel_root := build/$(board)/$(app_mode)
backtrace_address_bits := $(if $(CONFIG_ARCH_RISCV64),64,32)
fel_lds := $(image_root)/link_fel.ld
bin_lds := $(image_root)/link_bin.ld
efex_lds := $(image_root)/efex.lds
ifeq ($(CONFIG_APP_SRAM),y)
ifneq ($(board-fel-lds-y),)
board_fel_lds := $(srctree)/boards/$(board)/$(board-fel-lds-y)
board_bin_lds := $(srctree)/boards/$(board)/$(board-bin-lds-y)
$(fel_lds): $(board_fel_lds)
@mkdir -p $(dir $@)
@cp $< $@
$(bin_lds): $(board_bin_lds)
@mkdir -p $(dir $@)
@cp $< $@
else
lds_src := $(srctree)/arch/$(arch_dir)/syterkit.lds.S
$(fel_lds): $(lds_src) $(auto_header)
@mkdir -p $(dir $@)
@echo " LDS $(image_rel_root)/link_fel.ld"
@$(CC) $(KBUILD_CPPFLAGS) -E -P -x c -DSPL_TEXT_BASE=$(CONFIG_SPL_FEL_TEXT_BASE) \
-DSPL_MAX_SIZE=$(CONFIG_SPL_FEL_MAX_SIZE) $< -o $@
$(bin_lds): $(lds_src) $(auto_header)
@mkdir -p $(dir $@)
@echo " LDS $(image_rel_root)/link_bin.ld"
@$(CC) $(KBUILD_CPPFLAGS) -E -P -x c -DSPL_TEXT_BASE=$(CONFIG_SPL_BIN_TEXT_BASE) \
-DSPL_MAX_SIZE=$(CONFIG_SPL_BIN_MAX_SIZE) $< -o $@
endif
else ifeq ($(CONFIG_EFEX),y)
lds_src := $(srctree)/arch/$(arch_dir)/efex.lds.S
$(efex_lds): $(lds_src) $(auto_header)
@mkdir -p $(dir $@)
@echo " LDS $(image_rel_root)/efex.lds"
@$(CC) $(KBUILD_CPPFLAGS) -E -P -x c -DSPL_TEXT_BASE=$(CONFIG_SPL_FEL_TEXT_BASE) \
-DSPL_MAX_SIZE=$(CONFIG_SPL_FEL_MAX_SIZE) $< -o $@
else
lds_src := $(srctree)/arch/$(arch_dir)/syterkit.lds.S
$(bin_lds): $(lds_src) $(auto_header)
@mkdir -p $(dir $@)
@echo " LDS $(image_rel_root)/link_bin.ld"
@$(CC) $(KBUILD_CPPFLAGS) -E -P -x c -DSPL_TEXT_BASE=$(CONFIG_APP_DRAM_TEXT_BASE) \
-DSPL_MAX_SIZE=$(CONFIG_APP_DRAM_MAX_SIZE) $< -o $@
endif
link_flags = $(KBUILD_CFLAGS) -nostdlib -Wl,--gc-sections \
-Wl,-z,noexecstack $(rust_ffi_linker_flags) \
-Wl,--whole-archive $(common_builtins) $(1) $(board_libs) \
-Wl,--no-whole-archive $(2) -lgcc
define app_template
app_$(1)_dir := $(image_root)/$(1)
app_$(1)_rel_dir := $(image_rel_root)/$(1)
app_$(1)_builtin := $(if $(filter $(1),$(rust_apps)),$(rust_app_$(1)_builtin),$(objtree)/.obj/apps/$(board)/$(app_mode)/$(1)/built-in.o)
app_$(1)_rust_input := $(if $(filter $(1),$(rust_apps)),$(call rust_app_lib,$(1)),$(rust_core_link_input))
app_$(1)_fel_elf := $$(app_$(1)_dir)/$(1)_fel.elf
app_$(1)_bin_elf := $$(app_$(1)_dir)/$(1)_bin.elf
app_$(1)_fel_bin := $$(app_$(1)_dir)/$(1)_fel.bin
app_$(1)_card_bin := $$(app_$(1)_dir)/$(1)_card.bin
app_$(1)_spi_bin := $$(app_$(1)_dir)/$(1)_spi.bin
app_$(1)_fel_pass1 := $$(app_$(1)_dir)/.$(1)_fel.pass1.elf
app_$(1)_bin_pass1 := $$(app_$(1)_dir)/.$(1)_bin.pass1.elf
app_$(1)_fel_nm := $$(app_$(1)_dir)/.$(1)_fel.symbols.nm
app_$(1)_bin_nm := $$(app_$(1)_dir)/.$(1)_bin.symbols.nm
app_$(1)_fel_symbols_s := $$(app_$(1)_dir)/.$(1)_fel.symbols.S
app_$(1)_bin_symbols_s := $$(app_$(1)_dir)/.$(1)_bin.symbols.S
app_$(1)_fel_symbols_o := $$(app_$(1)_dir)/.$(1)_fel.symbols.o
app_$(1)_bin_symbols_o := $$(app_$(1)_dir)/.$(1)_bin.symbols.o
.PHONY: $(1)
$(1): $$(app_$(1)_fel_bin) $$(app_$(1)_card_bin) $$(app_$(1)_spi_bin)
ifneq ($(filter y,$(CONFIG_BUILD_DEBUG) $(CONFIG_BUILD_TRACE)),)
@echo " OBJDUMP $$(app_$(1)_rel_dir)/$(1)_fel.asm"
@$$(OBJDUMP) -D $$(app_$(1)_fel_elf) > $$(app_$(1)_fel_elf:.elf=.asm)
@echo " OBJDUMP $$(app_$(1)_rel_dir)/$(1)_bin.asm"
@$$(OBJDUMP) -D $$(app_$(1)_bin_elf) > $$(app_$(1)_bin_elf:.elf=.asm)
endif
@echo "Images are in $$(app_$(1)_rel_dir)"
ifeq ($(CONFIG_BACKTRACE_FULL),y)
$$(app_$(1)_fel_pass1): $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(fel_lds)
@mkdir -p $$(dir $$@)
@$$(CC) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(fel_lds) -o $$@
$$(app_$(1)_bin_pass1): $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(bin_lds)
@mkdir -p $$(dir $$@)
@$$(CC) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(bin_lds) -o $$@
$$(app_$(1)_fel_nm): $$(app_$(1)_fel_pass1)
@$$(NM) -n -S --defined-only $$< > $$@
$$(app_$(1)_bin_nm): $$(app_$(1)_bin_pass1)
@$$(NM) -n -S --defined-only $$< > $$@
$$(app_$(1)_fel_symbols_s): $$(app_$(1)_fel_nm) $(objtree)/tools/mkbacktrace
@$(objtree)/tools/mkbacktrace $(backtrace_address_bits) $$< $$@
$$(app_$(1)_bin_symbols_s): $$(app_$(1)_bin_nm) $(objtree)/tools/mkbacktrace
@$(objtree)/tools/mkbacktrace $(backtrace_address_bits) $$< $$@
$$(app_$(1)_fel_symbols_o): $$(app_$(1)_fel_symbols_s)
@$$(CC) $$(KBUILD_CPPFLAGS) $$(KBUILD_AFLAGS) -c $$< -o $$@
$$(app_$(1)_bin_symbols_o): $$(app_$(1)_bin_symbols_s)
@$$(CC) $$(KBUILD_CPPFLAGS) $$(KBUILD_AFLAGS) -c $$< -o $$@
$$(app_$(1)_fel_elf): $$(app_$(1)_fel_symbols_o) $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(fel_lds)
@mkdir -p $$(dir $$@)
@echo " LD $$(app_$(1)_rel_dir)/$(1)_fel.elf"
@$$(CC) $$(app_$(1)_fel_symbols_o) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(fel_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@$$(NM) -n -S --defined-only $$@ > $$(app_$(1)_fel_nm)
@$(objtree)/tools/mkbacktrace $(backtrace_address_bits) $$(app_$(1)_fel_nm) $$(app_$(1)_fel_symbols_s)
@$$(CC) $$(KBUILD_CPPFLAGS) $$(KBUILD_AFLAGS) -c $$(app_$(1)_fel_symbols_s) -o $$(app_$(1)_fel_symbols_o)
@$$(CC) $$(app_$(1)_fel_symbols_o) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(fel_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@cd $(objtree) && $$(SIZE) -B -x $$(app_$(1)_rel_dir)/$(1)_fel.elf
$$(app_$(1)_bin_elf): $$(app_$(1)_bin_symbols_o) $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(bin_lds)
@mkdir -p $$(dir $$@)
@echo " LD $$(app_$(1)_rel_dir)/$(1)_bin.elf"
@$$(CC) $$(app_$(1)_bin_symbols_o) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(bin_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@$$(NM) -n -S --defined-only $$@ > $$(app_$(1)_bin_nm)
@$(objtree)/tools/mkbacktrace $(backtrace_address_bits) $$(app_$(1)_bin_nm) $$(app_$(1)_bin_symbols_s)
@$$(CC) $$(KBUILD_CPPFLAGS) $$(KBUILD_AFLAGS) -c $$(app_$(1)_bin_symbols_s) -o $$(app_$(1)_bin_symbols_o)
@$$(CC) $$(app_$(1)_bin_symbols_o) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(bin_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@cd $(objtree) && $$(SIZE) -B -x $$(app_$(1)_rel_dir)/$(1)_bin.elf
else
$$(app_$(1)_fel_elf): $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(fel_lds)
@mkdir -p $$(dir $$@)
@echo " LD $$(app_$(1)_rel_dir)/$(1)_fel.elf"
@$$(CC) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(fel_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@cd $(objtree) && $$(SIZE) -B -x $$(app_$(1)_rel_dir)/$(1)_fel.elf
$$(app_$(1)_bin_elf): $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(bin_lds)
@mkdir -p $$(dir $$@)
@echo " LD $$(app_$(1)_rel_dir)/$(1)_bin.elf"
@$$(CC) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(bin_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@cd $(objtree) && $$(SIZE) -B -x $$(app_$(1)_rel_dir)/$(1)_bin.elf
endif
$$(app_$(1)_fel_bin): $$(app_$(1)_fel_elf)
@echo " OBJCOPY $$(app_$(1)_rel_dir)/$(1)_fel.bin"
@$$(OBJCOPY) -O binary $$< $$@
$$(app_$(1)_card_bin): $$(app_$(1)_bin_elf) $(objtree)/tools/mksunxi
@echo " OBJCOPY $$(app_$(1)_rel_dir)/$(1)_card.bin"
@$$(OBJCOPY) -O binary $$< $$@
@$(objtree)/tools/mksunxi $$@ 512
$$(app_$(1)_spi_bin): $$(app_$(1)_bin_elf) $(objtree)/tools/mksunxi
@echo " OBJCOPY $$(app_$(1)_rel_dir)/$(1)_spi.bin"
@$$(OBJCOPY) -O binary $$< $$@
@$(objtree)/tools/mksunxi $$@ 8192
endef
define efex_app_template
app_$(1)_dir := $(image_root)/$(1)
app_$(1)_rel_dir := $(image_rel_root)/$(1)
app_$(1)_builtin := $(if $(filter $(1),$(rust_apps)),$(rust_app_$(1)_builtin),$(objtree)/.obj/apps/$(board)/$(app_mode)/$(1)/built-in.o)
app_$(1)_rust_input := $(if $(filter $(1),$(rust_apps)),$(call rust_app_lib,$(1)),$(rust_core_link_input))
app_$(1)_efex_elf := $$(app_$(1)_dir)/$(1)_efex.elf
app_$(1)_efex_bin := $$(app_$(1)_dir)/$(1)_efex.bin
.PHONY: $(1)
$(1): $$(app_$(1)_efex_bin)
@echo "Images are in $$(app_$(1)_rel_dir)"
$$(app_$(1)_efex_elf): $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(efex_lds)
@mkdir -p $$(dir $$@)
@echo " LD $$(app_$(1)_rel_dir)/$(1)_efex.elf"
@$$(CC) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(efex_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@cd $(objtree) && $$(SIZE) -B -x $$(app_$(1)_rel_dir)/$(1)_efex.elf
$$(app_$(1)_efex_bin): $$(app_$(1)_efex_elf) $(objtree)/tools/mksunxi
@echo " OBJCOPY $$(app_$(1)_rel_dir)/$(1)_efex.bin"
@$$(OBJCOPY) -O binary $$< $$@
@$(objtree)/tools/mksunxi $$@ 512
endef
define dram_app_template
app_$(1)_dir := $(image_root)/$(1)
app_$(1)_rel_dir := $(image_rel_root)/$(1)
app_$(1)_builtin := $(if $(filter $(1),$(rust_apps)),$(rust_app_$(1)_builtin),$(objtree)/.obj/apps/$(board)/$(app_mode)/$(1)/built-in.o)
app_$(1)_rust_input := $(if $(filter $(1),$(rust_apps)),$(call rust_app_lib,$(1)),$(rust_core_link_input))
app_$(1)_dram_elf := $$(app_$(1)_dir)/$(1)_dram.elf
app_$(1)_dram_bin := $$(app_$(1)_dir)/$(1)_dram.bin
.PHONY: $(1)
$(1): $$(app_$(1)_dram_bin)
@echo "Images are in $$(app_$(1)_rel_dir)"
$$(app_$(1)_dram_elf): $(common_builtins) $$(app_$(1)_builtin) $(board_libs) $$(app_$(1)_rust_input) $(bin_lds)
@mkdir -p $$(dir $$@)
@echo " LD $$(app_$(1)_rel_dir)/$(1)_dram.elf"
@$$(CC) $$(call link_flags,$$(app_$(1)_builtin),$$(app_$(1)_rust_input)) -T$(bin_lds) \
-Wl,-Map,$$(@:.elf=.map) -o $$@
@cd $(objtree) && $$(SIZE) -B -x $$(app_$(1)_rel_dir)/$(1)_dram.elf
$$(app_$(1)_dram_bin): $$(app_$(1)_dram_elf)
@echo " OBJCOPY $$(app_$(1)_rel_dir)/$(1)_dram.bin"
@$$(OBJCOPY) -O binary $$< $$@
endef
ifeq ($(CONFIG_EFEX),y)
$(foreach app,$(apps),$(eval $(call efex_app_template,$(app))))
else ifeq ($(CONFIG_APP_DRAM),y)
$(foreach app,$(apps),$(eval $(call dram_app_template,$(app))))
else
$(foreach app,$(apps),$(eval $(call app_template,$(app))))
endif
host_tools := mksunxi bin2array bin2asm mkbacktrace
tools: $(addprefix $(objtree)/tools/,$(host_tools)) dt2c-check
utilities:
@set -e; for utility_dir in $(utility_dirs); do \
$(MAKE) -C $(srctree)/utils/$$utility_dir \
BUILD=$(utility_root)/$$utility_dir \
CROSS_COMPILE=$(BL33_CROSS_COMPILE); \
done
@echo "Utility images are in $(utility_rel_root)"
firmware_root := $(objtree)/firmware/$(board)
firmware_rel_root := firmware/$(board)
firmware:
@if test -z "$(firmware-y)"; then \
echo "No companion firmware is defined for $(board)"; \
else \
set -e; for firmware_dir in $(firmware-y); do \
$(MAKE) -C $(srctree)/boards/$(board)/$$firmware_dir \
BUILD=$(firmware_root)/$$firmware_dir \
CROSS_COMPILE=$(FIRMWARE_CROSS_COMPILE); \
done; \
echo "Firmware images are in $(firmware_rel_root)"; \
fi
check:
@$(srctree)/utils/check-build-structure.sh
test: dt2c-check
@$(MAKE) --no-print-directory -C $(srctree)/test
docs:
@command -v $(DOXYGEN) >/dev/null 2>&1 || { \
echo "doxygen is required to build the API documentation" >&2; \
exit 1; \
}
@$(DOXYGEN) $(srctree)/Doxyfile
@echo "API documentation is in docs/api/html"
$(objtree)/tools/%: $(srctree)/tools/%.c
@mkdir -p $(dir $@)
@echo " HOSTCC tools/$(notdir $<)"
@$(HOSTCC) -O2 -std=gnu99 $< -o $@
images: tools $(apps)
@echo "All images are in $(image_rel_root)"
image: images
artifacts: images firmware utilities
help:
@echo 'Configuration:'
@echo ' <board>[_<variant>]_defconfig'
@echo ' Select a board and application mode'
@echo ' menuconfig Configure with the source-built Kconfig UI'
@echo ' release Switch build and driver logs to Release'
@echo ' savedefconfig Save a minimal configuration'
@echo ' list-defconfigs List available board configurations'
@echo 'Build:'
@echo ' all Build every application for the selected board'
@echo ' artifacts Build images, companion firmware, and utilities'
@echo ' <app> Build one application for the selected mode'
@echo ' list-apps List applications for the selected board'
@echo ' rust-ffi Generate and build the optional Rust FFI library'
@echo ' tools Build host tools'
@echo ' utilities Build standalone BL33 utility images'
@echo ' firmware Build companion firmware for the selected board'
@echo ' check Validate the Make/Kconfig tree structure'
@echo ' test Run host and QEMU API tests'
@echo ' docs Build strict Doxygen API documentation'
@echo ' clean Remove generated build files'
@echo ' mrproper Also remove configuration files'
clean:
@$(RM) -r $(objtree)/.obj $(objtree)/build $(objtree)/firmware \
$(objtree)/utilities $(srctree)/docs/api \
$(objtree)/tools/mksunxi \
$(objtree)/tools/bin2array $(objtree)/tools/bin2asm \
$(objtree)/tools/mkbacktrace \
$(objtree)/include/generated/config.h
mrproper: clean
@$(RM) -r $(objtree)/include/config $(objtree)/include/generated \
$(kconfig_out) $(KCONFIG_CONFIG) $(objtree)/defconfig
FORCE: