2 * Copyright 2010-2011 Calxeda, Inc.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/string.h>
21 #include <linux/ctype.h>
23 #include <linux/list.h>
27 #define MAX_TFTP_PATH_LEN 127
31 * Like getenv, but prints an error if envvar isn't defined in the
32 * environment. It always returns what getenv does, so it can be used in
33 * place of getenv without changing error handling otherwise.
35 static char *from_env(char *envvar)
42 printf("missing environment variable: %s\n", envvar);
48 * Convert an ethaddr from the environment to the format used by pxelinux
49 * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
50 * the beginning of the ethernet address to indicate a hardware type of
51 * Ethernet. Also converts uppercase hex characters into lowercase, to match
52 * pxelinux's behavior.
54 * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
55 * environment, or some other value < 0 on error.
57 static int format_mac_pxe(char *outbuf, size_t outbuf_len)
62 ethaddr = from_env("ethaddr");
67 ethaddr_len = strlen(ethaddr);
70 * ethaddr_len + 4 gives room for "01-", ethaddr, and a NUL byte at
73 if (outbuf_len < ethaddr_len + 4) {
74 printf("outbuf is too small (%d < %d)\n",
75 outbuf_len, ethaddr_len + 4);
80 strcpy(outbuf, "01-");
82 for (p = outbuf + 3; *ethaddr; ethaddr++, p++) {
86 *p = tolower(*ethaddr);
95 * Returns the directory the file specified in the bootfile env variable is
96 * in. If bootfile isn't defined in the environment, return NULL, which should
97 * be interpreted as "don't prepend anything to paths".
99 static int get_bootfile_path(char *bootfile_path, size_t bootfile_path_size)
101 char *bootfile, *last_slash;
104 bootfile = from_env("bootfile");
107 bootfile_path[0] = '\0';
111 last_slash = strrchr(bootfile, '/');
113 if (last_slash == NULL) {
114 bootfile_path[0] = '\0';
118 path_len = (last_slash - bootfile) + 1;
120 if (bootfile_path_size < path_len) {
121 printf("bootfile_path too small. (%d < %d)\n",
122 bootfile_path_size, path_len);
127 strncpy(bootfile_path, bootfile, path_len);
129 bootfile_path[path_len] = '\0';
135 * As in pxelinux, paths to files referenced from files we retrieve are
136 * relative to the location of bootfile. get_relfile takes such a path and
137 * joins it with the bootfile path to get the full path to the target file. If
138 * the bootfile path is NULL, we use file_path as is.
140 * Returns 1 for success, or < 0 on error.
142 static int get_relfile(char *file_path, void *file_addr)
145 char relfile[MAX_TFTP_PATH_LEN+1];
147 char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
150 err = get_bootfile_path(relfile, sizeof(relfile));
155 path_len = strlen(file_path);
156 path_len += strlen(relfile);
158 if (path_len > MAX_TFTP_PATH_LEN) {
159 printf("Base path too long (%s%s)\n",
163 return -ENAMETOOLONG;
166 strcat(relfile, file_path);
168 printf("Retrieving file: %s\n", relfile);
170 sprintf(addr_buf, "%p", file_addr);
172 tftp_argv[1] = addr_buf;
173 tftp_argv[2] = relfile;
175 if (do_tftpb(NULL, 0, 3, tftp_argv))
182 * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
183 * 'bootfile' was specified in the environment, the path to bootfile will be
184 * prepended to 'file_path' and the resulting path will be used.
186 * Returns 1 on success, or < 0 for error.
188 static int get_pxe_file(char *file_path, void *file_addr)
190 unsigned long config_file_size;
194 err = get_relfile(file_path, file_addr);
200 * the file comes without a NUL byte at the end, so find out its size
201 * and add the NUL byte.
203 tftp_filesize = from_env("filesize");
208 if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
211 *(char *)(file_addr + config_file_size) = '\0';
216 #define PXELINUX_DIR "pxelinux.cfg/"
219 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
220 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
221 * from the bootfile path, as described above.
223 * Returns 1 on success or < 0 on error.
225 static int get_pxelinux_path(char *file, void *pxefile_addr_r)
227 size_t base_len = strlen(PXELINUX_DIR);
228 char path[MAX_TFTP_PATH_LEN+1];
230 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
231 printf("path (%s%s) too long, skipping\n",
233 return -ENAMETOOLONG;
236 sprintf(path, PXELINUX_DIR "%s", file);
238 return get_pxe_file(path, pxefile_addr_r);
242 * Looks for a pxe file with a name based on the pxeuuid environment variable.
244 * Returns 1 on success or < 0 on error.
246 static int pxe_uuid_path(void *pxefile_addr_r)
250 uuid_str = from_env("pxeuuid");
255 return get_pxelinux_path(uuid_str, pxefile_addr_r);
259 * Looks for a pxe file with a name based on the 'ethaddr' environment
262 * Returns 1 on success or < 0 on error.
264 static int pxe_mac_path(void *pxefile_addr_r)
269 err = format_mac_pxe(mac_str, sizeof(mac_str));
274 return get_pxelinux_path(mac_str, pxefile_addr_r);
278 * Looks for pxe files with names based on our IP address. See pxelinux
279 * documentation for details on what these file names look like. We match
282 * Returns 1 on success or < 0 on error.
284 static int pxe_ipaddr_paths(void *pxefile_addr_r)
289 sprintf(ip_addr, "%08X", ntohl(NetOurIP));
291 for (mask_pos = 7; mask_pos >= 0; mask_pos--) {
292 err = get_pxelinux_path(ip_addr, pxefile_addr_r);
297 ip_addr[mask_pos] = '\0';
304 * Entry point for the 'pxe get' command.
305 * This Follows pxelinux's rules to download a config file from a tftp server.
306 * The file is stored at the location given by the pxefile_addr_r environment
307 * variable, which must be set.
309 * UUID comes from pxeuuid env variable, if defined
310 * MAC addr comes from ethaddr env variable, if defined
313 * see http://syslinux.zytor.com/wiki/index.php/PXELINUX
315 * Returns 0 on success or 1 on error.
318 do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
320 char *pxefile_addr_str;
321 unsigned long pxefile_addr_r;
325 return CMD_RET_USAGE;
328 pxefile_addr_str = from_env("pxefile_addr_r");
330 if (!pxefile_addr_str)
333 err = strict_strtoul(pxefile_addr_str, 16,
334 (unsigned long *)&pxefile_addr_r);
339 * Keep trying paths until we successfully get a file we're looking
342 if (pxe_uuid_path((void *)pxefile_addr_r) > 0
343 || pxe_mac_path((void *)pxefile_addr_r) > 0
344 || pxe_ipaddr_paths((void *)pxefile_addr_r) > 0
345 || get_pxelinux_path("default", (void *)pxefile_addr_r) > 0) {
347 printf("Config file found\n");
352 printf("Config file not found\n");
358 * Wrapper to make it easier to store the file at file_path in the location
359 * specified by envaddr_name. file_path will be joined to the bootfile path,
360 * if any is specified.
362 * Returns 1 on success or < 0 on error.
364 static int get_relfile_envaddr(char *file_path, char *envaddr_name)
366 unsigned long file_addr;
369 envaddr = from_env(envaddr_name);
374 if (strict_strtoul(envaddr, 16, &file_addr) < 0)
377 return get_relfile(file_path, (void *)file_addr);
381 * A note on the pxe file parser.
383 * We're parsing files that use syslinux grammar, which has a few quirks.
384 * String literals must be recognized based on context - there is no
385 * quoting or escaping support. There's also nothing to explicitly indicate
386 * when a label section completes. We deal with that by ending a label
387 * section whenever we see a line that doesn't include.
389 * As with the syslinux family, this same file format could be reused in the
390 * future for non pxe purposes. The only action it takes during parsing that
391 * would throw this off is handling of include files. It assumes we're using
392 * pxe, and does a tftp download of a file listed as an include file in the
393 * middle of the parsing operation. That could be handled by refactoring it to
394 * take a 'include file getter' function.
398 * Describes a single label given in a pxe file.
400 * Create these with the 'label_create' function given below.
402 * name - the name of the menu as given on the 'menu label' line.
403 * kernel - the path to the kernel file to use for this label.
404 * append - kernel command line to use when booting this label
405 * initrd - path to the initrd to use for this label.
406 * attempted - 0 if we haven't tried to boot this label, 1 if we have.
407 * localboot - 1 if this label specified 'localboot', 0 otherwise.
408 * list - lets these form a list, which a pxe_menu struct will hold.
418 struct list_head list;
422 * Describes a pxe menu as given via pxe files.
424 * title - the name of the menu as given by a 'menu title' line.
425 * default_label - the name of the default label, if any.
426 * timeout - time in tenths of a second to wait for a user key-press before
427 * booting the default label.
428 * prompt - if 0, don't prompt for a choice unless the timeout period is
429 * interrupted. If 1, always prompt for a choice regardless of
431 * labels - a list of labels defined for the menu.
438 struct list_head labels;
442 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
443 * result must be free()'d to reclaim the memory.
445 * Returns NULL if malloc fails.
447 static struct pxe_label *label_create(void)
449 struct pxe_label *label;
451 label = malloc(sizeof(struct pxe_label));
456 memset(label, 0, sizeof(struct pxe_label));
462 * Free the memory used by a pxe_label, including that used by its name,
463 * kernel, append and initrd members, if they're non NULL.
465 * So - be sure to only use dynamically allocated memory for the members of
466 * the pxe_label struct, unless you want to clean it up first. These are
467 * currently only created by the pxe file parsing code.
469 static void label_destroy(struct pxe_label *label)
487 * Print a label and its string members if they're defined.
489 * This is passed as a callback to the menu code for displaying each
492 static void label_print(void *data)
494 struct pxe_label *label = data;
495 const char *c = label->menu ? label->menu : label->kernel;
497 printf("%s:\t%s\n", label->name, c);
500 printf("\t\tkernel: %s\n", label->kernel);
503 printf("\t\tappend: %s\n", label->append);
506 printf("\t\tinitrd: %s\n", label->initrd);
510 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
511 * environment variable is defined. Its contents will be executed as U-boot
512 * command. If the label specified an 'append' line, its contents will be
513 * used to overwrite the contents of the 'bootargs' environment variable prior
514 * to running 'localcmd'.
516 * Returns 1 on success or < 0 on error.
518 static int label_localboot(struct pxe_label *label)
520 char *localcmd, *dupcmd;
523 localcmd = from_env("localcmd");
529 * dup the command to avoid any issues with the version of it existing
530 * in the environment changing during the execution of the command.
532 dupcmd = strdup(localcmd);
538 setenv("bootargs", label->append);
540 printf("running: %s\n", dupcmd);
542 ret = run_command(dupcmd, 0);
550 * Boot according to the contents of a pxe_label.
552 * If we can't boot for any reason, we return. A successful boot never
555 * The kernel will be stored in the location given by the 'kernel_addr_r'
556 * environment variable.
558 * If the label specifies an initrd file, it will be stored in the location
559 * given by the 'ramdisk_addr_r' environment variable.
561 * If the label specifies an 'append' line, its contents will overwrite that
562 * of the 'bootargs' environment variable.
564 static void label_boot(struct pxe_label *label)
566 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
571 label->attempted = 1;
573 if (label->localboot) {
574 label_localboot(label);
578 if (label->kernel == NULL) {
579 printf("No kernel given, skipping %s\n",
585 if (get_relfile_envaddr(label->initrd, "ramdisk_addr_r") < 0) {
586 printf("Skipping %s for failure retrieving initrd\n",
591 bootm_argv[2] = getenv("ramdisk_addr_r");
596 if (get_relfile_envaddr(label->kernel, "kernel_addr_r") < 0) {
597 printf("Skipping %s for failure retrieving kernel\n",
603 setenv("bootargs", label->append);
605 bootm_argv[1] = getenv("kernel_addr_r");
608 * fdt usage is optional. If there is an fdt_addr specified, we will
609 * pass it along to bootm, and adjust argc appropriately.
611 bootm_argv[3] = getenv("fdt_addr");
616 do_bootm(NULL, 0, bootm_argc, bootm_argv);
620 * Tokens for the pxe file parser.
642 * A token - given by a value and a type.
646 enum token_type type;
650 * Keywords recognized.
652 static const struct token keywords[] = {
655 {"timeout", T_TIMEOUT},
656 {"default", T_DEFAULT},
657 {"prompt", T_PROMPT},
659 {"kernel", T_KERNEL},
661 {"localboot", T_LOCALBOOT},
662 {"append", T_APPEND},
663 {"initrd", T_INITRD},
664 {"include", T_INCLUDE},
669 * Since pxe(linux) files don't have a token to identify the start of a
670 * literal, we have to keep track of when we're in a state where a literal is
671 * expected vs when we're in a state a keyword is expected.
680 * get_string retrieves a string from *p and stores it as a token in
683 * get_string used for scanning both string literals and keywords.
685 * Characters from *p are copied into t-val until a character equal to
686 * delim is found, or a NUL byte is reached. If delim has the special value of
687 * ' ', any whitespace character will be used as a delimiter.
689 * If lower is unequal to 0, uppercase characters will be converted to
690 * lowercase in the result. This is useful to make keywords case
693 * The location of *p is updated to point to the first character after the end
694 * of the token - the ending delimiter.
696 * On success, the new value of t->val is returned. Memory for t->val is
697 * allocated using malloc and must be free()'d to reclaim it. If insufficient
698 * memory is available, NULL is returned.
700 static char *get_string(char **p, struct token *t, char delim, int lower)
706 * b and e both start at the beginning of the input stream.
708 * e is incremented until we find the ending delimiter, or a NUL byte
709 * is reached. Then, we take e - b to find the length of the token.
714 if ((delim == ' ' && isspace(*e)) || delim == *e)
722 * Allocate memory to hold the string, and copy it in, converting
723 * characters to lowercase if lower is != 0.
725 t->val = malloc(len + 1);
729 for (i = 0; i < len; i++, b++) {
731 t->val[i] = tolower(*b);
739 * Update *p so the caller knows where to continue scanning.
749 * Populate a keyword token with a type and value.
751 static void get_keyword(struct token *t)
755 for (i = 0; keywords[i].val; i++) {
756 if (!strcmp(t->val, keywords[i].val)) {
757 t->type = keywords[i].type;
764 * Get the next token. We have to keep track of which state we're in to know
765 * if we're looking to get a string literal or a keyword.
767 * *p is updated to point at the first character after the current token.
769 static void get_token(char **p, struct token *t, enum lex_state state)
775 /* eat non EOL whitespace */
780 * eat comments. note that string literals can't begin with #, but
781 * can contain a # after their first character.
784 while (*c && *c != '\n')
791 } else if (*c == '\0') {
794 } else if (state == L_SLITERAL) {
795 get_string(&c, t, '\n', 0);
796 } else if (state == L_KEYWORD) {
798 * when we expect a keyword, we first get the next string
799 * token delimited by whitespace, and then check if it
800 * matches a keyword in our keyword list. if it does, it's
801 * converted to a keyword token of the appropriate type, and
802 * if not, it remains a string token.
804 get_string(&c, t, ' ', 1);
812 * Increment *c until we get to the end of the current line, or EOF.
814 static void eol_or_eof(char **c)
816 while (**c && **c != '\n')
821 * All of these parse_* functions share some common behavior.
823 * They finish with *c pointing after the token they parse, and return 1 on
824 * success, or < 0 on error.
828 * Parse a string literal and store a pointer it at *dst. String literals
829 * terminate at the end of the line.
831 static int parse_sliteral(char **c, char **dst)
836 get_token(c, &t, L_SLITERAL);
838 if (t.type != T_STRING) {
839 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
849 * Parse a base 10 (unsigned) integer and store it at *dst.
851 static int parse_integer(char **c, int *dst)
857 get_token(c, &t, L_SLITERAL);
859 if (t.type != T_STRING) {
860 printf("Expected string: %.*s\n", (int)(*c - s), s);
864 if (strict_strtoul(t.val, 10, &temp) < 0) {
865 printf("Expected unsigned integer: %s\n", t.val);
876 static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level);
879 * Parse an include statement, and retrieve and parse the file it mentions.
881 * base should point to a location where it's safe to store the file, and
882 * nest_level should indicate how many nested includes have occurred. For this
883 * include, nest_level has already been incremented and doesn't need to be
886 static int handle_include(char **c, char *base,
887 struct pxe_menu *cfg, int nest_level)
893 err = parse_sliteral(c, &include_path);
896 printf("Expected include path: %.*s\n",
901 err = get_pxe_file(include_path, base);
904 printf("Couldn't retrieve %s\n", include_path);
908 return parse_pxefile_top(base, cfg, nest_level);
912 * Parse lines that begin with 'menu'.
914 * b and nest are provided to handle the 'menu include' case.
916 * b should be the address where the file currently being parsed is stored.
918 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
919 * a file it includes, 3 when parsing a file included by that file, and so on.
921 static int parse_menu(char **c, struct pxe_menu *cfg, char *b, int nest_level)
927 get_token(c, &t, L_KEYWORD);
931 err = parse_sliteral(c, &cfg->title);
936 err = handle_include(c, b + strlen(b) + 1, cfg,
941 printf("Ignoring malformed menu command: %.*s\n",
954 * Handles parsing a 'menu line' when we're parsing a label.
956 static int parse_label_menu(char **c, struct pxe_menu *cfg,
957 struct pxe_label *label)
964 get_token(c, &t, L_KEYWORD);
968 if (cfg->default_label)
969 free(cfg->default_label);
971 cfg->default_label = strdup(label->name);
973 if (!cfg->default_label)
978 parse_sliteral(c, &label->menu);
981 printf("Ignoring malformed menu command: %.*s\n",
991 * Parses a label and adds it to the list of labels for a menu.
993 * A label ends when we either get to the end of a file, or
994 * get some input we otherwise don't have a handler defined
998 static int parse_label(char **c, struct pxe_menu *cfg)
1002 struct pxe_label *label;
1005 label = label_create();
1009 err = parse_sliteral(c, &label->name);
1011 printf("Expected label name: %.*s\n", (int)(*c - s), s);
1012 label_destroy(label);
1016 list_add_tail(&label->list, &cfg->labels);
1020 get_token(c, &t, L_KEYWORD);
1025 err = parse_label_menu(c, cfg, label);
1030 err = parse_sliteral(c, &label->kernel);
1034 err = parse_sliteral(c, &label->append);
1038 err = parse_sliteral(c, &label->initrd);
1042 err = parse_integer(c, &label->localboot);
1050 * put the token back! we don't want it - it's the end
1051 * of a label and whatever token this is, it's
1052 * something for the menu level context to handle.
1064 * This 16 comes from the limit pxelinux imposes on nested includes.
1066 * There is no reason at all we couldn't do more, but some limit helps prevent
1067 * infinite (until crash occurs) recursion if a file tries to include itself.
1069 #define MAX_NEST_LEVEL 16
1072 * Entry point for parsing a menu file. nest_level indicates how many times
1073 * we've nested in includes. It will be 1 for the top level menu file.
1075 * Returns 1 on success, < 0 on error.
1077 static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level)
1080 char *s, *b, *label_name;
1085 if (nest_level > MAX_NEST_LEVEL) {
1086 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1093 get_token(&p, &t, L_KEYWORD);
1098 err = parse_menu(&p, cfg, b, nest_level);
1102 err = parse_integer(&p, &cfg->timeout);
1106 err = parse_label(&p, cfg);
1110 err = parse_sliteral(&p, &label_name);
1113 if (cfg->default_label)
1114 free(cfg->default_label);
1116 cfg->default_label = label_name;
1122 err = handle_include(&p, b + ALIGN(strlen(b), 4), cfg,
1127 err = parse_integer(&p, &cfg->prompt);
1137 printf("Ignoring unknown command: %.*s\n",
1148 * Free the memory used by a pxe_menu and its labels.
1150 static void destroy_pxe_menu(struct pxe_menu *cfg)
1152 struct list_head *pos, *n;
1153 struct pxe_label *label;
1158 if (cfg->default_label)
1159 free(cfg->default_label);
1161 list_for_each_safe(pos, n, &cfg->labels) {
1162 label = list_entry(pos, struct pxe_label, list);
1164 label_destroy(label);
1171 * Entry point for parsing a pxe file. This is only used for the top level
1174 * Returns NULL if there is an error, otherwise, returns a pointer to a
1175 * pxe_menu struct populated with the results of parsing the pxe file (and any
1176 * files it includes). The resulting pxe_menu struct can be free()'d by using
1177 * the destroy_pxe_menu() function.
1179 static struct pxe_menu *parse_pxefile(char *menucfg)
1181 struct pxe_menu *cfg;
1183 cfg = malloc(sizeof(struct pxe_menu));
1188 memset(cfg, 0, sizeof(struct pxe_menu));
1190 INIT_LIST_HEAD(&cfg->labels);
1192 if (parse_pxefile_top(menucfg, cfg, 1) < 0) {
1193 destroy_pxe_menu(cfg);
1201 * Converts a pxe_menu struct into a menu struct for use with U-boot's generic
1204 static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1206 struct pxe_label *label;
1207 struct list_head *pos;
1212 * Create a menu and add items for all the labels.
1214 m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print);
1219 list_for_each(pos, &cfg->labels) {
1220 label = list_entry(pos, struct pxe_label, list);
1222 if (menu_item_add(m, label->name, label) != 1) {
1229 * After we've created items for each label in the menu, set the
1230 * menu's default label if one was specified.
1232 if (cfg->default_label) {
1233 err = menu_default_set(m, cfg->default_label);
1235 if (err != -ENOENT) {
1240 printf("Missing default: %s\n", cfg->default_label);
1248 * Try to boot any labels we have yet to attempt to boot.
1250 static void boot_unattempted_labels(struct pxe_menu *cfg)
1252 struct list_head *pos;
1253 struct pxe_label *label;
1255 list_for_each(pos, &cfg->labels) {
1256 label = list_entry(pos, struct pxe_label, list);
1258 if (!label->attempted)
1264 * Boot the system as prescribed by a pxe_menu.
1266 * Use the menu system to either get the user's choice or the default, based
1267 * on config or user input. If there is no default or user's choice,
1268 * attempted to boot labels in the order they were given in pxe files.
1269 * If the default or user's choice fails to boot, attempt to boot other
1270 * labels in the order they were given in pxe files.
1272 * If this function returns, there weren't any labels that successfully
1273 * booted, or the user interrupted the menu selection via ctrl+c.
1275 static void handle_pxe_menu(struct pxe_menu *cfg)
1281 m = pxe_menu_to_menu(cfg);
1285 err = menu_get_choice(m, &choice);
1290 * err == 1 means we got a choice back from menu_get_choice.
1292 * err == -ENOENT if the menu was setup to select the default but no
1293 * default was set. in that case, we should continue trying to boot
1294 * labels that haven't been attempted yet.
1296 * otherwise, the user interrupted or there was some other error and
1302 else if (err != -ENOENT)
1305 boot_unattempted_labels(cfg);
1309 * Boots a system using a pxe file
1311 * Returns 0 on success, 1 on error.
1314 do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1316 unsigned long pxefile_addr_r;
1317 struct pxe_menu *cfg;
1318 char *pxefile_addr_str;
1321 pxefile_addr_str = from_env("pxefile_addr_r");
1322 if (!pxefile_addr_str)
1325 } else if (argc == 2) {
1326 pxefile_addr_str = argv[1];
1328 return CMD_RET_USAGE;
1331 if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
1332 printf("Invalid pxefile address: %s\n", pxefile_addr_str);
1336 cfg = parse_pxefile((char *)(pxefile_addr_r));
1339 printf("Error parsing config file\n");
1343 handle_pxe_menu(cfg);
1345 destroy_pxe_menu(cfg);
1350 static cmd_tbl_t cmd_pxe_sub[] = {
1351 U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
1352 U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
1355 int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1360 return CMD_RET_USAGE;
1362 /* drop initial "pxe" arg */
1366 cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub));
1369 return cp->cmd(cmdtp, flag, argc, argv);
1371 return CMD_RET_USAGE;
1376 "commands to get and boot from pxe files",
1377 "get - try to retrieve a pxe file using tftp\npxe "
1378 "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"