Subversion Repositories HomeAutomation

Rev

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

# $Id$
PRG            = bios
ASRC           = $(BIOSDIR)/vectors.S
CSRC           = $(BIOSDIR)/bios_export.c $(BIOSDIR)/bios.c $(BIOSDIR)/flash.c
BIOS_VERSION   = 0x1337
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

# 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)

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

cleanintermediate:
    -rm -f $(OBJ) $(PRG)_pass1.elf $(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
    @cp $(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)

# 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: