From 3e1c72ea23fe3c37f5a4e4e8bceea38c0322ba31 Mon Sep 17 00:00:00 2001 From: Jack Rosenthal Date: Tue, 30 Jul 2019 15:45:41 -0600 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1727570 Reviewed-by: Denis Brockus --- common/system.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'common') 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)); -- cgit v1.2.1