Subversion Repositories HomeAutomation

Rev

Rev 361 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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