1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2010-2011 Calxeda, Inc.
4 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
12 #include <linux/string.h>
13 #include <linux/ctype.h>
15 #include <linux/list.h>
23 #include "pxe_utils.h"
25 #define MAX_TFTP_PATH_LEN 127
30 * Convert an ethaddr from the environment to the format used by pxelinux
31 * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
32 * the beginning of the ethernet address to indicate a hardware type of
33 * Ethernet. Also converts uppercase hex characters into lowercase, to match
34 * pxelinux's behavior.
36 * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
37 * environment, or some other value < 0 on error.
39 int format_mac_pxe(char *outbuf, size_t outbuf_len)
43 if (outbuf_len < 21) {
44 printf("outbuf is too small (%zd < 21)\n", outbuf_len);
49 if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr))
52 sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x",
53 ethaddr[0], ethaddr[1], ethaddr[2],
54 ethaddr[3], ethaddr[4], ethaddr[5]);
60 * Returns the directory the file specified in the bootfile env variable is
61 * in. If bootfile isn't defined in the environment, return NULL, which should
62 * be interpreted as "don't prepend anything to paths".
64 static int get_bootfile_path(const char *file_path, char *bootfile_path,
65 size_t bootfile_path_size)
67 char *bootfile, *last_slash;
70 /* Only syslinux allows absolute paths */
71 if (file_path[0] == '/' && !is_pxe)
74 bootfile = from_env("bootfile");
79 last_slash = strrchr(bootfile, '/');
81 if (last_slash == NULL )
84 path_len = (last_slash - bootfile) + 1;
86 if (bootfile_path_size < path_len) {
87 printf("bootfile_path too small. (%zd < %zd)\n",
88 bootfile_path_size, path_len);
93 strncpy(bootfile_path, bootfile, path_len);
96 bootfile_path[path_len] = '\0';
101 int (*do_getfile)(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr);
104 * As in pxelinux, paths to files referenced from files we retrieve are
105 * relative to the location of bootfile. get_relfile takes such a path and
106 * joins it with the bootfile path to get the full path to the target file. If
107 * the bootfile path is NULL, we use file_path as is.
109 * Returns 1 for success, or < 0 on error.
111 static int get_relfile(cmd_tbl_t *cmdtp, const char *file_path,
112 unsigned long file_addr)
115 char relfile[MAX_TFTP_PATH_LEN+1];
119 err = get_bootfile_path(file_path, relfile, sizeof(relfile));
124 path_len = strlen(file_path);
125 path_len += strlen(relfile);
127 if (path_len > MAX_TFTP_PATH_LEN) {
128 printf("Base path too long (%s%s)\n",
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/"
187 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
188 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
189 * from the bootfile path, as described above.
191 * Returns 1 on success or < 0 on error.
193 int get_pxelinux_path(cmd_tbl_t *cmdtp, const char *file,
194 unsigned long pxefile_addr_r)
196 size_t base_len = strlen(PXELINUX_DIR);
197 char path[MAX_TFTP_PATH_LEN+1];
199 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
200 printf("path (%s%s) too long, skipping\n",
202 return -ENAMETOOLONG;
205 sprintf(path, PXELINUX_DIR "%s", file);
207 return get_pxe_file(cmdtp, path, pxefile_addr_r);
211 * Wrapper to make it easier to store the file at file_path in the location
212 * specified by envaddr_name. file_path will be joined to the bootfile path,
213 * if any is specified.
215 * Returns 1 on success or < 0 on error.
217 static int get_relfile_envaddr(cmd_tbl_t *cmdtp, const char *file_path, 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 == NULL) {
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) {
403 strcpy(mac_str, " BOOTIF=");
404 err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
410 if ((label->ipappend & 0x3) || label->append) {
411 char bootargs[CONFIG_SYS_CBSIZE] = "";
412 char finalbootargs[CONFIG_SYS_CBSIZE];
414 if (strlen(label->append ?: "") +
415 strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) {
416 printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n",
417 strlen(label->append ?: ""),
418 strlen(ip_str), strlen(mac_str),
423 strncpy(bootargs, label->append,
425 strcat(bootargs, ip_str);
426 strcat(bootargs, mac_str);
428 cli_simple_process_macros(bootargs, finalbootargs);
429 env_set("bootargs", finalbootargs);
430 printf("append: %s\n", finalbootargs);
434 bootm_argv[1] = env_get("kernel_addr_r");
435 /* for FIT, append the configuration identifier */
437 int len = strlen(bootm_argv[1]) + strlen(label->config) + 1;
439 fit_addr = malloc(len);
441 printf("malloc fail (FIT address)\n");
444 snprintf(fit_addr, len, "%s%s", bootm_argv[1], label->config);
445 bootm_argv[1] = fit_addr;
449 * fdt usage is optional:
450 * It handles the following scenarios. All scenarios are exclusive
452 * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
453 * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
454 * and adjust argc appropriately.
456 * Scenario 2: If there is an fdt_addr specified, pass it along to
457 * bootm, and adjust argc appropriately.
459 * Scenario 3: fdt blob is not available.
461 bootm_argv[3] = env_get("fdt_addr_r");
463 /* if fdt label is defined then get fdt from server */
465 char *fdtfile = NULL;
466 char *fdtfilefree = NULL;
469 fdtfile = label->fdt;
470 } else if (label->fdtdir) {
471 char *f1, *f2, *f3, *f4, *slash;
473 f1 = env_get("fdtfile");
480 * For complex cases where this code doesn't
481 * generate the correct filename, the board
482 * code should set $fdtfile during early boot,
483 * or the boot scripts should set $fdtfile
484 * before invoking "pxe" or "sysboot".
488 f3 = env_get("board");
492 len = strlen(label->fdtdir);
495 else if (label->fdtdir[len - 1] != '/')
500 len = strlen(label->fdtdir) + strlen(slash) +
501 strlen(f1) + strlen(f2) + strlen(f3) +
503 fdtfilefree = malloc(len);
505 printf("malloc fail (FDT filename)\n");
509 snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
510 label->fdtdir, slash, f1, f2, f3, f4);
511 fdtfile = fdtfilefree;
515 int err = get_relfile_envaddr(cmdtp, fdtfile, "fdt_addr_r");
518 printf("Skipping %s for failure retrieving fdt\n",
523 bootm_argv[3] = NULL;
528 bootm_argv[3] = env_get("fdt_addr");
536 kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
537 buf = map_sysmem(kernel_addr, 0);
538 /* Try bootm for legacy and FIT format image */
539 if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
540 do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
541 #ifdef CONFIG_CMD_BOOTI
542 /* Try booting an AArch64 Linux kernel image */
544 do_booti(cmdtp, 0, bootm_argc, bootm_argv);
545 #elif defined(CONFIG_CMD_BOOTZ)
546 /* Try booting a Image */
548 do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
559 * Tokens for the pxe file parser.
586 * A token - given by a value and a type.
590 enum token_type type;
594 * Keywords recognized.
596 static const struct token keywords[] = {
599 {"timeout", T_TIMEOUT},
600 {"default", T_DEFAULT},
601 {"prompt", T_PROMPT},
603 {"kernel", T_KERNEL},
605 {"localboot", T_LOCALBOOT},
606 {"append", T_APPEND},
607 {"initrd", T_INITRD},
608 {"include", T_INCLUDE},
609 {"devicetree", T_FDT},
611 {"devicetreedir", T_FDTDIR},
612 {"fdtdir", T_FDTDIR},
613 {"ontimeout", T_ONTIMEOUT,},
614 {"ipappend", T_IPAPPEND,},
615 {"background", T_BACKGROUND,},
620 * Since pxe(linux) files don't have a token to identify the start of a
621 * literal, we have to keep track of when we're in a state where a literal is
622 * expected vs when we're in a state a keyword is expected.
631 * get_string retrieves a string from *p and stores it as a token in
634 * get_string used for scanning both string literals and keywords.
636 * Characters from *p are copied into t-val until a character equal to
637 * delim is found, or a NUL byte is reached. If delim has the special value of
638 * ' ', any whitespace character will be used as a delimiter.
640 * If lower is unequal to 0, uppercase characters will be converted to
641 * lowercase in the result. This is useful to make keywords case
644 * The location of *p is updated to point to the first character after the end
645 * of the token - the ending delimiter.
647 * On success, the new value of t->val is returned. Memory for t->val is
648 * allocated using malloc and must be free()'d to reclaim it. If insufficient
649 * memory is available, NULL is returned.
651 static char *get_string(char **p, struct token *t, char delim, int lower)
657 * b and e both start at the beginning of the input stream.
659 * e is incremented until we find the ending delimiter, or a NUL byte
660 * is reached. Then, we take e - b to find the length of the token.
665 if ((delim == ' ' && isspace(*e)) || delim == *e)
673 * Allocate memory to hold the string, and copy it in, converting
674 * characters to lowercase if lower is != 0.
676 t->val = malloc(len + 1);
680 for (i = 0; i < len; i++, b++) {
682 t->val[i] = tolower(*b);
690 * Update *p so the caller knows where to continue scanning.
700 * Populate a keyword token with a type and value.
702 static void get_keyword(struct token *t)
706 for (i = 0; keywords[i].val; i++) {
707 if (!strcmp(t->val, keywords[i].val)) {
708 t->type = keywords[i].type;
715 * Get the next token. We have to keep track of which state we're in to know
716 * if we're looking to get a string literal or a keyword.
718 * *p is updated to point at the first character after the current token.
720 static void get_token(char **p, struct token *t, enum lex_state state)
726 /* eat non EOL whitespace */
731 * eat comments. note that string literals can't begin with #, but
732 * can contain a # after their first character.
735 while (*c && *c != '\n')
742 } else if (*c == '\0') {
745 } else if (state == L_SLITERAL) {
746 get_string(&c, t, '\n', 0);
747 } else if (state == L_KEYWORD) {
749 * when we expect a keyword, we first get the next string
750 * token delimited by whitespace, and then check if it
751 * matches a keyword in our keyword list. if it does, it's
752 * converted to a keyword token of the appropriate type, and
753 * if not, it remains a string token.
755 get_string(&c, t, ' ', 1);
763 * Increment *c until we get to the end of the current line, or EOF.
765 static void eol_or_eof(char **c)
767 while (**c && **c != '\n')
772 * All of these parse_* functions share some common behavior.
774 * They finish with *c pointing after the token they parse, and return 1 on
775 * success, or < 0 on error.
779 * Parse a string literal and store a pointer it at *dst. String literals
780 * terminate at the end of the line.
782 static int parse_sliteral(char **c, char **dst)
787 get_token(c, &t, L_SLITERAL);
789 if (t.type != T_STRING) {
790 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
800 * Parse a base 10 (unsigned) integer and store it at *dst.
802 static int parse_integer(char **c, int *dst)
807 get_token(c, &t, L_SLITERAL);
809 if (t.type != T_STRING) {
810 printf("Expected string: %.*s\n", (int)(*c - s), s);
814 *dst = simple_strtol(t.val, NULL, 10);
821 static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
822 struct pxe_menu *cfg, int nest_level);
825 * Parse an include statement, and retrieve and parse the file it mentions.
827 * base should point to a location where it's safe to store the file, and
828 * nest_level should indicate how many nested includes have occurred. For this
829 * include, nest_level has already been incremented and doesn't need to be
832 static int handle_include(cmd_tbl_t *cmdtp, char **c, unsigned long base,
833 struct pxe_menu *cfg, int nest_level)
841 err = parse_sliteral(c, &include_path);
844 printf("Expected include path: %.*s\n",
849 err = get_pxe_file(cmdtp, include_path, base);
852 printf("Couldn't retrieve %s\n", include_path);
856 buf = map_sysmem(base, 0);
857 ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
864 * Parse lines that begin with 'menu'.
866 * base and nest are provided to handle the 'menu include' case.
868 * base should point to a location where it's safe to store the included file.
870 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
871 * a file it includes, 3 when parsing a file included by that file, and so on.
873 static int parse_menu(cmd_tbl_t *cmdtp, char **c, struct pxe_menu *cfg,
874 unsigned long base, int nest_level)
880 get_token(c, &t, L_KEYWORD);
884 err = parse_sliteral(c, &cfg->title);
889 err = handle_include(cmdtp, c, base, cfg,
894 err = parse_sliteral(c, &cfg->bmp);
898 printf("Ignoring malformed menu command: %.*s\n",
911 * Handles parsing a 'menu line' when we're parsing a label.
913 static int parse_label_menu(char **c, struct pxe_menu *cfg,
914 struct pxe_label *label)
921 get_token(c, &t, L_KEYWORD);
925 if (!cfg->default_label)
926 cfg->default_label = strdup(label->name);
928 if (!cfg->default_label)
933 parse_sliteral(c, &label->menu);
936 printf("Ignoring malformed menu command: %.*s\n",
946 * Handles parsing a 'kernel' label.
947 * expecting "filename" or "<fit_filename>#cfg"
949 static int parse_label_kernel(char **c, struct pxe_label *label)
954 err = parse_sliteral(c, &label->kernel);
958 s = strstr(label->kernel, "#");
962 label->config = malloc(strlen(s) + 1);
966 strcpy(label->config, s);
973 * Parses a label and adds it to the list of labels for a menu.
975 * A label ends when we either get to the end of a file, or
976 * get some input we otherwise don't have a handler defined
980 static int parse_label(char **c, struct pxe_menu *cfg)
985 struct pxe_label *label;
988 label = label_create();
992 err = parse_sliteral(c, &label->name);
994 printf("Expected label name: %.*s\n", (int)(*c - s), s);
995 label_destroy(label);
999 list_add_tail(&label->list, &cfg->labels);
1003 get_token(c, &t, L_KEYWORD);
1008 err = parse_label_menu(c, cfg, label);
1013 err = parse_label_kernel(c, label);
1017 err = parse_sliteral(c, &label->append);
1020 s = strstr(label->append, "initrd=");
1024 len = (int)(strchr(s, ' ') - s);
1025 label->initrd = malloc(len + 1);
1026 strncpy(label->initrd, s, len);
1027 label->initrd[len] = '\0';
1033 err = parse_sliteral(c, &label->initrd);
1038 err = parse_sliteral(c, &label->fdt);
1043 err = parse_sliteral(c, &label->fdtdir);
1047 label->localboot = 1;
1048 err = parse_integer(c, &label->localboot_val);
1052 err = parse_integer(c, &label->ipappend);
1060 * put the token back! we don't want it - it's the end
1061 * of a label and whatever token this is, it's
1062 * something for the menu level context to handle.
1074 * This 16 comes from the limit pxelinux imposes on nested includes.
1076 * There is no reason at all we couldn't do more, but some limit helps prevent
1077 * infinite (until crash occurs) recursion if a file tries to include itself.
1079 #define MAX_NEST_LEVEL 16
1082 * Entry point for parsing a menu file. nest_level indicates how many times
1083 * we've nested in includes. It will be 1 for the top level menu file.
1085 * Returns 1 on success, < 0 on error.
1087 static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
1088 struct pxe_menu *cfg, int nest_level)
1091 char *s, *b, *label_name;
1096 if (nest_level > MAX_NEST_LEVEL) {
1097 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1104 get_token(&p, &t, L_KEYWORD);
1110 err = parse_menu(cmdtp, &p, cfg,
1111 base + ALIGN(strlen(b) + 1, 4),
1116 err = parse_integer(&p, &cfg->timeout);
1120 err = parse_label(&p, cfg);
1125 err = parse_sliteral(&p, &label_name);
1128 if (cfg->default_label)
1129 free(cfg->default_label);
1131 cfg->default_label = label_name;
1137 err = handle_include(cmdtp, &p,
1138 base + ALIGN(strlen(b), 4), cfg,
1153 printf("Ignoring unknown command: %.*s\n",
1164 * Free the memory used by a pxe_menu and its labels.
1166 void destroy_pxe_menu(struct pxe_menu *cfg)
1168 struct list_head *pos, *n;
1169 struct pxe_label *label;
1174 if (cfg->default_label)
1175 free(cfg->default_label);
1177 list_for_each_safe(pos, n, &cfg->labels) {
1178 label = list_entry(pos, struct pxe_label, list);
1180 label_destroy(label);
1187 * Entry point for parsing a pxe file. This is only used for the top level
1190 * Returns NULL if there is an error, otherwise, returns a pointer to a
1191 * pxe_menu struct populated with the results of parsing the pxe file (and any
1192 * files it includes). The resulting pxe_menu struct can be free()'d by using
1193 * the destroy_pxe_menu() function.
1195 struct pxe_menu *parse_pxefile(cmd_tbl_t *cmdtp, unsigned long menucfg)
1197 struct pxe_menu *cfg;
1201 cfg = malloc(sizeof(struct pxe_menu));
1206 memset(cfg, 0, sizeof(struct pxe_menu));
1208 INIT_LIST_HEAD(&cfg->labels);
1210 buf = map_sysmem(menucfg, 0);
1211 r = parse_pxefile_top(cmdtp, buf, menucfg, cfg, 1);
1215 destroy_pxe_menu(cfg);
1223 * Converts a pxe_menu struct into a menu struct for use with U-Boot's generic
1226 static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1228 struct pxe_label *label;
1229 struct list_head *pos;
1233 char *default_num = NULL;
1236 * Create a menu and add items for all the labels.
1238 m = menu_create(cfg->title, DIV_ROUND_UP(cfg->timeout, 10),
1239 cfg->prompt, label_print, NULL, NULL);
1244 list_for_each(pos, &cfg->labels) {
1245 label = list_entry(pos, struct pxe_label, list);
1247 sprintf(label->num, "%d", i++);
1248 if (menu_item_add(m, label->num, label) != 1) {
1252 if (cfg->default_label &&
1253 (strcmp(label->name, cfg->default_label) == 0))
1254 default_num = label->num;
1259 * After we've created items for each label in the menu, set the
1260 * menu's default label if one was specified.
1263 err = menu_default_set(m, default_num);
1265 if (err != -ENOENT) {
1270 printf("Missing default: %s\n", cfg->default_label);
1278 * Try to boot any labels we have yet to attempt to boot.
1280 static void boot_unattempted_labels(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
1282 struct list_head *pos;
1283 struct pxe_label *label;
1285 list_for_each(pos, &cfg->labels) {
1286 label = list_entry(pos, struct pxe_label, list);
1288 if (!label->attempted)
1289 label_boot(cmdtp, label);
1294 * Boot the system as prescribed by a pxe_menu.
1296 * Use the menu system to either get the user's choice or the default, based
1297 * on config or user input. If there is no default or user's choice,
1298 * attempted to boot labels in the order they were given in pxe files.
1299 * If the default or user's choice fails to boot, attempt to boot other
1300 * labels in the order they were given in pxe files.
1302 * If this function returns, there weren't any labels that successfully
1303 * booted, or the user interrupted the menu selection via ctrl+c.
1305 void handle_pxe_menu(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
1311 #ifdef CONFIG_CMD_BMP
1312 /* display BMP if available */
1314 if (get_relfile(cmdtp, cfg->bmp, load_addr)) {
1315 run_command("cls", 0);
1316 bmp_display(load_addr,
1317 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
1319 printf("Skipping background bmp %s for failure\n",
1325 m = pxe_menu_to_menu(cfg);
1329 err = menu_get_choice(m, &choice);
1334 * err == 1 means we got a choice back from menu_get_choice.
1336 * err == -ENOENT if the menu was setup to select the default but no
1337 * default was set. in that case, we should continue trying to boot
1338 * labels that haven't been attempted yet.
1340 * otherwise, the user interrupted or there was some other error and
1345 err = label_boot(cmdtp, choice);
1348 } else if (err != -ENOENT) {
1352 boot_unattempted_labels(cmdtp, cfg);