blob: 212010770432db7912ad153acee2e9e07080704e [file] [log] [blame]
Patrick Venture22e38752018-11-21 08:52:49 -08001/*
2 * Copyright 2018 Google Inc.
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
Patrick Venture148cd652018-11-06 10:59:47 -080017#include "config.h"
18
Patrick Venturea6b4abd2019-07-19 10:58:55 -070019#include "buildjson.hpp"
Patrick Venture64919ec2018-11-15 11:52:07 -080020#include "file_handler.hpp"
Patrick Venturec7ca2912018-11-02 11:38:33 -070021#include "firmware_handler.hpp"
Patrick Venture84778b82019-06-26 20:11:09 -070022#include "flags.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -080023#include "image_handler.hpp"
Patrick Ventureefce8f92018-12-14 16:39:00 -080024#include "lpc_aspeed.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -080025#include "lpc_handler.hpp"
Patrick Ventureefce8f92018-12-14 16:39:00 -080026#include "lpc_nuvoton.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -080027#include "pci_handler.hpp"
Patrick Venture6d7735d2019-06-21 10:03:19 -070028#include "prepare_systemd.hpp"
Patrick Venture1d66fe62019-06-03 14:57:27 -070029#include "status.hpp"
Patrick Venture6f81b162019-05-20 14:02:59 -070030#include "update_systemd.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -070031#include "util.hpp"
Patrick Venture26a17262019-05-20 11:03:35 -070032#include "verify_systemd.hpp"
Patrick Venturec7ca2912018-11-02 11:38:33 -070033
Patrick Venture192d60f2018-11-06 11:11:59 -080034#include <cstdint>
Patrick Venturec7ca2912018-11-02 11:38:33 -070035#include <memory>
36#include <phosphor-logging/log.hpp>
Patrick Venture4eb55952018-11-16 15:36:24 -080037#include <sdbusplus/bus.hpp>
Patrick Venturea6b4abd2019-07-19 10:58:55 -070038#include <string>
Patrick Venturefa06a5f2019-07-01 09:22:38 -070039#include <unordered_map>
Patrick Venturea6b4abd2019-07-19 10:58:55 -070040#include <vector>
Patrick Venturec7ca2912018-11-02 11:38:33 -070041
Patrick Venture1d5a31c2019-05-20 11:38:22 -070042namespace ipmi_flash
Patrick Venturec7ca2912018-11-02 11:38:33 -070043{
Patrick Venturea6b4abd2019-07-19 10:58:55 -070044
Patrick Venturea78e39f2018-11-06 18:37:06 -080045namespace
46{
Patrick Venture48e309c2019-06-29 07:51:19 -070047
Patrick Venture7b91cbc2018-11-28 14:24:41 -080048/* The maximum external buffer size we expect is 64KB. */
Patrick Venture28abae72018-12-14 09:44:02 -080049static constexpr std::size_t memoryRegionSize = 64 * 1024UL;
Patrick Venture7b91cbc2018-11-28 14:24:41 -080050
Patrick Venturea6b4abd2019-07-19 10:58:55 -070051static constexpr const char* jsonConfigurationPath =
52 "/usr/share/phosphor-ipmi-flash/";
53
Patrick Venturee7728422018-11-14 20:16:33 -080054#ifdef ENABLE_LPC_BRIDGE
55#if defined(ASPEED_LPC)
Patrick Venture78b1a662019-01-17 12:38:26 -080056LpcDataHandler lpcDataHandler(
57 LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize));
Patrick Venturee7728422018-11-14 20:16:33 -080058#elif defined(NUVOTON_LPC)
Patrick Venture36bffb42019-06-24 10:47:47 -070059LpcDataHandler lpcDataHandler(
60 LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS, memoryRegionSize));
Patrick Venturee7728422018-11-14 20:16:33 -080061#else
62#error "You must specify a hardware implementation."
63#endif
64#endif
65
Patrick Venture102ecbb2019-04-30 16:08:49 -070066#ifdef ENABLE_PCI_BRIDGE
67#if defined(ASPEED_P2A)
Patrick Venture4289e712019-04-30 17:08:50 -070068PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize);
Patrick Venture102ecbb2019-04-30 16:08:49 -070069#else
70#error "You must specify a hardware implementation."
71#endif
72#endif
Patrick Venturea78e39f2018-11-06 18:37:06 -080073
Patrick Venture1cde5f92018-11-07 08:26:47 -080074std::vector<DataHandlerPack> supportedTransports = {
Patrick Venture84778b82019-06-26 20:11:09 -070075 {FirmwareFlags::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080076#ifdef ENABLE_PCI_BRIDGE
Patrick Venture84778b82019-06-26 20:11:09 -070077 {FirmwareFlags::UpdateFlags::p2a, &pciDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080078#endif
79#ifdef ENABLE_LPC_BRIDGE
Patrick Venture84778b82019-06-26 20:11:09 -070080 {FirmwareFlags::UpdateFlags::lpc, &lpcDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080081#endif
82};
83
Patrick Venturef32a4532019-07-19 10:15:40 -070084/**
85 * Given a name and path, create a HandlerPack.
86 *
87 * @param[in] name - the blob id path for this
88 * @param[in] path - the file path to write the contents.
89 * @return the HandlerPack.
90 */
91HandlerPack CreateFileHandlerPack(const std::string& name,
92 const std::string& path)
93{
94 return HandlerPack(name, std::make_unique<FileHandler>(path));
95}
96
Patrick Venturea78e39f2018-11-06 18:37:06 -080097} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070098} // namespace ipmi_flash
Patrick Venturec7ca2912018-11-02 11:38:33 -070099
Patrick Venture5b451e62018-11-14 14:20:08 -0800100extern "C" {
Patrick Venture5b451e62018-11-14 14:20:08 -0800101std::unique_ptr<blobs::GenericBlobInterface> createHandler();
Patrick Venture5b451e62018-11-14 14:20:08 -0800102}
Patrick Venture5b451e62018-11-14 14:20:08 -0800103
104std::unique_ptr<blobs::GenericBlobInterface> createHandler()
Patrick Venturec7ca2912018-11-02 11:38:33 -0700105{
Patrick Venturea6b4abd2019-07-19 10:58:55 -0700106 /* NOTE: This is unused presently. */
107 {
108 std::vector<ipmi_flash::HandlerConfig> configsFromJson =
109 ipmi_flash::BuildHandlerConfigs(ipmi_flash::jsonConfigurationPath);
110
111 for (const auto& config : configsFromJson)
112 {
113 std::fprintf(stderr, "config loaded: %s\n", config.blobId.c_str());
114 }
115 }
116
Patrick Venture7c2a00e2019-07-01 17:33:03 -0700117 ipmi_flash::ActionMap actionPacks = {};
118
Patrick Venturef32a4532019-07-19 10:15:40 -0700119 {
120 auto bmcPack = std::make_unique<ipmi_flash::ActionPack>();
Patrick Venture6f81b162019-05-20 14:02:59 -0700121
Patrick Venturef32a4532019-07-19 10:15:40 -0700122#ifdef ENABLE_REBOOT_UPDATE
123 static constexpr auto rebootTarget = "reboot.target";
124 static constexpr auto rebootMode = "replace-irreversibly";
125
126 bmcPack->update =
127 ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
128 sdbusplus::bus::new_default(), rebootTarget, rebootMode);
Patrick Venture6f81b162019-05-20 14:02:59 -0700129#else
Patrick Venturef32a4532019-07-19 10:15:40 -0700130 bmcPack->update =
131 ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
132 sdbusplus::bus::new_default(), UPDATE_DBUS_SERVICE);
Patrick Venture6f81b162019-05-20 14:02:59 -0700133#endif
134
Patrick Venturef32a4532019-07-19 10:15:40 -0700135 bmcPack->preparation =
136 ipmi_flash::SystemdPreparation::CreatePreparation(
137 sdbusplus::bus::new_default(), PREPARATION_DBUS_SERVICE);
Patrick Venture48e309c2019-06-29 07:51:19 -0700138
Patrick Venturef32a4532019-07-19 10:15:40 -0700139 bmcPack->verification =
140 ipmi_flash::SystemdVerification::CreateVerification(
141 sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME,
142 VERIFY_DBUS_SERVICE);
Patrick Venture48e309c2019-06-29 07:51:19 -0700143
Patrick Venturef32a4532019-07-19 10:15:40 -0700144 std::string bmcName;
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700145#ifdef ENABLE_STATIC_LAYOUT
Patrick Venturef32a4532019-07-19 10:15:40 -0700146 bmcName = ipmi_flash::staticLayoutBlobId;
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700147#endif
148#ifdef ENABLE_TARBALL_UBI
Patrick Venturef32a4532019-07-19 10:15:40 -0700149 bmcName = ipmi_flash::ubiTarballBlobId;
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700150#endif
151
Patrick Venturef32a4532019-07-19 10:15:40 -0700152 actionPacks[bmcName] = std::move(bmcPack);
153 }
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700154
Patrick Venture7c2a00e2019-07-01 17:33:03 -0700155#ifdef ENABLE_HOST_BIOS
156 {
157 auto biosPack = std::make_unique<ipmi_flash::ActionPack>();
158
159 biosPack->preparation =
160 ipmi_flash::SystemdPreparation::CreatePreparation(
161 sdbusplus::bus::new_default(), PREPARATION_BIOS_TARGET);
162
163 biosPack->verification =
164 ipmi_flash::SystemdVerification::CreateVerification(
165 sdbusplus::bus::new_default(), BIOS_VERIFY_STATUS_FILENAME,
166 VERIFY_BIOS_TARGET);
167
168 biosPack->update =
169 ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
170 sdbusplus::bus::new_default(), UPDATE_BIOS_TARGET);
171
172 actionPacks[ipmi_flash::biosBlobId] = std::move(biosPack);
173 }
174#endif
175
Patrick Ventured4e20de2019-07-18 12:48:05 -0700176 std::vector<ipmi_flash::HandlerPack> supportedFirmware;
177
Patrick Venturef32a4532019-07-19 10:15:40 -0700178 supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack(
179 ipmi_flash::hashBlobId, HASH_FILENAME)));
Patrick Ventured4e20de2019-07-18 12:48:05 -0700180
181#ifdef ENABLE_STATIC_LAYOUT
Patrick Venturef32a4532019-07-19 10:15:40 -0700182 supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack(
183 ipmi_flash::staticLayoutBlobId, STATIC_HANDLER_STAGED_NAME)));
Patrick Ventured4e20de2019-07-18 12:48:05 -0700184#endif
185#ifdef ENABLE_TARBALL_UBI
Patrick Venturef32a4532019-07-19 10:15:40 -0700186 supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack(
187 ipmi_flash::ubiTarballBlobId, TARBALL_STAGED_NAME)));
Patrick Ventured4e20de2019-07-18 12:48:05 -0700188#endif
189#ifdef ENABLE_HOST_BIOS
Patrick Venturef32a4532019-07-19 10:15:40 -0700190 supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack(
191 ipmi_flash::biosBlobId, BIOS_STAGED_NAME)));
Patrick Ventured4e20de2019-07-18 12:48:05 -0700192#endif
193
Patrick Venture1d5a31c2019-05-20 11:38:22 -0700194 auto handler = ipmi_flash::FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventured4e20de2019-07-18 12:48:05 -0700195 std::move(supportedFirmware), ipmi_flash::supportedTransports,
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700196 std::move(actionPacks));
Patrick Venture52854622018-11-06 12:30:00 -0800197
198 if (!handler)
199 {
Patrick Venture48e309c2019-06-29 07:51:19 -0700200 using namespace phosphor::logging;
201
Patrick Venture52854622018-11-06 12:30:00 -0800202 log<level::ERR>("Firmware Handler has invalid configuration");
Patrick Venture5b451e62018-11-14 14:20:08 -0800203 return nullptr;
Patrick Venture52854622018-11-06 12:30:00 -0800204 }
205
Patrick Venturee1118bc2019-06-19 07:32:48 -0700206 return handler;
Patrick Venturec7ca2912018-11-02 11:38:33 -0700207}