]> git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/fnordlicht-bootloader/Makefile
reference eeprom contents
[fnordlicht-mini] / firmware / fnordlicht-bootloader / Makefile
1 ####################################################
2 # fnordlicht-ng Makefile
3 ####################################################
4
5 # ATTENTION:
6 # Any of these variables are overridden with the values from the file
7 # "config.mk", you can tune your settings there. The file "config.mk" is not
8 # under version control.
9 # Just run 'make' to create a "config.mk" with the default settings
10
11 # hardware type, possible values (default is unset):
12 # ATTENTION: please configure in config.mk, this is just included here for reference!
13 # - fnordlicht -- original fnordlicht hardware
14 # - fnordlichtmini -- fnordlichtmini hardware
15 #HARDWARE = fnordlicht
16
17 # controller
18 MCU = atmega8
19
20 # frequency
21 F_CPU = 16000000UL
22
23 # main application name (without .hex)
24 # eg 'test' when the main function is defined in 'test.c'
25 TARGET = fboot
26
27 # c sourcecode files
28 # eg. 'test.c foo.c foobar/baz.c'
29 SRC = $(wildcard *.c)
30
31 # asm sourcecode files
32 # eg. 'interrupts.S foobar/another.S'
33 ASRC = $(wildcard *.S)
34
35 # headers which should be considered when recompiling
36 # eg. 'global.h foobar/important.h'
37 HEADERS = $(wildcard *.h)
38
39 # include directories (used for both, c and asm)
40 # eg '. usbdrv/'
41 INCLUDES =
42
43
44 # use more debug-flags when compiling
45 DEBUG = 0
46
47 # default baudrate
48 CONFIG_SERIAL_BAUDRATE = 19200
49
50 # avrdude programmer protocol
51 PROG = usbasp
52 # avrdude programmer device
53 DEV = usb
54 # further flags for avrdude
55 AVRDUDE_FLAGS =
56
57 CFLAGS += -DHARDWARE_$(HARDWARE)=1
58 CFLAGS += -DCONFIG_SERIAL_BAUDRATE=$(CONFIG_SERIAL_BAUDRATE)
59
60 # use a custom linker script
61 LDFLAGS += -L$(CURDIR)/ldscripts
62
63 .PHONY: all
64
65 # main make target (moved up here because of the config.mk target)
66 all: $(TARGET).hex
67
68 # create config.mk (if it does not exist yet)
69 $(CURDIR)/config.mk:
70 @$(CP) config.mk.template config.mk
71 @echo "===================================================="
72 @echo "created file $@"
73 @echo 'please tune your settings (especially $$HARDWARE)'
74 @echo "there, then run 'make' again"
75 @echo "===================================================="
76 @exit 1
77
78 # include config file
79 -include $(CURDIR)/config.mk
80
81 # bootloader section start
82 # (see datasheet)
83 ifeq ($(MCU),atmega8)
84 # atmega8 with 1024 words bootloader:
85 # bootloader section starts at 0xc00 (word-address) == 0x1800 (byte-address)
86 #BOOT_SECTION_START = 0x1800
87 #
88 # atmega8 with 512 words bootloader:
89 # bootloader section starts at 0xe00 (word-address) == 0x1c00 (byte-address)
90 BOOT_SECTION_START = 0x1c00
91 # 7kb data memory (raw memory minus bootloader space)
92 DATA_MEM = 7
93
94 # use custom linker script
95 LDFLAGS += -T avr4.x
96 endif
97 ifeq ($(MCU),atmega88)
98 # atmega88 with 1024 words bootloader:
99 # bootloader section starts at 0xc00 (word-address) == 0x1800 (byte-address)
100 #BOOT_SECTION_START = 0x1800
101 #
102 # atmega88 with 512 words bootloader:
103 # bootloader section starts at 0xe00 (word-address) == 0x1c00 (byte-address)
104 BOOT_SECTION_START = 0x1c00
105 # 7kb data memory (raw memory minus bootloader space)
106 DATA_MEM = 7
107
108 # use custom linker script
109 LDFLAGS += -T avr4.x
110 endif
111 ifeq ($(MCU),atmega168)
112 # atmega168 with 1024 words bootloader:
113 # bootloader section starts at 0x1c00 (word-address) == 0x3800 (byte-address)
114 #BOOT_SECTION_START = 0x3800
115 #
116 # atmega168 with 512 words bootloader:
117 # bootloader section starts at 0x1e00 (word-address) == 0x3c00 (byte-address)
118 BOOT_SECTION_START = 0x3c00
119 # 15kb data memory (raw memory minus bootloader space)
120 DATA_MEM = 15
121
122 # use custom linker script
123 LDFLAGS += -T avr5.x
124 endif
125
126 LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START)
127 CFLAGS += -DBOOT_SECTION_START=$(BOOT_SECTION_START)
128
129
130 ####################################################
131 # 'make' configuration
132 ####################################################
133 CC = avr-gcc
134 OBJCOPY = avr-objcopy
135 OBJDUMP = avr-objdump
136 AS = avr-as
137 SIZE = avr-size
138 CP = cp
139 RM = rm -f
140 RMDIR = rm -rf
141 MKDIR = mkdir
142 AVRDUDE = avrdude
143
144 # flags for automatic dependency handling
145 DEPFLAGS = -MD -MP -MF .dep/$(@F).d
146
147 # flags for the compiler (for .c files)
148 CFLAGS += -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99 -fshort-enums $(DEPFLAGS)
149 CFLAGS += $(addprefix -I,$(INCLUDES))
150 CFLAGS += -fno-split-wide-types
151 CFLAGS += --param inline-call-cost=2 -finline-limit=3 -fno-inline-small-functions
152 CFLAGS += -Wl,--relax
153
154 # flags for the compiler (for .S files)
155 ASFLAGS += -g -mmcu=$(MCU) -DF_CPU=$(F_CPU) -x assembler-with-cpp $(DEPFLAGS)
156 ASFLAGS += $(addprefix -I,$(INCLUDES))
157
158 # flags for the linker
159 LDFLAGS += -mmcu=$(MCU)
160
161 # fill in object files
162 OBJECTS += $(SRC:.c=.o)
163 OBJECTS += $(ASRC:.S=.o)
164
165 # include more debug flags, if $(DEBUG) is 1
166 ifeq ($(DEBUG),1)
167 CFLAGS += -Wall -W -Wchar-subscripts -Wmissing-prototypes
168 CFLAGS += -Wmissing-declarations -Wredundant-decls
169 CFLAGS += -Wstrict-prototypes -Wshadow -Wbad-function-cast
170 CFLAGS += -Winline -Wpointer-arith -Wsign-compare
171 CFLAGS += -Wunreachable-code -Wdisabled-optimization
172 CFLAGS += -Wcast-align -Wwrite-strings -Wnested-externs -Wundef
173 CFLAGS += -Wa,-adhlns=$(basename $@).lst
174 CFLAGS += -DCONFIG_DEBUG=1
175 endif
176
177 ####################################################
178 # avrdude configuration
179 ####################################################
180 ifeq ($(MCU),atmega8)
181 AVRDUDE_MCU=m8
182 endif
183 ifeq ($(MCU),atmega48)
184 AVRDUDE_MCU=m48
185 endif
186 ifeq ($(MCU),atmega88)
187 AVRDUDE_MCU=m88
188 endif
189 ifeq ($(MCU),atmega168)
190 AVRDUDE_MCU=m168
191 endif
192
193 AVRDUDE_FLAGS += -p $(AVRDUDE_MCU)
194
195 ####################################################
196 # make targets
197 ####################################################
198
199 .PHONY: hardware-check clean distclean avrdude-terminal
200
201 # check if HARDWARE is set
202 hardware-check:
203 ifeq ($(HARDWARE),)
204 @echo 'please edit config.mk and set $$HARDWARE'
205 @exit 1
206 endif
207
208 $(TARGET).elf: hardware-check $(OBJECTS)
209 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
210
211 # all objects (.o files) and config.mk
212 $(OBJECTS): $(HEADERS) config.mk
213
214 # remove all compiled files
215 clean:
216 $(RM) $(foreach ext,elf hex eep.hex map,$(TARGET).$(ext)) \
217 $(foreach file,$(patsubst %.o,%,$(OBJECTS)),$(foreach ext,o lst lss,$(file).$(ext)))
218
219 # additionally remove the dependency makefile and config.mk
220 distclean: clean
221 $(RMDIR) .dep
222 $(RM) config.mk
223
224 # avrdude-related targets
225 install program: program-$(TARGET)
226
227 avrdude-terminal:
228 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -t
229
230 program-%: %.hex
231 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U flash:w:$< -U lock:w:0x2f:m
232
233 program-eeprom-%: %.eep.hex
234 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U eeprom:w:$<
235
236 # special programming targets
237 %.hex: %.elf
238 $(OBJCOPY) -O ihex -R .eeprom $< $@
239 @echo "===================================================="
240 @echo "$@ compiled for hardware: $(HARDWARE)"
241 @echo "using controller $(MCU)"
242 @echo -n "size for $< is "
243 @$(SIZE) -A $@ | grep '\.sec1' | tr -s ' ' | cut -d" " -f2
244 @echo "===================================================="
245
246 %.eep.hex: %.elf
247 $(OBJCOPY) --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex -j .eeprom $< $@
248
249 %.lss: %.elf
250 $(OBJDUMP) -h -S $< > $@
251
252 .PHONY: fuses-atmega8-fnordlichtmini-with-bootloader fuses-lock
253
254 fuses-atmega8-fnordlichtmini-with-bootloader:
255 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xda:m
256
257 fuses-atmega8-fnordlichtmini-without-bootloader:
258 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xd9:m
259
260 fuses-lock:
261 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lock:w:0x2f:m
262
263 -include $(shell $(MKDIR) .dep 2>/dev/null) $(wildcard .dep/*)
Impressum, Datenschutz