Skip to content

Commit e34b34a

Browse files
committed
Check boot mode to validate parameter HostNumber
Identify boot mode of the system using an existing dbus service. Boot mode for Single Node [2P-Default] is 0 and it is 1 for Multi-Node [2x1P]. Check the URL for resource bios_active and parameter HostNumber. If the boot mode is Multi-Node [2x1P] and HostNumber is 0, return an error. 0 is not a valid parameter HostNumber value for the resource bios_active on Multi-Node [2x1P] systems. Tested: Verified on Multi-Node [2x1P] and Single Node [2P-Default] systems. Signed-off-by: Shirish Pargaonkar <[email protected]>
1 parent 7a9dfd3 commit e34b34a

File tree

3 files changed

+78
-19
lines changed

3 files changed

+78
-19
lines changed

include/bootmode.hpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
namespace bootmode
4+
{
5+
6+
class BootMode {
7+
private:
8+
uint16_t bootMode{0};
9+
10+
void setBootMode(uint16_t bMode) {bootMode = bMode;};
11+
public:
12+
BootMode() {};
13+
BootMode(BootMode const&) = delete;
14+
void operator=(BootMode const&) = delete;
15+
16+
void bootModeService() {
17+
crow::connections::systemBus->async_method_call(
18+
[this](const boost::system::error_code& ec, sdbusplus::message::message& msg) {
19+
if (ec) {
20+
BMCWEB_LOG_ERROR("Failed to read CurrentMode: {}", ec);
21+
return;
22+
}
23+
24+
std::variant<uint16_t> value;
25+
msg.read(value);
26+
uint16_t bMode = std::get<uint16_t>(value);
27+
BMCWEB_LOG_DEBUG("boot mode: {}", bMode);
28+
this->setBootMode(bMode);
29+
},
30+
"xyz.openbmc_project.Settings", // service
31+
"/xyz/openbmc_project/control/HostMode", // object path
32+
"org.freedesktop.DBus.Properties", // standard dbus interface
33+
"Get", // method
34+
"xyz.openbmc_project.Control.HostMode", // interface
35+
"CurrentMode" // property
36+
);
37+
}
38+
39+
uint16_t getBootMode() const {return bootMode;};
40+
};
41+
}

redfish-core/lib/update_service.hpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "utils/dbus_utils.hpp"
3232
#include "utils/json_utils.hpp"
3333
#include "utils/sw_utils.hpp"
34+
#include "bootmode.hpp"
3435

3536
#include <sys/mman.h>
3637

@@ -67,6 +68,8 @@ static bool fwUpdateInProgress = false;
6768
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
6869
static std::unique_ptr<boost::asio::steady_timer> fwAvailableTimer;
6970

71+
extern bootmode::BootMode bmObj;
72+
7073
struct MemoryFileDescriptor
7174
{
7275
int fd = -1;
@@ -1386,25 +1389,34 @@ inline void handleUpdateServiceFirmwareInventoryGet(
13861389
}
13871390

13881391
boost::urls::url_view urlView = req.url();
1389-
uint16_t hostNumber;
1390-
1391-
for (const auto& parameter : urlView.params())
1392-
{
1393-
if (parameter.key == "HostNumber" && !parameter.value.empty())
1394-
{
1395-
try
1396-
{
1397-
int temp = std::stoi(std::string(parameter.value));
1398-
hostNumber = static_cast<uint16_t>(temp);
1399-
}
1400-
catch (const std::exception& e)
1401-
{
1402-
BMCWEB_LOG_WARNING("Invalid HostNumber format: {}",
1403-
parameter.value);
1404-
hostNumber = 0;
1405-
}
1406-
break;
1407-
}
1392+
uint16_t hostNumber = 0;
1393+
1394+
for (const auto& parameter : urlView.params()) {
1395+
if (parameter.key == "HostNumber") {
1396+
if (!parameter.value.empty()) {
1397+
try {
1398+
int temp = std::stoi(std::string(parameter.value));
1399+
hostNumber = static_cast<uint16_t>(temp);
1400+
uint16_t bootMode = bmObj.getBootMode();
1401+
if (hostNumber == 0 && bootMode == 1) {
1402+
BMCWEB_LOG_ERROR("Invalid HostNumber {} for the mode {}", hostNumber, bootMode);
1403+
messages::actionParameterNotSupported(
1404+
asyncResp->res, std::to_string(hostNumber), "HostNumber");
1405+
return;
1406+
}
1407+
}
1408+
catch (const std::exception& e) {
1409+
BMCWEB_LOG_ERROR("Invalid HostNumber format: {}", parameter.value);
1410+
messages::actionParameterValueFormatError(
1411+
asyncResp->res, parameter.value, "HostNumber", "");
1412+
return;
1413+
}
1414+
} else {
1415+
BMCWEB_LOG_ERROR("Missing HostNumber");
1416+
messages::actionParameterMissing(asyncResp->res, "HostNumber", "");
1417+
return;
1418+
}
1419+
}
14081420
}
14091421

14101422
if (hostNumber > 2)

redfish-core/src/redfish.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@
4646
#include "trigger.hpp"
4747
#include "update_service.hpp"
4848
#include "virtual_media.hpp"
49+
#include "bootmode.hpp"
4950

5051
namespace redfish
5152
{
5253

54+
bootmode::BootMode bmObj;
55+
5356
RedfishService::RedfishService(App& app)
5457
{
58+
59+
bmObj.bootModeService();
60+
5561
requestRoutesMetadata(app);
5662

5763
requestAccountServiceRoutes(app);

0 commit comments

Comments
 (0)