From b2680a12e4ddeaa0a33975eb0034feb6649d333c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Sat, 4 Jan 2020 18:04:39 +0200 Subject: drivers/pc80/rtc: Move sanitize_cmos() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implementation depends on USE_OPTION_TABLE. Change-Id: If7f8f478db3214842b6cc60cd77b4ea81cab6e3a Signed-off-by: Kyösti Mälkki Reviewed-on: https://review.coreboot.org/c/coreboot/+/38195 Reviewed-by: Angel Pons Tested-by: build bot (Jenkins) --- src/drivers/pc80/rtc/mc146818rtc_boot.c | 28 +--------------------------- src/drivers/pc80/rtc/option.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 27 deletions(-) (limited to 'src/drivers/pc80') diff --git a/src/drivers/pc80/rtc/mc146818rtc_boot.c b/src/drivers/pc80/rtc/mc146818rtc_boot.c index e599affd2d..718cfbf4d2 100644 --- a/src/drivers/pc80/rtc/mc146818rtc_boot.c +++ b/src/drivers/pc80/rtc/mc146818rtc_boot.c @@ -12,36 +12,10 @@ */ #include -#include +#include #include #include -#if CONFIG(USE_OPTION_TABLE) -#include - -int cmos_lb_cks_valid(void) -{ - return cmos_checksum_valid(LB_CKS_RANGE_START, LB_CKS_RANGE_END, LB_CKS_LOC); -} - -void sanitize_cmos(void) -{ - if (cmos_error() || !cmos_lb_cks_valid() || CONFIG(STATIC_OPTION_TABLE)) { - size_t length = 128; - const unsigned char *cmos_default = - cbfs_boot_map_with_leak("cmos.default", - CBFS_COMPONENT_CMOS_DEFAULT, &length); - if (cmos_default) { - size_t i; - u8 control_state = cmos_disable_rtc(); - for (i = 14; i < MIN(128, length); i++) - cmos_write_inner(cmos_default[i], i); - cmos_restore_rtc(control_state); - } - } -} -#endif - #if CONFIG_MAX_REBOOT_CNT > 15 #error "CONFIG_MAX_REBOOT_CNT too high" #endif diff --git a/src/drivers/pc80/rtc/option.c b/src/drivers/pc80/rtc/option.c index c7851e5357..ad77669a8d 100644 --- a/src/drivers/pc80/rtc/option.c +++ b/src/drivers/pc80/rtc/option.c @@ -233,3 +233,31 @@ enum cb_err cmos_set_option(const char *name, void *value) rdev_munmap(&rdev, ct); return CB_SUCCESS; } + +int cmos_lb_cks_valid(void) +{ + return cmos_checksum_valid(LB_CKS_RANGE_START, LB_CKS_RANGE_END, LB_CKS_LOC); +} + +static void cmos_load_defaults(void) +{ + size_t length = 128; + size_t i; + + const unsigned char *cmos_default = + cbfs_boot_map_with_leak("cmos.default", + CBFS_COMPONENT_CMOS_DEFAULT, &length); + if (!cmos_default) + return; + + u8 control_state = cmos_disable_rtc(); + for (i = 14; i < MIN(128, length); i++) + cmos_write_inner(cmos_default[i], i); + cmos_restore_rtc(control_state); +} + +void sanitize_cmos(void) +{ + if (cmos_error() || !cmos_lb_cks_valid() || CONFIG(STATIC_OPTION_TABLE)) + cmos_load_defaults(); +} -- cgit v1.2.3