1 #include "config.h" 2 3 #include "item_updater_helper.hpp" 4 5 #include "utils.hpp" 6 7 #include <phosphor-logging/lg2.hpp> 8 #include <sdbusplus/exception.hpp> 9 10 namespace phosphor 11 { 12 namespace software 13 { 14 namespace updater 15 { 16 17 PHOSPHOR_LOG2_USING; 18 19 void Helper::setEntry(const std::string& entryId, uint8_t value) 20 { 21 std::string serviceFile = "obmc-flash-bmc-setenv@" + entryId + "\\x3d" + 22 std::to_string(value) + ".service"; 23 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 24 SYSTEMD_INTERFACE, "StartUnit"); 25 method.append(serviceFile, "replace"); 26 bus.call_noreply(method); 27 } 28 29 void Helper::clearEntry(const std::string& entryId) 30 { 31 // Remove the priority environment variable. 32 auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service"; 33 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 34 SYSTEMD_INTERFACE, "StartUnit"); 35 method.append(serviceFile, "replace"); 36 bus.call_noreply(method); 37 } 38 39 void Helper::cleanup() 40 { 41 // Remove any volumes that do not match current versions. 42 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 43 SYSTEMD_INTERFACE, "StartUnit"); 44 method.append("obmc-flash-bmc-cleanup.service", "replace"); 45 bus.call_noreply(method); 46 } 47 48 void Helper::factoryReset() 49 { 50 // Mark the read-write partition for recreation upon reboot. 51 utils::execute("/sbin/fw_setenv", "rwreset", "true"); 52 } 53 54 void Helper::removeVersion(const std::string& versionId) 55 { 56 auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + ".service"; 57 58 // Remove the read-only partitions. 59 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 60 SYSTEMD_INTERFACE, "StartUnit"); 61 method.append(serviceFile, "replace"); 62 bus.call_noreply(method); 63 } 64 65 void Helper::updateUbootVersionId(const std::string& versionId) 66 { 67 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 68 SYSTEMD_INTERFACE, "StartUnit"); 69 auto updateEnvVarsFile = 70 "obmc-flash-bmc-updateubootvars@" + versionId + ".service"; 71 method.append(updateEnvVarsFile, "replace"); 72 73 try 74 { 75 bus.call_noreply(method); 76 } 77 catch (const sdbusplus::exception::exception& e) 78 { 79 error("Failed to update u-boot env variables", "VERSIONID", versionId); 80 } 81 } 82 83 void Helper::mirrorAlt() 84 { 85 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, 86 SYSTEMD_INTERFACE, "StartUnit"); 87 auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service"; 88 method.append(mirrorUbootFile, "replace"); 89 90 try 91 { 92 bus.call_noreply(method); 93 } 94 catch (const sdbusplus::exception::exception& e) 95 { 96 error("Failed to copy U-Boot to alternate chip: {ERROR}", "ERROR", e); 97 } 98 } 99 100 } // namespace updater 101 } // namespace software 102 } // namespace phosphor 103