-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rules.mk
207 lines (174 loc) · 5.74 KB
/
Rules.mk
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
#
# Rules.mk
#
# Circle - A C++ bare metal environment for Raspberry Pi
# Copyright (C) 2014-2020 R. Stange <rsta2@o2online.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
CIRCLEHOME ?= ..
-include $(CIRCLEHOME)/Config.mk
-include $(CIRCLEHOME)/Config2.mk # is not overwritten by "configure"
AARCH ?= 32
RASPPI ?= 1
PREFIX ?= arm-none-eabi-
PREFIX64 ?= aarch64-none-elf-
POSTFIX ?=
# see: doc/stdlib-support.txt
STDLIB_SUPPORT ?= 1
# set this to 0 to globally disable dependency checking
CHECK_DEPS ?= 1
# set this to "softfp" if you want to link specific libraries
FLOAT_ABI ?= hard
# set this to 1 to enable garbage collection on sections, may cause side effects
GC_SECTIONS ?= 0
CC = $(PREFIX)gcc$(POSTFIX)
CPP = $(PREFIX)g++$(POSTFIX)
AS = $(CC)
LD = $(PREFIX)ld$(POSTFIX)
AR = $(PREFIX)ar$(POSTFIX)
ifeq ($(strip $(AARCH)),32)
ifeq ($(strip $(RASPPI)),1)
ARCH ?= -DAARCH=32 -mcpu=arm1176jzf-s -marm -mfpu=vfp -mfloat-abi=$(FLOAT_ABI)
TARGET ?= kernel
else ifeq ($(strip $(RASPPI)),2)
ARCH ?= -DAARCH=32 -mcpu=cortex-a7 -marm -mfpu=neon-vfpv4 -mfloat-abi=$(FLOAT_ABI)
TARGET ?= kernel7
else ifeq ($(strip $(RASPPI)),3)
ARCH ?= -DAARCH=32 -mcpu=cortex-a53 -marm -mfpu=neon-fp-armv8 -mfloat-abi=$(FLOAT_ABI)
TARGET ?= kernel8-32
else ifeq ($(strip $(RASPPI)),4)
ARCH ?= -DAARCH=32 -mcpu=cortex-a72 -marm -mfpu=neon-fp-armv8 -mfloat-abi=$(FLOAT_ABI)
TARGET ?= kernel7l
else
$(error RASPPI must be set to 1, 2, 3 or 4)
endif
LOADADDR = 0x8000
else ifeq ($(strip $(AARCH)),64)
ifeq ($(strip $(RASPPI)),3)
ARCH ?= -DAARCH=64 -mcpu=cortex-a53 -mlittle-endian -mcmodel=small
TARGET ?= kernel8
else ifeq ($(strip $(RASPPI)),4)
ARCH ?= -DAARCH=64 -mcpu=cortex-a72 -mlittle-endian -mcmodel=small
TARGET ?= kernel8-rpi4
else
$(error RASPPI must be set to 3 or 4)
endif
PREFIX = $(PREFIX64)
LOADADDR = 0x80000
else
$(error AARCH must be set to 32 or 64)
endif
ifneq ($(strip $(STDLIB_SUPPORT)),0)
MAKE_VERSION_MAJOR := $(firstword $(subst ., ,$(MAKE_VERSION)))
ifneq ($(filter 0 1 2 3,$(MAKE_VERSION_MAJOR)),)
$(error STDLIB_SUPPORT > 0 requires GNU make 4.0 or newer)
endif
endif
ifeq ($(strip $(STDLIB_SUPPORT)),3)
LIBSTDCPP != $(CPP) $(ARCH) -print-file-name=libstdc++.a
EXTRALIBS += $(LIBSTDCPP)
LIBGCC_EH != $(CPP) $(ARCH) -print-file-name=libgcc_eh.a
ifneq ($(strip $(LIBGCC_EH)),libgcc_eh.a)
EXTRALIBS += $(LIBGCC_EH)
endif
ifeq ($(strip $(AARCH)),64)
CRTBEGIN != $(CPP) $(ARCH) -print-file-name=crtbegin.o
CRTEND != $(CPP) $(ARCH) -print-file-name=crtend.o
endif
else
CPPFLAGS += -fno-exceptions -fno-rtti -nostdinc++
endif
ifeq ($(strip $(STDLIB_SUPPORT)),0)
CFLAGS += -nostdinc
else
LIBGCC != $(CPP) $(ARCH) -print-file-name=libgcc.a
EXTRALIBS += $(LIBGCC)
endif
ifeq ($(strip $(STDLIB_SUPPORT)),1)
LIBM != $(CPP) $(ARCH) -print-file-name=libm.a
ifneq ($(strip $(LIBM)),libm.a)
EXTRALIBS += $(LIBM)
endif
endif
ifeq ($(strip $(GC_SECTIONS)),1)
CFLAGS += -ffunction-sections -fdata-sections
LDFLAGS += --gc-sections
endif
OPTIMIZE ?= -O2
INCLUDE += -I $(CIRCLEHOME)/include -I $(CIRCLEHOME)/addon -I $(CIRCLEHOME)/app/lib \
-I $(CIRCLEHOME)/addon/vc4 -I $(CIRCLEHOME)/addon/vc4/interface/khronos/include
DEFINE += -D__circle__ -DRASPPI=$(RASPPI) -DSTDLIB_SUPPORT=$(STDLIB_SUPPORT) \
-D__VCCOREVER__=0x04000000 -U__unix__ -U__linux__ #-DNDEBUG
AFLAGS += $(ARCH) $(DEFINE) $(INCLUDE) $(OPTIMIZE)
CFLAGS += $(ARCH) -Wall -fsigned-char -ffreestanding $(DEFINE) $(INCLUDE) $(OPTIMIZE) -g
CPPFLAGS+= $(CFLAGS) -std=c++14 -Wno-aligned-new
LDFLAGS += --section-start=.init=$(LOADADDR)
ifeq ($(strip $(CHECK_DEPS)),1)
DEPS = $(OBJS:.o=.d)
endif
%.o: %.S
@echo " AS $@"
@$(AS) $(AFLAGS) -c -o $@ $<
%.o: %.c
@echo " CC $@"
@$(CC) $(CFLAGS) -std=gnu99 -c -o $@ $<
%.o: %.cpp
@echo " CPP $@"
@$(CPP) $(CPPFLAGS) -c -o $@ $<
%.d: %.S
@$(AS) $(AFLAGS) -M -MG -MT $*.o -MT $@ -MF $@ $<
%.d: %.c
@$(CC) $(CFLAGS) -M -MG -MT $*.o -MT $@ -MF $@ $<
%.d: %.cpp
@$(CPP) $(CPPFLAGS) -M -MG -MT $*.o -MT $@ -MF $@ $<
$(TARGET).img: $(OBJS) $(LIBS) $(CIRCLEHOME)/circle.ld
@echo " LD $(TARGET).elf"
@$(LD) -o $(TARGET).elf -Map $(TARGET).map $(LDFLAGS) \
-T $(CIRCLEHOME)/circle.ld $(CRTBEGIN) $(OBJS) \
--start-group $(LIBS) $(EXTRALIBS) --end-group $(CRTEND)
@echo " DUMP $(TARGET).lst"
@$(PREFIX)objdump$(POSTFIX) -d $(TARGET).elf | $(PREFIX)c++filt$(POSTFIX) > $(TARGET).lst
@echo " COPY $(TARGET).img"
@$(PREFIX)objcopy$(POSTFIX) $(TARGET).elf -O binary $(TARGET).img
@echo -n " WC $(TARGET).img => "
@wc -c < $(TARGET).img
clean:
rm -f *.d *.o *.a *.elf *.lst *.img *.hex *.cir *.map *~ $(EXTRACLEAN)
ifneq ($(strip $(SDCARD)),)
install: $(TARGET).img
cp $(TARGET).img $(SDCARD)
sync
endif
ifneq ($(strip $(TFTPHOST)),)
tftpboot: $(TARGET).img
tftp -m binary $(TFTPHOST) -c put $(TARGET).img
endif
#
# Eclipse support
#
SERIALPORT ?= /dev/ttyUSB0
USERBAUD ?= 115200
FLASHBAUD ?= 115200
REBOOTMAGIC ?=
$(TARGET).hex: $(TARGET).img
@echo " COPY $(TARGET).hex"
@$(PREFIX)objcopy $(TARGET).elf -O ihex $(TARGET).hex
flash: $(TARGET).hex
ifneq ($(strip $(REBOOTMAGIC)),)
python3 $(CIRCLEHOME)/tools/reboottool.py $(REBOOTMAGIC) $(SERIALPORT) $(USERBAUD)
endif
python3 $(CIRCLEHOME)/tools/flasher.py $(TARGET).hex $(SERIALPORT) $(FLASHBAUD)
monitor:
putty -serial $(SERIALPORT) -sercfg $(USERBAUD)