diff options
author | Tom Hughes <tomhughes@chromium.org> | 2021-09-23 18:39:31 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-11 19:15:36 +0000 |
commit | f050111663cb33a061cfbdc07dc836a5af13d362 (patch) | |
tree | 0a2266b910027c12b8f4b2c06e09f288e908a987 | |
parent | 187f9155f684d0aeda4546bf04451ae8825f2de8 (diff) | |
download | chrome-ec-f050111663cb33a061cfbdc07dc836a5af13d362.tar.gz |
core: Fix flash size calculation when linking with lld (clang)
The map file generated by lld has a different format than the gnu linker
(ld). (We save this map file into build/<board>/<image>/ec.<image>.map
during the build.)
Instead of trying to parse the different formats in the .map file, use
the .smap file (the output of "nm"), which has the values of the symbols
and has the same format whether using lld or ld. We need to add a new
"__flash_size" symbol so that we can use that symbol to get the size
from the .smap.
This add flash sizes to a few boards that previously didn't have it:
asurada_scp, cherry_scp, and kukui_scp, since the previous logic was
always looking for FLASH and these use IROM.
BRANCH=none
BUG=b:172020503
TEST=make buildall -j
TEST=make CC=arm-none-eabi-clang BOARD=elemi
TEST=bcompare build_before_change build_after_change
=> only difference between space_free_flash.txt and
space_free_ram.txt files in the two builds is that this change adds
the space_free_flash.txt files for asurada_scp, cherry_scp, and
kukui_scp.
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I7c64b6ba9bceeeb4044559188c1c1bebbf60471d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3179314
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | Makefile.rules | 8 | ||||
-rw-r--r-- | chip/npcx/build.mk | 4 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 9 | ||||
-rw-r--r-- | core/cortex-m0/ec.lds.S | 9 | ||||
-rw-r--r-- | core/nds32/ec.lds.S | 9 | ||||
-rw-r--r-- | core/riscv-rv32i/ec.lds.S | 13 |
6 files changed, 38 insertions, 14 deletions
diff --git a/Makefile.rules b/Makefile.rules index bd26637b11..42afb26e6f 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -426,9 +426,9 @@ ifeq ($(V),0) cmd_size= else cmd_size=$(Q)awk '\ - /__flash_used =/ {flash_used = strtonum($$1)} \ - /^FLASH / {flash_size = strtonum($$3)} \ - /__ram_free =/ {ram_free = strtonum($$1)} \ + /__flash_used/ {flash_used = strtonum("0x" $$1)} \ + /__flash_size/ {flash_size = strtonum("0x" $$1)} \ + /__ram_free/ {ram_free = strtonum("0x" $$1)} \ END {room_free = flash_size - flash_used; \ print ram_free > "$(out)/$(1)/space_free_ram.txt"; \ printf " *** "; \ @@ -438,7 +438,7 @@ cmd_size=$(Q)awk '\ } \ printf ("%s bytes in RAM still available on $(BOARD) $(1) ****\n", \ ram_free) \ - }' $(out)/$(1)/$(PROJECT).$(1).map + }' $(out)/$(1)/$(PROJECT).$(1).smap endif # List the smallest free flash spaces diff --git a/chip/npcx/build.mk b/chip/npcx/build.mk index 4be1b2994f..1de37f6b0a 100644 --- a/chip/npcx/build.mk +++ b/chip/npcx/build.mk @@ -69,13 +69,13 @@ show_esct_cmd=$(if $(V),,echo ' ECST ' $(subst $(out)/,,$@) ; ) # size when the CONFIG_CHIP_INIT_ROM_REGION is used. Note that the -fwlen # parameter for the ecst utility must be in hex. cmd_fwlen=$(shell awk '\ - /__flash_used =/ {flash_used = strtonum($$1)} \ + /__flash_used/ {flash_used = strtonum("0x" $$1)} \ END {printf ("%x", flash_used)}' $(1)) # ECST options for header bld_ecst=${out}/util/ecst -chip $(CHIP_VARIANT) \ -usearmrst -mode bt -ph -i $(1) -o $(2) -nohcrc -nofcrc -flashsize 8 \ - -fwlen $(call cmd_fwlen, $(patsubst %.flat,%.map,$(2))) \ + -fwlen $(call cmd_fwlen, $(patsubst %.flat,%.smap,$(2))) \ -spimaxclk 50 -spireadmode dual 1> /dev/null # Replace original one with the flat file including header diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index c5314111d0..fcf7a1fecc 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -488,11 +488,16 @@ SECTIONS #endif /* - * __flash_used is used in flash free calculations by the makefile. + * __flash_used and __flash_size is used in flash free calculations by + * the makefile. Note the difference between __flash_size and + * __config_flash_size. __flash_size is the flash size for the given + * image (RW, RO, etc.), while __config_flash_size is the *total* + * flash size. * __image_size is stored in the struct image_data header and used - * in hash calcuations. + * in hash calculations. */ __flash_used = FLASH_USED_END - ORIGIN(EC_IMAGE_LMA_MEM_REGION); + __flash_size = LENGTH(EC_IMAGE_LMA_MEM_REGION); #ifndef CONFIG_CHIP_INIT_ROM_REGION #if !(defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 4)) __image_size = __flash_used; diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S index c5e66f9bcb..031cb6b1b3 100644 --- a/core/cortex-m0/ec.lds.S +++ b/core/cortex-m0/ec.lds.S @@ -308,11 +308,16 @@ SECTIONS (__shared_mem_buf + CONFIG_SHAREDMEM_MINIMUM_SIZE); /* - * __flash_used is used in flash free calculations by the makefile. + * __flash_used and __flash_size is used in flash free calculations by + * the makefile. Note the difference between __flash_size and + * __config_flash_size. __flash_size is the flash size for the given + * image (RW, RO, etc.), while __config_flash_size is the *total* + * flash size. * __image_size is stored in the struct image_data header and used - * in hash calcuations. + * in hash calculations. */ __flash_used = LOADADDR(.data) + SIZEOF(.data) - ORIGIN(FLASH); + __flash_size = LENGTH(FLASH); __image_size = __flash_used; #if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) diff --git a/core/nds32/ec.lds.S b/core/nds32/ec.lds.S index 4993593f87..da65f1a1f0 100644 --- a/core/nds32/ec.lds.S +++ b/core/nds32/ec.lds.S @@ -278,11 +278,16 @@ SECTIONS (__shared_mem_buf + CONFIG_SHAREDMEM_MINIMUM_SIZE); /* - * __flash_used is used in flash free calculations by the makefile. + * __flash_used and __flash_size is used in flash free calculations by + * the makefile. Note the difference between __flash_size and + * __config_flash_size. __flash_size is the flash size for the given + * image (RW, RO, etc.), while __config_flash_size is the *total* + * flash size. * __image_size is stored in the struct image_data header and used - * in hash calcuations. + * in hash calculations. */ __flash_used = LOADADDR(.data) + SIZEOF(.data) - FW_OFF(SECTION); + __flash_size = LENGTH(FLASH); __image_size = __flash_used; #if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) diff --git a/core/riscv-rv32i/ec.lds.S b/core/riscv-rv32i/ec.lds.S index 2b88b14f24..9e7acd684b 100644 --- a/core/riscv-rv32i/ec.lds.S +++ b/core/riscv-rv32i/ec.lds.S @@ -348,9 +348,13 @@ SECTIONS (__shared_mem_buf + CONFIG_SHAREDMEM_MINIMUM_SIZE); /* - * __flash_used is used in flash free calculations by the makefile. + * __flash_used and __flash_size is used in flash free calculations by + * the makefile. Note the difference between __flash_size and + * __config_flash_size. __flash_size is the flash size for the given + * image (RW, RO, etc.), while __config_flash_size is the *total* + * flash size. * __image_size is stored in the struct image_data header and used - * in hash calcuations. + * in hash calculations. */ #if defined(CHIP_FAMILY_IT8XXX2) __flash_used = LOADADDR(.data) + SIZEOF(.data) + \ @@ -358,6 +362,11 @@ SECTIONS #else __flash_used = LOADADDR(.data) + SIZEOF(.data) - FW_OFF(SECTION); #endif +#if defined(CONFIG_FLASH_PHYSICAL) + __flash_size = LENGTH(FLASH); +#else + __flash_size = LENGTH(IROM); +#endif __image_size = __flash_used; #if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) |