blob: 8dff6e1cda9ba4b5b48a46c0674c458e22ba7188 [file] [log] [blame]
AppaRao Pulie63eeda2019-07-05 16:25:38 +05301/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#pragma once
18
AppaRao Pulie4e95652019-07-19 16:52:01 +053019#include "pfr.hpp"
20
AppaRao Puli67d184c2020-05-29 00:48:33 +053021#include <boost/asio.hpp>
Jason M. Bills70108442022-09-21 12:32:16 -070022#include <boost/container/flat_map.hpp>
Alex Schendel5cf320c2021-12-09 12:11:04 -080023#include <phosphor-logging/lg2.hpp>
AppaRao Puli67d184c2020-05-29 00:48:33 +053024#include <phosphor-logging/log.hpp>
25#include <sdbusplus/asio/object_server.hpp>
26
27#include <string>
28
AppaRao Pulie63eeda2019-07-05 16:25:38 +053029namespace pfr
30{
31
AppaRao Puli67d184c2020-05-29 00:48:33 +053032static constexpr const char* versionPurposeBMC =
AppaRao Pulie4e95652019-07-19 16:52:01 +053033 "xyz.openbmc_project.Software.Version.VersionPurpose.BMC";
AppaRao Puli67d184c2020-05-29 00:48:33 +053034static constexpr const char* versionPurposeHost =
AppaRao Pulie4e95652019-07-19 16:52:01 +053035 "xyz.openbmc_project.Software.Version.VersionPurpose.Host";
AppaRao Puli67d184c2020-05-29 00:48:33 +053036static constexpr const char* versionPurposeOther =
AppaRao Pulie4e95652019-07-19 16:52:01 +053037 "xyz.openbmc_project.Software.Version.VersionPurpose.Other";
38
AppaRao Puli67d184c2020-05-29 00:48:33 +053039static constexpr const char* versionStr = "Version";
40static constexpr const char* ufmProvisionedStr = "UfmProvisioned";
41static constexpr const char* ufmLockedStr = "UfmLocked";
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +000042static constexpr const char* ufmSupportStr = "UfmSupport";
AppaRao Pulie4e95652019-07-19 16:52:01 +053043
AppaRao Pulie63eeda2019-07-05 16:25:38 +053044class PfrVersion
45{
46 public:
AppaRao Puli67d184c2020-05-29 00:48:33 +053047 PfrVersion(sdbusplus::asio::object_server& srv_,
48 std::shared_ptr<sdbusplus::asio::connection>& conn_,
49 const std::string& path_, const ImageType& imgType_,
50 const std::string& purpose_);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053051 ~PfrVersion() = default;
52
53 std::shared_ptr<sdbusplus::asio::connection> conn;
54
AppaRao Pulie4e95652019-07-19 16:52:01 +053055 void updateVersion();
56
AppaRao Pulie63eeda2019-07-05 16:25:38 +053057 private:
AppaRao Puli67d184c2020-05-29 00:48:33 +053058 sdbusplus::asio::object_server& server;
AppaRao Pulie4e95652019-07-19 16:52:01 +053059 std::shared_ptr<sdbusplus::asio::dbus_interface> versionIface;
60 bool internalSet = false;
AppaRao Pulie63eeda2019-07-05 16:25:38 +053061
62 std::string path;
63 std::string version;
64 std::string purpose;
AppaRao Pulie4e95652019-07-19 16:52:01 +053065 ImageType imgType;
AppaRao Pulie63eeda2019-07-05 16:25:38 +053066};
67
68class PfrConfig
69{
70 public:
AppaRao Puli67d184c2020-05-29 00:48:33 +053071 PfrConfig(sdbusplus::asio::object_server& srv_,
72 std::shared_ptr<sdbusplus::asio::connection>& conn_);
AppaRao Pulie63eeda2019-07-05 16:25:38 +053073 ~PfrConfig() = default;
74
75 std::shared_ptr<sdbusplus::asio::connection> conn;
76
AppaRao Pulie4e95652019-07-19 16:52:01 +053077 void updateProvisioningStatus();
78
Zhikui Renc96f37d2021-12-08 15:40:51 -080079 bool getPfrProvisioned() const
80 {
81 return ufmProvisioned;
82 }
83
AppaRao Pulie63eeda2019-07-05 16:25:38 +053084 private:
AppaRao Puli67d184c2020-05-29 00:48:33 +053085 sdbusplus::asio::object_server& server;
AppaRao Pulie4e95652019-07-19 16:52:01 +053086 std::shared_ptr<sdbusplus::asio::dbus_interface> pfrCfgIface;
87 bool internalSet = false;
AppaRao Pulie63eeda2019-07-05 16:25:38 +053088
AppaRao Pulie4e95652019-07-19 16:52:01 +053089 bool ufmProvisioned;
90 bool ufmLocked;
Chalapathi Venkataramashettyf8819702021-02-03 09:43:46 +000091 bool ufmSupport;
AppaRao Pulie63eeda2019-07-05 16:25:38 +053092};
93
Chalapathi Venkataramashettybcc7ce12021-05-17 04:27:21 +000094// Firmware resiliency major map.
95// {<CPLD association>, {<Redfish MessageID>, <Error reason> })
96static const boost::container::flat_map<uint8_t,
97 std::pair<std::string, std::string>>
98 majorErrorCodeMapRev2 = {
99 {0x03, {"FirmwareResiliencyError", "Firmware update failed"}}};
100
Zhikui Renc96f37d2021-12-08 15:40:51 -0800101// postcode (platform state) map.
102static const boost::container::flat_map<uint8_t, std::string> postcodeMap = {
103 {0x00, "Postcode unavailable"},
104 {0x01, "CPLD Nios II processor waiting to start"},
105 {0x02, "CPLD Nios II processor started"},
106 {0x03, "Enter T-1"},
107 {0x04, "T-1 reserved 4"},
108 {0x05, "T-1 Reserved 5"},
109 {0x06, "BMC flash authentication"},
110 {0x07, "PCH/CPU flash authentication"},
111 {0x08, "Lockdown due to authentication failures"},
112 {0x09, "Enter T0"},
113 {0x0A, "T0 BMC booted"},
114 {0x0B, "T0 ME booted"},
115 {0x0C, "T0 Modular booted"},
116 {0x0C, "T0 BIOS booted"},
117 {0x0E, "T0 boot complete"},
118 {0x0F, "T0 Reserved 0xF"},
119 {0x10, "PCH/CPU firmware update"},
120 {0x11, "BMC firmware update"},
121 {0x12, "CPLD update (in CPLD Active Image)"},
122 {0x13, "CPLD update (in CPLD ROM)"},
123 {0x14, "PCH/CPU firmware volume update"},
124 {0x15, "CPLD Nios II processor waiting to start"},
125 {0x16, "Reserved 0x16"},
126 {0x40, "T-1 firmware recovery due to authentication failure"},
127 {0x41, "T-1 forced active firmware recovery"},
128 {0x42, "WDT timeout recovery"},
129 {0x43, "CPLD recovery (in CPLD ROM)"},
130 {0x44, "Lockdown due to PIT L1"},
131 {0x45, "PIT L2 firmware sealed"},
132 {0x46, "Lockdown due to PIT L2 PCH/CPU firmware hash mismatch"},
133 {0x47, "Lockdown due to PIT L2 BMC firmware hash mismatch"},
134 {0x48, "Reserved 0x48"}};
135
136class PfrPostcode
137{
138 public:
139 PfrPostcode(sdbusplus::asio::object_server& srv_,
140 std::shared_ptr<sdbusplus::asio::connection>& conn_);
141 ~PfrPostcode() = default;
142
143 std::shared_ptr<sdbusplus::asio::connection> conn;
144
145 void updatePostcode();
146
147 private:
148 sdbusplus::asio::object_server& server;
149 std::shared_ptr<sdbusplus::asio::dbus_interface> pfrPostcodeIface;
150 bool internalSet = false;
151 uint8_t postcode;
152};
153
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530154} // namespace pfr