blob: f5229ea90b3398e3406da9d52891d92e536e5a13 [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
19/*
20 * Continue booting an OS image; caller already has:
21 * - copied image header to global variable `header'
22 * - checked header magic number, checksums (both header & image),
23 * - verified image architecture (PPC) and type (KERNEL or MULTI),
24 * - loaded (first part of) image to header load address,
25 * - disabled interrupts.
26 *
27 * @flag: Flags indicating what to do (BOOTM_STATE_...)
28 * @argc: Number of arguments. Note that the arguments are shifted down
29 * so that 0 is the first argument not processed by U-Boot, and
30 * argc is adjusted accordingly. This avoids confusion as to how
31 * many arguments are available for the OS.
32 * @images: Pointers to os/initrd/fdt
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010033 * Return: 1 on error. On success the OS boots so this function does
Simon Glass3b5866d2014-06-12 07:24:46 -060034 * not return.
35 */
Simon Glassed38aef2020-05-10 11:40:03 -060036typedef int boot_os_fn(int flag, int argc, char *const argv[],
Simon Glassdf00afa2022-09-06 20:26:50 -060037 struct bootm_headers *images);
Simon Glass3b5866d2014-06-12 07:24:46 -060038
39extern boot_os_fn do_bootm_linux;
Bin Meng54a735a2018-12-21 07:13:40 -080040extern boot_os_fn do_bootm_vxworks;
41
Simon Glassed38aef2020-05-10 11:40:03 -060042int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
Simon Glass3b5866d2014-06-12 07:24:46 -060043
44boot_os_fn *bootm_os_get_boot_func(int os);
45
Fabrice Fontained00d6b52019-05-03 22:37:05 +020046#if defined(CONFIG_FIT_SIGNATURE)
Simon Glassa51991d2014-06-12 07:24:53 -060047int bootm_host_load_images(const void *fit, int cfg_noffset);
Fabrice Fontained00d6b52019-05-03 22:37:05 +020048#endif
Simon Glassa51991d2014-06-12 07:24:53 -060049
Simon Glassed38aef2020-05-10 11:40:03 -060050int boot_selected_os(int argc, char *const argv[], int state,
Simon Glassdf00afa2022-09-06 20:26:50 -060051 struct bootm_headers *images, boot_os_fn *boot_fn);
Simon Glass3b5866d2014-06-12 07:24:46 -060052
53ulong bootm_disable_interrupts(void);
54
Simon Glassd46c81e2023-11-18 14:05:16 -070055/**
56 * bootm_find_images() - find and locate various images
57 *
58 * @img_addr: Address of image being loaded
59 * @conf_ramdisk: Indicates the ramdisk to use (typically second arg of bootm)
60 * @conf_fdt: Indicates the FDT to use (typically third arg of bootm)
61 * @start: OS image start address
62 * @size: OS image size
63 *
64 * boot_find_images() will attempt to load an available ramdisk,
65 * flattened device tree, as well as specifically marked
66 * "loadable" images (loadables are FIT only)
67 *
68 * Note: bootm_find_images will skip an image if it is not found
69 *
70 * This is a special function used by booti/bootz
71 *
72 * Return:
73 * 0, if all existing images were loaded correctly
74 * 1, if an image is found but corrupted, or invalid
75 */
76int bootm_find_images(ulong img_addr, const char *conf_ramdisk,
77 const char *conf_fdt, ulong start, ulong size);
Simon Glass3b5866d2014-06-12 07:24:46 -060078
Eddie James32401ba2023-10-24 10:43:50 -050079/*
80 * Measure the boot images. Measurement is the process of hashing some binary
81 * data and storing it into secure memory, i.e. TPM PCRs. In addition, each
82 * measurement is logged into the platform event log such that the operating
83 * system can access it and perform attestation of the boot.
84 *
85 * @images: The structure containing the various images to boot (linux,
86 * initrd, dts, etc.)
87 */
88int bootm_measure(struct bootm_headers *images);
89
Simon Glassed38aef2020-05-10 11:40:03 -060090int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassdf00afa2022-09-06 20:26:50 -060091 char *const argv[], int states, struct bootm_headers *images,
Simon Glassed38aef2020-05-10 11:40:03 -060092 int boot_progress);
Simon Glass3b5866d2014-06-12 07:24:46 -060093
Jeroen Hofstee7ade3de2014-10-08 22:58:00 +020094void arch_preboot_os(void);
95
Simon Glassc9b2e232018-05-16 09:42:26 -060096/*
97 * boards should define this to disable devices when EFI exits from boot
98 * services.
99 *
100 * TODO(sjg@chromium.org>): Update this to use driver model's device_remove().
101 */
Simon Glassf55305a2018-05-16 09:42:25 -0600102void board_quiesce_devices(void);
103
Heinrich Schuchardtaa0b11b2019-01-08 18:13:06 +0100104/**
105 * switch_to_non_secure_mode() - switch to non-secure mode
106 */
107void switch_to_non_secure_mode(void);
108
Simon Glass63660dc2020-11-05 10:33:44 -0700109/* Flags to control bootm_process_cmdline() */
110enum bootm_cmdline_t {
111 BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */
Simon Glass529e2082020-11-05 10:33:48 -0700112 BOOTM_CL_SUBST = 1 << 1, /* Do substitution */
Simon Glass63660dc2020-11-05 10:33:44 -0700113
Simon Glass529e2082020-11-05 10:33:48 -0700114 BOOTM_CL_ALL = 3, /* All substitutions */
Simon Glass63660dc2020-11-05 10:33:44 -0700115};
116
Heinrich Schuchardt25828e92020-09-15 01:58:11 +0200117/**
118 * arch_preboot_os() - arch specific configuration before booting
119 */
120void arch_preboot_os(void);
121
122/**
123 * board_preboot_os() - board specific configuration before booting
124 */
125void board_preboot_os(void);
126
Simon Glass2eab0172020-11-05 10:33:39 -0700127/*
Simon Glassb4e1b6d2020-11-05 10:33:45 -0700128 * bootm_process_cmdline() - Process fix-ups for the command line
129 *
Simon Glass529e2082020-11-05 10:33:48 -0700130 * This handles:
131 *
132 * - making Linux boot silently if requested ('silent_linux' envvar)
133 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glassb4e1b6d2020-11-05 10:33:45 -0700134 *
135 * @maxlen must provide enough space for the string being processed plus the
136 * resulting string
137 *
138 * @buf: buffer holding commandline string to adjust
139 * @maxlen: Maximum length of buffer at @buf (including \0)
140 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100141 * Return: 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too
Simon Glassb4e1b6d2020-11-05 10:33:45 -0700142 * long
143 */
144int bootm_process_cmdline(char *buf, int maxlen, int flags);
145
146/**
Simon Glassa50b6dd2020-11-05 10:33:40 -0700147 * bootm_process_cmdline_env() - Process fix-ups for the command line
Simon Glass2eab0172020-11-05 10:33:39 -0700148 *
Simon Glass529e2082020-11-05 10:33:48 -0700149 * Updates the 'bootargs' envvar as required. This handles:
150 *
151 * - making Linux boot silently if requested ('silent_linux' envvar)
152 * - performing substitutions in the command line ('bootargs_subst' envvar)
Simon Glass2eab0172020-11-05 10:33:39 -0700153 *
Simon Glass63660dc2020-11-05 10:33:44 -0700154 * @flags: Flags to control what happens (see bootm_cmdline_t)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100155 * Return: 0 if OK, -ENOMEM if out of memory
Simon Glass2eab0172020-11-05 10:33:39 -0700156 */
Simon Glass63660dc2020-11-05 10:33:44 -0700157int bootm_process_cmdline_env(int flags);
Simon Glass07a88862020-11-05 10:33:38 -0700158
Simon Glass4493d612023-07-30 11:16:53 -0600159/**
160 * zboot_start() - Boot a zimage
161 *
162 * Boot a zimage, given the component parts
163 *
164 * @addr: Address where the bzImage is moved before booting, either
165 * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
166 * @base: Pointer to the boot parameters, typically at address
167 * DEFAULT_SETUP_BASE
168 * @initrd: Address of the initial ramdisk, or 0 if none
169 * @initrd_size: Size of the initial ramdisk, or 0 if none
170 * @cmdline: Command line to use for booting
171 * Return: -EFAULT on error (normally it does not return)
172 */
173int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
174 ulong base, char *cmdline);
175
176/*
177 * zimage_get_kernel_version() - Get the version string from a kernel
178 *
179 * @params: boot_params pointer
180 * @kernel_base: base address of kernel
181 * Return: Kernel version as a NUL-terminated string
182 */
183const char *zimage_get_kernel_version(struct boot_params *params,
184 void *kernel_base);
185
Simon Glass5495aaf2023-07-30 11:17:00 -0600186/**
187 * zimage_dump() - Dump the metadata of a zimage
188 *
189 * This shows all available information in a zimage that has been loaded.
190 *
191 * @base_ptr: Pointer to the boot parameters, typically at address
192 * DEFAULT_SETUP_BASE
193 * @show_cmdline: true to show the full command line
194 */
195void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
196
Simon Glass18700262023-07-30 11:17:02 -0600197/*
198 * bootm_boot_start() - Boot an image at the given address
199 *
200 * @addr: Image address
201 * @cmdline: Command line to set
202 */
203int bootm_boot_start(ulong addr, const char *cmdline);
204
Simon Glass3b5866d2014-06-12 07:24:46 -0600205#endif