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 | 64919ec | 2018-11-15 11:52:07 -0800 | [diff] [blame] | 19 | #include "file_handler.hpp" |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 20 | #include "firmware_handler.hpp" |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 21 | #include "flags.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 22 | #include "image_handler.hpp" |
Patrick Venture | efce8f9 | 2018-12-14 16:39:00 -0800 | [diff] [blame] | 23 | #include "lpc_aspeed.hpp" |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 24 | #include "lpc_handler.hpp" |
Patrick Venture | efce8f9 | 2018-12-14 16:39:00 -0800 | [diff] [blame] | 25 | #include "lpc_nuvoton.hpp" |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 26 | #include "pci_handler.hpp" |
Patrick Venture | 6d7735d | 2019-06-21 10:03:19 -0700 | [diff] [blame] | 27 | #include "prepare_systemd.hpp" |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 28 | #include "status.hpp" |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 29 | #include "update_systemd.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 30 | #include "util.hpp" |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 31 | #include "verify_systemd.hpp" |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 32 | |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 33 | #include <cstdint> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 34 | #include <memory> |
| 35 | #include <phosphor-logging/log.hpp> |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 36 | #include <sdbusplus/bus.hpp> |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 37 | #include <unordered_map> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 38 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 39 | namespace ipmi_flash |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 40 | { |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 41 | namespace |
| 42 | { |
Patrick Venture | 48e309c | 2019-06-29 07:51:19 -0700 | [diff] [blame] | 43 | |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 44 | /* The maximum external buffer size we expect is 64KB. */ |
Patrick Venture | 28abae7 | 2018-12-14 09:44:02 -0800 | [diff] [blame] | 45 | static constexpr std::size_t memoryRegionSize = 64 * 1024UL; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 46 | |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 47 | #ifdef ENABLE_LPC_BRIDGE |
| 48 | #if defined(ASPEED_LPC) |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 49 | LpcDataHandler lpcDataHandler( |
| 50 | LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize)); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 51 | #elif defined(NUVOTON_LPC) |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 52 | LpcDataHandler lpcDataHandler( |
| 53 | LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS, memoryRegionSize)); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 54 | #else |
| 55 | #error "You must specify a hardware implementation." |
| 56 | #endif |
| 57 | #endif |
| 58 | |
Patrick Venture | 102ecbb | 2019-04-30 16:08:49 -0700 | [diff] [blame] | 59 | #ifdef ENABLE_PCI_BRIDGE |
| 60 | #if defined(ASPEED_P2A) |
Patrick Venture | 4289e71 | 2019-04-30 17:08:50 -0700 | [diff] [blame] | 61 | PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize); |
Patrick Venture | 102ecbb | 2019-04-30 16:08:49 -0700 | [diff] [blame] | 62 | #else |
| 63 | #error "You must specify a hardware implementation." |
| 64 | #endif |
| 65 | #endif |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 66 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 67 | std::vector<DataHandlerPack> supportedTransports = { |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 68 | {FirmwareFlags::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 69 | #ifdef ENABLE_PCI_BRIDGE |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 70 | {FirmwareFlags::UpdateFlags::p2a, &pciDataHandler}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 71 | #endif |
| 72 | #ifdef ENABLE_LPC_BRIDGE |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 73 | {FirmwareFlags::UpdateFlags::lpc, &lpcDataHandler}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 74 | #endif |
| 75 | }; |
| 76 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 77 | } // namespace |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 78 | } // namespace ipmi_flash |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 79 | |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 80 | extern "C" { |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 81 | std::unique_ptr<blobs::GenericBlobInterface> createHandler(); |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 82 | } |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 83 | |
| 84 | std::unique_ptr<blobs::GenericBlobInterface> createHandler() |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 85 | { |
Patrick Venture | 7c2a00e | 2019-07-01 17:33:03 -0700 | [diff] [blame] | 86 | ipmi_flash::ActionMap actionPacks = {}; |
| 87 | |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 88 | #ifdef ENABLE_REBOOT_UPDATE |
| 89 | static constexpr auto rebootTarget = "reboot.target"; |
| 90 | static constexpr auto rebootMode = "replace-irreversibly"; |
| 91 | |
| 92 | auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate( |
| 93 | sdbusplus::bus::new_default(), rebootTarget, rebootMode); |
| 94 | #else |
| 95 | auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate( |
| 96 | sdbusplus::bus::new_default(), UPDATE_DBUS_SERVICE); |
| 97 | #endif |
| 98 | |
Patrick Venture | 48e309c | 2019-06-29 07:51:19 -0700 | [diff] [blame] | 99 | auto prepare = ipmi_flash::SystemdPreparation::CreatePreparation( |
| 100 | sdbusplus::bus::new_default(), PREPARATION_DBUS_SERVICE); |
| 101 | |
| 102 | auto verifier = ipmi_flash::SystemdVerification::CreateVerification( |
| 103 | sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME, |
| 104 | VERIFY_DBUS_SERVICE); |
| 105 | |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 106 | /* TODO: for bios should the name be, bios or /flash/bios?, these are |
| 107 | * /flash/... and it simplifies a few other things later (open/etc) |
| 108 | */ |
| 109 | std::string bmcName; |
| 110 | #ifdef ENABLE_STATIC_LAYOUT |
| 111 | bmcName = ipmi_flash::staticLayoutBlobId; |
| 112 | #endif |
| 113 | #ifdef ENABLE_TARBALL_UBI |
| 114 | bmcName = ipmi_flash::ubiTarballBlobId; |
| 115 | #endif |
| 116 | |
| 117 | auto bmcPack = std::make_unique<ipmi_flash::ActionPack>(); |
| 118 | bmcPack->preparation = std::move(prepare); |
| 119 | bmcPack->verification = std::move(verifier); |
| 120 | bmcPack->update = std::move(updater); |
| 121 | actionPacks[bmcName] = std::move(bmcPack); |
| 122 | |
Patrick Venture | 7c2a00e | 2019-07-01 17:33:03 -0700 | [diff] [blame] | 123 | #ifdef ENABLE_HOST_BIOS |
| 124 | { |
| 125 | auto biosPack = std::make_unique<ipmi_flash::ActionPack>(); |
| 126 | |
| 127 | biosPack->preparation = |
| 128 | ipmi_flash::SystemdPreparation::CreatePreparation( |
| 129 | sdbusplus::bus::new_default(), PREPARATION_BIOS_TARGET); |
| 130 | |
| 131 | biosPack->verification = |
| 132 | ipmi_flash::SystemdVerification::CreateVerification( |
| 133 | sdbusplus::bus::new_default(), BIOS_VERIFY_STATUS_FILENAME, |
| 134 | VERIFY_BIOS_TARGET); |
| 135 | |
| 136 | biosPack->update = |
| 137 | ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate( |
| 138 | sdbusplus::bus::new_default(), UPDATE_BIOS_TARGET); |
| 139 | |
| 140 | actionPacks[ipmi_flash::biosBlobId] = std::move(biosPack); |
| 141 | } |
| 142 | #endif |
| 143 | |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 144 | std::vector<ipmi_flash::HandlerPack> supportedFirmware; |
| 145 | |
| 146 | supportedFirmware.push_back(std::move(ipmi_flash::HandlerPack( |
| 147 | ipmi_flash::hashBlobId, |
| 148 | std::make_unique<ipmi_flash::FileHandler>(HASH_FILENAME)))); |
| 149 | |
| 150 | #ifdef ENABLE_STATIC_LAYOUT |
| 151 | supportedFirmware.push_back(std::move( |
| 152 | ipmi_flash::HandlerPack(ipmi_flash::staticLayoutBlobId, |
| 153 | std::make_unique<ipmi_flash::FileHandler>( |
| 154 | STATIC_HANDLER_STAGED_NAME)))); |
| 155 | #endif |
| 156 | #ifdef ENABLE_TARBALL_UBI |
| 157 | supportedFirmware.push_back(std::move(ipmi_flash::HandlerPack( |
| 158 | ipmi_flash::ubiTarballBlobId, |
| 159 | std::make_unique<ipmi_flash::FileHandler>(TARBALL_STAGED_NAME)))); |
| 160 | #endif |
| 161 | #ifdef ENABLE_HOST_BIOS |
| 162 | supportedFirmware.push_back(std::move(ipmi_flash::HandlerPack( |
| 163 | ipmi_flash::biosBlobId, |
| 164 | std::make_unique<ipmi_flash::FileHandler>(BIOS_STAGED_NAME)))); |
| 165 | #endif |
| 166 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 167 | auto handler = ipmi_flash::FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 168 | std::move(supportedFirmware), ipmi_flash::supportedTransports, |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 169 | std::move(actionPacks)); |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 170 | |
| 171 | if (!handler) |
| 172 | { |
Patrick Venture | 48e309c | 2019-06-29 07:51:19 -0700 | [diff] [blame] | 173 | using namespace phosphor::logging; |
| 174 | |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 175 | log<level::ERR>("Firmware Handler has invalid configuration"); |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 176 | return nullptr; |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Patrick Venture | e1118bc | 2019-06-19 07:32:48 -0700 | [diff] [blame] | 179 | return handler; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 180 | } |