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