blob: 4344c7fce49d1f06912e0ad8faffdf3c747016f0 [file] [log] [blame]
Adriana Kobylak55f9e832017-05-14 16:13:00 -05001#include <experimental/filesystem>
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -05002#include "activation.hpp"
Adriana Kobylak692b5552017-04-17 14:02:58 -05003#include "config.h"
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -05004
5namespace openpower
6{
7namespace software
8{
9namespace updater
10{
11
Adriana Kobylak55f9e832017-05-14 16:13:00 -050012namespace fs = std::experimental::filesystem;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050013namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
14
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050015auto Activation::activation(Activations value) ->
16 Activations
17{
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050018 if (value == softwareServer::Activation::Activations::Activating)
19 {
20 if (!activationBlocksTransition)
21 {
22 activationBlocksTransition =
23 std::make_unique<ActivationBlocksTransition>(
24 bus,
25 path);
26 }
Saqib Khan1e9b7162017-04-18 10:21:59 -050027
28 // Creating a mount point to access squashfs image.
29 constexpr auto squashfsMountService = "obmc-flash-bios-squashfsmount@";
30 auto squashfsMountServiceFile = std::string(squashfsMountService) +
31 versionId + ".service";
32 auto method = bus.new_method_call(
33 SYSTEMD_BUSNAME,
34 SYSTEMD_PATH,
35 SYSTEMD_INTERFACE,
36 "StartUnit");
37 method.append(squashfsMountServiceFile,
38 "replace");
39 bus.call_noreply(method);
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050040 }
41 else
42 {
43 activationBlocksTransition.reset(nullptr);
44 }
45 return softwareServer::Activation::activation(value);
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050046}
47
48auto Activation::requestedActivation(RequestedActivations value) ->
49 RequestedActivations
50{
Adriana Kobylak692b5552017-04-17 14:02:58 -050051 if ((value == softwareServer::Activation::RequestedActivations::Active) &&
52 (softwareServer::Activation::requestedActivation() !=
53 softwareServer::Activation::RequestedActivations::Active))
54 {
55 constexpr auto ubimountService = "obmc-flash-bios-ubimount@";
56 auto ubimountServiceFile = std::string(ubimountService) +
57 versionId +
58 ".service";
59 auto method = bus.new_method_call(
60 SYSTEMD_BUSNAME,
61 SYSTEMD_PATH,
62 SYSTEMD_INTERFACE,
63 "StartUnit");
64 method.append(ubimountServiceFile,
65 "replace");
66 bus.call_noreply(method);
Adriana Kobylak55f9e832017-05-14 16:13:00 -050067
68 // The ubimount service files attemps to create the RW and Preserved
69 // UBI volumes. If the service fails, the mount directories PNOR_PRSV
70 // and PNOR_RW_PREFIX_<versionid> won't be present. Check for the
71 // existence of those directories to validate the service file was
72 // successful, also for the existence of the RO directory where the
73 // image is supposed to reside.
74 if ((fs::exists(PNOR_PRSV)) &&
75 (fs::exists(PNOR_RW_PREFIX + versionId)) &&
76 (fs::exists(PNOR_RO_PREFIX + versionId)))
77 {
78 if (!fs::exists(PNOR_ACTIVE_PATH))
79 {
80 fs::create_directories(PNOR_ACTIVE_PATH);
81 }
82
83 // If the RW or RO active links exist, remove them and create new
84 // ones pointing to the active version.
85 if (fs::exists(PNOR_RO_ACTIVE_PATH))
86 {
87 fs::remove(PNOR_RO_ACTIVE_PATH);
88 }
89 fs::create_directory_symlink(PNOR_RO_PREFIX + versionId,
90 PNOR_RO_ACTIVE_PATH);
91 if (fs::exists(PNOR_RW_ACTIVE_PATH))
92 {
93 fs::remove(PNOR_RW_ACTIVE_PATH);
94 }
95 fs::create_directory_symlink(PNOR_RW_PREFIX + versionId,
96 PNOR_RW_ACTIVE_PATH);
97
98 // There is only one preserved directory as it is not tied to a
99 // version, so just create the link if it doesn't exist already.
100 if (!fs::exists(PNOR_PRSV_ACTIVE_PATH))
101 {
102 fs::create_directory_symlink(PNOR_PRSV, PNOR_PRSV_ACTIVE_PATH);
103 }
104
105 Activation::activation(
106 softwareServer::Activation::Activations::Active);
107 }
108 else
109 {
110 Activation::activation(
111 softwareServer::Activation::Activations::Failed);
112 }
Adriana Kobylak692b5552017-04-17 14:02:58 -0500113 }
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500114 return softwareServer::Activation::requestedActivation(value);
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500115}
116
117} // namespace updater
118} // namespace software
119} // namespace openpower
120