summaryrefslogtreecommitdiffstats
path: root/bmc/main.cpp
blob: 9f1088ae811442aa8c9685b37f4b5347c8a2500d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * Copyright 2018 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "config.h"

#include "file_handler.hpp"
#include "firmware_handler.hpp"
#include "flags.hpp"
#include "image_handler.hpp"
#include "lpc_aspeed.hpp"
#include "lpc_handler.hpp"
#include "lpc_nuvoton.hpp"
#include "pci_handler.hpp"
#include "prepare_systemd.hpp"
#include "status.hpp"
#include "update_systemd.hpp"
#include "util.hpp"
#include "verify_systemd.hpp"

#include <cstdint>
#include <memory>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <unordered_map>

namespace ipmi_flash
{
namespace
{

FileHandler hashHandler(HASH_FILENAME);

#ifdef ENABLE_STATIC_LAYOUT
FileHandler staticLayoutHandler(STATIC_HANDLER_STAGED_NAME);
#endif
#ifdef ENABLE_TARBALL_UBI
FileHandler ubitarballHandler(TARBALL_STAGED_NAME);
#endif
#ifdef ENABLE_HOST_BIOS
FileHandler biosHandler(BIOS_STAGED_NAME);
#endif

/* The maximum external buffer size we expect is 64KB. */
static constexpr std::size_t memoryRegionSize = 64 * 1024UL;

#ifdef ENABLE_LPC_BRIDGE
#if defined(ASPEED_LPC)
LpcDataHandler lpcDataHandler(
    LpcMapperAspeed::createAspeedMapper(MAPPED_ADDRESS, memoryRegionSize));
#elif defined(NUVOTON_LPC)
LpcDataHandler lpcDataHandler(
    LpcMapperNuvoton::createNuvotonMapper(MAPPED_ADDRESS, memoryRegionSize));
#else
#error "You must specify a hardware implementation."
#endif
#endif

#ifdef ENABLE_PCI_BRIDGE
#if defined(ASPEED_P2A)
PciDataHandler pciDataHandler(MAPPED_ADDRESS, memoryRegionSize);
#else
#error "You must specify a hardware implementation."
#endif
#endif

std::vector<HandlerPack> supportedFirmware = {
    {hashBlobId, &hashHandler},
#ifdef ENABLE_STATIC_LAYOUT
    {staticLayoutBlobId, &staticLayoutHandler},
#endif
#ifdef ENABLE_TARBALL_UBI
    {ubiTarballBlobId, &ubitarballHandler},
#endif
#ifdef ENABLE_HOST_BIOS
    {biosBlobId, &biosHandler},
#endif
};

std::vector<DataHandlerPack> supportedTransports = {
    {FirmwareFlags::UpdateFlags::ipmi, nullptr},
#ifdef ENABLE_PCI_BRIDGE
    {FirmwareFlags::UpdateFlags::p2a, &pciDataHandler},
#endif
#ifdef ENABLE_LPC_BRIDGE
    {FirmwareFlags::UpdateFlags::lpc, &lpcDataHandler},
#endif
};

} // namespace
} // namespace ipmi_flash

extern "C" {
std::unique_ptr<blobs::GenericBlobInterface> createHandler();
}

std::unique_ptr<blobs::GenericBlobInterface> createHandler()
{
    ipmi_flash::ActionMap actionPacks = {};

#ifdef ENABLE_REBOOT_UPDATE
    static constexpr auto rebootTarget = "reboot.target";
    static constexpr auto rebootMode = "replace-irreversibly";

    auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
        sdbusplus::bus::new_default(), rebootTarget, rebootMode);
#else
    auto updater = ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
        sdbusplus::bus::new_default(), UPDATE_DBUS_SERVICE);
#endif

    auto prepare = ipmi_flash::SystemdPreparation::CreatePreparation(
        sdbusplus::bus::new_default(), PREPARATION_DBUS_SERVICE);

    auto verifier = ipmi_flash::SystemdVerification::CreateVerification(
        sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME,
        VERIFY_DBUS_SERVICE);

    /* TODO: for bios should the name be, bios or /flash/bios?, these are
     * /flash/... and it simplifies a few other things later (open/etc)
     */
    std::string bmcName;
#ifdef ENABLE_STATIC_LAYOUT
    bmcName = ipmi_flash::staticLayoutBlobId;
#endif
#ifdef ENABLE_TARBALL_UBI
    bmcName = ipmi_flash::ubiTarballBlobId;
#endif

    auto bmcPack = std::make_unique<ipmi_flash::ActionPack>();
    bmcPack->preparation = std::move(prepare);
    bmcPack->verification = std::move(verifier);
    bmcPack->update = std::move(updater);
    actionPacks[bmcName] = std::move(bmcPack);

#ifdef ENABLE_HOST_BIOS
    {
        auto biosPack = std::make_unique<ipmi_flash::ActionPack>();

        biosPack->preparation =
            ipmi_flash::SystemdPreparation::CreatePreparation(
                sdbusplus::bus::new_default(), PREPARATION_BIOS_TARGET);

        biosPack->verification =
            ipmi_flash::SystemdVerification::CreateVerification(
                sdbusplus::bus::new_default(), BIOS_VERIFY_STATUS_FILENAME,
                VERIFY_BIOS_TARGET);

        biosPack->update =
            ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
                sdbusplus::bus::new_default(), UPDATE_BIOS_TARGET);

        actionPacks[ipmi_flash::biosBlobId] = std::move(biosPack);
    }
#endif

    auto handler = ipmi_flash::FirmwareBlobHandler::CreateFirmwareBlobHandler(
        ipmi_flash::supportedFirmware, ipmi_flash::supportedTransports,
        std::move(actionPacks));

    if (!handler)
    {
        using namespace phosphor::logging;

        log<level::ERR>("Firmware Handler has invalid configuration");
        return nullptr;
    }

    return handler;
}
OpenPOWER on IntegriCloud