Subversion Repositories HomeAutomation

Rev

Rev 437 | Blame | Last modification | View Log | SVN | RSS feed

# $Id: Makefile 438 2007-05-09 22:29:16Z eqlazer $
PRG            = bios
ASRC           = $(BIOSDIR)/vectors.S
CSRC           = $(BIOSDIR)/bios_export.c $(BIOSDIR)/bios.c $(BIOSDIR)/flash.c
BIOS_VERSION   = 0x1338
OPTIMIZE       = -Os -mcall-prologues
LIBNAME        = libbios
BIOSDIR        = bios
TEMPLATEDIR     = template

include config.inc
include system.inc

DEFS           = -DF_CPU=$(F_CPU) -DCAN_DRIVER_H=$(CAN_DRIVER_H) -DBIOS_VERSION=$(BIOS_VERSION) -I. -I$(BIOSDIR)
LIBS           =

ifeq ($(CAN_CONTROLLER),MCP2515)
CSRC += drivers/can/mcp2515/mcp2515.c
CAN_DRIVER_H = \<drivers/can/mcp2515/mcp2515.h\>
endif

OBJ = $(ASRC:.S=.o) $(CSRC:.c=.o)

#
# You should not have to change anything below here.
#

CC             = avr-gcc
AWK            = awk

# Override is only needed by avr-lib build system.

override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU) $(DEFS)
override LDFLAGS       = -Wl,-Map,$(PRG).map,--defsym,__bios_start=$(BIOS_START),--defsym,__boot_start=$(BOOT_START),-Tldscripts/$(MCU).ld,--cref
override ASFLAGS       = -x assembler-with-cpp -Wa,-gstabs -mmcu=$(MCU) $(DEFS)

# Start address for linking pass 1, will be overridden for optimizing pass
BIOS_START = 0x100

OBJCOPY        = avr-objcopy
OBJDUMP        = avr-objdump
SIZE           = avr-size
SZFLAGS        = 

.PHONY: default
default: hex template lst cleanintermediate
    @$(SIZE) $(SZFLAGS) $(PRG).elf

#include $(CSRC:.c=.d)

.PHONY: all
all: $(PRG).elf lst hex eeprom template

$(PRG)_pass1.elf: $(BIOSDIR)/config.h $(OBJ)
    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

# Get old node config and build new bios "make update NODE_ID=0x01"
.PHONY: update oldconfig move
update: clean oldconfig all move

oldconfig:
    - cp $(PERSONALDIR)/*$(NODE_ID)*/bios.inc config.inc

# Copy template to personal dir
move:
    - mkdir -p $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)
    - cp $(TEMPLATEDIR)/bios.h $(TEMPLATEDIR)/bios.inc $(TEMPLATEDIR)/config.inc $(TEMPLATEDIR)/libbios.a $(TEMPLATEDIR)/main.c $(TEMPLATEDIR)/Makefile $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)/


.PHONY: clean cleanintermediate cleantemplate
clean: cleanintermediate cleantemplate
    -rm -f $(PRG).elf $(PRG).lst $(PRG).map *.hex

cleanintermediate:
    -rm -f $(OBJ) $(LIBNAME).[So] *.d $(BIOSDIR)/config.h

cleantemplate:
    -rm -f $(TEMPLATEDIR)/bios.* $(TEMPLATEDIR)/$(LIBNAME).a

.PHONY: lst
lst:  $(PRG).lst

%.lst: %.elf
    $(OBJDUMP) -h -S $< > $@

$(PRG).elf: $(PRG)_pass1.elf
    @echo Linking pass 2: Optimizing flash usage
    @rm -f $(PRG)_pass1.elf
    @$(MAKE) BIOS_START=$(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map) $(PRG)_pass1.elf
    @mv $(PRG)_pass1.elf $(PRG).elf

$(LIBNAME).S: $(PRG).elf
    @echo Generating $@
    @awk '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(PRG).map > $@

$(BIOSDIR)/config.h: config.inc
    @echo Generating $@
    @$(AWK) 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "#endif" }' $< > $@

$(TEMPLATEDIR)/bios.inc: config.inc $(PRG).elf
    @echo Generating $@
    @echo "# This file is automatically generated. Do not edit." > $@
    @$(AWK) '/^[^#].*=.*/ { print $$0 }' config.inc >> $@
    @$(AWK) '/0x[0-9a-f]+.*__bios_ram_end/ { print "BIOS_RAM_END="$$1 }' bios.map >> $@
    @echo "BIOS_VERSION=$(BIOS_VERSION)" >> $@

$(TEMPLATEDIR)/bios.h: drivers/can/can.h $(BIOSDIR)/bios_export.h
    @echo Generating $@
    @echo "/* This file is automatically generated. Do not edit. */\n" > $@
    @echo "#ifndef BIOS_H_\n#define BIOS_H_\n" >> $@
    @cat $^ >> $@
    @echo "\n#endif /*BIOS_H_*/" >> $@

.PHONY: template
template: $(TEMPLATEDIR)/bios.h $(TEMPLATEDIR)/bios.inc $(TEMPLATEDIR)/$(LIBNAME).a($(LIBNAME).o)

%.d: %.c
    @set -e; rm -f $@; \
    $(CC) -M $(CFLAGS) $< > $@.$$$$; \
    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
    rm -f $@.$$$$   

# Rules for building the rom images

hex:  $(PRG).hex

%.hex: %.elf
    $(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@

# Rules for uploading rom images to flash

install: hex
    $(UPLOAD) $(ULFLAGS)

reinstall: hex
    $(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
    $(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)

# Rules for building the eeprom images

eeprom: ehex

ehex:  $(PRG)_eeprom.hex

%_eeprom.hex: %.elf
    $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@

.DELETE_ON_ERROR: