blob: 85c560d5a0aebba549261f03a541149f2770dfa9 [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_...)
Simon Glassa48336e2023-12-15 20:14:13 -070042 * bmi: Bootm information
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010043 * Return: 1 on error. On success the OS boots so this function does
Simon Glassb6396402014-06-12 07:24:46 -060044 * not return.
45 */
Simon Glassa48336e2023-12-15 20:14:13 -070046typedef int boot_os_fn(int flag, struct bootm_info *bmi);
Simon Glassb6396402014-06-12 07:24:46 -060047
48extern boot_os_fn do_bootm_linux;
Bin Mengf2a53c72018-12-21 07:13:40 -080049extern boot_os_fn do_bootm_vxworks;
50
Simon Glassc4921622023-12-15 20:14:12 -070051int do_bootelf(struct cmd_tbl *cmdtp, int fglag, int argc, char *const argv[]);
Simon Glassb6396402014-06-12 07:24:46 -060052
53boot_os_fn *bootm_os_get_boot_func(int os);
54
Fabrice Fontaine93e07882019-05-03 22:37:05 +020055#if defined(CONFIG_FIT_SIGNATURE)
Simon Glassce1400f2014-06-12 07:24:53 -060056int bootm_host_load_images(const void *fit, int cfg_noffset);
Fabrice Fontaine93e07882019-05-03 22:37:05 +020057#endif
Simon Glassce1400f2014-06-12 07:24:53 -060058
Simon Glass09140112020-05-10 11:40:03 -060059int boot_selected_os(int argc, char *const argv[], int state,
Simon Glassd9d7c202022-09-06 20:26:50 -060060 struct bootm_headers *images, boot_os_fn *boot_fn);
Simon Glassb6396402014-06-12 07:24:46 -060061
62ulong bootm_disable_interrupts(void);
63
Simon Glass3ac85bd2023-11-18 14:05:16 -070064/**
65 * bootm_find_images() - find and locate various images
66 *
67 * @img_addr: Address of image being loaded
68 * @conf_ramdisk: Indicates the ramdisk to use (typically second arg of bootm)
69 * @conf_fdt: Indicates the FDT to use (typically third arg of bootm)
70 * @start: OS image start address
71 * @size: OS image size
72 *
73 * boot_find_images() will attempt to load an available ramdisk,
74 * flattened device tree, as well as specifically marked
75 * "loadable" images (loadables are FIT only)
76 *
77 * Note: bootm_find_images will skip an image if it is not found
78 *
79 * This is a special function used by booti/bootz
80 *
81 * Return:
82 * 0, if all existing images were loaded correctly
83 * 1, if an image is found but corrupted, or invalid
84 */
85int bootm_find_images(ulong img_addr, const char *conf_ramdisk,
86 const char *conf_fdt, ulong start, ulong size);
Simon Glassb6396402014-06-12 07:24:46 -060087
Eddie Jamesdec166d2023-10-24 10:43:50 -050088/*
89 * Measure the boot images. Measurement is the process of hashing some binary
90 * data and storing it into secure memory, i.e. TPM PCRs. In addition, each
91 * measurement is logged into the platform event log such that the operating
92 * system can access it and perform attestation of the boot.
93 *
94 * @images: The structure containing the various images to boot (linux,
95 * initrd, dts, etc.)
96 */
97int bootm_measure(struct bootm_headers *images);
98
Simon Glass09140112020-05-10 11:40:03 -060099int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassd9d7c202022-09-06 20:26:50 -0600100 char *const argv[], int states, struct bootm_headers *images,
Simon Glass09140112020-05-10 11:40:03 -0600101 int boot_progress);
Simon Glassb6396402014-06-12 07:24:46 -0600102
Jeroen Hofsteef1bd8712014-10-08 22:58:00 +0200103void arch_preboot_os(void);
104
Simon Glass896019b2018-05-16 09:42:26 -0600105/*
106 * boards should define this to disable devices when EFI exits from boot
107 * services.
108 *
109 * TODO(sjg@chromium.org>): Update this to use driver model's device_remove().
110 */
Simon Glass329da482018-05-16 09:42:25 -0600111void board_quiesce_devices(void);
112
Heinrich Schuchardtf6c6df72019-01-08 18:13:06 +0100113/**
114 * switch_to_non_secure_mode() - switch to non-secure mode
115 */
116void switch_to_non_secure_mode(void);
117
Simon Glassb3c01672020-11-05 10:33:44 -0700118/* Flags to control bootm_process_cmdline() */
119enum bootm_cmdline_t {
120 BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */
Simon Glass51bb3382020-11-05 10:33:48 -0700121 BOOTM_CL_SUBST = 1 << 1, /* Do substitution */
Simon Glassb3c01672020-11-05 10:33:44 -0700122
Simon Glass51bb3382020-11-05 10:33:48 -0700123 BOOTM_CL_ALL = 3, /* All substitutions */
Simon Glassb3c01672020-11-05 10:33:44 -0700124};
125
Heinrich Schuchardt73fdb952020-09-15 01:58:11 +0200126/**
127 * arch_preboot_os() - arch specific configuration before booting
128 */
129void arch_preboot_os(void);
130
131/**
132 * board_preboot_os() - board specific configuration before booting
133 */
134void board_preboot_os(void);
135
Simon Glass4ae42642020-11-05 10:33:39 -0700136/*
Simon Glass4448fe82020-11-05 10:33:45 -0700137 * bootm_process_cmdline() - Process fix-ups for the command line
138 *
Simon Glass51bb3382020-11-05 10:33:48 -0700139 * This handles:
140 *
141 * - making Linux boot silently if requested ('silent_linux' envvar)
142 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass4448fe82020-11-05 10:33:45 -0700143 *
144 * @maxlen must provide enough space for the string being processed plus the
145 * resulting string
146 *
147 * @buf: buffer holding commandline string to adjust
148 * @maxlen: Maximum length of buffer at @buf (including \0)
149 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100150 * Return: 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too
Simon Glass4448fe82020-11-05 10:33:45 -0700151 * long
152 */
153int bootm_process_cmdline(char *buf, int maxlen, int flags);
154
155/**
Simon Glass4dcb8152020-11-05 10:33:40 -0700156 * bootm_process_cmdline_env() - Process fix-ups for the command line
Simon Glass4ae42642020-11-05 10:33:39 -0700157 *
Simon Glass51bb3382020-11-05 10:33:48 -0700158 * Updates the 'bootargs' envvar as required. This handles:
159 *
160 * - making Linux boot silently if requested ('silent_linux' envvar)
161 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass4ae42642020-11-05 10:33:39 -0700162 *
Simon Glassb3c01672020-11-05 10:33:44 -0700163 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100164 * Return: 0 if OK, -ENOMEM if out of memory
Simon Glass4ae42642020-11-05 10:33:39 -0700165 */
Simon Glassb3c01672020-11-05 10:33:44 -0700166int bootm_process_cmdline_env(int flags);
Simon Glassf158ba12020-11-05 10:33:38 -0700167
Simon Glass1a081092023-07-30 11:16:53 -0600168/**
169 * zboot_start() - Boot a zimage
170 *
171 * Boot a zimage, given the component parts
172 *
173 * @addr: Address where the bzImage is moved before booting, either
174 * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
175 * @base: Pointer to the boot parameters, typically at address
176 * DEFAULT_SETUP_BASE
177 * @initrd: Address of the initial ramdisk, or 0 if none
178 * @initrd_size: Size of the initial ramdisk, or 0 if none
179 * @cmdline: Command line to use for booting
180 * Return: -EFAULT on error (normally it does not return)
181 */
182int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
183 ulong base, char *cmdline);
184
185/*
186 * zimage_get_kernel_version() - Get the version string from a kernel
187 *
188 * @params: boot_params pointer
189 * @kernel_base: base address of kernel
190 * Return: Kernel version as a NUL-terminated string
191 */
192const char *zimage_get_kernel_version(struct boot_params *params,
193 void *kernel_base);
194
Simon Glasscbb607d2023-07-30 11:17:00 -0600195/**
196 * zimage_dump() - Dump the metadata of a zimage
197 *
198 * This shows all available information in a zimage that has been loaded.
199 *
200 * @base_ptr: Pointer to the boot parameters, typically at address
201 * DEFAULT_SETUP_BASE
202 * @show_cmdline: true to show the full command line
203 */
204void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
205
Simon Glassdaffb0b2023-07-30 11:17:02 -0600206/*
207 * bootm_boot_start() - Boot an image at the given address
208 *
209 * @addr: Image address
210 * @cmdline: Command line to set
211 */
212int bootm_boot_start(ulong addr, const char *cmdline);
213
Simon Glassb6396402014-06-12 07:24:46 -0600214#endif