Alexander Hansen | 1ba6e1c | 2024-11-26 11:16:44 +0100 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "common/include/device.hpp" |
| 4 | #include "common/include/software_manager.hpp" |
| 5 | |
| 6 | #include <sdbusplus/asio/connection.hpp> |
| 7 | #include <sdbusplus/asio/object_server.hpp> |
| 8 | #include <sdbusplus/async/context.hpp> |
| 9 | |
| 10 | #include <string> |
| 11 | |
| 12 | class Software; |
| 13 | |
| 14 | class SPIDevice : public Device |
| 15 | { |
| 16 | public: |
| 17 | SPIDevice(sdbusplus::async::context& ctx, const std::string& spiDevName, |
| 18 | bool dryRun, bool hasME, |
| 19 | const std::vector<std::string>& gpioLines, |
| 20 | const std::vector<uint8_t>& gpioValues, DeviceConfig& config, |
| 21 | SoftwareManager* parent, bool layoutFlat, bool toolFlashrom, |
| 22 | bool debug); |
| 23 | |
| 24 | sdbusplus::async::task<bool> updateDevice( |
| 25 | const uint8_t* image, size_t image_size, |
| 26 | std::unique_ptr<SoftwareActivationProgress>& activationProgress) final; |
| 27 | |
| 28 | sdbusplus::async::task<std::string> getInventoryItemObjectPath() final; |
| 29 | |
| 30 | private: |
| 31 | // Management Engine specific members and functions |
| 32 | bool hasManagementEngine; |
| 33 | sdbusplus::async::task<> setManagementEngineRecoveryMode(); |
| 34 | sdbusplus::async::task<> resetManagementEngine(); |
| 35 | |
| 36 | std::vector<std::string> gpioLines; |
| 37 | std::vector<uint8_t> gpioValues; |
| 38 | |
| 39 | // SPI specific members and functions |
| 40 | std::string spiDev; |
| 41 | |
| 42 | // does the spi flash have a flat layout? |
| 43 | // Otherwise, we have to use Intel Flash Descriptor |
| 44 | // or another descriptor to figure out which regions should be written |
| 45 | bool layoutFlat; |
| 46 | |
| 47 | // do we use flashrom? |
| 48 | // if not, write directly to the mtd device. |
| 49 | bool toolFlashrom; |
| 50 | |
| 51 | // @param spi_dev e.g. "1e630000.spi" |
| 52 | // @returns true on success |
| 53 | sdbusplus::async::task<bool> bindSPIFlash(); |
| 54 | |
| 55 | // @param spi_dev e.g. "1e630000.spi" |
| 56 | // @returns true on success |
| 57 | sdbusplus::async::task<bool> unbindSPIFlash(); |
| 58 | |
| 59 | // @param spi_dev e.g. "1e630000.spi" |
| 60 | bool isSPIFlashBound(); |
| 61 | |
| 62 | bool debug; |
| 63 | |
| 64 | sdbusplus::async::task<bool> writeSPIFlash( |
| 65 | const uint8_t* image, size_t image_size, |
| 66 | const std::unique_ptr<SoftwareActivationProgress>& activationProgress); |
| 67 | |
| 68 | // this function assumes: |
| 69 | // - host is powered off |
| 70 | sdbusplus::async::task<bool> |
| 71 | writeSPIFlashHostOff(const uint8_t* image, size_t image_size); |
| 72 | |
| 73 | // this function assumes: |
| 74 | // - host is powered off |
| 75 | // - gpio / mux is set |
| 76 | sdbusplus::async::task<bool> |
| 77 | writeSPIFlashHostOffGPIOSet(const uint8_t* image, size_t image_size); |
| 78 | |
| 79 | // this function assumes: |
| 80 | // - host is powered off |
| 81 | // - gpio / mux is set |
| 82 | // - spi device is bound to the driver |
| 83 | // we write the flat image here |
| 84 | // @param image the component image |
| 85 | // @param image_size size of 'image' |
| 86 | // @returns true on success |
| 87 | sdbusplus::async::task<bool> writeSPIFlashHostOffGPIOSetDeviceBound( |
| 88 | const uint8_t* image, size_t image_size); |
| 89 | |
| 90 | // this function assumes: |
| 91 | // - host is powered off |
| 92 | // - gpio / mux is set |
| 93 | // - spi device is bound to the driver |
| 94 | // we use 'flashrom' here to write the image since it can deal with |
| 95 | // Intel Flash Descriptor |
| 96 | // TODO: look into using libflashrom instead |
| 97 | // @param image the component image |
| 98 | // @param image_size size of 'image' |
| 99 | // @returns true on success |
| 100 | sdbusplus::async::task<bool> writeSPIFlashFlashromHostOffGPIOSetDeviceBound( |
| 101 | const uint8_t* image, size_t image_size); |
| 102 | }; |