| // Copyright 2024 Google LLC |
| // |
| // 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. |
| |
| #pragma once |
| |
| #include "message_util.hpp" |
| |
| #include <CLI/CLI.hpp> |
| #include <boost/endian/arithmetic.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <xyz/openbmc_project/Control/Hoth/server.hpp> |
| |
| #include <optional> |
| #include <span> |
| #include <string> |
| #include <vector> |
| |
| using FirmwareUpdateStatus = sdbusplus::xyz::openbmc_project::Control::server:: |
| Hoth::FirmwareUpdateStatus; |
| |
| namespace google::hoth::tools |
| { |
| |
| struct Args |
| { |
| std::string hothId; |
| std::string imageFilename; |
| std::string updateMethod; |
| std::optional<uint32_t> address; |
| bool ro; |
| int result; |
| |
| // For package activation check. |
| std::string expectedRwVersion; |
| }; |
| |
| // From src/platform/ec/include/ec_commands.h |
| struct HothVersionStrings |
| { |
| // Null-terminated version strings for RO, RW |
| char version_string_ro[32]; |
| char version_string_rw[32]; |
| char reserved[32]; // Was previously RW-B string |
| boost::endian::little_uint32_t current_image; // One of ec_current_image |
| }; |
| |
| struct HothVersionStringsRsp |
| { |
| google::hoth::internal::RspHeader header; |
| HothVersionStrings version; |
| }; |
| |
| struct HothActivationStatistics |
| { |
| std::optional<uint32_t> rw_failure_code; |
| std::optional<uint32_t> rw_failed_minor; |
| std::optional<uint32_t> ro_failure_code; |
| std::optional<uint32_t> reset_flags; |
| std::optional<uint64_t> uptime_us; |
| }; |
| |
| class HothUpdaterCLI |
| { |
| public: |
| virtual ~HothUpdaterCLI() = default; |
| static void updateFirmware(sdbusplus::bus::bus &bus, |
| std::string_view hoth_id, |
| std::span<const uint8_t> image); |
| void doUpdate(const Args& args); |
| void doActivationCheck(const Args& args); |
| void doFirmwareVersion(const Args& args); |
| virtual void spiWrite(sdbusplus::bus::bus& bus, std::string_view hoth_id, |
| std::span<const uint8_t> image, |
| std::optional<uint32_t> address); |
| virtual std::vector<uint8_t> |
| readFileIntoByteArray(std::string_view filename); |
| virtual FirmwareUpdateStatus |
| getFirmwareUpdateStatus(sdbusplus::bus::bus& bus, |
| std::string_view hoth_id); |
| virtual HothVersionStringsRsp getHothVersion(sdbusplus::bus::bus& bus, |
| std::string_view hoth_id); |
| virtual HothActivationStatistics |
| getHothActivationStatistics(sdbusplus::bus::bus& bus, |
| std::string_view hoth_id); |
| }; |
| |
| void setupCLIApp(CLI::App& app, HothUpdaterCLI& cli, Args& args); |
| |
| std::vector<std::string> splitString(const std::string& s, char delim); |
| |
| } // namespace google::hoth::tools |