blob: d89369c3d06a5890e1d2925f29ac12b117f1870e [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 Venture64919ec2018-11-15 11:52:07 -080019#include "file_handler.hpp"
Patrick Venturec7ca2912018-11-02 11:38:33 -070020#include "firmware_handler.hpp"
Patrick Venture84778b82019-06-26 20:11:09 -070021#include "flags.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -080022#include "image_handler.hpp"
Patrick Ventureefce8f92018-12-14 16:39:00 -080023#include "lpc_aspeed.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -080024#include "lpc_handler.hpp"
Patrick Ventureefce8f92018-12-14 16:39:00 -080025#include "lpc_nuvoton.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -080026#include "pci_handler.hpp"
Patrick Venture6d7735d2019-06-21 10:03:19 -070027#include "prepare_systemd.hpp"
Patrick Venture1d66fe62019-06-03 14:57:27 -070028#include "status.hpp"
Patrick Venture6f81b162019-05-20 14:02:59 -070029#include "update_systemd.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -070030#include "util.hpp"
Patrick Venture26a17262019-05-20 11:03:35 -070031#include "verify_systemd.hpp"
Patrick Venturec7ca2912018-11-02 11:38:33 -070032
Patrick Venture192d60f2018-11-06 11:11:59 -080033#include <cstdint>
Patrick Venturec7ca2912018-11-02 11:38:33 -070034#include <memory>
35#include <phosphor-logging/log.hpp>
Patrick Venture4eb55952018-11-16 15:36:24 -080036#include <sdbusplus/bus.hpp>
Patrick Venturefa06a5f2019-07-01 09:22:38 -070037#include <unordered_map>
Patrick Venturec7ca2912018-11-02 11:38:33 -070038
Patrick Venture1d5a31c2019-05-20 11:38:22 -070039namespace ipmi_flash
Patrick Venturec7ca2912018-11-02 11:38:33 -070040{
Patrick Venturea78e39f2018-11-06 18:37:06 -080041namespace
42{
Patrick Venture48e309c2019-06-29 07:51:19 -070043
Patrick Venture64919ec2018-11-15 11:52:07 -080044FileHandler hashHandler(HASH_FILENAME);
Patrick Venture48e309c2019-06-29 07:51:19 -070045
Patrick Venture2ba71302019-05-17 14:48:46 -070046#ifdef ENABLE_STATIC_LAYOUT
Patrick Venture7753d942018-11-15 13:15:36 -080047FileHandler staticLayoutHandler(STATIC_HANDLER_STAGED_NAME);
Patrick Venture2ba71302019-05-17 14:48:46 -070048#endif
49#ifdef ENABLE_TARBALL_UBI
Patrick Ventured46b8112018-11-15 13:38:55 -080050FileHandler ubitarballHandler(TARBALL_STAGED_NAME);
Patrick Venture2ba71302019-05-17 14:48:46 -070051#endif
Patrick Venturee7728422018-11-14 20:16:33 -080052
Patrick Venture7b91cbc2018-11-28 14:24:41 -080053/* The maximum external buffer size we expect is 64KB. */
Patrick Venture28abae72018-12-14 09:44:02 -080054static constexpr std::size_t memoryRegionSize = 64 * 1024UL;
Patrick Venture7b91cbc2018-11-28 14:24:41 -080055
Patrick Venturee7728422018-11-14 20:16:33 -080056#ifdef ENABLE_LPC_BRIDGE
57#if defined(ASPEED_LPC)
Patrick Venture78b1a662019-01-17 12:38:26 -080058LpcDataHandler lpcDataHandler(
59 LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize));
Patrick Venturee7728422018-11-14 20:16:33 -080060#elif defined(NUVOTON_LPC)
Patrick Venture36bffb42019-06-24 10:47:47 -070061LpcDataHandler lpcDataHandler(
62 LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS, memoryRegionSize));
Patrick Venturee7728422018-11-14 20:16:33 -080063#else
64#error "You must specify a hardware implementation."
65#endif
66#endif
67
Patrick Venture102ecbb2019-04-30 16:08:49 -070068#ifdef ENABLE_PCI_BRIDGE
69#if defined(ASPEED_P2A)
Patrick Venture4289e712019-04-30 17:08:50 -070070PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize);
Patrick Venture102ecbb2019-04-30 16:08:49 -070071#else
72#error "You must specify a hardware implementation."
73#endif
74#endif
Patrick Venturea78e39f2018-11-06 18:37:06 -080075
76std::vector<HandlerPack> supportedFirmware = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070077 {hashBlobId, &hashHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080078#ifdef ENABLE_STATIC_LAYOUT
Patrick Venture7dad86f2019-05-17 08:52:20 -070079 {staticLayoutBlobId, &staticLayoutHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080080#endif
Patrick Ventured46b8112018-11-15 13:38:55 -080081#ifdef ENABLE_TARBALL_UBI
Patrick Venture7dad86f2019-05-17 08:52:20 -070082 {ubiTarballBlobId, &ubitarballHandler},
Patrick Ventured46b8112018-11-15 13:38:55 -080083#endif
Patrick Venture148cd652018-11-06 10:59:47 -080084};
85
Patrick Venture1cde5f92018-11-07 08:26:47 -080086std::vector<DataHandlerPack> supportedTransports = {
Patrick Venture84778b82019-06-26 20:11:09 -070087 {FirmwareFlags::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080088#ifdef ENABLE_PCI_BRIDGE
Patrick Venture84778b82019-06-26 20:11:09 -070089 {FirmwareFlags::UpdateFlags::p2a, &pciDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080090#endif
91#ifdef ENABLE_LPC_BRIDGE
Patrick Venture84778b82019-06-26 20:11:09 -070092 {FirmwareFlags::UpdateFlags::lpc, &lpcDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080093#endif
94};
95
Patrick Venturea78e39f2018-11-06 18:37:06 -080096} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070097} // namespace ipmi_flash
Patrick Venturec7ca2912018-11-02 11:38:33 -070098
Patrick Venture5b451e62018-11-14 14:20:08 -080099extern "C" {
Patrick Venture5b451e62018-11-14 14:20:08 -0800100std::unique_ptr<blobs::GenericBlobInterface> createHandler();
Patrick Venture5b451e62018-11-14 14:20:08 -0800101}
Patrick Venture5b451e62018-11-14 14:20:08 -0800102
103std::unique_ptr<blobs::GenericBlobInterface> createHandler()
Patrick Venturec7ca2912018-11-02 11:38:33 -0700104{
Patrick Venture6f81b162019-05-20 14:02:59 -0700105#ifdef ENABLE_REBOOT_UPDATE
106 static constexpr auto rebootTarget = "reboot.target";
107 static constexpr auto rebootMode = "replace-irreversibly";
108
109 auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
110 sdbusplus::bus::new_default(), rebootTarget, rebootMode);
111#else
112 auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
113 sdbusplus::bus::new_default(), UPDATE_DBUS_SERVICE);
114#endif
115
Patrick Venture48e309c2019-06-29 07:51:19 -0700116 auto prepare = ipmi_flash::SystemdPreparation::CreatePreparation(
117 sdbusplus::bus::new_default(), PREPARATION_DBUS_SERVICE);
118
119 auto verifier = ipmi_flash::SystemdVerification::CreateVerification(
120 sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME,
121 VERIFY_DBUS_SERVICE);
122
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700123 ipmi_flash::ActionMap actionPacks = {};
124
125 /* TODO: for bios should the name be, bios or /flash/bios?, these are
126 * /flash/... and it simplifies a few other things later (open/etc)
127 */
128 std::string bmcName;
129#ifdef ENABLE_STATIC_LAYOUT
130 bmcName = ipmi_flash::staticLayoutBlobId;
131#endif
132#ifdef ENABLE_TARBALL_UBI
133 bmcName = ipmi_flash::ubiTarballBlobId;
134#endif
135
136 auto bmcPack = std::make_unique<ipmi_flash::ActionPack>();
137 bmcPack->preparation = std::move(prepare);
138 bmcPack->verification = std::move(verifier);
139 bmcPack->update = std::move(updater);
140 actionPacks[bmcName] = std::move(bmcPack);
141
Patrick Venture1d5a31c2019-05-20 11:38:22 -0700142 auto handler = ipmi_flash::FirmwareBlobHandler::CreateFirmwareBlobHandler(
143 ipmi_flash::supportedFirmware, ipmi_flash::supportedTransports,
Patrick Venturefa06a5f2019-07-01 09:22:38 -0700144 std::move(actionPacks));
Patrick Venture52854622018-11-06 12:30:00 -0800145
146 if (!handler)
147 {
Patrick Venture48e309c2019-06-29 07:51:19 -0700148 using namespace phosphor::logging;
149
Patrick Venture52854622018-11-06 12:30:00 -0800150 log<level::ERR>("Firmware Handler has invalid configuration");
Patrick Venture5b451e62018-11-14 14:20:08 -0800151 return nullptr;
Patrick Venture52854622018-11-06 12:30:00 -0800152 }
153
Patrick Venturee1118bc2019-06-19 07:32:48 -0700154 return handler;
Patrick Venturec7ca2912018-11-02 11:38:33 -0700155}