Patrick Venture | 22e3875 | 2018-11-21 08:52:49 -0800 | [diff] [blame] | 1 | /* |
| 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 Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 17 | #include "config.h" |
| 18 | |
Patrick Venture | a6b4abd | 2019-07-19 10:58:55 -0700 | [diff] [blame^] | 19 | #include "buildjson.hpp" |
Patrick Venture | 64919ec | 2018-11-15 11:52:07 -0800 | [diff] [blame] | 20 | #include "file_handler.hpp" |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 21 | #include "firmware_handler.hpp" |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 22 | #include "flags.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 23 | #include "image_handler.hpp" |
Patrick Venture | efce8f9 | 2018-12-14 16:39:00 -0800 | [diff] [blame] | 24 | #include "lpc_aspeed.hpp" |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 25 | #include "lpc_handler.hpp" |
Patrick Venture | efce8f9 | 2018-12-14 16:39:00 -0800 | [diff] [blame] | 26 | #include "lpc_nuvoton.hpp" |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 27 | #include "pci_handler.hpp" |
Patrick Venture | 6d7735d | 2019-06-21 10:03:19 -0700 | [diff] [blame] | 28 | #include "prepare_systemd.hpp" |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 29 | #include "status.hpp" |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 30 | #include "update_systemd.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 31 | #include "util.hpp" |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 32 | #include "verify_systemd.hpp" |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 33 | |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 34 | #include <cstdint> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 35 | #include <memory> |
| 36 | #include <phosphor-logging/log.hpp> |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 37 | #include <sdbusplus/bus.hpp> |
Patrick Venture | a6b4abd | 2019-07-19 10:58:55 -0700 | [diff] [blame^] | 38 | #include <string> |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 39 | #include <unordered_map> |
Patrick Venture | a6b4abd | 2019-07-19 10:58:55 -0700 | [diff] [blame^] | 40 | #include <vector> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 41 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 42 | namespace ipmi_flash |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 43 | { |
Patrick Venture | a6b4abd | 2019-07-19 10:58:55 -0700 | [diff] [blame^] | 44 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 45 | namespace |
| 46 | { |
Patrick Venture | 48e309c | 2019-06-29 07:51:19 -0700 | [diff] [blame] | 47 | |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 48 | /* The maximum external buffer size we expect is 64KB. */ |
Patrick Venture | 28abae7 | 2018-12-14 09:44:02 -0800 | [diff] [blame] | 49 | static constexpr std::size_t memoryRegionSize = 64 * 1024UL; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 50 | |
Patrick Venture | a6b4abd | 2019-07-19 10:58:55 -0700 | [diff] [blame^] | 51 | static constexpr const char* jsonConfigurationPath = |
| 52 | "/usr/share/phosphor-ipmi-flash/"; |
| 53 | |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 54 | #ifdef ENABLE_LPC_BRIDGE |
| 55 | #if defined(ASPEED_LPC) |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 56 | LpcDataHandler lpcDataHandler( |
| 57 | LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize)); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 58 | #elif defined(NUVOTON_LPC) |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 59 | LpcDataHandler lpcDataHandler( |
| 60 | LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS, memoryRegionSize)); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 61 | #else |
| 62 | #error "You must specify a hardware implementation." |
| 63 | #endif |
| 64 | #endif |
| 65 | |
Patrick Venture | 102ecbb | 2019-04-30 16:08:49 -0700 | [diff] [blame] | 66 | #ifdef ENABLE_PCI_BRIDGE |
| 67 | #if defined(ASPEED_P2A) |
Patrick Venture | 4289e71 | 2019-04-30 17:08:50 -0700 | [diff] [blame] | 68 | PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize); |
Patrick Venture | 102ecbb | 2019-04-30 16:08:49 -0700 | [diff] [blame] | 69 | #else |
| 70 | #error "You must specify a hardware implementation." |
| 71 | #endif |
| 72 | #endif |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 73 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 74 | std::vector<DataHandlerPack> supportedTransports = { |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 75 | {FirmwareFlags::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 76 | #ifdef ENABLE_PCI_BRIDGE |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 77 | {FirmwareFlags::UpdateFlags::p2a, &pciDataHandler}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 78 | #endif |
| 79 | #ifdef ENABLE_LPC_BRIDGE |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 80 | {FirmwareFlags::UpdateFlags::lpc, &lpcDataHandler}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 81 | #endif |
| 82 | }; |
| 83 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 84 | /** |
| 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 | */ |
| 91 | HandlerPack CreateFileHandlerPack(const std::string& name, |
| 92 | const std::string& path) |
| 93 | { |
| 94 | return HandlerPack(name, std::make_unique<FileHandler>(path)); |
| 95 | } |
| 96 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 97 | } // namespace |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 98 | } // namespace ipmi_flash |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 99 | |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 100 | extern "C" { |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 101 | std::unique_ptr<blobs::GenericBlobInterface> createHandler(); |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 102 | } |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 103 | |
| 104 | std::unique_ptr<blobs::GenericBlobInterface> createHandler() |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 105 | { |
Patrick Venture | a6b4abd | 2019-07-19 10:58:55 -0700 | [diff] [blame^] | 106 | /* 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 Venture | 7c2a00e | 2019-07-01 17:33:03 -0700 | [diff] [blame] | 117 | ipmi_flash::ActionMap actionPacks = {}; |
| 118 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 119 | { |
| 120 | auto bmcPack = std::make_unique<ipmi_flash::ActionPack>(); |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 121 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 122 | #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 Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 129 | #else |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 130 | bmcPack->update = |
| 131 | ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate( |
| 132 | sdbusplus::bus::new_default(), UPDATE_DBUS_SERVICE); |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 133 | #endif |
| 134 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 135 | bmcPack->preparation = |
| 136 | ipmi_flash::SystemdPreparation::CreatePreparation( |
| 137 | sdbusplus::bus::new_default(), PREPARATION_DBUS_SERVICE); |
Patrick Venture | 48e309c | 2019-06-29 07:51:19 -0700 | [diff] [blame] | 138 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 139 | bmcPack->verification = |
| 140 | ipmi_flash::SystemdVerification::CreateVerification( |
| 141 | sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME, |
| 142 | VERIFY_DBUS_SERVICE); |
Patrick Venture | 48e309c | 2019-06-29 07:51:19 -0700 | [diff] [blame] | 143 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 144 | std::string bmcName; |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 145 | #ifdef ENABLE_STATIC_LAYOUT |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 146 | bmcName = ipmi_flash::staticLayoutBlobId; |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 147 | #endif |
| 148 | #ifdef ENABLE_TARBALL_UBI |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 149 | bmcName = ipmi_flash::ubiTarballBlobId; |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 150 | #endif |
| 151 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 152 | actionPacks[bmcName] = std::move(bmcPack); |
| 153 | } |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 154 | |
Patrick Venture | 7c2a00e | 2019-07-01 17:33:03 -0700 | [diff] [blame] | 155 | #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 Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 176 | std::vector<ipmi_flash::HandlerPack> supportedFirmware; |
| 177 | |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 178 | supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack( |
| 179 | ipmi_flash::hashBlobId, HASH_FILENAME))); |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 180 | |
| 181 | #ifdef ENABLE_STATIC_LAYOUT |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 182 | supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack( |
| 183 | ipmi_flash::staticLayoutBlobId, STATIC_HANDLER_STAGED_NAME))); |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 184 | #endif |
| 185 | #ifdef ENABLE_TARBALL_UBI |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 186 | supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack( |
| 187 | ipmi_flash::ubiTarballBlobId, TARBALL_STAGED_NAME))); |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 188 | #endif |
| 189 | #ifdef ENABLE_HOST_BIOS |
Patrick Venture | f32a453 | 2019-07-19 10:15:40 -0700 | [diff] [blame] | 190 | supportedFirmware.push_back(std::move(ipmi_flash::CreateFileHandlerPack( |
| 191 | ipmi_flash::biosBlobId, BIOS_STAGED_NAME))); |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 192 | #endif |
| 193 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 194 | auto handler = ipmi_flash::FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 195 | std::move(supportedFirmware), ipmi_flash::supportedTransports, |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 196 | std::move(actionPacks)); |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 197 | |
| 198 | if (!handler) |
| 199 | { |
Patrick Venture | 48e309c | 2019-06-29 07:51:19 -0700 | [diff] [blame] | 200 | using namespace phosphor::logging; |
| 201 | |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 202 | log<level::ERR>("Firmware Handler has invalid configuration"); |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 203 | return nullptr; |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Patrick Venture | e1118bc | 2019-06-19 07:32:48 -0700 | [diff] [blame] | 206 | return handler; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 207 | } |