blob: 905ecb28fbaca80ef64a849c0d8c2f68a95a0869 [file] [log] [blame]
Martin Roth9df9e9392016-01-12 15:55:28 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
Kyösti Mälkki5a5c8862014-01-26 14:41:54 +020014#include <smp/node.h>
Alexandru Gagniuccc966242016-01-07 19:10:24 -080015#include <arch/bootblock_romcc.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000016#include <pc80/mc146818rtc.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010017#include <halt.h>
Patrick Georgic9fa96d2010-02-24 13:58:23 +000018
Lee Leahy9c7c6f72017-03-16 11:24:09 -070019static const char *get_fallback(const char *stagelist)
20{
Lee Leahy0b5678f2017-03-16 16:01:40 -070021 while (*stagelist)
22 stagelist++;
Patrick Georgi06c04292012-01-07 19:15:43 +010023 return ++stagelist;
24}
25
Patrick Georgic9fa96d2010-02-24 13:58:23 +000026static void main(unsigned long bist)
27{
Martin Roth1b304cc2015-11-30 09:49:21 -070028 u8 boot_mode;
29 const char *default_filenames =
30 "normal/romstage\0fallback/romstage";
Kyösti Mälkkif28dbe02011-12-05 20:17:17 +020031
Patrick Georgic9fa96d2010-02-24 13:58:23 +000032 if (boot_cpu()) {
Kyösti Mälkkif9022482012-11-14 08:01:44 +020033 bootblock_mainboard_init();
Patrick Georgic9fa96d2010-02-24 13:58:23 +000034
Kyösti Mälkkif28dbe02011-12-05 20:17:17 +020035 sanitize_cmos();
Nico Huber5ce0fe12017-07-25 16:11:36 +020036
Kyösti Mälkkif28dbe02011-12-05 20:17:17 +020037 boot_mode = do_normal_boot();
38 } else {
Patrick Georgifab35e32011-03-08 07:50:43 +000039
Kyösti Mälkkif28dbe02011-12-05 20:17:17 +020040 /* Questionable single byte read from CMOS.
41 * Do not add any other CMOS access in the
42 * bootblock for AP CPUs.
43 */
Timothy Pearson82cb7872015-11-03 16:04:56 -060044 boot_mode = boot_use_normal(cmos_read(RTC_BOOT_BYTE));
Kyösti Mälkkif28dbe02011-12-05 20:17:17 +020045 }
46
Martin Roth1b304cc2015-11-30 09:49:21 -070047 char *normal_candidate = (char *)walkcbfs("coreboot-stages");
Patrick Georgi06c04292012-01-07 19:15:43 +010048
Martin Roth1b304cc2015-11-30 09:49:21 -070049 if (!normal_candidate)
50 normal_candidate = default_filenames;
51
52 unsigned long entry;
53
54 if (boot_mode) {
Patrick Georgi06c04292012-01-07 19:15:43 +010055 entry = findstage(normal_candidate);
Martin Roth1b304cc2015-11-30 09:49:21 -070056 if (entry)
57 call(entry, bist);
58 }
Patrick Georgic9fa96d2010-02-24 13:58:23 +000059
Patrick Georgi06c04292012-01-07 19:15:43 +010060 entry = findstage(get_fallback(normal_candidate));
Martin Roth1b304cc2015-11-30 09:49:21 -070061 if (entry)
62 call(entry, bist);
Patrick Georgic9fa96d2010-02-24 13:58:23 +000063
64 /* duh. we're stuck */
Patrick Georgi546953c2014-11-29 10:38:17 +010065 halt();
Patrick Georgic9fa96d2010-02-24 13:58:23 +000066}