Subversion Repositories HomeAutomation

Rev

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

# $Id: Makefile 550 2007-07-19 22:44:46Z andfri $
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"
# this is now done in two steps, first make oldconfig and then make update
# this due to re-reading the configfile
.PHONY: update oldconfig move updateconfig
update: clean all updateconfig

# Move config from a node-folder to avr-lib dir to be able to compile a new version of bios
# this removes the lines starting with BIOS_RAM_END and BIOS_VERSION becasue they are added in make template
oldconfig:
    cp config.inc config.old
    @$(AWK) '!/^BIOS_RAM_END*/ && !/^BIOS_VERSION*/ { print }' $(PERSONALDIR)/*$(NODE_ID)*/$(BIOSDIR)/bios.inc > config.inc
#   - cp $(PERSONALDIR)/*$(NODE_ID)*/bios.inc config.inc

# Copy template to personal dir
move:
    - mkdir -p $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)
    - cp -r $(TEMPLATEDIR)/* $(PERSONALDIR)/$(NODE_ID)_$(HW_NAME)/

# Copy template to personal dir but dont copy makefile and main.c as you dont want these files replaced generally 
updateconfig:
    - cp -r $(TEMPLATEDIR)/$(BIOSDIR) $(TEMPLATEDIR)/config.inc $(TEMPLATEDIR)/Makefile $(PERSONALDIR)/$(NODE_ID)_*/


.PHONY: clean cleanintermediate cleantemplate distclean
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)/$(BIOSDIR)/*

distclean:
    @echo Cleaning: template
    $(MAKE) -C template distclean
    @echo Cleaning: bios
    $(MAKE) clean

.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)/$(BIOSDIR)/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)/$(BIOSDIR)/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)/$(BIOSDIR)/bios.h $(TEMPLATEDIR)/$(BIOSDIR)/bios.inc $(TEMPLATEDIR)/$(BIOSDIR)/$(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)

# Update bios over can, get config from old node config and build new bios "make reinstall NODE_ID=0x01"
# this is now done in two steps, first make oldconfig and then make reinstall
# this due to re-reading the configfile
reinstall: update
#next row not needed when using candude
#   $(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
    $(CANUPLOAD) $(CANULFLAGS) -n $(NODE_ID) -f $(PRG).hex -r -b

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