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 512
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, '/');
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", relfile, file_path);
130 return -ENAMETOOLONG;
133 strcat(relfile, file_path);
135 printf("Retrieving file: %s\n", relfile);
137 sprintf(addr_buf, "%lx", file_addr);
139 return do_getfile(cmdtp, relfile, addr_buf);
143 * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
144 * 'bootfile' was specified in the environment, the path to bootfile will be
145 * prepended to 'file_path' and the resulting path will be used.
147 * Returns 1 on success, or < 0 for error.
149 int get_pxe_file(cmd_tbl_t *cmdtp, const char *file_path,
150 unsigned long file_addr)
152 unsigned long config_file_size;
157 err = get_relfile(cmdtp, file_path, file_addr);
163 * the file comes without a NUL byte at the end, so find out its size
164 * and add the NUL byte.
166 tftp_filesize = from_env("filesize");
171 if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
174 buf = map_sysmem(file_addr + config_file_size, 1);
181 #define PXELINUX_DIR "pxelinux.cfg/"
184 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
185 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
186 * from the bootfile path, as described above.
188 * Returns 1 on success or < 0 on error.
190 int get_pxelinux_path(cmd_tbl_t *cmdtp, const char *file,
191 unsigned long pxefile_addr_r)
193 size_t base_len = strlen(PXELINUX_DIR);
194 char path[MAX_TFTP_PATH_LEN + 1];
196 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
197 printf("path (%s%s) too long, skipping\n",
199 return -ENAMETOOLONG;
202 sprintf(path, PXELINUX_DIR "%s", file);
204 return get_pxe_file(cmdtp, path, pxefile_addr_r);
208 * Wrapper to make it easier to store the file at file_path in the location
209 * specified by envaddr_name. file_path will be joined to the bootfile path,
210 * if any is specified.
212 * Returns 1 on success or < 0 on error.
214 static int get_relfile_envaddr(cmd_tbl_t *cmdtp, const char *file_path,
215 const char *envaddr_name)
217 unsigned long file_addr;
220 envaddr = from_env(envaddr_name);
225 if (strict_strtoul(envaddr, 16, &file_addr) < 0)
228 return get_relfile(cmdtp, file_path, file_addr);
232 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
233 * result must be free()'d to reclaim the memory.
235 * Returns NULL if malloc fails.
237 static struct pxe_label *label_create(void)
239 struct pxe_label *label;
241 label = malloc(sizeof(struct pxe_label));
246 memset(label, 0, sizeof(struct pxe_label));
252 * Free the memory used by a pxe_label, including that used by its name,
253 * kernel, append and initrd members, if they're non NULL.
255 * So - be sure to only use dynamically allocated memory for the members of
256 * the pxe_label struct, unless you want to clean it up first. These are
257 * currently only created by the pxe file parsing code.
259 static void label_destroy(struct pxe_label *label)
286 * Print a label and its string members if they're defined.
288 * This is passed as a callback to the menu code for displaying each
291 static void label_print(void *data)
293 struct pxe_label *label = data;
294 const char *c = label->menu ? label->menu : label->name;
296 printf("%s:\t%s\n", label->num, c);
300 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
301 * environment variable is defined. Its contents will be executed as U-Boot
302 * command. If the label specified an 'append' line, its contents will be
303 * used to overwrite the contents of the 'bootargs' environment variable prior
304 * to running 'localcmd'.
306 * Returns 1 on success or < 0 on error.
308 static int label_localboot(struct pxe_label *label)
312 localcmd = from_env("localcmd");
318 char bootargs[CONFIG_SYS_CBSIZE];
320 cli_simple_process_macros(label->append, bootargs);
321 env_set("bootargs", bootargs);
324 debug("running: %s\n", localcmd);
326 return run_command_list(localcmd, strlen(localcmd), 0);
330 * Boot according to the contents of a pxe_label.
332 * If we can't boot for any reason, we return. A successful boot never
335 * The kernel will be stored in the location given by the 'kernel_addr_r'
336 * environment variable.
338 * If the label specifies an initrd file, it will be stored in the location
339 * given by the 'ramdisk_addr_r' environment variable.
341 * If the label specifies an 'append' line, its contents will overwrite that
342 * of the 'bootargs' environment variable.
344 static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
346 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
348 char mac_str[29] = "";
349 char ip_str[68] = "";
350 char *fit_addr = NULL;
358 label->attempted = 1;
360 if (label->localboot) {
361 if (label->localboot_val >= 0)
362 label_localboot(label);
366 if (!label->kernel) {
367 printf("No kernel given, skipping %s\n",
373 if (get_relfile_envaddr(cmdtp, label->initrd, "ramdisk_addr_r") < 0) {
374 printf("Skipping %s for failure retrieving initrd\n",
379 bootm_argv[2] = initrd_str;
380 strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18);
381 strcat(bootm_argv[2], ":");
382 strncat(bootm_argv[2], env_get("filesize"), 9);
386 if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
387 printf("Skipping %s for failure retrieving kernel\n",
392 if (label->ipappend & 0x1) {
393 sprintf(ip_str, " ip=%s:%s:%s:%s",
394 env_get("ipaddr"), env_get("serverip"),
395 env_get("gatewayip"), env_get("netmask"));
398 #ifdef CONFIG_CMD_NET
399 if (label->ipappend & 0x2) {
402 strcpy(mac_str, " BOOTIF=");
403 err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
409 if ((label->ipappend & 0x3) || label->append) {
410 char bootargs[CONFIG_SYS_CBSIZE] = "";
411 char finalbootargs[CONFIG_SYS_CBSIZE];
413 if (strlen(label->append ?: "") +
414 strlen(ip_str) + strlen(mac_str) + 1 > sizeof(bootargs)) {
415 printf("bootarg overflow %zd+%zd+%zd+1 > %zd\n",
416 strlen(label->append ?: ""),
417 strlen(ip_str), strlen(mac_str),
423 strncpy(bootargs, label->append, sizeof(bootargs));
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);
433 bootm_argv[1] = env_get("kernel_addr_r");
434 /* for FIT, append the configuration identifier */
436 int len = strlen(bootm_argv[1]) + strlen(label->config) + 1;
438 fit_addr = malloc(len);
440 printf("malloc fail (FIT address)\n");
443 snprintf(fit_addr, len, "%s%s", bootm_argv[1], label->config);
444 bootm_argv[1] = fit_addr;
448 * fdt usage is optional:
449 * It handles the following scenarios. All scenarios are exclusive
451 * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
452 * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
453 * and adjust argc appropriately.
455 * Scenario 2: If there is an fdt_addr specified, pass it along to
456 * bootm, and adjust argc appropriately.
458 * Scenario 3: fdt blob is not available.
460 bootm_argv[3] = env_get("fdt_addr_r");
462 /* if fdt label is defined then get fdt from server */
464 char *fdtfile = NULL;
465 char *fdtfilefree = NULL;
468 fdtfile = label->fdt;
469 } else if (label->fdtdir) {
470 char *f1, *f2, *f3, *f4, *slash;
472 f1 = env_get("fdtfile");
479 * For complex cases where this code doesn't
480 * generate the correct filename, the board
481 * code should set $fdtfile during early boot,
482 * or the boot scripts should set $fdtfile
483 * before invoking "pxe" or "sysboot".
487 f3 = env_get("board");
491 len = strlen(label->fdtdir);
494 else if (label->fdtdir[len - 1] != '/')
499 len = strlen(label->fdtdir) + strlen(slash) +
500 strlen(f1) + strlen(f2) + strlen(f3) +
502 fdtfilefree = malloc(len);
504 printf("malloc fail (FDT filename)\n");
508 snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
509 label->fdtdir, slash, f1, f2, f3, f4);
510 fdtfile = fdtfilefree;
514 int err = get_relfile_envaddr(cmdtp, fdtfile,
519 printf("Skipping %s for failure retrieving fdt\n",
524 bootm_argv[3] = NULL;
529 bootm_argv[3] = env_get("fdt_addr");
537 kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
538 buf = map_sysmem(kernel_addr, 0);
539 /* Try bootm for legacy and FIT format image */
540 if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
541 do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
542 #ifdef CONFIG_CMD_BOOTI
543 /* Try booting an AArch64 Linux kernel image */
545 do_booti(cmdtp, 0, bootm_argc, bootm_argv);
546 #elif defined(CONFIG_CMD_BOOTZ)
547 /* Try booting a Image */
549 do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
560 * Tokens for the pxe file parser.
587 * A token - given by a value and a type.
591 enum token_type type;
595 * Keywords recognized.
597 static const struct token keywords[] = {
600 {"timeout", T_TIMEOUT},
601 {"default", T_DEFAULT},
602 {"prompt", T_PROMPT},
604 {"kernel", T_KERNEL},
606 {"localboot", T_LOCALBOOT},
607 {"append", T_APPEND},
608 {"initrd", T_INITRD},
609 {"include", T_INCLUDE},
610 {"devicetree", T_FDT},
612 {"devicetreedir", T_FDTDIR},
613 {"fdtdir", T_FDTDIR},
614 {"ontimeout", T_ONTIMEOUT,},
615 {"ipappend", T_IPAPPEND,},
616 {"background", T_BACKGROUND,},
621 * Since pxe(linux) files don't have a token to identify the start of a
622 * literal, we have to keep track of when we're in a state where a literal is
623 * expected vs when we're in a state a keyword is expected.
632 * get_string retrieves a string from *p and stores it as a token in
635 * get_string used for scanning both string literals and keywords.
637 * Characters from *p are copied into t-val until a character equal to
638 * delim is found, or a NUL byte is reached. If delim has the special value of
639 * ' ', any whitespace character will be used as a delimiter.
641 * If lower is unequal to 0, uppercase characters will be converted to
642 * lowercase in the result. This is useful to make keywords case
645 * The location of *p is updated to point to the first character after the end
646 * of the token - the ending delimiter.
648 * On success, the new value of t->val is returned. Memory for t->val is
649 * allocated using malloc and must be free()'d to reclaim it. If insufficient
650 * memory is available, NULL is returned.
652 static char *get_string(char **p, struct token *t, char delim, int lower)
658 * b and e both start at the beginning of the input stream.
660 * e is incremented until we find the ending delimiter, or a NUL byte
661 * is reached. Then, we take e - b to find the length of the token.
667 if ((delim == ' ' && isspace(*e)) || delim == *e)
675 * Allocate memory to hold the string, and copy it in, converting
676 * characters to lowercase if lower is != 0.
678 t->val = malloc(len + 1);
682 for (i = 0; i < len; i++, b++) {
684 t->val[i] = tolower(*b);
692 * Update *p so the caller knows where to continue scanning.
702 * Populate a keyword token with a type and value.
704 static void get_keyword(struct token *t)
708 for (i = 0; keywords[i].val; i++) {
709 if (!strcmp(t->val, keywords[i].val)) {
710 t->type = keywords[i].type;
717 * Get the next token. We have to keep track of which state we're in to know
718 * if we're looking to get a string literal or a keyword.
720 * *p is updated to point at the first character after the current token.
722 static void get_token(char **p, struct token *t, enum lex_state state)
728 /* eat non EOL whitespace */
733 * eat comments. note that string literals can't begin with #, but
734 * can contain a # after their first character.
737 while (*c && *c != '\n')
744 } else if (*c == '\0') {
747 } else if (state == L_SLITERAL) {
748 get_string(&c, t, '\n', 0);
749 } else if (state == L_KEYWORD) {
751 * when we expect a keyword, we first get the next string
752 * token delimited by whitespace, and then check if it
753 * matches a keyword in our keyword list. if it does, it's
754 * converted to a keyword token of the appropriate type, and
755 * if not, it remains a string token.
757 get_string(&c, t, ' ', 1);
765 * Increment *c until we get to the end of the current line, or EOF.
767 static void eol_or_eof(char **c)
769 while (**c && **c != '\n')
774 * All of these parse_* functions share some common behavior.
776 * They finish with *c pointing after the token they parse, and return 1 on
777 * success, or < 0 on error.
781 * Parse a string literal and store a pointer it at *dst. String literals
782 * terminate at the end of the line.
784 static int parse_sliteral(char **c, char **dst)
789 get_token(c, &t, L_SLITERAL);
791 if (t.type != T_STRING) {
792 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
802 * Parse a base 10 (unsigned) integer and store it at *dst.
804 static int parse_integer(char **c, int *dst)
809 get_token(c, &t, L_SLITERAL);
811 if (t.type != T_STRING) {
812 printf("Expected string: %.*s\n", (int)(*c - s), s);
816 *dst = simple_strtol(t.val, NULL, 10);
823 static int parse_pxefile_top(cmd_tbl_t *cmdtp, char *p, unsigned long base,
824 struct pxe_menu *cfg, int nest_level);
827 * Parse an include statement, and retrieve and parse the file it mentions.
829 * base should point to a location where it's safe to store the file, and
830 * nest_level should indicate how many nested includes have occurred. For this
831 * include, nest_level has already been incremented and doesn't need to be
834 static int handle_include(cmd_tbl_t *cmdtp, char **c, unsigned long base,
835 struct pxe_menu *cfg, int nest_level)
843 err = parse_sliteral(c, &include_path);
846 printf("Expected include path: %.*s\n", (int)(*c - s), s);
850 err = get_pxe_file(cmdtp, include_path, base);
853 printf("Couldn't retrieve %s\n", include_path);
857 buf = map_sysmem(base, 0);
858 ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
865 * Parse lines that begin with 'menu'.
867 * base and nest are provided to handle the 'menu include' case.
869 * base should point to a location where it's safe to store the included file.
871 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
872 * a file it includes, 3 when parsing a file included by that file, and so on.
874 static int parse_menu(cmd_tbl_t *cmdtp, char **c, struct pxe_menu *cfg,
875 unsigned long base, int nest_level)
881 get_token(c, &t, L_KEYWORD);
885 err = parse_sliteral(c, &cfg->title);
890 err = handle_include(cmdtp, c, base, cfg, nest_level + 1);
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;
1258 * After we've created items for each label in the menu, set the
1259 * menu's default label if one was specified.
1262 err = menu_default_set(m, default_num);
1264 if (err != -ENOENT) {
1269 printf("Missing default: %s\n", cfg->default_label);
1277 * Try to boot any labels we have yet to attempt to boot.
1279 static void boot_unattempted_labels(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
1281 struct list_head *pos;
1282 struct pxe_label *label;
1284 list_for_each(pos, &cfg->labels) {
1285 label = list_entry(pos, struct pxe_label, list);
1287 if (!label->attempted)
1288 label_boot(cmdtp, label);
1293 * Boot the system as prescribed by a pxe_menu.
1295 * Use the menu system to either get the user's choice or the default, based
1296 * on config or user input. If there is no default or user's choice,
1297 * attempted to boot labels in the order they were given in pxe files.
1298 * If the default or user's choice fails to boot, attempt to boot other
1299 * labels in the order they were given in pxe files.
1301 * If this function returns, there weren't any labels that successfully
1302 * booted, or the user interrupted the menu selection via ctrl+c.
1304 void handle_pxe_menu(cmd_tbl_t *cmdtp, struct pxe_menu *cfg)
1310 #ifdef CONFIG_CMD_BMP
1311 /* display BMP if available */
1313 if (get_relfile(cmdtp, cfg->bmp, load_addr)) {
1314 run_command("cls", 0);
1315 bmp_display(load_addr,
1316 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
1318 printf("Skipping background bmp %s for failure\n",
1324 m = pxe_menu_to_menu(cfg);
1328 err = menu_get_choice(m, &choice);
1333 * err == 1 means we got a choice back from menu_get_choice.
1335 * err == -ENOENT if the menu was setup to select the default but no
1336 * default was set. in that case, we should continue trying to boot
1337 * labels that haven't been attempted yet.
1339 * otherwise, the user interrupted or there was some other error and
1344 err = label_boot(cmdtp, choice);
1347 } else if (err != -ENOENT) {
1351 boot_unattempted_labels(cmdtp, cfg);