-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Makefile.lpc21
281 lines (217 loc) · 7.39 KB
/
Makefile.lpc21
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
# Hey Emacs, this is a -*- makefile -*-
#
# Copyright (C) 2003-2005 Pascal Brisset, Antoine Drouin
#
# This file is part of paparazzi.
#
# paparazzi 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 2, or (at your option)
# any later version.
#
# paparazzi 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 paparazzi; see the file COPYING. If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
#
# This is the common Makefile for the arm7-target.
#
#TODO: this is not needed in some cases (e.g. ap target as it is defined there already)
# but it is needed for other targets like tunnel
# only define here or elsewhere?
SRC_ARCH = arch/lpc21
# Launch with "make Q=''" to get full command display
Q=@
#
# find compiler toolchain
#
ALLOW_OLD_ARM_MULTILIB_TOOLCHAIN = 1
include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-toolchain
#
# if the new arm-none-eabi multilib compiler was not found try the old arm-elf one
#
ifeq ($(CC),)
CC = $(shell which arm-elf-gcc)
LD = $(shell which arm-elf-gcc)
CP = $(shell which arm-elf-objcopy)
DMP = $(shell which arm-elf-objdump)
NM = $(shell which arm-elf-nm)
SIZE = $(shell which arm-elf-size)
endif
# MCU name and submodel
MCU = arm7tdmi
THUMB = -mthumb
THUMB_IW = -mthumb-interwork
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
#FLASH_MODE=ISP
SRCARM = $($(TARGET).srcs)
ASRCARM = crt0.S
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
OPT ?= s
CSTANDARD = -std=gnu99
CINCS = $(INCLUDES) -I$(SRC_ARCH)/include
# Compiler flags.
CFLAGS = $(CINCS)
CFLAGS += -O$(OPT)
# CFLAGS += -malignment-traps
CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(notdir $(subst $(suffix $<),.lst,$<))
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -finline-limit=1200 --param inline-unit-growth=100
# flags for warnings
CFLAGS += -Wall -Wextra -Wunused
CFLAGS += -Wcast-qual
CFLAGS += -Wcast-align
CFLAGS += -Wpointer-arith
CFLAGS += -Wswitch-default
CFLAGS += -Wredundant-decls -Wmissing-declarations
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -Wshadow
CFLAGS += -Wnested-externs
CFLAGS += $(CSTANDARD)
CFLAGS += $($(TARGET).CFLAGS) $(USER_CFLAGS)
# Assembler flags.
ASFLAGS = -Wa,-adhlns=$(OBJDIR)/$(notdir $(<:.S=.lst))
#Additional libraries.
MATH_LIB = -lm
# Linker flags.
LDFLAGS = -n -nostartfiles -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref
LDFLAGS += -lc
LDFLAGS += $(MATH_LIB)
LDFLAGS += -lc -lgcc
LDFLAGS += $(CPLUSPLUS_LIB)
LDFLAGS += -Wl,--gc-sections
ifndef LDSCRIPT
ifeq ($(FLASH_MODE),ISP)
LDSCRIPT = $(SRC_ARCH)/LPC2148-ROM.ld
else
LDSCRIPT = $(SRC_ARCH)/LPC2148-ROM-bl.ld
endif
endif
LDFLAGS +=-T$(LDSCRIPT)
# ---------------------------------------------------------------------------
# Flash-Programming support using lpc21isp by Martin Maurer
# Settings and variables:
LPC21ISP = lpc21isp
LPC21ISP_PORT ?= /dev/ttyS0
LPC21ISP_FLASHFILE = $(OBJDIR)/$(TARGET).hex
# verbose output:
#LPC21ISP_DEBUG = -debug
# enter bootloader via RS232 DTR/RTS (only if hardware supports this
# feature - see Philips AppNote):
ifndef LPC21ISP_CONTROL
LPC21ISP_CONTROL =
# -control
endif
# ---------------------------------------------------------------------------
# Flash-Programming support using lpc21iap by Martin Muller (usb bootloader)
LPC21IAP = $(PAPARAZZI_SRC)/sw/ground_segment/lpc21iap/lpc21iap
# ---------------------------------------------------------------------------
# Flash-Programming support using openocd
OOCD ?= openocd
OOCD_INTERFACE = arm-usb-ocd
OOCD_TARGET = csc
# Define all object files.
COBJ = $(SRC:%.c=$(OBJDIR)/%.o)
AOBJ = $(ASRC:%.S=$(OBJDIR)/%.o)
COBJARM = $(SRCARM:%.c=$(OBJDIR)/%.o)
AOBJARM = $(ASRCARM:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(ASRCARM:.S=.lst) $(SRC:.c=.lst) $(SRCARM:.c=.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. $(CFLAGS)
ALL_ASFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp $(ASFLAGS)
# some common informative targets
include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-common
# Default target.
all: printcommands sizebefore build sizeafter
# depend order only for parallel make
sizebefore: | printcommands
build: | printcommands sizebefore
sizeafter: | build
build: $(OBJDIR) elf hex lss sym
$(OBJDIR):
@echo CREATING object dir $(OBJDIR)
@test -d $(OBJDIR) || mkdir -p $(OBJDIR)
elf: $(OBJDIR)/$(TARGET).elf
hex: $(OBJDIR)/$(TARGET).hex
lss: $(OBJDIR)/$(TARGET).lss
sym: $(OBJDIR)/$(TARGET).sym
# Program the device.
upload program: $(OBJDIR)/$(TARGET).hex
ifeq ($(FLASH_MODE),IAP)
$(SUDO) $(LPC21IAP) $(OBJDIR)/$(TARGET).elf
else ifeq ($(FLASH_MODE),JTAG)
@echo "Using OOCD = $(OOCD)"
@echo -e " OOCD\t$<"
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
-f board/$(OOCD_TARGET).cfg \
-c init \
-c "reset halt" \
-c "flash write_image erase $(OBJDIR)/$(TARGET).bin 0x08000000" \
-c reset \
-c shutdown
else
@echo
$(LPC21ISP) $(LPC21ISP_CONTROL) $(LPC21ISP_DEBUG) $(LPC21ISP_FLASHFILE) $(LPC21ISP_PORT) $(LPC21ISP_BAUD) $(LPC21ISP_XTAL)
endif
# Create final output files (.hex, .eep) from ELF output file.
# TODO: handling the .eeprom-section should be redundant
%.hex: %.elf
@echo OBJC $@
$(Q)$(CP) -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
# testing: option -C
%.lss: %.elf
@echo OBJD $@
$(Q)$(DMP) -h -S -C $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo NM $@
$(Q)$(NM) -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(OBJDIR)/$(TARGET).elf
.PRECIOUS : $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ)
%.elf: $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ)
@echo LD $@
$(Q)$(CC) $(THUMB) $(ALL_CFLAGS) $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) --output $@ $(LDFLAGS) $($(TARGET).LDFLAGS)
# Compile: create object files from C source files. ARM-only
$(OBJDIR)/%.o : %.c $(OBJDIR)/../Makefile.ac
@echo CC $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(Q)$(CC) -MMD -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
$(OBJDIR)/%.o : $(SRC_ARCH)/lpcusb/%.c $(OBJDIR)/../Makefile.ac
@echo CC $@
$(Q)$(CC) -MMD -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
# grab files in var/aircrafts/$(AIRCRAFT)/$(TARGET) aka $(OBJDIR)
#$(OBJDIR)/%.o : $(OBJDIR)/%.c
# @echo CC $@
# $(Q)$(CC) -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
# Assemble: create object files from assembler source files. ARM/Thumb
$(AOBJ) : $(OBJDIR)/%.o : %.S
@echo AS $@
$(Q)$(CC) -c $(THUMB) $(ALL_ASFLAGS) $< -o $@
# Assemble: create object files from assembler source files. ARM-only
$(AOBJARM) : $(OBJDIR)/%.o : $(SRC_ARCH)/%.S
@echo AS $@
$(Q)$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Listing of phony targets.
.PHONY : all build elf hex lss sym load upload program
#
# Dependencies
#
DEPS = $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.c=.d))
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif