170f5bc04SAdriana Kobylak #include "config.h" 270f5bc04SAdriana Kobylak 386013f39SAdriana Kobylak #include "flash.hpp" 486013f39SAdriana Kobylak 586013f39SAdriana Kobylak #include "activation.hpp" 6*25773a7eSAdriana Kobylak #include "item_updater.hpp" 786013f39SAdriana Kobylak 886013f39SAdriana Kobylak namespace phosphor 986013f39SAdriana Kobylak { 1086013f39SAdriana Kobylak namespace software 1186013f39SAdriana Kobylak { 1286013f39SAdriana Kobylak namespace updater 1386013f39SAdriana Kobylak { 1486013f39SAdriana Kobylak 1570f5bc04SAdriana Kobylak namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; 1670f5bc04SAdriana Kobylak 1786013f39SAdriana Kobylak void Activation::flashWrite() 1886013f39SAdriana Kobylak { 1970f5bc04SAdriana Kobylak auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 2070f5bc04SAdriana Kobylak SYSTEMD_INTERFACE, "StartUnit"); 2170f5bc04SAdriana Kobylak auto serviceFile = "obmc-flash-mmc@" + versionId + ".service"; 2270f5bc04SAdriana Kobylak method.append(serviceFile, "replace"); 2370f5bc04SAdriana Kobylak bus.call_noreply(method); 2486013f39SAdriana Kobylak } 2586013f39SAdriana Kobylak 2670f5bc04SAdriana Kobylak void Activation::onStateChanges(sdbusplus::message::message& msg) 2786013f39SAdriana Kobylak { 2870f5bc04SAdriana Kobylak uint32_t newStateID{}; 2970f5bc04SAdriana Kobylak sdbusplus::message::object_path newStateObjPath; 3070f5bc04SAdriana Kobylak std::string newStateUnit{}; 3170f5bc04SAdriana Kobylak std::string newStateResult{}; 3270f5bc04SAdriana Kobylak 3370f5bc04SAdriana Kobylak // Read the msg and populate each variable 3470f5bc04SAdriana Kobylak msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); 3570f5bc04SAdriana Kobylak 3670f5bc04SAdriana Kobylak auto mmcServiceFile = "obmc-flash-mmc@" + versionId + ".service"; 37*25773a7eSAdriana Kobylak auto flashId = parent.versions.find(versionId)->second->path(); 38*25773a7eSAdriana Kobylak auto mmcSetPrimary = "obmc-flash-mmc-setprimary@" + flashId + ".service"; 3970f5bc04SAdriana Kobylak 4070f5bc04SAdriana Kobylak if (newStateUnit == mmcServiceFile && newStateResult == "done") 4170f5bc04SAdriana Kobylak { 4270f5bc04SAdriana Kobylak roVolumeCreated = true; 4370f5bc04SAdriana Kobylak activationProgress->progress(activationProgress->progress() + 1); 4470f5bc04SAdriana Kobylak } 4570f5bc04SAdriana Kobylak 4634124351SAdriana Kobylak if (newStateUnit == mmcSetPrimary && newStateResult == "done") 4734124351SAdriana Kobylak { 4834124351SAdriana Kobylak ubootEnvVarsUpdated = true; 4934124351SAdriana Kobylak } 5034124351SAdriana Kobylak 5134124351SAdriana Kobylak if (newStateUnit == mmcServiceFile || newStateUnit == mmcSetPrimary) 5270f5bc04SAdriana Kobylak { 5370f5bc04SAdriana Kobylak if (newStateResult == "failed" || newStateResult == "dependency") 5470f5bc04SAdriana Kobylak { 5570f5bc04SAdriana Kobylak Activation::activation( 5670f5bc04SAdriana Kobylak softwareServer::Activation::Activations::Failed); 5770f5bc04SAdriana Kobylak } 5870f5bc04SAdriana Kobylak else if (roVolumeCreated) 5970f5bc04SAdriana Kobylak { 6034124351SAdriana Kobylak if (!ubootEnvVarsUpdated) 6134124351SAdriana Kobylak { 6234124351SAdriana Kobylak activationProgress->progress(90); 6334124351SAdriana Kobylak 6434124351SAdriana Kobylak // Set the priority which triggers the service that updates the 6534124351SAdriana Kobylak // environment variables. 6634124351SAdriana Kobylak if (!Activation::redundancyPriority) 6734124351SAdriana Kobylak { 6834124351SAdriana Kobylak Activation::redundancyPriority = 6934124351SAdriana Kobylak std::make_unique<RedundancyPriority>(bus, path, *this, 7034124351SAdriana Kobylak 0); 7134124351SAdriana Kobylak } 7234124351SAdriana Kobylak } 7334124351SAdriana Kobylak else // Environment variables were updated 7434124351SAdriana Kobylak { 7570f5bc04SAdriana Kobylak Activation::onFlashWriteSuccess(); 7670f5bc04SAdriana Kobylak } 7770f5bc04SAdriana Kobylak } 7834124351SAdriana Kobylak } 7970f5bc04SAdriana Kobylak 8070f5bc04SAdriana Kobylak return; 8186013f39SAdriana Kobylak } 8286013f39SAdriana Kobylak 8386013f39SAdriana Kobylak } // namespace updater 8486013f39SAdriana Kobylak } // namespace software 8586013f39SAdriana Kobylak } // namespace phosphor 86