blob: fe7f80b88a5c39af336cdea1211b8df6f3238801 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass3b5866d2014-06-12 07:24:46 -06002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glass3b5866d2014-06-12 07:24:46 -06005 */
6
7#ifndef _BOOTM_H
8#define _BOOTM_H
9
Simon Glass3b5866d2014-06-12 07:24:46 -060010#include <image.h>
11
Simon Glass4493d612023-07-30 11:16:53 -060012struct boot_params;
Simon Glassed38aef2020-05-10 11:40:03 -060013struct cmd_tbl;
14
Simon Glass3b5866d2014-06-12 07:24:46 -060015#define BOOTM_ERR_RESET (-1)
16#define BOOTM_ERR_OVERLAP (-2)
17#define BOOTM_ERR_UNIMPLEMENTED (-3)
18
Simon Glass526ea782023-12-15 20:14:12 -070019/**
20 * struct bootm_info() - information used when processing images to boot
21 *
Simon Glass112b0202023-12-15 20:14:14 -070022 * These mirror the first three arguments of the bootm command. They are
23 * designed to handle any type of image, but typically it is a FIT.
24 *
25 * @addr_img: Address of image to bootm, as passed to
26 * genimg_get_kernel_addr_fit() for processing:
27 *
28 * NULL: Usees default load address, i.e. image_load_addr
29 * <addr>: Uses hex address
30 *
31 * For FIT:
32 * "[<addr>]#<conf>": Uses address (or image_load_addr) and also specifies
33 * the FIT configuration to use
34 * "[<addr>]:<subimage>": Uses address (or image_load_addr) and also
35 * specifies the subimage name containing the OS
36 *
37 * @conf_ramdisk: Address (or with FIT, the name) of the ramdisk image, as
38 * passed to boot_get_ramdisk() for processing, or NULL for none
39 * @conf_fdt: Address (or with FIT, the name) of the FDT image, as passed to
40 * boot_get_fdt() for processing, or NULL for none
41 * @boot_progress: true to show boot progress
Simon Glass526ea782023-12-15 20:14:12 -070042 * @images: images information
Simon Glass112b0202023-12-15 20:14:14 -070043 * @cmd_name: command which invoked this operation, e.g. "bootm"
Simon Glass526ea782023-12-15 20:14:12 -070044 * @argc: Number of arguments to the command (excluding the actual command).
45 * This is 0 if there are no arguments
46 * @argv: NULL-terminated list of arguments, or NULL if there are no arguments
Simon Glass0fdb4b32025-03-05 17:24:58 -070047 *
48 * For zboot:
49 * @bzimage_addr: Address of the bzImage to boot, or 0 if the image has already
50 * been loaded and does not exist (as a cohesive whole) in memory
51 * @bzimage_size: Size of the bzImage, or 0 to detect this
52 * @initrd_addr: Address of the initial ramdisk, or 0 if none
53 * @initrd_size: Size of the initial ramdisk, or 0 if none
54 * @load_address: Address where the bzImage is moved before booting, either
55 * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
56 * This is set up when loading the zimage
57 * @base_ptr: Pointer to the boot parameters, typically at address
58 * DEFAULT_SETUP_BASE
59 * This is set up when loading the zimage
60 * @cmdline: Environment variable containing the 'override' command line, or
61 * NULL to use the one in the setup block
Simon Glass526ea782023-12-15 20:14:12 -070062 */
63struct bootm_info {
Simon Glass112b0202023-12-15 20:14:14 -070064 const char *addr_img;
65 const char *conf_ramdisk;
66 const char *conf_fdt;
67 bool boot_progress;
Simon Glass526ea782023-12-15 20:14:12 -070068 struct bootm_headers *images;
Simon Glass112b0202023-12-15 20:14:14 -070069 const char *cmd_name;
Simon Glass526ea782023-12-15 20:14:12 -070070 int argc;
71 char *const *argv;
Simon Glass0fdb4b32025-03-05 17:24:58 -070072
73 /* zboot items */
74#ifdef CONFIG_X86
75 ulong bzimage_addr;
76 ulong bzimage_size;
77 ulong initrd_addr;
78 ulong initrd_size;
79 ulong load_address;
80 struct boot_params *base_ptr;
81 const char *cmdline;
82#endif
Simon Glass526ea782023-12-15 20:14:12 -070083};
84
Simon Glass0fdb4b32025-03-05 17:24:58 -070085/* macro to allow setting fields in generic code */
86#ifdef CONFIG_X86
87#define bootm_x86_set(_bmi, _field, _val) (_bmi)->_field = (_val)
88#else
89#define bootm_x86_set(_bmi, _field, _val)
90#endif
91
Simon Glass112b0202023-12-15 20:14:14 -070092/**
93 * bootm_init() - Set up a bootm_info struct with useful defaults
94 *
Simon Glass7b15c572025-03-05 17:25:00 -070095 * @bmi: Bootm information
96 *
Simon Glass112b0202023-12-15 20:14:14 -070097 * Set up the struct with default values for all members:
98 * @boot_progress is set to true and @images is set to the global images
99 * variable. Everything else is set to NULL except @argc which is 0
100 */
101void bootm_init(struct bootm_info *bmi);
102
Simon Glass3b5866d2014-06-12 07:24:46 -0600103/*
104 * Continue booting an OS image; caller already has:
105 * - copied image header to global variable `header'
106 * - checked header magic number, checksums (both header & image),
107 * - verified image architecture (PPC) and type (KERNEL or MULTI),
108 * - loaded (first part of) image to header load address,
109 * - disabled interrupts.
110 *
111 * @flag: Flags indicating what to do (BOOTM_STATE_...)
Simon Glass7b15c572025-03-05 17:25:00 -0700112 * @bmi: Bootm information
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100113 * Return: 1 on error. On success the OS boots so this function does
Simon Glass3b5866d2014-06-12 07:24:46 -0600114 * not return.
115 */
Simon Glass0726d9d2023-12-15 20:14:13 -0700116typedef int boot_os_fn(int flag, struct bootm_info *bmi);
Simon Glass3b5866d2014-06-12 07:24:46 -0600117
118extern boot_os_fn do_bootm_linux;
Bin Meng54a735a2018-12-21 07:13:40 -0800119extern boot_os_fn do_bootm_vxworks;
120
Simon Glass526ea782023-12-15 20:14:12 -0700121int do_bootelf(struct cmd_tbl *cmdtp, int fglag, int argc, char *const argv[]);
Simon Glass3b5866d2014-06-12 07:24:46 -0600122
123boot_os_fn *bootm_os_get_boot_func(int os);
124
Fabrice Fontained00d6b52019-05-03 22:37:05 +0200125#if defined(CONFIG_FIT_SIGNATURE)
Simon Glassa51991d2014-06-12 07:24:53 -0600126int bootm_host_load_images(const void *fit, int cfg_noffset);
Fabrice Fontained00d6b52019-05-03 22:37:05 +0200127#endif
Simon Glassa51991d2014-06-12 07:24:53 -0600128
Simon Glass454746d2023-12-15 20:14:20 -0700129int boot_selected_os(int state, struct bootm_info *bmi, boot_os_fn *boot_fn);
Simon Glass3b5866d2014-06-12 07:24:46 -0600130
131ulong bootm_disable_interrupts(void);
132
Simon Glassd46c81e2023-11-18 14:05:16 -0700133/**
134 * bootm_find_images() - find and locate various images
135 *
136 * @img_addr: Address of image being loaded
137 * @conf_ramdisk: Indicates the ramdisk to use (typically second arg of bootm)
138 * @conf_fdt: Indicates the FDT to use (typically third arg of bootm)
139 * @start: OS image start address
140 * @size: OS image size
141 *
142 * boot_find_images() will attempt to load an available ramdisk,
143 * flattened device tree, as well as specifically marked
144 * "loadable" images (loadables are FIT only)
145 *
146 * Note: bootm_find_images will skip an image if it is not found
147 *
148 * This is a special function used by booti/bootz
149 *
150 * Return:
151 * 0, if all existing images were loaded correctly
152 * 1, if an image is found but corrupted, or invalid
153 */
154int bootm_find_images(ulong img_addr, const char *conf_ramdisk,
155 const char *conf_fdt, ulong start, ulong size);
Simon Glass3b5866d2014-06-12 07:24:46 -0600156
Eddie James32401ba2023-10-24 10:43:50 -0500157/*
158 * Measure the boot images. Measurement is the process of hashing some binary
159 * data and storing it into secure memory, i.e. TPM PCRs. In addition, each
160 * measurement is logged into the platform event log such that the operating
161 * system can access it and perform attestation of the boot.
162 *
163 * @images: The structure containing the various images to boot (linux,
164 * initrd, dts, etc.)
165 */
166int bootm_measure(struct bootm_headers *images);
167
Simon Glass839e9e42023-12-15 20:14:15 -0700168/**
Simon Glassd90f94f2023-12-15 20:14:19 -0700169 * bootm_run_states() - Execute selected states of the bootm command.
Simon Glass839e9e42023-12-15 20:14:15 -0700170 *
171 * Note that if states contains more than one flag it MUST contain
Simon Glass50fa2fe2023-12-15 20:14:18 -0700172 * BOOTM_STATE_START, since this handles the addr_fit, conf_ramdisk and conf_fit
173 * members of @bmi
Simon Glass839e9e42023-12-15 20:14:15 -0700174 *
Simon Glass50fa2fe2023-12-15 20:14:18 -0700175 * Also note that aside from boot_os_fn functions and bootm_load_os, no other
176 * functions store the return value of in 'ret' may use a negative return
Simon Glass839e9e42023-12-15 20:14:15 -0700177 * value, without special handling.
178 *
Simon Glass50fa2fe2023-12-15 20:14:18 -0700179 * @bmi: bootm information
180 * @states Mask containing states to run (BOOTM_STATE_...)
Simon Glass839e9e42023-12-15 20:14:15 -0700181 * Return: 0 if ok, something else on error. Some errors will cause this
182 * function to perform a reboot! If states contains BOOTM_STATE_OS_GO
183 * then the intent is to boot an OS, so this function will not return
184 * unless the image type is standalone.
185 */
Simon Glassd90f94f2023-12-15 20:14:19 -0700186int bootm_run_states(struct bootm_info *bmi, int states);
Simon Glass3b5866d2014-06-12 07:24:46 -0600187
Simon Glassbd73cac2023-12-15 20:14:21 -0700188/**
Simon Glass6568e4b2023-12-15 20:14:26 -0700189 * boot_run() - Run the entire bootm/booti/bootz process
190 *
191 * This runs through the boot process from start to finish, with a base set of
192 * states, along with the extra ones supplied.
193 *
194 * This uses bootm_run_states().
195 *
196 * Note that it is normally easier to use bootm_run(), etc. since they handle
197 * the extra states correctly.
198 *
199 * @bmi: bootm information
200 * @cmd: command being run, NULL if none
201 * @extra_states: Mask of extra states to use for the boot
202 * Return: 0 if ok, something else on error
203 */
204int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states);
205
206/**
Simon Glassbd73cac2023-12-15 20:14:21 -0700207 * bootm_run() - Run the entire bootm process
208 *
209 * This runs through the bootm process from start to finish, using the default
210 * set of states.
211 *
212 * This uses bootm_run_states().
213 *
214 * @bmi: bootm information
215 * Return: 0 if ok, something else on error
216 */
217int bootm_run(struct bootm_info *bmi);
218
Simon Glasse176bb12023-12-15 20:14:23 -0700219/**
220 * bootz_run() - Run the entire bootz process
221 *
222 * This runs through the bootz process from start to finish, using the default
223 * set of states.
224 *
225 * This uses bootm_run_states().
226 *
227 * @bmi: bootm information
228 * Return: 0 if ok, something else on error
229 */
230int bootz_run(struct bootm_info *bmi);
231
Simon Glass2d043a62023-12-15 20:14:25 -0700232/**
233 * booti_run() - Run the entire booti process
234 *
235 * This runs through the booti process from start to finish, using the default
236 * set of states.
237 *
238 * This uses bootm_run_states().
239 *
240 * @bmi: bootm information
241 * Return: 0 if ok, something else on error
242 */
243int booti_run(struct bootm_info *bmi);
244
Jeroen Hofstee7ade3de2014-10-08 22:58:00 +0200245void arch_preboot_os(void);
246
Simon Glassc9b2e232018-05-16 09:42:26 -0600247/*
248 * boards should define this to disable devices when EFI exits from boot
249 * services.
250 *
251 * TODO(sjg@chromium.org>): Update this to use driver model's device_remove().
252 */
Simon Glassf55305a2018-05-16 09:42:25 -0600253void board_quiesce_devices(void);
254
Heinrich Schuchardtaa0b11b2019-01-08 18:13:06 +0100255/**
256 * switch_to_non_secure_mode() - switch to non-secure mode
257 */
258void switch_to_non_secure_mode(void);
259
Simon Glass63660dc2020-11-05 10:33:44 -0700260/* Flags to control bootm_process_cmdline() */
261enum bootm_cmdline_t {
262 BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */
Simon Glass529e2082020-11-05 10:33:48 -0700263 BOOTM_CL_SUBST = 1 << 1, /* Do substitution */
Simon Glass63660dc2020-11-05 10:33:44 -0700264
Simon Glass529e2082020-11-05 10:33:48 -0700265 BOOTM_CL_ALL = 3, /* All substitutions */
Simon Glass63660dc2020-11-05 10:33:44 -0700266};
267
Heinrich Schuchardt25828e92020-09-15 01:58:11 +0200268/**
269 * arch_preboot_os() - arch specific configuration before booting
270 */
271void arch_preboot_os(void);
272
273/**
274 * board_preboot_os() - board specific configuration before booting
275 */
276void board_preboot_os(void);
277
Simon Glass2eab0172020-11-05 10:33:39 -0700278/*
Simon Glassb4e1b6d2020-11-05 10:33:45 -0700279 * bootm_process_cmdline() - Process fix-ups for the command line
280 *
Simon Glass529e2082020-11-05 10:33:48 -0700281 * This handles:
282 *
283 * - making Linux boot silently if requested ('silent_linux' envvar)
284 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glassb4e1b6d2020-11-05 10:33:45 -0700285 *
286 * @maxlen must provide enough space for the string being processed plus the
287 * resulting string
288 *
289 * @buf: buffer holding commandline string to adjust
290 * @maxlen: Maximum length of buffer at @buf (including \0)
291 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100292 * Return: 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too
Simon Glassb4e1b6d2020-11-05 10:33:45 -0700293 * long
294 */
295int bootm_process_cmdline(char *buf, int maxlen, int flags);
296
297/**
Simon Glassa50b6dd2020-11-05 10:33:40 -0700298 * bootm_process_cmdline_env() - Process fix-ups for the command line
Simon Glass2eab0172020-11-05 10:33:39 -0700299 *
Simon Glass529e2082020-11-05 10:33:48 -0700300 * Updates the 'bootargs' envvar as required. This handles:
301 *
302 * - making Linux boot silently if requested ('silent_linux' envvar)
303 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass2eab0172020-11-05 10:33:39 -0700304 *
Simon Glass63660dc2020-11-05 10:33:44 -0700305 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100306 * Return: 0 if OK, -ENOMEM if out of memory
Simon Glass2eab0172020-11-05 10:33:39 -0700307 */
Simon Glass63660dc2020-11-05 10:33:44 -0700308int bootm_process_cmdline_env(int flags);
Simon Glass07a88862020-11-05 10:33:38 -0700309
Simon Glass4493d612023-07-30 11:16:53 -0600310/**
Simon Glass09519372025-03-05 17:24:56 -0700311 * zboot_run_args() - Run through the various steps to boot a zimage
Simon Glass4493d612023-07-30 11:16:53 -0600312 *
313 * Boot a zimage, given the component parts
314 *
315 * @addr: Address where the bzImage is moved before booting, either
316 * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
Simon Glass166e79a2023-12-03 17:29:38 -0700317 * @size: Size of bzImage, or 0 to detect this
Simon Glass4493d612023-07-30 11:16:53 -0600318 * @initrd: Address of the initial ramdisk, or 0 if none
319 * @initrd_size: Size of the initial ramdisk, or 0 if none
Simon Glass166e79a2023-12-03 17:29:38 -0700320 * @base_addr: If non-zero, this indicates that the boot parameters have already
321 * been loaded by the caller to this address, so the load_zimage() call
322 * in zboot_load() will be skipped when booting
323 * @cmdline: If non-NULL, the environment variable containing the command line
324 * to use for booting
Simon Glass4493d612023-07-30 11:16:53 -0600325 * Return: -EFAULT on error (normally it does not return)
326 */
Simon Glass09519372025-03-05 17:24:56 -0700327int zboot_run_args(ulong addr, ulong size, ulong initrd, ulong initrd_size,
328 ulong base, char *cmdline);
Simon Glass4493d612023-07-30 11:16:53 -0600329
330/*
331 * zimage_get_kernel_version() - Get the version string from a kernel
332 *
333 * @params: boot_params pointer
334 * @kernel_base: base address of kernel
335 * Return: Kernel version as a NUL-terminated string
336 */
337const char *zimage_get_kernel_version(struct boot_params *params,
338 void *kernel_base);
339
Simon Glass5495aaf2023-07-30 11:17:00 -0600340/**
341 * zimage_dump() - Dump the metadata of a zimage
342 *
343 * This shows all available information in a zimage that has been loaded.
344 *
Simon Glass7b15c572025-03-05 17:25:00 -0700345 * @bmi: Bootm information
Simon Glass5495aaf2023-07-30 11:17:00 -0600346 * @base_ptr: Pointer to the boot parameters, typically at address
347 * DEFAULT_SETUP_BASE
348 * @show_cmdline: true to show the full command line
349 */
Simon Glass7b15c572025-03-05 17:25:00 -0700350void zimage_dump(struct bootm_info *bmi, struct boot_params *base_ptr,
351 bool show_cmdline);
Simon Glass5495aaf2023-07-30 11:17:00 -0600352
Simon Glass18700262023-07-30 11:17:02 -0600353/*
354 * bootm_boot_start() - Boot an image at the given address
355 *
356 * @addr: Image address
Tom Rini793921e2024-04-18 08:29:35 -0600357 * @cmdline: Command line to set
Simon Glass18700262023-07-30 11:17:02 -0600358 */
359int bootm_boot_start(ulong addr, const char *cmdline);
360
Simon Glass3b5866d2014-06-12 07:24:46 -0600361#endif