-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
123 lines (98 loc) · 2.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
#
# DAFU Makefile
#
# Targets:
# all - make everything, look for dafu.elf inparticular
# clean - delete intermediates
# clobber - delete all build products
#
#
#
# Toolchain
CC = arm-none-eabi-gcc
OBJDUMP = arm-none-eabi-objdump
OBJCOPY = arm-none-eabi-objcopy
NM = arm-none-eabi-nm
SIZE = arm-none-eabi-size
# Basename of targets
TARGET_NAME = dafu
# Hardware configuration. Not so critical. I suspect binary would not change
# for any value here in the D21 family.
PART = SAMD21J18A
# Compiler flags.
CFLAGS = -Wall --std=gnu99 -Os -g3 \
-flto -fdata-sections -ffunction-sections -funsigned-char -funsigned-bitfields \
-mcpu=cortex-m0plus -mthumb -D __$(PART)__ -I .
# USB PID/VID and other branding values
CFLAGS += \
-D USB_PRODUCT_ID=0x7551 \
-D USB_VENDOR_ID=0x1209 \
-D USB_MANUFACTURER_STR='"Nobody"' \
-D USB_PRODUCT_STR='"DAFU Bootloader"' \
-D COPYRIGHT_NOTE='"Visit https://githib.com/opendime/DAFU"' \
-D USE_CORE_RESET
# Header file search path
PRJ_PATH = deps
INC_PATHS = \
usb \
sam0/cmsis \
sam0/include \
sam0/cmsis/samd21/include \
sam0/cmsis/samd21/source
CFLAGS += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATHS)),-I$(INC))
# Specialized linker-script here. Not the standard one!
#
LINKER_SCRIPT = link-script.ld
LDFLAGS += -flto -Wl,--gc-sections --specs=nano.specs -Wl,-T$(LINKER_SCRIPT)
C_SRCS = \
common/startup_samd21.c \
main.c \
usb.c \
common/clock.c \
my_customizations.c \
deps/usb/class/dfu/dfu.c \
deps/usb/samd/usb_samd.c \
deps/usb/usb_requests.c
OBJS = $(addsuffix .o, $(basename $(C_SRCS) $(ASM_SRCS)))
TARGET_ELF = $(TARGET_NAME).elf
TARGETS = $(TARGET_NAME).hex $(TARGET_NAME).lss $(TARGET_NAME).bin $(TARGET_NAME).sym $(TARGET_NAME).o
all: $(TARGETS)
# recompile on any change, because with a small project like this...
$(OBJS): Makefile $(C_SRCS) $(ASM_SRCS)
$(TARGETS): $(TARGET_ELF) Makefile
# link step
$(TARGET_ELF): $(OBJS) $(LINKER_SCRIPT) Makefile
$(CC) $(CFLAGS) -o $(TARGET_ELF) $(LDFLAGS) $(OBJS)
$(SIZE) -Ax $@
# detailed listing, very handy
%.lss: $(TARGET_ELF)
$(OBJDUMP) -h -S $< > $@
# symbol dump, meh
%.sym: $(TARGET_ELF)
$(NM) -n $< > $@
# intel HEX format
%.hex: $(TARGET_ELF)
$(OBJCOPY) -O ihex $< $@
# raw binary
%.bin: $(TARGET_ELF)
$(OBJCOPY) -O binary $< $@
# a binary of just the ROM area, ready to be linked into another program.
$(TARGET_NAME).o: $(TARGET_ELF)
$(OBJCOPY) --rename-section .text=.vectors.bootloader \
--prefix-symbols=dafu_ \
--pad-to 0x1000 --gap-fill 0xff \
$(TARGET_ELF) $@
$(OBJDUMP) -h $@
$(SIZE) -Ax $@
clean:
$(RM) $(OBJS)
clobber: clean
$(RM) $(TARGETS)
debug:
@echo CFLAGS = $(CFLAGS)
@echo
@echo C_SRCS = $(C_SRCS)
@echo
@echo OBJS = $(OBJS)
tags:
ctags -f .tags *.[ch] -R deps/sam0 deps/usb common