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(const char *file_path, char *bootfile_path,
100 size_t bootfile_path_size)
102 char *bootfile, *last_slash;
105 if (file_path[0] == '/')
108 bootfile = from_env("bootfile");
113 last_slash = strrchr(bootfile, '/');
115 if (last_slash == NULL)
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);
130 bootfile_path[path_len] = '\0';
136 * As in pxelinux, paths to files referenced from files we retrieve are
137 * relative to the location of bootfile. get_relfile takes such a path and
138 * joins it with the bootfile path to get the full path to the target file. If
139 * the bootfile path is NULL, we use file_path as is.
141 * Returns 1 for success, or < 0 on error.
143 static int get_relfile(char *file_path, void *file_addr)
146 char relfile[MAX_TFTP_PATH_LEN+1];
148 char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
151 err = get_bootfile_path(file_path, relfile, sizeof(relfile));
156 path_len = strlen(file_path);
157 path_len += strlen(relfile);
159 if (path_len > MAX_TFTP_PATH_LEN) {
160 printf("Base path too long (%s%s)\n",
164 return -ENAMETOOLONG;
167 strcat(relfile, file_path);
169 printf("Retrieving file: %s\n", relfile);
171 sprintf(addr_buf, "%p", file_addr);
173 tftp_argv[1] = addr_buf;
174 tftp_argv[2] = relfile;
176 if (do_tftpb(NULL, 0, 3, tftp_argv))
183 * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
184 * 'bootfile' was specified in the environment, the path to bootfile will be
185 * prepended to 'file_path' and the resulting path will be used.
187 * Returns 1 on success, or < 0 for error.
189 static int get_pxe_file(char *file_path, void *file_addr)
191 unsigned long config_file_size;
195 err = get_relfile(file_path, file_addr);
201 * the file comes without a NUL byte at the end, so find out its size
202 * and add the NUL byte.
204 tftp_filesize = from_env("filesize");
209 if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
212 *(char *)(file_addr + config_file_size) = '\0';
217 #define PXELINUX_DIR "pxelinux.cfg/"
220 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
221 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
222 * from the bootfile path, as described above.
224 * Returns 1 on success or < 0 on error.
226 static int get_pxelinux_path(char *file, void *pxefile_addr_r)
228 size_t base_len = strlen(PXELINUX_DIR);
229 char path[MAX_TFTP_PATH_LEN+1];
231 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
232 printf("path (%s%s) too long, skipping\n",
234 return -ENAMETOOLONG;
237 sprintf(path, PXELINUX_DIR "%s", file);
239 return get_pxe_file(path, pxefile_addr_r);
243 * Looks for a pxe file with a name based on the pxeuuid environment variable.
245 * Returns 1 on success or < 0 on error.
247 static int pxe_uuid_path(void *pxefile_addr_r)
251 uuid_str = from_env("pxeuuid");
256 return get_pxelinux_path(uuid_str, pxefile_addr_r);
260 * Looks for a pxe file with a name based on the 'ethaddr' environment
263 * Returns 1 on success or < 0 on error.
265 static int pxe_mac_path(void *pxefile_addr_r)
270 err = format_mac_pxe(mac_str, sizeof(mac_str));
275 return get_pxelinux_path(mac_str, pxefile_addr_r);
279 * Looks for pxe files with names based on our IP address. See pxelinux
280 * documentation for details on what these file names look like. We match
283 * Returns 1 on success or < 0 on error.
285 static int pxe_ipaddr_paths(void *pxefile_addr_r)
290 sprintf(ip_addr, "%08X", ntohl(NetOurIP));
292 for (mask_pos = 7; mask_pos >= 0; mask_pos--) {
293 err = get_pxelinux_path(ip_addr, pxefile_addr_r);
298 ip_addr[mask_pos] = '\0';
305 * Entry point for the 'pxe get' command.
306 * This Follows pxelinux's rules to download a config file from a tftp server.
307 * The file is stored at the location given by the pxefile_addr_r environment
308 * variable, which must be set.
310 * UUID comes from pxeuuid env variable, if defined
311 * MAC addr comes from ethaddr env variable, if defined
314 * see http://syslinux.zytor.com/wiki/index.php/PXELINUX
316 * Returns 0 on success or 1 on error.
319 do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
321 char *pxefile_addr_str;
322 unsigned long pxefile_addr_r;
326 return CMD_RET_USAGE;
329 pxefile_addr_str = from_env("pxefile_addr_r");
331 if (!pxefile_addr_str)
334 err = strict_strtoul(pxefile_addr_str, 16,
335 (unsigned long *)&pxefile_addr_r);
340 * Keep trying paths until we successfully get a file we're looking
343 if (pxe_uuid_path((void *)pxefile_addr_r) > 0
344 || pxe_mac_path((void *)pxefile_addr_r) > 0
345 || pxe_ipaddr_paths((void *)pxefile_addr_r) > 0
346 || get_pxelinux_path("default", (void *)pxefile_addr_r) > 0) {
348 printf("Config file found\n");
353 printf("Config file not found\n");
359 * Wrapper to make it easier to store the file at file_path in the location
360 * specified by envaddr_name. file_path will be joined to the bootfile path,
361 * if any is specified.
363 * Returns 1 on success or < 0 on error.
365 static int get_relfile_envaddr(char *file_path, char *envaddr_name)
367 unsigned long file_addr;
370 envaddr = from_env(envaddr_name);
375 if (strict_strtoul(envaddr, 16, &file_addr) < 0)
378 return get_relfile(file_path, (void *)file_addr);
382 * A note on the pxe file parser.
384 * We're parsing files that use syslinux grammar, which has a few quirks.
385 * String literals must be recognized based on context - there is no
386 * quoting or escaping support. There's also nothing to explicitly indicate
387 * when a label section completes. We deal with that by ending a label
388 * section whenever we see a line that doesn't include.
390 * As with the syslinux family, this same file format could be reused in the
391 * future for non pxe purposes. The only action it takes during parsing that
392 * would throw this off is handling of include files. It assumes we're using
393 * pxe, and does a tftp download of a file listed as an include file in the
394 * middle of the parsing operation. That could be handled by refactoring it to
395 * take a 'include file getter' function.
399 * Describes a single label given in a pxe file.
401 * Create these with the 'label_create' function given below.
403 * name - the name of the menu as given on the 'menu label' line.
404 * kernel - the path to the kernel file to use for this label.
405 * append - kernel command line to use when booting this label
406 * initrd - path to the initrd to use for this label.
407 * attempted - 0 if we haven't tried to boot this label, 1 if we have.
408 * localboot - 1 if this label specified 'localboot', 0 otherwise.
409 * list - lets these form a list, which a pxe_menu struct will hold.
419 struct list_head list;
423 * Describes a pxe menu as given via pxe files.
425 * title - the name of the menu as given by a 'menu title' line.
426 * default_label - the name of the default label, if any.
427 * timeout - time in tenths of a second to wait for a user key-press before
428 * booting the default label.
429 * prompt - if 0, don't prompt for a choice unless the timeout period is
430 * interrupted. If 1, always prompt for a choice regardless of
432 * labels - a list of labels defined for the menu.
439 struct list_head labels;
443 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
444 * result must be free()'d to reclaim the memory.
446 * Returns NULL if malloc fails.
448 static struct pxe_label *label_create(void)
450 struct pxe_label *label;
452 label = malloc(sizeof(struct pxe_label));
457 memset(label, 0, sizeof(struct pxe_label));
463 * Free the memory used by a pxe_label, including that used by its name,
464 * kernel, append and initrd members, if they're non NULL.
466 * So - be sure to only use dynamically allocated memory for the members of
467 * the pxe_label struct, unless you want to clean it up first. These are
468 * currently only created by the pxe file parsing code.
470 static void label_destroy(struct pxe_label *label)
488 * Print a label and its string members if they're defined.
490 * This is passed as a callback to the menu code for displaying each
493 static void label_print(void *data)
495 struct pxe_label *label = data;
496 const char *c = label->menu ? label->menu : label->kernel;
498 printf("%s:\t%s\n", label->name, c);
501 printf("\t\tkernel: %s\n", label->kernel);
504 printf("\t\tappend: %s\n", label->append);
507 printf("\t\tinitrd: %s\n", label->initrd);
511 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
512 * environment variable is defined. Its contents will be executed as U-boot
513 * command. If the label specified an 'append' line, its contents will be
514 * used to overwrite the contents of the 'bootargs' environment variable prior
515 * to running 'localcmd'.
517 * Returns 1 on success or < 0 on error.
519 static int label_localboot(struct pxe_label *label)
521 char *localcmd, *dupcmd;
524 localcmd = from_env("localcmd");
530 * dup the command to avoid any issues with the version of it existing
531 * in the environment changing during the execution of the command.
533 dupcmd = strdup(localcmd);
539 setenv("bootargs", label->append);
541 printf("running: %s\n", dupcmd);
543 ret = run_command(dupcmd, 0);
551 * Boot according to the contents of a pxe_label.
553 * If we can't boot for any reason, we return. A successful boot never
556 * The kernel will be stored in the location given by the 'kernel_addr_r'
557 * environment variable.
559 * If the label specifies an initrd file, it will be stored in the location
560 * given by the 'ramdisk_addr_r' environment variable.
562 * If the label specifies an 'append' line, its contents will overwrite that
563 * of the 'bootargs' environment variable.
565 static void label_boot(struct pxe_label *label)
567 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
572 label->attempted = 1;
574 if (label->localboot) {
575 label_localboot(label);
579 if (label->kernel == NULL) {
580 printf("No kernel given, skipping %s\n",
586 if (get_relfile_envaddr(label->initrd, "ramdisk_addr_r") < 0) {
587 printf("Skipping %s for failure retrieving initrd\n",
592 bootm_argv[2] = getenv("ramdisk_addr_r");
597 if (get_relfile_envaddr(label->kernel, "kernel_addr_r") < 0) {
598 printf("Skipping %s for failure retrieving kernel\n",
604 setenv("bootargs", label->append);
606 bootm_argv[1] = getenv("kernel_addr_r");
609 * fdt usage is optional. If there is an fdt_addr specified, we will
610 * pass it along to bootm, and adjust argc appropriately.
612 bootm_argv[3] = getenv("fdt_addr");
617 do_bootm(NULL, 0, bootm_argc, bootm_argv);
621 * Tokens for the pxe file parser.
643 * A token - given by a value and a type.
647 enum token_type type;
651 * Keywords recognized.
653 static const struct token keywords[] = {
656 {"timeout", T_TIMEOUT},
657 {"default", T_DEFAULT},
658 {"prompt", T_PROMPT},
660 {"kernel", T_KERNEL},
662 {"localboot", T_LOCALBOOT},
663 {"append", T_APPEND},
664 {"initrd", T_INITRD},
665 {"include", T_INCLUDE},
670 * Since pxe(linux) files don't have a token to identify the start of a
671 * literal, we have to keep track of when we're in a state where a literal is
672 * expected vs when we're in a state a keyword is expected.
681 * get_string retrieves a string from *p and stores it as a token in
684 * get_string used for scanning both string literals and keywords.
686 * Characters from *p are copied into t-val until a character equal to
687 * delim is found, or a NUL byte is reached. If delim has the special value of
688 * ' ', any whitespace character will be used as a delimiter.
690 * If lower is unequal to 0, uppercase characters will be converted to
691 * lowercase in the result. This is useful to make keywords case
694 * The location of *p is updated to point to the first character after the end
695 * of the token - the ending delimiter.
697 * On success, the new value of t->val is returned. Memory for t->val is
698 * allocated using malloc and must be free()'d to reclaim it. If insufficient
699 * memory is available, NULL is returned.
701 static char *get_string(char **p, struct token *t, char delim, int lower)
707 * b and e both start at the beginning of the input stream.
709 * e is incremented until we find the ending delimiter, or a NUL byte
710 * is reached. Then, we take e - b to find the length of the token.
715 if ((delim == ' ' && isspace(*e)) || delim == *e)
723 * Allocate memory to hold the string, and copy it in, converting
724 * characters to lowercase if lower is != 0.
726 t->val = malloc(len + 1);
730 for (i = 0; i < len; i++, b++) {
732 t->val[i] = tolower(*b);
740 * Update *p so the caller knows where to continue scanning.
750 * Populate a keyword token with a type and value.
752 static void get_keyword(struct token *t)
756 for (i = 0; keywords[i].val; i++) {
757 if (!strcmp(t->val, keywords[i].val)) {
758 t->type = keywords[i].type;
765 * Get the next token. We have to keep track of which state we're in to know
766 * if we're looking to get a string literal or a keyword.
768 * *p is updated to point at the first character after the current token.
770 static void get_token(char **p, struct token *t, enum lex_state state)
776 /* eat non EOL whitespace */
781 * eat comments. note that string literals can't begin with #, but
782 * can contain a # after their first character.
785 while (*c && *c != '\n')
792 } else if (*c == '\0') {
795 } else if (state == L_SLITERAL) {
796 get_string(&c, t, '\n', 0);
797 } else if (state == L_KEYWORD) {
799 * when we expect a keyword, we first get the next string
800 * token delimited by whitespace, and then check if it
801 * matches a keyword in our keyword list. if it does, it's
802 * converted to a keyword token of the appropriate type, and
803 * if not, it remains a string token.
805 get_string(&c, t, ' ', 1);
813 * Increment *c until we get to the end of the current line, or EOF.
815 static void eol_or_eof(char **c)
817 while (**c && **c != '\n')
822 * All of these parse_* functions share some common behavior.
824 * They finish with *c pointing after the token they parse, and return 1 on
825 * success, or < 0 on error.
829 * Parse a string literal and store a pointer it at *dst. String literals
830 * terminate at the end of the line.
832 static int parse_sliteral(char **c, char **dst)
837 get_token(c, &t, L_SLITERAL);
839 if (t.type != T_STRING) {
840 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
850 * Parse a base 10 (unsigned) integer and store it at *dst.
852 static int parse_integer(char **c, int *dst)
858 get_token(c, &t, L_SLITERAL);
860 if (t.type != T_STRING) {
861 printf("Expected string: %.*s\n", (int)(*c - s), s);
865 if (strict_strtoul(t.val, 10, &temp) < 0) {
866 printf("Expected unsigned integer: %s\n", t.val);
877 static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level);
880 * Parse an include statement, and retrieve and parse the file it mentions.
882 * base should point to a location where it's safe to store the file, and
883 * nest_level should indicate how many nested includes have occurred. For this
884 * include, nest_level has already been incremented and doesn't need to be
887 static int handle_include(char **c, char *base,
888 struct pxe_menu *cfg, int nest_level)
894 err = parse_sliteral(c, &include_path);
897 printf("Expected include path: %.*s\n",
902 err = get_pxe_file(include_path, base);
905 printf("Couldn't retrieve %s\n", include_path);
909 return parse_pxefile_top(base, cfg, nest_level);
913 * Parse lines that begin with 'menu'.
915 * b and nest are provided to handle the 'menu include' case.
917 * b should be the address where the file currently being parsed is stored.
919 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
920 * a file it includes, 3 when parsing a file included by that file, and so on.
922 static int parse_menu(char **c, struct pxe_menu *cfg, char *b, int nest_level)
928 get_token(c, &t, L_KEYWORD);
932 err = parse_sliteral(c, &cfg->title);
937 err = handle_include(c, b + strlen(b) + 1, cfg,
942 printf("Ignoring malformed menu command: %.*s\n",
955 * Handles parsing a 'menu line' when we're parsing a label.
957 static int parse_label_menu(char **c, struct pxe_menu *cfg,
958 struct pxe_label *label)
965 get_token(c, &t, L_KEYWORD);
969 if (cfg->default_label)
970 free(cfg->default_label);
972 cfg->default_label = strdup(label->name);
974 if (!cfg->default_label)
979 parse_sliteral(c, &label->menu);
982 printf("Ignoring malformed menu command: %.*s\n",
992 * Parses a label and adds it to the list of labels for a menu.
994 * A label ends when we either get to the end of a file, or
995 * get some input we otherwise don't have a handler defined
999 static int parse_label(char **c, struct pxe_menu *cfg)
1003 struct pxe_label *label;
1006 label = label_create();
1010 err = parse_sliteral(c, &label->name);
1012 printf("Expected label name: %.*s\n", (int)(*c - s), s);
1013 label_destroy(label);
1017 list_add_tail(&label->list, &cfg->labels);
1021 get_token(c, &t, L_KEYWORD);
1026 err = parse_label_menu(c, cfg, label);
1031 err = parse_sliteral(c, &label->kernel);
1035 err = parse_sliteral(c, &label->append);
1039 err = parse_sliteral(c, &label->initrd);
1043 err = parse_integer(c, &label->localboot);
1051 * put the token back! we don't want it - it's the end
1052 * of a label and whatever token this is, it's
1053 * something for the menu level context to handle.
1065 * This 16 comes from the limit pxelinux imposes on nested includes.
1067 * There is no reason at all we couldn't do more, but some limit helps prevent
1068 * infinite (until crash occurs) recursion if a file tries to include itself.
1070 #define MAX_NEST_LEVEL 16
1073 * Entry point for parsing a menu file. nest_level indicates how many times
1074 * we've nested in includes. It will be 1 for the top level menu file.
1076 * Returns 1 on success, < 0 on error.
1078 static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level)
1081 char *s, *b, *label_name;
1086 if (nest_level > MAX_NEST_LEVEL) {
1087 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1094 get_token(&p, &t, L_KEYWORD);
1099 err = parse_menu(&p, cfg, b, nest_level);
1103 err = parse_integer(&p, &cfg->timeout);
1107 err = parse_label(&p, cfg);
1111 err = parse_sliteral(&p, &label_name);
1114 if (cfg->default_label)
1115 free(cfg->default_label);
1117 cfg->default_label = label_name;
1123 err = handle_include(&p, b + ALIGN(strlen(b), 4), cfg,
1128 err = parse_integer(&p, &cfg->prompt);
1138 printf("Ignoring unknown command: %.*s\n",
1149 * Free the memory used by a pxe_menu and its labels.
1151 static void destroy_pxe_menu(struct pxe_menu *cfg)
1153 struct list_head *pos, *n;
1154 struct pxe_label *label;
1159 if (cfg->default_label)
1160 free(cfg->default_label);
1162 list_for_each_safe(pos, n, &cfg->labels) {
1163 label = list_entry(pos, struct pxe_label, list);
1165 label_destroy(label);
1172 * Entry point for parsing a pxe file. This is only used for the top level
1175 * Returns NULL if there is an error, otherwise, returns a pointer to a
1176 * pxe_menu struct populated with the results of parsing the pxe file (and any
1177 * files it includes). The resulting pxe_menu struct can be free()'d by using
1178 * the destroy_pxe_menu() function.
1180 static struct pxe_menu *parse_pxefile(char *menucfg)
1182 struct pxe_menu *cfg;
1184 cfg = malloc(sizeof(struct pxe_menu));
1189 memset(cfg, 0, sizeof(struct pxe_menu));
1191 INIT_LIST_HEAD(&cfg->labels);
1193 if (parse_pxefile_top(menucfg, cfg, 1) < 0) {
1194 destroy_pxe_menu(cfg);
1202 * Converts a pxe_menu struct into a menu struct for use with U-boot's generic
1205 static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1207 struct pxe_label *label;
1208 struct list_head *pos;
1213 * Create a menu and add items for all the labels.
1215 m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print);
1220 list_for_each(pos, &cfg->labels) {
1221 label = list_entry(pos, struct pxe_label, list);
1223 if (menu_item_add(m, label->name, label) != 1) {
1230 * After we've created items for each label in the menu, set the
1231 * menu's default label if one was specified.
1233 if (cfg->default_label) {
1234 err = menu_default_set(m, cfg->default_label);
1236 if (err != -ENOENT) {
1241 printf("Missing default: %s\n", cfg->default_label);
1249 * Try to boot any labels we have yet to attempt to boot.
1251 static void boot_unattempted_labels(struct pxe_menu *cfg)
1253 struct list_head *pos;
1254 struct pxe_label *label;
1256 list_for_each(pos, &cfg->labels) {
1257 label = list_entry(pos, struct pxe_label, list);
1259 if (!label->attempted)
1265 * Boot the system as prescribed by a pxe_menu.
1267 * Use the menu system to either get the user's choice or the default, based
1268 * on config or user input. If there is no default or user's choice,
1269 * attempted to boot labels in the order they were given in pxe files.
1270 * If the default or user's choice fails to boot, attempt to boot other
1271 * labels in the order they were given in pxe files.
1273 * If this function returns, there weren't any labels that successfully
1274 * booted, or the user interrupted the menu selection via ctrl+c.
1276 static void handle_pxe_menu(struct pxe_menu *cfg)
1282 m = pxe_menu_to_menu(cfg);
1286 err = menu_get_choice(m, &choice);
1291 * err == 1 means we got a choice back from menu_get_choice.
1293 * err == -ENOENT if the menu was setup to select the default but no
1294 * default was set. in that case, we should continue trying to boot
1295 * labels that haven't been attempted yet.
1297 * otherwise, the user interrupted or there was some other error and
1303 else if (err != -ENOENT)
1306 boot_unattempted_labels(cfg);
1310 * Boots a system using a pxe file
1312 * Returns 0 on success, 1 on error.
1315 do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1317 unsigned long pxefile_addr_r;
1318 struct pxe_menu *cfg;
1319 char *pxefile_addr_str;
1322 pxefile_addr_str = from_env("pxefile_addr_r");
1323 if (!pxefile_addr_str)
1326 } else if (argc == 2) {
1327 pxefile_addr_str = argv[1];
1329 return CMD_RET_USAGE;
1332 if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
1333 printf("Invalid pxefile address: %s\n", pxefile_addr_str);
1337 cfg = parse_pxefile((char *)(pxefile_addr_r));
1340 printf("Error parsing config file\n");
1344 handle_pxe_menu(cfg);
1346 destroy_pxe_menu(cfg);
1351 static cmd_tbl_t cmd_pxe_sub[] = {
1352 U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
1353 U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
1356 int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1361 return CMD_RET_USAGE;
1363 /* drop initial "pxe" arg */
1367 cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub));
1370 return cp->cmd(cmdtp, flag, argc, argv);
1372 return CMD_RET_USAGE;
1377 "commands to get and boot from pxe files",
1378 "get - try to retrieve a pxe file using tftp\npxe "
1379 "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"