-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
182 lines (148 loc) · 4.42 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
BINARYNAME = fsbl
OPTFLAG = -O3
SRCDIR = src
EXTLIBDIR = third-party
LINKSCR = linkscript.ld
SD_DISK_DEV ?= /dev/disk4
SOURCES = $(SRCDIR)/startup.s \
$(SRCDIR)/main.cc \
$(SRCDIR)/systeminit.c \
$(SRCDIR)/libc_stub.c \
$(SRCDIR)/libcpp_stub.cc \
$(SRCDIR)/print.cc \
$(EXTLIBDIR)/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_ll_usart.c \
$(EXTLIBDIR)/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_ll_rcc.c \
$(EXTLIBDIR)/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal.c \
$(EXTLIBDIR)/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_ll_sdmmc.c \
$(EXTLIBDIR)/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_sd.c \
$(SRCDIR)/drivers/ddr/stm32mp1_ddr.cc \
$(SRCDIR)/drivers/ddr/stm32mp1_ram.cc \
$(SRCDIR)/drivers/ddr/ram_tests.cc \
$(SRCDIR)/uboot-port/common/memsize.c \
$(SRCDIR)/uboot-port/lib/crc32.c \
$(SRCDIR)/drivers/norflash/qspi_ll.c \
$(SRCDIR)/drivers/norflash/qspi_norflash_read.c \
$(SRCDIR)/gpt/gpt.cc \
INCLUDES = -I. \
-I$(SRCDIR) \
-I$(SRCDIR)/board_conf \
-I$(EXTLIBDIR)/STM32MP1xx_HAL_Driver/Inc \
-I$(EXTLIBDIR)/CMSIS/Core_A/Include \
-I$(EXTLIBDIR)/CMSIS/Device/ST/STM32MP1xx/Include \
-I$(SRCDIR)/drivers/ddr/ \
-I$(SRCDIR)/uboot-port/include \
-I$(SRCDIR)/uboot-port/arch/arm/include \
MCU = -mcpu=cortex-a7 -march=armv7ve -mfpu=neon-vfpv4 -mlittle-endian -mfloat-abi=hard
ARCH_CFLAGS = -DUSE_FULL_LL_DRIVER \
-DSTM32MP157Cxx \
-DSTM32MP1 \
-DCORE_CA7 \
$(EXTRA_ARCH_CFLAGS) \
ifeq ("$(BOARD_CONF)","OSD32")
ARCH_CFLAGS += -DBOARD_CONF_OSD32
else
ifeq ("$(BOARD_CONF)","DK2")
ARCH_CFLAGS += -DBOARD_CONF_DK2
else
ifneq ("$(BOARD_CONF)","")
ARCH_CFLAGS += -DBOARD_CONF_PATH=$(BOARD_CONF)
endif
endif
endif
AFLAGS = $(MCU)
CFLAGS = -g2 \
-fno-common \
$(ARCH_CFLAGS) \
$(MCU) \
$(INCLUDES) \
-fdata-sections -ffunction-sections \
-nostartfiles \
-ffreestanding \
$(EXTRACFLAGS)\
CXXFLAGS = $(CFLAGS) \
-std=c++2a \
-fno-rtti \
-fno-exceptions \
-fno-unwind-tables \
-ffreestanding \
-fno-threadsafe-statics \
-mno-unaligned-access \
-Werror=return-type \
-Wdouble-promotion \
-Wno-register \
-Wno-volatile \
$(EXTRACXXFLAGS) \
LFLAGS = -Wl,--gc-sections \
-Wl,-Map,$(BUILDDIR)/$(BINARYNAME).map,--cref \
$(MCU) \
-T $(LINKSCR) \
-nostdlib \
-nostartfiles \
-ffreestanding \
-Wl,--no-warn-rwx-segments \
$(EXTRALDFLAGS) \
DEPFLAGS = -MMD -MP -MF $(OBJDIR)/$(basename $<).d
ARCH = arm-none-eabi
CC = $(ARCH)-gcc
CXX = $(ARCH)-g++
LD = $(ARCH)-g++
AS = $(ARCH)-as
OBJCPY = $(ARCH)-objcopy
OBJDMP = $(ARCH)-objdump
GDB = $(ARCH)-gdb
SZ = $(ARCH)-size
SZOPTS = -d
ELF = $(BUILDDIR)/$(BINARYNAME).elf
HEX = $(BUILDDIR)/$(BINARYNAME).hex
BIN = $(BUILDDIR)/$(BINARYNAME).bin
OBJECTS = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(SOURCES))))
DEPS = $(addprefix $(OBJDIR)/, $(addsuffix .d, $(basename $(SOURCES))))
BUILDDIR = build
OBJDIR = $(BUILDDIR)/obj/obj
all: Makefile $(ELF) $(UIMAGENAME) image
@:
$(OBJDIR)/%.o: %.s
@mkdir -p $(dir $@)
$(info Building $< at $(OPTFLAG))
@$(AS) $(AFLAGS) $< -o $@
$(OBJDIR)/%.o: %.c $(OBJDIR)/%.d
@mkdir -p $(dir $@)
$(info Building $< at $(OPTFLAG))
@$(CC) -c $(DEPFLAGS) $(OPTFLAG) $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: %.c[cp]* $(OBJDIR)/%.d
@mkdir -p $(dir $@)
$(info Building $< at $(OPTFLAG))
@$(CXX) -c $(DEPFLAGS) $(OPTFLAG) $(CXXFLAGS) $< -o $@
$(ELF): $(OBJECTS) $(LINKSCR)
$(info Linking...)
@$(LD) $(LFLAGS) -o $@ $(OBJECTS)
$(BIN): $(ELF)
$(OBJCPY) -O binary $< $@
$(HEX): $(ELF)
@$(OBJCPY) --output-target=ihex $< $@
@$(SZ) $(SZOPTS) $(ELF)
$(BUILDDIR)/$(BINARYNAME).stm32: $(BIN)
python3 fsbl_header.py $(BUILDDIR)/$(BINARYNAME).bin $(BUILDDIR)/$(BINARYNAME).stm32
@ls -l $(BUILDDIR)/$(BINARYNAME).stm32
image: $(BUILDDIR)/$(BINARYNAME).stm32
load: image
@read -p "What is the disk device (Enter for $(SD_DISK_DEV)): " DISK && \
DISK=$${DISK:-$(SD_DISK_DEV)} && \
echo "Writing to $${DISK}s1 and $${DISK}s2" && \
sudo dd if=$(BUILDDIR)/$(BINARYNAME).stm32 of=$${DISK}s1 && \
sudo dd if=$(BUILDDIR)/$(BINARYNAME).stm32 of=$${DISK}s2 && \
diskutil unmountDisk $${DISK}
%.d: ;
clean:
rm -rf build
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEPS)
endif
.PRECIOUS: $(DEPS) $(OBJECTS) $(ELF)
.PHONY: all clean image load
.PHONY: compile_commands
compile_commands:
compiledb make
compdb -p ./ list > compile_commands.tmp 2>/dev/null
rm compile_commands.json
mv compile_commands.tmp compile_commands.json