Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2010-2011 Calxeda, Inc. |
| 4 | * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. |
| 5 | */ |
| 6 | |
Simon Glass | 9b2c78c | 2024-06-19 06:34:50 -0600 | [diff] [blame] | 7 | #define LOG_CATEGORY LOGC_BOOT |
| 8 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 9 | #include <command.h> |
Patrick Delaunay | 6ec8cb9 | 2022-03-22 17:08:43 +0100 | [diff] [blame] | 10 | #include <dm.h> |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 85f1378 | 2019-12-28 10:45:03 -0700 | [diff] [blame] | 12 | #include <image.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 14 | #include <malloc.h> |
| 15 | #include <mapmem.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 16 | #include <net.h> |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 17 | #include <fdt_support.h> |
Patrick Delaunay | 6ec8cb9 | 2022-03-22 17:08:43 +0100 | [diff] [blame] | 18 | #include <video.h> |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 19 | #include <linux/libfdt.h> |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 20 | #include <linux/string.h> |
| 21 | #include <linux/ctype.h> |
| 22 | #include <errno.h> |
| 23 | #include <linux/list.h> |
| 24 | |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 25 | #include <rng.h> |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 26 | |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 27 | #include <splash.h> |
| 28 | #include <asm/io.h> |
| 29 | |
| 30 | #include "menu.h" |
| 31 | #include "cli.h" |
| 32 | |
| 33 | #include "pxe_utils.h" |
| 34 | |
Ben Wolsieffer | 6273f13 | 2019-11-28 00:07:08 -0500 | [diff] [blame] | 35 | #define MAX_TFTP_PATH_LEN 512 |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 36 | |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 37 | int pxe_get_file_size(ulong *sizep) |
| 38 | { |
| 39 | const char *val; |
| 40 | |
| 41 | val = from_env("filesize"); |
| 42 | if (!val) |
| 43 | return -ENOENT; |
| 44 | |
| 45 | if (strict_strtoul(val, 16, sizep) < 0) |
| 46 | return -EINVAL; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 51 | /** |
| 52 | * format_mac_pxe() - obtain a MAC address in the PXE format |
| 53 | * |
| 54 | * This produces a MAC-address string in the format for the current ethernet |
| 55 | * device: |
| 56 | * |
| 57 | * 01-aa-bb-cc-dd-ee-ff |
| 58 | * |
| 59 | * where aa-ff is the MAC address in hex |
| 60 | * |
| 61 | * @outbuf: Buffer to write string to |
| 62 | * @outbuf_len: length of buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 63 | * Return: 1 if OK, -ENOSPC if buffer is too small, -ENOENT is there is no |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 64 | * current ethernet device |
| 65 | */ |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 66 | int format_mac_pxe(char *outbuf, size_t outbuf_len) |
| 67 | { |
| 68 | uchar ethaddr[6]; |
| 69 | |
| 70 | if (outbuf_len < 21) { |
| 71 | printf("outbuf is too small (%zd < 21)\n", outbuf_len); |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 72 | return -ENOSPC; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr)) |
| 76 | return -ENOENT; |
| 77 | |
| 78 | sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x", |
| 79 | ethaddr[0], ethaddr[1], ethaddr[2], |
| 80 | ethaddr[3], ethaddr[4], ethaddr[5]); |
| 81 | |
| 82 | return 1; |
| 83 | } |
| 84 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 85 | /** |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 86 | * get_relfile() - read a file relative to the PXE file |
| 87 | * |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 88 | * As in pxelinux, paths to files referenced from files we retrieve are |
| 89 | * relative to the location of bootfile. get_relfile takes such a path and |
| 90 | * joins it with the bootfile path to get the full path to the target file. If |
| 91 | * the bootfile path is NULL, we use file_path as is. |
| 92 | * |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 93 | * @ctx: PXE context |
| 94 | * @file_path: File path to read (relative to the PXE file) |
| 95 | * @file_addr: Address to load file to |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 96 | * @filesizep: If not NULL, returns the file size in bytes |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 97 | * Returns 1 for success, or < 0 on error |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 98 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 99 | static int get_relfile(struct pxe_context *ctx, const char *file_path, |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 100 | unsigned long file_addr, ulong *filesizep) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 101 | { |
| 102 | size_t path_len; |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 103 | char relfile[MAX_TFTP_PATH_LEN + 1]; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 104 | char addr_buf[18]; |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 105 | ulong size; |
| 106 | int ret; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 107 | |
Simon Glass | 5e3e39a | 2021-10-14 12:48:05 -0600 | [diff] [blame] | 108 | if (file_path[0] == '/' && ctx->allow_abs_path) |
| 109 | *relfile = '\0'; |
| 110 | else |
| 111 | strncpy(relfile, ctx->bootdir, MAX_TFTP_PATH_LEN); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 112 | |
Simon Glass | 5e3e39a | 2021-10-14 12:48:05 -0600 | [diff] [blame] | 113 | path_len = strlen(file_path) + strlen(relfile); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 114 | |
| 115 | if (path_len > MAX_TFTP_PATH_LEN) { |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 116 | printf("Base path too long (%s%s)\n", relfile, file_path); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 117 | |
| 118 | return -ENAMETOOLONG; |
| 119 | } |
| 120 | |
| 121 | strcat(relfile, file_path); |
| 122 | |
| 123 | printf("Retrieving file: %s\n", relfile); |
| 124 | |
| 125 | sprintf(addr_buf, "%lx", file_addr); |
| 126 | |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 127 | ret = ctx->getfile(ctx, relfile, addr_buf, &size); |
| 128 | if (ret < 0) |
| 129 | return log_msg_ret("get", ret); |
| 130 | if (filesizep) |
| 131 | *filesizep = size; |
| 132 | |
| 133 | return 1; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 136 | /** |
| 137 | * get_pxe_file() - read a file |
| 138 | * |
| 139 | * The file is read and nul-terminated |
| 140 | * |
| 141 | * @ctx: PXE context |
| 142 | * @file_path: File path to read (relative to the PXE file) |
| 143 | * @file_addr: Address to load file to |
| 144 | * Returns 1 for success, or < 0 on error |
| 145 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 146 | int get_pxe_file(struct pxe_context *ctx, const char *file_path, |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 147 | ulong file_addr) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 148 | { |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 149 | ulong size; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 150 | int err; |
| 151 | char *buf; |
| 152 | |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 153 | err = get_relfile(ctx, file_path, file_addr, &size); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 154 | if (err < 0) |
| 155 | return err; |
| 156 | |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 157 | buf = map_sysmem(file_addr + size, 1); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 158 | *buf = '\0'; |
| 159 | unmap_sysmem(buf); |
| 160 | |
| 161 | return 1; |
| 162 | } |
| 163 | |
| 164 | #define PXELINUX_DIR "pxelinux.cfg/" |
| 165 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 166 | /** |
| 167 | * get_pxelinux_path() - Get a file in the pxelinux.cfg/ directory |
| 168 | * |
| 169 | * @ctx: PXE context |
| 170 | * @file: Filename to process (relative to pxelinux.cfg/) |
| 171 | * Returns 1 for success, -ENAMETOOLONG if the resulting path is too long. |
| 172 | * or other value < 0 on other error |
| 173 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 174 | int get_pxelinux_path(struct pxe_context *ctx, const char *file, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 175 | unsigned long pxefile_addr_r) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 176 | { |
| 177 | size_t base_len = strlen(PXELINUX_DIR); |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 178 | char path[MAX_TFTP_PATH_LEN + 1]; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 179 | |
| 180 | if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) { |
| 181 | printf("path (%s%s) too long, skipping\n", |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 182 | PXELINUX_DIR, file); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 183 | return -ENAMETOOLONG; |
| 184 | } |
| 185 | |
| 186 | sprintf(path, PXELINUX_DIR "%s", file); |
| 187 | |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 188 | return get_pxe_file(ctx, path, pxefile_addr_r); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 191 | /** |
| 192 | * get_relfile_envaddr() - read a file to an address in an env var |
| 193 | * |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 194 | * Wrapper to make it easier to store the file at file_path in the location |
| 195 | * specified by envaddr_name. file_path will be joined to the bootfile path, |
| 196 | * if any is specified. |
| 197 | * |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 198 | * @ctx: PXE context |
| 199 | * @file_path: File path to read (relative to the PXE file) |
| 200 | * @envaddr_name: Name of environment variable which contains the address to |
| 201 | * load to |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 202 | * @filesizep: Returns the file size in bytes |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 203 | * Returns 1 on success, -ENOENT if @envaddr_name does not exist as an |
| 204 | * environment variable, -EINVAL if its format is not valid hex, or other |
| 205 | * value < 0 on other error |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 206 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 207 | static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path, |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 208 | const char *envaddr_name, ulong *filesizep) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 209 | { |
| 210 | unsigned long file_addr; |
| 211 | char *envaddr; |
| 212 | |
| 213 | envaddr = from_env(envaddr_name); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 214 | if (!envaddr) |
| 215 | return -ENOENT; |
| 216 | |
| 217 | if (strict_strtoul(envaddr, 16, &file_addr) < 0) |
| 218 | return -EINVAL; |
| 219 | |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 220 | return get_relfile(ctx, file_path, file_addr, filesizep); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 223 | /** |
| 224 | * label_create() - crate a new PXE label |
| 225 | * |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 226 | * Allocates memory for and initializes a pxe_label. This uses malloc, so the |
| 227 | * result must be free()'d to reclaim the memory. |
| 228 | * |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 229 | * Returns a pointer to the label, or NULL if out of memory |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 230 | */ |
| 231 | static struct pxe_label *label_create(void) |
| 232 | { |
| 233 | struct pxe_label *label; |
| 234 | |
| 235 | label = malloc(sizeof(struct pxe_label)); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 236 | if (!label) |
| 237 | return NULL; |
| 238 | |
| 239 | memset(label, 0, sizeof(struct pxe_label)); |
| 240 | |
| 241 | return label; |
| 242 | } |
| 243 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 244 | /** |
| 245 | * label_destroy() - free the memory used by a pxe_label |
| 246 | * |
| 247 | * This frees @label itself as well as memory used by its name, |
| 248 | * kernel, config, append, initrd, fdt, fdtdir and fdtoverlay members, if |
| 249 | * they're non-NULL. |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 250 | * |
| 251 | * So - be sure to only use dynamically allocated memory for the members of |
| 252 | * the pxe_label struct, unless you want to clean it up first. These are |
| 253 | * currently only created by the pxe file parsing code. |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 254 | * |
| 255 | * @label: Label to free |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 256 | */ |
| 257 | static void label_destroy(struct pxe_label *label) |
| 258 | { |
Simon Glass | 764d0c0 | 2021-10-14 12:48:02 -0600 | [diff] [blame] | 259 | free(label->name); |
Patrick Delaunay | 41c7e4a | 2022-10-28 11:01:19 +0200 | [diff] [blame] | 260 | free(label->kernel_label); |
Simon Glass | 764d0c0 | 2021-10-14 12:48:02 -0600 | [diff] [blame] | 261 | free(label->kernel); |
| 262 | free(label->config); |
| 263 | free(label->append); |
| 264 | free(label->initrd); |
| 265 | free(label->fdt); |
| 266 | free(label->fdtdir); |
| 267 | free(label->fdtoverlays); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 268 | free(label); |
| 269 | } |
| 270 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 271 | /** |
| 272 | * label_print() - Print a label and its string members if they're defined |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 273 | * |
| 274 | * This is passed as a callback to the menu code for displaying each |
| 275 | * menu entry. |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 276 | * |
| 277 | * @data: Label to print (is cast to struct pxe_label *) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 278 | */ |
| 279 | static void label_print(void *data) |
| 280 | { |
| 281 | struct pxe_label *label = data; |
| 282 | const char *c = label->menu ? label->menu : label->name; |
| 283 | |
| 284 | printf("%s:\t%s\n", label->num, c); |
| 285 | } |
| 286 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 287 | /** |
| 288 | * label_localboot() - Boot a label that specified 'localboot' |
| 289 | * |
| 290 | * This requires that the 'localcmd' environment variable is defined. Its |
| 291 | * contents will be executed as U-Boot commands. If the label specified an |
| 292 | * 'append' line, its contents will be used to overwrite the contents of the |
| 293 | * 'bootargs' environment variable prior to running 'localcmd'. |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 294 | * |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 295 | * @label: Label to process |
| 296 | * Returns 1 on success or < 0 on error |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 297 | */ |
| 298 | static int label_localboot(struct pxe_label *label) |
| 299 | { |
| 300 | char *localcmd; |
| 301 | |
| 302 | localcmd = from_env("localcmd"); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 303 | if (!localcmd) |
| 304 | return -ENOENT; |
| 305 | |
| 306 | if (label->append) { |
| 307 | char bootargs[CONFIG_SYS_CBSIZE]; |
| 308 | |
Simon Glass | c7b03e8 | 2020-11-05 10:33:47 -0700 | [diff] [blame] | 309 | cli_simple_process_macros(label->append, bootargs, |
| 310 | sizeof(bootargs)); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 311 | env_set("bootargs", bootargs); |
| 312 | } |
| 313 | |
| 314 | debug("running: %s\n", localcmd); |
| 315 | |
| 316 | return run_command_list(localcmd, strlen(localcmd), 0); |
| 317 | } |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 318 | |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 319 | /* |
| 320 | * label_boot_kaslrseed generate kaslrseed from hw rng |
| 321 | */ |
| 322 | |
| 323 | static void label_boot_kaslrseed(void) |
| 324 | { |
Marek Vasut | 0d871e7 | 2024-04-26 01:02:07 +0200 | [diff] [blame] | 325 | #if CONFIG_IS_ENABLED(DM_RNG) |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 326 | ulong fdt_addr; |
| 327 | struct fdt_header *working_fdt; |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 328 | int err; |
| 329 | |
| 330 | /* Get the main fdt and map it */ |
| 331 | fdt_addr = hextoul(env_get("fdt_addr_r"), NULL); |
| 332 | working_fdt = map_sysmem(fdt_addr, 0); |
| 333 | err = fdt_check_header(working_fdt); |
| 334 | if (err) |
| 335 | return; |
| 336 | |
| 337 | /* add extra size for holding kaslr-seed */ |
| 338 | /* err is new fdt size, 0 or negtive */ |
| 339 | err = fdt_shrink_to_minimum(working_fdt, 512); |
| 340 | if (err <= 0) |
| 341 | return; |
| 342 | |
Tim Harvey | c75fab4 | 2024-06-18 14:06:08 -0700 | [diff] [blame] | 343 | fdt_kaslrseed(working_fdt, true); |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 344 | #endif |
| 345 | return; |
| 346 | } |
| 347 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 348 | /** |
| 349 | * label_boot_fdtoverlay() - Loads fdt overlays specified in 'fdtoverlays' |
Edoardo Tomelleri | 6acf1b9 | 2022-09-21 15:26:33 +0200 | [diff] [blame] | 350 | * or 'devicetree-overlay' |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 351 | * |
| 352 | * @ctx: PXE context |
| 353 | * @label: Label to process |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 354 | */ |
| 355 | #ifdef CONFIG_OF_LIBFDT_OVERLAY |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 356 | static void label_boot_fdtoverlay(struct pxe_context *ctx, |
| 357 | struct pxe_label *label) |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 358 | { |
| 359 | char *fdtoverlay = label->fdtoverlays; |
| 360 | struct fdt_header *working_fdt; |
| 361 | char *fdtoverlay_addr_env; |
| 362 | ulong fdtoverlay_addr; |
| 363 | ulong fdt_addr; |
| 364 | int err; |
| 365 | |
| 366 | /* Get the main fdt and map it */ |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 367 | fdt_addr = hextoul(env_get("fdt_addr_r"), NULL); |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 368 | working_fdt = map_sysmem(fdt_addr, 0); |
| 369 | err = fdt_check_header(working_fdt); |
| 370 | if (err) |
| 371 | return; |
| 372 | |
| 373 | /* Get the specific overlay loading address */ |
| 374 | fdtoverlay_addr_env = env_get("fdtoverlay_addr_r"); |
| 375 | if (!fdtoverlay_addr_env) { |
| 376 | printf("Invalid fdtoverlay_addr_r for loading overlays\n"); |
| 377 | return; |
| 378 | } |
| 379 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 380 | fdtoverlay_addr = hextoul(fdtoverlay_addr_env, NULL); |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 381 | |
| 382 | /* Cycle over the overlay files and apply them in order */ |
| 383 | do { |
| 384 | struct fdt_header *blob; |
| 385 | char *overlayfile; |
| 386 | char *end; |
| 387 | int len; |
| 388 | |
| 389 | /* Drop leading spaces */ |
| 390 | while (*fdtoverlay == ' ') |
| 391 | ++fdtoverlay; |
| 392 | |
| 393 | /* Copy a single filename if multiple provided */ |
| 394 | end = strstr(fdtoverlay, " "); |
| 395 | if (end) { |
| 396 | len = (int)(end - fdtoverlay); |
| 397 | overlayfile = malloc(len + 1); |
| 398 | strncpy(overlayfile, fdtoverlay, len); |
| 399 | overlayfile[len] = '\0'; |
| 400 | } else |
| 401 | overlayfile = fdtoverlay; |
| 402 | |
| 403 | if (!strlen(overlayfile)) |
| 404 | goto skip_overlay; |
| 405 | |
| 406 | /* Load overlay file */ |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 407 | err = get_relfile_envaddr(ctx, overlayfile, "fdtoverlay_addr_r", |
| 408 | NULL); |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 409 | if (err < 0) { |
| 410 | printf("Failed loading overlay %s\n", overlayfile); |
| 411 | goto skip_overlay; |
| 412 | } |
| 413 | |
| 414 | /* Resize main fdt */ |
| 415 | fdt_shrink_to_minimum(working_fdt, 8192); |
| 416 | |
| 417 | blob = map_sysmem(fdtoverlay_addr, 0); |
| 418 | err = fdt_check_header(blob); |
| 419 | if (err) { |
| 420 | printf("Invalid overlay %s, skipping\n", |
| 421 | overlayfile); |
| 422 | goto skip_overlay; |
| 423 | } |
| 424 | |
| 425 | err = fdt_overlay_apply_verbose(working_fdt, blob); |
| 426 | if (err) { |
| 427 | printf("Failed to apply overlay %s, skipping\n", |
| 428 | overlayfile); |
| 429 | goto skip_overlay; |
| 430 | } |
| 431 | |
| 432 | skip_overlay: |
| 433 | if (end) |
| 434 | free(overlayfile); |
| 435 | } while ((fdtoverlay = strstr(fdtoverlay, " "))); |
| 436 | } |
| 437 | #endif |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 438 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 439 | /** |
| 440 | * label_boot() - Boot according to the contents of a pxe_label |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 441 | * |
| 442 | * If we can't boot for any reason, we return. A successful boot never |
| 443 | * returns. |
| 444 | * |
| 445 | * The kernel will be stored in the location given by the 'kernel_addr_r' |
| 446 | * environment variable. |
| 447 | * |
| 448 | * If the label specifies an initrd file, it will be stored in the location |
| 449 | * given by the 'ramdisk_addr_r' environment variable. |
| 450 | * |
| 451 | * If the label specifies an 'append' line, its contents will overwrite that |
| 452 | * of the 'bootargs' environment variable. |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 453 | * |
| 454 | * @ctx: PXE context |
| 455 | * @label: Label to process |
| 456 | * Returns does not return on success, otherwise returns 0 if a localboot |
| 457 | * label was processed, or 1 on error |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 458 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 459 | static int label_boot(struct pxe_context *ctx, struct pxe_label *label) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 460 | { |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 461 | char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL }; |
| 462 | char *zboot_argv[] = { "zboot", NULL, "0", NULL, NULL }; |
Zhaofeng Li | bc14b93 | 2021-10-20 00:18:15 -0700 | [diff] [blame] | 463 | char *kernel_addr = NULL; |
| 464 | char *initrd_addr_str = NULL; |
Zhaofeng Li | dbf84cc | 2021-10-20 00:18:14 -0700 | [diff] [blame] | 465 | char initrd_filesize[10]; |
Zhaofeng Li | bc14b93 | 2021-10-20 00:18:15 -0700 | [diff] [blame] | 466 | char initrd_str[28]; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 467 | char mac_str[29] = ""; |
| 468 | char ip_str[68] = ""; |
| 469 | char *fit_addr = NULL; |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 470 | int bootm_argc = 2; |
| 471 | int zboot_argc = 3; |
| 472 | int len = 0; |
| 473 | ulong kernel_addr_r; |
| 474 | void *buf; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 475 | |
| 476 | label_print(label); |
| 477 | |
| 478 | label->attempted = 1; |
| 479 | |
| 480 | if (label->localboot) { |
| 481 | if (label->localboot_val >= 0) |
| 482 | label_localboot(label); |
| 483 | return 0; |
| 484 | } |
| 485 | |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 486 | if (!label->kernel) { |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 487 | printf("No kernel given, skipping %s\n", |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 488 | label->name); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 489 | return 1; |
| 490 | } |
| 491 | |
Patrick Delaunay | 6b5cb36 | 2022-10-28 11:01:18 +0200 | [diff] [blame] | 492 | if (get_relfile_envaddr(ctx, label->kernel, "kernel_addr_r", |
| 493 | NULL) < 0) { |
| 494 | printf("Skipping %s for failure retrieving kernel\n", |
| 495 | label->name); |
| 496 | return 1; |
| 497 | } |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 498 | |
Patrick Delaunay | 6b5cb36 | 2022-10-28 11:01:18 +0200 | [diff] [blame] | 499 | kernel_addr = env_get("kernel_addr_r"); |
| 500 | /* for FIT, append the configuration identifier */ |
| 501 | if (label->config) { |
| 502 | int len = strlen(kernel_addr) + strlen(label->config) + 1; |
| 503 | |
| 504 | fit_addr = malloc(len); |
| 505 | if (!fit_addr) { |
| 506 | printf("malloc fail (FIT address)\n"); |
| 507 | return 1; |
| 508 | } |
| 509 | snprintf(fit_addr, len, "%s%s", kernel_addr, label->config); |
| 510 | kernel_addr = fit_addr; |
| 511 | } |
| 512 | |
Patrick Delaunay | 41c7e4a | 2022-10-28 11:01:19 +0200 | [diff] [blame] | 513 | /* For FIT, the label can be identical to kernel one */ |
| 514 | if (label->initrd && !strcmp(label->kernel_label, label->initrd)) { |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 515 | initrd_addr_str = kernel_addr; |
Patrick Delaunay | 41c7e4a | 2022-10-28 11:01:19 +0200 | [diff] [blame] | 516 | } else if (label->initrd) { |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 517 | ulong size; |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 518 | if (get_relfile_envaddr(ctx, label->initrd, "ramdisk_addr_r", |
| 519 | &size) < 0) { |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 520 | printf("Skipping %s for failure retrieving initrd\n", |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 521 | label->name); |
Patrick Delaunay | 6b5cb36 | 2022-10-28 11:01:18 +0200 | [diff] [blame] | 522 | goto cleanup; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 523 | } |
Thomas Mittelstaedt | ca65d23 | 2023-05-04 13:42:55 +0000 | [diff] [blame] | 524 | strcpy(initrd_filesize, simple_xtoa(size)); |
Zhaofeng Li | bc14b93 | 2021-10-20 00:18:15 -0700 | [diff] [blame] | 525 | initrd_addr_str = env_get("ramdisk_addr_r"); |
Heinrich Schuchardt | a8d6aed | 2021-11-15 19:26:51 +0100 | [diff] [blame] | 526 | size = snprintf(initrd_str, sizeof(initrd_str), "%s:%lx", |
| 527 | initrd_addr_str, size); |
| 528 | if (size >= sizeof(initrd_str)) |
Patrick Delaunay | 6b5cb36 | 2022-10-28 11:01:18 +0200 | [diff] [blame] | 529 | goto cleanup; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | if (label->ipappend & 0x1) { |
| 533 | sprintf(ip_str, " ip=%s:%s:%s:%s", |
| 534 | env_get("ipaddr"), env_get("serverip"), |
| 535 | env_get("gatewayip"), env_get("netmask")); |
| 536 | } |
| 537 | |
Kory Maincent | caabd24 | 2021-02-02 16:42:28 +0100 | [diff] [blame] | 538 | if (IS_ENABLED(CONFIG_CMD_NET)) { |
| 539 | if (label->ipappend & 0x2) { |
| 540 | int err; |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 541 | |
Kory Maincent | caabd24 | 2021-02-02 16:42:28 +0100 | [diff] [blame] | 542 | strcpy(mac_str, " BOOTIF="); |
| 543 | err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8); |
| 544 | if (err < 0) |
| 545 | mac_str[0] = '\0'; |
| 546 | } |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 547 | } |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 548 | |
| 549 | if ((label->ipappend & 0x3) || label->append) { |
| 550 | char bootargs[CONFIG_SYS_CBSIZE] = ""; |
| 551 | char finalbootargs[CONFIG_SYS_CBSIZE]; |
| 552 | |
| 553 | if (strlen(label->append ?: "") + |
| 554 | strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) { |
| 555 | printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n", |
| 556 | strlen(label->append ?: ""), |
| 557 | strlen(ip_str), strlen(mac_str), |
| 558 | sizeof(bootargs)); |
Patrick Delaunay | 6b5cb36 | 2022-10-28 11:01:18 +0200 | [diff] [blame] | 559 | goto cleanup; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 560 | } |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 561 | |
| 562 | if (label->append) |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 563 | strncpy(bootargs, label->append, sizeof(bootargs)); |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 564 | |
| 565 | strcat(bootargs, ip_str); |
| 566 | strcat(bootargs, mac_str); |
| 567 | |
Simon Glass | c7b03e8 | 2020-11-05 10:33:47 -0700 | [diff] [blame] | 568 | cli_simple_process_macros(bootargs, finalbootargs, |
| 569 | sizeof(finalbootargs)); |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 570 | env_set("bootargs", finalbootargs); |
| 571 | printf("append: %s\n", finalbootargs); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 572 | } |
| 573 | |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 574 | /* |
| 575 | * fdt usage is optional: |
| 576 | * It handles the following scenarios. |
| 577 | * |
| 578 | * Scenario 1: If fdt_addr_r specified and "fdt" or "fdtdir" label is |
| 579 | * defined in pxe file, retrieve fdt blob from server. Pass fdt_addr_r to |
| 580 | * bootm, and adjust argc appropriately. |
| 581 | * |
| 582 | * If retrieve fails and no exact fdt blob is specified in pxe file with |
| 583 | * "fdt" label, try Scenario 2. |
| 584 | * |
| 585 | * Scenario 2: If there is an fdt_addr specified, pass it along to |
| 586 | * bootm, and adjust argc appropriately. |
| 587 | * |
| 588 | * Scenario 3: If there is an fdtcontroladdr specified, pass it along to |
| 589 | * bootm, and adjust argc appropriately, unless the image type is fitImage. |
| 590 | * |
| 591 | * Scenario 4: fdt blob is not available. |
| 592 | */ |
| 593 | bootm_argv[3] = env_get("fdt_addr_r"); |
| 594 | |
| 595 | /* For FIT, the label can be identical to kernel one */ |
| 596 | if (label->fdt && !strcmp(label->kernel_label, label->fdt)) { |
| 597 | bootm_argv[3] = kernel_addr; |
| 598 | /* if fdt label is defined then get fdt from server */ |
| 599 | } else if (bootm_argv[3]) { |
| 600 | char *fdtfile = NULL; |
| 601 | char *fdtfilefree = NULL; |
| 602 | |
| 603 | if (label->fdt) { |
| 604 | if (IS_ENABLED(CONFIG_SUPPORT_PASSING_ATAGS)) { |
| 605 | if (strcmp("-", label->fdt)) |
| 606 | fdtfile = label->fdt; |
| 607 | } else { |
| 608 | fdtfile = label->fdt; |
| 609 | } |
| 610 | } else if (label->fdtdir) { |
| 611 | char *f1, *f2, *f3, *f4, *slash; |
| 612 | |
| 613 | f1 = env_get("fdtfile"); |
| 614 | if (f1) { |
| 615 | f2 = ""; |
| 616 | f3 = ""; |
| 617 | f4 = ""; |
| 618 | } else { |
| 619 | /* |
| 620 | * For complex cases where this code doesn't |
| 621 | * generate the correct filename, the board |
| 622 | * code should set $fdtfile during early boot, |
| 623 | * or the boot scripts should set $fdtfile |
| 624 | * before invoking "pxe" or "sysboot". |
| 625 | */ |
| 626 | f1 = env_get("soc"); |
| 627 | f2 = "-"; |
| 628 | f3 = env_get("board"); |
| 629 | f4 = ".dtb"; |
| 630 | if (!f1) { |
| 631 | f1 = ""; |
| 632 | f2 = ""; |
| 633 | } |
| 634 | if (!f3) { |
| 635 | f2 = ""; |
| 636 | f3 = ""; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | len = strlen(label->fdtdir); |
| 641 | if (!len) |
| 642 | slash = "./"; |
| 643 | else if (label->fdtdir[len - 1] != '/') |
| 644 | slash = "/"; |
| 645 | else |
| 646 | slash = ""; |
| 647 | |
| 648 | len = strlen(label->fdtdir) + strlen(slash) + |
| 649 | strlen(f1) + strlen(f2) + strlen(f3) + |
| 650 | strlen(f4) + 1; |
| 651 | fdtfilefree = malloc(len); |
| 652 | if (!fdtfilefree) { |
| 653 | printf("malloc fail (FDT filename)\n"); |
| 654 | goto cleanup; |
| 655 | } |
| 656 | |
| 657 | snprintf(fdtfilefree, len, "%s%s%s%s%s%s", |
| 658 | label->fdtdir, slash, f1, f2, f3, f4); |
| 659 | fdtfile = fdtfilefree; |
| 660 | } |
| 661 | |
| 662 | if (fdtfile) { |
| 663 | int err = get_relfile_envaddr(ctx, fdtfile, |
| 664 | "fdt_addr_r", NULL); |
| 665 | |
| 666 | free(fdtfilefree); |
| 667 | if (err < 0) { |
| 668 | bootm_argv[3] = NULL; |
| 669 | |
| 670 | if (label->fdt) { |
| 671 | printf("Skipping %s for failure retrieving FDT\n", |
| 672 | label->name); |
| 673 | goto cleanup; |
| 674 | } |
| 675 | |
| 676 | if (label->fdtdir) { |
| 677 | printf("Skipping fdtdir %s for failure retrieving dts\n", |
| 678 | label->fdtdir); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | if (label->kaslrseed) |
| 683 | label_boot_kaslrseed(); |
| 684 | |
| 685 | #ifdef CONFIG_OF_LIBFDT_OVERLAY |
| 686 | if (label->fdtoverlays) |
| 687 | label_boot_fdtoverlay(ctx, label); |
| 688 | #endif |
| 689 | } else { |
| 690 | bootm_argv[3] = NULL; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | bootm_argv[1] = kernel_addr; |
| 695 | zboot_argv[1] = kernel_addr; |
| 696 | |
| 697 | if (initrd_addr_str) { |
| 698 | bootm_argv[2] = initrd_str; |
| 699 | bootm_argc = 3; |
| 700 | |
| 701 | zboot_argv[3] = initrd_addr_str; |
| 702 | zboot_argv[4] = initrd_filesize; |
| 703 | zboot_argc = 5; |
| 704 | } |
| 705 | |
| 706 | if (!bootm_argv[3]) { |
| 707 | if (IS_ENABLED(CONFIG_SUPPORT_PASSING_ATAGS)) { |
| 708 | if (strcmp("-", label->fdt)) |
| 709 | bootm_argv[3] = env_get("fdt_addr"); |
| 710 | } else { |
| 711 | bootm_argv[3] = env_get("fdt_addr"); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | kernel_addr_r = genimg_get_kernel_addr(kernel_addr); |
| 716 | buf = map_sysmem(kernel_addr_r, 0); |
| 717 | |
| 718 | if (!bootm_argv[3] && genimg_get_format(buf) != IMAGE_FORMAT_FIT) { |
| 719 | if (IS_ENABLED(CONFIG_SUPPORT_PASSING_ATAGS)) { |
| 720 | if (strcmp("-", label->fdt)) |
| 721 | bootm_argv[3] = env_get("fdtcontroladdr"); |
| 722 | } else { |
| 723 | bootm_argv[3] = env_get("fdtcontroladdr"); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | if (bootm_argv[3]) { |
| 728 | if (!bootm_argv[2]) |
| 729 | bootm_argv[2] = "-"; |
| 730 | bootm_argc = 4; |
| 731 | } |
| 732 | |
| 733 | /* Try bootm for legacy and FIT format image */ |
| 734 | if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID && |
Simon Glass | 9b2c78c | 2024-06-19 06:34:50 -0600 | [diff] [blame] | 735 | IS_ENABLED(CONFIG_CMD_BOOTM)) { |
| 736 | log_debug("using bootm\n"); |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 737 | do_bootm(ctx->cmdtp, 0, bootm_argc, bootm_argv); |
| 738 | /* Try booting an AArch64 Linux kernel image */ |
Simon Glass | 9b2c78c | 2024-06-19 06:34:50 -0600 | [diff] [blame] | 739 | } else if (IS_ENABLED(CONFIG_CMD_BOOTI)) { |
| 740 | log_debug("using booti\n"); |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 741 | do_booti(ctx->cmdtp, 0, bootm_argc, bootm_argv); |
| 742 | /* Try booting a Image */ |
Simon Glass | 9b2c78c | 2024-06-19 06:34:50 -0600 | [diff] [blame] | 743 | } else if (IS_ENABLED(CONFIG_CMD_BOOTZ)) { |
| 744 | log_debug("using bootz\n"); |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 745 | do_bootz(ctx->cmdtp, 0, bootm_argc, bootm_argv); |
| 746 | /* Try booting an x86_64 Linux kernel image */ |
Simon Glass | 9b2c78c | 2024-06-19 06:34:50 -0600 | [diff] [blame] | 747 | } else if (IS_ENABLED(CONFIG_CMD_ZBOOT)) { |
| 748 | log_debug("using zboot\n"); |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 749 | do_zboot_parent(ctx->cmdtp, 0, zboot_argc, zboot_argv, NULL); |
Simon Glass | 9b2c78c | 2024-06-19 06:34:50 -0600 | [diff] [blame] | 750 | } |
Tom Rini | 793921e | 2024-04-18 08:29:35 -0600 | [diff] [blame] | 751 | |
| 752 | unmap_sysmem(buf); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 753 | |
| 754 | cleanup: |
Simon Glass | 764d0c0 | 2021-10-14 12:48:02 -0600 | [diff] [blame] | 755 | free(fit_addr); |
| 756 | |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 757 | return 1; |
| 758 | } |
| 759 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 760 | /** enum token_type - Tokens for the pxe file parser */ |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 761 | enum token_type { |
| 762 | T_EOL, |
| 763 | T_STRING, |
| 764 | T_EOF, |
| 765 | T_MENU, |
| 766 | T_TITLE, |
| 767 | T_TIMEOUT, |
| 768 | T_LABEL, |
| 769 | T_KERNEL, |
| 770 | T_LINUX, |
| 771 | T_APPEND, |
| 772 | T_INITRD, |
| 773 | T_LOCALBOOT, |
| 774 | T_DEFAULT, |
| 775 | T_PROMPT, |
| 776 | T_INCLUDE, |
| 777 | T_FDT, |
| 778 | T_FDTDIR, |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 779 | T_FDTOVERLAYS, |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 780 | T_ONTIMEOUT, |
| 781 | T_IPAPPEND, |
| 782 | T_BACKGROUND, |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 783 | T_KASLRSEED, |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 784 | T_INVALID |
| 785 | }; |
| 786 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 787 | /** struct token - token - given by a value and a type */ |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 788 | struct token { |
| 789 | char *val; |
| 790 | enum token_type type; |
| 791 | }; |
| 792 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 793 | /* Keywords recognized */ |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 794 | static const struct token keywords[] = { |
| 795 | {"menu", T_MENU}, |
| 796 | {"title", T_TITLE}, |
| 797 | {"timeout", T_TIMEOUT}, |
| 798 | {"default", T_DEFAULT}, |
| 799 | {"prompt", T_PROMPT}, |
| 800 | {"label", T_LABEL}, |
| 801 | {"kernel", T_KERNEL}, |
| 802 | {"linux", T_LINUX}, |
| 803 | {"localboot", T_LOCALBOOT}, |
| 804 | {"append", T_APPEND}, |
| 805 | {"initrd", T_INITRD}, |
| 806 | {"include", T_INCLUDE}, |
| 807 | {"devicetree", T_FDT}, |
| 808 | {"fdt", T_FDT}, |
| 809 | {"devicetreedir", T_FDTDIR}, |
| 810 | {"fdtdir", T_FDTDIR}, |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 811 | {"fdtoverlays", T_FDTOVERLAYS}, |
Edoardo Tomelleri | 6acf1b9 | 2022-09-21 15:26:33 +0200 | [diff] [blame] | 812 | {"devicetree-overlay", T_FDTOVERLAYS}, |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 813 | {"ontimeout", T_ONTIMEOUT,}, |
| 814 | {"ipappend", T_IPAPPEND,}, |
| 815 | {"background", T_BACKGROUND,}, |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 816 | {"kaslrseed", T_KASLRSEED,}, |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 817 | {NULL, T_INVALID} |
| 818 | }; |
| 819 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 820 | /** |
| 821 | * enum lex_state - lexer state |
| 822 | * |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 823 | * Since pxe(linux) files don't have a token to identify the start of a |
| 824 | * literal, we have to keep track of when we're in a state where a literal is |
| 825 | * expected vs when we're in a state a keyword is expected. |
| 826 | */ |
| 827 | enum lex_state { |
| 828 | L_NORMAL = 0, |
| 829 | L_KEYWORD, |
| 830 | L_SLITERAL |
| 831 | }; |
| 832 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 833 | /** |
| 834 | * get_string() - retrieves a string from *p and stores it as a token in *t. |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 835 | * |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 836 | * This is used for scanning both string literals and keywords. |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 837 | * |
| 838 | * Characters from *p are copied into t-val until a character equal to |
| 839 | * delim is found, or a NUL byte is reached. If delim has the special value of |
| 840 | * ' ', any whitespace character will be used as a delimiter. |
| 841 | * |
| 842 | * If lower is unequal to 0, uppercase characters will be converted to |
| 843 | * lowercase in the result. This is useful to make keywords case |
| 844 | * insensitive. |
| 845 | * |
| 846 | * The location of *p is updated to point to the first character after the end |
| 847 | * of the token - the ending delimiter. |
| 848 | * |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 849 | * Memory for t->val is allocated using malloc and must be free()'d to reclaim |
| 850 | * it. |
| 851 | * |
| 852 | * @p: Points to a pointer to the current position in the input being processed. |
| 853 | * Updated to point at the first character after the current token |
| 854 | * @t: Pointers to a token to fill in |
| 855 | * @delim: Delimiter character to look for, either newline or space |
| 856 | * @lower: true to convert the string to lower case when storing |
| 857 | * Returns the new value of t->val, on success, NULL if out of memory |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 858 | */ |
| 859 | static char *get_string(char **p, struct token *t, char delim, int lower) |
| 860 | { |
| 861 | char *b, *e; |
| 862 | size_t len, i; |
| 863 | |
| 864 | /* |
| 865 | * b and e both start at the beginning of the input stream. |
| 866 | * |
| 867 | * e is incremented until we find the ending delimiter, or a NUL byte |
| 868 | * is reached. Then, we take e - b to find the length of the token. |
| 869 | */ |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 870 | b = *p; |
| 871 | e = *p; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 872 | while (*e) { |
| 873 | if ((delim == ' ' && isspace(*e)) || delim == *e) |
| 874 | break; |
| 875 | e++; |
| 876 | } |
| 877 | |
| 878 | len = e - b; |
| 879 | |
| 880 | /* |
| 881 | * Allocate memory to hold the string, and copy it in, converting |
| 882 | * characters to lowercase if lower is != 0. |
| 883 | */ |
| 884 | t->val = malloc(len + 1); |
| 885 | if (!t->val) |
| 886 | return NULL; |
| 887 | |
| 888 | for (i = 0; i < len; i++, b++) { |
| 889 | if (lower) |
| 890 | t->val[i] = tolower(*b); |
| 891 | else |
| 892 | t->val[i] = *b; |
| 893 | } |
| 894 | |
| 895 | t->val[len] = '\0'; |
| 896 | |
Simon Glass | 764d0c0 | 2021-10-14 12:48:02 -0600 | [diff] [blame] | 897 | /* Update *p so the caller knows where to continue scanning */ |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 898 | *p = e; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 899 | t->type = T_STRING; |
| 900 | |
| 901 | return t->val; |
| 902 | } |
| 903 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 904 | /** |
| 905 | * get_keyword() - Populate a keyword token with a type and value |
| 906 | * |
| 907 | * Updates the ->type field based on the keyword string in @val |
| 908 | * @t: Token to populate |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 909 | */ |
| 910 | static void get_keyword(struct token *t) |
| 911 | { |
| 912 | int i; |
| 913 | |
| 914 | for (i = 0; keywords[i].val; i++) { |
| 915 | if (!strcmp(t->val, keywords[i].val)) { |
| 916 | t->type = keywords[i].type; |
| 917 | break; |
| 918 | } |
| 919 | } |
| 920 | } |
| 921 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 922 | /** |
| 923 | * get_token() - Get the next token |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 924 | * |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 925 | * We have to keep track of which state we're in to know if we're looking to get |
| 926 | * a string literal or a keyword. |
| 927 | * |
| 928 | * @p: Points to a pointer to the current position in the input being processed. |
| 929 | * Updated to point at the first character after the current token |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 930 | */ |
| 931 | static void get_token(char **p, struct token *t, enum lex_state state) |
| 932 | { |
| 933 | char *c = *p; |
| 934 | |
| 935 | t->type = T_INVALID; |
| 936 | |
| 937 | /* eat non EOL whitespace */ |
| 938 | while (isblank(*c)) |
| 939 | c++; |
| 940 | |
| 941 | /* |
| 942 | * eat comments. note that string literals can't begin with #, but |
| 943 | * can contain a # after their first character. |
| 944 | */ |
| 945 | if (*c == '#') { |
| 946 | while (*c && *c != '\n') |
| 947 | c++; |
| 948 | } |
| 949 | |
| 950 | if (*c == '\n') { |
| 951 | t->type = T_EOL; |
| 952 | c++; |
| 953 | } else if (*c == '\0') { |
| 954 | t->type = T_EOF; |
| 955 | c++; |
| 956 | } else if (state == L_SLITERAL) { |
| 957 | get_string(&c, t, '\n', 0); |
| 958 | } else if (state == L_KEYWORD) { |
| 959 | /* |
| 960 | * when we expect a keyword, we first get the next string |
| 961 | * token delimited by whitespace, and then check if it |
| 962 | * matches a keyword in our keyword list. if it does, it's |
| 963 | * converted to a keyword token of the appropriate type, and |
| 964 | * if not, it remains a string token. |
| 965 | */ |
| 966 | get_string(&c, t, ' ', 1); |
| 967 | get_keyword(t); |
| 968 | } |
| 969 | |
| 970 | *p = c; |
| 971 | } |
| 972 | |
Simon Glass | 0030244 | 2021-10-14 12:48:01 -0600 | [diff] [blame] | 973 | /** |
| 974 | * eol_or_eof() - Find end of line |
| 975 | * |
| 976 | * Increment *c until we get to the end of the current line, or EOF |
| 977 | * |
| 978 | * @c: Points to a pointer to the current position in the input being processed. |
| 979 | * Updated to point at the first character after the current token |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 980 | */ |
| 981 | static void eol_or_eof(char **c) |
| 982 | { |
| 983 | while (**c && **c != '\n') |
| 984 | (*c)++; |
| 985 | } |
| 986 | |
| 987 | /* |
| 988 | * All of these parse_* functions share some common behavior. |
| 989 | * |
| 990 | * They finish with *c pointing after the token they parse, and return 1 on |
| 991 | * success, or < 0 on error. |
| 992 | */ |
| 993 | |
| 994 | /* |
| 995 | * Parse a string literal and store a pointer it at *dst. String literals |
| 996 | * terminate at the end of the line. |
| 997 | */ |
| 998 | static int parse_sliteral(char **c, char **dst) |
| 999 | { |
| 1000 | struct token t; |
| 1001 | char *s = *c; |
| 1002 | |
| 1003 | get_token(c, &t, L_SLITERAL); |
| 1004 | |
| 1005 | if (t.type != T_STRING) { |
| 1006 | printf("Expected string literal: %.*s\n", (int)(*c - s), s); |
| 1007 | return -EINVAL; |
| 1008 | } |
| 1009 | |
| 1010 | *dst = t.val; |
| 1011 | |
| 1012 | return 1; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * Parse a base 10 (unsigned) integer and store it at *dst. |
| 1017 | */ |
| 1018 | static int parse_integer(char **c, int *dst) |
| 1019 | { |
| 1020 | struct token t; |
| 1021 | char *s = *c; |
| 1022 | |
| 1023 | get_token(c, &t, L_SLITERAL); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1024 | if (t.type != T_STRING) { |
| 1025 | printf("Expected string: %.*s\n", (int)(*c - s), s); |
| 1026 | return -EINVAL; |
| 1027 | } |
| 1028 | |
| 1029 | *dst = simple_strtol(t.val, NULL, 10); |
| 1030 | |
| 1031 | free(t.val); |
| 1032 | |
| 1033 | return 1; |
| 1034 | } |
| 1035 | |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1036 | static int parse_pxefile_top(struct pxe_context *ctx, char *p, ulong base, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1037 | struct pxe_menu *cfg, int nest_level); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1038 | |
| 1039 | /* |
| 1040 | * Parse an include statement, and retrieve and parse the file it mentions. |
| 1041 | * |
| 1042 | * base should point to a location where it's safe to store the file, and |
| 1043 | * nest_level should indicate how many nested includes have occurred. For this |
| 1044 | * include, nest_level has already been incremented and doesn't need to be |
| 1045 | * incremented here. |
| 1046 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1047 | static int handle_include(struct pxe_context *ctx, char **c, unsigned long base, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1048 | struct pxe_menu *cfg, int nest_level) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1049 | { |
| 1050 | char *include_path; |
| 1051 | char *s = *c; |
| 1052 | int err; |
| 1053 | char *buf; |
| 1054 | int ret; |
| 1055 | |
| 1056 | err = parse_sliteral(c, &include_path); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1057 | if (err < 0) { |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1058 | printf("Expected include path: %.*s\n", (int)(*c - s), s); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1059 | return err; |
| 1060 | } |
| 1061 | |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1062 | err = get_pxe_file(ctx, include_path, base); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1063 | if (err < 0) { |
| 1064 | printf("Couldn't retrieve %s\n", include_path); |
| 1065 | return err; |
| 1066 | } |
| 1067 | |
| 1068 | buf = map_sysmem(base, 0); |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1069 | ret = parse_pxefile_top(ctx, buf, base, cfg, nest_level); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1070 | unmap_sysmem(buf); |
| 1071 | |
| 1072 | return ret; |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | * Parse lines that begin with 'menu'. |
| 1077 | * |
| 1078 | * base and nest are provided to handle the 'menu include' case. |
| 1079 | * |
| 1080 | * base should point to a location where it's safe to store the included file. |
| 1081 | * |
| 1082 | * nest_level should be 1 when parsing the top level pxe file, 2 when parsing |
| 1083 | * a file it includes, 3 when parsing a file included by that file, and so on. |
| 1084 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1085 | static int parse_menu(struct pxe_context *ctx, char **c, struct pxe_menu *cfg, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1086 | unsigned long base, int nest_level) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1087 | { |
| 1088 | struct token t; |
| 1089 | char *s = *c; |
| 1090 | int err = 0; |
| 1091 | |
| 1092 | get_token(c, &t, L_KEYWORD); |
| 1093 | |
| 1094 | switch (t.type) { |
| 1095 | case T_TITLE: |
| 1096 | err = parse_sliteral(c, &cfg->title); |
| 1097 | |
| 1098 | break; |
| 1099 | |
| 1100 | case T_INCLUDE: |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1101 | err = handle_include(ctx, c, base, cfg, nest_level + 1); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1102 | break; |
| 1103 | |
| 1104 | case T_BACKGROUND: |
| 1105 | err = parse_sliteral(c, &cfg->bmp); |
| 1106 | break; |
| 1107 | |
| 1108 | default: |
| 1109 | printf("Ignoring malformed menu command: %.*s\n", |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1110 | (int)(*c - s), s); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1111 | } |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1112 | if (err < 0) |
| 1113 | return err; |
| 1114 | |
| 1115 | eol_or_eof(c); |
| 1116 | |
| 1117 | return 1; |
| 1118 | } |
| 1119 | |
| 1120 | /* |
| 1121 | * Handles parsing a 'menu line' when we're parsing a label. |
| 1122 | */ |
| 1123 | static int parse_label_menu(char **c, struct pxe_menu *cfg, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1124 | struct pxe_label *label) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1125 | { |
| 1126 | struct token t; |
| 1127 | char *s; |
| 1128 | |
| 1129 | s = *c; |
| 1130 | |
| 1131 | get_token(c, &t, L_KEYWORD); |
| 1132 | |
| 1133 | switch (t.type) { |
| 1134 | case T_DEFAULT: |
| 1135 | if (!cfg->default_label) |
| 1136 | cfg->default_label = strdup(label->name); |
| 1137 | |
| 1138 | if (!cfg->default_label) |
| 1139 | return -ENOMEM; |
| 1140 | |
| 1141 | break; |
| 1142 | case T_LABEL: |
| 1143 | parse_sliteral(c, &label->menu); |
| 1144 | break; |
| 1145 | default: |
| 1146 | printf("Ignoring malformed menu command: %.*s\n", |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1147 | (int)(*c - s), s); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | eol_or_eof(c); |
| 1151 | |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | /* |
| 1156 | * Handles parsing a 'kernel' label. |
| 1157 | * expecting "filename" or "<fit_filename>#cfg" |
| 1158 | */ |
| 1159 | static int parse_label_kernel(char **c, struct pxe_label *label) |
| 1160 | { |
| 1161 | char *s; |
| 1162 | int err; |
| 1163 | |
| 1164 | err = parse_sliteral(c, &label->kernel); |
| 1165 | if (err < 0) |
| 1166 | return err; |
| 1167 | |
Patrick Delaunay | 41c7e4a | 2022-10-28 11:01:19 +0200 | [diff] [blame] | 1168 | /* copy the kernel label to compare with FDT / INITRD when FIT is used */ |
| 1169 | label->kernel_label = strdup(label->kernel); |
| 1170 | if (!label->kernel_label) |
| 1171 | return -ENOMEM; |
| 1172 | |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1173 | s = strstr(label->kernel, "#"); |
| 1174 | if (!s) |
| 1175 | return 1; |
| 1176 | |
Patrick Delaunay | 9d464f8 | 2022-10-28 11:01:20 +0200 | [diff] [blame] | 1177 | label->config = strdup(s); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1178 | if (!label->config) |
| 1179 | return -ENOMEM; |
| 1180 | |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1181 | *s = 0; |
| 1182 | |
| 1183 | return 1; |
| 1184 | } |
| 1185 | |
| 1186 | /* |
| 1187 | * Parses a label and adds it to the list of labels for a menu. |
| 1188 | * |
| 1189 | * A label ends when we either get to the end of a file, or |
| 1190 | * get some input we otherwise don't have a handler defined |
| 1191 | * for. |
| 1192 | * |
| 1193 | */ |
| 1194 | static int parse_label(char **c, struct pxe_menu *cfg) |
| 1195 | { |
| 1196 | struct token t; |
| 1197 | int len; |
| 1198 | char *s = *c; |
| 1199 | struct pxe_label *label; |
| 1200 | int err; |
| 1201 | |
| 1202 | label = label_create(); |
| 1203 | if (!label) |
| 1204 | return -ENOMEM; |
| 1205 | |
| 1206 | err = parse_sliteral(c, &label->name); |
| 1207 | if (err < 0) { |
| 1208 | printf("Expected label name: %.*s\n", (int)(*c - s), s); |
| 1209 | label_destroy(label); |
| 1210 | return -EINVAL; |
| 1211 | } |
| 1212 | |
| 1213 | list_add_tail(&label->list, &cfg->labels); |
| 1214 | |
| 1215 | while (1) { |
| 1216 | s = *c; |
| 1217 | get_token(c, &t, L_KEYWORD); |
| 1218 | |
| 1219 | err = 0; |
| 1220 | switch (t.type) { |
| 1221 | case T_MENU: |
| 1222 | err = parse_label_menu(c, cfg, label); |
| 1223 | break; |
| 1224 | |
| 1225 | case T_KERNEL: |
| 1226 | case T_LINUX: |
| 1227 | err = parse_label_kernel(c, label); |
| 1228 | break; |
| 1229 | |
| 1230 | case T_APPEND: |
| 1231 | err = parse_sliteral(c, &label->append); |
| 1232 | if (label->initrd) |
| 1233 | break; |
| 1234 | s = strstr(label->append, "initrd="); |
| 1235 | if (!s) |
| 1236 | break; |
| 1237 | s += 7; |
| 1238 | len = (int)(strchr(s, ' ') - s); |
| 1239 | label->initrd = malloc(len + 1); |
| 1240 | strncpy(label->initrd, s, len); |
| 1241 | label->initrd[len] = '\0'; |
| 1242 | |
| 1243 | break; |
| 1244 | |
| 1245 | case T_INITRD: |
| 1246 | if (!label->initrd) |
| 1247 | err = parse_sliteral(c, &label->initrd); |
| 1248 | break; |
| 1249 | |
| 1250 | case T_FDT: |
| 1251 | if (!label->fdt) |
| 1252 | err = parse_sliteral(c, &label->fdt); |
| 1253 | break; |
| 1254 | |
| 1255 | case T_FDTDIR: |
| 1256 | if (!label->fdtdir) |
| 1257 | err = parse_sliteral(c, &label->fdtdir); |
| 1258 | break; |
| 1259 | |
Neil Armstrong | c77a1a3 | 2021-01-20 09:54:53 +0100 | [diff] [blame] | 1260 | case T_FDTOVERLAYS: |
| 1261 | if (!label->fdtoverlays) |
| 1262 | err = parse_sliteral(c, &label->fdtoverlays); |
| 1263 | break; |
| 1264 | |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1265 | case T_LOCALBOOT: |
| 1266 | label->localboot = 1; |
| 1267 | err = parse_integer(c, &label->localboot_val); |
| 1268 | break; |
| 1269 | |
| 1270 | case T_IPAPPEND: |
| 1271 | err = parse_integer(c, &label->ipappend); |
| 1272 | break; |
| 1273 | |
Zhang Ning | 9c1d9c5 | 2022-02-01 08:33:37 +0800 | [diff] [blame] | 1274 | case T_KASLRSEED: |
| 1275 | label->kaslrseed = 1; |
| 1276 | break; |
| 1277 | |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1278 | case T_EOL: |
| 1279 | break; |
| 1280 | |
| 1281 | default: |
| 1282 | /* |
| 1283 | * put the token back! we don't want it - it's the end |
| 1284 | * of a label and whatever token this is, it's |
| 1285 | * something for the menu level context to handle. |
| 1286 | */ |
| 1287 | *c = s; |
| 1288 | return 1; |
| 1289 | } |
| 1290 | |
| 1291 | if (err < 0) |
| 1292 | return err; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | * This 16 comes from the limit pxelinux imposes on nested includes. |
| 1298 | * |
| 1299 | * There is no reason at all we couldn't do more, but some limit helps prevent |
| 1300 | * infinite (until crash occurs) recursion if a file tries to include itself. |
| 1301 | */ |
| 1302 | #define MAX_NEST_LEVEL 16 |
| 1303 | |
| 1304 | /* |
| 1305 | * Entry point for parsing a menu file. nest_level indicates how many times |
| 1306 | * we've nested in includes. It will be 1 for the top level menu file. |
| 1307 | * |
| 1308 | * Returns 1 on success, < 0 on error. |
| 1309 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1310 | static int parse_pxefile_top(struct pxe_context *ctx, char *p, unsigned long base, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1311 | struct pxe_menu *cfg, int nest_level) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1312 | { |
| 1313 | struct token t; |
| 1314 | char *s, *b, *label_name; |
| 1315 | int err; |
| 1316 | |
| 1317 | b = p; |
| 1318 | |
| 1319 | if (nest_level > MAX_NEST_LEVEL) { |
| 1320 | printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL); |
| 1321 | return -EMLINK; |
| 1322 | } |
| 1323 | |
| 1324 | while (1) { |
| 1325 | s = p; |
| 1326 | |
| 1327 | get_token(&p, &t, L_KEYWORD); |
| 1328 | |
| 1329 | err = 0; |
| 1330 | switch (t.type) { |
| 1331 | case T_MENU: |
| 1332 | cfg->prompt = 1; |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1333 | err = parse_menu(ctx, &p, cfg, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1334 | base + ALIGN(strlen(b) + 1, 4), |
| 1335 | nest_level); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1336 | break; |
| 1337 | |
| 1338 | case T_TIMEOUT: |
| 1339 | err = parse_integer(&p, &cfg->timeout); |
| 1340 | break; |
| 1341 | |
| 1342 | case T_LABEL: |
| 1343 | err = parse_label(&p, cfg); |
| 1344 | break; |
| 1345 | |
| 1346 | case T_DEFAULT: |
| 1347 | case T_ONTIMEOUT: |
| 1348 | err = parse_sliteral(&p, &label_name); |
| 1349 | |
| 1350 | if (label_name) { |
| 1351 | if (cfg->default_label) |
| 1352 | free(cfg->default_label); |
| 1353 | |
| 1354 | cfg->default_label = label_name; |
| 1355 | } |
| 1356 | |
| 1357 | break; |
| 1358 | |
| 1359 | case T_INCLUDE: |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1360 | err = handle_include(ctx, &p, |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1361 | base + ALIGN(strlen(b), 4), cfg, |
| 1362 | nest_level + 1); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1363 | break; |
| 1364 | |
| 1365 | case T_PROMPT: |
Manuel Traut | 2008124 | 2022-11-18 09:00:27 +0100 | [diff] [blame] | 1366 | err = parse_integer(&p, &cfg->prompt); |
| 1367 | // Do not fail if prompt configuration is undefined |
| 1368 | if (err < 0) |
| 1369 | eol_or_eof(&p); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1370 | break; |
| 1371 | |
| 1372 | case T_EOL: |
| 1373 | break; |
| 1374 | |
| 1375 | case T_EOF: |
| 1376 | return 1; |
| 1377 | |
| 1378 | default: |
| 1379 | printf("Ignoring unknown command: %.*s\n", |
Patrice Chotard | 6233de4 | 2019-11-25 09:07:39 +0100 | [diff] [blame] | 1380 | (int)(p - s), s); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1381 | eol_or_eof(&p); |
| 1382 | } |
| 1383 | |
| 1384 | if (err < 0) |
| 1385 | return err; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /* |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1390 | */ |
| 1391 | void destroy_pxe_menu(struct pxe_menu *cfg) |
| 1392 | { |
| 1393 | struct list_head *pos, *n; |
| 1394 | struct pxe_label *label; |
| 1395 | |
Simon Glass | 764d0c0 | 2021-10-14 12:48:02 -0600 | [diff] [blame] | 1396 | free(cfg->title); |
| 1397 | free(cfg->default_label); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1398 | |
| 1399 | list_for_each_safe(pos, n, &cfg->labels) { |
| 1400 | label = list_entry(pos, struct pxe_label, list); |
| 1401 | |
| 1402 | label_destroy(label); |
| 1403 | } |
| 1404 | |
| 1405 | free(cfg); |
| 1406 | } |
| 1407 | |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1408 | struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1409 | { |
| 1410 | struct pxe_menu *cfg; |
| 1411 | char *buf; |
| 1412 | int r; |
| 1413 | |
| 1414 | cfg = malloc(sizeof(struct pxe_menu)); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1415 | if (!cfg) |
| 1416 | return NULL; |
| 1417 | |
| 1418 | memset(cfg, 0, sizeof(struct pxe_menu)); |
| 1419 | |
| 1420 | INIT_LIST_HEAD(&cfg->labels); |
| 1421 | |
| 1422 | buf = map_sysmem(menucfg, 0); |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1423 | r = parse_pxefile_top(ctx, buf, menucfg, cfg, 1); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1424 | unmap_sysmem(buf); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1425 | if (r < 0) { |
| 1426 | destroy_pxe_menu(cfg); |
| 1427 | return NULL; |
| 1428 | } |
| 1429 | |
| 1430 | return cfg; |
| 1431 | } |
| 1432 | |
| 1433 | /* |
| 1434 | * Converts a pxe_menu struct into a menu struct for use with U-Boot's generic |
| 1435 | * menu code. |
| 1436 | */ |
| 1437 | static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg) |
| 1438 | { |
| 1439 | struct pxe_label *label; |
| 1440 | struct list_head *pos; |
| 1441 | struct menu *m; |
Amjad Ouled-Ameur | 1d564a9 | 2021-11-13 14:09:20 +0100 | [diff] [blame] | 1442 | char *label_override; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1443 | int err; |
| 1444 | int i = 1; |
| 1445 | char *default_num = NULL; |
Amjad Ouled-Ameur | 1d564a9 | 2021-11-13 14:09:20 +0100 | [diff] [blame] | 1446 | char *override_num = NULL; |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1447 | |
| 1448 | /* |
| 1449 | * Create a menu and add items for all the labels. |
| 1450 | */ |
| 1451 | m = menu_create(cfg->title, DIV_ROUND_UP(cfg->timeout, 10), |
Thirupathaiah Annapureddy | d6b9f6b | 2020-03-18 11:38:42 -0700 | [diff] [blame] | 1452 | cfg->prompt, NULL, label_print, NULL, NULL); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1453 | if (!m) |
| 1454 | return NULL; |
| 1455 | |
Amjad Ouled-Ameur | 1d564a9 | 2021-11-13 14:09:20 +0100 | [diff] [blame] | 1456 | label_override = env_get("pxe_label_override"); |
| 1457 | |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1458 | list_for_each(pos, &cfg->labels) { |
| 1459 | label = list_entry(pos, struct pxe_label, list); |
| 1460 | |
| 1461 | sprintf(label->num, "%d", i++); |
| 1462 | if (menu_item_add(m, label->num, label) != 1) { |
| 1463 | menu_destroy(m); |
| 1464 | return NULL; |
| 1465 | } |
| 1466 | if (cfg->default_label && |
| 1467 | (strcmp(label->name, cfg->default_label) == 0)) |
| 1468 | default_num = label->num; |
Amjad Ouled-Ameur | 1d564a9 | 2021-11-13 14:09:20 +0100 | [diff] [blame] | 1469 | if (label_override && !strcmp(label->name, label_override)) |
| 1470 | override_num = label->num; |
| 1471 | } |
| 1472 | |
| 1473 | |
| 1474 | if (label_override) { |
| 1475 | if (override_num) |
| 1476 | default_num = override_num; |
| 1477 | else |
| 1478 | printf("Missing override pxe label: %s\n", |
| 1479 | label_override); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /* |
| 1483 | * After we've created items for each label in the menu, set the |
| 1484 | * menu's default label if one was specified. |
| 1485 | */ |
| 1486 | if (default_num) { |
| 1487 | err = menu_default_set(m, default_num); |
| 1488 | if (err != 1) { |
| 1489 | if (err != -ENOENT) { |
| 1490 | menu_destroy(m); |
| 1491 | return NULL; |
| 1492 | } |
| 1493 | |
| 1494 | printf("Missing default: %s\n", cfg->default_label); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | return m; |
| 1499 | } |
| 1500 | |
| 1501 | /* |
| 1502 | * Try to boot any labels we have yet to attempt to boot. |
| 1503 | */ |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1504 | static void boot_unattempted_labels(struct pxe_context *ctx, |
| 1505 | struct pxe_menu *cfg) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1506 | { |
| 1507 | struct list_head *pos; |
| 1508 | struct pxe_label *label; |
| 1509 | |
| 1510 | list_for_each(pos, &cfg->labels) { |
| 1511 | label = list_entry(pos, struct pxe_label, list); |
| 1512 | |
| 1513 | if (!label->attempted) |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1514 | label_boot(ctx, label); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1518 | void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg) |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1519 | { |
| 1520 | void *choice; |
| 1521 | struct menu *m; |
| 1522 | int err; |
| 1523 | |
Kory Maincent | caabd24 | 2021-02-02 16:42:28 +0100 | [diff] [blame] | 1524 | if (IS_ENABLED(CONFIG_CMD_BMP)) { |
| 1525 | /* display BMP if available */ |
| 1526 | if (cfg->bmp) { |
Simon Glass | a9401b9 | 2021-10-14 12:48:08 -0600 | [diff] [blame] | 1527 | if (get_relfile(ctx, cfg->bmp, image_load_addr, NULL)) { |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 1528 | #if defined(CONFIG_VIDEO) |
Patrick Delaunay | 6ec8cb9 | 2022-03-22 17:08:43 +0100 | [diff] [blame] | 1529 | struct udevice *dev; |
| 1530 | |
| 1531 | err = uclass_first_device_err(UCLASS_VIDEO, &dev); |
| 1532 | if (!err) |
| 1533 | video_clear(dev); |
| 1534 | #endif |
Kory Maincent | caabd24 | 2021-02-02 16:42:28 +0100 | [diff] [blame] | 1535 | bmp_display(image_load_addr, |
| 1536 | BMP_ALIGN_CENTER, BMP_ALIGN_CENTER); |
| 1537 | } else { |
| 1538 | printf("Skipping background bmp %s for failure\n", |
| 1539 | cfg->bmp); |
| 1540 | } |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1541 | } |
| 1542 | } |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1543 | |
| 1544 | m = pxe_menu_to_menu(cfg); |
| 1545 | if (!m) |
| 1546 | return; |
| 1547 | |
| 1548 | err = menu_get_choice(m, &choice); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1549 | menu_destroy(m); |
| 1550 | |
| 1551 | /* |
| 1552 | * err == 1 means we got a choice back from menu_get_choice. |
| 1553 | * |
| 1554 | * err == -ENOENT if the menu was setup to select the default but no |
| 1555 | * default was set. in that case, we should continue trying to boot |
| 1556 | * labels that haven't been attempted yet. |
| 1557 | * |
| 1558 | * otherwise, the user interrupted or there was some other error and |
| 1559 | * we give up. |
| 1560 | */ |
| 1561 | |
| 1562 | if (err == 1) { |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1563 | err = label_boot(ctx, choice); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1564 | if (!err) |
| 1565 | return; |
| 1566 | } else if (err != -ENOENT) { |
| 1567 | return; |
| 1568 | } |
| 1569 | |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1570 | boot_unattempted_labels(ctx, cfg); |
| 1571 | } |
| 1572 | |
Simon Glass | e719fe0 | 2021-10-14 12:48:04 -0600 | [diff] [blame] | 1573 | int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, |
| 1574 | pxe_getfile_func getfile, void *userdata, |
Sean Edmond | ba80286 | 2023-04-11 10:48:47 -0700 | [diff] [blame] | 1575 | bool allow_abs_path, const char *bootfile, bool use_ipv6) |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1576 | { |
Simon Glass | e719fe0 | 2021-10-14 12:48:04 -0600 | [diff] [blame] | 1577 | const char *last_slash; |
| 1578 | size_t path_len = 0; |
| 1579 | |
| 1580 | memset(ctx, '\0', sizeof(*ctx)); |
Simon Glass | b0d08db | 2021-10-14 12:47:56 -0600 | [diff] [blame] | 1581 | ctx->cmdtp = cmdtp; |
Simon Glass | 44a20ef | 2021-10-14 12:47:57 -0600 | [diff] [blame] | 1582 | ctx->getfile = getfile; |
Simon Glass | 121e131 | 2021-10-14 12:47:58 -0600 | [diff] [blame] | 1583 | ctx->userdata = userdata; |
Simon Glass | 3ae416a | 2021-10-14 12:47:59 -0600 | [diff] [blame] | 1584 | ctx->allow_abs_path = allow_abs_path; |
Sean Edmond | ba80286 | 2023-04-11 10:48:47 -0700 | [diff] [blame] | 1585 | ctx->use_ipv6 = use_ipv6; |
Simon Glass | e719fe0 | 2021-10-14 12:48:04 -0600 | [diff] [blame] | 1586 | |
| 1587 | /* figure out the boot directory, if there is one */ |
| 1588 | if (bootfile && strlen(bootfile) >= MAX_TFTP_PATH_LEN) |
| 1589 | return -ENOSPC; |
| 1590 | ctx->bootdir = strdup(bootfile ? bootfile : ""); |
| 1591 | if (!ctx->bootdir) |
| 1592 | return -ENOMEM; |
| 1593 | |
| 1594 | if (bootfile) { |
| 1595 | last_slash = strrchr(bootfile, '/'); |
| 1596 | if (last_slash) |
| 1597 | path_len = (last_slash - bootfile) + 1; |
| 1598 | } |
| 1599 | ctx->bootdir[path_len] = '\0'; |
| 1600 | |
| 1601 | return 0; |
| 1602 | } |
| 1603 | |
| 1604 | void pxe_destroy_ctx(struct pxe_context *ctx) |
| 1605 | { |
| 1606 | free(ctx->bootdir); |
Patrice Chotard | 17e8804 | 2019-11-25 09:07:37 +0100 | [diff] [blame] | 1607 | } |
Simon Glass | 791bbfe | 2021-10-14 12:48:03 -0600 | [diff] [blame] | 1608 | |
| 1609 | int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt) |
| 1610 | { |
| 1611 | struct pxe_menu *cfg; |
| 1612 | |
| 1613 | cfg = parse_pxefile(ctx, pxefile_addr_r); |
| 1614 | if (!cfg) { |
| 1615 | printf("Error parsing config file\n"); |
| 1616 | return 1; |
| 1617 | } |
| 1618 | |
| 1619 | if (prompt) |
| 1620 | cfg->prompt = 1; |
| 1621 | |
| 1622 | handle_pxe_menu(ctx, cfg); |
| 1623 | |
| 1624 | destroy_pxe_menu(cfg); |
| 1625 | |
| 1626 | return 0; |
| 1627 | } |