diff options
| author | Lei YU <mine260309@gmail.com> | 2018-06-21 16:09:44 +0800 |
|---|---|---|
| committer | Lei YU <mine260309@gmail.com> | 2018-07-17 01:45:16 +0000 |
| commit | 56aaf454adef04bd4c1d45870cd86dc2de0a880a (patch) | |
| tree | 424d81ddba382ca5e63afd7af098cf4fc1397603 /ubi | |
| parent | 1be8d500a8e90f9299bab9abf532ff0762177175 (diff) | |
| download | phosphor-bmc-code-mgmt-56aaf454adef04bd4c1d45870cd86dc2de0a880a.tar.gz phosphor-bmc-code-mgmt-56aaf454adef04bd4c1d45870cd86dc2de0a880a.zip | |
item_updater: sort ubi specific code
Add item_updater_helper and implement it in ubi and static layouts.
Tested: Build this repo on both Romulus and Witherspoon OK;
Tested on Romulus and Witherspoon that code update works fine.
Change-Id: I706cfe63900f89bb41672dcc745b3483e06838c7
Signed-off-by: Lei YU <mine260309@gmail.com>
Diffstat (limited to 'ubi')
| -rw-r--r-- | ubi/Makefile.am.include | 3 | ||||
| -rw-r--r-- | ubi/item_updater_helper.cpp | 107 |
2 files changed, 109 insertions, 1 deletions
diff --git a/ubi/Makefile.am.include b/ubi/Makefile.am.include index 7bcfcb2..1a5128a 100644 --- a/ubi/Makefile.am.include +++ b/ubi/Makefile.am.include @@ -1,2 +1,3 @@ phosphor_image_updater_SOURCES += \ - %reldir%/flash.cpp + %reldir%/flash.cpp \ + %reldir%/item_updater_helper.cpp diff --git a/ubi/item_updater_helper.cpp b/ubi/item_updater_helper.cpp new file mode 100644 index 0000000..6704c21 --- /dev/null +++ b/ubi/item_updater_helper.cpp @@ -0,0 +1,107 @@ +#include <phosphor-logging/log.hpp> + +#include "config.h" +#include "item_updater_helper.hpp" + +namespace phosphor +{ +namespace software +{ +namespace updater +{ + +using namespace phosphor::logging; +void Helper::clearEntry(const std::string& entryId) +{ + // Remove the priority environment variable. + auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service"; + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + method.append(serviceFile, "replace"); + bus.call_noreply(method); +} + +void Helper::cleanup() +{ + // Remove any volumes that do not match current versions. + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + method.append("obmc-flash-bmc-cleanup.service", "replace"); + bus.call_noreply(method); +} + +void Helper::factoryReset() +{ + // Mark the read-write partition for recreation upon reboot. + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace"); + bus.call_noreply(method); +} + +void Helper::removeVersion(const std::string& versionId) +{ + auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + ".service"; + + // Remove the read-only partitions. + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + method.append(serviceFile, "replace"); + bus.call_noreply(method); +} + +void Helper::updateUbootVersionId(const std::string& versionId) +{ + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + auto updateEnvVarsFile = + "obmc-flash-bmc-updateubootvars@" + versionId + ".service"; + method.append(updateEnvVarsFile, "replace"); + auto result = bus.call(method); + + // Check that the bus call didn't result in an error + if (result.is_method_error()) + { + log<level::ERR>("Failed to update u-boot env variables", + entry("VERSIONID=%s", versionId.c_str())); + } +} + +void Helper::enableFieldMode() +{ + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service", + "replace"); + bus.call_noreply(method); + + method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StopUnit"); + method.append("usr-local.mount", "replace"); + bus.call_noreply(method); + + std::vector<std::string> usrLocal = {"usr-local.mount"}; + + method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "MaskUnitFiles"); + method.append(usrLocal, false, true); + bus.call_noreply(method); +} +void Helper::mirrorAlt() +{ + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StartUnit"); + auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service"; + method.append(mirrorUbootFile, "replace"); + auto result = bus.call(method); + + // Check that the bus call didn't result in an error + if (result.is_method_error()) + { + log<level::ERR>("Failed to copy U-Boot to alternate chip"); + } +} + +} // namespace updater +} // namespace software +} // namespace phosphor |

