Another indirection for normal/fallback bootblock
[coreboot.git] / src / arch / x86 / init / bootblock_normal.c
1 #include <bootblock_common.h>
2 #include <pc80/mc146818rtc.h>
3
4 static const char *get_fallback(const char *stagelist) {
5         while (*stagelist) stagelist++;
6         return ++stagelist;
7 }
8
9 static void main(unsigned long bist)
10 {
11         unsigned long entry;
12         int boot_mode;
13         const char *default_filenames = "normal/romstage\0fallback/romstage";
14
15         if (boot_cpu()) {
16                 bootblock_northbridge_init();
17                 bootblock_southbridge_init();
18                 bootblock_cpu_init();
19
20 #if CONFIG_USE_OPTION_TABLE
21                 sanitize_cmos();
22 #endif
23                 boot_mode = do_normal_boot();
24         } else {
25
26                 /* Questionable single byte read from CMOS.
27                  * Do not add any other CMOS access in the
28                  * bootblock for AP CPUs.
29                  */
30                 boot_mode = last_boot_normal();
31         }
32
33         char *filenames = (char *)walkcbfs("coreboot-stages");
34         if (!filenames) {
35                 filenames = default_filenames;
36         }
37         char *normal_candidate = filenames;
38
39         if (boot_mode)
40                 entry = findstage(normal_candidate);
41         else
42                 entry = findstage(get_fallback(normal_candidate));
43
44         if (entry) call(entry, bist);
45
46         /* run fallback if normal can't be found */
47         entry = findstage(get_fallback(normal_candidate));
48         if (entry) call(entry, bist);
49
50         /* duh. we're stuck */
51         asm volatile ("1:\n\thlt\n\tjmp 1b\n\t");
52 }
53