blob: 33917eacb143977acac6eed5fe3dd91ba8c27da7 [file] [log] [blame]
Ramesh Iyyarc98bab52020-04-16 04:04:29 -05001extern "C" {
2#include <libpdbg.h>
3}
4
Marri Devender Rao78479602020-01-06 03:45:11 -06005#include "phalerror/phal_error.hpp"
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -05006
Ramesh Iyyarc98bab52020-04-16 04:04:29 -05007#include <libekb.H>
Marri Devender Rao78479602020-01-06 03:45:11 -06008#include <libipl.H>
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -05009
Lakshminarayana R. Kammath75912e82020-04-28 07:37:17 -050010#include <ext_interface.hpp>
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050011#include <phosphor-logging/log.hpp>
12#include <registration.hpp>
Lakshminarayana R. Kammath75912e82020-04-28 07:37:17 -050013
14#include "attributes_info.H"
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050015namespace openpower
16{
17namespace phal
18{
19
20using namespace phosphor::logging;
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050021
22/**
Lakshminarayana R. Kammath75912e82020-04-28 07:37:17 -050023 * @brief Check if master processor or not
24 *
25 * @return True/False
26 */
27bool isMasterProc(struct pdbg_target* procTarget)
28{
29 ATTR_PROC_MASTER_TYPE_Type type;
30
31 // Get processor type (Master or Alt-master)
32 if (DT_GET_PROP(ATTR_PROC_MASTER_TYPE, procTarget, type))
33 {
34 log<level::ERR>("Attribute [ATTR_PROC_MASTER_TYPE] get failed");
35 throw std::runtime_error(
36 "Attribute [ATTR_PROC_MASTER_TYPE] get failed");
37 }
38
39 /* Attribute value 0 corresponds to master processor */
40 if (type == 0)
41 {
42 return true;
43 }
44 else
45 {
46 return false;
47 }
48}
49
50/**
51 * @brief Select BOOT SEEPROM and Measurement SEEPROM(PRIMARY/BACKUP) on POWER
52 * processor position 0/1 depending on boot count before kicking off
53 * the boot.
54 *
55 * @return void
56 */
57void selectBootSeeprom()
58{
59 struct pdbg_target* procTarget;
60 ATTR_BACKUP_SEEPROM_SELECT_Enum bkpSeePromSelect;
61 ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT_Enum bkpMeaSeePromSelect;
62
63 pdbg_for_each_class_target("proc", procTarget)
64 {
65 if (!isMasterProc(procTarget))
66 {
67 continue;
68 }
69
70 // Choose seeprom side to boot from based on boot count
71 if (getBootCount() > 0)
72 {
73 log<level::INFO>("Setting SBE seeprom side to 0",
74 entry("SBE_SIDE_SELECT=%d",
75 ENUM_ATTR_BACKUP_SEEPROM_SELECT_PRIMARY));
76
77 bkpSeePromSelect = ENUM_ATTR_BACKUP_SEEPROM_SELECT_PRIMARY;
78 bkpMeaSeePromSelect =
79 ENUM_ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT_PRIMARY;
80 }
81 else
82 {
83 log<level::INFO>("Setting SBE seeprom side to 1",
84 entry("SBE_SIDE_SELECT=%d",
85 ENUM_ATTR_BACKUP_SEEPROM_SELECT_SECONDARY));
86 bkpSeePromSelect = ENUM_ATTR_BACKUP_SEEPROM_SELECT_SECONDARY;
87 bkpMeaSeePromSelect =
88 ENUM_ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT_SECONDARY;
89 }
90
91 // Set the Attribute as per bootcount policy for boot seeprom
92 if (DT_SET_PROP(ATTR_BACKUP_SEEPROM_SELECT, procTarget,
93 bkpSeePromSelect))
94 {
95 log<level::ERR>(
96 "Attribute [ATTR_BACKUP_SEEPROM_SELECT] set failed");
97 throw std::runtime_error(
98 "Attribute [ATTR_BACKUP_SEEPROM_SELECT] set failed");
99 }
100
101 // Set the Attribute as per bootcount policy for measurement seeprom
102 if (DT_SET_PROP(ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT, procTarget,
103 bkpMeaSeePromSelect))
104 {
105 log<level::ERR>(
106 "Attribute [ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT] set "
107 "failed");
108 throw std::runtime_error(
109 "Attribute [ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT] set "
110 "failed");
111 }
112 }
113}
114
115/**
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500116 * @brief Starts the self boot engine on POWER processor position 0
117 * to kick off a boot.
118 * @return void
119 */
Dhruvaraj Subhashchandranc2e42762020-06-17 00:30:12 -0500120void startHost(enum ipl_type iplType = IPL_TYPE_NORMAL)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500121{
Marri Devender Rao78479602020-01-06 03:45:11 -0600122 // add callback methods for debug traces and for boot failures
123 openpower::pel::addBootErrorCallbacks();
124
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500125 if (!pdbg_targets_init(NULL))
126 {
127 log<level::ERR>("pdbg_targets_init failed");
128 openpower::pel::detail::processBootErrorCallback(false);
129 throw std::runtime_error("pdbg target initialization failed");
130 }
131 // To clear trace if success
132 openpower::pel::detail::processBootErrorCallback(true);
133
134 if (libekb_init())
135 {
136 log<level::ERR>("libekb_init failed");
137 openpower::pel::detail::processBootErrorCallback(false);
138 throw std::runtime_error("libekb initialization failed");
139 }
140 // To clear trace if success
141 openpower::pel::detail::processBootErrorCallback(true);
142
143 if (ipl_init(IPL_AUTOBOOT) != 0)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500144 {
145 log<level::ERR>("ipl_init failed");
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500146 openpower::pel::detail::processBootErrorCallback(false);
Marri Devender Rao78479602020-01-06 03:45:11 -0600147 throw std::runtime_error("Boot initialization failed");
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500148 }
Dhruvaraj Subhashchandranc2e42762020-06-17 00:30:12 -0500149
150 ipl_set_type(iplType);
151
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500152 // To clear trace if success
153 openpower::pel::detail::processBootErrorCallback(true);
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500154
Lakshminarayana R. Kammath75912e82020-04-28 07:37:17 -0500155 // Run select seeprom before poweron
156 try
157 {
158 selectBootSeeprom();
159
160 // To clear trace as it is success
161 openpower::pel::detail::processBootErrorCallback(true);
162 }
163 catch (const std::exception& ex)
164 {
165 // create PEL in failure
166 openpower::pel::detail::processBootErrorCallback(false);
167 log<level::ERR>("SEEPROM selection failed", entry("ERR=%s", ex.what()));
168 throw ex;
169 }
170
Marri Devender Rao78479602020-01-06 03:45:11 -0600171 // callback method will be called upon failure which will create the PEL
172 int rc = ipl_run_major(0);
173 if (rc > 0)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500174 {
175 log<level::ERR>("step 0 failed to start the host");
Marri Devender Rao78479602020-01-06 03:45:11 -0600176 throw std::runtime_error("Failed to execute host start boot step");
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500177 }
178}
179
Dhruvaraj Subhashchandranc2e42762020-06-17 00:30:12 -0500180/**
181 * @brief Starts the reboot with type memory preserving reboot.
182 * @return void
183 */
184void startHostMpReboot()
185{
186 // set ipl type as mpipl
187 startHost(IPL_TYPE_MPIPL);
188}
189
190/**
191 * @brief Starts the normal boot type.
192 * @return void
193 */
194void startHostNormal()
195{
196 startHost();
197}
198
199REGISTER_PROCEDURE("startHost", startHostNormal);
200REGISTER_PROCEDURE("startHostMpReboot", startHostMpReboot);
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500201
202} // namespace phal
203} // namespace openpower