Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
361 andfri 1
# $Id: Makefile 397 2007-04-29 21:26:14Z arune $
2
PRG            = bios
3
ASRC           = $(BIOSDIR)/vectors.S
4
CSRC           = $(BIOSDIR)/bios_export.c $(BIOSDIR)/bios.c $(BIOSDIR)/flash.c
5
BIOS_VERSION   = 0x1337
6
OPTIMIZE       = -Os -mcall-prologues
7
LIBNAME        = libbios
8
BIOSDIR        = bios
9
TEMPLATEDIR     = template
10
 
11
include config.inc
12
include system.inc
13
 
14
DEFS           = -DF_CPU=$(F_CPU) -DCAN_DRIVER_H=$(CAN_DRIVER_H) -DBIOS_VERSION=$(BIOS_VERSION) -I. -I$(BIOSDIR)
15
LIBS           =
16
 
17
ifeq ($(CAN_CONTROLLER),MCP2515)
18
CSRC += drivers/can/mcp2515/mcp2515.c
19
CAN_DRIVER_H = \<drivers/can/mcp2515/mcp2515.h\>
20
endif
21
 
22
OBJ = $(ASRC:.S=.o) $(CSRC:.c=.o)
23
 
24
#
25
# You should not have to change anything below here.
26
#
27
 
28
CC             = avr-gcc
397 arune 29
AWK            = awk
361 andfri 30
 
31
# Override is only needed by avr-lib build system.
32
 
33
override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU) $(DEFS)
34
override LDFLAGS       = -Wl,-Map,$(PRG).map,--defsym,__bios_start=$(BIOS_START),--defsym,__boot_start=$(BOOT_START),-Tldscripts/$(MCU).ld,--cref
35
override ASFLAGS       = -x assembler-with-cpp -Wa,-gstabs -mmcu=$(MCU) $(DEFS)
36
 
37
# Start address for linking pass 1, will be overridden for optimizing pass
38
BIOS_START = 0x100
39
 
40
OBJCOPY        = avr-objcopy
41
OBJDUMP        = avr-objdump
42
SIZE           = avr-size
43
SZFLAGS        = 
44
 
45
.PHONY: default
46
default: hex template lst cleanintermediate
47
	@$(SIZE) $(SZFLAGS) $(PRG).elf
48
 
49
#include $(CSRC:.c=.d)
50
 
51
.PHONY: all
52
all: $(PRG).elf lst hex eeprom template
53
 
54
$(PRG)_pass1.elf: $(BIOSDIR)/config.h $(OBJ)
55
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
56
 
57
.PHONY: clean cleanintermediate cleantemplate
58
clean: cleanintermediate cleantemplate
59
	-rm -f $(PRG).elf $(PRG).lst $(PRG).map *.hex
60
 
61
cleanintermediate:
362 andfri 62
	-rm -f $(OBJ) $(LIBNAME).[So] *.d $(BIOSDIR)/config.h
361 andfri 63
 
64
cleantemplate:
65
	-rm -f $(TEMPLATEDIR)/bios.* $(TEMPLATEDIR)/$(LIBNAME).a
66
 
67
.PHONY: lst
68
lst:  $(PRG).lst
69
 
70
%.lst: %.elf
71
	$(OBJDUMP) -h -S $< > $@
72
 
73
$(PRG).elf: $(PRG)_pass1.elf
74
	@echo Linking pass 2: Optimizing flash usage
75
	@rm -f $(PRG)_pass1.elf
397 arune 76
	@$(MAKE) BIOS_START=$(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map) $(PRG)_pass1.elf
362 andfri 77
	@mv $(PRG)_pass1.elf $(PRG).elf
361 andfri 78
 
79
$(LIBNAME).S: $(PRG).elf
80
	@echo Generating $@
81
	@awk '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(PRG).map > $@
82
 
83
$(BIOSDIR)/config.h: config.inc
84
	@echo Generating $@
397 arune 85
	@$(AWK) 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "#endif" }' $< > $@
361 andfri 86
 
87
$(TEMPLATEDIR)/bios.inc: config.inc $(PRG).elf
88
	@echo Generating $@
89
	@echo "# This file is automatically generated. Do not edit." > $@
397 arune 90
	@$(AWK) '/^[^#].*=.*/ { print $$0 }' config.inc >> $@
91
	@$(AWK) '/0x[0-9a-f]+.*__bios_ram_end/ { print "BIOS_RAM_END="$$1 }' bios.map >> $@
361 andfri 92
	@echo "BIOS_VERSION=$(BIOS_VERSION)" >> $@
93
 
94
$(TEMPLATEDIR)/bios.h: drivers/can/can.h $(BIOSDIR)/bios_export.h
95
	@echo Generating $@
96
	@echo "/* This file is automatically generated. Do not edit. */\n" > $@
97
	@echo "#ifndef BIOS_H_\n#define BIOS_H_\n" >> $@
98
	@cat $^ >> $@
99
	@echo "\n#endif /*BIOS_H_*/" >> $@
100
 
101
.PHONY: template
102
template: $(TEMPLATEDIR)/bios.h $(TEMPLATEDIR)/bios.inc $(TEMPLATEDIR)/$(LIBNAME).a($(LIBNAME).o)
103
 
104
%.d: %.c
105
	@set -e; rm -f $@; \
106
	$(CC) -M $(CFLAGS) $< > $@.$$$$; \
107
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
108
	rm -f $@.$$$$	
109
 
110
# Rules for building the rom images
111
 
112
hex:  $(PRG).hex
113
 
114
%.hex: %.elf
115
	$(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@
116
 
117
# Rules for uploading rom images to flash
118
 
119
install: hex
120
	$(UPLOAD) $(ULFLAGS)
121
 
362 andfri 122
reinstall: hex
397 arune 123
	$(OBJCOPY) -I ihex -O ihex --change-addresses=-$(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map) bios.hex bios_offset.hex
124
	$(CANMANAGER) $(CANMANFLAGS) -n $(NODE_ID) -u bios_offset.hex --flashcopy 0,$(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map),$(shell $(AWK) '/0x[0-9a-f]+.*__bios_size/ { print $$1 }' bios.map)
362 andfri 125
 
361 andfri 126
# Rules for building the eeprom images
127
 
128
eeprom: ehex
129
 
130
ehex:  $(PRG)_eeprom.hex
131
 
132
%_eeprom.hex: %.elf
133
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
134
 
135
.DELETE_ON_ERROR:
136