Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 1 | // clang-format off |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 2 | /******************************************************************************** |
| 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 Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 17 | // clang-format on |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 18 | |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 19 | #include <bioscommands.hpp> |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 20 | #include <boost/endian/arithmetic.hpp> |
| 21 | #include <file_handling.hpp> |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 22 | #include <ipmid/api.hpp> |
| 23 | #include <phosphor-logging/log.hpp> |
| 24 | #include <sdbusplus/message/types.hpp> |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 25 | |
| 26 | struct bios_boot_count |
| 27 | { |
| 28 | uint32_t header; |
| 29 | uint32_t count; |
| 30 | }; |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 31 | |
| 32 | namespace ipmi |
| 33 | { |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 34 | static void registerBIOSFunctions() __attribute__((constructor)); |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 35 | ipmi::RspType<uint32_t> |
| 36 | FiiBIOSBootCount([[maybe_unused]] boost::asio::yield_context yield, |
| 37 | std::vector<uint8_t> reqParams) |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 38 | { |
| 39 | int boot_count_operation; |
| 40 | bios_boot_count boot; |
| 41 | if (reqParams.empty()) |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 42 | { |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 43 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 44 | " Fii bios cmd : command format error."); |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 45 | return ipmi::responseReqDataLenInvalid(); |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 48 | boot_count_operation = reqParams[0]; |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 49 | |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 50 | if ((boot_count_operation == BOOT_COUNT_SET && |
| 51 | reqParams.size() != SET_BYTE_LENGTH) || |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 52 | (boot_count_operation != BOOT_COUNT_SET && |
| 53 | reqParams.size() != OPERATION_BYTE_LENGTH)) |
| 54 | { |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 55 | return ipmi::responseReqDataLenInvalid(); |
Mohaimen Alsamarai | 35c1ac4 | 2021-04-20 13:16:42 -0500 | [diff] [blame] | 56 | } |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 57 | |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 58 | if (boot_count_operation > BOOT_COUNT_SET) |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 59 | { |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 60 | return ipmi::responseInvalidCommand(); |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | int fd = sysopen(EEPROM_PATH); |
| 64 | readBin(fd, EEPROM_OFFSET, &boot, sizeof(boot)); |
| 65 | |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 66 | if (boot.header != BOOT_COUNT_HEADER) |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 67 | { |
| 68 | phosphor::logging::log<phosphor::logging::level::INFO>( |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 69 | "Boot count header is corrupted or missing. Initializing."); |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 70 | boot.header = BOOT_COUNT_HEADER; |
| 71 | boot.count = INITIAL_VALUE; |
| 72 | writeBin(fd, EEPROM_OFFSET, &boot, sizeof(boot)); |
| 73 | } |
| 74 | |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 75 | switch (boot_count_operation) |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 76 | { |
| 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 Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 90 | if (boot_count_operation != BOOT_COUNT_READ) |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 91 | { |
| 92 | writeBin(fd, EEPROM_OFFSET + 4, &boot.count, sizeof(boot.count)); |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 93 | } |
Avenash Asai Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 94 | sysclose(fd); |
| 95 | return ipmi::responseSuccess(boot.count); |
| 96 | } |
| 97 | |
| 98 | void registerBIOSFunctions() |
| 99 | { |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 100 | 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 Thambi | da2cf0d | 2021-08-26 15:51:47 -0500 | [diff] [blame] | 107 | } |
Willy Tu | 4055324 | 2022-11-14 09:27:39 -0800 | [diff] [blame] | 108 | } // namespace ipmi |