Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef _BOOTM_H |
| 8 | #define _BOOTM_H |
| 9 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 10 | #include <image.h> |
| 11 | |
Simon Glass | 1a08109 | 2023-07-30 11:16:53 -0600 | [diff] [blame] | 12 | struct boot_params; |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 13 | struct cmd_tbl; |
| 14 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 15 | #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 Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 33 | * Return: 1 on error. On success the OS boots so this function does |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 34 | * not return. |
| 35 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 36 | typedef int boot_os_fn(int flag, int argc, char *const argv[], |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 37 | struct bootm_headers *images); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 38 | |
| 39 | extern boot_os_fn do_bootm_linux; |
Bin Meng | f2a53c7 | 2018-12-21 07:13:40 -0800 | [diff] [blame] | 40 | extern boot_os_fn do_bootm_vxworks; |
| 41 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 42 | int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 43 | |
| 44 | boot_os_fn *bootm_os_get_boot_func(int os); |
| 45 | |
Fabrice Fontaine | 93e0788 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 46 | #if defined(CONFIG_FIT_SIGNATURE) |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 47 | int bootm_host_load_images(const void *fit, int cfg_noffset); |
Fabrice Fontaine | 93e0788 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 48 | #endif |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 49 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 50 | int boot_selected_os(int argc, char *const argv[], int state, |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 51 | struct bootm_headers *images, boot_os_fn *boot_fn); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 52 | |
| 53 | ulong bootm_disable_interrupts(void); |
| 54 | |
Tom Rini | d2b2ffe | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 55 | /* This is a special function used by booti/bootz */ |
Tero Kristo | fbde758 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 56 | int bootm_find_images(int flag, int argc, char *const argv[], ulong start, |
| 57 | ulong size); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 58 | |
Eddie James | dec166d | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 59 | /* |
| 60 | * Measure the boot images. Measurement is the process of hashing some binary |
| 61 | * data and storing it into secure memory, i.e. TPM PCRs. In addition, each |
| 62 | * measurement is logged into the platform event log such that the operating |
| 63 | * system can access it and perform attestation of the boot. |
| 64 | * |
| 65 | * @images: The structure containing the various images to boot (linux, |
| 66 | * initrd, dts, etc.) |
| 67 | */ |
| 68 | int bootm_measure(struct bootm_headers *images); |
| 69 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 70 | int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 71 | char *const argv[], int states, struct bootm_headers *images, |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 72 | int boot_progress); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 73 | |
Jeroen Hofstee | f1bd871 | 2014-10-08 22:58:00 +0200 | [diff] [blame] | 74 | void arch_preboot_os(void); |
| 75 | |
Simon Glass | 896019b | 2018-05-16 09:42:26 -0600 | [diff] [blame] | 76 | /* |
| 77 | * boards should define this to disable devices when EFI exits from boot |
| 78 | * services. |
| 79 | * |
| 80 | * TODO(sjg@chromium.org>): Update this to use driver model's device_remove(). |
| 81 | */ |
Simon Glass | 329da48 | 2018-05-16 09:42:25 -0600 | [diff] [blame] | 82 | void board_quiesce_devices(void); |
| 83 | |
Heinrich Schuchardt | f6c6df7 | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 84 | /** |
| 85 | * switch_to_non_secure_mode() - switch to non-secure mode |
| 86 | */ |
| 87 | void switch_to_non_secure_mode(void); |
| 88 | |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 89 | /* Flags to control bootm_process_cmdline() */ |
| 90 | enum bootm_cmdline_t { |
| 91 | BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */ |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 92 | BOOTM_CL_SUBST = 1 << 1, /* Do substitution */ |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 93 | |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 94 | BOOTM_CL_ALL = 3, /* All substitutions */ |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Heinrich Schuchardt | 73fdb95 | 2020-09-15 01:58:11 +0200 | [diff] [blame] | 97 | /** |
| 98 | * arch_preboot_os() - arch specific configuration before booting |
| 99 | */ |
| 100 | void arch_preboot_os(void); |
| 101 | |
| 102 | /** |
| 103 | * board_preboot_os() - board specific configuration before booting |
| 104 | */ |
| 105 | void board_preboot_os(void); |
| 106 | |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 107 | /* |
Simon Glass | 4448fe8 | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 108 | * bootm_process_cmdline() - Process fix-ups for the command line |
| 109 | * |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 110 | * This handles: |
| 111 | * |
| 112 | * - making Linux boot silently if requested ('silent_linux' envvar) |
| 113 | * - performing substitutions in the command line ('bootargs_subst' envvar) |
Simon Glass | 4448fe8 | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 114 | * |
| 115 | * @maxlen must provide enough space for the string being processed plus the |
| 116 | * resulting string |
| 117 | * |
| 118 | * @buf: buffer holding commandline string to adjust |
| 119 | * @maxlen: Maximum length of buffer at @buf (including \0) |
| 120 | * @flags: Flags to control what happens (see bootm_cmdline_t) |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 121 | * Return: 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too |
Simon Glass | 4448fe8 | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 122 | * long |
| 123 | */ |
| 124 | int bootm_process_cmdline(char *buf, int maxlen, int flags); |
| 125 | |
| 126 | /** |
Simon Glass | 4dcb815 | 2020-11-05 10:33:40 -0700 | [diff] [blame] | 127 | * bootm_process_cmdline_env() - Process fix-ups for the command line |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 128 | * |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 129 | * Updates the 'bootargs' envvar as required. This handles: |
| 130 | * |
| 131 | * - making Linux boot silently if requested ('silent_linux' envvar) |
| 132 | * - performing substitutions in the command line ('bootargs_subst' envvar) |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 133 | * |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 134 | * @flags: Flags to control what happens (see bootm_cmdline_t) |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 135 | * Return: 0 if OK, -ENOMEM if out of memory |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 136 | */ |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 137 | int bootm_process_cmdline_env(int flags); |
Simon Glass | f158ba1 | 2020-11-05 10:33:38 -0700 | [diff] [blame] | 138 | |
Simon Glass | 1a08109 | 2023-07-30 11:16:53 -0600 | [diff] [blame] | 139 | /** |
Simon Glass | d2c485a | 2023-12-03 17:29:35 -0700 | [diff] [blame] | 140 | * zboot_run() - Run through the various steps to boot a zimage |
Simon Glass | 1a08109 | 2023-07-30 11:16:53 -0600 | [diff] [blame] | 141 | * |
| 142 | * Boot a zimage, given the component parts |
| 143 | * |
| 144 | * @addr: Address where the bzImage is moved before booting, either |
| 145 | * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR |
Simon Glass | 8d24535 | 2023-12-03 17:29:38 -0700 | [diff] [blame^] | 146 | * @size: Size of bzImage, or 0 to detect this |
Simon Glass | 1a08109 | 2023-07-30 11:16:53 -0600 | [diff] [blame] | 147 | * @initrd: Address of the initial ramdisk, or 0 if none |
| 148 | * @initrd_size: Size of the initial ramdisk, or 0 if none |
Simon Glass | 8d24535 | 2023-12-03 17:29:38 -0700 | [diff] [blame^] | 149 | * @base_addr: If non-zero, this indicates that the boot parameters have already |
| 150 | * been loaded by the caller to this address, so the load_zimage() call |
| 151 | * in zboot_load() will be skipped when booting |
| 152 | * @cmdline: If non-NULL, the environment variable containing the command line |
| 153 | * to use for booting |
Simon Glass | 1a08109 | 2023-07-30 11:16:53 -0600 | [diff] [blame] | 154 | * Return: -EFAULT on error (normally it does not return) |
| 155 | */ |
Simon Glass | d2c485a | 2023-12-03 17:29:35 -0700 | [diff] [blame] | 156 | int zboot_run(ulong addr, ulong size, ulong initrd, ulong initrd_size, |
| 157 | ulong base, char *cmdline); |
Simon Glass | 1a08109 | 2023-07-30 11:16:53 -0600 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * zimage_get_kernel_version() - Get the version string from a kernel |
| 161 | * |
| 162 | * @params: boot_params pointer |
| 163 | * @kernel_base: base address of kernel |
| 164 | * Return: Kernel version as a NUL-terminated string |
| 165 | */ |
| 166 | const char *zimage_get_kernel_version(struct boot_params *params, |
| 167 | void *kernel_base); |
| 168 | |
Simon Glass | cbb607d | 2023-07-30 11:17:00 -0600 | [diff] [blame] | 169 | /** |
| 170 | * zimage_dump() - Dump the metadata of a zimage |
| 171 | * |
| 172 | * This shows all available information in a zimage that has been loaded. |
| 173 | * |
| 174 | * @base_ptr: Pointer to the boot parameters, typically at address |
| 175 | * DEFAULT_SETUP_BASE |
| 176 | * @show_cmdline: true to show the full command line |
| 177 | */ |
| 178 | void zimage_dump(struct boot_params *base_ptr, bool show_cmdline); |
| 179 | |
Simon Glass | daffb0b | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 180 | /* |
| 181 | * bootm_boot_start() - Boot an image at the given address |
| 182 | * |
| 183 | * @addr: Image address |
| 184 | * @cmdline: Command line to set |
| 185 | */ |
| 186 | int bootm_boot_start(ulong addr, const char *cmdline); |
| 187 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 188 | #endif |