Rev 469 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 361 | andfri | 1 | # $Id: Makefile 550 2007-07-19 22:44:46Z andfri $ |
| 2 | PRG = bios |
||
| 3 | ASRC = $(BIOSDIR)/vectors.S |
||
| 4 | CSRC = $(BIOSDIR)/bios_export.c $(BIOSDIR)/bios.c $(BIOSDIR)/flash.c |
||
| 425 | eqlazer | 5 | BIOS_VERSION = 0x1338 |
| 361 | andfri | 6 | OPTIMIZE = -Os -mcall-prologues |
| 7 | LIBNAME = libbios |
||
| 8 | BIOSDIR = bios |
||
| 550 | andfri | 9 | TEMPLATEDIR = template |
| 361 | andfri | 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 | |||
| 438 | eqlazer | 57 | # Get old node config and build new bios "make update NODE_ID=0x01" |
| 469 | arune | 58 | # this is now done in two steps, first make oldconfig and then make update |
| 59 | # this due to re-reading the configfile |
||
| 60 | .PHONY: update oldconfig move updateconfig |
||
| 61 | update: clean all updateconfig |
||
| 438 | eqlazer | 62 | |
| 469 | arune | 63 | # Move config from a node-folder to avr-lib dir to be able to compile a new version of bios |
| 64 | # this removes the lines starting with BIOS_RAM_END and BIOS_VERSION becasue they are added in make template |
||
| 438 | eqlazer | 65 | oldconfig: |
| 550 | andfri | 66 | cp config.inc config.old |
| 67 | @$(AWK) '!/^BIOS_RAM_END*/ && !/^BIOS_VERSION*/ { print }' $(PERSONALDIR)/*$(NODE_ID)*/$(BIOSDIR)/bios.inc > config.inc |
||
| 469 | arune | 68 | # - cp $(PERSONALDIR)/*$(NODE_ID)*/bios.inc config.inc |
| 438 | eqlazer | 69 | |
| 437 | eqlazer | 70 | # Copy template to personal dir |
| 71 | move: |
||
| 438 | eqlazer | 72 | - mkdir -p $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME) |
| 550 | andfri | 73 | - cp -r $(TEMPLATEDIR)/* $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)/ |
| 437 | eqlazer | 74 | |
| 469 | arune | 75 | # Copy template to personal dir but dont copy makefile and main.c as you dont want these files replaced generally |
| 76 | updateconfig: |
||
| 550 | andfri | 77 | - cp -r $(TEMPLATEDIR)/$(BIOSDIR) $(TEMPLATEDIR)/config.inc $(TEMPLATEDIR)/Makefile $(PERSONALDIR)/$(NODE_ID)_*/ |
| 438 | eqlazer | 78 | |
| 469 | arune | 79 | |
| 550 | andfri | 80 | .PHONY: clean cleanintermediate cleantemplate distclean |
| 361 | andfri | 81 | clean: cleanintermediate cleantemplate |
| 82 | -rm -f $(PRG).elf $(PRG).lst $(PRG).map *.hex |
||
| 83 | |||
| 84 | cleanintermediate: |
||
| 362 | andfri | 85 | -rm -f $(OBJ) $(LIBNAME).[So] *.d $(BIOSDIR)/config.h |
| 361 | andfri | 86 | |
| 87 | cleantemplate: |
||
| 550 | andfri | 88 | -rm -f $(TEMPLATEDIR)/$(BIOSDIR)/* |
| 361 | andfri | 89 | |
| 550 | andfri | 90 | distclean: |
| 91 | @echo Cleaning: template |
||
| 92 | $(MAKE) -C template distclean |
||
| 93 | @echo Cleaning: bios |
||
| 94 | $(MAKE) clean |
||
| 95 | |||
| 361 | andfri | 96 | .PHONY: lst |
| 97 | lst: $(PRG).lst |
||
| 98 | |||
| 99 | %.lst: %.elf |
||
| 100 | $(OBJDUMP) -h -S $< > $@ |
||
| 101 | |||
| 102 | $(PRG).elf: $(PRG)_pass1.elf |
||
| 103 | @echo Linking pass 2: Optimizing flash usage |
||
| 104 | @rm -f $(PRG)_pass1.elf |
||
| 397 | arune | 105 | @$(MAKE) BIOS_START=$(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map) $(PRG)_pass1.elf |
| 362 | andfri | 106 | @mv $(PRG)_pass1.elf $(PRG).elf |
| 361 | andfri | 107 | |
| 108 | $(LIBNAME).S: $(PRG).elf |
||
| 109 | @echo Generating $@ |
||
| 469 | arune | 110 | @$(AWK) '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(PRG).map > $@ |
| 361 | andfri | 111 | |
| 112 | $(BIOSDIR)/config.h: config.inc |
||
| 113 | @echo Generating $@ |
||
| 397 | arune | 114 | @$(AWK) 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "#endif" }' $< > $@ |
| 361 | andfri | 115 | |
| 550 | andfri | 116 | $(TEMPLATEDIR)/$(BIOSDIR)/bios.inc: config.inc $(PRG).elf |
| 361 | andfri | 117 | @echo Generating $@ |
| 118 | @echo "# This file is automatically generated. Do not edit." > $@ |
||
| 397 | arune | 119 | @$(AWK) '/^[^#].*=.*/ { print $$0 }' config.inc >> $@ |
| 120 | @$(AWK) '/0x[0-9a-f]+.*__bios_ram_end/ { print "BIOS_RAM_END="$$1 }' bios.map >> $@ |
||
| 361 | andfri | 121 | @echo "BIOS_VERSION=$(BIOS_VERSION)" >> $@ |
| 122 | |||
| 550 | andfri | 123 | $(TEMPLATEDIR)/$(BIOSDIR)/bios.h: drivers/can/can.h $(BIOSDIR)/bios_export.h |
| 361 | andfri | 124 | @echo Generating $@ |
| 125 | @echo "/* This file is automatically generated. Do not edit. */\n" > $@ |
||
| 126 | @echo "#ifndef BIOS_H_\n#define BIOS_H_\n" >> $@ |
||
| 127 | @cat $^ >> $@ |
||
| 128 | @echo "\n#endif /*BIOS_H_*/" >> $@ |
||
| 129 | |||
| 130 | .PHONY: template |
||
| 550 | andfri | 131 | template: $(TEMPLATEDIR)/$(BIOSDIR)/bios.h $(TEMPLATEDIR)/$(BIOSDIR)/bios.inc $(TEMPLATEDIR)/$(BIOSDIR)/$(LIBNAME).a($(LIBNAME).o) |
| 361 | andfri | 132 | |
| 133 | %.d: %.c |
||
| 134 | @set -e; rm -f $@; \ |
||
| 135 | $(CC) -M $(CFLAGS) $< > $@.$$$$; \ |
||
| 136 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ |
||
| 137 | rm -f $@.$$$$ |
||
| 138 | |||
| 139 | # Rules for building the rom images |
||
| 140 | |||
| 141 | hex: $(PRG).hex |
||
| 142 | |||
| 143 | %.hex: %.elf |
||
| 144 | $(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@ |
||
| 145 | |||
| 146 | # Rules for uploading rom images to flash |
||
| 147 | |||
| 148 | install: hex |
||
| 149 | $(UPLOAD) $(ULFLAGS) |
||
| 150 | |||
| 469 | arune | 151 | # Update bios over can, get config from old node config and build new bios "make reinstall NODE_ID=0x01" |
| 152 | # this is now done in two steps, first make oldconfig and then make reinstall |
||
| 153 | # this due to re-reading the configfile |
||
| 154 | reinstall: update |
||
| 155 | #next row not needed when using candude |
||
| 156 | # $(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 |
||
| 157 | $(CANUPLOAD) $(CANULFLAGS) -n $(NODE_ID) -f $(PRG).hex -r -b |
||
| 362 | andfri | 158 | |
| 361 | andfri | 159 | # Rules for building the eeprom images |
| 160 | |||
| 161 | eeprom: ehex |
||
| 162 | |||
| 163 | ehex: $(PRG)_eeprom.hex |
||
| 164 | |||
| 165 | %_eeprom.hex: %.elf |
||
| 166 | $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ |
||
| 167 | |||
| 168 | .DELETE_ON_ERROR: |
||
| 169 |