From 6e95f4a761021e3204912e3a7c5b80a18d9f16cf Mon Sep 17 00:00:00 2001 From: Jennifer Lee Date: Mon, 10 Dec 2018 10:36:44 -0800 Subject: [PATCH] Modified firmware activation to launch fwupd.sh through non-ubi fs code path to match more closely to the upstream design - Added option FWUPD_SCRIPT to saperate intel customized code - Adopted ActivationProgress from ubi fs activation code mainly for progress indicator for ipmi update Signed-off-by: Jennifer Lee Signed-off-by: James Feist --- activation.cpp | 50 +++++++++++++++++++++++++++++++++++++---------- meson.build | 2 ++ meson_options.txt | 3 +++ static/flash.cpp | 42 +++++++++++++++++++++++++++++++++++++-- ubi/flash.cpp | 9 +++------ 5 files changed, 88 insertions(+), 18 deletions(-) diff --git a/activation.cpp b/activation.cpp index 5490cd9974b3..e43959d78ed2 100644 --- a/activation.cpp +++ b/activation.cpp @@ -88,20 +88,50 @@ auto Activation::activation(Activations value) -> Activations if (value == softwareServer::Activation::Activations::Activating) { -#ifdef WANT_SIGNATURE_VERIFY - fs::path uploadDir(IMG_UPLOAD_DIR); - if (!verifySignature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH)) +#ifdef FWUPD_SCRIPT + if (!activationProgress) { - onVerifyFailed(); - // Stop the activation process, if fieldMode is enabled. - if (parent.control::FieldMode::fieldModeEnabled()) + // Enable systemd signals + Activation::subscribeToSystemdSignals(); + parent.freeSpace(*this); + + activationProgress = + std::make_unique(bus, path); + +#ifdef WANT_SIGNATURE_VERIFY + fs::path uploadDir(IMG_UPLOAD_DIR); + if (!verifySignature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH)) { - return softwareServer::Activation::activation( - softwareServer::Activation::Activations::Failed); + onVerifyFailed(); + // Stop the activation process, if fieldMode is enabled. + if (parent.control::FieldMode::fieldModeEnabled()) + { + return softwareServer::Activation::activation( + softwareServer::Activation::Activations::Failed); + } } - } #endif + flashWrite(); + } + else if (activationProgress->progress() == 100) + { + error("progress == 100..."); + if (!redundancyPriority) + { + redundancyPriority = + std::make_unique(bus, path, *this, 0); + } + + // Remove version object from image manager + Activation::deleteImageManagerObject(); + // Create active association + parent.createActiveAssociation(path); + + return softwareServer::Activation::activation( + softwareServer::Activation::Activations::Active); + } +#else // !FWUPD_SCRIPT #ifdef HOST_BIOS_UPGRADE auto purpose = parent.versions.find(versionId)->second->purpose(); if (purpose == VersionPurpose::Host) @@ -124,7 +154,6 @@ auto Activation::activation(Activations value) -> Activations return softwareServer::Activation::activation(value); } #endif - auto versionStr = parent.versions.find(versionId)->second->version(); if (!minimum_ship_level::verify(versionStr)) @@ -174,6 +203,7 @@ auto Activation::activation(Activations value) -> Activations return softwareServer::Activation::activation( softwareServer::Activation::Activations::Active); #endif +#endif // FWUPD_SCRIPT } else { diff --git a/meson.build b/meson.build index a6ebcc43c0ec..5c7900924959 100644 --- a/meson.build +++ b/meson.build @@ -59,6 +59,8 @@ conf.set('WANT_SIGNATURE_VERIFY', \ get_option('verify-full-signature').enabled()) conf.set('WANT_SIGNATURE_FULL_VERIFY', get_option('verify-full-signature').enabled()) +conf.set('FWUPD_SCRIPT', get_option('fwupd-script').enabled()) + # Configurable variables conf.set('ACTIVE_BMC_MAX_ALLOWED', get_option('active-bmc-max-allowed')) conf.set_quoted('HASH_FILE_NAME', get_option('hash-file-name')) diff --git a/meson_options.txt b/meson_options.txt index 4def7f982809..74e757b75f01 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -25,6 +25,9 @@ option('verify-signature', type: 'feature', option('verify-full-signature', type: 'feature', description: 'Enable image full signature validation.') +option('fwupd-script', type: 'feature', + description: 'Enable fwupd script support.') + # Variables option( 'active-bmc-max-allowed', type: 'integer', diff --git a/static/flash.cpp b/static/flash.cpp index 101828b1ade5..5506a59ac499 100644 --- a/static/flash.cpp +++ b/static/flash.cpp @@ -22,9 +22,11 @@ namespace updater namespace fs = std::filesystem; using namespace phosphor::software::image; +namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; void Activation::flashWrite() { +#ifndef FWUPD_SCRIPT // For static layout code update, just put images in /run/initramfs. // It expects user to trigger a reboot and an updater script will program // the image to flash during reboot. @@ -36,11 +38,47 @@ void Activation::flashWrite() fs::copy_file(uploadDir / versionId / bmcImage, toPath / bmcImage, fs::copy_options::overwrite_existing); } + +#else + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + method.append("fwupd@" + versionId + ".service", "replace"); + bus.call_noreply(method); +#endif } -void Activation::onStateChanges(sdbusplus::message::message& /*msg*/) +void Activation::onStateChanges(__attribute__((unused)) + sdbusplus::message::message& msg) { - // Empty +#ifndef FWUPD_SCRIPT + uint32_t newStateID{}; + sdbusplus::message::object_path newStateObjPath; + std::string newStateUnit{}; + std::string newStateResult{}; + + msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); + + auto rwServiceFile = "fwupdw@" + versionId + ".service"; + + if (newStateUnit == rwServiceFile && newStateResult == "done") + { + activationProgress->progress(100); + } + + if (newStateUnit == rwServiceFile) + { + if (newStateResult == "failed" || newStateResult == "dependency") + { + Activation::activation( + softwareServer::Activation::Activations::Failed); + } + else + { + Activation::activation( + softwareServer::Activation::Activations::Activating); + } + } +#endif } } // namespace updater diff --git a/ubi/flash.cpp b/ubi/flash.cpp index a263bfb81116..c58eefc4ec48 100644 --- a/ubi/flash.cpp +++ b/ubi/flash.cpp @@ -15,13 +15,10 @@ void Activation::flashWrite() { auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, SYSTEMD_INTERFACE, "StartUnit"); - std::string rwServiceFile = - "obmc-flash-bmc-ubirw@" + versionId + ".service"; - method.append(rwServiceFile, "replace"); + method.append("obmc-flash-bmc-ubirw.service", "replace"); bus.call_noreply(method); - std::string roServiceFile = - "obmc-flash-bmc-ubiro@" + versionId + ".service"; + auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service"; method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, SYSTEMD_INTERFACE, "StartUnit"); method.append(roServiceFile, "replace"); @@ -40,7 +37,7 @@ void Activation::onStateChanges(sdbusplus::message::message& msg) // Read the msg and populate each variable msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); - auto rwServiceFile = "obmc-flash-bmc-ubirw@" + versionId + ".service"; + auto rwServiceFile = "obmc-flash-bmc-ubirw.service"; auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service"; auto ubootVarsServiceFile = "obmc-flash-bmc-updateubootvars@" + versionId + ".service"; -- 2.17.1