1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2010-2011 Calxeda, Inc.
4 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
16 #include <linux/string.h>
17 #include <linux/ctype.h>
19 #include <linux/list.h>
27 #include "pxe_utils.h"
29 #define MAX_TFTP_PATH_LEN 512
34 * Convert an ethaddr from the environment to the format used by pxelinux
35 * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
36 * the beginning of the ethernet address to indicate a hardware type of
37 * Ethernet. Also converts uppercase hex characters into lowercase, to match
38 * pxelinux's behavior.
40 * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
41 * environment, or some other value < 0 on error.
43 int format_mac_pxe(char *outbuf, size_t outbuf_len)
47 if (outbuf_len < 21) {
48 printf("outbuf is too small (%zd < 21)\n", outbuf_len);
53 if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr))
56 sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x",
57 ethaddr[0], ethaddr[1], ethaddr[2],
58 ethaddr[3], ethaddr[4], ethaddr[5]);
64 * Returns the directory the file specified in the bootfile env variable is
65 * in. If bootfile isn't defined in the environment, return NULL, which should
66 * be interpreted as "don't prepend anything to paths".
68 static int get_bootfile_path(const char *file_path, char *bootfile_path,
69 size_t bootfile_path_size)
71 char *bootfile, *last_slash;
74 /* Only syslinux allows absolute paths */
75 if (file_path[0] == '/' && !is_pxe)
78 bootfile = from_env("bootfile");
83 last_slash = strrchr(bootfile, '/');
88 path_len = (last_slash - bootfile) + 1;
90 if (bootfile_path_size < path_len) {
91 printf("bootfile_path too small. (%zd < %zd)\n",
92 bootfile_path_size, path_len);
97 strncpy(bootfile_path, bootfile, path_len);
100 bootfile_path[path_len] = '\0';
105 int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
109 * As in pxelinux, paths to files referenced from files we retrieve are
110 * relative to the location of bootfile. get_relfile takes such a path and
111 * joins it with the bootfile path to get the full path to the target file. If
112 * the bootfile path is NULL, we use file_path as is.
114 * Returns 1 for success, or < 0 on error.
116 static int get_relfile(struct cmd_tbl *cmdtp, const char *file_path,
117 unsigned long file_addr)
120 char relfile[MAX_TFTP_PATH_LEN + 1];
124 err = get_bootfile_path(file_path, relfile, sizeof(relfile));
129 path_len = strlen(file_path);
130 path_len += strlen(relfile);
132 if (path_len > MAX_TFTP_PATH_LEN) {
133 printf("Base path too long (%s%s)\n", relfile, file_path);
135 return -ENAMETOOLONG;
138 strcat(relfile, file_path);
140 printf("Retrieving file: %s\n", relfile);
142 sprintf(addr_buf, "%lx", file_addr);
144 return do_getfile(cmdtp, relfile, addr_buf);
148 * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
149 * 'bootfile' was specified in the environment, the path to bootfile will be
150 * prepended to 'file_path' and the resulting path will be used.
152 * Returns 1 on success, or < 0 for error.
154 int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
155 unsigned long file_addr)
157 unsigned long config_file_size;
162 err = get_relfile(cmdtp, file_path, file_addr);
168 * the file comes without a NUL byte at the end, so find out its size
169 * and add the NUL byte.
171 tftp_filesize = from_env("filesize");
176 if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
179 buf = map_sysmem(file_addr + config_file_size, 1);
186 #define PXELINUX_DIR "pxelinux.cfg/"
189 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
190 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
191 * from the bootfile path, as described above.
193 * Returns 1 on success or < 0 on error.
195 int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
196 unsigned long pxefile_addr_r)
198 size_t base_len = strlen(PXELINUX_DIR);
199 char path[MAX_TFTP_PATH_LEN + 1];
201 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
202 printf("path (%s%s) too long, skipping\n",
204 return -ENAMETOOLONG;
207 sprintf(path, PXELINUX_DIR "%s", file);
209 return get_pxe_file(cmdtp, path, pxefile_addr_r);
213 * Wrapper to make it easier to store the file at file_path in the location
214 * specified by envaddr_name. file_path will be joined to the bootfile path,
215 * if any is specified.
217 * Returns 1 on success or < 0 on error.
219 static int get_relfile_envaddr(struct cmd_tbl *cmdtp, const char *file_path,
220 const char *envaddr_name)
222 unsigned long file_addr;
225 envaddr = from_env(envaddr_name);
230 if (strict_strtoul(envaddr, 16, &file_addr) < 0)
233 return get_relfile(cmdtp, file_path, file_addr);
237 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
238 * result must be free()'d to reclaim the memory.
240 * Returns NULL if malloc fails.
242 static struct pxe_label *label_create(void)
244 struct pxe_label *label;
246 label = malloc(sizeof(struct pxe_label));
251 memset(label, 0, sizeof(struct pxe_label));
257 * Free the memory used by a pxe_label, including that used by its name,
258 * kernel, append and initrd members, if they're non NULL.
260 * So - be sure to only use dynamically allocated memory for the members of
261 * the pxe_label struct, unless you want to clean it up first. These are
262 * currently only created by the pxe file parsing code.
264 static void label_destroy(struct pxe_label *label)
291 * Print a label and its string members if they're defined.
293 * This is passed as a callback to the menu code for displaying each
296 static void label_print(void *data)
298 struct pxe_label *label = data;
299 const char *c = label->menu ? label->menu : label->name;
301 printf("%s:\t%s\n", label->num, c);
305 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
306 * environment variable is defined. Its contents will be executed as U-Boot
307 * command. If the label specified an 'append' line, its contents will be
308 * used to overwrite the contents of the 'bootargs' environment variable prior
309 * to running 'localcmd'.
311 * Returns 1 on success or < 0 on error.
313 static int label_localboot(struct pxe_label *label)
317 localcmd = from_env("localcmd");
323 char bootargs[CONFIG_SYS_CBSIZE];
325 cli_simple_process_macros(label->append, bootargs);
326 env_set("bootargs", bootargs);
329 debug("running: %s\n", localcmd);
331 return run_command_list(localcmd, strlen(localcmd), 0);
335 * Boot according to the contents of a pxe_label.
337 * If we can't boot for any reason, we return. A successful boot never
340 * The kernel will be stored in the location given by the 'kernel_addr_r'
341 * environment variable.
343 * If the label specifies an initrd file, it will be stored in the location
344 * given by the 'ramdisk_addr_r' environment variable.
346 * If the label specifies an 'append' line, its contents will overwrite that
347 * of the 'bootargs' environment variable.
349 static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
351 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
353 char mac_str[29] = "";
354 char ip_str[68] = "";
355 char *fit_addr = NULL;
363 label->attempted = 1;
365 if (label->localboot) {
366 if (label->localboot_val >= 0)
367 label_localboot(label);
371 if (!label->kernel) {
372 printf("No kernel given, skipping %s\n",
378 if (get_relfile_envaddr(cmdtp, label->initrd, "ramdisk_addr_r") < 0) {
379 printf("Skipping %s for failure retrieving initrd\n",
384 bootm_argv[2] = initrd_str;
385 strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18);
386 strcat(bootm_argv[2], ":");
387 strncat(bootm_argv[2], env_get("filesize"), 9);
391 if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
392 printf("Skipping %s for failure retrieving kernel\n",
397 if (label->ipappend & 0x1) {
398 sprintf(ip_str, " ip=%s:%s:%s:%s",
399 env_get("ipaddr"), env_get("serverip"),
400 env_get("gatewayip"), env_get("netmask"));
403 #ifdef CONFIG_CMD_NET
404 if (label->ipappend & 0x2) {
407 strcpy(mac_str, " BOOTIF=");
408 err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
414 if ((label->ipappend & 0x3) || label->append) {
415 char bootargs[CONFIG_SYS_CBSIZE] = "";
416 char finalbootargs[CONFIG_SYS_CBSIZE];
418 if (strlen(label->append ?: "") +
419 strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) {
420 printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n",
421 strlen(label->append ?: ""),
422 strlen(ip_str), strlen(mac_str),
428 strncpy(bootargs, label->append, sizeof(bootargs));
430 strcat(bootargs, ip_str);
431 strcat(bootargs, mac_str);
433 cli_simple_process_macros(bootargs, finalbootargs);
434 env_set("bootargs", finalbootargs);
435 printf("append: %s\n", finalbootargs);
438 bootm_argv[1] = env_get("kernel_addr_r");
439 /* for FIT, append the configuration identifier */
441 int len = strlen(bootm_argv[1]) + strlen(label->config) + 1;
443 fit_addr = malloc(len);
445 printf("malloc fail (FIT address)\n");
448 snprintf(fit_addr, len, "%s%s", bootm_argv[1], label->config);
449 bootm_argv[1] = fit_addr;
453 * fdt usage is optional:
454 * It handles the following scenarios. All scenarios are exclusive
456 * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
457 * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
458 * and adjust argc appropriately.
460 * Scenario 2: If there is an fdt_addr specified, pass it along to
461 * bootm, and adjust argc appropriately.
463 * Scenario 3: fdt blob is not available.
465 bootm_argv[3] = env_get("fdt_addr_r");
467 /* if fdt label is defined then get fdt from server */
469 char *fdtfile = NULL;
470 char *fdtfilefree = NULL;
473 fdtfile = label->fdt;
474 } else if (label->fdtdir) {
475 char *f1, *f2, *f3, *f4, *slash;
477 f1 = env_get("fdtfile");
484 * For complex cases where this code doesn't
485 * generate the correct filename, the board
486 * code should set $fdtfile during early boot,
487 * or the boot scripts should set $fdtfile
488 * before invoking "pxe" or "sysboot".
492 f3 = env_get("board");
496 len = strlen(label->fdtdir);
499 else if (label->fdtdir[len - 1] != '/')
504 len = strlen(label->fdtdir) + strlen(slash) +
505 strlen(f1) + strlen(f2) + strlen(f3) +
507 fdtfilefree = malloc(len);
509 printf("malloc fail (FDT filename)\n");
513 snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
514 label->fdtdir, slash, f1, f2, f3, f4);
515 fdtfile = fdtfilefree;
519 int err = get_relfile_envaddr(cmdtp, fdtfile,
524 printf("Skipping %s for failure retrieving fdt\n",
529 bootm_argv[3] = NULL;
534 bootm_argv[3] = env_get("fdt_addr");
542 kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
543 buf = map_sysmem(kernel_addr, 0);
544 /* Try bootm for legacy and FIT format image */
545 if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
546 do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
547 #ifdef CONFIG_CMD_BOOTI
548 /* Try booting an AArch64 Linux kernel image */
550 do_booti(cmdtp, 0, bootm_argc, bootm_argv);
551 #elif defined(CONFIG_CMD_BOOTZ)
552 /* Try booting a Image */
554 do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
565 * Tokens for the pxe file parser.
592 * A token - given by a value and a type.
596 enum token_type type;
600 * Keywords recognized.
602 static const struct token keywords[] = {
605 {"timeout", T_TIMEOUT},
606 {"default", T_DEFAULT},
607 {"prompt", T_PROMPT},
609 {"kernel", T_KERNEL},
611 {"localboot", T_LOCALBOOT},
612 {"append", T_APPEND},
613 {"initrd", T_INITRD},
614 {"include", T_INCLUDE},
615 {"devicetree", T_FDT},
617 {"devicetreedir", T_FDTDIR},
618 {"fdtdir", T_FDTDIR},
619 {"ontimeout", T_ONTIMEOUT,},
620 {"ipappend", T_IPAPPEND,},
621 {"background", T_BACKGROUND,},
626 * Since pxe(linux) files don't have a token to identify the start of a
627 * literal, we have to keep track of when we're in a state where a literal is
628 * expected vs when we're in a state a keyword is expected.
637 * get_string retrieves a string from *p and stores it as a token in
640 * get_string used for scanning both string literals and keywords.
642 * Characters from *p are copied into t-val until a character equal to
643 * delim is found, or a NUL byte is reached. If delim has the special value of
644 * ' ', any whitespace character will be used as a delimiter.
646 * If lower is unequal to 0, uppercase characters will be converted to
647 * lowercase in the result. This is useful to make keywords case
650 * The location of *p is updated to point to the first character after the end
651 * of the token - the ending delimiter.
653 * On success, the new value of t->val is returned. Memory for t->val is
654 * allocated using malloc and must be free()'d to reclaim it. If insufficient
655 * memory is available, NULL is returned.
657 static char *get_string(char **p, struct token *t, char delim, int lower)
663 * b and e both start at the beginning of the input stream.
665 * e is incremented until we find the ending delimiter, or a NUL byte
666 * is reached. Then, we take e - b to find the length of the token.
672 if ((delim == ' ' && isspace(*e)) || delim == *e)
680 * Allocate memory to hold the string, and copy it in, converting
681 * characters to lowercase if lower is != 0.
683 t->val = malloc(len + 1);
687 for (i = 0; i < len; i++, b++) {
689 t->val[i] = tolower(*b);
697 * Update *p so the caller knows where to continue scanning.
707 * Populate a keyword token with a type and value.
709 static void get_keyword(struct token *t)
713 for (i = 0; keywords[i].val; i++) {
714 if (!strcmp(t->val, keywords[i].val)) {
715 t->type = keywords[i].type;
722 * Get the next token. We have to keep track of which state we're in to know
723 * if we're looking to get a string literal or a keyword.
725 * *p is updated to point at the first character after the current token.
727 static void get_token(char **p, struct token *t, enum lex_state state)
733 /* eat non EOL whitespace */
738 * eat comments. note that string literals can't begin with #, but
739 * can contain a # after their first character.
742 while (*c && *c != '\n')
749 } else if (*c == '\0') {
752 } else if (state == L_SLITERAL) {
753 get_string(&c, t, '\n', 0);
754 } else if (state == L_KEYWORD) {
756 * when we expect a keyword, we first get the next string
757 * token delimited by whitespace, and then check if it
758 * matches a keyword in our keyword list. if it does, it's
759 * converted to a keyword token of the appropriate type, and
760 * if not, it remains a string token.
762 get_string(&c, t, ' ', 1);
770 * Increment *c until we get to the end of the current line, or EOF.
772 static void eol_or_eof(char **c)
774 while (**c && **c != '\n')
779 * All of these parse_* functions share some common behavior.
781 * They finish with *c pointing after the token they parse, and return 1 on
782 * success, or < 0 on error.
786 * Parse a string literal and store a pointer it at *dst. String literals
787 * terminate at the end of the line.
789 static int parse_sliteral(char **c, char **dst)
794 get_token(c, &t, L_SLITERAL);
796 if (t.type != T_STRING) {
797 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
807 * Parse a base 10 (unsigned) integer and store it at *dst.
809 static int parse_integer(char **c, int *dst)
814 get_token(c, &t, L_SLITERAL);
816 if (t.type != T_STRING) {
817 printf("Expected string: %.*s\n", (int)(*c - s), s);
821 *dst = simple_strtol(t.val, NULL, 10);
828 static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
829 struct pxe_menu *cfg, int nest_level);
832 * Parse an include statement, and retrieve and parse the file it mentions.
834 * base should point to a location where it's safe to store the file, and
835 * nest_level should indicate how many nested includes have occurred. For this
836 * include, nest_level has already been incremented and doesn't need to be
839 static int handle_include(struct cmd_tbl *cmdtp, char **c, unsigned long base,
840 struct pxe_menu *cfg, int nest_level)
848 err = parse_sliteral(c, &include_path);
851 printf("Expected include path: %.*s\n", (int)(*c - s), s);
855 err = get_pxe_file(cmdtp, include_path, base);
858 printf("Couldn't retrieve %s\n", include_path);
862 buf = map_sysmem(base, 0);
863 ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
870 * Parse lines that begin with 'menu'.
872 * base and nest are provided to handle the 'menu include' case.
874 * base should point to a location where it's safe to store the included file.
876 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
877 * a file it includes, 3 when parsing a file included by that file, and so on.
879 static int parse_menu(struct cmd_tbl *cmdtp, char **c, struct pxe_menu *cfg,
880 unsigned long base, int nest_level)
886 get_token(c, &t, L_KEYWORD);
890 err = parse_sliteral(c, &cfg->title);
895 err = handle_include(cmdtp, c, base, cfg, nest_level + 1);
899 err = parse_sliteral(c, &cfg->bmp);
903 printf("Ignoring malformed menu command: %.*s\n",
916 * Handles parsing a 'menu line' when we're parsing a label.
918 static int parse_label_menu(char **c, struct pxe_menu *cfg,
919 struct pxe_label *label)
926 get_token(c, &t, L_KEYWORD);
930 if (!cfg->default_label)
931 cfg->default_label = strdup(label->name);
933 if (!cfg->default_label)
938 parse_sliteral(c, &label->menu);
941 printf("Ignoring malformed menu command: %.*s\n",
951 * Handles parsing a 'kernel' label.
952 * expecting "filename" or "<fit_filename>#cfg"
954 static int parse_label_kernel(char **c, struct pxe_label *label)
959 err = parse_sliteral(c, &label->kernel);
963 s = strstr(label->kernel, "#");
967 label->config = malloc(strlen(s) + 1);
971 strcpy(label->config, s);
978 * Parses a label and adds it to the list of labels for a menu.
980 * A label ends when we either get to the end of a file, or
981 * get some input we otherwise don't have a handler defined
985 static int parse_label(char **c, struct pxe_menu *cfg)
990 struct pxe_label *label;
993 label = label_create();
997 err = parse_sliteral(c, &label->name);
999 printf("Expected label name: %.*s\n", (int)(*c - s), s);
1000 label_destroy(label);
1004 list_add_tail(&label->list, &cfg->labels);
1008 get_token(c, &t, L_KEYWORD);
1013 err = parse_label_menu(c, cfg, label);
1018 err = parse_label_kernel(c, label);
1022 err = parse_sliteral(c, &label->append);
1025 s = strstr(label->append, "initrd=");
1029 len = (int)(strchr(s, ' ') - s);
1030 label->initrd = malloc(len + 1);
1031 strncpy(label->initrd, s, len);
1032 label->initrd[len] = '\0';
1038 err = parse_sliteral(c, &label->initrd);
1043 err = parse_sliteral(c, &label->fdt);
1048 err = parse_sliteral(c, &label->fdtdir);
1052 label->localboot = 1;
1053 err = parse_integer(c, &label->localboot_val);
1057 err = parse_integer(c, &label->ipappend);
1065 * put the token back! we don't want it - it's the end
1066 * of a label and whatever token this is, it's
1067 * something for the menu level context to handle.
1079 * This 16 comes from the limit pxelinux imposes on nested includes.
1081 * There is no reason at all we couldn't do more, but some limit helps prevent
1082 * infinite (until crash occurs) recursion if a file tries to include itself.
1084 #define MAX_NEST_LEVEL 16
1087 * Entry point for parsing a menu file. nest_level indicates how many times
1088 * we've nested in includes. It will be 1 for the top level menu file.
1090 * Returns 1 on success, < 0 on error.
1092 static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
1093 struct pxe_menu *cfg, int nest_level)
1096 char *s, *b, *label_name;
1101 if (nest_level > MAX_NEST_LEVEL) {
1102 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1109 get_token(&p, &t, L_KEYWORD);
1115 err = parse_menu(cmdtp, &p, cfg,
1116 base + ALIGN(strlen(b) + 1, 4),
1121 err = parse_integer(&p, &cfg->timeout);
1125 err = parse_label(&p, cfg);
1130 err = parse_sliteral(&p, &label_name);
1133 if (cfg->default_label)
1134 free(cfg->default_label);
1136 cfg->default_label = label_name;
1142 err = handle_include(cmdtp, &p,
1143 base + ALIGN(strlen(b), 4), cfg,
1158 printf("Ignoring unknown command: %.*s\n",
1169 * Free the memory used by a pxe_menu and its labels.
1171 void destroy_pxe_menu(struct pxe_menu *cfg)
1173 struct list_head *pos, *n;
1174 struct pxe_label *label;
1179 if (cfg->default_label)
1180 free(cfg->default_label);
1182 list_for_each_safe(pos, n, &cfg->labels) {
1183 label = list_entry(pos, struct pxe_label, list);
1185 label_destroy(label);
1192 * Entry point for parsing a pxe file. This is only used for the top level
1195 * Returns NULL if there is an error, otherwise, returns a pointer to a
1196 * pxe_menu struct populated with the results of parsing the pxe file (and any
1197 * files it includes). The resulting pxe_menu struct can be free()'d by using
1198 * the destroy_pxe_menu() function.
1200 struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, unsigned long menucfg)
1202 struct pxe_menu *cfg;
1206 cfg = malloc(sizeof(struct pxe_menu));
1211 memset(cfg, 0, sizeof(struct pxe_menu));
1213 INIT_LIST_HEAD(&cfg->labels);
1215 buf = map_sysmem(menucfg, 0);
1216 r = parse_pxefile_top(cmdtp, buf, menucfg, cfg, 1);
1220 destroy_pxe_menu(cfg);
1228 * Converts a pxe_menu struct into a menu struct for use with U-Boot's generic
1231 static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1233 struct pxe_label *label;
1234 struct list_head *pos;
1238 char *default_num = NULL;
1241 * Create a menu and add items for all the labels.
1243 m = menu_create(cfg->title, DIV_ROUND_UP(cfg->timeout, 10),
1244 cfg->prompt, NULL, label_print, NULL, NULL);
1249 list_for_each(pos, &cfg->labels) {
1250 label = list_entry(pos, struct pxe_label, list);
1252 sprintf(label->num, "%d", i++);
1253 if (menu_item_add(m, label->num, label) != 1) {
1257 if (cfg->default_label &&
1258 (strcmp(label->name, cfg->default_label) == 0))
1259 default_num = label->num;
1263 * After we've created items for each label in the menu, set the
1264 * menu's default label if one was specified.
1267 err = menu_default_set(m, default_num);
1269 if (err != -ENOENT) {
1274 printf("Missing default: %s\n", cfg->default_label);
1282 * Try to boot any labels we have yet to attempt to boot.
1284 static void boot_unattempted_labels(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
1286 struct list_head *pos;
1287 struct pxe_label *label;
1289 list_for_each(pos, &cfg->labels) {
1290 label = list_entry(pos, struct pxe_label, list);
1292 if (!label->attempted)
1293 label_boot(cmdtp, label);
1298 * Boot the system as prescribed by a pxe_menu.
1300 * Use the menu system to either get the user's choice or the default, based
1301 * on config or user input. If there is no default or user's choice,
1302 * attempted to boot labels in the order they were given in pxe files.
1303 * If the default or user's choice fails to boot, attempt to boot other
1304 * labels in the order they were given in pxe files.
1306 * If this function returns, there weren't any labels that successfully
1307 * booted, or the user interrupted the menu selection via ctrl+c.
1309 void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
1315 #ifdef CONFIG_CMD_BMP
1316 /* display BMP if available */
1318 if (get_relfile(cmdtp, cfg->bmp, image_load_addr)) {
1319 if (CONFIG_IS_ENABLED(CMD_CLS))
1320 run_command("cls", 0);
1321 bmp_display(image_load_addr,
1322 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
1324 printf("Skipping background bmp %s for failure\n",
1330 m = pxe_menu_to_menu(cfg);
1334 err = menu_get_choice(m, &choice);
1339 * err == 1 means we got a choice back from menu_get_choice.
1341 * err == -ENOENT if the menu was setup to select the default but no
1342 * default was set. in that case, we should continue trying to boot
1343 * labels that haven't been attempted yet.
1345 * otherwise, the user interrupted or there was some other error and
1350 err = label_boot(cmdtp, choice);
1353 } else if (err != -ENOENT) {
1357 boot_unattempted_labels(cmdtp, cfg);