Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * (C) Copyright 2019 - 2020 Xilinx, Inc. |
| 4 | */ |
| 5 | |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 6 | #include <command.h> |
| 7 | #include <fdtdec.h> |
| 8 | #include <malloc.h> |
| 9 | |
| 10 | #include "fru.h" |
| 11 | |
| 12 | static 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 Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 21 | addr = hextoul(argv[2], &endp); |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 22 | if (*argv[1] == 0 || *endp != 0) |
| 23 | return -1; |
| 24 | |
| 25 | return fru_capture(addr); |
| 26 | } |
| 27 | |
| 28 | static 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 Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 35 | static 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 Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 43 | addr = hextoul(argv[2], NULL); |
Michal Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 44 | |
| 45 | return fru_generate(addr, argv[3], argv[4], argv[5], argv[6], argv[7]); |
| 46 | } |
| 47 | |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 48 | static 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 Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 51 | U_BOOT_CMD_MKENT(board_gen, 8, 0, do_fru_generate, "", ""), |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static 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 Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 74 | U_BOOT_LONGHELP(fru, |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 75 | "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 Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 78 | "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 Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 81 | " pointing to place where FRU is generated.\n"); |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 82 | |
| 83 | U_BOOT_CMD( |
Michal Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 84 | fru, 8, 1, do_fru, |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 85 | "FRU table info", |
| 86 | fru_help_text |
Simon Glass | 761d602 | 2023-11-18 14:04:52 -0700 | [diff] [blame] | 87 | ); |