blob: 0d7f2ef230a586e8a60dceffc31379cd705d34a1 [file] [log] [blame]
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +05301/*
2 * Copyright (c) 2018-present Facebook. All Rights Reserved.
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
Patrick Williamsf863a182022-06-16 16:17:28 -050017#include <ipmid/api.h>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053018#include <stdbool.h>
19#include <stdio.h>
20#include <sys/stat.h>
21
22#include <appcommands.hpp>
23#include <ipmid/api.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050024#include <ipmid/utils.hpp>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053025#include <nlohmann/json.hpp>
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053026#include <phosphor-logging/lg2.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050027#include <phosphor-logging/log.hpp>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053028#include <sdbusplus/asio/connection.hpp>
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +053029#include <sdbusplus/asio/property.hpp>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053030
31#include <fstream>
32#include <iomanip>
33#include <iostream>
34#include <sstream>
35
36namespace ipmi
37{
38
Patrick Williams13ce3792024-08-27 13:03:46 -040039static constexpr bool DEBUG = false;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053040
Patrick Williams13ce3792024-08-27 13:03:46 -040041static constexpr auto JSON_POST_DATA_FILE =
42 "/usr/share/lcd-debug/post_desc.json";
43static constexpr auto JSON_GPIO_DATA_FILE =
44 "/usr/share/lcd-debug/gpio_desc.json";
45static constexpr auto JSON_SENSOR_NAMES_FILE =
46 "/usr/share/lcd-debug/cri_sensors.json";
47
48static constexpr auto ETH_INTF_NAME = "eth0";
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053049
50#define ESCAPE "\x1B"
51#define ESC_BAT ESCAPE "B"
52#define ESC_MCU_BL_VER ESCAPE "U"
53#define ESC_MCU_RUN_VER ESCAPE "R"
54#define ESC_ALT ESCAPE "[5;7m"
55#define ESC_RST ESCAPE "[m"
56
Patrick Williams13ce3792024-08-27 13:03:46 -040057static constexpr char LINE_DELIMITER = '\x1F';
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053058
Patrick Williams13ce3792024-08-27 13:03:46 -040059static constexpr size_t FRAME_BUFF_SIZE = 4096;
60static constexpr size_t FRAME_PAGE_BUF_SIZE = 256;
61
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053062#define FRU_ALL 0
Liora Guo4006fe72025-08-19 15:21:24 +080063#define BOOT_POSTCODE_SERVICE "xyz.openbmc_project.State.Boot.PostCode"
64#define BOOT_POSTCODE_OBJECTPATH "/xyz/openbmc_project/State/Boot/PostCode"
65#define BOOT_POSTCODE_INTERFACE "xyz.openbmc_project.State.Boot.PostCode"
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053066
Patrick Williams13ce3792024-08-27 13:03:46 -040067static constexpr auto DEBUG_GPIO_KEY = "GpioDesc";
68static constexpr auto GPIO_ARRAY_SIZE = 4;
69static constexpr auto GPIO_PIN_INDEX = 0;
70static constexpr auto GPIO_LEVEL_INDEX = 1;
71static constexpr auto GPIO_DEF_INDEX = 2;
72static constexpr auto GPIO_DESC_INDEX = 3;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053073
Patrick Williams13ce3792024-08-27 13:03:46 -040074static constexpr size_t BMC_POSITION = 0;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053075
Patrick Williams13ce3792024-08-27 13:03:46 -040076static constexpr uint8_t meAddress = 1;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053077static constexpr uint8_t lun = 0;
78
79using IpmbMethodType =
80 std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>;
81
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053082struct frame
83{
84 char title[32];
85 size_t max_size;
86 size_t max_page;
87 char* buf;
Patrick Williams13ce3792024-08-27 13:03:46 -040088 size_t idx_head, idx_tail;
89 size_t line_per_page;
90 size_t line_width;
91 size_t lines, pages;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053092 uint8_t esc_sts;
Patrick Williams13ce3792024-08-27 13:03:46 -040093 bool overwrite;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053094 time_t mtime;
Patrick Williams13ce3792024-08-27 13:03:46 -040095
96 frame() : buf(nullptr), pages(0), mtime(0) {}
97
98 void init(size_t size = FRAME_BUFF_SIZE);
99 void append(const std::string& str, size_t indent = 0);
100 int getPage(size_t page, char* page_buf, size_t page_buf_size);
101 bool isFull() const;
102 bool isEscSeq(char chr);
103
104 private:
105 auto parse(const std::string& input, size_t indent) -> std::string;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530106};
107
Patrick Williams13ce3792024-08-27 13:03:46 -0400108frame frame_info;
109frame frame_sel;
110frame frame_snr;
111frame frame_postcode;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530112
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400113enum class panel : uint8_t
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530114{
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400115 NONE = 0,
116 MAIN = 1,
117 BOOT_ORDER = 2,
118 POWER_POLICY = 3,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530119};
120
121struct ctrl_panel
122{
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400123 panel parent;
124 size_t item_num;
125 std::array<std::string, 8> item_str;
126 panel (*select)(size_t item);
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530127};
128
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400129static panel panel_main(size_t item);
130static panel panel_boot_order(size_t item);
131static panel panel_power_policy(size_t item);
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530132
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400133static ctrl_panel panels[] = {
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530134 {/* dummy entry for making other to 1-based */},
135 {
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400136 .parent = panel::MAIN,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530137 .item_num = 2,
138 .item_str =
139 {
140 "User Setting",
141 ">Boot Order",
142 ">Power Policy",
143 },
144 .select = panel_main,
145 },
146 {
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400147 .parent = panel::MAIN,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530148 .item_num = 0,
149 .item_str =
150 {
151 "Boot Order",
152 },
153 .select = panel_boot_order,
154 },
155 {
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400156 .parent = panel::MAIN,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530157 .item_num = 0,
158 .item_str =
159 {
160 "Power Policy",
161 },
162 .select = panel_power_policy,
163 },
164};
165
166} // end of namespace ipmi