Merge tag 'xilinx-for-v2025.01-rc3-v2' of https://source.denx.de/u-boot/custodians...
[u-boot.git] / cmd / bootstage.c
blob8248c41ca8262e1d11196a89472474f5894bd5d7
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 2012, Google Inc. All rights reserved.
4 */
6 #include <bootstage.h>
7 #include <command.h>
8 #include <vsprintf.h>
10 static int do_bootstage_report(struct cmd_tbl *cmdtp, int flag, int argc,
11 char *const argv[])
13 bootstage_report();
15 return 0;
18 #if IS_ENABLED(CONFIG_BOOTSTAGE_STASH)
19 static int get_base_size(int argc, char *const argv[], ulong *basep,
20 ulong *sizep)
22 char *endp;
24 *basep = CONFIG_BOOTSTAGE_STASH_ADDR;
25 *sizep = CONFIG_BOOTSTAGE_STASH_SIZE;
26 if (argc < 2)
27 return 0;
28 *basep = hextoul(argv[1], &endp);
29 if (*argv[1] == 0 || *endp != 0)
30 return -1;
31 if (argc == 2)
32 return 0;
33 *sizep = hextoul(argv[2], &endp);
34 if (*argv[2] == 0 || *endp != 0)
35 return -1;
37 return 0;
40 static int do_bootstage_stash(struct cmd_tbl *cmdtp, int flag, int argc,
41 char *const argv[])
43 ulong base, size;
44 int ret;
46 if (get_base_size(argc, argv, &base, &size))
47 return CMD_RET_USAGE;
48 if (base == -1UL) {
49 printf("No bootstage stash area defined\n");
50 return 1;
53 if (0 == strcmp(argv[0], "stash"))
54 ret = bootstage_stash((void *)base, size);
55 else
56 ret = bootstage_unstash((void *)base, size);
57 if (ret)
58 return 1;
60 return 0;
62 #endif
64 static struct cmd_tbl cmd_bootstage_sub[] = {
65 U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""),
66 #if IS_ENABLED(CONFIG_BOOTSTAGE_STASH)
67 U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""),
68 U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""),
69 #endif
73 * Process a bootstage sub-command
75 static int do_boostage(struct cmd_tbl *cmdtp, int flag, int argc,
76 char *const argv[])
78 struct cmd_tbl *c;
80 /* Strip off leading 'bootstage' command argument */
81 argc--;
82 argv++;
84 c = find_cmd_tbl(argv[0], cmd_bootstage_sub,
85 ARRAY_SIZE(cmd_bootstage_sub));
87 if (c)
88 return c->cmd(cmdtp, flag, argc, argv);
89 else
90 return CMD_RET_USAGE;
93 U_BOOT_CMD(bootstage, 4, 1, do_boostage,
94 "Boot stage command",
95 " - check boot progress and timing\n"
96 "report - Print a report\n"
97 #if IS_ENABLED(CONFIG_BOOTSTAGE_STASH)
98 "stash [<start> [<size>]] - Stash data into memory\n"
99 "unstash [<start> [<size>]] - Unstash data from memory\n"
100 #endif