1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2010-2011 Calxeda, Inc.
4 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
14 #include <linux/string.h>
15 #include <linux/ctype.h>
17 #include <linux/list.h>
25 #include "pxe_utils.h"
27 #define MAX_TFTP_PATH_LEN 512
32 * Convert an ethaddr from the environment to the format used by pxelinux
33 * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
34 * the beginning of the ethernet address to indicate a hardware type of
35 * Ethernet. Also converts uppercase hex characters into lowercase, to match
36 * pxelinux's behavior.
38 * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
39 * environment, or some other value < 0 on error.
41 int format_mac_pxe(char *outbuf, size_t outbuf_len)
45 if (outbuf_len < 21) {
46 printf("outbuf is too small (%zd < 21)\n", outbuf_len);
51 if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr))
54 sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x",
55 ethaddr[0], ethaddr[1], ethaddr[2],
56 ethaddr[3], ethaddr[4], ethaddr[5]);
62 * Returns the directory the file specified in the bootfile env variable is
63 * in. If bootfile isn't defined in the environment, return NULL, which should
64 * be interpreted as "don't prepend anything to paths".
66 static int get_bootfile_path(const char *file_path, char *bootfile_path,
67 size_t bootfile_path_size)
69 char *bootfile, *last_slash;
72 /* Only syslinux allows absolute paths */
73 if (file_path[0] == '/' && !is_pxe)
76 bootfile = from_env("bootfile");
81 last_slash = strrchr(bootfile, '/');
86 path_len = (last_slash - bootfile) + 1;
88 if (bootfile_path_size < path_len) {
89 printf("bootfile_path too small. (%zd < %zd)\n",
90 bootfile_path_size, path_len);
95 strncpy(bootfile_path, bootfile, path_len);
98 bootfile_path[path_len] = '\0';
103 int (*do_getfile)(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr);
106 * As in pxelinux, paths to files referenced from files we retrieve are
107 * relative to the location of bootfile. get_relfile takes such a path and
108 * joins it with the bootfile path to get the full path to the target file. If
109 * the bootfile path is NULL, we use file_path as is.
111 * Returns 1 for success, or < 0 on error.
113 static int get_relfile(cmd_tbl_t *cmdtp, const char *file_path,
114 unsigned long file_addr)
117 char relfile[MAX_TFTP_PATH_LEN + 1];
121 err = get_bootfile_path(file_path, relfile, sizeof(relfile));
126 path_len = strlen(file_path);
127 path_len += strlen(relfile);
129 if (path_len > MAX_TFTP_PATH_LEN) {
130 printf("Base path too long (%s%s)\n", relfile, file_path);
132 return -ENAMETOOLONG;
135 strcat(relfile, file_path);
137 printf("Retrieving file: %s\n", relfile);
139 sprintf(addr_buf, "%lx", file_addr);
141 return do_getfile(cmdtp, relfile, addr_buf);
145 * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
146 * 'bootfile' was specified in the environment, the path to bootfile will be
147 * prepended to 'file_path' and the resulting path will be used.
149 * Returns 1 on success, or < 0 for error.
151 int get_pxe_file(cmd_tbl_t *cmdtp, const char *file_path,
152 unsigned long file_addr)
154 unsigned long config_file_size;
159 err = get_relfile(cmdtp, file_path, file_addr);
165 * the file comes without a NUL byte at the end, so find out its size
166 * and add the NUL byte.
168 tftp_filesize = from_env("filesize");
173 if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
176 buf = map_sysmem(file_addr + config_file_size, 1);
183 #define PXELINUX_DIR "pxelinux.cfg/"
186 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
187 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
188 * from the bootfile path, as described above.
190 * Returns 1 on success or < 0 on error.
192 int get_pxelinux_path(cmd_tbl_t *cmdtp, const char *file,
193 unsigned long pxefile_addr_r)
195 size_t base_len = strlen(PXELINUX_DIR);
196 char path[MAX_TFTP_PATH_LEN + 1];
198 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
199 printf("path (%s%s) too long, skipping\n",
201 return -ENAMETOOLONG;
204 sprintf(path, PXELINUX_DIR "%s", file);
206 return get_pxe_file(cmdtp, path, pxefile_addr_r);
210 * Wrapper to make it easier to store the file at file_path in the location
211 * specified by envaddr_name. file_path will be joined to the bootfile path,
212 * if any is specified.
214 * Returns 1 on success or < 0 on error.
216 static int get_relfile_envaddr(cmd_tbl_t *cmdtp, const char *file_path,
217 const char *envaddr_name)
219 unsigned long file_addr;
222 envaddr = from_env(envaddr_name);
227 if (strict_strtoul(envaddr, 16, &file_addr) < 0)
230 return get_relfile(cmdtp, file_path, file_addr);
234 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
235 * result must be free()'d to reclaim the memory.
237 * Returns NULL if malloc fails.
239 static struct pxe_label *label_create(void)
241 struct pxe_label *label;
243 label = malloc(sizeof(struct pxe_label));
248 memset(label, 0, sizeof(struct pxe_label));
254 * Free the memory used by a pxe_label, including that used by its name,
255 * kernel, append and initrd members, if they're non NULL.
257 * So - be sure to only use dynamically allocated memory for the members of
258 * the pxe_label struct, unless you want to clean it up first. These are
259 * currently only created by the pxe file parsing code.
261 static void label_destroy(struct pxe_label *label)
288 * Print a label and its string members if they're defined.
290 * This is passed as a callback to the menu code for displaying each
293 static void label_print(void *data)
295 struct pxe_label *label = data;
296 const char *c = label->menu ? label->menu : label->name;
298 printf("%s:\t%s\n", label->num, c);
302 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
303 * environment variable is defined. Its contents will be executed as U-Boot
304 * command. If the label specified an 'append' line, its contents will be
305 * used to overwrite the contents of the 'bootargs' environment variable prior
306 * to running 'localcmd'.
308 * Returns 1 on success or < 0 on error.
310 static int label_localboot(struct pxe_label *label)
314 localcmd = from_env("localcmd");
320 char bootargs[CONFIG_SYS_CBSIZE];
322 cli_simple_process_macros(label->append, bootargs);
323 env_set("bootargs", bootargs);
326 debug("running: %s\n", localcmd);
328 return run_command_list(localcmd, strlen(localcmd), 0);
332 * Boot according to the contents of a pxe_label.
334 * If we can't boot for any reason, we return. A successful boot never
337 * The kernel will be stored in the location given by the 'kernel_addr_r'
338 * environment variable.
340 * If the label specifies an initrd file, it will be stored in the location
341 * given by the 'ramdisk_addr_r' environment variable.
343 * If the label specifies an 'append' line, its contents will overwrite that
344 * of the 'bootargs' environment variable.
346 static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
348 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
350 char mac_str[29] = "";
351 char ip_str[68] = "";
352 char *fit_addr = NULL;
360 label->attempted = 1;
362 if (label->localboot) {
363 if (label->localboot_val >= 0)
364 label_localboot(label);
368 if (!label->kernel) {
369 printf("No kernel given, skipping %s\n",
375 if (get_relfile_envaddr(cmdtp, label->initrd, "ramdisk_addr_r") < 0) {
376 printf("Skipping %s for failure retrieving initrd\n",
381 bootm_argv[2] = initrd_str;
382 strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18);
383 strcat(bootm_argv[2], ":");
384 strncat(bootm_argv[2], env_get("filesize"), 9);
388 if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
389 printf("Skipping %s for failure retrieving kernel\n",
394 if (label->ipappend & 0x1) {
395 sprintf(ip_str, " ip=%s:%s:%s:%s",
396 env_get("ipaddr"), env_get("serverip"),
397 env_get("gatewayip"), env_get("netmask"));
400 #ifdef CONFIG_CMD_NET
401 if (label->ipappend & 0x2) {
404 strcpy(mac_str, " BOOTIF=");
405 err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
411 if ((label->ipappend & 0x3) || label->append) {
412 char bootargs[CONFIG_SYS_CBSIZE] = "";
413 char finalbootargs[CONFIG_SYS_CBSIZE];
415 if (strlen(label->append ?: "") +
416 strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) {
417 printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n",
418 strlen(label->append ?: ""),
419 strlen(ip_str), strlen(mac_str),
425 strncpy(bootargs, label->append, sizeof(bootargs));
427 strcat(bootargs, ip_str);
428 strcat(bootargs, mac_str);
430 cli_simple_process_macros(bootargs, finalbootargs);
431 env_set("bootargs", finalbootargs);
432 printf("append: %s\n", finalbootargs);
435 bootm_argv[1] = env_get("kernel_addr_r");
436 /* for FIT, append the configuration identifier */
438 int len = strlen(bootm_argv[1]) + strlen(label->config) + 1;
440 fit_addr = malloc(len);
442 printf("malloc fail (FIT address)\n");
445 snprintf(fit_addr, len, "%s%s", bootm_argv[1], label->config);
446 bootm_argv[1] = fit_addr;
450 * fdt usage is optional:
451 * It handles the following scenarios. All scenarios are exclusive
453 * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
454 * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
455 * and adjust argc appropriately.
457 * Scenario 2: If there is an fdt_addr specified, pass it along to
458 * bootm, and adjust argc appropriately.
460 * Scenario 3: fdt blob is not available.
462 bootm_argv[3] = env_get("fdt_addr_r");
464 /* if fdt label is defined then get fdt from server */
466 char *fdtfile = NULL;
467 char *fdtfilefree = NULL;
470 fdtfile = label->fdt;
471 } else if (label->fdtdir) {
472 char *f1, *f2, *f3, *f4, *slash;
474 f1 = env_get("fdtfile");
481 * For complex cases where this code doesn't
482 * generate the correct filename, the board
483 * code should set $fdtfile during early boot,
484 * or the boot scripts should set $fdtfile
485 * before invoking "pxe" or "sysboot".
489 f3 = env_get("board");
493 len = strlen(label->fdtdir);
496 else if (label->fdtdir[len - 1] != '/')
501 len = strlen(label->fdtdir) + strlen(slash) +
502 strlen(f1) + strlen(f2) + strlen(f3) +
504 fdtfilefree = malloc(len);
506 printf("malloc fail (FDT filename)\n");
510 snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
511 label->fdtdir, slash, f1, f2, f3, f4);
512 fdtfile = fdtfilefree;
516 int err = get_relfile_envaddr(cmdtp, fdtfile,
521 printf("Skipping %s for failure retrieving fdt\n",
526 bootm_argv[3] = NULL;
531 bootm_argv[3] = env_get("fdt_addr");
539 kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
540 buf = map_sysmem(kernel_addr, 0);
541 /* Try bootm for legacy and FIT format image */
542 if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
543 do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
544 #ifdef CONFIG_CMD_BOOTI
545 /* Try booting an AArch64 Linux kernel image */
547 do_booti(cmdtp, 0, bootm_argc, bootm_argv);
548 #elif defined(CONFIG_CMD_BOOTZ)
549 /* Try booting a Image */
551 do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
562 * Tokens for the pxe file parser.
589 * A token - given by a value and a type.
593 enum token_type type;
597 * Keywords recognized.
599 static const struct token keywords[] = {
602 {"timeout", T_TIMEOUT},
603 {"default", T_DEFAULT},
604 {"prompt", T_PROMPT},
606 {"kernel", T_KERNEL},
608 {"localboot", T_LOCALBOOT},
609 {"append", T_APPEND},
610 {"initrd", T_INITRD},
611 {"include", T_INCLUDE},
612 {"devicetree", T_FDT},
614 {"devicetreedir", T_FDTDIR},
615 {"fdtdir", T_FDTDIR},
616 {"ontimeout", T_ONTIMEOUT,},
617 {"ipappend", T_IPAPPEND,},
618 {"background", T_BACKGROUND,},
623 * Since pxe(linux) files don't have a token to identify the start of a
624 * literal, we have to keep track of when we're in a state where a literal is
625 * expected vs when we're in a state a keyword is expected.
634 * get_string retrieves a string from *p and stores it as a token in
637 * get_string used for scanning both string literals and keywords.
639 * Characters from *p are copied into t-val until a character equal to
640 * delim is found, or a NUL byte is reached. If delim has the special value of
641 * ' ', any whitespace character will be used as a delimiter.
643 * If lower is unequal to 0, uppercase characters will be converted to
644 * lowercase in the result. This is useful to make keywords case
647 * The location of *p is updated to point to the first character after the end
648 * of the token - the ending delimiter.
650 * On success, the new value of t->val is returned. Memory for t->val is
651 * allocated using malloc and must be free()'d to reclaim it. If insufficient
652 * memory is available, NULL is returned.
654 static char *get_string(char **p, struct token *t, char delim, int lower)
660 * b and e both start at the beginning of the input stream.
662 * e is incremented until we find the ending delimiter, or a NUL byte
663 * is reached. Then, we take e - b to find the length of the token.
669 if ((delim == ' ' && isspace(*e)) || delim == *e)
677 * Allocate memory to hold the string, and copy it in, converting
678 * characters to lowercase if lower is != 0.
680 t->val = malloc(len + 1);
684 for (i = 0; i < len; i++, b++) {
686 t->val[i] = tolower(*b);
694 * Update *p so the caller knows where to continue scanning.
704 * Populate a keyword token with a type and value.
706 static void get_keyword(struct token *t)
710 for (i = 0; keywords[i].val; i++) {
711 if (!strcmp(t->val, keywords[i].val)) {
712 t->type = keywords[i].type;
719 * Get the next token. We have to keep track of which state we're in to know
720 * if we're looking to get a string literal or a keyword.
722 * *p is updated to point at the first character after the current token.
724 static void get_token(char **p, struct token *t, enum lex_state state)
730 /* eat non EOL whitespace */
735 * eat comments. note that string literals can't begin with #, but
736 * can contain a # after their first character.
739 while (*c && *c != '\n')
746 } else if (*c == '\0') {
749 } else if (state == L_SLITERAL) {
750 get_string(&c, t, '\n', 0);
751 } else if (state == L_KEYWORD) {
753 * when we expect a keyword, we first get the next string
754 * token delimited by whitespace, and then check if it
755 * matches a keyword in our keyword list. if it does, it's
756 * converted to a keyword token of the appropriate type, and
757 * if not, it remains a string token.
759 get_string(&c, t, ' ', 1);
767 * Increment *c until we get to the end of the current line, or EOF.
769 static void eol_or_eof(char **c)
771 while (**c && **c != '\n')
776 * All of these parse_* functions share some common behavior.
778 * They finish with *c pointing after the token they parse, and return 1 on
779 * success, or < 0 on error.
783 * Parse a string literal and store a pointer it at *dst. String literals
784 * terminate at the end of the line.
786 static int parse_sliteral(char **c, char **dst)
791 get_token(c, &t, L_SLITERAL);
793 if (t.type != T_STRING) {
794 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
804 * Parse a base 10 (unsigned) integer and store it at *dst.
806 static int parse_integer(char **c, int *dst)
811 get_token(c, &t, L_SLITERAL);
813 if (t.type != T_STRING) {
814 printf("Expected string: %.*s\n", (int)(*c - s), s);
818 *dst = simple_strtol(t.val, NULL, 10);
825 static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
826 struct pxe_menu *cfg, int nest_level);
829 * Parse an include statement, and retrieve and parse the file it mentions.
831 * base should point to a location where it's safe to store the file, and
832 * nest_level should indicate how many nested includes have occurred. For this
833 * include, nest_level has already been incremented and doesn't need to be
836 static int handle_include(cmd_tbl_t *cmdtp, char **c, unsigned long base,
837 struct pxe_menu *cfg, int nest_level)
845 err = parse_sliteral(c, &include_path);
848 printf("Expected include path: %.*s\n", (int)(*c - s), s);
852 err = get_pxe_file(cmdtp, include_path, base);
855 printf("Couldn't retrieve %s\n", include_path);
859 buf = map_sysmem(base, 0);
860 ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
867 * Parse lines that begin with 'menu'.
869 * base and nest are provided to handle the 'menu include' case.
871 * base should point to a location where it's safe to store the included file.
873 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
874 * a file it includes, 3 when parsing a file included by that file, and so on.
876 static int parse_menu(cmd_tbl_t *cmdtp, char **c, struct pxe_menu *cfg,
877 unsigned long base, int nest_level)
883 get_token(c, &t, L_KEYWORD);
887 err = parse_sliteral(c, &cfg->title);
892 err = handle_include(cmdtp, c, base, cfg, nest_level + 1);
896 err = parse_sliteral(c, &cfg->bmp);
900 printf("Ignoring malformed menu command: %.*s\n",
913 * Handles parsing a 'menu line' when we're parsing a label.
915 static int parse_label_menu(char **c, struct pxe_menu *cfg,
916 struct pxe_label *label)
923 get_token(c, &t, L_KEYWORD);
927 if (!cfg->default_label)
928 cfg->default_label = strdup(label->name);
930 if (!cfg->default_label)
935 parse_sliteral(c, &label->menu);
938 printf("Ignoring malformed menu command: %.*s\n",
948 * Handles parsing a 'kernel' label.
949 * expecting "filename" or "<fit_filename>#cfg"
951 static int parse_label_kernel(char **c, struct pxe_label *label)
956 err = parse_sliteral(c, &label->kernel);
960 s = strstr(label->kernel, "#");
964 label->config = malloc(strlen(s) + 1);
968 strcpy(label->config, s);
975 * Parses a label and adds it to the list of labels for a menu.
977 * A label ends when we either get to the end of a file, or
978 * get some input we otherwise don't have a handler defined
982 static int parse_label(char **c, struct pxe_menu *cfg)
987 struct pxe_label *label;
990 label = label_create();
994 err = parse_sliteral(c, &label->name);
996 printf("Expected label name: %.*s\n", (int)(*c - s), s);
997 label_destroy(label);
1001 list_add_tail(&label->list, &cfg->labels);
1005 get_token(c, &t, L_KEYWORD);
1010 err = parse_label_menu(c, cfg, label);
1015 err = parse_label_kernel(c, label);
1019 err = parse_sliteral(c, &label->append);
1022 s = strstr(label->append, "initrd=");
1026 len = (int)(strchr(s, ' ') - s);
1027 label->initrd = malloc(len + 1);
1028 strncpy(label->initrd, s, len);
1029 label->initrd[len] = '\0';
1035 err = parse_sliteral(c, &label->initrd);
1040 err = parse_sliteral(c, &label->fdt);
1045 err = parse_sliteral(c, &label->fdtdir);
1049 label->localboot = 1;
1050 err = parse_integer(c, &label->localboot_val);
1054 err = parse_integer(c, &label->ipappend);
1062 * put the token back! we don't want it - it's the end
1063 * of a label and whatever token this is, it's
1064 * something for the menu level context to handle.
1076 * This 16 comes from the limit pxelinux imposes on nested includes.
1078 * There is no reason at all we couldn't do more, but some limit helps prevent
1079 * infinite (until crash occurs) recursion if a file tries to include itself.
1081 #define MAX_NEST_LEVEL 16
1084 * Entry point for parsing a menu file. nest_level indicates how many times
1085 * we've nested in includes. It will be 1 for the top level menu file.
1087 * Returns 1 on success, < 0 on error.
1089 static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
1090 struct pxe_menu *cfg, int nest_level)
1093 char *s, *b, *label_name;
1098 if (nest_level > MAX_NEST_LEVEL) {
1099 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1106 get_token(&p, &t, L_KEYWORD);
1112 err = parse_menu(cmdtp, &p, cfg,
1113 base + ALIGN(strlen(b) + 1, 4),
1118 err = parse_integer(&p, &cfg->timeout);
1122 err = parse_label(&p, cfg);
1127 err = parse_sliteral(&p, &label_name);
1130 if (cfg->default_label)
1131 free(cfg->default_label);
1133 cfg->default_label = label_name;
1139 err = handle_include(cmdtp, &p,
1140 base + ALIGN(strlen(b), 4), cfg,
1155 printf("Ignoring unknown command: %.*s\n",
1166 * Free the memory used by a pxe_menu and its labels.
1168 void destroy_pxe_menu(struct pxe_menu *cfg)
1170 struct list_head *pos, *n;
1171 struct pxe_label *label;
1176 if (cfg->default_label)
1177 free(cfg->default_label);
1179 list_for_each_safe(pos, n, &cfg->labels) {
1180 label = list_entry(pos, struct pxe_label, list);
1182 label_destroy(label);
1189 * Entry point for parsing a pxe file. This is only used for the top level
1192 * Returns NULL if there is an error, otherwise, returns a pointer to a
1193 * pxe_menu struct populated with the results of parsing the pxe file (and any
1194 * files it includes). The resulting pxe_menu struct can be free()'d by using
1195 * the destroy_pxe_menu() function.
1197 struct pxe_menu *parse_pxefile(cmd_tbl_t *cmdtp, unsigned long menucfg)
1199 struct pxe_menu *cfg;
1203 cfg = malloc(sizeof(struct pxe_menu));
1208 memset(cfg, 0, sizeof(struct pxe_menu));
1210 INIT_LIST_HEAD(&cfg->labels);
1212 buf = map_sysmem(menucfg, 0);
1213 r = parse_pxefile_top(cmdtp, buf, menucfg, cfg, 1);
1217 destroy_pxe_menu(cfg);
1225 * Converts a pxe_menu struct into a menu struct for use with U-Boot's generic
1228 static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1230 struct pxe_label *label;
1231 struct list_head *pos;
1235 char *default_num = NULL;
1238 * Create a menu and add items for all the labels.
1240 m = menu_create(cfg->title, DIV_ROUND_UP(cfg->timeout, 10),
1241 cfg->prompt, NULL, label_print, NULL, NULL);
1246 list_for_each(pos, &cfg->labels) {
1247 label = list_entry(pos, struct pxe_label, list);
1249 sprintf(label->num, "%d", i++);
1250 if (menu_item_add(m, label->num, label) != 1) {
1254 if (cfg->default_label &&
1255 (strcmp(label->name, cfg->default_label) == 0))
1256 default_num = label->num;
1260 * After we've created items for each label in the menu, set the
1261 * menu's default label if one was specified.
1264 err = menu_default_set(m, default_num);
1266 if (err != -ENOENT) {
1271 printf("Missing default: %s\n", cfg->default_label);
1279 * Try to boot any labels we have yet to attempt to boot.
1281 static void boot_unattempted_labels(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
1283 struct list_head *pos;
1284 struct pxe_label *label;
1286 list_for_each(pos, &cfg->labels) {
1287 label = list_entry(pos, struct pxe_label, list);
1289 if (!label->attempted)
1290 label_boot(cmdtp, label);
1295 * Boot the system as prescribed by a pxe_menu.
1297 * Use the menu system to either get the user's choice or the default, based
1298 * on config or user input. If there is no default or user's choice,
1299 * attempted to boot labels in the order they were given in pxe files.
1300 * If the default or user's choice fails to boot, attempt to boot other
1301 * labels in the order they were given in pxe files.
1303 * If this function returns, there weren't any labels that successfully
1304 * booted, or the user interrupted the menu selection via ctrl+c.
1306 void handle_pxe_menu(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
1312 #ifdef CONFIG_CMD_BMP
1313 /* display BMP if available */
1315 if (get_relfile(cmdtp, cfg->bmp, image_load_addr)) {
1316 if (CONFIG_IS_ENABLED(CMD_CLS))
1317 run_command("cls", 0);
1318 bmp_display(image_load_addr,
1319 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
1321 printf("Skipping background bmp %s for failure\n",
1327 m = pxe_menu_to_menu(cfg);
1331 err = menu_get_choice(m, &choice);
1336 * err == 1 means we got a choice back from menu_get_choice.
1338 * err == -ENOENT if the menu was setup to select the default but no
1339 * default was set. in that case, we should continue trying to boot
1340 * labels that haven't been attempted yet.
1342 * otherwise, the user interrupted or there was some other error and
1347 err = label_boot(cmdtp, choice);
1350 } else if (err != -ENOENT) {
1354 boot_unattempted_labels(cmdtp, cfg);