coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mc146818rtc_boot.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stdint.h>
4 #include <console/console.h>
5 #include <pc80/mc146818rtc.h>
6 #include <fallback.h>
7 
8 #if CONFIG_MAX_REBOOT_CNT > 15
9 #error "CONFIG_MAX_REBOOT_CNT too high"
10 #endif
11 
12 static int boot_count(uint8_t rtc_byte)
13 {
14  return rtc_byte >> 4;
15 }
16 
18 {
19  return rtc_byte + (1 << 4);
20 }
21 
23 {
24  return rtc_byte & ~RTC_BOOT_NORMAL;
25 }
26 
27 static int boot_use_normal(uint8_t rtc_byte)
28 {
29  return rtc_byte & RTC_BOOT_NORMAL;
30 }
31 
32 int do_normal_boot(void)
33 {
34  unsigned char byte;
35 
36  if (cmos_error() || (CONFIG(USE_OPTION_TABLE) && !cmos_lb_cks_valid())) {
38  "Invalid CMOS checksum detected! Force fallback boot...\n");
39  byte = cmos_read(RTC_BOOT_BYTE);
40  byte &= boot_set_fallback(byte) & 0x0f;
41  byte |= 0xf << 4;
43  }
44 
45  /* The RTC_BOOT_BYTE is now o.k. see where to go. */
46  byte = cmos_read(RTC_BOOT_BYTE);
47 
48  /* Are we attempting to boot normally? */
49  if (boot_use_normal(byte)) {
50  /* Are we already at the max count? */
51  if (boot_count(byte) < CONFIG_MAX_REBOOT_CNT)
52  byte = increment_boot_count(byte);
53  else
54  byte = boot_set_fallback(byte);
55  }
56 
57  /* Save the boot byte */
59 
60  /* Return selected code path for this boot attempt */
61  return boot_use_normal(byte);
62 }
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
int cmos_error(void)
Definition: mc146818rtc.c:60
static void cmos_write(unsigned char val, unsigned char addr)
Definition: mc146818rtc.h:141
#define RTC_BOOT_BYTE
Definition: mc146818rtc.h:102
static unsigned char cmos_read(unsigned char addr)
Definition: mc146818rtc.h:105
#define RTC_BOOT_NORMAL
Definition: mc146818rtc.h:103
static int boot_use_normal(uint8_t rtc_byte)
static int boot_count(uint8_t rtc_byte)
static uint8_t boot_set_fallback(uint8_t rtc_byte)
static uint8_t increment_boot_count(uint8_t rtc_byte)
int do_normal_boot(void)
int cmos_lb_cks_valid(void)
Definition: option.c:194
unsigned char uint8_t
Definition: stdint.h:8