-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
186 lines (151 loc) · 4.75 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
179
180
181
182
183
184
185
186
# Makefile for Punch BOOT
ifndef BOARD
$(error BOARD is not defined)
endif
Q ?= @
# Default settings and apps
TARGET = pb
PB_VERSION = $(shell cat version.txt)
BPAK ?= $(shell which bpak)
KEYSTORE_BPAK ?= pki/internal_keystore.bpak
PYTHON ?= $(shell which python3)
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
AR=$(CROSS_COMPILE)ar
SIZE=$(CROSS_COMPILE)size
STRIP=$(CROSS_COMPILE)strip
OBJCOPY=$(CROSS_COMPILE)objcopy
# Helper macros
unquote = $(subst $\",,$(1))
BUILD_DIR ?= build-$(lastword $(subst /, ,$(BOARD)))
KCONFIG_CONFIG ?= .config
BUILD_CONFIG ?= $(BUILD_DIR)/.config
$(shell mkdir -p $(BUILD_DIR))
$(shell BOARD=$(BOARD) KCONFIG_CONFIG=$(KCONFIG_CONFIG) $(PYTHON) scripts/genconfig.py --header-path $(BUILD_DIR)/config.h --config-out $(BUILD_CONFIG) src/Kconfig)
include $(BUILD_CONFIG)
ifdef TIMING_REPORT
LOGLEVEL = 0
TIMING_REPORT=1
else
TIMING_REPORT=0
endif
cflags-y = -std=c99
cflags-y += -O$(call unquote,$(CONFIG_OPTIMIZE))
cflags-$(CONFIG_DEBUG_SYMBOLS) += -g
cflags-y += -nostdlib -nostartfiles -nostdinc
cflags-y += -ffunction-sections
cflags-y += -fdata-sections
cflags-y += -fno-omit-frame-pointer
cflags-y += -DPB_VERSION=\"$(PB_VERSION)\"
cflags-y += -DLOGLEVEL=$(CONFIG_LOGLEVEL)
cflags-y += -DTIMING_REPORT=$(TIMING_REPORT)
cflags-y += -fno-common -fno-builtin
cflags-y += -ffreestanding -fno-exceptions
cflags-y += -fstack-usage
cflags-y += -fno-stack-protector
cflags-y += -MMD -MP
# Include path
cflags-y += -I src/
cflags-y += -I include/
cflags-y += -I include/libc
cflags-y += -I $(BOARD)/include
cflags-y += -I $(BUILD_DIR)
# Warnings
cflags-y += -Wall
cflags-y += -Wextra
cflags-y += -Wunused-result
#cflags-y += -Wmissing-include-dirs
cflags-y += -Wunused
cflags-y += -Wdisabled-optimization
cflags-y += -Wvla
cflags-y += -Wshadow
cflags-y += -Wno-unused-parameter
cflags-y += -Wextra
#cflags-y += -Wmissing-declarations
cflags-y += -Wmissing-format-attribute
cflags-y += -Wmissing-prototypes
cflags-y += -Wpointer-arith
cflags-y += -Wredundant-decls
cflags-y += -Waggregate-return
# Bootloader
src-y = src/main.c
src-y += keystore.c
src-y += src/delay.c
src-$(CONFIG_ENABLE_TIMESTAMPING) += src/timestamp.c
src-$(CONFIG_CRYPTO) += src/crypto.c
src-$(CONFIG_BIO_CORE) += src/bio.c
src-$(CONFIG_DEVICE_UUID) += src/device_uuid.c
src-$(CONFIG_SELF_TEST) += src/self_test.c
src-y += src/wire.c
src-y += src/console.c
src-y += src/rot.c
src-y += src/slc.c
include src/drivers/*/makefile.mk
include src/boot/makefile.mk
include src/lib/makefile.mk
include $(BOARD)/makefile.mk
include src/arch/*/makefile.mk
include src/plat/*/makefile.mk
include src/cm/makefile.mk
ldflags-y += -Map=$(BUILD_DIR)/pb.map
ldflags-y += --defsym=PB_ENTRY=$(PB_ENTRY)
ldflags-y += --defsym=PB_STACK_SIZE_KiB=$(CONFIG_STACK_SIZE_KiB)
ldflags-y += -T$(CONFIG_LINK_FILE) --build-id=none
ldflags-y += --gc-sections
OBJS =
OBJS += $(patsubst %.c, $(BUILD_DIR)/%.o, $(src-y))
OBJS += $(patsubst %.S, $(BUILD_DIR)/%.o, $(asm-y))
BLOB_OBJS = $(patsubst %.bin, $(BUILD_DIR)/%.bino, $(blobs-y))
BLOB_OBJS2 = $(patsubst %.bin, $(BUILD_DIR)/%.bino, $(notdir $(blobs-y)))
DEPS = $(OBJS:.o=.d)
FINAL_OUTPUT = $(BUILD_DIR)/$(TARGET).bin
.PHONY: keystore menuconfig
menuconfig:
$(Q)BOARD=$(BOARD) $(PYTHON) scripts/menuconfig.py src/Kconfig
all: $(BUILD_DIR)/$(TARGET).bin $(plat-y)
$(Q)$(SIZE) -x -t -B $(BUILD_DIR)/$(TARGET)
@echo "Success, final output: $(FINAL_OUTPUT)"
$(BUILD_DIR)/keystore.o:
@echo GEN $(BUILD_DIR)/keystore.c
$(Q)$(BPAK) generate keystore --name pb $(CONFIG_KEYSTORE) --decorate > $(BUILD_DIR)/keystore.c
$(Q)$(CC) -c $(cflags-y) $(BUILD_DIR)/keystore.c -o $(BUILD_DIR)/keystore.o
$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET)
@echo OBJCOPY $< $@
$(Q)cp $< $<_unstripped
$(Q)$(STRIP) --strip-all $<
$(Q)$(OBJCOPY) -O binary -R .comment $< $@
$(BUILD_DIR)/$(TARGET): $(BUILD_DIR)/keystore.o $(OBJS) $(BLOB_OBJS)
@echo LD $@
$(Q)$(LD) $(ldflags-y) $(OBJS) $(BLOB_OBJS2) $(LIBS) -o $@
$(BUILD_DIR)/%.bino: %.bin
@mkdir -p $(@D)
@mkdir -p blobs/
@mkdir -p $(BUILD_DIR)/blobs
@cp $< blobs/
@echo BLOB $< $(notdir $<)
$(Q)$(OBJCOPY) -I binary -O $(ARCH_OUTPUT) -B $(ARCH) blobs/$(notdir $<) $(BUILD_DIR)/$(notdir $@)
$(BUILD_DIR)/%.o: %.S
@mkdir -p $(@D)
@echo AS $<
$(Q)$(CC) -D__ASSEMBLY__ -c $(cflags-y) $< -o $@
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(@D)
@echo CC $<
$(Q)$(CC) -c $(cflags-y) $< -o $@
clean:
@-rm -rf $(BUILD_DIR)/
@-rm -rf *.gcov
install: all
@test -d $(INSTALL_DIR) || echo "You must set INSTALL_DIR"
@test -d $(INSTALL_DIR)
@echo Installing $(FINAL_OUTPUT) to '$(INSTALL_DIR)'
@cp $(FINAL_OUTPUT) $(INSTALL_DIR)
gcovr:
@gcovr --gcov-exclude src/plat \
--gcov-exclude uuid \
--gcov-exclude src/fdt \
--gcov-exclude tests \
--gcov-exclude src/lib \
--gcov-exclude bearssl
.DEFAULT_GOAL := all
-include $(DEPS)