blob: 94e602b8a5b60d682c21b4483870d93b1bd3627e [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
Simon Glass95c8c8b2024-06-19 06:34:51 -06008#define LOG_CATEGORY LOGC_BOOT
9
Simon Glass2bf90bd2023-12-03 17:29:27 -070010#include <command.h>
11#include <mapmem.h>
12#include <vsprintf.h>
13#include <asm/zimage.h>
14
Simon Glassa911beb2023-12-03 17:29:30 -070015static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
16 char *const argv[])
17{
Simon Glass357105f2023-12-03 17:29:34 -070018 ulong bzimage_addr = 0, bzimage_size, initrd_addr, initrd_size;
Simon Glass357105f2023-12-03 17:29:34 -070019 const char *s, *cmdline;
Simon Glass95c8c8b2024-06-19 06:34:51 -060020 ulong base_addr;
21 int i;
22
23 log_debug("argc %d:", argc);
24 for (i = 0; i < argc; i++)
25 log_debug(" %s", argv[i]);
26 log_debug("\n");
Simon Glass2bf90bd2023-12-03 17:29:27 -070027
Simon Glass357105f2023-12-03 17:29:34 -070028 /* argv[1] holds the address of the bzImage */
29 s = cmd_arg1(argc, argv) ? : env_get("fileaddr");
30 if (s)
31 bzimage_addr = hextoul(s, NULL);
32 bzimage_size = argc > 2 ? hextoul(argv[2], NULL) : 0;
33 initrd_addr = argc > 3 ? hextoul(argv[3], NULL) : 0;
34 initrd_size = argc > 4 ? hextoul(argv[4], NULL) : 0;
35 base_addr = argc > 5 ? hextoul(argv[5], NULL) : 0;
36 cmdline = argc > 6 ? env_get(argv[6]) : NULL;
37
Simon Glass14c0fc72023-12-03 17:29:36 -070038 zboot_start(bzimage_addr, bzimage_size, initrd_addr, initrd_size,
39 base_addr, cmdline);
40
41 return 0;
Simon Glass2bf90bd2023-12-03 17:29:27 -070042}
43
Simon Glassf6d7ebd2023-12-03 17:29:31 -070044static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
45 char *const argv[])
Simon Glassa911beb2023-12-03 17:29:30 -070046{
47 int ret;
48
49 ret = zboot_load();
Simon Glassa911beb2023-12-03 17:29:30 -070050 if (ret)
51 return ret;
52
53 return 0;
54}
55
Simon Glass82e6b892023-12-03 17:29:32 -070056static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
57 char *const argv[])
Simon Glass2bf90bd2023-12-03 17:29:27 -070058{
Simon Glass82e6b892023-12-03 17:29:32 -070059 if (!state.base_ptr) {
Simon Glass2bf90bd2023-12-03 17:29:27 -070060 printf("base is not set: use 'zboot load' first\n");
61 return CMD_RET_FAILURE;
62 }
63 if (zboot_setup()) {
64 puts("Setting up boot parameters failed ...\n");
65 return CMD_RET_FAILURE;
66 }
67
Simon Glass82e6b892023-12-03 17:29:32 -070068 if (zboot_setup())
69 return CMD_RET_FAILURE;
Simon Glass2bf90bd2023-12-03 17:29:27 -070070
Simon Glass82e6b892023-12-03 17:29:32 -070071 return 0;
Simon Glassa911beb2023-12-03 17:29:30 -070072}
73
Simon Glassa911beb2023-12-03 17:29:30 -070074static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
75 char *const argv[])
76{
77 zboot_info();
Simon Glass2bf90bd2023-12-03 17:29:27 -070078
79 return 0;
80}
81
82static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
83 char *const argv[])
84{
85 int ret;
86
Simon Glasse1f59f42023-12-03 17:29:33 -070087 ret = zboot_go();
Simon Glassa911beb2023-12-03 17:29:30 -070088 if (ret) {
89 printf("Kernel returned! (err=%d)\n", ret);
90 return CMD_RET_FAILURE;
91 }
Simon Glass2bf90bd2023-12-03 17:29:27 -070092
Simon Glassa911beb2023-12-03 17:29:30 -070093 return 0;
Simon Glass2bf90bd2023-12-03 17:29:27 -070094}
95
96static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc,
97 char *const argv[])
98{
99 struct boot_params *base_ptr = state.base_ptr;
100
101 if (argc > 1)
102 base_ptr = (void *)hextoul(argv[1], NULL);
103 if (!base_ptr) {
104 printf("No zboot setup_base\n");
105 return CMD_RET_FAILURE;
106 }
107 zimage_dump(base_ptr, true);
108
109 return 0;
110}
111
112/* Note: This defines the complete_zboot() function */
113U_BOOT_SUBCMDS(zboot,
114 U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
115 U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
116 U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""),
117 U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
118 U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
119 U_BOOT_CMD_MKENT(dump, 2, 1, do_zboot_dump, "", ""),
120)
121
122int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
123 char *const argv[], int state_mask)
124{
Simon Glass1f613c62024-06-19 06:34:52 -0600125 int ret = 0;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700126
Simon Glass95c8c8b2024-06-19 06:34:51 -0600127 log_debug("state_mask %x\n", state_mask);
Simon Glass1f613c62024-06-19 06:34:52 -0600128 if (state_mask & ZBOOT_STATE_START)
Simon Glass205374e2023-12-03 17:29:29 -0700129 ret = do_zboot_start(cmdtp, flag, argc, argv);
Simon Glass1f613c62024-06-19 06:34:52 -0600130 if (!ret && (state_mask & ZBOOT_STATE_LOAD))
Simon Glass205374e2023-12-03 17:29:29 -0700131 ret = do_zboot_load(cmdtp, flag, argc, argv);
Simon Glass1f613c62024-06-19 06:34:52 -0600132 if (!ret && (state_mask & ZBOOT_STATE_SETUP))
Simon Glass205374e2023-12-03 17:29:29 -0700133 ret = do_zboot_setup(cmdtp, flag, argc, argv);
Simon Glass1f613c62024-06-19 06:34:52 -0600134 if (!ret && (state_mask & ZBOOT_STATE_INFO))
Simon Glass205374e2023-12-03 17:29:29 -0700135 ret = do_zboot_info(cmdtp, flag, argc, argv);
Simon Glass1f613c62024-06-19 06:34:52 -0600136 if (!ret && (state_mask & ZBOOT_STATE_GO))
Simon Glass205374e2023-12-03 17:29:29 -0700137 ret = do_zboot_go(cmdtp, flag, argc, argv);
138 if (ret)
139 return ret;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700140
141 return 0;
142}
143
144int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
145 char *const argv[], int *repeatable)
146{
147 /* determine if we have a sub command */
148 if (argc > 1) {
149 char *endp;
150
151 hextoul(argv[1], &endp);
152 /*
153 * endp pointing to nul means that argv[1] was just a valid
154 * number, so pass it along to the normal processing
155 */
156 if (*endp)
157 return do_zboot(cmdtp, flag, argc, argv, repeatable);
158 }
159
160 do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
161 ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP |
162 ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
163
164 return CMD_RET_FAILURE;
165}
166
167U_BOOT_CMDREP_COMPLETE(
168 zboot, 8, do_zboot_parent, "Boot bzImage",
169 "[addr] [size] [initrd addr] [initrd size] [setup] [cmdline]\n"
170 " addr - The optional starting address of the bzimage.\n"
171 " If not set it defaults to the environment\n"
172 " variable \"fileaddr\".\n"
173 " size - The optional size of the bzimage. Defaults to\n"
174 " zero.\n"
175 " initrd addr - The address of the initrd image to use, if any.\n"
176 " initrd size - The size of the initrd image to use, if any.\n"
177 " setup - The address of the kernel setup region, if this\n"
178 " is not at addr\n"
179 " cmdline - Environment variable containing the kernel\n"
180 " command line, to override U-Boot's normal\n"
181 " cmdline generation\n"
182 "\n"
183 "Sub-commands to do part of the zboot sequence:\n"
184 "\tstart [addr [arg ...]] - specify arguments\n"
185 "\tload - load OS image\n"
186 "\tsetup - set up table\n"
187 "\tinfo - show summary info\n"
188 "\tgo - start OS\n"
189 "\tdump [addr] - dump info (optional address of boot params)",
190 complete_zboot
191);