From c5ae02deda839919841dee5c68db564c0b74c690 Mon Sep 17 00:00:00 2001 From: Michal Ulianko Date: Thu, 19 Mar 2015 19:50:05 +0100 Subject: Fix generating $3_len in BIN_TO_OBJ makefile function --- makefiles/toolchain_gnu-arm-eabi.mk | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'makefiles') diff --git a/makefiles/toolchain_gnu-arm-eabi.mk b/makefiles/toolchain_gnu-arm-eabi.mk index 2c5302812..93ee235c4 100644 --- a/makefiles/toolchain_gnu-arm-eabi.mk +++ b/makefiles/toolchain_gnu-arm-eabi.mk @@ -296,6 +296,9 @@ endef # # - compile an empty file to generate a suitable object file # - relink the object and insert the binary file +# - extract the length +# - create const unsigned $3_len with the extracted length as its value and compile it to an object file +# - link the two generated object files together # - edit symbol names to suit # # NOTE: exercise caution using this with absolute pathnames; it looks @@ -320,11 +323,14 @@ define BIN_TO_OBJ @$(MKDIR) -p $(dir $2) $(Q) $(ECHO) > $2.c $(call COMPILE,$2.c,$2.c.o) - $(Q) $(LD) -r -o $2 $2.c.o -b binary $1 + $(Q) $(LD) -r -o $2.bin.o $2.c.o -b binary $1 + $(Q) $(ECHO) "const unsigned int $3_len = 0x`$(NM) $2.bin.o | egrep $(call BIN_SYM_PREFIX,$1)_size$$ | cut -d' ' -f1`;" > $2.c + $(call COMPILE,$2.c,$2.c.o) + $(Q) $(LD) -r -o $2 $2.c.o $2.bin.o $(Q) $(OBJCOPY) $2 \ --redefine-sym $(call BIN_SYM_PREFIX,$1)_start=$3 \ - --redefine-sym $(call BIN_SYM_PREFIX,$1)_size=$3_len \ + --strip-symbol $(call BIN_SYM_PREFIX,$1)_size \ --strip-symbol $(call BIN_SYM_PREFIX,$1)_end \ --rename-section .data=.rodata - $(Q) $(REMOVE) $2.c $2.c.o + $(Q) $(REMOVE) $2.c $2.c.o $2.bin.o endef -- cgit v1.2.3 From 354809bff4da0ce2a74ca6a750fa15a3ff441847 Mon Sep 17 00:00:00 2001 From: Michal Ulianko Date: Fri, 20 Mar 2015 23:22:42 +0100 Subject: BIN_TO_OBJ: Switch egrep and cut to $(GREP). Use posix format and decimal radix with $(NM). --- makefiles/toolchain_gnu-arm-eabi.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'makefiles') diff --git a/makefiles/toolchain_gnu-arm-eabi.mk b/makefiles/toolchain_gnu-arm-eabi.mk index 93ee235c4..033d6e1fe 100644 --- a/makefiles/toolchain_gnu-arm-eabi.mk +++ b/makefiles/toolchain_gnu-arm-eabi.mk @@ -324,7 +324,7 @@ define BIN_TO_OBJ $(Q) $(ECHO) > $2.c $(call COMPILE,$2.c,$2.c.o) $(Q) $(LD) -r -o $2.bin.o $2.c.o -b binary $1 - $(Q) $(ECHO) "const unsigned int $3_len = 0x`$(NM) $2.bin.o | egrep $(call BIN_SYM_PREFIX,$1)_size$$ | cut -d' ' -f1`;" > $2.c + $(Q) $(ECHO) "const unsigned int $3_len = `$(NM) -p --radix=d $2.bin.o | $(GREP) $(call BIN_SYM_PREFIX,$1)_size$$ | $(GREP) -o ^[0-9]*`;" > $2.c $(call COMPILE,$2.c,$2.c.o) $(Q) $(LD) -r -o $2 $2.c.o $2.bin.o $(Q) $(OBJCOPY) $2 \ -- cgit v1.2.3 From 631e518c45b054441cbe9eba5167d3075d5d2a9d Mon Sep 17 00:00:00 2001 From: Michal Ulianko Date: Sat, 21 Mar 2015 00:31:52 +0100 Subject: BIN_TO_OBJ: Change NM radix back to hex so multiple leading zeros in NM output won't generate octal constant in C. --- makefiles/toolchain_gnu-arm-eabi.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'makefiles') diff --git a/makefiles/toolchain_gnu-arm-eabi.mk b/makefiles/toolchain_gnu-arm-eabi.mk index 033d6e1fe..3b9fefb3e 100644 --- a/makefiles/toolchain_gnu-arm-eabi.mk +++ b/makefiles/toolchain_gnu-arm-eabi.mk @@ -324,7 +324,7 @@ define BIN_TO_OBJ $(Q) $(ECHO) > $2.c $(call COMPILE,$2.c,$2.c.o) $(Q) $(LD) -r -o $2.bin.o $2.c.o -b binary $1 - $(Q) $(ECHO) "const unsigned int $3_len = `$(NM) -p --radix=d $2.bin.o | $(GREP) $(call BIN_SYM_PREFIX,$1)_size$$ | $(GREP) -o ^[0-9]*`;" > $2.c + $(Q) $(ECHO) "const unsigned int $3_len = 0x`$(NM) -p --radix=x $2.bin.o | $(GREP) $(call BIN_SYM_PREFIX,$1)_size$$ | $(GREP) -o ^[0-9a-fA-F]*`;" > $2.c $(call COMPILE,$2.c,$2.c.o) $(Q) $(LD) -r -o $2 $2.c.o $2.bin.o $(Q) $(OBJCOPY) $2 \ -- cgit v1.2.3