]> git.zerfleddert.de Git - fnordlicht-mini/blame - firmware/fnordlicht-bootloader/Makefile
reference eeprom contents
[fnordlicht-mini] / firmware / fnordlicht-bootloader / Makefile
CommitLineData
ec1bef8e 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
18MCU = atmega8
19
20# frequency
21F_CPU = 16000000UL
22
23# main application name (without .hex)
24# eg 'test' when the main function is defined in 'test.c'
25TARGET = fboot
26
27# c sourcecode files
28# eg. 'test.c foo.c foobar/baz.c'
29SRC = $(wildcard *.c)
30
31# asm sourcecode files
32# eg. 'interrupts.S foobar/another.S'
33ASRC = $(wildcard *.S)
34
35# headers which should be considered when recompiling
36# eg. 'global.h foobar/important.h'
37HEADERS = $(wildcard *.h)
38
39# include directories (used for both, c and asm)
40# eg '. usbdrv/'
41INCLUDES =
42
43
44# use more debug-flags when compiling
45DEBUG = 0
46
47# default baudrate
48CONFIG_SERIAL_BAUDRATE = 19200
49
50# avrdude programmer protocol
51PROG = usbasp
52# avrdude programmer device
53DEV = usb
54# further flags for avrdude
55AVRDUDE_FLAGS =
56
57CFLAGS += -DHARDWARE_$(HARDWARE)=1
58CFLAGS += -DCONFIG_SERIAL_BAUDRATE=$(CONFIG_SERIAL_BAUDRATE)
59
60# use a custom linker script
61LDFLAGS += -L$(CURDIR)/ldscripts
62
63.PHONY: all
64
65# main make target (moved up here because of the config.mk target)
66all: $(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)
83ifeq ($(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
96endif
97ifeq ($(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
110endif
111ifeq ($(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
124endif
125
126LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START)
127CFLAGS += -DBOOT_SECTION_START=$(BOOT_SECTION_START)
128
129
130####################################################
131# 'make' configuration
132####################################################
133CC = avr-gcc
134OBJCOPY = avr-objcopy
135OBJDUMP = avr-objdump
136AS = avr-as
137SIZE = avr-size
138CP = cp
139RM = rm -f
140RMDIR = rm -rf
141MKDIR = mkdir
142AVRDUDE = avrdude
143
144# flags for automatic dependency handling
145DEPFLAGS = -MD -MP -MF .dep/$(@F).d
146
147# flags for the compiler (for .c files)
148CFLAGS += -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99 -fshort-enums $(DEPFLAGS)
149CFLAGS += $(addprefix -I,$(INCLUDES))
150CFLAGS += -fno-split-wide-types
151CFLAGS += --param inline-call-cost=2 -finline-limit=3 -fno-inline-small-functions
152CFLAGS += -Wl,--relax
153
154# flags for the compiler (for .S files)
155ASFLAGS += -g -mmcu=$(MCU) -DF_CPU=$(F_CPU) -x assembler-with-cpp $(DEPFLAGS)
156ASFLAGS += $(addprefix -I,$(INCLUDES))
157
158# flags for the linker
159LDFLAGS += -mmcu=$(MCU)
160
161# fill in object files
162OBJECTS += $(SRC:.c=.o)
163OBJECTS += $(ASRC:.S=.o)
164
165# include more debug flags, if $(DEBUG) is 1
166ifeq ($(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
175endif
176
177####################################################
178# avrdude configuration
179####################################################
180ifeq ($(MCU),atmega8)
181 AVRDUDE_MCU=m8
182endif
183ifeq ($(MCU),atmega48)
184 AVRDUDE_MCU=m48
185endif
186ifeq ($(MCU),atmega88)
187 AVRDUDE_MCU=m88
188endif
189ifeq ($(MCU),atmega168)
190 AVRDUDE_MCU=m168
191endif
192
193AVRDUDE_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
202hardware-check:
203ifeq ($(HARDWARE),)
204 @echo 'please edit config.mk and set $$HARDWARE'
205 @exit 1
206endif
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
215clean:
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
220distclean: clean
221 $(RMDIR) .dep
222 $(RM) config.mk
223
224# avrdude-related targets
225install program: program-$(TARGET)
226
227avrdude-terminal:
228 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -t
229
230program-%: %.hex
231 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U flash:w:$< -U lock:w:0x2f:m
232
233program-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
254fuses-atmega8-fnordlichtmini-with-bootloader:
255 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xda:m
256
257fuses-atmega8-fnordlichtmini-without-bootloader:
258 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xd9:m
259
260fuses-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