blob: f392b6b3e4931bf109e329a968619f3b1691ab97 [file] [log] [blame]
Simon Glass2bf90bd2023-12-03 17:29:27 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2002
5 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
6 */
7
8#include <command.h>
9#include <mapmem.h>
10#include <vsprintf.h>
11#include <asm/zimage.h>
12
Simon Glassa911beb2023-12-03 17:29:30 -070013static void zboot_start(int argc, char *const argv[])
Simon Glass2bf90bd2023-12-03 17:29:27 -070014{
15 const char *s;
16
17 memset(&state, '\0', sizeof(state));
18 if (argc >= 2) {
19 /* argv[1] holds the address of the bzImage */
20 s = argv[1];
21 } else {
22 s = env_get("fileaddr");
23 }
24
25 if (s)
26 state.bzimage_addr = hextoul(s, NULL);
27
28 if (argc >= 3) {
29 /* argv[2] holds the size of the bzImage */
30 state.bzimage_size = hextoul(argv[2], NULL);
31 }
32
33 if (argc >= 4)
34 state.initrd_addr = hextoul(argv[3], NULL);
35 if (argc >= 5)
36 state.initrd_size = hextoul(argv[4], NULL);
37 if (argc >= 6) {
38 /*
39 * When the base_ptr is passed in, we assume that the image is
40 * already loaded at the address given by argv[1] and therefore
41 * the original bzImage is somewhere else, or not accessible.
42 * In any case, we don't need access to the bzImage since all
43 * the processing is assumed to be done.
44 *
45 * So set the base_ptr to the given address, use this arg as the
46 * load address and set bzimage_addr to 0 so we know that it
47 * cannot be proceesed (or processed again).
48 */
49 state.base_ptr = (void *)hextoul(argv[5], NULL);
50 state.load_address = state.bzimage_addr;
51 state.bzimage_addr = 0;
52 }
53 if (argc >= 7)
54 state.cmdline = env_get(argv[6]);
Simon Glassa911beb2023-12-03 17:29:30 -070055}
56
57static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
58 char *const argv[])
59{
60 zboot_start(argc, argv);
Simon Glass2bf90bd2023-12-03 17:29:27 -070061
62 return 0;
63}
64
Simon Glassf6d7ebd2023-12-03 17:29:31 -070065static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
66 char *const argv[])
Simon Glassa911beb2023-12-03 17:29:30 -070067{
68 int ret;
69
70 ret = zboot_load();
Simon Glassa911beb2023-12-03 17:29:30 -070071 if (ret)
72 return ret;
73
74 return 0;
75}
76
Simon Glass82e6b892023-12-03 17:29:32 -070077static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
78 char *const argv[])
Simon Glass2bf90bd2023-12-03 17:29:27 -070079{
Simon Glass82e6b892023-12-03 17:29:32 -070080 if (!state.base_ptr) {
Simon Glass2bf90bd2023-12-03 17:29:27 -070081 printf("base is not set: use 'zboot load' first\n");
82 return CMD_RET_FAILURE;
83 }
84 if (zboot_setup()) {
85 puts("Setting up boot parameters failed ...\n");
86 return CMD_RET_FAILURE;
87 }
88
Simon Glass82e6b892023-12-03 17:29:32 -070089 if (zboot_setup())
90 return CMD_RET_FAILURE;
Simon Glass2bf90bd2023-12-03 17:29:27 -070091
Simon Glass82e6b892023-12-03 17:29:32 -070092 return 0;
Simon Glassa911beb2023-12-03 17:29:30 -070093}
94
95static void zboot_info(void)
Simon Glass2bf90bd2023-12-03 17:29:27 -070096{
97 printf("Kernel loaded at %08lx, setup_base=%p\n",
98 state.load_address, state.base_ptr);
Simon Glassa911beb2023-12-03 17:29:30 -070099}
100
101static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
102 char *const argv[])
103{
104 zboot_info();
Simon Glass2bf90bd2023-12-03 17:29:27 -0700105
106 return 0;
107}
108
Simon Glassa911beb2023-12-03 17:29:30 -0700109static int _zboot_go(void)
110{
111 int ret;
112
113 ret = zboot_go();
114
115 return ret;
116}
117
Simon Glass2bf90bd2023-12-03 17:29:27 -0700118static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
119 char *const argv[])
120{
121 int ret;
122
Simon Glassa911beb2023-12-03 17:29:30 -0700123 ret = _zboot_go();
124 if (ret) {
125 printf("Kernel returned! (err=%d)\n", ret);
126 return CMD_RET_FAILURE;
127 }
Simon Glass2bf90bd2023-12-03 17:29:27 -0700128
Simon Glassa911beb2023-12-03 17:29:30 -0700129 return 0;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700130}
131
132static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc,
133 char *const argv[])
134{
135 struct boot_params *base_ptr = state.base_ptr;
136
137 if (argc > 1)
138 base_ptr = (void *)hextoul(argv[1], NULL);
139 if (!base_ptr) {
140 printf("No zboot setup_base\n");
141 return CMD_RET_FAILURE;
142 }
143 zimage_dump(base_ptr, true);
144
145 return 0;
146}
147
148/* Note: This defines the complete_zboot() function */
149U_BOOT_SUBCMDS(zboot,
150 U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
151 U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
152 U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""),
153 U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
154 U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
155 U_BOOT_CMD_MKENT(dump, 2, 1, do_zboot_dump, "", ""),
156)
157
158int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
159 char *const argv[], int state_mask)
160{
Simon Glass205374e2023-12-03 17:29:29 -0700161 int ret;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700162
Simon Glass205374e2023-12-03 17:29:29 -0700163 if (flag & ZBOOT_STATE_START)
164 ret = do_zboot_start(cmdtp, flag, argc, argv);
165 if (!ret && (flag & ZBOOT_STATE_LOAD))
166 ret = do_zboot_load(cmdtp, flag, argc, argv);
167 if (!ret && (flag & ZBOOT_STATE_SETUP))
168 ret = do_zboot_setup(cmdtp, flag, argc, argv);
169 if (!ret && (flag & ZBOOT_STATE_INFO))
170 ret = do_zboot_info(cmdtp, flag, argc, argv);
171 if (!ret && (flag & ZBOOT_STATE_GO))
172 ret = do_zboot_go(cmdtp, flag, argc, argv);
173 if (ret)
174 return ret;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700175
176 return 0;
177}
178
179int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
180 char *const argv[], int *repeatable)
181{
182 /* determine if we have a sub command */
183 if (argc > 1) {
184 char *endp;
185
186 hextoul(argv[1], &endp);
187 /*
188 * endp pointing to nul means that argv[1] was just a valid
189 * number, so pass it along to the normal processing
190 */
191 if (*endp)
192 return do_zboot(cmdtp, flag, argc, argv, repeatable);
193 }
194
195 do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
196 ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP |
197 ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
198
199 return CMD_RET_FAILURE;
200}
201
202U_BOOT_CMDREP_COMPLETE(
203 zboot, 8, do_zboot_parent, "Boot bzImage",
204 "[addr] [size] [initrd addr] [initrd size] [setup] [cmdline]\n"
205 " addr - The optional starting address of the bzimage.\n"
206 " If not set it defaults to the environment\n"
207 " variable \"fileaddr\".\n"
208 " size - The optional size of the bzimage. Defaults to\n"
209 " zero.\n"
210 " initrd addr - The address of the initrd image to use, if any.\n"
211 " initrd size - The size of the initrd image to use, if any.\n"
212 " setup - The address of the kernel setup region, if this\n"
213 " is not at addr\n"
214 " cmdline - Environment variable containing the kernel\n"
215 " command line, to override U-Boot's normal\n"
216 " cmdline generation\n"
217 "\n"
218 "Sub-commands to do part of the zboot sequence:\n"
219 "\tstart [addr [arg ...]] - specify arguments\n"
220 "\tload - load OS image\n"
221 "\tsetup - set up table\n"
222 "\tinfo - show summary info\n"
223 "\tgo - start OS\n"
224 "\tdump [addr] - dump info (optional address of boot params)",
225 complete_zboot
226);