blob: 9e0f8d60de0a2505a73000ba5e07f243e4dea6fd [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassb6396402014-06-12 07:24:46 -06002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glassb6396402014-06-12 07:24:46 -06005 */
6
7#ifndef _BOOTM_H
8#define _BOOTM_H
9
Simon Glassb6396402014-06-12 07:24:46 -060010#include <image.h>
11
Simon Glass1a081092023-07-30 11:16:53 -060012struct boot_params;
Simon Glass09140112020-05-10 11:40:03 -060013struct cmd_tbl;
14
Simon Glassb6396402014-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 Glassc4921622023-12-15 20:14:12 -070019/**
20 * struct bootm_info() - information used when processing images to boot
21 *
Simon Glassc2211ff2023-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 Glassc4921622023-12-15 20:14:12 -070042 * @images: images information
Simon Glassc2211ff2023-12-15 20:14:14 -070043 * @cmd_name: command which invoked this operation, e.g. "bootm"
Simon Glassc4921622023-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
47 */
48struct bootm_info {
Simon Glassc2211ff2023-12-15 20:14:14 -070049 const char *addr_img;
50 const char *conf_ramdisk;
51 const char *conf_fdt;
52 bool boot_progress;
Simon Glassc4921622023-12-15 20:14:12 -070053 struct bootm_headers *images;
Simon Glassc2211ff2023-12-15 20:14:14 -070054 const char *cmd_name;
Simon Glassc4921622023-12-15 20:14:12 -070055 int argc;
56 char *const *argv;
57};
58
Simon Glassc2211ff2023-12-15 20:14:14 -070059/**
60 * bootm_init() - Set up a bootm_info struct with useful defaults
61 *
62 * Set up the struct with default values for all members:
63 * @boot_progress is set to true and @images is set to the global images
64 * variable. Everything else is set to NULL except @argc which is 0
65 */
66void bootm_init(struct bootm_info *bmi);
67
Simon Glassb6396402014-06-12 07:24:46 -060068/*
69 * Continue booting an OS image; caller already has:
70 * - copied image header to global variable `header'
71 * - checked header magic number, checksums (both header & image),
72 * - verified image architecture (PPC) and type (KERNEL or MULTI),
73 * - loaded (first part of) image to header load address,
74 * - disabled interrupts.
75 *
76 * @flag: Flags indicating what to do (BOOTM_STATE_...)
Simon Glassa48336e2023-12-15 20:14:13 -070077 * bmi: Bootm information
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010078 * Return: 1 on error. On success the OS boots so this function does
Simon Glassb6396402014-06-12 07:24:46 -060079 * not return.
80 */
Simon Glassa48336e2023-12-15 20:14:13 -070081typedef int boot_os_fn(int flag, struct bootm_info *bmi);
Simon Glassb6396402014-06-12 07:24:46 -060082
83extern boot_os_fn do_bootm_linux;
Bin Mengf2a53c72018-12-21 07:13:40 -080084extern boot_os_fn do_bootm_vxworks;
85
Simon Glassc4921622023-12-15 20:14:12 -070086int do_bootelf(struct cmd_tbl *cmdtp, int fglag, int argc, char *const argv[]);
Simon Glassb6396402014-06-12 07:24:46 -060087
88boot_os_fn *bootm_os_get_boot_func(int os);
89
Fabrice Fontaine93e07882019-05-03 22:37:05 +020090#if defined(CONFIG_FIT_SIGNATURE)
Simon Glassce1400f2014-06-12 07:24:53 -060091int bootm_host_load_images(const void *fit, int cfg_noffset);
Fabrice Fontaine93e07882019-05-03 22:37:05 +020092#endif
Simon Glassce1400f2014-06-12 07:24:53 -060093
Simon Glass725ddf12023-12-15 20:14:20 -070094int boot_selected_os(int state, struct bootm_info *bmi, boot_os_fn *boot_fn);
Simon Glassb6396402014-06-12 07:24:46 -060095
96ulong bootm_disable_interrupts(void);
97
Simon Glass3ac85bd2023-11-18 14:05:16 -070098/**
99 * bootm_find_images() - find and locate various images
100 *
101 * @img_addr: Address of image being loaded
102 * @conf_ramdisk: Indicates the ramdisk to use (typically second arg of bootm)
103 * @conf_fdt: Indicates the FDT to use (typically third arg of bootm)
104 * @start: OS image start address
105 * @size: OS image size
106 *
107 * boot_find_images() will attempt to load an available ramdisk,
108 * flattened device tree, as well as specifically marked
109 * "loadable" images (loadables are FIT only)
110 *
111 * Note: bootm_find_images will skip an image if it is not found
112 *
113 * This is a special function used by booti/bootz
114 *
115 * Return:
116 * 0, if all existing images were loaded correctly
117 * 1, if an image is found but corrupted, or invalid
118 */
119int bootm_find_images(ulong img_addr, const char *conf_ramdisk,
120 const char *conf_fdt, ulong start, ulong size);
Simon Glassb6396402014-06-12 07:24:46 -0600121
Eddie Jamesdec166d2023-10-24 10:43:50 -0500122/*
123 * Measure the boot images. Measurement is the process of hashing some binary
124 * data and storing it into secure memory, i.e. TPM PCRs. In addition, each
125 * measurement is logged into the platform event log such that the operating
126 * system can access it and perform attestation of the boot.
127 *
128 * @images: The structure containing the various images to boot (linux,
129 * initrd, dts, etc.)
130 */
131int bootm_measure(struct bootm_headers *images);
132
Simon Glasse370e3d2023-12-15 20:14:15 -0700133/**
Simon Glassb5d397f2023-12-15 20:14:19 -0700134 * bootm_run_states() - Execute selected states of the bootm command.
Simon Glasse370e3d2023-12-15 20:14:15 -0700135 *
136 * Note that if states contains more than one flag it MUST contain
Simon Glassa6c49162023-12-15 20:14:18 -0700137 * BOOTM_STATE_START, since this handles the addr_fit, conf_ramdisk and conf_fit
138 * members of @bmi
Simon Glasse370e3d2023-12-15 20:14:15 -0700139 *
Simon Glassa6c49162023-12-15 20:14:18 -0700140 * Also note that aside from boot_os_fn functions and bootm_load_os, no other
141 * functions store the return value of in 'ret' may use a negative return
Simon Glasse370e3d2023-12-15 20:14:15 -0700142 * value, without special handling.
143 *
Simon Glassa6c49162023-12-15 20:14:18 -0700144 * @bmi: bootm information
145 * @states Mask containing states to run (BOOTM_STATE_...)
Simon Glasse370e3d2023-12-15 20:14:15 -0700146 * Return: 0 if ok, something else on error. Some errors will cause this
147 * function to perform a reboot! If states contains BOOTM_STATE_OS_GO
148 * then the intent is to boot an OS, so this function will not return
149 * unless the image type is standalone.
150 */
Simon Glassb5d397f2023-12-15 20:14:19 -0700151int bootm_run_states(struct bootm_info *bmi, int states);
Simon Glassb6396402014-06-12 07:24:46 -0600152
Simon Glasse1a24c02023-12-15 20:14:21 -0700153/**
Simon Glassd37086a2023-12-15 20:14:26 -0700154 * boot_run() - Run the entire bootm/booti/bootz process
155 *
156 * This runs through the boot process from start to finish, with a base set of
157 * states, along with the extra ones supplied.
158 *
159 * This uses bootm_run_states().
160 *
161 * Note that it is normally easier to use bootm_run(), etc. since they handle
162 * the extra states correctly.
163 *
164 * @bmi: bootm information
165 * @cmd: command being run, NULL if none
166 * @extra_states: Mask of extra states to use for the boot
167 * Return: 0 if ok, something else on error
168 */
169int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states);
170
171/**
Simon Glasse1a24c02023-12-15 20:14:21 -0700172 * bootm_run() - Run the entire bootm process
173 *
174 * This runs through the bootm process from start to finish, using the default
175 * set of states.
176 *
177 * This uses bootm_run_states().
178 *
179 * @bmi: bootm information
180 * Return: 0 if ok, something else on error
181 */
182int bootm_run(struct bootm_info *bmi);
183
Simon Glass3405c9b2023-12-15 20:14:23 -0700184/**
185 * bootz_run() - Run the entire bootz process
186 *
187 * This runs through the bootz process from start to finish, using the default
188 * set of states.
189 *
190 * This uses bootm_run_states().
191 *
192 * @bmi: bootm information
193 * Return: 0 if ok, something else on error
194 */
195int bootz_run(struct bootm_info *bmi);
196
Simon Glasse7683c32023-12-15 20:14:25 -0700197/**
198 * booti_run() - Run the entire booti process
199 *
200 * This runs through the booti process from start to finish, using the default
201 * set of states.
202 *
203 * This uses bootm_run_states().
204 *
205 * @bmi: bootm information
206 * Return: 0 if ok, something else on error
207 */
208int booti_run(struct bootm_info *bmi);
209
Jeroen Hofsteef1bd8712014-10-08 22:58:00 +0200210void arch_preboot_os(void);
211
Simon Glass896019b2018-05-16 09:42:26 -0600212/*
213 * boards should define this to disable devices when EFI exits from boot
214 * services.
215 *
216 * TODO(sjg@chromium.org>): Update this to use driver model's device_remove().
217 */
Simon Glass329da482018-05-16 09:42:25 -0600218void board_quiesce_devices(void);
219
Heinrich Schuchardtf6c6df72019-01-08 18:13:06 +0100220/**
221 * switch_to_non_secure_mode() - switch to non-secure mode
222 */
223void switch_to_non_secure_mode(void);
224
Simon Glassb3c01672020-11-05 10:33:44 -0700225/* Flags to control bootm_process_cmdline() */
226enum bootm_cmdline_t {
227 BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */
Simon Glass51bb3382020-11-05 10:33:48 -0700228 BOOTM_CL_SUBST = 1 << 1, /* Do substitution */
Simon Glassb3c01672020-11-05 10:33:44 -0700229
Simon Glass51bb3382020-11-05 10:33:48 -0700230 BOOTM_CL_ALL = 3, /* All substitutions */
Simon Glassb3c01672020-11-05 10:33:44 -0700231};
232
Heinrich Schuchardt73fdb952020-09-15 01:58:11 +0200233/**
234 * arch_preboot_os() - arch specific configuration before booting
235 */
236void arch_preboot_os(void);
237
238/**
239 * board_preboot_os() - board specific configuration before booting
240 */
241void board_preboot_os(void);
242
Simon Glass4ae42642020-11-05 10:33:39 -0700243/*
Simon Glass4448fe82020-11-05 10:33:45 -0700244 * bootm_process_cmdline() - Process fix-ups for the command line
245 *
Simon Glass51bb3382020-11-05 10:33:48 -0700246 * This handles:
247 *
248 * - making Linux boot silently if requested ('silent_linux' envvar)
249 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass4448fe82020-11-05 10:33:45 -0700250 *
251 * @maxlen must provide enough space for the string being processed plus the
252 * resulting string
253 *
254 * @buf: buffer holding commandline string to adjust
255 * @maxlen: Maximum length of buffer at @buf (including \0)
256 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100257 * Return: 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too
Simon Glass4448fe82020-11-05 10:33:45 -0700258 * long
259 */
260int bootm_process_cmdline(char *buf, int maxlen, int flags);
261
262/**
Simon Glass4dcb8152020-11-05 10:33:40 -0700263 * bootm_process_cmdline_env() - Process fix-ups for the command line
Simon Glass4ae42642020-11-05 10:33:39 -0700264 *
Simon Glass51bb3382020-11-05 10:33:48 -0700265 * Updates the 'bootargs' envvar as required. This handles:
266 *
267 * - making Linux boot silently if requested ('silent_linux' envvar)
268 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass4ae42642020-11-05 10:33:39 -0700269 *
Simon Glassb3c01672020-11-05 10:33:44 -0700270 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100271 * Return: 0 if OK, -ENOMEM if out of memory
Simon Glass4ae42642020-11-05 10:33:39 -0700272 */
Simon Glassb3c01672020-11-05 10:33:44 -0700273int bootm_process_cmdline_env(int flags);
Simon Glassf158ba12020-11-05 10:33:38 -0700274
Simon Glass1a081092023-07-30 11:16:53 -0600275/**
276 * zboot_start() - Boot a zimage
277 *
278 * Boot a zimage, given the component parts
279 *
280 * @addr: Address where the bzImage is moved before booting, either
281 * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
282 * @base: Pointer to the boot parameters, typically at address
283 * DEFAULT_SETUP_BASE
284 * @initrd: Address of the initial ramdisk, or 0 if none
285 * @initrd_size: Size of the initial ramdisk, or 0 if none
286 * @cmdline: Command line to use for booting
287 * Return: -EFAULT on error (normally it does not return)
288 */
289int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
290 ulong base, char *cmdline);
291
292/*
293 * zimage_get_kernel_version() - Get the version string from a kernel
294 *
295 * @params: boot_params pointer
296 * @kernel_base: base address of kernel
297 * Return: Kernel version as a NUL-terminated string
298 */
299const char *zimage_get_kernel_version(struct boot_params *params,
300 void *kernel_base);
301
Simon Glasscbb607d2023-07-30 11:17:00 -0600302/**
303 * zimage_dump() - Dump the metadata of a zimage
304 *
305 * This shows all available information in a zimage that has been loaded.
306 *
307 * @base_ptr: Pointer to the boot parameters, typically at address
308 * DEFAULT_SETUP_BASE
309 * @show_cmdline: true to show the full command line
310 */
311void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
312
Simon Glassdaffb0b2023-07-30 11:17:02 -0600313/*
314 * bootm_boot_start() - Boot an image at the given address
315 *
316 * @addr: Image address
317 * @cmdline: Command line to set
318 */
319int bootm_boot_start(ulong addr, const char *cmdline);
320
Simon Glassb6396402014-06-12 07:24:46 -0600321#endif