Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | /* SPDX-License-Identifier: GPL-2.0+ */ /* * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */ #ifndef _BOOTM_H #define _BOOTM_H #include <event_decl.h> #include <image.h> struct boot_params; struct cmd_tbl; #define BOOTM_ERR_RESET (-1) #define BOOTM_ERR_OVERLAP (-2) #define BOOTM_ERR_UNIMPLEMENTED (-3) /** * struct bootm_info() - information used when processing images to boot * * These mirror the first three arguments of the bootm command. They are * designed to handle any type of image, but typically it is a FIT. * * @addr_img: Address of image to bootm, as passed to * genimg_get_kernel_addr_fit() for processing: * * NULL: Usees default load address, i.e. image_load_addr * <addr>: Uses hex address * * For FIT: * "[<addr>]#<conf>": Uses address (or image_load_addr) and also specifies * the FIT configuration to use * "[<addr>]:<subimage>": Uses address (or image_load_addr) and also * specifies the subimage name containing the OS * * @conf_ramdisk: Address (or with FIT, the name) of the ramdisk image, as * passed to boot_get_ramdisk() for processing, or NULL for none * @conf_fdt: Address (or with FIT, the name) of the FDT image, as passed to * boot_get_fdt() for processing, or NULL for none * @boot_progress: true to show boot progress * @images: images information * @cmd_name: command which invoked this operation, e.g. "bootm" * @argc: Number of arguments to the command (excluding the actual command). * This is 0 if there are no arguments * @argv: NULL-terminated list of arguments, or NULL if there are no arguments * @ignore_bootm_len: Ignore the value CONFIG_SYS_BOOTM_LEN and use 10x the * compressed length as the maximum uncompressed size * @kern_comp_addr: Address to decompress the kernel to, if needed. If 0, space * is reserved using lmb and this value is updated * @kern_comp_size: Maximum size of the decompressed kernel. If 0, the size is * calculated based on 4x the size of the kernel, up to a limit of 1G * @os_size: Size of the loaded OS image in bytes, 0 if not loaded/not known * * For zboot: * @bzimage_addr: Address of the bzImage to boot, or 0 if the image has already * been loaded and does not exist (as a cohesive whole) in memory * @bzimage_size: Size of the bzImage, or 0 to detect this * @initrd_addr: Address of the initial ramdisk, or 0 if none * @initrd_size: Size of the initial ramdisk, or 0 if none * @load_address: Address where the bzImage is moved before booting, either * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR * This is set up when loading the zimage * @base_ptr: Pointer to the boot parameters, typically at address * DEFAULT_SETUP_BASE * This is set up when loading the zimage * @cmdline: Environment variable containing the 'override' command line, or * NULL to use the one in the setup block */ struct bootm_info { const char *addr_img; const char *conf_ramdisk; const char *conf_fdt; bool boot_progress; struct bootm_headers *images; const char *cmd_name; int argc; char *const *argv; bool ignore_bootm_len; ulong os_size; ulong kern_comp_addr; ulong kern_comp_size; /* zboot items */ #ifdef CONFIG_X86 ulong bzimage_addr; ulong bzimage_size; ulong initrd_addr; ulong initrd_size; ulong load_address; struct boot_params *base_ptr; const char *cmdline; #endif }; /* macro to allow setting fields in generic code */ #ifdef CONFIG_X86 #define bootm_x86_set(_bmi, _field, _val) (_bmi)->_field = (_val) #else #define bootm_x86_set(_bmi, _field, _val) #endif /* length of strings needed to hold an address within struct bootm_info */ enum { BOOTM_STRLEN = 2 * sizeof(long) + 1, }; /** * bootm_set_addr_img() - Set the address of an image * * This only supports setting a single address, with no FIT configuration, etc. * * @bmi: Bootm information * @addr: Address to set * @str: String to hold the address (must be maintained by the caller) */ void bootm_set_addr_img_(struct bootm_info *bmi, ulong addr, char str[BOOTM_STRLEN]); #define bootm_set_addr_img(bmi, addr, str) \ ({ \ _Static_assert(sizeof(str) >= BOOTM_STRLEN, \ "string buffer too small"); \ bootm_set_addr_img_(bmi, addr, str); \ }) /** * bootm_set_conf_ramdisk() - Set the address of a ramdisk * * This only supports setting a single address, with no FIT configuration, etc. * * @bmi: Bootm information * @addr: Address to set * @str: String to hold the address (must be maintained by the caller) */ void bootm_set_conf_ramdisk_(struct bootm_info *bmi, ulong addr, char str[BOOTM_STRLEN]); #define bootm_set_conf_ramdisk(bmi, addr, str) \ ({ \ _Static_assert(sizeof(str) >= BOOTM_STRLEN, \ "string buffer too small"); \ bootm_set_conf_ramdisk_(bmi, addr, str); \ }) /** * bootm_set_conf_fdt() - Set the address of the FDT * * This only supports setting a single address, with no FIT configuration, etc. * * @bmi: Bootm information * @addr: Address to set * @str: String to hold the address (must be maintained by the caller) */ void bootm_set_conf_fdt_(struct bootm_info *bmi, ulong addr, char str[BOOTM_STRLEN]); #define bootm_set_conf_fdt(bmi, addr, str) \ ({ \ _Static_assert(sizeof(str) >= BOOTM_STRLEN, \ "string buffer too small"); \ bootm_set_conf_fdt_(bmi, addr, str); \ }) static inline ulong bootm_len(void) { #ifdef CONFIG_SYS_BOOTM_LEN return CONFIG_SYS_BOOTM_LEN; #endif return 0; } /** * bootm_read_env() - Read environment variables used during the boot * * If bootm needs to decompress a kernel, it can use the 'kernel_comp_addr_r' * and 'kernel_comp_size' variables to specify a region to decompress into. * Call this function after bootm_init() to set up these variables. Otherwise, * space will be reserved using lmb */ void bootm_read_env(struct bootm_info *bmi); /** * bootm_init() - Set up a bootm_info struct with useful defaults * * @bmi: Bootm information * * Set up the struct with default values for all members: * @boot_progress is set to true and @images is set to the global images * variable. Everything else is set to NULL except @argc which is 0 */ void bootm_init(struct bootm_info *bmi); /* * Continue booting an OS image; caller already has: * - copied image header to global variable `header' * - checked header magic number, checksums (both header & image), * - verified image architecture (PPC) and type (KERNEL or MULTI), * - loaded (first part of) image to header load address, * - disabled interrupts. * * @flag: Flags indicating what to do (BOOTM_STATE_...) * @bmi: Bootm information * Return: 1 on error. On success the OS boots so this function does * not return. */ typedef int boot_os_fn(int flag, struct bootm_info *bmi); extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks; int do_bootelf(struct cmd_tbl *cmdtp, int fglag, int argc, char *const argv[]); boot_os_fn *bootm_os_get_boot_func(int os); #if defined(CONFIG_FIT_SIGNATURE) int bootm_host_load_images(const void *fit, int cfg_noffset); #endif int boot_selected_os(int state, struct bootm_info *bmi, boot_os_fn *boot_fn); ulong bootm_disable_interrupts(void); /** * bootm_find_images() - find and locate various images * * @img_addr: Address of image being loaded * @conf_ramdisk: Indicates the ramdisk to use (typically second arg of bootm) * @conf_fdt: Indicates the FDT to use (typically third arg of bootm) * @start: OS image start address * @size: OS image size * * boot_find_images() will attempt to load an available ramdisk, * flattened device tree, as well as specifically marked * "loadable" images (loadables are FIT only) * * Note: bootm_find_images will skip an image if it is not found * * This is a special function used by booti/bootz * * Return: * 0, if all existing images were loaded correctly * 1, if an image is found but corrupted, or invalid */ int bootm_find_images(ulong img_addr, const char *conf_ramdisk, const char *conf_fdt, ulong start, ulong size); /* * Measure the boot images. Measurement is the process of hashing some binary * data and storing it into secure memory, i.e. TPM PCRs. In addition, each * measurement is logged into the platform event log such that the operating * system can access it and perform attestation of the boot. * * @images: The structure containing the various images to boot (linux, * initrd, dts, etc.) */ int bootm_measure(struct bootm_headers *images); /** * bootm_run_states() - Execute selected states of the bootm command. * * Note that if states contains more than one flag it MUST contain * BOOTM_STATE_START, since this handles the addr_fit, conf_ramdisk and conf_fit * members of @bmi * * Also note that aside from boot_os_fn functions and bootm_load_os, no other * functions store the return value of in 'ret' may use a negative return * value, without special handling. * * @bmi: bootm information * @states Mask containing states to run (BOOTM_STATE_...) * Return: 0 if ok, -ENOPKG if a 'load-only' FIT was loaded and there is no OS * to load, something else on error. Some errors will cause this * function to perform a reboot! If states contains BOOTM_STATE_OS_GO * then the intent is to boot an OS, so this function will not return * unless the image type is standalone or this is a=. */ int bootm_run_states(struct bootm_info *bmi, int states); /** * boot_run() - Run the entire bootm/booti/bootz process * * This runs through the boot process from start to finish, with a base set of * states, along with the extra ones supplied. * * This uses bootm_run_states(). * * Note that it is normally easier to use bootm_run(), etc. since they handle * the extra states correctly. * * @bmi: bootm information * @cmd: command being run, NULL if none * @extra_states: Mask of extra states to use for the boot * Return: 0 if ok, something else on error */ int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states); /** * bootm_run() - Run the entire bootm process * * This runs through the bootm process from start to finish, using the default * set of states. * * This uses bootm_run_states(). * * @bmi: bootm information * Return: 0 if ok, something else on error */ int bootm_run(struct bootm_info *bmi); /** * bootz_run() - Run the entire bootz process * * This runs through the bootz process from start to finish, using the default * set of states. * * This uses bootm_run_states(). * * @bmi: bootm information * Return: 0 if ok, something else on error */ int bootz_run(struct bootm_info *bmi); /** * booti_run() - Run the entire booti process * * This runs through the booti process from start to finish, using the default * set of states. * * This uses bootm_run_states(). * * @bmi: bootm information * Return: 0 if ok, something else on error */ int booti_run(struct bootm_info *bmi); void arch_preboot_os(void); /* * boards should define this to disable devices when EFI exits from boot * services. * * TODO(sjg@chromium.org>): Update this to use driver model's device_remove(). */ void board_quiesce_devices(void); /** * switch_to_non_secure_mode() - switch to non-secure mode */ void switch_to_non_secure_mode(void); /* Flags to control bootm_process_cmdline() */ enum bootm_cmdline_t { BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */ BOOTM_CL_SUBST = 1 << 1, /* Do substitution */ BOOTM_CL_ALL = 3, /* All substitutions */ }; /** * arch_preboot_os() - arch specific configuration before booting */ void arch_preboot_os(void); /** * board_preboot_os() - board specific configuration before booting */ void board_preboot_os(void); /* * bootm_process_cmdline() - Process fix-ups for the command line * * This handles: * * - making Linux boot silently if requested ('silent_linux' envvar) * - performing substitutions in the command line ('bootargs_subst' envvar) * * @maxlen must provide enough space for the string being processed plus the * resulting string * * @buf: buffer holding commandline string to adjust * @maxlen: Maximum length of buffer at @buf (including \0) * @flags: Flags to control what happens (see bootm_cmdline_t) * Return: 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too * long */ int bootm_process_cmdline(char *buf, int maxlen, int flags); /** * bootm_process_cmdline_env() - Process fix-ups for the command line * * Updates the 'bootargs' envvar as required. This handles: * * - making Linux boot silently if requested ('silent_linux' envvar) * - performing substitutions in the command line ('bootargs_subst' envvar) * * @flags: Flags to control what happens (see bootm_cmdline_t) * Return: 0 if OK, -ENOMEM if out of memory */ int bootm_process_cmdline_env(int flags); /** * zboot_run() - Run through the various steps to boot a zimage * * @bmi: Bootm information, with bzimage_size, initrd_addr, initrd_size and * cmdline set up. If base_ptr is 0, then bzimage_addr must be set to the start * of the bzImage. Otherwise base_ptr and load_address must be provided. */ int zboot_run(struct bootm_info *bmi); /** * zboot_run_args() - Run through the various steps to boot a zimage * * Boot a zimage, given the component parts * * @addr: Address where the bzImage is moved before booting, either * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR * @size: Size of bzImage, or 0 to detect this * @initrd: Address of the initial ramdisk, or 0 if none * @initrd_size: Size of the initial ramdisk, or 0 if none * @base_addr: If non-zero, this indicates that the boot parameters have already * been loaded by the caller to this address, so the load_zimage() call * in zboot_load() will be skipped when booting * @cmdline: If non-NULL, the environment variable containing the command line * to use for booting * Return: -EFAULT on error (normally it does not return) */ int zboot_run_args(ulong addr, ulong size, ulong initrd, ulong initrd_size, ulong base, char *cmdline); /* * zimage_get_kernel_version() - Get the version string from a kernel * * @params: boot_params pointer * @kernel_base: base address of kernel * Return: Kernel version as a NUL-terminated string */ const char *zimage_get_kernel_version(struct boot_params *params, void *kernel_base); /** * zimage_dump() - Dump the metadata of a zimage * * This shows all available information in a zimage that has been loaded. * * @bmi: Bootm information, with valid base_ptr * @show_cmdline: true to show the full command line */ void zimage_dump(struct bootm_info *bmi, bool show_cmdline); /* * bootm_boot_start() - Boot an image at the given address * * @addr: Image address * @cmdline: Command line to set */ int bootm_boot_start(ulong addr, const char *cmdline); /** * bootm_final() - Announce and do cleanup before boot * * @flags: Flags to control what this function does */ void bootm_final(enum bootm_final_t flags); int cleanup_before_linux(void); #endif |