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 | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 21 | #include "image_handler.hpp" |
Patrick Venture | efce8f9 | 2018-12-14 16:39:00 -0800 | [diff] [blame] | 22 | #include "lpc_aspeed.hpp" |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 23 | #include "lpc_handler.hpp" |
Patrick Venture | efce8f9 | 2018-12-14 16:39:00 -0800 | [diff] [blame] | 24 | #include "lpc_nuvoton.hpp" |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 25 | #include "pci_handler.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 26 | #include "util.hpp" |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 27 | |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 28 | #include <cstdint> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 29 | #include <memory> |
| 30 | #include <phosphor-logging/log.hpp> |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 31 | #include <sdbusplus/bus.hpp> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 32 | |
| 33 | namespace blobs |
| 34 | { |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 35 | namespace |
| 36 | { |
Patrick Venture | 64919ec | 2018-11-15 11:52:07 -0800 | [diff] [blame] | 37 | FileHandler hashHandler(HASH_FILENAME); |
Patrick Venture | 7753d94 | 2018-11-15 13:15:36 -0800 | [diff] [blame] | 38 | FileHandler staticLayoutHandler(STATIC_HANDLER_STAGED_NAME); |
Patrick Venture | d46b811 | 2018-11-15 13:38:55 -0800 | [diff] [blame] | 39 | FileHandler ubitarballHandler(TARBALL_STAGED_NAME); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 40 | |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 41 | /* The maximum external buffer size we expect is 64KB. */ |
Patrick Venture | 28abae7 | 2018-12-14 09:44:02 -0800 | [diff] [blame] | 42 | static constexpr std::size_t memoryRegionSize = 64 * 1024UL; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 43 | |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 44 | #ifdef ENABLE_LPC_BRIDGE |
| 45 | #if defined(ASPEED_LPC) |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 46 | LpcDataHandler lpcDataHandler( |
| 47 | LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize)); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 48 | #elif defined(NUVOTON_LPC) |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 49 | LpcDataHandler |
| 50 | lpcDataHandler(LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS)); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 51 | #else |
| 52 | #error "You must specify a hardware implementation." |
| 53 | #endif |
| 54 | #endif |
| 55 | |
Patrick Venture | 102ecbb | 2019-04-30 16:08:49 -0700 | [diff] [blame] | 56 | #ifdef ENABLE_PCI_BRIDGE |
| 57 | #if defined(ASPEED_P2A) |
Patrick Venture | 4289e71 | 2019-04-30 17:08:50 -0700 | [diff] [blame] | 58 | PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize); |
Patrick Venture | 102ecbb | 2019-04-30 16:08:49 -0700 | [diff] [blame] | 59 | #else |
| 60 | #error "You must specify a hardware implementation." |
| 61 | #endif |
| 62 | #endif |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 63 | |
| 64 | std::vector<HandlerPack> supportedFirmware = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 65 | {hashBlobId, &hashHandler}, |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 66 | #ifdef ENABLE_STATIC_LAYOUT |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 67 | {staticLayoutBlobId, &staticLayoutHandler}, |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 68 | #endif |
Patrick Venture | d46b811 | 2018-11-15 13:38:55 -0800 | [diff] [blame] | 69 | #ifdef ENABLE_TARBALL_UBI |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 70 | {ubiTarballBlobId, &ubitarballHandler}, |
Patrick Venture | d46b811 | 2018-11-15 13:38:55 -0800 | [diff] [blame] | 71 | #endif |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 74 | std::vector<DataHandlerPack> supportedTransports = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 75 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 76 | #ifdef ENABLE_PCI_BRIDGE |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 77 | {FirmwareBlobHandler::UpdateFlags::p2a, &pciDataHandler}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 78 | #endif |
| 79 | #ifdef ENABLE_LPC_BRIDGE |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 80 | {FirmwareBlobHandler::UpdateFlags::lpc, &lpcDataHandler}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 81 | #endif |
| 82 | }; |
| 83 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 84 | } // namespace |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 85 | |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 86 | } // namespace blobs |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 87 | |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 88 | extern "C" { |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 89 | std::unique_ptr<blobs::GenericBlobInterface> createHandler(); |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 90 | } |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 91 | |
| 92 | std::unique_ptr<blobs::GenericBlobInterface> createHandler() |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 93 | { |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 94 | using namespace phosphor::logging; |
| 95 | |
| 96 | auto handler = blobs::FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 97 | sdbusplus::bus::new_default(), blobs::supportedFirmware, |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame^] | 98 | blobs::supportedTransports, VERIFY_STATUS_FILENAME); |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 99 | |
| 100 | if (!handler) |
| 101 | { |
| 102 | log<level::ERR>("Firmware Handler has invalid configuration"); |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 103 | return nullptr; |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Patrick Venture | 5b451e6 | 2018-11-14 14:20:08 -0800 | [diff] [blame] | 106 | return std::move(handler); |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 107 | } |