1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 2012, Google Inc. All rights reserved.
4 */
5
6 #include <common.h>
7 #include <bootstage.h>
8 #include <command.h>
9
do_bootstage_report(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])10 static int do_bootstage_report(struct cmd_tbl *cmdtp, int flag, int argc,
11 char *const argv[])
12 {
13 bootstage_report();
14
15 return 0;
16 }
17
get_base_size(int argc,char * const argv[],ulong * basep,ulong * sizep)18 static int get_base_size(int argc, char *const argv[], ulong *basep,
19 ulong *sizep)
20 {
21 char *endp;
22
23 *basep = CONFIG_BOOTSTAGE_STASH_ADDR;
24 *sizep = CONFIG_BOOTSTAGE_STASH_SIZE;
25 if (argc < 2)
26 return 0;
27 *basep = simple_strtoul(argv[1], &endp, 16);
28 if (*argv[1] == 0 || *endp != 0)
29 return -1;
30 if (argc == 2)
31 return 0;
32 *sizep = simple_strtoul(argv[2], &endp, 16);
33 if (*argv[2] == 0 || *endp != 0)
34 return -1;
35
36 return 0;
37 }
38
do_bootstage_stash(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])39 static int do_bootstage_stash(struct cmd_tbl *cmdtp, int flag, int argc,
40 char *const argv[])
41 {
42 ulong base, size;
43 int ret;
44
45 if (get_base_size(argc, argv, &base, &size))
46 return CMD_RET_USAGE;
47 if (base == -1UL) {
48 printf("No bootstage stash area defined\n");
49 return 1;
50 }
51
52 if (0 == strcmp(argv[0], "stash"))
53 ret = bootstage_stash((void *)base, size);
54 else
55 ret = bootstage_unstash((void *)base, size);
56 if (ret)
57 return 1;
58
59 return 0;
60 }
61
62 static struct cmd_tbl cmd_bootstage_sub[] = {
63 U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""),
64 U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""),
65 U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""),
66 };
67
68 /*
69 * Process a bootstage sub-command
70 */
do_boostage(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])71 static int do_boostage(struct cmd_tbl *cmdtp, int flag, int argc,
72 char *const argv[])
73 {
74 struct cmd_tbl *c;
75
76 /* Strip off leading 'bootstage' command argument */
77 argc--;
78 argv++;
79
80 c = find_cmd_tbl(argv[0], cmd_bootstage_sub,
81 ARRAY_SIZE(cmd_bootstage_sub));
82
83 if (c)
84 return c->cmd(cmdtp, flag, argc, argv);
85 else
86 return CMD_RET_USAGE;
87 }
88
89
90 U_BOOT_CMD(bootstage, 4, 1, do_boostage,
91 "Boot stage command",
92 " - check boot progress and timing\n"
93 "report - Print a report\n"
94 "stash [<start> [<size>]] - Stash data into memory\n"
95 "unstash [<start> [<size>]] - Unstash data from memory"
96 );
97