blob: 3130eec5cb4cf6097a0b0a7ef8218824af0317c0 [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 Venturea78e39f2018-11-06 18:37:06 -080021#include "image_handler.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -080022#include "lpc_handler.hpp"
23#include "pci_handler.hpp"
Patrick Venturec7ca2912018-11-02 11:38:33 -070024
25#include <blobs-ipmid/manager.hpp>
Patrick Venture192d60f2018-11-06 11:11:59 -080026#include <cstdint>
Patrick Venturec7ca2912018-11-02 11:38:33 -070027#include <memory>
28#include <phosphor-logging/log.hpp>
Patrick Venture4eb55952018-11-16 15:36:24 -080029#include <sdbusplus/bus.hpp>
Patrick Venturec7ca2912018-11-02 11:38:33 -070030
31namespace blobs
32{
Patrick Venturea78e39f2018-11-06 18:37:06 -080033namespace
34{
Patrick Venture64919ec2018-11-15 11:52:07 -080035FileHandler hashHandler(HASH_FILENAME);
Patrick Venture7753d942018-11-15 13:15:36 -080036FileHandler staticLayoutHandler(STATIC_HANDLER_STAGED_NAME);
Patrick Ventured46b8112018-11-15 13:38:55 -080037FileHandler ubitarballHandler(TARBALL_STAGED_NAME);
Patrick Venturee7728422018-11-14 20:16:33 -080038
39#ifdef ENABLE_LPC_BRIDGE
40#if defined(ASPEED_LPC)
Patrick Venture002916a2018-11-15 10:38:07 -080041LpcDataHandler lpcDataHandler(MAPPED_ADDRESS,
42 LpcMapperAspeed::createAspeedMapper());
Patrick Venturee7728422018-11-14 20:16:33 -080043#elif defined(NUVOTON_LPC)
Patrick Venture002916a2018-11-15 10:38:07 -080044LpcDataHandler lpcDataHandler(MAPPED_ADDRESS,
45 LpcMapperNuvoton::createNuvotonMapper());
Patrick Venturee7728422018-11-14 20:16:33 -080046#else
47#error "You must specify a hardware implementation."
48#endif
49#endif
50
Patrick Venture002916a2018-11-15 10:38:07 -080051PciDataHandler pciDataHandler(MAPPED_ADDRESS);
Patrick Venturea78e39f2018-11-06 18:37:06 -080052
53std::vector<HandlerPack> supportedFirmware = {
Patrick Venture18235e62018-11-08 10:21:09 -080054 {FirmwareBlobHandler::hashBlobID, &hashHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080055#ifdef ENABLE_STATIC_LAYOUT
Patrick Venturea78e39f2018-11-06 18:37:06 -080056 {"/flash/image", &staticLayoutHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080057#endif
Patrick Ventured46b8112018-11-15 13:38:55 -080058#ifdef ENABLE_TARBALL_UBI
59 {"/flash/tarball", &ubitarballHandler},
60#endif
Patrick Venture148cd652018-11-06 10:59:47 -080061};
62
Patrick Venture1cde5f92018-11-07 08:26:47 -080063std::vector<DataHandlerPack> supportedTransports = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080064 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080065#ifdef ENABLE_PCI_BRIDGE
Patrick Venture05abf7e2018-11-09 11:02:56 -080066 {FirmwareBlobHandler::UpdateFlags::p2a, &pciDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080067#endif
68#ifdef ENABLE_LPC_BRIDGE
Patrick Venture05abf7e2018-11-09 11:02:56 -080069 {FirmwareBlobHandler::UpdateFlags::lpc, &lpcDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080070#endif
71};
72
Patrick Venturea78e39f2018-11-06 18:37:06 -080073} // namespace
Patrick Venture192d60f2018-11-06 11:11:59 -080074
Patrick Venture5b451e62018-11-14 14:20:08 -080075} // namespace blobs
Patrick Venturec7ca2912018-11-02 11:38:33 -070076
Patrick Venture5b451e62018-11-14 14:20:08 -080077extern "C" {
Patrick Venture5b451e62018-11-14 14:20:08 -080078std::unique_ptr<blobs::GenericBlobInterface> createHandler();
Patrick Venture5b451e62018-11-14 14:20:08 -080079}
Patrick Venture5b451e62018-11-14 14:20:08 -080080
81std::unique_ptr<blobs::GenericBlobInterface> createHandler()
Patrick Venturec7ca2912018-11-02 11:38:33 -070082{
Patrick Venture5b451e62018-11-14 14:20:08 -080083 using namespace phosphor::logging;
84
85 auto handler = blobs::FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture4eb55952018-11-16 15:36:24 -080086 sdbusplus::bus::new_default(), blobs::supportedFirmware,
87 blobs::supportedTransports);
Patrick Venture52854622018-11-06 12:30:00 -080088
89 if (!handler)
90 {
91 log<level::ERR>("Firmware Handler has invalid configuration");
Patrick Venture5b451e62018-11-14 14:20:08 -080092 return nullptr;
Patrick Venture52854622018-11-06 12:30:00 -080093 }
94
Patrick Venture5b451e62018-11-14 14:20:08 -080095 return std::move(handler);
Patrick Venturec7ca2912018-11-02 11:38:33 -070096}