Restrict updating of IM keyword
This commit adds code to restrict updating of IM value from vpd-tool if
the value is not in the supported list of IM values.
Test:
```
root@p10bmc:~# vpd-tool -w -O "/system/chassis/motherboard" -R "VSBP" -K "IM" -V "0x50001003"
Given IM value [0x50001003] does not match to any valid system type.
root@p10bmc:~# vpd-tool -w -O "/system/chassis/motherboard" -R "VSBP" -K "IM" -V "5000"
Given IM value [5000] does not match to any valid system type.
root@p10bmc:~# vpd-tool -w -O "/system/chassis/motherboard" -R "VSBP" -K "IM" -V "0x50001002"
Data updated successfully
```
Change-Id: Ia14d6ffe8673a3ed94fc3a5f4fdbfe37f351b2a8
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-tool/include/tool_constants.hpp b/vpd-tool/include/tool_constants.hpp
index dbc4eb2..3201755 100644
--- a/vpd-tool/include/tool_constants.hpp
+++ b/vpd-tool/include/tool_constants.hpp
@@ -1,6 +1,8 @@
#pragma once
#include <cstdint>
+#include <string>
+#include <vector>
namespace vpd
{
@@ -51,6 +53,13 @@
constexpr auto biosConfigMgrInterface =
"xyz.openbmc_project.BIOSConfig.Manager";
+constexpr auto KwdIM = "IM";
+
+// Valid IM values list.
+static std::vector<std::string> validImValues{
+ "0x50001000", "0x50001001", "0x50001002", "0x50003000", "0x50004000",
+ "0x60001000", "0x60001001", "0x60001002", "0x60002000", "0x60004000"};
+
static constexpr auto VALUE_0 = 0;
static constexpr auto VALUE_1 = 1;
static constexpr auto VALUE_2 = 2;
diff --git a/vpd-tool/src/vpd_tool_main.cpp b/vpd-tool/src/vpd_tool_main.cpp
index 18d71ef..152cfca 100644
--- a/vpd-tool/src/vpd_tool_main.cpp
+++ b/vpd-tool/src/vpd_tool_main.cpp
@@ -113,6 +113,26 @@
return vpd::constants::FAILURE;
}
+ if (i_keywordName == vpd::constants::KwdIM)
+ {
+ if (!(i_keywordValue.substr(0, 2).compare("0x") ==
+ vpd::constants::STR_CMP_SUCCESS))
+ {
+ std::cerr << "Please provide IM value in hex format." << std::endl;
+ return vpd::constants::FAILURE;
+ }
+
+ if (std::find(vpd::constants::validImValues.begin(),
+ vpd::constants::validImValues.end(), i_keywordValue) ==
+ vpd::constants::validImValues.end())
+ {
+ std::cerr << "Given IM value [" << i_keywordValue
+ << "] doesn't match with any of the valid system type."
+ << std::endl;
+ return vpd::constants::FAILURE;
+ }
+ }
+
vpd::VpdTool l_vpdToolObj;
return l_vpdToolObj.writeKeyword(i_vpdPath, i_recordName, i_keywordName,
i_keywordValue, !i_hardwareFlag->empty());