blob: e9de21c2e143190a8a9a2b21775c10034afa062c [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 Ventureefce8f92018-12-14 16:39:00 -080022#include "lpc_aspeed.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -080023#include "lpc_handler.hpp"
Patrick Ventureefce8f92018-12-14 16:39:00 -080024#include "lpc_nuvoton.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -080025#include "pci_handler.hpp"
Patrick Venturec7ca2912018-11-02 11:38:33 -070026
Patrick Venture192d60f2018-11-06 11:11:59 -080027#include <cstdint>
Patrick Venturec7ca2912018-11-02 11:38:33 -070028#include <memory>
29#include <phosphor-logging/log.hpp>
Patrick Venture4eb55952018-11-16 15:36:24 -080030#include <sdbusplus/bus.hpp>
Patrick Venturec7ca2912018-11-02 11:38:33 -070031
32namespace blobs
33{
Patrick Venturea78e39f2018-11-06 18:37:06 -080034namespace
35{
Patrick Venture64919ec2018-11-15 11:52:07 -080036FileHandler hashHandler(HASH_FILENAME);
Patrick Venture7753d942018-11-15 13:15:36 -080037FileHandler staticLayoutHandler(STATIC_HANDLER_STAGED_NAME);
Patrick Ventured46b8112018-11-15 13:38:55 -080038FileHandler ubitarballHandler(TARBALL_STAGED_NAME);
Patrick Venturee7728422018-11-14 20:16:33 -080039
Patrick Venture7b91cbc2018-11-28 14:24:41 -080040/* The maximum external buffer size we expect is 64KB. */
Patrick Venture28abae72018-12-14 09:44:02 -080041static constexpr std::size_t memoryRegionSize = 64 * 1024UL;
Patrick Venture7b91cbc2018-11-28 14:24:41 -080042
Patrick Venturee7728422018-11-14 20:16:33 -080043#ifdef ENABLE_LPC_BRIDGE
44#if defined(ASPEED_LPC)
Patrick Venture78b1a662019-01-17 12:38:26 -080045LpcDataHandler lpcDataHandler(
46 LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize));
Patrick Venturee7728422018-11-14 20:16:33 -080047#elif defined(NUVOTON_LPC)
Patrick Venture78b1a662019-01-17 12:38:26 -080048LpcDataHandler
49 lpcDataHandler(LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS));
Patrick Venturee7728422018-11-14 20:16:33 -080050#else
51#error "You must specify a hardware implementation."
52#endif
53#endif
54
Patrick Venture102ecbb2019-04-30 16:08:49 -070055#ifdef ENABLE_PCI_BRIDGE
56#if defined(ASPEED_P2A)
Patrick Venture4289e712019-04-30 17:08:50 -070057PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize);
Patrick Venture102ecbb2019-04-30 16:08:49 -070058#else
59#error "You must specify a hardware implementation."
60#endif
61#endif
Patrick Venturea78e39f2018-11-06 18:37:06 -080062
63std::vector<HandlerPack> supportedFirmware = {
Patrick Venture18235e62018-11-08 10:21:09 -080064 {FirmwareBlobHandler::hashBlobID, &hashHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080065#ifdef ENABLE_STATIC_LAYOUT
Patrick Venturea78e39f2018-11-06 18:37:06 -080066 {"/flash/image", &staticLayoutHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080067#endif
Patrick Ventured46b8112018-11-15 13:38:55 -080068#ifdef ENABLE_TARBALL_UBI
69 {"/flash/tarball", &ubitarballHandler},
70#endif
Patrick Venture148cd652018-11-06 10:59:47 -080071};
72
Patrick Venture1cde5f92018-11-07 08:26:47 -080073std::vector<DataHandlerPack> supportedTransports = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080074 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080075#ifdef ENABLE_PCI_BRIDGE
Patrick Venture05abf7e2018-11-09 11:02:56 -080076 {FirmwareBlobHandler::UpdateFlags::p2a, &pciDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080077#endif
78#ifdef ENABLE_LPC_BRIDGE
Patrick Venture05abf7e2018-11-09 11:02:56 -080079 {FirmwareBlobHandler::UpdateFlags::lpc, &lpcDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080080#endif
81};
82
Patrick Venturea78e39f2018-11-06 18:37:06 -080083} // namespace
Patrick Venture192d60f2018-11-06 11:11:59 -080084
Patrick Venture5b451e62018-11-14 14:20:08 -080085} // namespace blobs
Patrick Venturec7ca2912018-11-02 11:38:33 -070086
Patrick Venture5b451e62018-11-14 14:20:08 -080087extern "C" {
Patrick Venture5b451e62018-11-14 14:20:08 -080088std::unique_ptr<blobs::GenericBlobInterface> createHandler();
Patrick Venture5b451e62018-11-14 14:20:08 -080089}
Patrick Venture5b451e62018-11-14 14:20:08 -080090
91std::unique_ptr<blobs::GenericBlobInterface> createHandler()
Patrick Venturec7ca2912018-11-02 11:38:33 -070092{
Patrick Venture5b451e62018-11-14 14:20:08 -080093 using namespace phosphor::logging;
94
95 auto handler = blobs::FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture4eb55952018-11-16 15:36:24 -080096 sdbusplus::bus::new_default(), blobs::supportedFirmware,
97 blobs::supportedTransports);
Patrick Venture52854622018-11-06 12:30:00 -080098
99 if (!handler)
100 {
101 log<level::ERR>("Firmware Handler has invalid configuration");
Patrick Venture5b451e62018-11-14 14:20:08 -0800102 return nullptr;
Patrick Venture52854622018-11-06 12:30:00 -0800103 }
104
Patrick Venture5b451e62018-11-14 14:20:08 -0800105 return std::move(handler);
Patrick Venturec7ca2912018-11-02 11:38:33 -0700106}