blob: 03c27fb43a62ba53c4e54c421e4a924cc9bf37ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
From d629bf86a9ac970d8c0505c0aa2488373c9df102 Mon Sep 17 00:00:00 2001
From: Wiktor Golgowski <wiktor.golgowski@linux.intel.com>
Date: Thu, 30 Apr 2020 11:09:35 +0200
Subject: [PATCH] Use chip id-based UUID for Service Root.
If the sysfs-provided chip id is available, it will be used as
payload to generate Service Root UUID from hardcoded namespace.
Tested:
Generated UUID is consistent between BMC image reflashes.
If the sysfs node is not available, code falls back to randomly
generated UUID.
Signed-off-by: Wiktor Gołgowski <wiktor.golgowski@linux.intel.com>
---
include/persistent_data_middleware.hpp | 32 +++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/include/persistent_data_middleware.hpp b/include/persistent_data_middleware.hpp
index 348079b..925e7b6 100644
--- a/include/persistent_data_middleware.hpp
+++ b/include/persistent_data_middleware.hpp
@@ -30,6 +30,10 @@ class Middleware
public:
// todo(ed) should read this from a fixed location somewhere, not CWD
static constexpr const char* filename = "bmcweb_persistent_data.json";
+ static constexpr const char* chipIdSysfsNode = "/sys/devices/platform"
+ "/ahb/ahb:apb/1e6e2000.syscon/1e6e2000.syscon:misc_control/chip_id";
+ static constexpr const char* UuidNs = "{b7b0553a-54cc-4162-982d-"
+ "944847ed76f5}";
struct Context
{
@@ -143,9 +147,31 @@ class Middleware
if (systemUuid.empty())
{
- systemUuid =
- boost::uuids::to_string(boost::uuids::random_generator()());
- needWrite = true;
+ // Try to retrieve chip id-based uuid.
+ std::ifstream chipIdFile(chipIdSysfsNode);
+ if (chipIdFile.is_open())
+ {
+ std::string chipId;
+ std::getline(chipIdFile, chipId);
+ if (!chipId.empty())
+ {
+ boost::uuids::name_generator_sha1 gen(
+ boost::uuids::string_generator()(UuidNs));
+ systemUuid = boost::uuids::to_string(gen(chipId.c_str()));
+ needWrite = true;
+ }
+ else
+ {
+ BMCWEB_LOG_ERROR << "Cannot get chip id-based System UUID.";
+ }
+ }
+ // If the above fails, generate random uuid.
+ if (systemUuid.empty())
+ {
+ systemUuid =
+ boost::uuids::to_string(boost::uuids::random_generator()());
+ needWrite = true;
+ }
}
if (fileRevision < jsonRevision)
{
--
2.20.1
|