]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_bootstage.c
x86: Add CBMEM console driver for coreboot
[karo-tx-uboot.git] / common / cmd_bootstage.c
1 /*
2  * Copyright (c) 2012, Google Inc. All rights reserved.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24
25 #ifndef CONFIG_BOOTSTAGE_STASH
26 #define CONFIG_BOOTSTAGE_STASH          -1UL
27 #define CONFIG_BOOTSTAGE_STASH_SIZE     -1
28 #endif
29
30 static int do_bootstage_report(cmd_tbl_t *cmdtp, int flag, int argc,
31                                char * const argv[])
32 {
33         bootstage_report();
34
35         return 0;
36 }
37
38 static int get_base_size(int argc, char * const argv[], ulong *basep,
39                          ulong *sizep)
40 {
41         char *endp;
42
43         *basep = CONFIG_BOOTSTAGE_STASH;
44         *sizep = CONFIG_BOOTSTAGE_STASH_SIZE;
45         if (argc < 2)
46                 return 0;
47         *basep = simple_strtoul(argv[1], &endp, 16);
48         if (*argv[1] == 0 || *endp != 0)
49                 return -1;
50         if (argc == 2)
51                 return 0;
52         *sizep = simple_strtoul(argv[2], &endp, 16);
53         if (*argv[2] == 0 || *endp != 0)
54                 return -1;
55
56         return 0;
57 }
58
59 static int do_bootstage_stash(cmd_tbl_t *cmdtp, int flag, int argc,
60                               char * const argv[])
61 {
62         ulong base, size;
63         int ret;
64
65         if (get_base_size(argc, argv, &base, &size))
66                 return CMD_RET_USAGE;
67         if (base == -1UL) {
68                 printf("No bootstage stash area defined\n");
69                 return 1;
70         }
71
72         if (0 == strcmp(argv[0], "stash"))
73                 ret = bootstage_stash((void *)base, size);
74         else
75                 ret = bootstage_unstash((void *)base, size);
76         if (ret)
77                 return 1;
78
79         return 0;
80 }
81
82 static cmd_tbl_t cmd_bootstage_sub[] = {
83         U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""),
84         U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""),
85         U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""),
86 };
87
88 /*
89  * Process a bootstage sub-command
90  */
91 static int do_boostage(cmd_tbl_t *cmdtp, int flag, int argc,
92                        char * const argv[])
93 {
94         cmd_tbl_t *c;
95
96         /* Strip off leading 'bootstage' command argument */
97         argc--;
98         argv++;
99
100         c = find_cmd_tbl(argv[0], cmd_bootstage_sub,
101                          ARRAY_SIZE(cmd_bootstage_sub));
102
103         if (c)
104                 return c->cmd(cmdtp, flag, argc, argv);
105         else
106                 return CMD_RET_USAGE;
107 }
108
109
110 U_BOOT_CMD(bootstage, 4, 1, do_boostage,
111         "Boot stage command",
112         " - check boot progress and timing\n"
113         "report                      - Print a report\n"
114         "stash [<start> [<size>]]    - Stash data into memory\n"
115         "unstash [<start> [<size>]]  - Unstash data from memory"
116 );