blob: eb7fa0858a0eaa643f45e3a6c3dad39cf9a2f453 [file] [log] [blame]
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -05001/********************************************************************************
2* HON HAI Precision IND.Co., LTD. *
3* Personal Computer & Enterprise Product Business Group *
4* Enterprise Product Business Gro:qup *
5* *
6* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
7* All data and information contained in this document is confidential *
8* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
9* are reserved. By accepting this material the recipient agrees that *
10* the information contained therein is held in confidence and in trust *
11* and will not be used, copied, reproduced in whole or in part, nor its *
12* contents revealed in any manner to others without the express written *
13* permission of FOXCONN/CESBG/CABG/SRD. *
14* *
15********************************************************************************/
16
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050017#include <ipmid/api.hpp>
18#include <phosphor-logging/log.hpp>
19#include <sdbusplus/message/types.hpp>
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050020#include <bioscommands.hpp>
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050021#include <boost/endian/arithmetic.hpp>
22#include <file_handling.hpp>
23
24struct bios_boot_count
25{
26 uint32_t header;
27 uint32_t count;
28};
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050029
30namespace ipmi
31{
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050032static void registerBIOSFunctions() __attribute__((constructor));
33ipmi::RspType<uint32_t> FiiBIOSBootCount(boost::asio::yield_context yield,
34 std::vector<uint8_t> reqParams)
35{
36 int boot_count_operation;
37 bios_boot_count boot;
38 if (reqParams.empty())
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050039 {
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050040 phosphor::logging::log<phosphor::logging::level::ERR>(
41 " Fii bios cmd : command format error.");
42 return ipmi::responseReqDataLenInvalid();
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050043 }
44
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050045 boot_count_operation = reqParams[0];
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050046
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050047 if((boot_count_operation == BOOT_COUNT_SET &&
48 reqParams.size() != SET_BYTE_LENGTH) ||
49 (boot_count_operation != BOOT_COUNT_SET &&
50 reqParams.size() != OPERATION_BYTE_LENGTH))
51 {
52 return ipmi::responseReqDataLenInvalid();
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -050053 }
Avenash Asai Thambida2cf0d2021-08-26 15:51:47 -050054
55 if(boot_count_operation > BOOT_COUNT_SET)
56 {
57 return ipmi::responseInvalidCommand();
58 }
59
60 int fd = sysopen(EEPROM_PATH);
61 readBin(fd, EEPROM_OFFSET, &boot, sizeof(boot));
62
63 if(boot.header != BOOT_COUNT_HEADER)
64 {
65 phosphor::logging::log<phosphor::logging::level::INFO>(
66 "Boot count header is corrupted or missing. Initializing.");
67 boot.header = BOOT_COUNT_HEADER;
68 boot.count = INITIAL_VALUE;
69 writeBin(fd, EEPROM_OFFSET, &boot, sizeof(boot));
70 }
71
72 switch(boot_count_operation)
73 {
74 case BOOT_COUNT_READ:
75 break;
76 case BOOT_COUNT_INCREMENT:
77 boot.count = boot.count + 1;
78 break;
79 case BOOT_COUNT_CLEAR:
80 boot.count = INITIAL_VALUE;
81 break;
82 case BOOT_COUNT_SET:
83 memcpy(&boot.count, &reqParams[1], sizeof(boot.count));
84 break;
85 }
86
87 if( boot_count_operation != BOOT_COUNT_READ )
88 {
89 writeBin(fd, EEPROM_OFFSET + 4, &boot.count, sizeof(boot.count));
90 }
91 sysclose(fd);
92 return ipmi::responseSuccess(boot.count);
93}
94
95void registerBIOSFunctions()
96{
97 std::fprintf(stderr, "Registering OEM:[0x34], Cmd:[%#04X] for Fii BIOS OEM Commands\n",
98 FII_CMD_BIOS_BOOT_COUNT);
99 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree, FII_CMD_BIOS_BOOT_COUNT,
100 ipmi::Privilege::User, FiiBIOSBootCount);
101}
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -0500102}