PHAL: Compute RO device tree file path from RW device tree symbolic link
Example:
RW file = /media/hostfw/running/DEVTREE -> 81e00672.lid
RO file = /media/hostfw/running-ro/ + 81e00672.lid
Compute the lid name by reading the RW symbolic link and use
it to comptue RO file.
Symbolic links cannot be created to RO files so using this approach
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
Change-Id: I46101b8e246267c861edb5eae1ac24420cfc3c6d
diff --git a/meson.build b/meson.build
index bbaeeed..8af1f98 100644
--- a/meson.build
+++ b/meson.build
@@ -43,10 +43,9 @@
description : 'Path to the devtree file r/w version'
)
-conf_data.set_quoted('CEC_DEVTREE_RO_PATH', get_option('CEC_DEVTREE_RO_PATH'),
- description : 'Path to the devtree file read only version'
+conf_data.set_quoted('CEC_DEVTREE_RO_BASE_PATH', get_option('CEC_DEVTREE_RO_BASE_PATH'),
+ description : 'Base path to the devtree file read only version'
)
-
conf_data.set_quoted('CEC_INFODB_PATH', get_option('CEC_INFODB_PATH'),
description : 'Path to the devtree attributes based database path'
)
diff --git a/meson_options.txt b/meson_options.txt
index 766c215..b5117f2 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -12,12 +12,12 @@
description : 'Path to the devtree export copy file'
)
option('CEC_DEVTREE_RW_PATH', type : 'string',
- value : '/var/lib/phosphor-software-manager/pnor/rw/DEVTREE',
+ value : '/media/hostfw/running/DEVTREE',
description : 'Path to the devtree file r/w version'
)
-option('CEC_DEVTREE_RO_PATH', type : 'string',
- value : '/var/lib/phosphor-software-manager/pnor/ro/DEVTREE',
- description : 'Path to the devtree file read only version'
+option('CEC_DEVTREE_RO_BASE_PATH', type : 'string',
+ value : '/media/hostfw/running-ro/',
+ description : 'Base path to the devtree file read only version'
)
option('CEC_INFODB_PATH', type : 'string',
value : '/usr/share/pdata/attributes_info.db',
diff --git a/procedures/phal/reinit_devtree.cpp b/procedures/phal/reinit_devtree.cpp
index 6451c92..60e6e49 100644
--- a/procedures/phal/reinit_devtree.cpp
+++ b/procedures/phal/reinit_devtree.cpp
@@ -53,6 +53,39 @@
}
/**
+ * @brief Compute RO device tree file path from RW symbolic link
+ * @return RO file path one failure exception will be thrown
+ */
+fs::path computeRODeviceTreePath()
+{
+ // Symbolic links are not created for RO files, compute the lid name
+ // for the RW symbolic link and use it to compute RO file.
+ // Example:
+ // RW file = /media/hostfw/running/DEVTREE -> 81e00672.lid
+ // RO file = /media/hostfw/running-ro/ + 81e00672.lid
+ fs::path rwFileName = fs::read_symlink(CEC_DEVTREE_RW_PATH);
+ if (rwFileName.empty())
+ {
+ std::string err =
+ fmt::format("Failed to read the target file "
+ "for the RW device tree symbolic link ({})",
+ CEC_DEVTREE_RW_PATH);
+ log<level::ERR>(err.c_str());
+ throw std::runtime_error(err);
+ }
+ fs::path roFilePath = CEC_DEVTREE_RO_BASE_PATH / rwFileName;
+ if (!fs::exists(roFilePath))
+ {
+ auto err = fmt::format("RO device tree file ({}) does not "
+ "exit ",
+ roFilePath.string());
+ log<level::ERR>(err.c_str());
+ throw std::runtime_error(err);
+ }
+ return roFilePath;
+}
+
+/**
* @brief reinitialize the devtree attributes.
* In the regular host boot path devtree attribute need to
* initialize the default data and also some of the selected
@@ -135,7 +168,8 @@
}
// Step 2: Create temporary devtree file by copying devtree r/o version
- std::filesystem::copy(CEC_DEVTREE_RO_PATH, tmpDevtreePath, copyOptions);
+ fs::path roFilePath = computeRODeviceTreePath();
+ std::filesystem::copy(roFilePath, tmpDevtreePath, copyOptions);
// get r/o version data file pointer
FILE_Ptr fpImport(fopen(tmpFile.getPath().c_str(), "r"), fclose);
@@ -196,10 +230,10 @@
else
{
// Attempt boot with genesis mode attribute data.
+ fs::path roFilePath = computeRODeviceTreePath();
log<level::WARNING>("reinitDevtree: DEVTREE(r/w) initilizing with "
"genesis mode attribute data");
- std::filesystem::copy(CEC_DEVTREE_RO_PATH, CEC_DEVTREE_RW_PATH,
- copyOptions);
+ std::filesystem::copy(roFilePath, CEC_DEVTREE_RW_PATH, copyOptions);
}
}
catch (const std::exception& e)