summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/drivers/pc80/rtc/mc146818rtc_boot.c28
-rw-r--r--src/drivers/pc80/rtc/option.c28
-rw-r--r--src/include/option.h2
-rw-r--r--src/include/pc80/mc146818rtc.h1
-rw-r--r--src/lib/bootblock.c1
5 files changed, 32 insertions, 28 deletions
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 <stdint.h>
-#include <cbfs.h>
+#include <option.h>
#include <pc80/mc146818rtc.h>
#include <fallback.h>
-#if CONFIG(USE_OPTION_TABLE)
-#include <option_table.h>
-
-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();
+}
diff --git a/src/include/option.h b/src/include/option.h
index 198ca00d02..ba7cd0c1a4 100644
--- a/src/include/option.h
+++ b/src/include/option.h
@@ -16,6 +16,8 @@
#include <types.h>
+void sanitize_cmos(void);
+
enum cb_err cmos_set_option(const char *name, void *val);
enum cb_err cmos_get_option(void *dest, const char *name);
diff --git a/src/include/pc80/mc146818rtc.h b/src/include/pc80/mc146818rtc.h
index 9cd00b525c..20e963909b 100644
--- a/src/include/pc80/mc146818rtc.h
+++ b/src/include/pc80/mc146818rtc.h
@@ -217,7 +217,6 @@ static inline void cmos_post_log(void) {}
#endif /* CONFIG_ARCH_X86 */
-void sanitize_cmos(void);
void cmos_post_init(void);
#endif /* PC80_MC146818RTC_H */
diff --git a/src/lib/bootblock.c b/src/lib/bootblock.c
index beb6701cee..386f4e38d7 100644
--- a/src/lib/bootblock.c
+++ b/src/lib/bootblock.c
@@ -18,6 +18,7 @@
#include <bootblock_common.h>
#include <console/console.h>
#include <delay.h>
+#include <option.h>
#include <pc80/mc146818rtc.h>
#include <program_loading.h>
#include <symbols.h>