blob: 8cf307e33f200837c868c95f9743b76628adcdd6 [file] [log] [blame]
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * (C) Copyright 2019 - 2020 Xilinx, Inc.
4 */
5
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +05306#include <command.h>
7#include <fdtdec.h>
8#include <malloc.h>
9
10#include "fru.h"
11
12static int do_fru_capture(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
14{
15 unsigned long addr;
16 char *endp;
17
18 if (argc < cmdtp->maxargs)
19 return CMD_RET_USAGE;
20
Simon Glass3ff49ec2021-07-24 09:03:29 -060021 addr = hextoul(argv[2], &endp);
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +053022 if (*argv[1] == 0 || *endp != 0)
23 return -1;
24
25 return fru_capture(addr);
26}
27
28static int do_fru_display(struct cmd_tbl *cmdtp, int flag, int argc,
29 char *const argv[])
30{
31 fru_display(1);
32 return CMD_RET_SUCCESS;
33}
34
Michal Simekd5c33212019-04-15 13:54:09 +020035static int do_fru_generate(struct cmd_tbl *cmdtp, int flag, int argc,
36 char *const argv[])
37{
38 unsigned long addr;
39
40 if (argc < cmdtp->maxargs)
41 return CMD_RET_USAGE;
42
Simon Glass3ff49ec2021-07-24 09:03:29 -060043 addr = hextoul(argv[2], NULL);
Michal Simekd5c33212019-04-15 13:54:09 +020044
45 return fru_generate(addr, argv[3], argv[4], argv[5], argv[6], argv[7]);
46}
47
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +053048static struct cmd_tbl cmd_fru_sub[] = {
49 U_BOOT_CMD_MKENT(capture, 3, 0, do_fru_capture, "", ""),
50 U_BOOT_CMD_MKENT(display, 2, 0, do_fru_display, "", ""),
Michal Simekd5c33212019-04-15 13:54:09 +020051 U_BOOT_CMD_MKENT(board_gen, 8, 0, do_fru_generate, "", ""),
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +053052};
53
54static int do_fru(struct cmd_tbl *cmdtp, int flag, int argc,
55 char *const argv[])
56{
57 struct cmd_tbl *c;
58 int ret;
59
60 if (argc < 2)
61 return CMD_RET_USAGE;
62
63 c = find_cmd_tbl(argv[1], &cmd_fru_sub[0],
64 ARRAY_SIZE(cmd_fru_sub));
65 if (!c)
66 return CMD_RET_USAGE;
67
68 ret = c->cmd(c, flag, argc, argv);
69
70 return cmd_process_error(c, ret);
71}
72
73/***************************************************/
Tom Rini03f146c2023-10-07 15:13:08 -040074U_BOOT_LONGHELP(fru,
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +053075 "capture <addr> - Parse and capture FRU table present at address.\n"
76 "fru display - Displays content of FRU table that was captured using\n"
77 " fru capture command\n"
Michal Simekd5c33212019-04-15 13:54:09 +020078 "fru board_gen <addr> <manufacturer> <board name> <serial number>\n"
79 " <part number> <revision> - Generate FRU format with\n"
80 " board info area filled based on parameters. <addr> is\n"
Tom Rini03f146c2023-10-07 15:13:08 -040081 " pointing to place where FRU is generated.\n");
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +053082
83U_BOOT_CMD(
Michal Simekd5c33212019-04-15 13:54:09 +020084 fru, 8, 1, do_fru,
Siva Durga Prasad Paladugu7177d022019-04-10 12:38:10 +053085 "FRU table info",
86 fru_help_text
Simon Glass761d6022023-11-18 14:04:52 -070087);