From 5ce0fe117626b10f327fe279f64856cde575946c Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Tue, 25 Jul 2017 16:11:36 +0200 Subject: Port cmos.default handling to C environment bootblock Gather related code in the new file drivers/pc80/rtc/mc146818rtc_boot.c, call sanitize_cmos() from C environment bootblock. Change-Id: Ia5c64de208a5986299c0508d0e11eeb8473deef1 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/20768 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/drivers/pc80/rtc/Makefile.inc | 1 + src/drivers/pc80/rtc/mc146818rtc_boot.c | 78 ++++++++++++++++++++++++++++++++ src/drivers/pc80/rtc/mc146818rtc_romcc.c | 34 +------------- 3 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 src/drivers/pc80/rtc/mc146818rtc_boot.c (limited to 'src/drivers/pc80') diff --git a/src/drivers/pc80/rtc/Makefile.inc b/src/drivers/pc80/rtc/Makefile.inc index eb65bf5da4..998b7e7dbd 100644 --- a/src/drivers/pc80/rtc/Makefile.inc +++ b/src/drivers/pc80/rtc/Makefile.inc @@ -1,5 +1,6 @@ ifeq ($(CONFIG_ARCH_X86),y) +bootblock-$(CONFIG_DRIVERS_MC146818) += mc146818rtc_boot.c bootblock-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c postcar-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c romstage-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c diff --git a/src/drivers/pc80/rtc/mc146818rtc_boot.c b/src/drivers/pc80/rtc/mc146818rtc_boot.c new file mode 100644 index 0000000000..c5cd86ce85 --- /dev/null +++ b/src/drivers/pc80/rtc/mc146818rtc_boot.c @@ -0,0 +1,78 @@ +/* + * This file is part of the coreboot project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#ifdef __ROMCC__ +#include +#else +#include +#endif +#include +#if IS_ENABLED(CONFIG_USE_OPTION_TABLE) +#include +#endif + +int cmos_error(void); +int cmos_error(void) +{ + unsigned char reg_d; + /* See if the cmos error condition has been flagged */ + reg_d = cmos_read(RTC_REG_D); + return (reg_d & RTC_VRT) == 0; +} + +int cmos_chksum_valid(void); +int cmos_chksum_valid(void) +{ +#if IS_ENABLED(CONFIG_USE_OPTION_TABLE) + unsigned char addr; + u16 sum, old_sum; + + sum = 0; + /* Compute the cmos checksum */ + for (addr = LB_CKS_RANGE_START; addr <= LB_CKS_RANGE_END; addr++) + sum += cmos_read(addr); + + /* Read the stored checksum */ + old_sum = cmos_read(LB_CKS_LOC) << 8; + old_sum |= cmos_read(LB_CKS_LOC + 1); + + return sum == old_sum; +#else + return 0; +#endif +} + +#if IS_ENABLED(CONFIG_USE_OPTION_TABLE) +void sanitize_cmos(void) +{ + if (cmos_error() || !cmos_chksum_valid() || + IS_ENABLED(CONFIG_STATIC_OPTION_TABLE)) { + size_t length = 128; + const unsigned char *cmos_default = +#ifdef __ROMCC__ + walkcbfs("cmos.default"); +#else + cbfs_boot_map_with_leak("cmos.default", + CBFS_COMPONENT_CMOS_DEFAULT, &length); +#endif + if (cmos_default) { + int i; + cmos_disable_rtc(); + for (i = 14; i < MIN(128, length); i++) + cmos_write_inner(cmos_default[i], i); + cmos_enable_rtc(); + } + } +} +#endif diff --git a/src/drivers/pc80/rtc/mc146818rtc_romcc.c b/src/drivers/pc80/rtc/mc146818rtc_romcc.c index dc4f2efec4..a280882a77 100644 --- a/src/drivers/pc80/rtc/mc146818rtc_romcc.c +++ b/src/drivers/pc80/rtc/mc146818rtc_romcc.c @@ -1,43 +1,13 @@ #include #include #include -#if IS_ENABLED(CONFIG_USE_OPTION_TABLE) -#include "option_table.h" -#endif + +#include "mc146818rtc_boot.c" #if CONFIG_MAX_REBOOT_CNT > 15 #error "CONFIG_MAX_REBOOT_CNT too high" #endif -static int cmos_error(void) -{ - unsigned char reg_d; - /* See if the cmos error condition has been flagged */ - reg_d = cmos_read(RTC_REG_D); - return (reg_d & RTC_VRT) == 0; -} - -static int cmos_chksum_valid(void) -{ -#if IS_ENABLED(CONFIG_USE_OPTION_TABLE) - unsigned char addr; - u16 sum, old_sum; - - sum = 0; - /* Compute the cmos checksum */ - for (addr = LB_CKS_RANGE_START; addr <= LB_CKS_RANGE_END; addr++) - sum += cmos_read(addr); - - /* Read the stored checksum */ - old_sum = cmos_read(LB_CKS_LOC) << 8; - old_sum |= cmos_read(LB_CKS_LOC+1); - - return sum == old_sum; -#else - return 0; -#endif -} - static inline __attribute__((unused)) int boot_count(uint8_t rtc_byte) { return rtc_byte >> 4; -- cgit v1.2.3