Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "system.hpp" |
| 18 | |
| 19 | #include "mdrv2.hpp" |
| 20 | |
Kuiying Wang | 26de0d7 | 2020-11-18 19:31:46 +0800 | [diff] [blame] | 21 | #include <fstream> |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 22 | #include <iomanip> |
| 23 | #include <iostream> |
| 24 | #include <sstream> |
| 25 | namespace phosphor |
| 26 | { |
| 27 | namespace smbios |
| 28 | { |
| 29 | |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 30 | std::string System::uuid(std::string value) |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 31 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 32 | uint8_t* dataIn = storage; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 33 | dataIn = getSMBIOSTypePtr(dataIn, systemType); |
| 34 | if (dataIn != nullptr) |
| 35 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 36 | auto systemInfo = reinterpret_cast<struct SystemInfo*>(dataIn); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 37 | std::stringstream stream; |
| 38 | stream << std::setfill('0') << std::hex; |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 39 | stream << std::setw(8) << systemInfo->uuid.timeLow; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 40 | stream << "-"; |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 41 | stream << std::setw(4) << systemInfo->uuid.timeMid; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 42 | stream << "-"; |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 43 | stream << std::setw(4) << systemInfo->uuid.timeHiAndVer; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 44 | stream << "-"; |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 45 | stream << std::setw(2) << static_cast<int>(systemInfo->uuid.clockSeqHi); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 46 | stream << std::setw(2) |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 47 | << static_cast<int>(systemInfo->uuid.clockSeqLow); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 48 | stream << "-"; |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 49 | static_assert(sizeof(systemInfo->uuid.node) == 6); |
| 50 | stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[0]); |
| 51 | stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[1]); |
| 52 | stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[2]); |
| 53 | stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[3]); |
| 54 | stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[4]); |
| 55 | stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[5]); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 56 | |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 57 | return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid( |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 58 | stream.str()); |
| 59 | } |
| 60 | |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 61 | return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid( |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 62 | "00000000-0000-0000-0000-000000000000"); |
| 63 | } |
| 64 | |
| 65 | std::string System::version(std::string value) |
| 66 | { |
| 67 | std::string result = "No BIOS Version"; |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 68 | uint8_t* dataIn = storage; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 69 | dataIn = getSMBIOSTypePtr(dataIn, biosType); |
| 70 | if (dataIn != nullptr) |
| 71 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 72 | auto biosInfo = reinterpret_cast<struct BIOSInfo*>(dataIn); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 73 | uint8_t biosVerByte = biosInfo->biosVersion; |
| 74 | std::string tempS = |
| 75 | positionToString(biosInfo->biosVersion, biosInfo->length, dataIn); |
Kuiying Wang | 26de0d7 | 2020-11-18 19:31:46 +0800 | [diff] [blame] | 76 | if (std::find_if(tempS.begin(), tempS.end(), |
| 77 | [](char ch) { return !isprint(ch); }) != tempS.end()) |
| 78 | { |
| 79 | std::ofstream smbiosFile(mdrType2File, std::ios_base::trunc); |
| 80 | if (!smbiosFile.good()) |
| 81 | { |
| 82 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 83 | "Open MDRV2 table file failure"); |
| 84 | return result; |
| 85 | } |
| 86 | smbiosFile.clear(); |
| 87 | smbiosFile.close(); |
| 88 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 89 | "Find non-print char, delete the broken MDRV2 table file!"); |
| 90 | return sdbusplus::xyz::openbmc_project::Inventory::Decorator:: |
| 91 | server::Revision::version(result); |
| 92 | } |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 93 | result = tempS; |
| 94 | } |
Alex Schendel | 5f2d627 | 2021-09-22 10:35:40 -0700 | [diff] [blame] | 95 | lg2::info("VERSION INFO - BIOS - {VER}", "VER", result); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 96 | return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server:: |
| 97 | Revision::version(result); |
| 98 | } |
| 99 | |
| 100 | } // namespace smbios |
| 101 | } // namespace phosphor |