diff options
-rw-r--r-- | board/chell/board.c | 3 | ||||
-rw-r--r-- | board/coral/board.c | 3 | ||||
-rw-r--r-- | board/elm/board.c | 3 | ||||
-rw-r--r-- | board/eve/board.c | 3 | ||||
-rw-r--r-- | board/fizz/board.c | 3 | ||||
-rw-r--r-- | board/glados/board.c | 3 | ||||
-rw-r--r-- | board/glados_pd/board.c | 2 | ||||
-rw-r--r-- | board/kahlee/board.c | 3 | ||||
-rw-r--r-- | board/kevin/charge_ramp.c | 3 | ||||
-rw-r--r-- | board/oak/board.c | 3 | ||||
-rw-r--r-- | board/poppy/board.c | 3 | ||||
-rw-r--r-- | board/reef/board.c | 3 | ||||
-rw-r--r-- | board/reef_it8320/board.c | 3 | ||||
-rw-r--r-- | board/rowan/board.c | 3 | ||||
-rw-r--r-- | board/samus_pd/board.c | 5 | ||||
-rw-r--r-- | board/zoombini/board.c | 3 | ||||
-rw-r--r-- | common/flash.c | 2 | ||||
-rw-r--r-- | common/system.c | 14 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 2 | ||||
-rw-r--r-- | include/system.h | 7 | ||||
-rw-r--r-- | test/flash.c | 2 |
21 files changed, 39 insertions, 37 deletions
diff --git a/board/chell/board.c b/board/chell/board.c index 6637e56543..1d56ceb237 100644 --- a/board/chell/board.c +++ b/board/chell/board.c @@ -358,8 +358,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/coral/board.c b/board/coral/board.c index a1ebd18e7b..c712a79711 100644 --- a/board/coral/board.c +++ b/board/coral/board.c @@ -674,8 +674,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return (supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/elm/board.c b/board/elm/board.c index 2ec3e08de0..78989c7348 100644 --- a/board/elm/board.c +++ b/board/elm/board.c @@ -344,8 +344,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/eve/board.c b/board/eve/board.c index 38926113bd..38d9102b89 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -547,8 +547,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return (supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/fizz/board.c b/board/fizz/board.c index 842a75d1b0..9c810a772b 100644 --- a/board/fizz/board.c +++ b/board/fizz/board.c @@ -380,8 +380,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return (supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/glados/board.c b/board/glados/board.c index 893d3c32db..3d626ff5e1 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -327,8 +327,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/glados_pd/board.c b/board/glados_pd/board.c index ba46c59b78..f97845aa24 100644 --- a/board/glados_pd/board.c +++ b/board/glados_pd/board.c @@ -59,7 +59,7 @@ static void board_init(void) /* Set PD MCU system status bits */ if (system_jumped_to_this_image()) pd_status_flags |= PD_STATUS_JUMPED_TO_IMAGE; - if (system_get_image_copy() == SYSTEM_IMAGE_RW) + if (system_is_in_rw()) pd_status_flags |= PD_STATUS_IN_RW; } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); diff --git a/board/kahlee/board.c b/board/kahlee/board.c index b825d9b124..ea2d0827ce 100644 --- a/board/kahlee/board.c +++ b/board/kahlee/board.c @@ -422,8 +422,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return (supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/kevin/charge_ramp.c b/board/kevin/charge_ramp.c index 70f12da5a3..566caa6e10 100644 --- a/board/kevin/charge_ramp.c +++ b/board/kevin/charge_ramp.c @@ -19,8 +19,7 @@ int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/oak/board.c b/board/oak/board.c index 704c287c11..446edb56c5 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -326,8 +326,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/poppy/board.c b/board/poppy/board.c index 2e3c3e33b7..0303da3fba 100644 --- a/board/poppy/board.c +++ b/board/poppy/board.c @@ -685,8 +685,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return (supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/reef/board.c b/board/reef/board.c index 8abb856141..f71bba079a 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -657,8 +657,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return (supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/reef_it8320/board.c b/board/reef_it8320/board.c index 101deb2baf..8e9f97ad58 100644 --- a/board/reef_it8320/board.c +++ b/board/reef_it8320/board.c @@ -432,8 +432,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return (supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/rowan/board.c b/board/rowan/board.c index 957a0bde0d..132034f13f 100644 --- a/board/rowan/board.c +++ b/board/rowan/board.c @@ -358,8 +358,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c index aa8e6537dc..f20afd7985 100644 --- a/board/samus_pd/board.c +++ b/board/samus_pd/board.c @@ -250,7 +250,7 @@ static void board_init(void) /* Set PD MCU system status bits */ if (system_jumped_to_this_image()) pd_status_flags |= PD_STATUS_JUMPED_TO_IMAGE; - if (system_get_image_copy() == SYSTEM_IMAGE_RW) + if (system_is_in_rw()) pd_status_flags |= PD_STATUS_IN_RW; #ifdef CONFIG_PWM @@ -369,8 +369,7 @@ int pd_is_max_request_allowed(void) int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; else return supplier == CHARGE_SUPPLIER_BC12_DCP || diff --git a/board/zoombini/board.c b/board/zoombini/board.c index 47fc04e149..05aaf91239 100644 --- a/board/zoombini/board.c +++ b/board/zoombini/board.c @@ -190,8 +190,7 @@ int board_get_ramp_current_limit(int supplier, int sup_curr) int board_is_ramp_allowed(int supplier) { /* Don't allow ramping in RO when write protected. */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) return 0; /* diff --git a/common/flash.c b/common/flash.c index 3101a766bd..36c4701264 100644 --- a/common/flash.c +++ b/common/flash.c @@ -368,7 +368,7 @@ static const uintptr_t get_pstate_addr(void) uintptr_t addr = (uintptr_t)&pstate_data; /* Always use the pstate data in RO, even if we're RW */ - if (system_get_image_copy() == SYSTEM_IMAGE_RW) + if (system_is_in_rw()) addr += CONFIG_RO_MEM_OFF - CONFIG_RW_MEM_OFF; return addr; diff --git a/common/system.c b/common/system.c index 716053a870..db6ab782f6 100644 --- a/common/system.c +++ b/common/system.c @@ -497,6 +497,16 @@ static void jump_to_image(uintptr_t init_addr) resetvec(); } +static int is_rw_image(enum system_image_copy_t copy) +{ + return copy == SYSTEM_IMAGE_RW || copy == SYSTEM_IMAGE_RW_B; +} + +int system_is_in_rw(void) +{ + return is_rw_image(system_get_image_copy()); +} + int system_run_image_copy(enum system_image_copy_t copy) { uintptr_t base; @@ -515,7 +525,7 @@ int system_run_image_copy(enum system_image_copy_t copy) return EC_ERROR_ACCESS_DENIED; /* Target image must be RW image */ - if (copy != SYSTEM_IMAGE_RW) + if (!is_rw_image(copy)) return EC_ERROR_ACCESS_DENIED; /* Jumping must still be enabled */ @@ -588,7 +598,7 @@ static const struct image_data *system_get_image_data( * Read the version information from the proper location * on storage. */ - addr += (copy == SYSTEM_IMAGE_RW) ? + addr += (is_rw_image(copy)) ? CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF : CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF; diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 021839d68c..675d069472 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -1629,7 +1629,7 @@ static void pd_init_tasks(void) enable = 0; #elif defined(CONFIG_USB_PD_COMM_LOCKED) /* Disable PD communication at init if we're in RO and locked. */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW && system_is_locked()) + if (!system_is_in_rw() && system_is_locked()) enable = 0; #endif for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) diff --git a/include/system.h b/include/system.h index 5b7be4064f..2a229a68ef 100644 --- a/include/system.h +++ b/include/system.h @@ -48,6 +48,13 @@ enum system_image_copy_t { }; /** + * Checks if running image is RW or not + * + * @return True if system is running in a RW image or false otherwise. + */ +int system_is_in_rw(void); + +/** * Pre-initializes the module. This occurs before clocks or tasks are * set up. */ diff --git a/test/flash.c b/test/flash.c index ab0cf29aa7..b3bad5e984 100644 --- a/test/flash.c +++ b/test/flash.c @@ -313,7 +313,7 @@ static int test_overwrite_other(void) uint32_t offset, size; /* Test that we can overwrite the other image */ - if (system_get_image_copy() == SYSTEM_IMAGE_RW) { + if (system_is_in_rw()) { offset = CONFIG_RO_STORAGE_OFF; size = CONFIG_RO_SIZE; } else { |