blob: a6d5d5ceee8f43465563619d439d635fc467a739 [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 *
22 * @images: images information
23 * @argc: Number of arguments to the command (excluding the actual command).
24 * This is 0 if there are no arguments
25 * @argv: NULL-terminated list of arguments, or NULL if there are no arguments
26 */
27struct bootm_info {
28 struct bootm_headers *images;
29 int argc;
30 char *const *argv;
31};
32
Simon Glassb6396402014-06-12 07:24:46 -060033/*
34 * Continue booting an OS image; caller already has:
35 * - copied image header to global variable `header'
36 * - checked header magic number, checksums (both header & image),
37 * - verified image architecture (PPC) and type (KERNEL or MULTI),
38 * - loaded (first part of) image to header load address,
39 * - disabled interrupts.
40 *
41 * @flag: Flags indicating what to do (BOOTM_STATE_...)
42 * @argc: Number of arguments. Note that the arguments are shifted down
43 * so that 0 is the first argument not processed by U-Boot, and
44 * argc is adjusted accordingly. This avoids confusion as to how
45 * many arguments are available for the OS.
46 * @images: Pointers to os/initrd/fdt
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010047 * Return: 1 on error. On success the OS boots so this function does
Simon Glassb6396402014-06-12 07:24:46 -060048 * not return.
49 */
Simon Glass09140112020-05-10 11:40:03 -060050typedef int boot_os_fn(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -060051 struct bootm_headers *images);
Simon Glassb6396402014-06-12 07:24:46 -060052
53extern boot_os_fn do_bootm_linux;
Bin Mengf2a53c72018-12-21 07:13:40 -080054extern boot_os_fn do_bootm_vxworks;
55
Simon Glassc4921622023-12-15 20:14:12 -070056int do_bootelf(struct cmd_tbl *cmdtp, int fglag, int argc, char *const argv[]);
Simon Glassb6396402014-06-12 07:24:46 -060057
58boot_os_fn *bootm_os_get_boot_func(int os);
59
Fabrice Fontaine93e07882019-05-03 22:37:05 +020060#if defined(CONFIG_FIT_SIGNATURE)
Simon Glassce1400f2014-06-12 07:24:53 -060061int bootm_host_load_images(const void *fit, int cfg_noffset);
Fabrice Fontaine93e07882019-05-03 22:37:05 +020062#endif
Simon Glassce1400f2014-06-12 07:24:53 -060063
Simon Glass09140112020-05-10 11:40:03 -060064int boot_selected_os(int argc, char *const argv[], int state,
Simon Glassd9d7c202022-09-06 20:26:50 -060065 struct bootm_headers *images, boot_os_fn *boot_fn);
Simon Glassb6396402014-06-12 07:24:46 -060066
67ulong bootm_disable_interrupts(void);
68
Simon Glass3ac85bd2023-11-18 14:05:16 -070069/**
70 * bootm_find_images() - find and locate various images
71 *
72 * @img_addr: Address of image being loaded
73 * @conf_ramdisk: Indicates the ramdisk to use (typically second arg of bootm)
74 * @conf_fdt: Indicates the FDT to use (typically third arg of bootm)
75 * @start: OS image start address
76 * @size: OS image size
77 *
78 * boot_find_images() will attempt to load an available ramdisk,
79 * flattened device tree, as well as specifically marked
80 * "loadable" images (loadables are FIT only)
81 *
82 * Note: bootm_find_images will skip an image if it is not found
83 *
84 * This is a special function used by booti/bootz
85 *
86 * Return:
87 * 0, if all existing images were loaded correctly
88 * 1, if an image is found but corrupted, or invalid
89 */
90int bootm_find_images(ulong img_addr, const char *conf_ramdisk,
91 const char *conf_fdt, ulong start, ulong size);
Simon Glassb6396402014-06-12 07:24:46 -060092
Eddie Jamesdec166d2023-10-24 10:43:50 -050093/*
94 * Measure the boot images. Measurement is the process of hashing some binary
95 * data and storing it into secure memory, i.e. TPM PCRs. In addition, each
96 * measurement is logged into the platform event log such that the operating
97 * system can access it and perform attestation of the boot.
98 *
99 * @images: The structure containing the various images to boot (linux,
100 * initrd, dts, etc.)
101 */
102int bootm_measure(struct bootm_headers *images);
103
Simon Glass09140112020-05-10 11:40:03 -0600104int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassd9d7c202022-09-06 20:26:50 -0600105 char *const argv[], int states, struct bootm_headers *images,
Simon Glass09140112020-05-10 11:40:03 -0600106 int boot_progress);
Simon Glassb6396402014-06-12 07:24:46 -0600107
Jeroen Hofsteef1bd8712014-10-08 22:58:00 +0200108void arch_preboot_os(void);
109
Simon Glass896019b2018-05-16 09:42:26 -0600110/*
111 * boards should define this to disable devices when EFI exits from boot
112 * services.
113 *
114 * TODO(sjg@chromium.org>): Update this to use driver model's device_remove().
115 */
Simon Glass329da482018-05-16 09:42:25 -0600116void board_quiesce_devices(void);
117
Heinrich Schuchardtf6c6df72019-01-08 18:13:06 +0100118/**
119 * switch_to_non_secure_mode() - switch to non-secure mode
120 */
121void switch_to_non_secure_mode(void);
122
Simon Glassb3c01672020-11-05 10:33:44 -0700123/* Flags to control bootm_process_cmdline() */
124enum bootm_cmdline_t {
125 BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */
Simon Glass51bb3382020-11-05 10:33:48 -0700126 BOOTM_CL_SUBST = 1 << 1, /* Do substitution */
Simon Glassb3c01672020-11-05 10:33:44 -0700127
Simon Glass51bb3382020-11-05 10:33:48 -0700128 BOOTM_CL_ALL = 3, /* All substitutions */
Simon Glassb3c01672020-11-05 10:33:44 -0700129};
130
Heinrich Schuchardt73fdb952020-09-15 01:58:11 +0200131/**
132 * arch_preboot_os() - arch specific configuration before booting
133 */
134void arch_preboot_os(void);
135
136/**
137 * board_preboot_os() - board specific configuration before booting
138 */
139void board_preboot_os(void);
140
Simon Glass4ae42642020-11-05 10:33:39 -0700141/*
Simon Glass4448fe82020-11-05 10:33:45 -0700142 * bootm_process_cmdline() - Process fix-ups for the command line
143 *
Simon Glass51bb3382020-11-05 10:33:48 -0700144 * This handles:
145 *
146 * - making Linux boot silently if requested ('silent_linux' envvar)
147 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass4448fe82020-11-05 10:33:45 -0700148 *
149 * @maxlen must provide enough space for the string being processed plus the
150 * resulting string
151 *
152 * @buf: buffer holding commandline string to adjust
153 * @maxlen: Maximum length of buffer at @buf (including \0)
154 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100155 * Return: 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too
Simon Glass4448fe82020-11-05 10:33:45 -0700156 * long
157 */
158int bootm_process_cmdline(char *buf, int maxlen, int flags);
159
160/**
Simon Glass4dcb8152020-11-05 10:33:40 -0700161 * bootm_process_cmdline_env() - Process fix-ups for the command line
Simon Glass4ae42642020-11-05 10:33:39 -0700162 *
Simon Glass51bb3382020-11-05 10:33:48 -0700163 * Updates the 'bootargs' envvar as required. This handles:
164 *
165 * - making Linux boot silently if requested ('silent_linux' envvar)
166 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass4ae42642020-11-05 10:33:39 -0700167 *
Simon Glassb3c01672020-11-05 10:33:44 -0700168 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100169 * Return: 0 if OK, -ENOMEM if out of memory
Simon Glass4ae42642020-11-05 10:33:39 -0700170 */
Simon Glassb3c01672020-11-05 10:33:44 -0700171int bootm_process_cmdline_env(int flags);
Simon Glassf158ba12020-11-05 10:33:38 -0700172
Simon Glass1a081092023-07-30 11:16:53 -0600173/**
174 * zboot_start() - Boot a zimage
175 *
176 * Boot a zimage, given the component parts
177 *
178 * @addr: Address where the bzImage is moved before booting, either
179 * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
180 * @base: Pointer to the boot parameters, typically at address
181 * DEFAULT_SETUP_BASE
182 * @initrd: Address of the initial ramdisk, or 0 if none
183 * @initrd_size: Size of the initial ramdisk, or 0 if none
184 * @cmdline: Command line to use for booting
185 * Return: -EFAULT on error (normally it does not return)
186 */
187int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
188 ulong base, char *cmdline);
189
190/*
191 * zimage_get_kernel_version() - Get the version string from a kernel
192 *
193 * @params: boot_params pointer
194 * @kernel_base: base address of kernel
195 * Return: Kernel version as a NUL-terminated string
196 */
197const char *zimage_get_kernel_version(struct boot_params *params,
198 void *kernel_base);
199
Simon Glasscbb607d2023-07-30 11:17:00 -0600200/**
201 * zimage_dump() - Dump the metadata of a zimage
202 *
203 * This shows all available information in a zimage that has been loaded.
204 *
205 * @base_ptr: Pointer to the boot parameters, typically at address
206 * DEFAULT_SETUP_BASE
207 * @show_cmdline: true to show the full command line
208 */
209void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
210
Simon Glassdaffb0b2023-07-30 11:17:02 -0600211/*
212 * bootm_boot_start() - Boot an image at the given address
213 *
214 * @addr: Image address
215 * @cmdline: Command line to set
216 */
217int bootm_boot_start(ulong addr, const char *cmdline);
218
Simon Glassb6396402014-06-12 07:24:46 -0600219#endif