2012-03-05 16:47:01 +01:00
|
|
|
### Compiler definitions
|
|
|
|
CC = sdcc
|
|
|
|
LD = sdcc
|
|
|
|
AS = sdcc
|
2013-08-06 18:09:32 +02:00
|
|
|
AR = sdar
|
2012-03-05 16:47:01 +01:00
|
|
|
OBJCOPY = objcopy
|
|
|
|
STRIP = strip
|
|
|
|
|
|
|
|
### Hex file conversions
|
|
|
|
PACKIHX = packihx
|
|
|
|
SREC_CAT = srec_cat
|
|
|
|
SREC_FLAGS = -disable_sequence_warnings
|
|
|
|
|
|
|
|
BANK_ALLOC = $(CONTIKI_CPU)/bank-alloc.py
|
|
|
|
SEGMENT_RULES = $(OBJECTDIR)/segment.rules
|
|
|
|
|
|
|
|
CFLAGS += --model-$(MEMORY_MODEL) --stack-auto --std-c99
|
2012-04-20 15:01:32 +02:00
|
|
|
CFLAGS += -DCC2530_LAST_FLASH_BANK=$(HIGH_FLASH_BANK)
|
2012-08-29 13:51:49 +02:00
|
|
|
CFLAGS += --fomit-frame-pointer
|
2012-03-05 16:47:01 +01:00
|
|
|
|
2013-08-09 16:36:30 +02:00
|
|
|
### Disable warning 110 (EVELYN the modified dog) and 126 (unreachable code)
|
|
|
|
CFLAGS += --disable-warning 110 --disable-warning 126
|
|
|
|
|
2012-03-05 16:47:01 +01:00
|
|
|
LDFLAGS += --model-$(MEMORY_MODEL) --stack-auto --out-fmt-ihx
|
|
|
|
LDFLAGS += --xram-loc 0x0000 --xram-size 0x1F00
|
|
|
|
LDFLAGS += --code-loc $(START_ADDR) --code-size $(CODE_SIZE)
|
|
|
|
|
|
|
|
ASFLAGS += -plosgff
|
|
|
|
|
2013-08-06 18:09:32 +02:00
|
|
|
AROPTS = -rc
|
2012-03-05 16:47:01 +01:00
|
|
|
|
|
|
|
### Our object files are .rel, so we can't use the default finalize dependency
|
|
|
|
### generation. Override here.
|
|
|
|
define FINALIZE_SDCC_DEPENDENCY
|
|
|
|
cp $(@:.rel=.d) $(@:.rel=.$$$$); \
|
|
|
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.rel=.$$$$) >> $(@:.rel=.d); \
|
|
|
|
rm -f $(@:.rel=.$$$$)
|
|
|
|
endef
|
|
|
|
|
2012-04-20 15:01:32 +02:00
|
|
|
### SoC flavor (F256, F128, F64, F32) as the ID of the last flash bank (0...7)
|
|
|
|
### We assume F256, project Makefile can override
|
|
|
|
###
|
|
|
|
### ToDo:
|
|
|
|
### Fix --code-size accordingly
|
|
|
|
### Fix the bank allocator to play for all flavors
|
|
|
|
ifndef HIGH_FLASH_BANK
|
|
|
|
HIGH_FLASH_BANK=7
|
|
|
|
endif
|
|
|
|
|
2012-03-05 16:47:01 +01:00
|
|
|
### Banking Guesswork:
|
|
|
|
### Generic examples do not specify banking.
|
|
|
|
### We automatically turn it on if its unspecified and if we are building with
|
|
|
|
### UIP_CONF_IPV6
|
|
|
|
ifndef HAVE_BANKING
|
|
|
|
ifeq ($(UIP_CONF_IPV6),1)
|
|
|
|
HAVE_BANKING=1
|
|
|
|
else
|
|
|
|
HAVE_BANKING=0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
### Does the project want us to offset the firmware?
|
|
|
|
### define start address and max code size accordingly
|
|
|
|
ifeq ($(OFFSET_FIRMWARE),1)
|
|
|
|
START_ADDR = 0x01000
|
|
|
|
HOME_START = 00001000
|
|
|
|
ifeq ($(HAVE_BANKING),1)
|
|
|
|
CODE_SIZE = 0x3F000
|
|
|
|
else
|
|
|
|
CODE_SIZE = 0x0F000
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
START_ADDR = 0x00000
|
|
|
|
HOME_START = 00000000
|
|
|
|
ifeq ($(HAVE_BANKING),1)
|
|
|
|
CODE_SIZE = 0x40000
|
|
|
|
else
|
|
|
|
CODE_SIZE = 0x10000
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
### Are we building with BANKing supoprt?
|
|
|
|
ifeq ($(HAVE_BANKING),1)
|
|
|
|
## Yes
|
|
|
|
MEMORY_MODEL=huge
|
|
|
|
LDFLAGS += -Wl-r
|
|
|
|
LD_PRE_FLAGS += -Wl-bBANK1=0x018000
|
|
|
|
CFLAGS += -DHAVE_SDCC_BANKING
|
|
|
|
#use this in $(call c_seg,$<) to get segment for a source file.
|
|
|
|
c_seg = --codeseg $(shell python $(BANK_ALLOC) $1 $(SEGMENT_RULES) $2)
|
|
|
|
else
|
|
|
|
## No banking
|
|
|
|
MEMORY_MODEL=large
|
|
|
|
c_seg =
|
|
|
|
endif
|
|
|
|
|
|
|
|
### CPU-dependent cleanup files
|
|
|
|
CLEAN += *.lnk *.lk *.sym *.lib *.ihx *.rel *.mem *.rst *.asm *.hex
|
|
|
|
CLEAN += *.omf *.cdb *.banks *.flags *.banked-hex
|
|
|
|
CLEAN += symbols.c symbols.h
|
|
|
|
|
|
|
|
### CPU-dependent directories
|
|
|
|
CONTIKI_CPU_DIRS = . dev
|
|
|
|
|
|
|
|
### CPU-dependent source files
|
2012-09-07 12:12:31 +02:00
|
|
|
CONTIKI_SOURCEFILES += soc.c clock.c stack.c
|
2012-03-05 16:47:01 +01:00
|
|
|
CONTIKI_SOURCEFILES += uart0.c uart1.c uart-intr.c
|
|
|
|
CONTIKI_SOURCEFILES += dma.c dma_intr.c
|
|
|
|
CONTIKI_SOURCEFILES += cc2530-rf.c
|
|
|
|
CONTIKI_SOURCEFILES += watchdog.c rtimer-arch.c
|
2012-08-16 16:24:57 +02:00
|
|
|
CONTIKI_SOURCEFILES += port2-intr.c port2.c
|
2012-03-05 16:47:01 +01:00
|
|
|
CONTIKI_ASMFILES +=
|
|
|
|
|
2012-08-07 15:19:40 +02:00
|
|
|
include $(CONTIKI_CPU)/usb/Makefile.usb
|
|
|
|
|
|
|
|
CONTIKI_SOURCEFILES += $(USB_SOURCEFILES)
|
|
|
|
|
2012-03-05 16:47:01 +01:00
|
|
|
CONTIKI_ASMOBJECTFILES = $(addprefix $(OBJECTDIR)/,$(CONTIKI_ASMFILES:.S=.rel))
|
|
|
|
|
|
|
|
CONTIKI_CASMOBJECTFILES = $(addprefix $(OBJECTDIR)/, \
|
|
|
|
$(CONTIKI_CASMFILES:.cS=.rel))
|
|
|
|
|
|
|
|
CONTIKI_PLATFORM_DIRS = $(PLATFORM_APPDIRS) \
|
|
|
|
$(addprefix $(CONTIKI)/platform/$(TARGET)/, $(CONTIKI_TARGET_DIRS))
|
|
|
|
|
|
|
|
CONTIKI_CPU_DIRS_LIST = $(addprefix $(CONTIKI_CPU)/, \
|
|
|
|
$(CONTIKI_CPU_DIRS))
|
|
|
|
|
|
|
|
oname = $(patsubst %.c,%.rel,$(patsubst %.S,%.rel,$(1)))
|
|
|
|
|
|
|
|
CONTIKI_OBJECTFILES = $(addprefix $(OBJECTDIR)/, \
|
|
|
|
$(call oname, $(CONTIKI_SOURCEFILES)))
|
|
|
|
|
|
|
|
PROJECT_OBJECTFILES = $(addprefix $(OBJECTDIR)/, \
|
|
|
|
$(call oname, $(PROJECT_SOURCEFILES)))
|
|
|
|
|
|
|
|
### Compilation rules
|
|
|
|
|
|
|
|
SEGMENT_RULE_FILES = $(foreach dir, . $(CONTIKI_PLATFORM_DIRS) \
|
|
|
|
$(CONTIKI_CPU_DIRS_LIST), $(wildcard $(dir)/segment.rules) )
|
|
|
|
|
2013-06-21 00:45:41 +02:00
|
|
|
# NB: Assumes SEGMENT_RULES was not overridden and is in $(OBJECTDIR)
|
|
|
|
$(SEGMENT_RULES): $(SEGMENT_RULE_FILES) | $(OBJECTDIR)
|
2012-03-05 16:47:01 +01:00
|
|
|
cat $(SEGMENT_RULE_FILES) | \
|
|
|
|
sed -e 's/#.*$$//' -e 's/^\s*//' -e '/^$$/d' > $@
|
|
|
|
|
|
|
|
CUSTOM_RULE_LINK=1
|
|
|
|
CUSTOM_RULE_C_TO_OBJECTDIR_O=1
|
|
|
|
CUSTOM_RULE_ALLOBJS_TO_TARGETLIB=1
|
|
|
|
|
2013-06-21 00:45:41 +02:00
|
|
|
$(OBJECTDIR)/%.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR)
|
2013-08-06 18:19:01 +02:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(call c_seg,$<,$@) $(CFLAGS) -c $< -o $@ -Wp,-MMD,$(@:.rel=.d),-MQ,$@
|
2012-03-05 16:47:01 +01:00
|
|
|
@$(FINALIZE_SDCC_DEPENDENCY)
|
|
|
|
|
|
|
|
contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) \
|
|
|
|
$(CONTIKI_ASMOBJECTFILES) $(CONTIKI_CASMOBJECTFILES)
|
|
|
|
rm -f $@
|
|
|
|
for target in $^; do echo $$target >> $@; done
|
|
|
|
|
|
|
|
.PRECIOUS: %.$(TARGET) %.hex
|
|
|
|
|
|
|
|
# build app/example local object files. We need a separate rule so that we can
|
|
|
|
# pass -DAUTOSTART_ENABLE for those files only
|
2013-06-21 00:45:41 +02:00
|
|
|
$(OBJECTDIR)/%.app.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR)
|
2013-08-06 18:19:01 +02:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(call c_seg,$<,$@) -DAUTOSTART_ENABLE $(CFLAGS) -c $< -o $@
|
2012-03-05 16:47:01 +01:00
|
|
|
|
|
|
|
# .ihx is the sdcc binary output file
|
|
|
|
ifeq ($(HAVE_BANKING),1)
|
|
|
|
### Build bankable firmware
|
|
|
|
%.ihx: $(OBJECTDIR)/%.app.rel $(CONTIKI_TARGET_MAIN) contiki-$(TARGET).lib
|
|
|
|
@echo "\nFirst Link"
|
|
|
|
@echo "==============="
|
2013-08-06 18:19:01 +02:00
|
|
|
$(TRACE_LD)
|
|
|
|
$(Q)$(CC) $(LDFLAGS) $(LD_PRE_FLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib
|
2012-03-05 16:47:01 +01:00
|
|
|
|
|
|
|
%.flags: %.ihx
|
|
|
|
### Allocate modules to banks and relocate object files
|
|
|
|
@echo "\nBank Allocation"
|
|
|
|
@echo "==============="
|
|
|
|
python $(BANK_ALLOC) $(basename $(@F)) $(SEGMENT_RULES) $(OFFSET_FIRMWARE)
|
|
|
|
|
|
|
|
%.banked-hex: %.flags
|
|
|
|
### Link again with new bank allocations
|
|
|
|
@echo "\nFinal Link"
|
|
|
|
@echo "==============="
|
2013-08-06 18:19:01 +02:00
|
|
|
$(TRACE_LD)
|
|
|
|
$(Q)$(LD) $(LDFLAGS) $(shell cat $<) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib
|
2012-03-05 16:47:01 +01:00
|
|
|
|
|
|
|
%.hex: %.banked-hex
|
|
|
|
### Post-process the hex file for programmers which dislike SDCC output hex format
|
|
|
|
$(eval BANKS := $(shell egrep '(^BANK[0-9])=' $(@:.hex=.map) | sed -e 's/BANK\([0-9]\).*/\1/' | uniq))
|
|
|
|
$(eval FILES := $(addsuffix .hex,$(addprefix bank,$(BANKS))))
|
|
|
|
@echo "\nPack hex file"
|
|
|
|
@echo "==============="
|
|
|
|
@for bank in $(BANKS); do \
|
|
|
|
echo $(SREC_CAT) $(SREC_FLAGS) $(@:.hex=.banked-hex) -intel \
|
|
|
|
-crop 0x"$$bank"8000 "0x"$$bank"FFFF" \
|
|
|
|
-offset -$$((0x8000 * $$bank + 0x08000)) -o bank"$$bank".hex -intel; \
|
|
|
|
$(SREC_CAT) $(SREC_FLAGS) $(@:.hex=.banked-hex) -intel \
|
|
|
|
-crop 0x"$$bank"8000 "0x"$$bank"FFFF" \
|
|
|
|
-offset -$$((0x8000 * $$bank + 0x08000)) -o bank"$$bank".hex -intel; \
|
|
|
|
done
|
|
|
|
$(SREC_CAT) $(SREC_FLAGS) $(@:.hex=.banked-hex) -intel -crop 0x00000 0x07FFF -o home.ihx -intel
|
|
|
|
srec_cat home.ihx -intel $(foreach file,$(FILES),$(file) -intel) -o $@ -intel
|
|
|
|
rm -f home.ihx $(FILES)
|
|
|
|
else
|
|
|
|
### Build non-banked firmware
|
|
|
|
%.ihx: $(OBJECTDIR)/%.app.rel $(CONTIKI_TARGET_MAIN) contiki-$(TARGET).lib
|
2013-08-06 18:19:01 +02:00
|
|
|
$(TRACE_LD)
|
|
|
|
$(Q)$(LD) $(LDFLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib
|
2012-03-05 16:47:01 +01:00
|
|
|
|
|
|
|
%.hex: %.ihx
|
|
|
|
$(PACKIHX) $< > $@
|
|
|
|
endif
|