blob: 361b809698a0ec0fb24728e8a8931d02d6796e9f [file] [log] [blame]
Willy Tu40553242022-11-14 09:27:39 -08001// clang-format off
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -05002/********************************************************************************
3* HON HAI Precision IND.Co., LTD. *
4* Personal Computer & Enterprise Product Business Group *
5* Enterprise Product Business Gro:qup *
6* *
7* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
8* All data and information contained in this document is confidential *
9* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
10* are reserved. By accepting this material the recipient agrees that *
11* the information contained therein is held in confidence and in trust *
12* and will not be used, copied, reproduced in whole or in part, nor its *
13* contents revealed in any manner to others without the express written *
14* permission of FOXCONN/CESBG/CABG/SRD. *
15* *
16********************************************************************************/
Willy Tu40553242022-11-14 09:27:39 -080017// clang-format on
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050018
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050019#include <bioscommands.hpp>
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050020#include <boost/endian/arithmetic.hpp>
21#include <file_handling.hpp>
Willy Tu40553242022-11-14 09:27:39 -080022#include <ipmid/api.hpp>
23#include <phosphor-logging/log.hpp>
24#include <sdbusplus/message/types.hpp>
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050025
26struct bios_boot_count
27{
28 uint32_t header;
29 uint32_t count;
30};
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050031
32namespace ipmi
33{
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050034static void registerBIOSFunctions() __attribute__((constructor));
Willy Tu40553242022-11-14 09:27:39 -080035ipmi::RspType<uint32_t>
36 FiiBIOSBootCount([[maybe_unused]] boost::asio::yield_context yield,
37 std::vector<uint8_t> reqParams)
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050038{
39 int boot_count_operation;
40 bios_boot_count boot;
41 if (reqParams.empty())
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050042 {
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050043 phosphor::logging::log<phosphor::logging::level::ERR>(
Willy Tu40553242022-11-14 09:27:39 -080044 " Fii bios cmd : command format error.");
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050045 return ipmi::responseReqDataLenInvalid();
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050046 }
47
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050048 boot_count_operation = reqParams[0];
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050049
Willy Tu40553242022-11-14 09:27:39 -080050 if ((boot_count_operation == BOOT_COUNT_SET &&
51 reqParams.size() != SET_BYTE_LENGTH) ||
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050052 (boot_count_operation != BOOT_COUNT_SET &&
53 reqParams.size() != OPERATION_BYTE_LENGTH))
54 {
Willy Tu40553242022-11-14 09:27:39 -080055 return ipmi::responseReqDataLenInvalid();
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050056 }
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050057
Willy Tu40553242022-11-14 09:27:39 -080058 if (boot_count_operation > BOOT_COUNT_SET)
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050059 {
Willy Tu40553242022-11-14 09:27:39 -080060 return ipmi::responseInvalidCommand();
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050061 }
62
63 int fd = sysopen(EEPROM_PATH);
64 readBin(fd, EEPROM_OFFSET, &boot, sizeof(boot));
65
Willy Tu40553242022-11-14 09:27:39 -080066 if (boot.header != BOOT_COUNT_HEADER)
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050067 {
68 phosphor::logging::log<phosphor::logging::level::INFO>(
Willy Tu40553242022-11-14 09:27:39 -080069 "Boot count header is corrupted or missing. Initializing.");
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050070 boot.header = BOOT_COUNT_HEADER;
71 boot.count = INITIAL_VALUE;
72 writeBin(fd, EEPROM_OFFSET, &boot, sizeof(boot));
73 }
74
Willy Tu40553242022-11-14 09:27:39 -080075 switch (boot_count_operation)
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050076 {
77 case BOOT_COUNT_READ:
78 break;
79 case BOOT_COUNT_INCREMENT:
80 boot.count = boot.count + 1;
81 break;
82 case BOOT_COUNT_CLEAR:
83 boot.count = INITIAL_VALUE;
84 break;
85 case BOOT_COUNT_SET:
86 memcpy(&boot.count, &reqParams[1], sizeof(boot.count));
87 break;
88 }
89
Willy Tu40553242022-11-14 09:27:39 -080090 if (boot_count_operation != BOOT_COUNT_READ)
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050091 {
92 writeBin(fd, EEPROM_OFFSET + 4, &boot.count, sizeof(boot.count));
Willy Tu40553242022-11-14 09:27:39 -080093 }
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050094 sysclose(fd);
95 return ipmi::responseSuccess(boot.count);
96}
97
98void registerBIOSFunctions()
99{
Willy Tu40553242022-11-14 09:27:39 -0800100 std::fprintf(
101 stderr,
102 "Registering OEM:[0x34], Cmd:[%#04X] for Fii BIOS OEM Commands\n",
103 FII_CMD_BIOS_BOOT_COUNT);
104 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree,
105 FII_CMD_BIOS_BOOT_COUNT, ipmi::Privilege::User,
106 FiiBIOSBootCount);
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -0500107}
Willy Tu40553242022-11-14 09:27:39 -0800108} // namespace ipmi