Subversion Repositories HomeAutomation

Rev

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

Rev 437 Rev 438
1
# $Id: Makefile 437 2007-05-09 19:43:41Z eqlazer $
1
# $Id: Makefile 438 2007-05-09 22:29:16Z eqlazer $
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   = 0x1338
5
BIOS_VERSION   = 0x1338
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
AWK            = awk
29
AWK            = awk
30
 
30
 
31
# Override is only needed by avr-lib build system.
31
# Override is only needed by avr-lib build system.
32
 
32
 
33
override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU) $(DEFS)
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
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)
35
override ASFLAGS       = -x assembler-with-cpp -Wa,-gstabs -mmcu=$(MCU) $(DEFS)
36
 
36
 
37
# Start address for linking pass 1, will be overridden for optimizing pass
37
# Start address for linking pass 1, will be overridden for optimizing pass
38
BIOS_START = 0x100
38
BIOS_START = 0x100
39
 
39
 
40
OBJCOPY        = avr-objcopy
40
OBJCOPY        = avr-objcopy
41
OBJDUMP        = avr-objdump
41
OBJDUMP        = avr-objdump
42
SIZE           = avr-size
42
SIZE           = avr-size
43
SZFLAGS        = 
43
SZFLAGS        = 
44
 
44
 
45
.PHONY: default
45
.PHONY: default
46
default: hex template lst cleanintermediate
46
default: hex template lst cleanintermediate
47
	@$(SIZE) $(SZFLAGS) $(PRG).elf
47
	@$(SIZE) $(SZFLAGS) $(PRG).elf
48
 
48
 
49
#include $(CSRC:.c=.d)
49
#include $(CSRC:.c=.d)
50
 
50
 
51
.PHONY: all
51
.PHONY: all
52
all: $(PRG).elf lst hex eeprom template
52
all: $(PRG).elf lst hex eeprom template
53
 
53
 
54
$(PRG)_pass1.elf: $(BIOSDIR)/config.h $(OBJ)
54
$(PRG)_pass1.elf: $(BIOSDIR)/config.h $(OBJ)
55
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
55
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
-
 
56
 
-
 
57
# Get old node config and build new bios "make update NODE_ID=0x01"
-
 
58
.PHONY: update oldconfig move
-
 
59
update: clean oldconfig all move
-
 
60
 
-
 
61
oldconfig:
-
 
62
	- cp $(PERSONALDIR)/*$(NODE_ID)*/bios.inc config.inc
56
 
63
 
57
# Copy template to personal dir
64
# Copy template to personal dir
58
.PHONY: move
-
 
59
move:
65
move:
60
	- cp -r $(TEMPLATEDIR) $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)
66
	- mkdir -p $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)
61
	- rm -rf $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)/.svn
67
	- cp $(TEMPLATEDIR)/bios.h $(TEMPLATEDIR)/bios.inc $(TEMPLATEDIR)/config.inc $(TEMPLATEDIR)/libbios.a $(TEMPLATEDIR)/main.c $(TEMPLATEDIR)/Makefile $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)/
-
 
68
 
62
 
69
 
63
.PHONY: clean cleanintermediate cleantemplate
70
.PHONY: clean cleanintermediate cleantemplate
64
clean: cleanintermediate cleantemplate
71
clean: cleanintermediate cleantemplate
65
	-rm -f $(PRG).elf $(PRG).lst $(PRG).map *.hex
72
	-rm -f $(PRG).elf $(PRG).lst $(PRG).map *.hex
66
 
73
 
67
cleanintermediate:
74
cleanintermediate:
68
	-rm -f $(OBJ) $(LIBNAME).[So] *.d $(BIOSDIR)/config.h
75
	-rm -f $(OBJ) $(LIBNAME).[So] *.d $(BIOSDIR)/config.h
69
 
76
 
70
cleantemplate:
77
cleantemplate:
71
	-rm -f $(TEMPLATEDIR)/bios.* $(TEMPLATEDIR)/$(LIBNAME).a
78
	-rm -f $(TEMPLATEDIR)/bios.* $(TEMPLATEDIR)/$(LIBNAME).a
72
 
79
 
73
.PHONY: lst
80
.PHONY: lst
74
lst:  $(PRG).lst
81
lst:  $(PRG).lst
75
 
82
 
76
%.lst: %.elf
83
%.lst: %.elf
77
	$(OBJDUMP) -h -S $< > $@
84
	$(OBJDUMP) -h -S $< > $@
78
 
85
 
79
$(PRG).elf: $(PRG)_pass1.elf
86
$(PRG).elf: $(PRG)_pass1.elf
80
	@echo Linking pass 2: Optimizing flash usage
87
	@echo Linking pass 2: Optimizing flash usage
81
	@rm -f $(PRG)_pass1.elf
88
	@rm -f $(PRG)_pass1.elf
82
	@$(MAKE) BIOS_START=$(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map) $(PRG)_pass1.elf
89
	@$(MAKE) BIOS_START=$(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map) $(PRG)_pass1.elf
83
	@mv $(PRG)_pass1.elf $(PRG).elf
90
	@mv $(PRG)_pass1.elf $(PRG).elf
84
 
91
 
85
$(LIBNAME).S: $(PRG).elf
92
$(LIBNAME).S: $(PRG).elf
86
	@echo Generating $@
93
	@echo Generating $@
87
	@awk '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(PRG).map > $@
94
	@awk '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(PRG).map > $@
88
 
95
 
89
$(BIOSDIR)/config.h: config.inc
96
$(BIOSDIR)/config.h: config.inc
90
	@echo Generating $@
97
	@echo Generating $@
91
	@$(AWK) 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "#endif" }' $< > $@
98
	@$(AWK) 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "#endif" }' $< > $@
92
 
99
 
93
$(TEMPLATEDIR)/bios.inc: config.inc $(PRG).elf
100
$(TEMPLATEDIR)/bios.inc: config.inc $(PRG).elf
94
	@echo Generating $@
101
	@echo Generating $@
95
	@echo "# This file is automatically generated. Do not edit." > $@
102
	@echo "# This file is automatically generated. Do not edit." > $@
96
	@$(AWK) '/^[^#].*=.*/ { print $$0 }' config.inc >> $@
103
	@$(AWK) '/^[^#].*=.*/ { print $$0 }' config.inc >> $@
97
	@$(AWK) '/0x[0-9a-f]+.*__bios_ram_end/ { print "BIOS_RAM_END="$$1 }' bios.map >> $@
104
	@$(AWK) '/0x[0-9a-f]+.*__bios_ram_end/ { print "BIOS_RAM_END="$$1 }' bios.map >> $@
98
	@echo "BIOS_VERSION=$(BIOS_VERSION)" >> $@
105
	@echo "BIOS_VERSION=$(BIOS_VERSION)" >> $@
99
 
106
 
100
$(TEMPLATEDIR)/bios.h: drivers/can/can.h $(BIOSDIR)/bios_export.h
107
$(TEMPLATEDIR)/bios.h: drivers/can/can.h $(BIOSDIR)/bios_export.h
101
	@echo Generating $@
108
	@echo Generating $@
102
	@echo "/* This file is automatically generated. Do not edit. */\n" > $@
109
	@echo "/* This file is automatically generated. Do not edit. */\n" > $@
103
	@echo "#ifndef BIOS_H_\n#define BIOS_H_\n" >> $@
110
	@echo "#ifndef BIOS_H_\n#define BIOS_H_\n" >> $@
104
	@cat $^ >> $@
111
	@cat $^ >> $@
105
	@echo "\n#endif /*BIOS_H_*/" >> $@
112
	@echo "\n#endif /*BIOS_H_*/" >> $@
106
 
113
 
107
.PHONY: template
114
.PHONY: template
108
template: $(TEMPLATEDIR)/bios.h $(TEMPLATEDIR)/bios.inc $(TEMPLATEDIR)/$(LIBNAME).a($(LIBNAME).o)
115
template: $(TEMPLATEDIR)/bios.h $(TEMPLATEDIR)/bios.inc $(TEMPLATEDIR)/$(LIBNAME).a($(LIBNAME).o)
109
 
116
 
110
%.d: %.c
117
%.d: %.c
111
	@set -e; rm -f $@; \
118
	@set -e; rm -f $@; \
112
	$(CC) -M $(CFLAGS) $< > $@.$$$$; \
119
	$(CC) -M $(CFLAGS) $< > $@.$$$$; \
113
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
120
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
114
	rm -f $@.$$$$	
121
	rm -f $@.$$$$	
115
 
122
 
116
# Rules for building the rom images
123
# Rules for building the rom images
117
 
124
 
118
hex:  $(PRG).hex
125
hex:  $(PRG).hex
119
 
126
 
120
%.hex: %.elf
127
%.hex: %.elf
121
	$(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@
128
	$(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@
122
 
129
 
123
# Rules for uploading rom images to flash
130
# Rules for uploading rom images to flash
124
 
131
 
125
install: hex
132
install: hex
126
	$(UPLOAD) $(ULFLAGS)
133
	$(UPLOAD) $(ULFLAGS)
127
 
134
 
128
reinstall: hex
135
reinstall: hex
129
	$(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
136
	$(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
130
	$(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)
137
	$(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)
131
 
138
 
132
# Rules for building the eeprom images
139
# Rules for building the eeprom images
133
 
140
 
134
eeprom: ehex
141
eeprom: ehex
135
 
142
 
136
ehex:  $(PRG)_eeprom.hex
143
ehex:  $(PRG)_eeprom.hex
137
 
144
 
138
%_eeprom.hex: %.elf
145
%_eeprom.hex: %.elf
139
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
146
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
140
 
147
 
141
.DELETE_ON_ERROR:
148
.DELETE_ON_ERROR:
142
	
149