From 4271e82d56403879635cabe17a0e959c49fc1a83 Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Sat, 29 Aug 2009 06:14:28 +0000 Subject: [PATCH] Only re-compile version.c as often as necessary Make bootrom version information pointer a proper symbol (with hacky ld strangeness workaround) --- armsrc/Makefile | 7 +++---- armsrc/appmain.c | 12 +++++++----- armsrc/ldscript | 2 +- bootrom/Makefile | 4 ++-- bootrom/ldscript-flash | 11 +++++++---- common/Makefile.common | 14 +++++++++----- common/ldscript.common | 4 ++++ 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/armsrc/Makefile b/armsrc/Makefile index 00e99b1f..bc15aeb9 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -13,7 +13,6 @@ THUMBSRC = start.c \ lfops.c \ iso15693.c \ util.c \ - version.c \ hitag2.c \ usb.c @@ -30,14 +29,14 @@ all: $(OBJDIR)/osimage.s19 $(OBJDIR)/fpgaimage.s19 $(OBJDIR)/fpga.o: fpga.bit $(OBJCOPY) -O elf32-littlearm -I binary -B arm --redefine-sym _binary____fpga_fpga_bit_start=_binary_fpga_bit_start --redefine-sym _binary____fpga_fpga_bit_end=_binary_fpga_bit_end --prefix-sections=fpga_bit $^ $@ -$(OBJDIR)/fullimage.elf: $(OBJDIR)/fpga.o $(THUMBOBJ) $(ARMOBJ) $(ARMLIB)/libgcc.a +$(OBJDIR)/fullimage.elf: $(VERSIONOBJ) $(OBJDIR)/fpga.o $(THUMBOBJ) $(ARMOBJ) $(ARMLIB)/libgcc.a $(LD) -g -Tldscript -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ $(OBJDIR)/fpgaimage.elf: $(OBJDIR)/fullimage.elf - $(OBJCOPY) -F elf32-littlearm --only-section fpgaimage $^ $@ + $(OBJCOPY) -F elf32-littlearm --only-section .fpgaimage $^ $@ $(OBJDIR)/osimage.elf: $(OBJDIR)/fullimage.elf - $(OBJCOPY) -F elf32-littlearm --remove-section fpgaimage $^ $@ + $(OBJCOPY) -F elf32-littlearm --remove-section .fpgaimage $^ $@ clean: $(DELETE) $(OBJDIR)$(PATHSEP)*.o diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 59cc6dea..72d8789e 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -238,17 +238,19 @@ void ReadMem(int addr) /* osimage version information is linked in */ extern struct version_information version_information; +/* bootrom version information is pointed to from _bootphase1_version_pointer */ +extern char _bootphase1_version_pointer, _flash_start, _flash_end; void SendVersion(void) { char temp[48]; /* Limited data payload in USB packets */ DbpString("Prox/RFID mark3 RFID instrument"); - /* Try to find the bootrom version information. For the time being, expect - * to find a pointer at address 0x1001fc, perform slight sanity checks on - * the pointer, then use it. + /* Try to find the bootrom version information. Expect to find a pointer at + * symbol _bootphase1_version_pointer, perform slight sanity checks on the + * pointer, then use it. */ - void *bootrom_version = *(void**)0x1001fc; - if( bootrom_version < (void*)0x100000 || bootrom_version > (void*)0x101000 ) { + void *bootrom_version = *(void**)&_bootphase1_version_pointer; + if( bootrom_version < (void*)&_flash_start || bootrom_version >= (void*)&_flash_end ) { DbpString("bootrom version information appears invalid"); } else { FormatVersionInformation(temp, sizeof(temp), "bootrom: ", bootrom_version); diff --git a/armsrc/ldscript b/armsrc/ldscript index b99cea2f..3a01a68f 100644 --- a/armsrc/ldscript +++ b/armsrc/ldscript @@ -3,7 +3,7 @@ INCLUDE ../common/ldscript.common ENTRY(Vector) SECTIONS { - fpgaimage : { + .fpgaimage : { *(fpga_bit.data) } >fpgaimage .start : { *(.startos) } >osimage diff --git a/bootrom/Makefile b/bootrom/Makefile index 30b55466..c80b650c 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -2,7 +2,7 @@ # DO NOT use thumb mode in the phase 1 bootloader since that generates a section with glue code ARMSRC = fromflash.c -THUMBSRC = usb.c version.c bootrom.c +THUMBSRC = usb.c bootrom.c ASMSRC = ram-reset.s flash-reset.s # Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC @@ -10,7 +10,7 @@ include ../common/Makefile.common all: $(OBJDIR)/bootrom.s19 -$(OBJDIR)/bootrom.elf: $(ASMOBJ) $(ARMOBJ) $(THUMBOBJ) +$(OBJDIR)/bootrom.elf: $(VERSIONOBJ) $(ASMOBJ) $(ARMOBJ) $(THUMBOBJ) $(LD) -g -Tldscript-flash --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ clean: diff --git a/bootrom/ldscript-flash b/bootrom/ldscript-flash index d2e6648b..37bfaaa1 100644 --- a/bootrom/ldscript-flash +++ b/bootrom/ldscript-flash @@ -5,7 +5,7 @@ SECTIONS { . = 0; - bootphase1 : { + .bootphase1 : { *(.startup) *(.bootphase1) @@ -15,14 +15,17 @@ SECTIONS of the version information at the end of the section. -- Henryk Plötz 2009-08-28 */ - _version_information_start = .; + _version_information_start = ABSOLUTE(.); *(.version_information); - . = LENGTH(bootphase1) - 0x4; /* Skip ahead to the end */ + /* Why doesn't this work even though _bootphase1_version_pointer = 0x1001fc? + . = _bootphase1_version_pointer - ORIGIN(bootphase1); */ + /* This works, apparently it fools the linker into accepting an absolute address */ + . = _bootphase1_version_pointer - ORIGIN(bootphase1) + ORIGIN(bootphase1); LONG(_version_information_start) } >bootphase1 - bootphase2 : { + .bootphase2 : { __bootphase2_start__ = .; *(.startphase2) *(.text) diff --git a/common/Makefile.common b/common/Makefile.common index 04b0b330..901ce2e1 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -58,6 +58,7 @@ CFLAGS = -c $(INCLUDE) -Wall $(APP_CFLAGS) THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(ARMSRC)) ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC)) +VERSIONOBJ = $(OBJDIR)/version.o $(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< @@ -68,13 +69,16 @@ $(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(ASMOBJ): $(OBJDIR)/%.o: %.s $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< +$(VERSIONOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) + $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< + # This objcopy call translates physical flash addresses to logical addresses # See ldscript.common. -- Henryk Plötz 2009-08-27 $(OBJDIR)/%.s19: $(OBJDIR)/%.elf $(OBJCOPY) -Osrec --srec-forceS3 --no-change-warnings \ - --change-section-address bootphase1-0x100000 \ - --change-section-address bootphase2-0x100000 \ - --change-section-address fpgaimage-0x100000 \ + --change-section-address .bootphase1-0x100000 \ + --change-section-address .bootphase2-0x100000 \ + --change-section-address .fpgaimage-0x100000 \ --change-section-address .start-0x100000 \ --change-section-address .text-0x100000 \ --change-section-address .rodata-0x100000 $^ $@ @@ -90,9 +94,9 @@ DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \ $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC))) $(DEPENDENCY_FILES): Makefile ../common/Makefile.common -$(OBJDIR)/%.d: %.c +$(patsubst %.o,%.d,$(THUMBOBJ) $(ARMOBJ)): $(OBJDIR)/%.d: %.c @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ -$(OBJDIR)/%.d: %.s +$(patsubst %.o,%.d,$(ASMOBJ)):$(OBJDIR)/%.d: %.s @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ -include $(DEPENDENCY_FILES) diff --git a/common/ldscript.common b/common/ldscript.common index 4c4bd390..4379d40c 100644 --- a/common/ldscript.common +++ b/common/ldscript.common @@ -14,3 +14,7 @@ MEMORY ram : ORIGIN = 0x00200000, LENGTH = 64K } +/* Export some information that can be used from within the firmware */ +_bootphase1_version_pointer = ORIGIN(bootphase1) + LENGTH(bootphase1) - 0x4; +_flash_start = ORIGIN(bootphase1); +_flash_end = ORIGIN(osimage) + LENGTH(osimage); \ No newline at end of file -- 2.39.5