diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2019-07-30 15:45:41 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-31 18:55:48 +0000 |
commit | 3e1c72ea23fe3c37f5a4e4e8bceea38c0322ba31 (patch) | |
tree | 3dfe5a8708d231c7b260ec2659d63d0faf2fdc01 | |
parent | b224441aaaa5dd08274811d65bb795b4abc231d8 (diff) | |
download | chrome-ec-3e1c72ea23fe3c37f5a4e4e8bceea38c0322ba31.tar.gz |
common/system: refactor some confusing ifdefs
I had a hard time reading this section, so figured I may as well
rewrite it to use IS_ENABLED while I was here.
Gave CONFIG_{RO,RW}_HEAD_ROOM a default value of zero here, which
makes the math work out for boards without it anyway.
BUG=none
BRANCH=none
TEST=buildall
Change-Id: I87dc2d73838c350088916b57aa51d5f368c5592f
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1727570
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | chip/g/config_chip.h | 3 | ||||
-rw-r--r-- | common/system.c | 45 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 4 | ||||
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | include/system.h | 5 |
5 files changed, 28 insertions, 33 deletions
diff --git a/chip/g/config_chip.h b/chip/g/config_chip.h index 36b88697b1..493cb0eb0f 100644 --- a/chip/g/config_chip.h +++ b/chip/g/config_chip.h @@ -29,7 +29,10 @@ #define CONFIG_PROGRAM_MEMORY_BASE 0x40000 #define CONFIG_FLASH_SIZE (512 * 1024) #define CONFIG_FLASH_ERASED_VALUE32 (-1U) + +#undef CONFIG_RO_HEAD_ROOM #define CONFIG_RO_HEAD_ROOM 1024 /* Room for ROM signature. */ +#undef CONFIG_RW_HEAD_ROOM #define CONFIG_RW_HEAD_ROOM CONFIG_RO_HEAD_ROOM /* same for RW */ /* Memory-mapped internal flash */ diff --git a/common/system.c b/common/system.c index 0c1a958cfc..fec9b63380 100644 --- a/common/system.c +++ b/common/system.c @@ -598,30 +598,27 @@ test_mockable int system_run_image_copy(enum system_image_copy_t copy) if (base == 0xffffffff) return EC_ERROR_INVAL; -#ifdef CONFIG_EXTERNAL_STORAGE - /* Jump to loader */ - init_addr = system_get_lfw_address(); - system_set_image_copy(copy); -#else -#ifdef CONFIG_FW_RESET_VECTOR - /* Get reset vector */ - init_addr = system_get_fw_reset_vector(base); -#else -#if defined(CONFIG_RO_HEAD_ROOM) - /* Skip any head room in the RO image */ - if (copy == SYSTEM_IMAGE_RO) - /* Don't change base, though! */ - init_addr = *(uintptr_t *)(base + CONFIG_RO_HEAD_ROOM + 4); - else -#endif - init_addr = *(uintptr_t *)(base + 4); -#endif -#ifndef EMU_BUILD - /* Make sure the reset vector is inside the destination image */ - if (init_addr < base || init_addr >= base + get_size(copy)) - return EC_ERROR_UNKNOWN; -#endif -#endif + if (IS_ENABLED(CONFIG_EXTERNAL_STORAGE)) { + /* Jump to loader */ + init_addr = system_get_lfw_address(); + system_set_image_copy(copy); + } else if (IS_ENABLED(CONFIG_FW_RESET_VECTOR)) { + /* Get reset vector */ + init_addr = system_get_fw_reset_vector(base); + } else { + uintptr_t init = base + 4; + + /* Skip any head room in the RO image */ + if (copy == SYSTEM_IMAGE_RO) + init += CONFIG_RO_HEAD_ROOM; + + init_addr = *(uintptr_t *)(init); + + /* Make sure the reset vector is inside the destination image */ + if (!IS_ENABLED(EMU_BUILD) && + (init_addr < base || init_addr >= base + get_size(copy))) + return EC_ERROR_UNKNOWN; + } CPRINTS("Jumping to image %s", system_image_copy_t_to_string(copy)); diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index 93eb70550b..90ba292c5b 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -80,10 +80,10 @@ SECTIONS } > SHARED_LIB #endif .text : { -#if defined(SECTION_IS_RO) && defined(CONFIG_RO_HEAD_ROOM) +#ifdef SECTION_IS_RO . = . + CONFIG_RO_HEAD_ROOM; #endif -#if defined(SECTION_IS_RW) && defined(CONFIG_RW_HEAD_ROOM) +#ifdef SECTION_IS_RW . = . + CONFIG_RW_HEAD_ROOM; #endif *(.text.vecttable) diff --git a/include/config.h b/include/config.h index 723347b12a..5b7c6661ce 100644 --- a/include/config.h +++ b/include/config.h @@ -4155,8 +4155,8 @@ * If needed to allocate some free space in the base of the RO or RW section * of the image, define these to be equal the required size of the free space. */ -#undef CONFIG_RO_HEAD_ROOM -#undef CONFIG_RW_HEAD_ROOM +#define CONFIG_RO_HEAD_ROOM 0 +#define CONFIG_RW_HEAD_ROOM 0 /* Firmware upgrade options. */ /* Firmware updates using other than HC channel(s). */ diff --git a/include/system.h b/include/system.h index 8145fdd491..d09d4121b3 100644 --- a/include/system.h +++ b/include/system.h @@ -552,7 +552,6 @@ void system_set_rtc_alarm(uint32_t seconds, uint32_t microseconds); */ void system_reset_rtc_alarm(void); -#ifdef CONFIG_EXTERNAL_STORAGE /** * Return address of little FW to prepare for sysjump * @@ -581,16 +580,12 @@ void system_set_image_copy(enum system_image_copy_t copy); */ enum system_image_copy_t system_get_shrspi_image_copy(void); -#endif - -#ifdef CONFIG_FW_RESET_VECTOR /** * Determine reset vector will be jumped to the assigned address. * * @return The address of the reset vector for RO/RW firmware image jump. */ uintptr_t system_get_fw_reset_vector(uintptr_t base); -#endif /** * Check if the EC is warm booting. |