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 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | #include <fdtdec.h> |
| 9 | #include <malloc.h> |
| 10 | |
| 11 | #include "fru.h" |
| 12 | |
| 13 | static int do_fru_capture(struct cmd_tbl *cmdtp, int flag, int argc, |
| 14 | char *const argv[]) |
| 15 | { |
| 16 | unsigned long addr; |
| 17 | char *endp; |
| 18 | |
| 19 | if (argc < cmdtp->maxargs) |
| 20 | return CMD_RET_USAGE; |
| 21 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 22 | addr = hextoul(argv[2], &endp); |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 23 | if (*argv[1] == 0 || *endp != 0) |
| 24 | return -1; |
| 25 | |
| 26 | return fru_capture(addr); |
| 27 | } |
| 28 | |
| 29 | static int do_fru_display(struct cmd_tbl *cmdtp, int flag, int argc, |
| 30 | char *const argv[]) |
| 31 | { |
| 32 | fru_display(1); |
| 33 | return CMD_RET_SUCCESS; |
| 34 | } |
| 35 | |
Michal Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 36 | static int do_fru_generate(struct cmd_tbl *cmdtp, int flag, int argc, |
| 37 | char *const argv[]) |
| 38 | { |
| 39 | unsigned long addr; |
| 40 | |
| 41 | if (argc < cmdtp->maxargs) |
| 42 | return CMD_RET_USAGE; |
| 43 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 44 | addr = hextoul(argv[2], NULL); |
Michal Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 45 | |
| 46 | return fru_generate(addr, argv[3], argv[4], argv[5], argv[6], argv[7]); |
| 47 | } |
| 48 | |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 49 | static struct cmd_tbl cmd_fru_sub[] = { |
| 50 | U_BOOT_CMD_MKENT(capture, 3, 0, do_fru_capture, "", ""), |
| 51 | U_BOOT_CMD_MKENT(display, 2, 0, do_fru_display, "", ""), |
Michal Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 52 | 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] | 53 | }; |
| 54 | |
| 55 | static int do_fru(struct cmd_tbl *cmdtp, int flag, int argc, |
| 56 | char *const argv[]) |
| 57 | { |
| 58 | struct cmd_tbl *c; |
| 59 | int ret; |
| 60 | |
| 61 | if (argc < 2) |
| 62 | return CMD_RET_USAGE; |
| 63 | |
| 64 | c = find_cmd_tbl(argv[1], &cmd_fru_sub[0], |
| 65 | ARRAY_SIZE(cmd_fru_sub)); |
| 66 | if (!c) |
| 67 | return CMD_RET_USAGE; |
| 68 | |
| 69 | ret = c->cmd(c, flag, argc, argv); |
| 70 | |
| 71 | return cmd_process_error(c, ret); |
| 72 | } |
| 73 | |
| 74 | /***************************************************/ |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 75 | U_BOOT_LONGHELP(fru, |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 76 | "capture <addr> - Parse and capture FRU table present at address.\n" |
| 77 | "fru display - Displays content of FRU table that was captured using\n" |
| 78 | " fru capture command\n" |
Michal Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 79 | "fru board_gen <addr> <manufacturer> <board name> <serial number>\n" |
| 80 | " <part number> <revision> - Generate FRU format with\n" |
| 81 | " board info area filled based on parameters. <addr> is\n" |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 82 | " pointing to place where FRU is generated.\n"); |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 83 | |
| 84 | U_BOOT_CMD( |
Michal Simek | d5c3321 | 2019-04-15 13:54:09 +0200 | [diff] [blame] | 85 | fru, 8, 1, do_fru, |
Siva Durga Prasad Paladugu | 7177d02 | 2019-04-10 12:38:10 +0530 | [diff] [blame] | 86 | "FRU table info", |
| 87 | fru_help_text |
Simon Glass | 761d602 | 2023-11-18 14:04:52 -0700 | [diff] [blame] | 88 | ); |