blob: 09a97138e8f07db6b8469f32dc63bfedbaecd28e [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 Venture1d66fe62019-06-03 14:57:27 -070026#include "status.hpp"
Patrick Venture6f81b162019-05-20 14:02:59 -070027#include "update_systemd.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -070028#include "util.hpp"
Patrick Venture26a17262019-05-20 11:03:35 -070029#include "verify_systemd.hpp"
Patrick Venturec7ca2912018-11-02 11:38:33 -070030
Patrick Venture192d60f2018-11-06 11:11:59 -080031#include <cstdint>
Patrick Venturec7ca2912018-11-02 11:38:33 -070032#include <memory>
33#include <phosphor-logging/log.hpp>
Patrick Venture4eb55952018-11-16 15:36:24 -080034#include <sdbusplus/bus.hpp>
Patrick Venturec7ca2912018-11-02 11:38:33 -070035
Patrick Venture1d5a31c2019-05-20 11:38:22 -070036namespace ipmi_flash
Patrick Venturec7ca2912018-11-02 11:38:33 -070037{
Patrick Venturea78e39f2018-11-06 18:37:06 -080038namespace
39{
Patrick Venture64919ec2018-11-15 11:52:07 -080040FileHandler hashHandler(HASH_FILENAME);
Patrick Venture2ba71302019-05-17 14:48:46 -070041#ifdef ENABLE_STATIC_LAYOUT
Patrick Venture7753d942018-11-15 13:15:36 -080042FileHandler staticLayoutHandler(STATIC_HANDLER_STAGED_NAME);
Patrick Venture2ba71302019-05-17 14:48:46 -070043#endif
44#ifdef ENABLE_TARBALL_UBI
Patrick Ventured46b8112018-11-15 13:38:55 -080045FileHandler ubitarballHandler(TARBALL_STAGED_NAME);
Patrick Venture2ba71302019-05-17 14:48:46 -070046#endif
Patrick Venturee7728422018-11-14 20:16:33 -080047
Patrick Venture7b91cbc2018-11-28 14:24:41 -080048/* The maximum external buffer size we expect is 64KB. */
Patrick Venture28abae72018-12-14 09:44:02 -080049static constexpr std::size_t memoryRegionSize = 64 * 1024UL;
Patrick Venture7b91cbc2018-11-28 14:24:41 -080050
Patrick Venturee7728422018-11-14 20:16:33 -080051#ifdef ENABLE_LPC_BRIDGE
52#if defined(ASPEED_LPC)
Patrick Venture78b1a662019-01-17 12:38:26 -080053LpcDataHandler lpcDataHandler(
54 LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize));
Patrick Venturee7728422018-11-14 20:16:33 -080055#elif defined(NUVOTON_LPC)
Patrick Venture78b1a662019-01-17 12:38:26 -080056LpcDataHandler
57 lpcDataHandler(LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS));
Patrick Venturee7728422018-11-14 20:16:33 -080058#else
59#error "You must specify a hardware implementation."
60#endif
61#endif
62
Patrick Venture102ecbb2019-04-30 16:08:49 -070063#ifdef ENABLE_PCI_BRIDGE
64#if defined(ASPEED_P2A)
Patrick Venture4289e712019-04-30 17:08:50 -070065PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize);
Patrick Venture102ecbb2019-04-30 16:08:49 -070066#else
67#error "You must specify a hardware implementation."
68#endif
69#endif
Patrick Venturea78e39f2018-11-06 18:37:06 -080070
71std::vector<HandlerPack> supportedFirmware = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070072 {hashBlobId, &hashHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080073#ifdef ENABLE_STATIC_LAYOUT
Patrick Venture7dad86f2019-05-17 08:52:20 -070074 {staticLayoutBlobId, &staticLayoutHandler},
Patrick Venture148cd652018-11-06 10:59:47 -080075#endif
Patrick Ventured46b8112018-11-15 13:38:55 -080076#ifdef ENABLE_TARBALL_UBI
Patrick Venture7dad86f2019-05-17 08:52:20 -070077 {ubiTarballBlobId, &ubitarballHandler},
Patrick Ventured46b8112018-11-15 13:38:55 -080078#endif
Patrick Venture148cd652018-11-06 10:59:47 -080079};
80
Patrick Venture1cde5f92018-11-07 08:26:47 -080081std::vector<DataHandlerPack> supportedTransports = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080082 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080083#ifdef ENABLE_PCI_BRIDGE
Patrick Venture05abf7e2018-11-09 11:02:56 -080084 {FirmwareBlobHandler::UpdateFlags::p2a, &pciDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080085#endif
86#ifdef ENABLE_LPC_BRIDGE
Patrick Venture05abf7e2018-11-09 11:02:56 -080087 {FirmwareBlobHandler::UpdateFlags::lpc, &lpcDataHandler},
Patrick Venture1cde5f92018-11-07 08:26:47 -080088#endif
89};
90
Patrick Venturea78e39f2018-11-06 18:37:06 -080091} // namespace
Patrick Venture192d60f2018-11-06 11:11:59 -080092
Patrick Venture1d5a31c2019-05-20 11:38:22 -070093} // namespace ipmi_flash
Patrick Venturec7ca2912018-11-02 11:38:33 -070094
Patrick Venture5b451e62018-11-14 14:20:08 -080095extern "C" {
Patrick Venture5b451e62018-11-14 14:20:08 -080096std::unique_ptr<blobs::GenericBlobInterface> createHandler();
Patrick Venture5b451e62018-11-14 14:20:08 -080097}
Patrick Venture5b451e62018-11-14 14:20:08 -080098
99std::unique_ptr<blobs::GenericBlobInterface> createHandler()
Patrick Venturec7ca2912018-11-02 11:38:33 -0700100{
Patrick Venture5b451e62018-11-14 14:20:08 -0800101 using namespace phosphor::logging;
102
Patrick Venture6f81b162019-05-20 14:02:59 -0700103#ifdef ENABLE_REBOOT_UPDATE
104 static constexpr auto rebootTarget = "reboot.target";
105 static constexpr auto rebootMode = "replace-irreversibly";
106
107 auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
108 sdbusplus::bus::new_default(), rebootTarget, rebootMode);
109#else
110 auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
111 sdbusplus::bus::new_default(), UPDATE_DBUS_SERVICE);
112#endif
113
Patrick Venture1d5a31c2019-05-20 11:38:22 -0700114 auto handler = ipmi_flash::FirmwareBlobHandler::CreateFirmwareBlobHandler(
115 ipmi_flash::supportedFirmware, ipmi_flash::supportedTransports,
116 ipmi_flash::SystemdVerification::CreateVerification(
Patrick Venture3ecb3502019-05-17 11:03:51 -0700117 sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME,
Patrick Venture27ac5822019-05-20 17:39:31 -0700118 VERIFY_DBUS_SERVICE),
119 std::move(updater));
Patrick Venture52854622018-11-06 12:30:00 -0800120
121 if (!handler)
122 {
123 log<level::ERR>("Firmware Handler has invalid configuration");
Patrick Venture5b451e62018-11-14 14:20:08 -0800124 return nullptr;
Patrick Venture52854622018-11-06 12:30:00 -0800125 }
126
Patrick Venture5b451e62018-11-14 14:20:08 -0800127 return std::move(handler);
Patrick Venturec7ca2912018-11-02 11:38:33 -0700128}