From 29a57a037abb86f11d3390dc8de0a5acf93f442f Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Fri, 19 Dec 2014 16:16:26 -0800 Subject: system: Add function to convert passed system_image_copy_t to string This conversion is needed in files outside of system.c, so add a new function. BUG=chrome-os-partner:34599 TEST=Manual on samus_pd. Run "pd 0 info" and verify "Image RW" is printed. BRANCH=Samus Signed-off-by: Shawn Nematbakhsh Change-Id: Ia905ba9cf985f3714fa75c81670b8a39e9608f3d Reviewed-on: https://chromium-review.googlesource.com/236980 Tested-by: Shawn Nematbakhsh Reviewed-by: Alec Berg Commit-Queue: Shawn Nematbakhsh --- common/system.c | 17 +++++++++++------ common/usb_pd_protocol.c | 3 ++- include/system.h | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common/system.c b/common/system.c index 268e393b1b..b31ab43015 100644 --- a/common/system.c +++ b/common/system.c @@ -81,7 +81,6 @@ static const char * const reset_flag_descs[] = { "hibernate", "rtc-alarm", "wake-pin", "low-battery", "sysjump", "hard", "ap-off", "preserved"}; -static const char * const image_names[] = {"unknown", "RO", "RW"}; static uint32_t reset_flags; static int jumped_to_image; static int disable_jump; /* Disable ALL jumps if system is locked */ @@ -293,10 +292,11 @@ void system_disable_jump(void) } if (ret == EC_SUCCESS) { enable_mpu = 1; - CPRINTS("%s image locked", image_names[copy]); + CPRINTS("%s image locked", + system_image_copy_t_to_string(copy)); } else { CPRINTS("Failed to lock %s image (%d)", - image_names[copy], ret); + system_image_copy_t_to_string(copy), ret); } if (enable_mpu) @@ -372,8 +372,13 @@ test_mockable int system_unsafe_to_overwrite(uint32_t offset, uint32_t size) const char *system_get_image_copy_string(void) { - int copy = system_get_image_copy(); - return copy < ARRAY_SIZE(image_names) ? image_names[copy] : "?"; + return system_image_copy_t_to_string(system_get_image_copy()); +} + +const char *system_image_copy_t_to_string(enum system_image_copy_t copy) +{ + static const char * const image_names[] = {"unknown", "RO", "RW"}; + return image_names[copy < ARRAY_SIZE(image_names) ? copy : 0]; } /** @@ -469,7 +474,7 @@ int system_run_image_copy(enum system_image_copy_t copy) return EC_ERROR_UNKNOWN; #endif - CPRINTS("Jumping to image %s", image_names[copy]); + CPRINTS("Jumping to image %s", system_image_copy_t_to_string(copy)); jump_to_image(init_addr); diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 515ec40d47..97afce801f 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -2667,7 +2667,8 @@ static int command_pd(int argc, char **argv) ccprintf("Hash "); for (i = 0; i < PD_RW_HASH_SIZE / 4; i++) ccprintf("%08x ", pd[port].dev_rw_hash[i]); - ccprintf("\nImage %d\n", pd[port].current_image); + ccprintf("\nImage %s\n", system_image_copy_t_to_string( + pd[port].current_image)); } else if (!strncasecmp(argv[2], "soft", 4)) { set_state(port, PD_STATE_SOFT_RESET); task_wake(PORT_TO_TASK_ID(port)); diff --git a/include/system.h b/include/system.h index 4463c4baf9..71cad098f9 100644 --- a/include/system.h +++ b/include/system.h @@ -146,6 +146,11 @@ int system_unsafe_to_overwrite(uint32_t offset, uint32_t size); */ const char *system_get_image_copy_string(void); +/** + * Return a text description of the passed image copy parameter. + */ +const char *system_image_copy_t_to_string(enum system_image_copy_t copy); + /** * Return the number of bytes used in the specified image. * -- cgit v1.2.1