From 82393ec1c3c8a9d3e98cfccb52622d7af577427d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 23 Sep 2021 21:04:08 +0000 Subject: core: Add assert to check alignment Assert that the RW image size padding adding results in correct alignment. This assertion will make it easier to verify future clang changes. BRANCH=none BUG=b:172020503, b:188117811 TEST=make buildall -j Signed-off-by: Tom Hughes Change-Id: Ibdc6feaf31cf271f67594ae1e519272fd9a88cd4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3179317 Reviewed-by: Daisuke Nojiri Reviewed-by: Denis Brockus --- core/cortex-m/ec.lds.S | 5 +++++ core/cortex-m0/ec.lds.S | 6 ++++++ core/minute-ia/ec.lds.S | 6 ++++++ core/nds32/ec.lds.S | 6 ++++++ core/riscv-rv32i/ec.lds.S | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index 7b08be81a6..fa35684e31 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -512,6 +512,11 @@ SECTIONS __image_size = __flash_used + SIZEOF(.rw_image_size_alignment); #endif +#if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) + /* Alignment is needed by flash_command_write() for RW update. */ + ASSERT(__image_size % CONFIG_FLASH_WRITE_SIZE == 0, + "Error: RW image is not aligned to CONFIG_FLASH_WRITE_SIZE") +#endif #endif /* CONFIG_CHIP_INIT_ROM_REGION */ #ifdef CONFIG_FLASH_CROS diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S index bc461b90de..c5e66f9bcb 100644 --- a/core/cortex-m0/ec.lds.S +++ b/core/cortex-m0/ec.lds.S @@ -315,6 +315,12 @@ SECTIONS __flash_used = LOADADDR(.data) + SIZEOF(.data) - ORIGIN(FLASH); __image_size = __flash_used; +#if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) + /* Alignment is needed by flash_command_write() for RW update. */ + ASSERT(__image_size % CONFIG_FLASH_WRITE_SIZE == 0, + "Error: RW image is not aligned to CONFIG_FLASH_WRITE_SIZE") +#endif + #ifdef CONFIG_FLASH_CROS /* * These linker labels are just for analysis and not used in the code. diff --git a/core/minute-ia/ec.lds.S b/core/minute-ia/ec.lds.S index dc61699fed..beda1dbfae 100644 --- a/core/minute-ia/ec.lds.S +++ b/core/minute-ia/ec.lds.S @@ -235,6 +235,12 @@ SECTIONS /* TODO: Adjust __image_size to proper value for core minute-ia later */ __image_size = . - CONFIG_ISH_BOOT_START; +#if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) + /* Alignment is needed by flash_command_write() for RW update. */ + ASSERT(__image_size % CONFIG_FLASH_WRITE_SIZE == 0, + "Error: RW image is not aligned to CONFIG_FLASH_WRITE_SIZE") +#endif + def_irq_low = ABSOLUTE(default_int_handler) & 0xFFFF; def_irq_high = ABSOLUTE(default_int_handler) >> 16; diff --git a/core/nds32/ec.lds.S b/core/nds32/ec.lds.S index 2c21b94761..4993593f87 100644 --- a/core/nds32/ec.lds.S +++ b/core/nds32/ec.lds.S @@ -285,6 +285,12 @@ SECTIONS __flash_used = LOADADDR(.data) + SIZEOF(.data) - FW_OFF(SECTION); __image_size = __flash_used; +#if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) + /* Alignment is needed by flash_command_write() for RW update. */ + ASSERT(__image_size % CONFIG_FLASH_WRITE_SIZE == 0, + "Error: RW image is not aligned to CONFIG_FLASH_WRITE_SIZE") +#endif + #ifdef CONFIG_FLASH_CROS /* * These linker labels are just for analysis and not used in the code. diff --git a/core/riscv-rv32i/ec.lds.S b/core/riscv-rv32i/ec.lds.S index e8963c1b14..2b88b14f24 100644 --- a/core/riscv-rv32i/ec.lds.S +++ b/core/riscv-rv32i/ec.lds.S @@ -360,6 +360,12 @@ SECTIONS #endif __image_size = __flash_used; +#if defined(SECTION_IS_RW) && (CONFIG_FLASH_WRITE_SIZE > 0) + /* Alignment is needed by flash_command_write() for RW update. */ + ASSERT(__image_size % CONFIG_FLASH_WRITE_SIZE == 0, + "Error: RW image is not aligned to CONFIG_FLASH_WRITE_SIZE") +#endif + #ifdef CONFIG_FLASH_CROS /* * These linker labels are just for analysis and not used in the code. -- cgit v1.2.1