1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2010-2011 Calxeda, Inc.
4 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
15 #include <linux/string.h>
16 #include <linux/ctype.h>
18 #include <linux/list.h>
26 #include "pxe_utils.h"
28 #define MAX_TFTP_PATH_LEN 512
33 * Convert an ethaddr from the environment to the format used by pxelinux
34 * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
35 * the beginning of the ethernet address to indicate a hardware type of
36 * Ethernet. Also converts uppercase hex characters into lowercase, to match
37 * pxelinux's behavior.
39 * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
40 * environment, or some other value < 0 on error.
42 int format_mac_pxe(char *outbuf, size_t outbuf_len)
46 if (outbuf_len < 21) {
47 printf("outbuf is too small (%zd < 21)\n", outbuf_len);
52 if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr))
55 sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x",
56 ethaddr[0], ethaddr[1], ethaddr[2],
57 ethaddr[3], ethaddr[4], ethaddr[5]);
63 * Returns the directory the file specified in the bootfile env variable is
64 * in. If bootfile isn't defined in the environment, return NULL, which should
65 * be interpreted as "don't prepend anything to paths".
67 static int get_bootfile_path(const char *file_path, char *bootfile_path,
68 size_t bootfile_path_size)
70 char *bootfile, *last_slash;
73 /* Only syslinux allows absolute paths */
74 if (file_path[0] == '/' && !is_pxe)
77 bootfile = from_env("bootfile");
82 last_slash = strrchr(bootfile, '/');
87 path_len = (last_slash - bootfile) + 1;
89 if (bootfile_path_size < path_len) {
90 printf("bootfile_path too small. (%zd < %zd)\n",
91 bootfile_path_size, path_len);
96 strncpy(bootfile_path, bootfile, path_len);
99 bootfile_path[path_len] = '\0';
104 int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
108 * As in pxelinux, paths to files referenced from files we retrieve are
109 * relative to the location of bootfile. get_relfile takes such a path and
110 * joins it with the bootfile path to get the full path to the target file. If
111 * the bootfile path is NULL, we use file_path as is.
113 * Returns 1 for success, or < 0 on error.
115 static int get_relfile(struct cmd_tbl *cmdtp, const char *file_path,
116 unsigned long file_addr)
119 char relfile[MAX_TFTP_PATH_LEN + 1];
123 err = get_bootfile_path(file_path, relfile, sizeof(relfile));
128 path_len = strlen(file_path);
129 path_len += strlen(relfile);
131 if (path_len > MAX_TFTP_PATH_LEN) {
132 printf("Base path too long (%s%s)\n", relfile, file_path);
134 return -ENAMETOOLONG;
137 strcat(relfile, file_path);
139 printf("Retrieving file: %s\n", relfile);
141 sprintf(addr_buf, "%lx", file_addr);
143 return do_getfile(cmdtp, relfile, addr_buf);
147 * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
148 * 'bootfile' was specified in the environment, the path to bootfile will be
149 * prepended to 'file_path' and the resulting path will be used.
151 * Returns 1 on success, or < 0 for error.
153 int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
154 unsigned long file_addr)
156 unsigned long config_file_size;
161 err = get_relfile(cmdtp, file_path, file_addr);
167 * the file comes without a NUL byte at the end, so find out its size
168 * and add the NUL byte.
170 tftp_filesize = from_env("filesize");
175 if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
178 buf = map_sysmem(file_addr + config_file_size, 1);
185 #define PXELINUX_DIR "pxelinux.cfg/"
188 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
189 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
190 * from the bootfile path, as described above.
192 * Returns 1 on success or < 0 on error.
194 int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
195 unsigned long pxefile_addr_r)
197 size_t base_len = strlen(PXELINUX_DIR);
198 char path[MAX_TFTP_PATH_LEN + 1];
200 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
201 printf("path (%s%s) too long, skipping\n",
203 return -ENAMETOOLONG;
206 sprintf(path, PXELINUX_DIR "%s", file);
208 return get_pxe_file(cmdtp, path, pxefile_addr_r);
212 * Wrapper to make it easier to store the file at file_path in the location
213 * specified by envaddr_name. file_path will be joined to the bootfile path,
214 * if any is specified.
216 * Returns 1 on success or < 0 on error.
218 static int get_relfile_envaddr(struct cmd_tbl *cmdtp, const char *file_path,
219 const char *envaddr_name)
221 unsigned long file_addr;
224 envaddr = from_env(envaddr_name);
229 if (strict_strtoul(envaddr, 16, &file_addr) < 0)
232 return get_relfile(cmdtp, file_path, file_addr);
236 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
237 * result must be free()'d to reclaim the memory.
239 * Returns NULL if malloc fails.
241 static struct pxe_label *label_create(void)
243 struct pxe_label *label;
245 label = malloc(sizeof(struct pxe_label));
250 memset(label, 0, sizeof(struct pxe_label));
256 * Free the memory used by a pxe_label, including that used by its name,
257 * kernel, append and initrd members, if they're non NULL.
259 * So - be sure to only use dynamically allocated memory for the members of
260 * the pxe_label struct, unless you want to clean it up first. These are
261 * currently only created by the pxe file parsing code.
263 static void label_destroy(struct pxe_label *label)
290 * Print a label and its string members if they're defined.
292 * This is passed as a callback to the menu code for displaying each
295 static void label_print(void *data)
297 struct pxe_label *label = data;
298 const char *c = label->menu ? label->menu : label->name;
300 printf("%s:\t%s\n", label->num, c);
304 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
305 * environment variable is defined. Its contents will be executed as U-Boot
306 * command. If the label specified an 'append' line, its contents will be
307 * used to overwrite the contents of the 'bootargs' environment variable prior
308 * to running 'localcmd'.
310 * Returns 1 on success or < 0 on error.
312 static int label_localboot(struct pxe_label *label)
316 localcmd = from_env("localcmd");
322 char bootargs[CONFIG_SYS_CBSIZE];
324 cli_simple_process_macros(label->append, bootargs);
325 env_set("bootargs", bootargs);
328 debug("running: %s\n", localcmd);
330 return run_command_list(localcmd, strlen(localcmd), 0);
334 * Boot according to the contents of a pxe_label.
336 * If we can't boot for any reason, we return. A successful boot never
339 * The kernel will be stored in the location given by the 'kernel_addr_r'
340 * environment variable.
342 * If the label specifies an initrd file, it will be stored in the location
343 * given by the 'ramdisk_addr_r' environment variable.
345 * If the label specifies an 'append' line, its contents will overwrite that
346 * of the 'bootargs' environment variable.
348 static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
350 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
352 char mac_str[29] = "";
353 char ip_str[68] = "";
354 char *fit_addr = NULL;
362 label->attempted = 1;
364 if (label->localboot) {
365 if (label->localboot_val >= 0)
366 label_localboot(label);
370 if (!label->kernel) {
371 printf("No kernel given, skipping %s\n",
377 if (get_relfile_envaddr(cmdtp, label->initrd, "ramdisk_addr_r") < 0) {
378 printf("Skipping %s for failure retrieving initrd\n",
383 bootm_argv[2] = initrd_str;
384 strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18);
385 strcat(bootm_argv[2], ":");
386 strncat(bootm_argv[2], env_get("filesize"), 9);
390 if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
391 printf("Skipping %s for failure retrieving kernel\n",
396 if (label->ipappend & 0x1) {
397 sprintf(ip_str, " ip=%s:%s:%s:%s",
398 env_get("ipaddr"), env_get("serverip"),
399 env_get("gatewayip"), env_get("netmask"));
402 #ifdef CONFIG_CMD_NET
403 if (label->ipappend & 0x2) {
406 strcpy(mac_str, " BOOTIF=");
407 err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
413 if ((label->ipappend & 0x3) || label->append) {
414 char bootargs[CONFIG_SYS_CBSIZE] = "";
415 char finalbootargs[CONFIG_SYS_CBSIZE];
417 if (strlen(label->append ?: "") +
418 strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) {
419 printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n",
420 strlen(label->append ?: ""),
421 strlen(ip_str), strlen(mac_str),
427 strncpy(bootargs, label->append, sizeof(bootargs));
429 strcat(bootargs, ip_str);
430 strcat(bootargs, mac_str);
432 cli_simple_process_macros(bootargs, finalbootargs);
433 env_set("bootargs", finalbootargs);
434 printf("append: %s\n", finalbootargs);
437 bootm_argv[1] = env_get("kernel_addr_r");
438 /* for FIT, append the configuration identifier */
440 int len = strlen(bootm_argv[1]) + strlen(label->config) + 1;
442 fit_addr = malloc(len);
444 printf("malloc fail (FIT address)\n");
447 snprintf(fit_addr, len, "%s%s", bootm_argv[1], label->config);
448 bootm_argv[1] = fit_addr;
452 * fdt usage is optional:
453 * It handles the following scenarios. All scenarios are exclusive
455 * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
456 * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
457 * and adjust argc appropriately.
459 * Scenario 2: If there is an fdt_addr specified, pass it along to
460 * bootm, and adjust argc appropriately.
462 * Scenario 3: fdt blob is not available.
464 bootm_argv[3] = env_get("fdt_addr_r");
466 /* if fdt label is defined then get fdt from server */
468 char *fdtfile = NULL;
469 char *fdtfilefree = NULL;
472 fdtfile = label->fdt;
473 } else if (label->fdtdir) {
474 char *f1, *f2, *f3, *f4, *slash;
476 f1 = env_get("fdtfile");
483 * For complex cases where this code doesn't
484 * generate the correct filename, the board
485 * code should set $fdtfile during early boot,
486 * or the boot scripts should set $fdtfile
487 * before invoking "pxe" or "sysboot".
491 f3 = env_get("board");
495 len = strlen(label->fdtdir);
498 else if (label->fdtdir[len - 1] != '/')
503 len = strlen(label->fdtdir) + strlen(slash) +
504 strlen(f1) + strlen(f2) + strlen(f3) +
506 fdtfilefree = malloc(len);
508 printf("malloc fail (FDT filename)\n");
512 snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
513 label->fdtdir, slash, f1, f2, f3, f4);
514 fdtfile = fdtfilefree;
518 int err = get_relfile_envaddr(cmdtp, fdtfile,
523 printf("Skipping %s for failure retrieving fdt\n",
528 bootm_argv[3] = NULL;
533 bootm_argv[3] = env_get("fdt_addr");
541 kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
542 buf = map_sysmem(kernel_addr, 0);
543 /* Try bootm for legacy and FIT format image */
544 if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
545 do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
546 #ifdef CONFIG_CMD_BOOTI
547 /* Try booting an AArch64 Linux kernel image */
549 do_booti(cmdtp, 0, bootm_argc, bootm_argv);
550 #elif defined(CONFIG_CMD_BOOTZ)
551 /* Try booting a Image */
553 do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
564 * Tokens for the pxe file parser.
591 * A token - given by a value and a type.
595 enum token_type type;
599 * Keywords recognized.
601 static const struct token keywords[] = {
604 {"timeout", T_TIMEOUT},
605 {"default", T_DEFAULT},
606 {"prompt", T_PROMPT},
608 {"kernel", T_KERNEL},
610 {"localboot", T_LOCALBOOT},
611 {"append", T_APPEND},
612 {"initrd", T_INITRD},
613 {"include", T_INCLUDE},
614 {"devicetree", T_FDT},
616 {"devicetreedir", T_FDTDIR},
617 {"fdtdir", T_FDTDIR},
618 {"ontimeout", T_ONTIMEOUT,},
619 {"ipappend", T_IPAPPEND,},
620 {"background", T_BACKGROUND,},
625 * Since pxe(linux) files don't have a token to identify the start of a
626 * literal, we have to keep track of when we're in a state where a literal is
627 * expected vs when we're in a state a keyword is expected.
636 * get_string retrieves a string from *p and stores it as a token in
639 * get_string used for scanning both string literals and keywords.
641 * Characters from *p are copied into t-val until a character equal to
642 * delim is found, or a NUL byte is reached. If delim has the special value of
643 * ' ', any whitespace character will be used as a delimiter.
645 * If lower is unequal to 0, uppercase characters will be converted to
646 * lowercase in the result. This is useful to make keywords case
649 * The location of *p is updated to point to the first character after the end
650 * of the token - the ending delimiter.
652 * On success, the new value of t->val is returned. Memory for t->val is
653 * allocated using malloc and must be free()'d to reclaim it. If insufficient
654 * memory is available, NULL is returned.
656 static char *get_string(char **p, struct token *t, char delim, int lower)
662 * b and e both start at the beginning of the input stream.
664 * e is incremented until we find the ending delimiter, or a NUL byte
665 * is reached. Then, we take e - b to find the length of the token.
671 if ((delim == ' ' && isspace(*e)) || delim == *e)
679 * Allocate memory to hold the string, and copy it in, converting
680 * characters to lowercase if lower is != 0.
682 t->val = malloc(len + 1);
686 for (i = 0; i < len; i++, b++) {
688 t->val[i] = tolower(*b);
696 * Update *p so the caller knows where to continue scanning.
706 * Populate a keyword token with a type and value.
708 static void get_keyword(struct token *t)
712 for (i = 0; keywords[i].val; i++) {
713 if (!strcmp(t->val, keywords[i].val)) {
714 t->type = keywords[i].type;
721 * Get the next token. We have to keep track of which state we're in to know
722 * if we're looking to get a string literal or a keyword.
724 * *p is updated to point at the first character after the current token.
726 static void get_token(char **p, struct token *t, enum lex_state state)
732 /* eat non EOL whitespace */
737 * eat comments. note that string literals can't begin with #, but
738 * can contain a # after their first character.
741 while (*c && *c != '\n')
748 } else if (*c == '\0') {
751 } else if (state == L_SLITERAL) {
752 get_string(&c, t, '\n', 0);
753 } else if (state == L_KEYWORD) {
755 * when we expect a keyword, we first get the next string
756 * token delimited by whitespace, and then check if it
757 * matches a keyword in our keyword list. if it does, it's
758 * converted to a keyword token of the appropriate type, and
759 * if not, it remains a string token.
761 get_string(&c, t, ' ', 1);
769 * Increment *c until we get to the end of the current line, or EOF.
771 static void eol_or_eof(char **c)
773 while (**c && **c != '\n')
778 * All of these parse_* functions share some common behavior.
780 * They finish with *c pointing after the token they parse, and return 1 on
781 * success, or < 0 on error.
785 * Parse a string literal and store a pointer it at *dst. String literals
786 * terminate at the end of the line.
788 static int parse_sliteral(char **c, char **dst)
793 get_token(c, &t, L_SLITERAL);
795 if (t.type != T_STRING) {
796 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
806 * Parse a base 10 (unsigned) integer and store it at *dst.
808 static int parse_integer(char **c, int *dst)
813 get_token(c, &t, L_SLITERAL);
815 if (t.type != T_STRING) {
816 printf("Expected string: %.*s\n", (int)(*c - s), s);
820 *dst = simple_strtol(t.val, NULL, 10);
827 static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
828 struct pxe_menu *cfg, int nest_level);
831 * Parse an include statement, and retrieve and parse the file it mentions.
833 * base should point to a location where it's safe to store the file, and
834 * nest_level should indicate how many nested includes have occurred. For this
835 * include, nest_level has already been incremented and doesn't need to be
838 static int handle_include(struct cmd_tbl *cmdtp, char **c, unsigned long base,
839 struct pxe_menu *cfg, int nest_level)
847 err = parse_sliteral(c, &include_path);
850 printf("Expected include path: %.*s\n", (int)(*c - s), s);
854 err = get_pxe_file(cmdtp, include_path, base);
857 printf("Couldn't retrieve %s\n", include_path);
861 buf = map_sysmem(base, 0);
862 ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
869 * Parse lines that begin with 'menu'.
871 * base and nest are provided to handle the 'menu include' case.
873 * base should point to a location where it's safe to store the included file.
875 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
876 * a file it includes, 3 when parsing a file included by that file, and so on.
878 static int parse_menu(struct cmd_tbl *cmdtp, char **c, struct pxe_menu *cfg,
879 unsigned long base, int nest_level)
885 get_token(c, &t, L_KEYWORD);
889 err = parse_sliteral(c, &cfg->title);
894 err = handle_include(cmdtp, c, base, cfg, nest_level + 1);
898 err = parse_sliteral(c, &cfg->bmp);
902 printf("Ignoring malformed menu command: %.*s\n",
915 * Handles parsing a 'menu line' when we're parsing a label.
917 static int parse_label_menu(char **c, struct pxe_menu *cfg,
918 struct pxe_label *label)
925 get_token(c, &t, L_KEYWORD);
929 if (!cfg->default_label)
930 cfg->default_label = strdup(label->name);
932 if (!cfg->default_label)
937 parse_sliteral(c, &label->menu);
940 printf("Ignoring malformed menu command: %.*s\n",
950 * Handles parsing a 'kernel' label.
951 * expecting "filename" or "<fit_filename>#cfg"
953 static int parse_label_kernel(char **c, struct pxe_label *label)
958 err = parse_sliteral(c, &label->kernel);
962 s = strstr(label->kernel, "#");
966 label->config = malloc(strlen(s) + 1);
970 strcpy(label->config, s);
977 * Parses a label and adds it to the list of labels for a menu.
979 * A label ends when we either get to the end of a file, or
980 * get some input we otherwise don't have a handler defined
984 static int parse_label(char **c, struct pxe_menu *cfg)
989 struct pxe_label *label;
992 label = label_create();
996 err = parse_sliteral(c, &label->name);
998 printf("Expected label name: %.*s\n", (int)(*c - s), s);
999 label_destroy(label);
1003 list_add_tail(&label->list, &cfg->labels);
1007 get_token(c, &t, L_KEYWORD);
1012 err = parse_label_menu(c, cfg, label);
1017 err = parse_label_kernel(c, label);
1021 err = parse_sliteral(c, &label->append);
1024 s = strstr(label->append, "initrd=");
1028 len = (int)(strchr(s, ' ') - s);
1029 label->initrd = malloc(len + 1);
1030 strncpy(label->initrd, s, len);
1031 label->initrd[len] = '\0';
1037 err = parse_sliteral(c, &label->initrd);
1042 err = parse_sliteral(c, &label->fdt);
1047 err = parse_sliteral(c, &label->fdtdir);
1051 label->localboot = 1;
1052 err = parse_integer(c, &label->localboot_val);
1056 err = parse_integer(c, &label->ipappend);
1064 * put the token back! we don't want it - it's the end
1065 * of a label and whatever token this is, it's
1066 * something for the menu level context to handle.
1078 * This 16 comes from the limit pxelinux imposes on nested includes.
1080 * There is no reason at all we couldn't do more, but some limit helps prevent
1081 * infinite (until crash occurs) recursion if a file tries to include itself.
1083 #define MAX_NEST_LEVEL 16
1086 * Entry point for parsing a menu file. nest_level indicates how many times
1087 * we've nested in includes. It will be 1 for the top level menu file.
1089 * Returns 1 on success, < 0 on error.
1091 static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
1092 struct pxe_menu *cfg, int nest_level)
1095 char *s, *b, *label_name;
1100 if (nest_level > MAX_NEST_LEVEL) {
1101 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1108 get_token(&p, &t, L_KEYWORD);
1114 err = parse_menu(cmdtp, &p, cfg,
1115 base + ALIGN(strlen(b) + 1, 4),
1120 err = parse_integer(&p, &cfg->timeout);
1124 err = parse_label(&p, cfg);
1129 err = parse_sliteral(&p, &label_name);
1132 if (cfg->default_label)
1133 free(cfg->default_label);
1135 cfg->default_label = label_name;
1141 err = handle_include(cmdtp, &p,
1142 base + ALIGN(strlen(b), 4), cfg,
1157 printf("Ignoring unknown command: %.*s\n",
1168 * Free the memory used by a pxe_menu and its labels.
1170 void destroy_pxe_menu(struct pxe_menu *cfg)
1172 struct list_head *pos, *n;
1173 struct pxe_label *label;
1178 if (cfg->default_label)
1179 free(cfg->default_label);
1181 list_for_each_safe(pos, n, &cfg->labels) {
1182 label = list_entry(pos, struct pxe_label, list);
1184 label_destroy(label);
1191 * Entry point for parsing a pxe file. This is only used for the top level
1194 * Returns NULL if there is an error, otherwise, returns a pointer to a
1195 * pxe_menu struct populated with the results of parsing the pxe file (and any
1196 * files it includes). The resulting pxe_menu struct can be free()'d by using
1197 * the destroy_pxe_menu() function.
1199 struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, unsigned long menucfg)
1201 struct pxe_menu *cfg;
1205 cfg = malloc(sizeof(struct pxe_menu));
1210 memset(cfg, 0, sizeof(struct pxe_menu));
1212 INIT_LIST_HEAD(&cfg->labels);
1214 buf = map_sysmem(menucfg, 0);
1215 r = parse_pxefile_top(cmdtp, buf, menucfg, cfg, 1);
1219 destroy_pxe_menu(cfg);
1227 * Converts a pxe_menu struct into a menu struct for use with U-Boot's generic
1230 static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1232 struct pxe_label *label;
1233 struct list_head *pos;
1237 char *default_num = NULL;
1240 * Create a menu and add items for all the labels.
1242 m = menu_create(cfg->title, DIV_ROUND_UP(cfg->timeout, 10),
1243 cfg->prompt, NULL, label_print, NULL, NULL);
1248 list_for_each(pos, &cfg->labels) {
1249 label = list_entry(pos, struct pxe_label, list);
1251 sprintf(label->num, "%d", i++);
1252 if (menu_item_add(m, label->num, label) != 1) {
1256 if (cfg->default_label &&
1257 (strcmp(label->name, cfg->default_label) == 0))
1258 default_num = label->num;
1262 * After we've created items for each label in the menu, set the
1263 * menu's default label if one was specified.
1266 err = menu_default_set(m, default_num);
1268 if (err != -ENOENT) {
1273 printf("Missing default: %s\n", cfg->default_label);
1281 * Try to boot any labels we have yet to attempt to boot.
1283 static void boot_unattempted_labels(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
1285 struct list_head *pos;
1286 struct pxe_label *label;
1288 list_for_each(pos, &cfg->labels) {
1289 label = list_entry(pos, struct pxe_label, list);
1291 if (!label->attempted)
1292 label_boot(cmdtp, label);
1297 * Boot the system as prescribed by a pxe_menu.
1299 * Use the menu system to either get the user's choice or the default, based
1300 * on config or user input. If there is no default or user's choice,
1301 * attempted to boot labels in the order they were given in pxe files.
1302 * If the default or user's choice fails to boot, attempt to boot other
1303 * labels in the order they were given in pxe files.
1305 * If this function returns, there weren't any labels that successfully
1306 * booted, or the user interrupted the menu selection via ctrl+c.
1308 void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
1314 #ifdef CONFIG_CMD_BMP
1315 /* display BMP if available */
1317 if (get_relfile(cmdtp, cfg->bmp, image_load_addr)) {
1318 if (CONFIG_IS_ENABLED(CMD_CLS))
1319 run_command("cls", 0);
1320 bmp_display(image_load_addr,
1321 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
1323 printf("Skipping background bmp %s for failure\n",
1329 m = pxe_menu_to_menu(cfg);
1333 err = menu_get_choice(m, &choice);
1338 * err == 1 means we got a choice back from menu_get_choice.
1340 * err == -ENOENT if the menu was setup to select the default but no
1341 * default was set. in that case, we should continue trying to boot
1342 * labels that haven't been attempted yet.
1344 * otherwise, the user interrupted or there was some other error and
1349 err = label_boot(cmdtp, choice);
1352 } else if (err != -ENOENT) {
1356 boot_unattempted_labels(cmdtp, cfg);