blob: f49cdd91a1f87f0d918886ac1604fc9e1a3137db [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
109static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
110 char *const argv[])
111{
112 int ret;
113
Simon Glasse1f59f42023-12-03 17:29:33 -0700114 ret = zboot_go();
Simon Glassa911beb2023-12-03 17:29:30 -0700115 if (ret) {
116 printf("Kernel returned! (err=%d)\n", ret);
117 return CMD_RET_FAILURE;
118 }
Simon Glass2bf90bd2023-12-03 17:29:27 -0700119
Simon Glassa911beb2023-12-03 17:29:30 -0700120 return 0;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700121}
122
123static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc,
124 char *const argv[])
125{
126 struct boot_params *base_ptr = state.base_ptr;
127
128 if (argc > 1)
129 base_ptr = (void *)hextoul(argv[1], NULL);
130 if (!base_ptr) {
131 printf("No zboot setup_base\n");
132 return CMD_RET_FAILURE;
133 }
134 zimage_dump(base_ptr, true);
135
136 return 0;
137}
138
139/* Note: This defines the complete_zboot() function */
140U_BOOT_SUBCMDS(zboot,
141 U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
142 U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
143 U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""),
144 U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
145 U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
146 U_BOOT_CMD_MKENT(dump, 2, 1, do_zboot_dump, "", ""),
147)
148
149int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
150 char *const argv[], int state_mask)
151{
Simon Glass205374e2023-12-03 17:29:29 -0700152 int ret;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700153
Simon Glass205374e2023-12-03 17:29:29 -0700154 if (flag & ZBOOT_STATE_START)
155 ret = do_zboot_start(cmdtp, flag, argc, argv);
156 if (!ret && (flag & ZBOOT_STATE_LOAD))
157 ret = do_zboot_load(cmdtp, flag, argc, argv);
158 if (!ret && (flag & ZBOOT_STATE_SETUP))
159 ret = do_zboot_setup(cmdtp, flag, argc, argv);
160 if (!ret && (flag & ZBOOT_STATE_INFO))
161 ret = do_zboot_info(cmdtp, flag, argc, argv);
162 if (!ret && (flag & ZBOOT_STATE_GO))
163 ret = do_zboot_go(cmdtp, flag, argc, argv);
164 if (ret)
165 return ret;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700166
167 return 0;
168}
169
170int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
171 char *const argv[], int *repeatable)
172{
173 /* determine if we have a sub command */
174 if (argc > 1) {
175 char *endp;
176
177 hextoul(argv[1], &endp);
178 /*
179 * endp pointing to nul means that argv[1] was just a valid
180 * number, so pass it along to the normal processing
181 */
182 if (*endp)
183 return do_zboot(cmdtp, flag, argc, argv, repeatable);
184 }
185
186 do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
187 ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP |
188 ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
189
190 return CMD_RET_FAILURE;
191}
192
193U_BOOT_CMDREP_COMPLETE(
194 zboot, 8, do_zboot_parent, "Boot bzImage",
195 "[addr] [size] [initrd addr] [initrd size] [setup] [cmdline]\n"
196 " addr - The optional starting address of the bzimage.\n"
197 " If not set it defaults to the environment\n"
198 " variable \"fileaddr\".\n"
199 " size - The optional size of the bzimage. Defaults to\n"
200 " zero.\n"
201 " initrd addr - The address of the initrd image to use, if any.\n"
202 " initrd size - The size of the initrd image to use, if any.\n"
203 " setup - The address of the kernel setup region, if this\n"
204 " is not at addr\n"
205 " cmdline - Environment variable containing the kernel\n"
206 " command line, to override U-Boot's normal\n"
207 " cmdline generation\n"
208 "\n"
209 "Sub-commands to do part of the zboot sequence:\n"
210 "\tstart [addr [arg ...]] - specify arguments\n"
211 "\tload - load OS image\n"
212 "\tsetup - set up table\n"
213 "\tinfo - show summary info\n"
214 "\tgo - start OS\n"
215 "\tdump [addr] - dump info (optional address of boot params)",
216 complete_zboot
217);