summaryrefslogtreecommitdiff
path: root/usb-device-massstorage-project/Makefile
blob: 6b2656559028d6bb4af7557b00b1301796aab5a7 (plain)
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
# ----------------------------------------------------------------------------
#         ATMEL Microcontroller Software Support 
# ----------------------------------------------------------------------------
# Copyright (c) 2008, Atmel Corporation
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the disclaimer below.
#
# Atmel's name may not be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
# DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------------

#    Makefile for compiling usb-device-massstorage-project

#-------------------------------------------------------------------------------
#        User-modifiable options
#-------------------------------------------------------------------------------

# Chip & board used for compilation
# (can be overriden by adding CHIP=chip and BOARD=board to the command-line)
CHIP  = at91sam3u4
BOARD = at91sam3u-ek

# Trace level used for compilation
# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
# TRACE_LEVEL_DEBUG      5
# TRACE_LEVEL_INFO       4
# TRACE_LEVEL_WARNING    3
# TRACE_LEVEL_ERROR      2
# TRACE_LEVEL_FATAL      1
# TRACE_LEVEL_NO_TRACE   0
TRACE_LEVEL = 3

# Optimization level, put in comment for debugging
OPTIMIZATION = -O0

# AT91 library directory
AT91LIB = ../../at91lib

# External library
EXT_LIBS= ../external_libs

# Output file basename
OUTPUT = usb-device-massstorage-project-$(BOARD)-$(CHIP)

# Compile with chip specific features
include $(AT91LIB)/boards/$(BOARD)/$(CHIP)/chip.mak

# Compile for all memories available on the board (this sets $(MEMORIES))
include $(AT91LIB)/boards/$(BOARD)/board.mak

# Output directories
BIN = bin
OBJ = obj

#-------------------------------------------------------------------------------
#        Tools
#-------------------------------------------------------------------------------

# Tool suffix when cross-compiling
CROSS_COMPILE = arm-none-eabi-

# Compilation tools
CC = $(CROSS_COMPILE)gcc
SIZE = $(CROSS_COMPILE)size
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy

# Flags
INCLUDES += -I$(AT91LIB)/boards/$(BOARD)
INCLUDES += -I$(AT91LIB)/peripherals
INCLUDES += -I$(AT91LIB)/drivers
INCLUDES += -I$(AT91LIB)/memories
INCLUDES += -I$(AT91LIB)
INCLUDES += -I$(EXT_LIBS)

ifeq ($(CHIP_CORE), cortexm3)
TARGET_OPTS = -mcpu=cortex-m3 -mthumb
else
TARGET_OPTS =
endif

CFLAGS += $(TARGET_OPTS)
CFLAGS += -Wall -mlong-calls -ffunction-sections
CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL)
ASFLAGS = $(TARGET_OPTS) -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
LDFLAGS = -g $(OPTIMIZATION) -nostartfiles $(TARGET_OPTS) -Wl,-Map=$(OUTPUT).map,--cref,--gc-sections

ifdef ORIGIN_SD_PORT
CFLAGS += -DORIGIN_SD_PORT_$(ORIGIN_SD_PORT)
endif

#-------------------------------------------------------------------------------
#         Files
#-------------------------------------------------------------------------------

# Objects built from C source files

# at91lib/usb/common/core
VPATH += $(AT91LIB)/usb/common/core
C_OBJECTS += USBConfigurationDescriptor.o
C_OBJECTS += USBEndpointDescriptor.o
C_OBJECTS += USBFeatureRequest.o
C_OBJECTS += USBGenericDescriptor.o
C_OBJECTS += USBGenericRequest.o
C_OBJECTS += USBGetDescriptorRequest.o
C_OBJECTS += USBInterfaceRequest.o
C_OBJECTS += USBSetAddressRequest.o
C_OBJECTS += USBSetConfigurationRequest.o

# at91lib/usb/device/core
VPATH += $(AT91LIB)/usb/device/core
#C_OBJECTS += USBD_OTGHS.o
#C_OBJECTS += USBD_UDP.o
C_OBJECTS += USBD_UDPHS.o
C_OBJECTS += USBDCallbacks_Initialized.o
#C_OBJECTS += USBDCallbacks_RequestReceived.o
C_OBJECTS += USBDCallbacks_Reset.o
#C_OBJECTS += USBDCallbacks_Resumed.o
#C_OBJECTS += USBDCallbacks_Suspended.o
C_OBJECTS += USBDDriver.o
C_OBJECTS += USBDDriverCb_IfSettingChanged.o
#C_OBJECTS += USBDDriverCb_CfgChanged.o

# at91lib/usb/device/massstorage
VPATH += $(AT91LIB)/usb/device/massstorage
VPATH += $(AT91LIB)/usb/common/massstorage
C_OBJECTS += MSDDriver.o
C_OBJECTS += MSDDriverDescriptors.o
C_OBJECTS += MSDDStateMachine.o
C_OBJECTS += MSDLun.o
C_OBJECTS += SBCMethods.o

# at91lib/utility
VPATH += $(AT91LIB)/utility
C_OBJECTS += led.o
C_OBJECTS += math.o
C_OBJECTS += stdio.o

# at91lib/peripherals
PERIPH = $(AT91LIB)/peripherals
VPATH += $(PERIPH)/irq
VPATH += $(PERIPH)/dbgu
VPATH += $(PERIPH)/eefc
VPATH += $(PERIPH)/efc
VPATH += $(PERIPH)/pio
VPATH += $(PERIPH)/pmc
VPATH += $(PERIPH)/tc
VPATH += $(PERIPH)/mci
VPATH += $(PERIPH)/dma
VPATH += $(PERIPH)/hsmc4
C_OBJECTS += dbgu.o
C_OBJECTS += pio.o
C_OBJECTS += pio_it.o
C_OBJECTS += pmc.o
C_OBJECTS += tc.o

# at91lib/drivers
VPATH += $(AT91LIB)/drivers/dmad

# at91lib/boards/at91xxx/
VPATH += $(AT91LIB)/boards/$(BOARD)
VPATH += $(AT91LIB)/boards/$(BOARD)/$(CHIP)
C_OBJECTS += board_lowlevel.o
C_OBJECTS += trace.o
C_OBJECTS += board_memories.o

# at91lib/memories
VPATH += $(AT91LIB)/memories
C_OBJECTS += Media.o

# external_libs
VPATH += $(EXT_LIBS)/cmsis

ifeq ($(CHIP_IP_MCI), MCI_DMA)
VPATH += $(AT91LIB)/memories/sdmmc
C_OBJECTS += sdmmc_mci.o
C_OBJECTS += MEDSdcard.o
C_OBJECTS += mci_hs.o
C_OBJECTS += dma.o
C_OBJECTS += dmad.o
endif

ifeq ($(CHIP_IP_MCI), MCI_PDC)
VPATH += $(AT91LIB)/memories/sdmmc
C_OBJECTS += sdmmc_mci.o
C_OBJECTS += MEDSdcard.o
C_OBJECTS += mci.o
endif

ifeq ($(CHIP_CORE), cortexm3)
C_OBJECTS += MEDRamDisk.o
else
C_OBJECTS += MEDSdram.o
C_OBJECTS += MEDDdram.o
endif

# at91lib/memories/flash
VPATH += $(AT91LIB)/memories/flash

ifneq ($(CHIP_CORE), cortexm3)
ifeq ($(CHIP_IP_EFC),EFC)
C_OBJECTS += efc.o
C_OBJECTS += flashd_efc.o
C_OBJECTS += MEDFlash.o
else ifeq ($(CHIP_IP_EFC),EEFC)
C_OBJECTS += eefc.o
C_OBJECTS += flashd_eefc.o
C_OBJECTS += MEDFlash.o
endif
endif

# at91lib/memories/nandflash
#VPATH += $(AT91LIB)/memories/nandflash

#C_OBJECTS += MEDNandFlash.o
#C_OBJECTS += EccNandFlash.o
##C_OBJECTS += SkipBlockNandFlash.o
#C_OBJECTS += NandFlashModel.o
#C_OBJECTS += NandFlashModelList.o
#C_OBJECTS += NandSpareScheme.o
#C_OBJECTS += ManagedNandFlash.o
#C_OBJECTS += MappedNandFlash.o
#C_OBJECTS += TranslatedNandFlash.o
#C_OBJECTS += math.o
#C_OBJECTS += hamming.o

# Objects for chips with nfc
#ifeq ($(CHIP_IP_NAND), NAND_CTRL)
#C_OBJECTS += NfcRawNandFlash.o
#C_OBJECTS += hsmc4.o
#else
#C_OBJECTS += RawNandFlash.o
#endif

#Objects for chips with HW ECC
ifeq ($(CHIP_IP_ECC), HW_ECC)
C_OBJECTS += hsmc4_ecc.o
endif

# Individual objects for different chips
ifeq ($(CHIP_CORE), cortexm3)
VPATH += $(PERIPH)/systick

C_OBJECTS += nvic.o
C_OBJECTS += exceptions.o
C_OBJECTS += board_cstartup_gnu.o
C_OBJECTS += core_cm3.o
C_OBJECTS += systick.o
else
VPATH += $(PERIPH)/cp15
VPATH += $(PERIPH)/pit

C_OBJECTS += aic.o
C_OBJECTS += cp15.o
C_OBJECTS += pit.o
endif

# usb-device-massstorage-project
C_OBJECTS += main.o

# Objects built from Assembly source files
ifneq ($(CHIP_CORE), cortexm3)
# at91lib/boards/at91xxx/
ASM_OBJECTS += board_cstartup.o
# at91lib/peripherals
ASM_OBJECTS += cp15_asm.o
endif

# Append OBJ and BIN directories to output filename
OUTPUT := $(BIN)/$(OUTPUT)

#-------------------------------------------------------------------------------
#        Rules
#-------------------------------------------------------------------------------

all: $(BIN) $(OBJ) $(MEMORIES)

$(BIN) $(OBJ):
	mkdir $@

define RULES
C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))

$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
	$(CC) $(LDFLAGS) -T"$(AT91LIB)/boards/$(BOARD)/$(CHIP)/$$@.lds" -o $(OUTPUT)-$$@.elf $$^
	$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
	$(SIZE) $$^ $(OUTPUT)-$$@.elf

$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
	$(CC) $(CFLAGS) -D$(1) -c -o $$@ $$<

$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
	$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<

debug_$(1): $(1)
	perl ../resources/gdb/debug.pl $(OUTPUT)-$(1).elf

endef

$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))

clean:
	-rm -f $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf

personal git repositories of Harald Welte. Your mileage may vary