blob: addf28cb4aae5477c19cbd0bc7688e5585cccda9 [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 int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
14 char *const argv[])
15{
Simon Glass357105f2023-12-03 17:29:34 -070016 ulong bzimage_addr = 0, bzimage_size, initrd_addr, initrd_size;
17 ulong base_addr;
18 const char *s, *cmdline;
Simon Glass2bf90bd2023-12-03 17:29:27 -070019
Simon Glass357105f2023-12-03 17:29:34 -070020 /* argv[1] holds the address of the bzImage */
21 s = cmd_arg1(argc, argv) ? : env_get("fileaddr");
22 if (s)
23 bzimage_addr = hextoul(s, NULL);
24 bzimage_size = argc > 2 ? hextoul(argv[2], NULL) : 0;
25 initrd_addr = argc > 3 ? hextoul(argv[3], NULL) : 0;
26 initrd_size = argc > 4 ? hextoul(argv[4], NULL) : 0;
27 base_addr = argc > 5 ? hextoul(argv[5], NULL) : 0;
28 cmdline = argc > 6 ? env_get(argv[6]) : NULL;
29
Simon Glass14c0fc72023-12-03 17:29:36 -070030 zboot_start(bzimage_addr, bzimage_size, initrd_addr, initrd_size,
31 base_addr, cmdline);
32
33 return 0;
Simon Glass2bf90bd2023-12-03 17:29:27 -070034}
35
Simon Glassf6d7ebd2023-12-03 17:29:31 -070036static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
37 char *const argv[])
Simon Glassa911beb2023-12-03 17:29:30 -070038{
39 int ret;
40
41 ret = zboot_load();
Simon Glassa911beb2023-12-03 17:29:30 -070042 if (ret)
43 return ret;
44
45 return 0;
46}
47
Simon Glass82e6b892023-12-03 17:29:32 -070048static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
49 char *const argv[])
Simon Glass2bf90bd2023-12-03 17:29:27 -070050{
Simon Glass82e6b892023-12-03 17:29:32 -070051 if (!state.base_ptr) {
Simon Glass2bf90bd2023-12-03 17:29:27 -070052 printf("base is not set: use 'zboot load' first\n");
53 return CMD_RET_FAILURE;
54 }
55 if (zboot_setup()) {
56 puts("Setting up boot parameters failed ...\n");
57 return CMD_RET_FAILURE;
58 }
59
Simon Glass82e6b892023-12-03 17:29:32 -070060 if (zboot_setup())
61 return CMD_RET_FAILURE;
Simon Glass2bf90bd2023-12-03 17:29:27 -070062
Simon Glass82e6b892023-12-03 17:29:32 -070063 return 0;
Simon Glassa911beb2023-12-03 17:29:30 -070064}
65
Simon Glassa911beb2023-12-03 17:29:30 -070066static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
67 char *const argv[])
68{
69 zboot_info();
Simon Glass2bf90bd2023-12-03 17:29:27 -070070
71 return 0;
72}
73
74static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
75 char *const argv[])
76{
77 int ret;
78
Simon Glasse1f59f42023-12-03 17:29:33 -070079 ret = zboot_go();
Simon Glassa911beb2023-12-03 17:29:30 -070080 if (ret) {
81 printf("Kernel returned! (err=%d)\n", ret);
82 return CMD_RET_FAILURE;
83 }
Simon Glass2bf90bd2023-12-03 17:29:27 -070084
Simon Glassa911beb2023-12-03 17:29:30 -070085 return 0;
Simon Glass2bf90bd2023-12-03 17:29:27 -070086}
87
88static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc,
89 char *const argv[])
90{
91 struct boot_params *base_ptr = state.base_ptr;
92
93 if (argc > 1)
94 base_ptr = (void *)hextoul(argv[1], NULL);
95 if (!base_ptr) {
96 printf("No zboot setup_base\n");
97 return CMD_RET_FAILURE;
98 }
99 zimage_dump(base_ptr, true);
100
101 return 0;
102}
103
104/* Note: This defines the complete_zboot() function */
105U_BOOT_SUBCMDS(zboot,
106 U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
107 U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
108 U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""),
109 U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
110 U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
111 U_BOOT_CMD_MKENT(dump, 2, 1, do_zboot_dump, "", ""),
112)
113
114int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
115 char *const argv[], int state_mask)
116{
Simon Glass205374e2023-12-03 17:29:29 -0700117 int ret;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700118
Simon Glass205374e2023-12-03 17:29:29 -0700119 if (flag & ZBOOT_STATE_START)
120 ret = do_zboot_start(cmdtp, flag, argc, argv);
121 if (!ret && (flag & ZBOOT_STATE_LOAD))
122 ret = do_zboot_load(cmdtp, flag, argc, argv);
123 if (!ret && (flag & ZBOOT_STATE_SETUP))
124 ret = do_zboot_setup(cmdtp, flag, argc, argv);
125 if (!ret && (flag & ZBOOT_STATE_INFO))
126 ret = do_zboot_info(cmdtp, flag, argc, argv);
127 if (!ret && (flag & ZBOOT_STATE_GO))
128 ret = do_zboot_go(cmdtp, flag, argc, argv);
129 if (ret)
130 return ret;
Simon Glass2bf90bd2023-12-03 17:29:27 -0700131
132 return 0;
133}
134
135int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
136 char *const argv[], int *repeatable)
137{
138 /* determine if we have a sub command */
139 if (argc > 1) {
140 char *endp;
141
142 hextoul(argv[1], &endp);
143 /*
144 * endp pointing to nul means that argv[1] was just a valid
145 * number, so pass it along to the normal processing
146 */
147 if (*endp)
148 return do_zboot(cmdtp, flag, argc, argv, repeatable);
149 }
150
151 do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
152 ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP |
153 ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
154
155 return CMD_RET_FAILURE;
156}
157
158U_BOOT_CMDREP_COMPLETE(
159 zboot, 8, do_zboot_parent, "Boot bzImage",
160 "[addr] [size] [initrd addr] [initrd size] [setup] [cmdline]\n"
161 " addr - The optional starting address of the bzimage.\n"
162 " If not set it defaults to the environment\n"
163 " variable \"fileaddr\".\n"
164 " size - The optional size of the bzimage. Defaults to\n"
165 " zero.\n"
166 " initrd addr - The address of the initrd image to use, if any.\n"
167 " initrd size - The size of the initrd image to use, if any.\n"
168 " setup - The address of the kernel setup region, if this\n"
169 " is not at addr\n"
170 " cmdline - Environment variable containing the kernel\n"
171 " command line, to override U-Boot's normal\n"
172 " cmdline generation\n"
173 "\n"
174 "Sub-commands to do part of the zboot sequence:\n"
175 "\tstart [addr [arg ...]] - specify arguments\n"
176 "\tload - load OS image\n"
177 "\tsetup - set up table\n"
178 "\tinfo - show summary info\n"
179 "\tgo - start OS\n"
180 "\tdump [addr] - dump info (optional address of boot params)",
181 complete_zboot
182);