blob: db271abcfc1d2aeeaa41aa9e840530bb6660dc3e [file] [log] [blame]
Adriana Kobylak70f5bc02020-05-13 14:08:14 -05001#include "config.h"
2
Adriana Kobylak86013f32020-05-13 12:12:38 -05003#include "item_updater_helper.hpp"
4
Isaac Kurth7eebeaa2021-06-15 13:25:30 -05005#include "utils.hpp"
6
Adriana Kobylak34124352020-05-22 09:40:40 -05007#include <thread>
8
Adriana Kobylak86013f32020-05-13 12:12:38 -05009namespace phosphor
10{
11namespace software
12{
13namespace updater
14{
15
16void Helper::setEntry(const std::string& /* entryId */, uint8_t /* value */)
17{
18 // Empty
19}
20
21void Helper::clearEntry(const std::string& /* entryId */)
22{
23 // Empty
24}
25
26void Helper::cleanup()
27{
28 // Empty
29}
30
31void Helper::factoryReset()
32{
Isaac Kurth7eebeaa2021-06-15 13:25:30 -050033 // Mark the read-write partition for recreation upon reboot.
34 utils::execute("/sbin/fw_setenv", "rwreset", "true");
Adriana Kobylak86013f32020-05-13 12:12:38 -050035}
36
Adriana Kobylak25773a72022-01-21 15:24:48 +000037void Helper::removeVersion(const std::string& flashId)
Adriana Kobylak86013f32020-05-13 12:12:38 -050038{
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050039 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
40 SYSTEMD_INTERFACE, "StartUnit");
Adriana Kobylak25773a72022-01-21 15:24:48 +000041 auto serviceFile = "obmc-flash-mmc-remove@" + flashId + ".service";
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050042 method.append(serviceFile, "replace");
43 bus.call_noreply(method);
Adriana Kobylakc31943e2020-07-29 12:41:59 -050044
45 // Wait a few seconds for the service file to finish, otherwise the BMC may
46 // start the update while the image is still being deleted.
47 constexpr auto removeWait = std::chrono::seconds(3);
48 std::this_thread::sleep_for(removeWait);
Adriana Kobylak86013f32020-05-13 12:12:38 -050049}
50
Adriana Kobylak25773a72022-01-21 15:24:48 +000051void Helper::updateUbootVersionId(const std::string& flashId)
Adriana Kobylak86013f32020-05-13 12:12:38 -050052{
Adriana Kobylak34124352020-05-22 09:40:40 -050053 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
54 SYSTEMD_INTERFACE, "StartUnit");
Adriana Kobylak25773a72022-01-21 15:24:48 +000055 auto serviceFile = "obmc-flash-mmc-setprimary@" + flashId + ".service";
Adriana Kobylak34124352020-05-22 09:40:40 -050056 method.append(serviceFile, "replace");
57 bus.call_noreply(method);
58
59 // Wait a few seconds for the service file to finish, otherwise the BMC may
60 // be rebooted while pointing to a non-existent version.
61 constexpr auto setPrimaryWait = std::chrono::seconds(3);
62 std::this_thread::sleep_for(setPrimaryWait);
Adriana Kobylak86013f32020-05-13 12:12:38 -050063}
64
65void Helper::mirrorAlt()
66{
Lakshmi Yadlapati87c5b5b2022-11-15 18:14:12 -060067 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
68 SYSTEMD_INTERFACE, "StartUnit");
69 auto serviceFile = "obmc-flash-mmc-mirroruboot.service";
70 method.append(serviceFile, "replace");
71 bus.call_noreply(method);
Adriana Kobylak86013f32020-05-13 12:12:38 -050072}
73
74} // namespace updater
75} // namespace software
76} // namespace phosphor