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.
417 struct list_head list;
421 * Describes a pxe menu as given via pxe files.
423 * title - the name of the menu as given by a 'menu title' line.
424 * default_label - the name of the default label, if any.
425 * timeout - time in tenths of a second to wait for a user key-press before
426 * booting the default label.
427 * prompt - if 0, don't prompt for a choice unless the timeout period is
428 * interrupted. If 1, always prompt for a choice regardless of
430 * labels - a list of labels defined for the menu.
437 struct list_head labels;
441 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
442 * result must be free()'d to reclaim the memory.
444 * Returns NULL if malloc fails.
446 static struct pxe_label *label_create(void)
448 struct pxe_label *label;
450 label = malloc(sizeof(struct pxe_label));
455 memset(label, 0, sizeof(struct pxe_label));
461 * Free the memory used by a pxe_label, including that used by its name,
462 * kernel, append and initrd members, if they're non NULL.
464 * So - be sure to only use dynamically allocated memory for the members of
465 * the pxe_label struct, unless you want to clean it up first. These are
466 * currently only created by the pxe file parsing code.
468 static void label_destroy(struct pxe_label *label)
486 * Print a label and its string members if they're defined.
488 * This is passed as a callback to the menu code for displaying each
491 static void label_print(void *data)
493 struct pxe_label *label = data;
495 printf("Label: %s\n", label->name);
498 printf("\tkernel: %s\n", label->kernel);
501 printf("\tappend: %s\n", label->append);
504 printf("\tinitrd: %s\n", label->initrd);
508 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
509 * environment variable is defined. Its contents will be executed as U-boot
510 * command. If the label specified an 'append' line, its contents will be
511 * used to overwrite the contents of the 'bootargs' environment variable prior
512 * to running 'localcmd'.
514 * Returns 1 on success or < 0 on error.
516 static int label_localboot(struct pxe_label *label)
518 char *localcmd, *dupcmd;
521 localcmd = from_env("localcmd");
527 * dup the command to avoid any issues with the version of it existing
528 * in the environment changing during the execution of the command.
530 dupcmd = strdup(localcmd);
536 setenv("bootargs", label->append);
538 printf("running: %s\n", dupcmd);
540 ret = run_command(dupcmd, 0);
548 * Boot according to the contents of a pxe_label.
550 * If we can't boot for any reason, we return. A successful boot never
553 * The kernel will be stored in the location given by the 'kernel_addr_r'
554 * environment variable.
556 * If the label specifies an initrd file, it will be stored in the location
557 * given by the 'ramdisk_addr_r' environment variable.
559 * If the label specifies an 'append' line, its contents will overwrite that
560 * of the 'bootargs' environment variable.
562 static void label_boot(struct pxe_label *label)
564 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
569 label->attempted = 1;
571 if (label->localboot) {
572 label_localboot(label);
576 if (label->kernel == NULL) {
577 printf("No kernel given, skipping %s\n",
583 if (get_relfile_envaddr(label->initrd, "ramdisk_addr_r") < 0) {
584 printf("Skipping %s for failure retrieving initrd\n",
589 bootm_argv[2] = getenv("ramdisk_addr_r");
594 if (get_relfile_envaddr(label->kernel, "kernel_addr_r") < 0) {
595 printf("Skipping %s for failure retrieving kernel\n",
601 setenv("bootargs", label->append);
603 bootm_argv[1] = getenv("kernel_addr_r");
606 * fdt usage is optional. If there is an fdt_addr specified, we will
607 * pass it along to bootm, and adjust argc appropriately.
609 bootm_argv[3] = getenv("fdt_addr");
614 do_bootm(NULL, 0, bootm_argc, bootm_argv);
618 * Tokens for the pxe file parser.
639 * A token - given by a value and a type.
643 enum token_type type;
647 * Keywords recognized.
649 static const struct token keywords[] = {
652 {"timeout", T_TIMEOUT},
653 {"default", T_DEFAULT},
654 {"prompt", T_PROMPT},
656 {"kernel", T_KERNEL},
657 {"localboot", T_LOCALBOOT},
658 {"append", T_APPEND},
659 {"initrd", T_INITRD},
660 {"include", T_INCLUDE},
665 * Since pxe(linux) files don't have a token to identify the start of a
666 * literal, we have to keep track of when we're in a state where a literal is
667 * expected vs when we're in a state a keyword is expected.
676 * get_string retrieves a string from *p and stores it as a token in
679 * get_string used for scanning both string literals and keywords.
681 * Characters from *p are copied into t-val until a character equal to
682 * delim is found, or a NUL byte is reached. If delim has the special value of
683 * ' ', any whitespace character will be used as a delimiter.
685 * If lower is unequal to 0, uppercase characters will be converted to
686 * lowercase in the result. This is useful to make keywords case
689 * The location of *p is updated to point to the first character after the end
690 * of the token - the ending delimiter.
692 * On success, the new value of t->val is returned. Memory for t->val is
693 * allocated using malloc and must be free()'d to reclaim it. If insufficient
694 * memory is available, NULL is returned.
696 static char *get_string(char **p, struct token *t, char delim, int lower)
702 * b and e both start at the beginning of the input stream.
704 * e is incremented until we find the ending delimiter, or a NUL byte
705 * is reached. Then, we take e - b to find the length of the token.
710 if ((delim == ' ' && isspace(*e)) || delim == *e)
718 * Allocate memory to hold the string, and copy it in, converting
719 * characters to lowercase if lower is != 0.
721 t->val = malloc(len + 1);
725 for (i = 0; i < len; i++, b++) {
727 t->val[i] = tolower(*b);
735 * Update *p so the caller knows where to continue scanning.
745 * Populate a keyword token with a type and value.
747 static void get_keyword(struct token *t)
751 for (i = 0; keywords[i].val; i++) {
752 if (!strcmp(t->val, keywords[i].val)) {
753 t->type = keywords[i].type;
760 * Get the next token. We have to keep track of which state we're in to know
761 * if we're looking to get a string literal or a keyword.
763 * *p is updated to point at the first character after the current token.
765 static void get_token(char **p, struct token *t, enum lex_state state)
771 /* eat non EOL whitespace */
776 * eat comments. note that string literals can't begin with #, but
777 * can contain a # after their first character.
780 while (*c && *c != '\n')
787 } else if (*c == '\0') {
790 } else if (state == L_SLITERAL) {
791 get_string(&c, t, '\n', 0);
792 } else if (state == L_KEYWORD) {
794 * when we expect a keyword, we first get the next string
795 * token delimited by whitespace, and then check if it
796 * matches a keyword in our keyword list. if it does, it's
797 * converted to a keyword token of the appropriate type, and
798 * if not, it remains a string token.
800 get_string(&c, t, ' ', 1);
808 * Increment *c until we get to the end of the current line, or EOF.
810 static void eol_or_eof(char **c)
812 while (**c && **c != '\n')
817 * All of these parse_* functions share some common behavior.
819 * They finish with *c pointing after the token they parse, and return 1 on
820 * success, or < 0 on error.
824 * Parse a string literal and store a pointer it at *dst. String literals
825 * terminate at the end of the line.
827 static int parse_sliteral(char **c, char **dst)
832 get_token(c, &t, L_SLITERAL);
834 if (t.type != T_STRING) {
835 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
845 * Parse a base 10 (unsigned) integer and store it at *dst.
847 static int parse_integer(char **c, int *dst)
853 get_token(c, &t, L_SLITERAL);
855 if (t.type != T_STRING) {
856 printf("Expected string: %.*s\n", (int)(*c - s), s);
860 if (strict_strtoul(t.val, 10, &temp) < 0) {
861 printf("Expected unsigned integer: %s\n", t.val);
872 static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level);
875 * Parse an include statement, and retrieve and parse the file it mentions.
877 * base should point to a location where it's safe to store the file, and
878 * nest_level should indicate how many nested includes have occurred. For this
879 * include, nest_level has already been incremented and doesn't need to be
882 static int handle_include(char **c, char *base,
883 struct pxe_menu *cfg, int nest_level)
889 err = parse_sliteral(c, &include_path);
892 printf("Expected include path: %.*s\n",
897 err = get_pxe_file(include_path, base);
900 printf("Couldn't retrieve %s\n", include_path);
904 return parse_pxefile_top(base, cfg, nest_level);
908 * Parse lines that begin with 'menu'.
910 * b and nest are provided to handle the 'menu include' case.
912 * b should be the address where the file currently being parsed is stored.
914 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
915 * a file it includes, 3 when parsing a file included by that file, and so on.
917 static int parse_menu(char **c, struct pxe_menu *cfg, char *b, int nest_level)
923 get_token(c, &t, L_KEYWORD);
927 err = parse_sliteral(c, &cfg->title);
932 err = handle_include(c, b + strlen(b) + 1, cfg,
937 printf("Ignoring malformed menu command: %.*s\n",
950 * Handles parsing a 'menu line' when we're parsing a label.
952 static int parse_label_menu(char **c, struct pxe_menu *cfg,
953 struct pxe_label *label)
960 get_token(c, &t, L_KEYWORD);
964 if (cfg->default_label)
965 free(cfg->default_label);
967 cfg->default_label = strdup(label->name);
969 if (!cfg->default_label)
974 printf("Ignoring malformed menu command: %.*s\n",
984 * Parses a label and adds it to the list of labels for a menu.
986 * A label ends when we either get to the end of a file, or
987 * get some input we otherwise don't have a handler defined
991 static int parse_label(char **c, struct pxe_menu *cfg)
995 struct pxe_label *label;
998 label = label_create();
1002 err = parse_sliteral(c, &label->name);
1004 printf("Expected label name: %.*s\n", (int)(*c - s), s);
1005 label_destroy(label);
1009 list_add_tail(&label->list, &cfg->labels);
1013 get_token(c, &t, L_KEYWORD);
1018 err = parse_label_menu(c, cfg, label);
1022 err = parse_sliteral(c, &label->kernel);
1026 err = parse_sliteral(c, &label->append);
1030 err = parse_sliteral(c, &label->initrd);
1034 err = parse_integer(c, &label->localboot);
1042 * put the token back! we don't want it - it's the end
1043 * of a label and whatever token this is, it's
1044 * something for the menu level context to handle.
1056 * This 16 comes from the limit pxelinux imposes on nested includes.
1058 * There is no reason at all we couldn't do more, but some limit helps prevent
1059 * infinite (until crash occurs) recursion if a file tries to include itself.
1061 #define MAX_NEST_LEVEL 16
1064 * Entry point for parsing a menu file. nest_level indicates how many times
1065 * we've nested in includes. It will be 1 for the top level menu file.
1067 * Returns 1 on success, < 0 on error.
1069 static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level)
1072 char *s, *b, *label_name;
1077 if (nest_level > MAX_NEST_LEVEL) {
1078 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1085 get_token(&p, &t, L_KEYWORD);
1090 err = parse_menu(&p, cfg, b, nest_level);
1094 err = parse_integer(&p, &cfg->timeout);
1098 err = parse_label(&p, cfg);
1102 err = parse_sliteral(&p, &label_name);
1105 if (cfg->default_label)
1106 free(cfg->default_label);
1108 cfg->default_label = label_name;
1114 err = parse_integer(&p, &cfg->prompt);
1124 printf("Ignoring unknown command: %.*s\n",
1135 * Free the memory used by a pxe_menu and its labels.
1137 static void destroy_pxe_menu(struct pxe_menu *cfg)
1139 struct list_head *pos, *n;
1140 struct pxe_label *label;
1145 if (cfg->default_label)
1146 free(cfg->default_label);
1148 list_for_each_safe(pos, n, &cfg->labels) {
1149 label = list_entry(pos, struct pxe_label, list);
1151 label_destroy(label);
1158 * Entry point for parsing a pxe file. This is only used for the top level
1161 * Returns NULL if there is an error, otherwise, returns a pointer to a
1162 * pxe_menu struct populated with the results of parsing the pxe file (and any
1163 * files it includes). The resulting pxe_menu struct can be free()'d by using
1164 * the destroy_pxe_menu() function.
1166 static struct pxe_menu *parse_pxefile(char *menucfg)
1168 struct pxe_menu *cfg;
1170 cfg = malloc(sizeof(struct pxe_menu));
1175 memset(cfg, 0, sizeof(struct pxe_menu));
1177 INIT_LIST_HEAD(&cfg->labels);
1179 if (parse_pxefile_top(menucfg, cfg, 1) < 0) {
1180 destroy_pxe_menu(cfg);
1188 * Converts a pxe_menu struct into a menu struct for use with U-boot's generic
1191 static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1193 struct pxe_label *label;
1194 struct list_head *pos;
1199 * Create a menu and add items for all the labels.
1201 m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print);
1206 list_for_each(pos, &cfg->labels) {
1207 label = list_entry(pos, struct pxe_label, list);
1209 if (menu_item_add(m, label->name, label) != 1) {
1216 * After we've created items for each label in the menu, set the
1217 * menu's default label if one was specified.
1219 if (cfg->default_label) {
1220 err = menu_default_set(m, cfg->default_label);
1222 if (err != -ENOENT) {
1227 printf("Missing default: %s\n", cfg->default_label);
1235 * Try to boot any labels we have yet to attempt to boot.
1237 static void boot_unattempted_labels(struct pxe_menu *cfg)
1239 struct list_head *pos;
1240 struct pxe_label *label;
1242 list_for_each(pos, &cfg->labels) {
1243 label = list_entry(pos, struct pxe_label, list);
1245 if (!label->attempted)
1251 * Boot the system as prescribed by a pxe_menu.
1253 * Use the menu system to either get the user's choice or the default, based
1254 * on config or user input. If there is no default or user's choice,
1255 * attempted to boot labels in the order they were given in pxe files.
1256 * If the default or user's choice fails to boot, attempt to boot other
1257 * labels in the order they were given in pxe files.
1259 * If this function returns, there weren't any labels that successfully
1260 * booted, or the user interrupted the menu selection via ctrl+c.
1262 static void handle_pxe_menu(struct pxe_menu *cfg)
1268 m = pxe_menu_to_menu(cfg);
1272 err = menu_get_choice(m, &choice);
1277 * err == 1 means we got a choice back from menu_get_choice.
1279 * err == -ENOENT if the menu was setup to select the default but no
1280 * default was set. in that case, we should continue trying to boot
1281 * labels that haven't been attempted yet.
1283 * otherwise, the user interrupted or there was some other error and
1289 else if (err != -ENOENT)
1292 boot_unattempted_labels(cfg);
1296 * Boots a system using a pxe file
1298 * Returns 0 on success, 1 on error.
1301 do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1303 unsigned long pxefile_addr_r;
1304 struct pxe_menu *cfg;
1305 char *pxefile_addr_str;
1308 pxefile_addr_str = from_env("pxefile_addr_r");
1309 if (!pxefile_addr_str)
1312 } else if (argc == 2) {
1313 pxefile_addr_str = argv[1];
1315 return CMD_RET_USAGE;
1318 if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
1319 printf("Invalid pxefile address: %s\n", pxefile_addr_str);
1323 cfg = parse_pxefile((char *)(pxefile_addr_r));
1326 printf("Error parsing config file\n");
1330 handle_pxe_menu(cfg);
1332 destroy_pxe_menu(cfg);
1337 static cmd_tbl_t cmd_pxe_sub[] = {
1338 U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
1339 U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
1342 int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1347 return CMD_RET_USAGE;
1349 /* drop initial "pxe" arg */
1353 cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub));
1356 return cp->cmd(cmdtp, flag, argc, argv);
1358 return CMD_RET_USAGE;
1363 "commands to get and boot from pxe files",
1364 "get - try to retrieve a pxe file using tftp\npxe "
1365 "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"