Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 1 | /******************************************************************************** |
| 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 Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame^] | 17 | #include <ipmid/api.hpp> |
| 18 | #include <phosphor-logging/log.hpp> |
| 19 | #include <sdbusplus/message/types.hpp> |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 20 | #include <bioscommands.hpp> |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame^] | 21 | #include <boost/endian/arithmetic.hpp> |
| 22 | #include <file_handling.hpp> |
| 23 | |
| 24 | struct bios_boot_count |
| 25 | { |
| 26 | uint32_t header; |
| 27 | uint32_t count; |
| 28 | }; |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 29 | |
| 30 | namespace ipmi |
| 31 | { |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame^] | 32 | static void registerBIOSFunctions() __attribute__((constructor)); |
| 33 | ipmi::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 Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 39 | { |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame^] | 40 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 41 | " Fii bios cmd : command format error."); |
| 42 | return ipmi::responseReqDataLenInvalid(); |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame^] | 45 | boot_count_operation = reqParams[0]; |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 46 | |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame^] | 47 | 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 Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 53 | } |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame^] | 54 | |
| 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 | |
| 95 | void 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 Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 102 | } |