#pragma once #include "common/include/NotifyWatch.hpp" #include "common/include/device.hpp" #include "common/include/software.hpp" #include "common/include/software_manager.hpp" #include #include #include #include class SPIDevice; using namespace phosphor::software; using namespace phosphor::software::manager; using namespace phosphor::notify::watch; using NotifyWatchIntf = phosphor::notify::watch::NotifyWatch; const std::string biosVersionDirPath = "/var/bios/"; const std::string biosVersionFilename = "host0_bios_version.txt"; const std::string biosVersionPath = biosVersionDirPath + biosVersionFilename; const std::string versionUnknown = "Unknown"; enum FlashLayout { flashLayoutFlat, flashLayoutIntelFlashDescriptor, }; enum FlashTool { flashToolNone, // write directly to the mtd device flashToolFlashrom, // use flashrom, to handle e.g. IFD }; class SPIDevice : public Device, public NotifyWatchIntf { public: using Device::softwareCurrent; SPIDevice(sdbusplus::async::context& ctx, uint64_t spiControllerIndex, uint64_t spiDeviceIndex, bool dryRun, const std::vector& gpioLinesIn, const std::vector& gpioValuesIn, SoftwareConfig& config, SoftwareManager* parent, enum FlashLayout layout, enum FlashTool tool, const std::string& versionDirPath = biosVersionDirPath); sdbusplus::async::task updateDevice(const uint8_t* image, size_t image_size) final; // @returns the bios version which is externally provided. static std::string getVersion(); /** @brief Process async changes to cable configuration */ auto processUpdate(std::string versionFileName) -> sdbusplus::async::task<>; private: bool dryRun; std::vector gpioLines; std::vector gpioValues; uint64_t spiControllerIndex; uint64_t spiDeviceIndex; // e.g. "1e631000.spi" std::string spiDev; enum FlashLayout layout; enum FlashTool tool; // @returns true on success sdbusplus::async::task bindSPIFlash(); // @returns true on success sdbusplus::async::task unbindSPIFlash(); bool isSPIFlashBound(); // @description preconditions: // - host is powered off // @returns true on success sdbusplus::async::task writeSPIFlash(const uint8_t* image, size_t image_size); // @description preconditions: // - host is powered off // - gpio / mux is set // - spi device is bound to the driver // we write the flat image here // @param image the component image // @param image_size size of 'image' // @returns true on success sdbusplus::async::task writeSPIFlashDefault(const uint8_t* image, size_t image_size); // @description preconditions: // - host is powered off // - gpio / mux is set // - spi device is bound to the driver // we use 'flashrom' here to write the image since it can deal with // Intel Flash Descriptor // @param image the component image // @param image_size size of 'image' // @returns 0 on success sdbusplus::async::task writeSPIFlashWithFlashrom( const uint8_t* image, size_t image_size) const; // @returns nullopt on error std::optional getMTDDevicePath() const; };