blob: de47e9a67fec483def8e6fb9697ded59d4bfd902 [file] [log] [blame]
Jason Hobbs06283a62011-08-31 10:37:30 -05001/*
2 * Copyright 2010-2011 Calxeda, Inc.
3 *
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)
7 * any later version.
8 *
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
12 * more details.
13 *
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/>.
16 */
17#include <common.h>
18#include <command.h>
19#include <malloc.h>
20#include <linux/string.h>
21#include <linux/ctype.h>
22#include <errno.h>
23#include <linux/list.h>
24
25#include "menu.h"
Justin L Wernerdc80e002012-08-09 14:20:30 -060026#if defined(CONFIG_BOOTP_VENDOREX) && defined(CONFIG_BOOTP_VENDOREX_PXE_SHARED)
27#include "../net/magic.h"
28#endif
Jason Hobbs06283a62011-08-31 10:37:30 -050029
30#define MAX_TFTP_PATH_LEN 127
31
32
33/*
34 * Like getenv, but prints an error if envvar isn't defined in the
35 * environment. It always returns what getenv does, so it can be used in
36 * place of getenv without changing error handling otherwise.
37 */
38static char *from_env(char *envvar)
39{
40 char *ret;
41
42 ret = getenv(envvar);
43
44 if (!ret)
45 printf("missing environment variable: %s\n", envvar);
46
47 return ret;
48}
49
50/*
51 * Convert an ethaddr from the environment to the format used by pxelinux
52 * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
53 * the beginning of the ethernet address to indicate a hardware type of
54 * Ethernet. Also converts uppercase hex characters into lowercase, to match
55 * pxelinux's behavior.
56 *
57 * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
58 * environment, or some other value < 0 on error.
59 */
60static int format_mac_pxe(char *outbuf, size_t outbuf_len)
61{
62 size_t ethaddr_len;
63 char *p, *ethaddr;
64
65 ethaddr = from_env("ethaddr");
66
67 if (!ethaddr)
John Rigbybe99b9e2011-07-13 23:05:19 -060068 ethaddr = from_env("usbethaddr");
69
70 if (!ethaddr)
Jason Hobbs06283a62011-08-31 10:37:30 -050071 return -ENOENT;
72
73 ethaddr_len = strlen(ethaddr);
74
75 /*
76 * ethaddr_len + 4 gives room for "01-", ethaddr, and a NUL byte at
77 * the end.
78 */
79 if (outbuf_len < ethaddr_len + 4) {
80 printf("outbuf is too small (%d < %d)\n",
81 outbuf_len, ethaddr_len + 4);
82
83 return -EINVAL;
84 }
85
86 strcpy(outbuf, "01-");
87
88 for (p = outbuf + 3; *ethaddr; ethaddr++, p++) {
89 if (*ethaddr == ':')
90 *p = '-';
91 else
92 *p = tolower(*ethaddr);
93 }
94
95 *p = '\0';
96
97 return 1;
98}
99
Justin L Wernerdc80e002012-08-09 14:20:30 -0600100#if defined(CONFIG_BOOTP_VENDOREX) && defined(CONFIG_BOOTP_VENDOREX_PXE_SHARED)
101/*
102 * Returns the directory the file specified in the bootfile env variable is
103 * in, unless DHCP MAGIC was received and we have a PathPrefix value, in which
104 * case the bootenv (if it was specified) is overridden. If bootfile
105 * isn't defined in the environment or obtained from PathPrefix DHCP
106 * vendor extension, return NULL, which should be interpreted as
107 * "don't prepend anything to paths".
108 */
109#else
Jason Hobbs06283a62011-08-31 10:37:30 -0500110/*
111 * Returns the directory the file specified in the bootfile env variable is
112 * in. If bootfile isn't defined in the environment, return NULL, which should
113 * be interpreted as "don't prepend anything to paths".
114 */
Justin L Wernerdc80e002012-08-09 14:20:30 -0600115#endif
Rob Herringae97aaf2012-03-28 05:51:36 +0000116static int get_bootfile_path(const char *file_path, char *bootfile_path,
117 size_t bootfile_path_size)
Jason Hobbs06283a62011-08-31 10:37:30 -0500118{
119 char *bootfile, *last_slash;
Rob Herringae97aaf2012-03-28 05:51:36 +0000120 size_t path_len = 0;
Justin L Wernerdc80e002012-08-09 14:20:30 -0600121#if defined(CONFIG_BOOTP_VENDOREX) && defined(CONFIG_BOOTP_VENDOREX_PXE_SHARED)
122 char *path_prefix = getenv(PXE_PATH_PREFIX);
123
124 /* Override the initial environment */
125 if (path_prefix) {
126 setenv("bootfile", path_prefix);
127 }
128#endif
129
130 bootfile = from_env("bootfile");
Rob Herringae97aaf2012-03-28 05:51:36 +0000131
132 if (file_path[0] == '/')
133 goto ret;
Jason Hobbs06283a62011-08-31 10:37:30 -0500134
135 bootfile = from_env("bootfile");
Rob Herringae97aaf2012-03-28 05:51:36 +0000136 if (!bootfile)
137 goto ret;
Jason Hobbs06283a62011-08-31 10:37:30 -0500138
139 last_slash = strrchr(bootfile, '/');
140
Rob Herringae97aaf2012-03-28 05:51:36 +0000141 if (last_slash == NULL)
142 goto ret;
Jason Hobbs06283a62011-08-31 10:37:30 -0500143
144 path_len = (last_slash - bootfile) + 1;
145
146 if (bootfile_path_size < path_len) {
147 printf("bootfile_path too small. (%d < %d)\n",
148 bootfile_path_size, path_len);
149
150 return -1;
151 }
152
153 strncpy(bootfile_path, bootfile, path_len);
154
Rob Herringae97aaf2012-03-28 05:51:36 +0000155 ret:
Jason Hobbs06283a62011-08-31 10:37:30 -0500156 bootfile_path[path_len] = '\0';
157
158 return 1;
159}
160
Rob Herringcfb48a32012-05-25 10:47:39 +0000161static int (*do_getfile)(char *file_path, char *file_addr);
162
163static int do_get_tftp(char *file_path, char *file_addr)
164{
165 char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
166
167 tftp_argv[1] = file_addr;
168 tftp_argv[2] = file_path;
169
170 if (do_tftpb(NULL, 0, 3, tftp_argv))
171 return -ENOENT;
172
173 return 1;
174}
175
176static char *fs_argv[5];
177
178static int do_get_ext2(char *file_path, char *file_addr)
179{
180#ifdef CONFIG_CMD_EXT2
181 fs_argv[0] = "ext2load";
182 fs_argv[3] = file_addr;
183 fs_argv[4] = file_path;
184
185 if (!do_ext2load(NULL, 0, 5, fs_argv))
186 return 1;
187#endif
188 return -ENOENT;
189}
190
191static int do_get_fat(char *file_path, char *file_addr)
192{
193#ifdef CONFIG_CMD_FAT
194 fs_argv[0] = "fatload";
195 fs_argv[3] = file_addr;
196 fs_argv[4] = file_path;
197
198 if (!do_fat_fsload(NULL, 0, 5, fs_argv))
199 return 1;
200#endif
201 return -ENOENT;
202}
203
204
205
Jason Hobbs06283a62011-08-31 10:37:30 -0500206/*
207 * As in pxelinux, paths to files referenced from files we retrieve are
208 * relative to the location of bootfile. get_relfile takes such a path and
209 * joins it with the bootfile path to get the full path to the target file. If
210 * the bootfile path is NULL, we use file_path as is.
211 *
212 * Returns 1 for success, or < 0 on error.
213 */
214static int get_relfile(char *file_path, void *file_addr)
215{
216 size_t path_len;
217 char relfile[MAX_TFTP_PATH_LEN+1];
218 char addr_buf[10];
Jason Hobbs06283a62011-08-31 10:37:30 -0500219 int err;
220
Rob Herringae97aaf2012-03-28 05:51:36 +0000221 err = get_bootfile_path(file_path, relfile, sizeof(relfile));
Jason Hobbs06283a62011-08-31 10:37:30 -0500222
223 if (err < 0)
224 return err;
225
226 path_len = strlen(file_path);
227 path_len += strlen(relfile);
228
229 if (path_len > MAX_TFTP_PATH_LEN) {
230 printf("Base path too long (%s%s)\n",
231 relfile,
232 file_path);
233
234 return -ENAMETOOLONG;
235 }
236
237 strcat(relfile, file_path);
238
239 printf("Retrieving file: %s\n", relfile);
240
241 sprintf(addr_buf, "%p", file_addr);
242
Rob Herringcfb48a32012-05-25 10:47:39 +0000243 return do_getfile(relfile, addr_buf);
Jason Hobbs06283a62011-08-31 10:37:30 -0500244}
245
246/*
247 * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
248 * 'bootfile' was specified in the environment, the path to bootfile will be
249 * prepended to 'file_path' and the resulting path will be used.
250 *
251 * Returns 1 on success, or < 0 for error.
252 */
253static int get_pxe_file(char *file_path, void *file_addr)
254{
255 unsigned long config_file_size;
256 char *tftp_filesize;
257 int err;
258
259 err = get_relfile(file_path, file_addr);
260
261 if (err < 0)
262 return err;
263
264 /*
265 * the file comes without a NUL byte at the end, so find out its size
266 * and add the NUL byte.
267 */
268 tftp_filesize = from_env("filesize");
269
270 if (!tftp_filesize)
271 return -ENOENT;
272
273 if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
274 return -EINVAL;
275
276 *(char *)(file_addr + config_file_size) = '\0';
277
278 return 1;
279}
280
281#define PXELINUX_DIR "pxelinux.cfg/"
282
283/*
284 * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
285 * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
286 * from the bootfile path, as described above.
287 *
288 * Returns 1 on success or < 0 on error.
289 */
290static int get_pxelinux_path(char *file, void *pxefile_addr_r)
291{
292 size_t base_len = strlen(PXELINUX_DIR);
293 char path[MAX_TFTP_PATH_LEN+1];
294
295 if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
296 printf("path (%s%s) too long, skipping\n",
297 PXELINUX_DIR, file);
298 return -ENAMETOOLONG;
299 }
300
301 sprintf(path, PXELINUX_DIR "%s", file);
302
303 return get_pxe_file(path, pxefile_addr_r);
304}
305
Justin L Wernerdc80e002012-08-09 14:20:30 -0600306#if defined(CONFIG_BOOTP_VENDOREX) && defined(CONFIG_BOOTP_VENDOREX_PXE_SHARED)
307/*
308 * Attempt to load a config file obtained from DHCP vendor extension option
309 *
310 * Returns 1 on success or < 0 on error.
311 */
312static int pxe_dhcp_config_path(void *pxefile_addr_r)
313{
314 char *name = getenv(PXE_CONFIG_FILE);
315 int retval = -ENOENT;
316
317 if (name && *name) {
318 retval = get_pxelinux_path(name, pxefile_addr_r);
319 }
320
321 return retval;
322}
323#endif
324
Jason Hobbs06283a62011-08-31 10:37:30 -0500325/*
326 * Looks for a pxe file with a name based on the pxeuuid environment variable.
327 *
328 * Returns 1 on success or < 0 on error.
329 */
330static int pxe_uuid_path(void *pxefile_addr_r)
331{
332 char *uuid_str;
333
334 uuid_str = from_env("pxeuuid");
335
336 if (!uuid_str)
337 return -ENOENT;
338
339 return get_pxelinux_path(uuid_str, pxefile_addr_r);
340}
341
342/*
343 * Looks for a pxe file with a name based on the 'ethaddr' environment
344 * variable.
345 *
346 * Returns 1 on success or < 0 on error.
347 */
348static int pxe_mac_path(void *pxefile_addr_r)
349{
350 char mac_str[21];
351 int err;
352
353 err = format_mac_pxe(mac_str, sizeof(mac_str));
354
355 if (err < 0)
356 return err;
357
358 return get_pxelinux_path(mac_str, pxefile_addr_r);
359}
360
361/*
362 * Looks for pxe files with names based on our IP address. See pxelinux
363 * documentation for details on what these file names look like. We match
364 * that exactly.
365 *
366 * Returns 1 on success or < 0 on error.
367 */
368static int pxe_ipaddr_paths(void *pxefile_addr_r)
369{
370 char ip_addr[9];
371 int mask_pos, err;
372
373 sprintf(ip_addr, "%08X", ntohl(NetOurIP));
374
375 for (mask_pos = 7; mask_pos >= 0; mask_pos--) {
376 err = get_pxelinux_path(ip_addr, pxefile_addr_r);
377
378 if (err > 0)
379 return err;
380
381 ip_addr[mask_pos] = '\0';
382 }
383
384 return -ENOENT;
385}
386
387/*
388 * Entry point for the 'pxe get' command.
389 * This Follows pxelinux's rules to download a config file from a tftp server.
390 * The file is stored at the location given by the pxefile_addr_r environment
391 * variable, which must be set.
392 *
393 * UUID comes from pxeuuid env variable, if defined
394 * MAC addr comes from ethaddr env variable, if defined
395 * IP
396 *
397 * see http://syslinux.zytor.com/wiki/index.php/PXELINUX
398 *
399 * Returns 0 on success or 1 on error.
400 */
401static int
402do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
403{
404 char *pxefile_addr_str;
Jason Hobbs834c9382012-03-05 08:12:28 +0000405 unsigned long pxefile_addr_r;
Jason Hobbs06283a62011-08-31 10:37:30 -0500406 int err;
407
Rob Herringcfb48a32012-05-25 10:47:39 +0000408 do_getfile = do_get_tftp;
409
Jason Hobbs06283a62011-08-31 10:37:30 -0500410 if (argc != 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000411 return CMD_RET_USAGE;
Jason Hobbs06283a62011-08-31 10:37:30 -0500412
413
414 pxefile_addr_str = from_env("pxefile_addr_r");
415
416 if (!pxefile_addr_str)
417 return 1;
418
419 err = strict_strtoul(pxefile_addr_str, 16,
420 (unsigned long *)&pxefile_addr_r);
421 if (err < 0)
422 return 1;
423
424 /*
425 * Keep trying paths until we successfully get a file we're looking
426 * for.
427 */
Justin L Wernerdc80e002012-08-09 14:20:30 -0600428#if defined(CONFIG_BOOTP_VENDOREX) && defined(CONFIG_BOOTP_VENDOREX_PXE_SHARED)
429 if (pxe_dhcp_config_path(pxefile_addr_r) > 0
430 || pxe_uuid_path(pxefile_addr_r) > 0
431#else
432 if (pxe_uuid_path(pxefile_addr_r) > 0
433#endif
Jason Hobbs834c9382012-03-05 08:12:28 +0000434 || pxe_mac_path((void *)pxefile_addr_r) > 0
435 || pxe_ipaddr_paths((void *)pxefile_addr_r) > 0
436 || get_pxelinux_path("default", (void *)pxefile_addr_r) > 0) {
Jason Hobbs06283a62011-08-31 10:37:30 -0500437
438 printf("Config file found\n");
439
440 return 0;
441 }
442
443 printf("Config file not found\n");
444
445 return 1;
446}
447
448/*
449 * Wrapper to make it easier to store the file at file_path in the location
450 * specified by envaddr_name. file_path will be joined to the bootfile path,
451 * if any is specified.
452 *
453 * Returns 1 on success or < 0 on error.
454 */
455static int get_relfile_envaddr(char *file_path, char *envaddr_name)
456{
Jason Hobbs834c9382012-03-05 08:12:28 +0000457 unsigned long file_addr;
Jason Hobbs06283a62011-08-31 10:37:30 -0500458 char *envaddr;
459
460 envaddr = from_env(envaddr_name);
461
462 if (!envaddr)
463 return -ENOENT;
464
Jason Hobbs834c9382012-03-05 08:12:28 +0000465 if (strict_strtoul(envaddr, 16, &file_addr) < 0)
Jason Hobbs06283a62011-08-31 10:37:30 -0500466 return -EINVAL;
467
Jason Hobbs834c9382012-03-05 08:12:28 +0000468 return get_relfile(file_path, (void *)file_addr);
Jason Hobbs06283a62011-08-31 10:37:30 -0500469}
470
471/*
472 * A note on the pxe file parser.
473 *
474 * We're parsing files that use syslinux grammar, which has a few quirks.
475 * String literals must be recognized based on context - there is no
476 * quoting or escaping support. There's also nothing to explicitly indicate
477 * when a label section completes. We deal with that by ending a label
478 * section whenever we see a line that doesn't include.
479 *
480 * As with the syslinux family, this same file format could be reused in the
481 * future for non pxe purposes. The only action it takes during parsing that
482 * would throw this off is handling of include files. It assumes we're using
483 * pxe, and does a tftp download of a file listed as an include file in the
484 * middle of the parsing operation. That could be handled by refactoring it to
485 * take a 'include file getter' function.
486 */
487
488/*
489 * Describes a single label given in a pxe file.
490 *
491 * Create these with the 'label_create' function given below.
492 *
493 * name - the name of the menu as given on the 'menu label' line.
494 * kernel - the path to the kernel file to use for this label.
495 * append - kernel command line to use when booting this label
496 * initrd - path to the initrd to use for this label.
497 * attempted - 0 if we haven't tried to boot this label, 1 if we have.
498 * localboot - 1 if this label specified 'localboot', 0 otherwise.
499 * list - lets these form a list, which a pxe_menu struct will hold.
500 */
501struct pxe_label {
502 char *name;
Rob Herringe539d112012-03-28 05:51:34 +0000503 char *menu;
Jason Hobbs06283a62011-08-31 10:37:30 -0500504 char *kernel;
505 char *append;
506 char *initrd;
507 int attempted;
508 int localboot;
509 struct list_head list;
510};
511
512/*
513 * Describes a pxe menu as given via pxe files.
514 *
515 * title - the name of the menu as given by a 'menu title' line.
516 * default_label - the name of the default label, if any.
517 * timeout - time in tenths of a second to wait for a user key-press before
518 * booting the default label.
519 * prompt - if 0, don't prompt for a choice unless the timeout period is
520 * interrupted. If 1, always prompt for a choice regardless of
521 * timeout.
522 * labels - a list of labels defined for the menu.
523 */
524struct pxe_menu {
525 char *title;
526 char *default_label;
527 int timeout;
528 int prompt;
529 struct list_head labels;
530};
531
532/*
533 * Allocates memory for and initializes a pxe_label. This uses malloc, so the
534 * result must be free()'d to reclaim the memory.
535 *
536 * Returns NULL if malloc fails.
537 */
538static struct pxe_label *label_create(void)
539{
540 struct pxe_label *label;
541
542 label = malloc(sizeof(struct pxe_label));
543
544 if (!label)
545 return NULL;
546
547 memset(label, 0, sizeof(struct pxe_label));
548
549 return label;
550}
551
552/*
553 * Free the memory used by a pxe_label, including that used by its name,
554 * kernel, append and initrd members, if they're non NULL.
555 *
556 * So - be sure to only use dynamically allocated memory for the members of
557 * the pxe_label struct, unless you want to clean it up first. These are
558 * currently only created by the pxe file parsing code.
559 */
560static void label_destroy(struct pxe_label *label)
561{
562 if (label->name)
563 free(label->name);
564
565 if (label->kernel)
566 free(label->kernel);
567
568 if (label->append)
569 free(label->append);
570
571 if (label->initrd)
572 free(label->initrd);
573
574 free(label);
575}
576
577/*
578 * Print a label and its string members if they're defined.
579 *
580 * This is passed as a callback to the menu code for displaying each
581 * menu entry.
582 */
583static void label_print(void *data)
584{
585 struct pxe_label *label = data;
Rob Herringe539d112012-03-28 05:51:34 +0000586 const char *c = label->menu ? label->menu : label->kernel;
Jason Hobbs06283a62011-08-31 10:37:30 -0500587
Rob Herringe539d112012-03-28 05:51:34 +0000588 printf("%s:\t%s\n", label->name, c);
Jason Hobbs06283a62011-08-31 10:37:30 -0500589
590 if (label->kernel)
Rob Herringe539d112012-03-28 05:51:34 +0000591 printf("\t\tkernel: %s\n", label->kernel);
Jason Hobbs06283a62011-08-31 10:37:30 -0500592
593 if (label->append)
Rob Herringe539d112012-03-28 05:51:34 +0000594 printf("\t\tappend: %s\n", label->append);
Jason Hobbs06283a62011-08-31 10:37:30 -0500595
596 if (label->initrd)
Rob Herringe539d112012-03-28 05:51:34 +0000597 printf("\t\tinitrd: %s\n", label->initrd);
Jason Hobbs06283a62011-08-31 10:37:30 -0500598}
599
600/*
601 * Boot a label that specified 'localboot'. This requires that the 'localcmd'
602 * environment variable is defined. Its contents will be executed as U-boot
603 * command. If the label specified an 'append' line, its contents will be
604 * used to overwrite the contents of the 'bootargs' environment variable prior
605 * to running 'localcmd'.
606 *
607 * Returns 1 on success or < 0 on error.
608 */
609static int label_localboot(struct pxe_label *label)
610{
611 char *localcmd, *dupcmd;
612 int ret;
613
614 localcmd = from_env("localcmd");
615
616 if (!localcmd)
617 return -ENOENT;
618
619 /*
620 * dup the command to avoid any issues with the version of it existing
621 * in the environment changing during the execution of the command.
622 */
623 dupcmd = strdup(localcmd);
624
625 if (!dupcmd)
626 return -ENOMEM;
627
628 if (label->append)
629 setenv("bootargs", label->append);
630
631 printf("running: %s\n", dupcmd);
632
Simon Glass009dde12012-02-14 19:59:20 +0000633 ret = run_command(dupcmd, 0);
Jason Hobbs06283a62011-08-31 10:37:30 -0500634
635 free(dupcmd);
636
637 return ret;
638}
639
640/*
641 * Boot according to the contents of a pxe_label.
642 *
643 * If we can't boot for any reason, we return. A successful boot never
644 * returns.
645 *
646 * The kernel will be stored in the location given by the 'kernel_addr_r'
647 * environment variable.
648 *
649 * If the label specifies an initrd file, it will be stored in the location
650 * given by the 'ramdisk_addr_r' environment variable.
651 *
652 * If the label specifies an 'append' line, its contents will overwrite that
653 * of the 'bootargs' environment variable.
654 */
655static void label_boot(struct pxe_label *label)
656{
657 char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
658 int bootm_argc = 3;
659
660 label_print(label);
661
662 label->attempted = 1;
663
664 if (label->localboot) {
665 label_localboot(label);
666 return;
667 }
668
669 if (label->kernel == NULL) {
670 printf("No kernel given, skipping %s\n",
671 label->name);
672 return;
673 }
674
675 if (label->initrd) {
676 if (get_relfile_envaddr(label->initrd, "ramdisk_addr_r") < 0) {
677 printf("Skipping %s for failure retrieving initrd\n",
678 label->name);
679 return;
680 }
681
682 bootm_argv[2] = getenv("ramdisk_addr_r");
683 } else {
684 bootm_argv[2] = "-";
685 }
686
687 if (get_relfile_envaddr(label->kernel, "kernel_addr_r") < 0) {
688 printf("Skipping %s for failure retrieving kernel\n",
689 label->name);
690 return;
691 }
692
693 if (label->append)
694 setenv("bootargs", label->append);
695
696 bootm_argv[1] = getenv("kernel_addr_r");
697
698 /*
699 * fdt usage is optional. If there is an fdt_addr specified, we will
700 * pass it along to bootm, and adjust argc appropriately.
701 */
702 bootm_argv[3] = getenv("fdt_addr");
703
704 if (bootm_argv[3])
705 bootm_argc = 4;
706
707 do_bootm(NULL, 0, bootm_argc, bootm_argv);
708}
709
710/*
711 * Tokens for the pxe file parser.
712 */
713enum token_type {
714 T_EOL,
715 T_STRING,
716 T_EOF,
717 T_MENU,
718 T_TITLE,
719 T_TIMEOUT,
720 T_LABEL,
721 T_KERNEL,
Rob Herringa0854ad2012-03-28 05:51:35 +0000722 T_LINUX,
Jason Hobbs06283a62011-08-31 10:37:30 -0500723 T_APPEND,
724 T_INITRD,
725 T_LOCALBOOT,
726 T_DEFAULT,
727 T_PROMPT,
728 T_INCLUDE,
729 T_INVALID
730};
731
732/*
733 * A token - given by a value and a type.
734 */
735struct token {
736 char *val;
737 enum token_type type;
738};
739
740/*
741 * Keywords recognized.
742 */
743static const struct token keywords[] = {
744 {"menu", T_MENU},
745 {"title", T_TITLE},
746 {"timeout", T_TIMEOUT},
747 {"default", T_DEFAULT},
748 {"prompt", T_PROMPT},
749 {"label", T_LABEL},
750 {"kernel", T_KERNEL},
Rob Herringa0854ad2012-03-28 05:51:35 +0000751 {"linux", T_LINUX},
Jason Hobbs06283a62011-08-31 10:37:30 -0500752 {"localboot", T_LOCALBOOT},
753 {"append", T_APPEND},
754 {"initrd", T_INITRD},
755 {"include", T_INCLUDE},
756 {NULL, T_INVALID}
757};
758
759/*
760 * Since pxe(linux) files don't have a token to identify the start of a
761 * literal, we have to keep track of when we're in a state where a literal is
762 * expected vs when we're in a state a keyword is expected.
763 */
764enum lex_state {
765 L_NORMAL = 0,
766 L_KEYWORD,
767 L_SLITERAL
768};
769
770/*
771 * get_string retrieves a string from *p and stores it as a token in
772 * *t.
773 *
774 * get_string used for scanning both string literals and keywords.
775 *
776 * Characters from *p are copied into t-val until a character equal to
777 * delim is found, or a NUL byte is reached. If delim has the special value of
778 * ' ', any whitespace character will be used as a delimiter.
779 *
780 * If lower is unequal to 0, uppercase characters will be converted to
781 * lowercase in the result. This is useful to make keywords case
782 * insensitive.
783 *
784 * The location of *p is updated to point to the first character after the end
785 * of the token - the ending delimiter.
786 *
787 * On success, the new value of t->val is returned. Memory for t->val is
788 * allocated using malloc and must be free()'d to reclaim it. If insufficient
789 * memory is available, NULL is returned.
790 */
791static char *get_string(char **p, struct token *t, char delim, int lower)
792{
793 char *b, *e;
794 size_t len, i;
795
796 /*
797 * b and e both start at the beginning of the input stream.
798 *
799 * e is incremented until we find the ending delimiter, or a NUL byte
800 * is reached. Then, we take e - b to find the length of the token.
801 */
802 b = e = *p;
803
804 while (*e) {
805 if ((delim == ' ' && isspace(*e)) || delim == *e)
806 break;
807 e++;
808 }
809
810 len = e - b;
811
812 /*
813 * Allocate memory to hold the string, and copy it in, converting
814 * characters to lowercase if lower is != 0.
815 */
816 t->val = malloc(len + 1);
817 if (!t->val)
818 return NULL;
819
820 for (i = 0; i < len; i++, b++) {
821 if (lower)
822 t->val[i] = tolower(*b);
823 else
824 t->val[i] = *b;
825 }
826
827 t->val[len] = '\0';
828
829 /*
830 * Update *p so the caller knows where to continue scanning.
831 */
832 *p = e;
833
834 t->type = T_STRING;
835
836 return t->val;
837}
838
839/*
840 * Populate a keyword token with a type and value.
841 */
842static void get_keyword(struct token *t)
843{
844 int i;
845
846 for (i = 0; keywords[i].val; i++) {
847 if (!strcmp(t->val, keywords[i].val)) {
848 t->type = keywords[i].type;
849 break;
850 }
851 }
852}
853
854/*
855 * Get the next token. We have to keep track of which state we're in to know
856 * if we're looking to get a string literal or a keyword.
857 *
858 * *p is updated to point at the first character after the current token.
859 */
860static void get_token(char **p, struct token *t, enum lex_state state)
861{
862 char *c = *p;
863
864 t->type = T_INVALID;
865
866 /* eat non EOL whitespace */
867 while (isblank(*c))
868 c++;
869
870 /*
871 * eat comments. note that string literals can't begin with #, but
872 * can contain a # after their first character.
873 */
874 if (*c == '#') {
875 while (*c && *c != '\n')
876 c++;
877 }
878
879 if (*c == '\n') {
880 t->type = T_EOL;
881 c++;
882 } else if (*c == '\0') {
883 t->type = T_EOF;
884 c++;
885 } else if (state == L_SLITERAL) {
886 get_string(&c, t, '\n', 0);
887 } else if (state == L_KEYWORD) {
888 /*
889 * when we expect a keyword, we first get the next string
890 * token delimited by whitespace, and then check if it
891 * matches a keyword in our keyword list. if it does, it's
892 * converted to a keyword token of the appropriate type, and
893 * if not, it remains a string token.
894 */
895 get_string(&c, t, ' ', 1);
896 get_keyword(t);
897 }
898
899 *p = c;
900}
901
902/*
903 * Increment *c until we get to the end of the current line, or EOF.
904 */
905static void eol_or_eof(char **c)
906{
907 while (**c && **c != '\n')
908 (*c)++;
909}
910
911/*
912 * All of these parse_* functions share some common behavior.
913 *
914 * They finish with *c pointing after the token they parse, and return 1 on
915 * success, or < 0 on error.
916 */
917
918/*
919 * Parse a string literal and store a pointer it at *dst. String literals
920 * terminate at the end of the line.
921 */
922static int parse_sliteral(char **c, char **dst)
923{
924 struct token t;
925 char *s = *c;
926
927 get_token(c, &t, L_SLITERAL);
928
929 if (t.type != T_STRING) {
930 printf("Expected string literal: %.*s\n", (int)(*c - s), s);
931 return -EINVAL;
932 }
933
934 *dst = t.val;
935
936 return 1;
937}
938
939/*
940 * Parse a base 10 (unsigned) integer and store it at *dst.
941 */
942static int parse_integer(char **c, int *dst)
943{
944 struct token t;
945 char *s = *c;
946 unsigned long temp;
947
948 get_token(c, &t, L_SLITERAL);
949
950 if (t.type != T_STRING) {
951 printf("Expected string: %.*s\n", (int)(*c - s), s);
952 return -EINVAL;
953 }
954
955 if (strict_strtoul(t.val, 10, &temp) < 0) {
956 printf("Expected unsigned integer: %s\n", t.val);
957 return -EINVAL;
958 }
959
960 *dst = (int)temp;
961
962 free(t.val);
963
964 return 1;
965}
966
967static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level);
968
969/*
970 * Parse an include statement, and retrieve and parse the file it mentions.
971 *
972 * base should point to a location where it's safe to store the file, and
973 * nest_level should indicate how many nested includes have occurred. For this
974 * include, nest_level has already been incremented and doesn't need to be
975 * incremented here.
976 */
977static int handle_include(char **c, char *base,
978 struct pxe_menu *cfg, int nest_level)
979{
980 char *include_path;
981 char *s = *c;
982 int err;
983
984 err = parse_sliteral(c, &include_path);
985
986 if (err < 0) {
987 printf("Expected include path: %.*s\n",
988 (int)(*c - s), s);
989 return err;
990 }
991
992 err = get_pxe_file(include_path, base);
993
994 if (err < 0) {
995 printf("Couldn't retrieve %s\n", include_path);
996 return err;
997 }
998
999 return parse_pxefile_top(base, cfg, nest_level);
1000}
1001
1002/*
1003 * Parse lines that begin with 'menu'.
1004 *
1005 * b and nest are provided to handle the 'menu include' case.
1006 *
1007 * b should be the address where the file currently being parsed is stored.
1008 *
1009 * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
1010 * a file it includes, 3 when parsing a file included by that file, and so on.
1011 */
1012static int parse_menu(char **c, struct pxe_menu *cfg, char *b, int nest_level)
1013{
1014 struct token t;
1015 char *s = *c;
Heiko Schocher43d4a5e2011-12-12 20:37:17 +00001016 int err = 0;
Jason Hobbs06283a62011-08-31 10:37:30 -05001017
1018 get_token(c, &t, L_KEYWORD);
1019
1020 switch (t.type) {
1021 case T_TITLE:
1022 err = parse_sliteral(c, &cfg->title);
1023
1024 break;
1025
1026 case T_INCLUDE:
1027 err = handle_include(c, b + strlen(b) + 1, cfg,
1028 nest_level + 1);
1029 break;
1030
1031 default:
1032 printf("Ignoring malformed menu command: %.*s\n",
1033 (int)(*c - s), s);
1034 }
1035
1036 if (err < 0)
1037 return err;
1038
1039 eol_or_eof(c);
1040
1041 return 1;
1042}
1043
1044/*
1045 * Handles parsing a 'menu line' when we're parsing a label.
1046 */
1047static int parse_label_menu(char **c, struct pxe_menu *cfg,
1048 struct pxe_label *label)
1049{
1050 struct token t;
1051 char *s;
1052
1053 s = *c;
1054
1055 get_token(c, &t, L_KEYWORD);
1056
1057 switch (t.type) {
1058 case T_DEFAULT:
1059 if (cfg->default_label)
1060 free(cfg->default_label);
1061
1062 cfg->default_label = strdup(label->name);
1063
1064 if (!cfg->default_label)
1065 return -ENOMEM;
1066
1067 break;
Rob Herringe539d112012-03-28 05:51:34 +00001068 case T_LABEL:
1069 parse_sliteral(c, &label->menu);
1070 break;
Jason Hobbs06283a62011-08-31 10:37:30 -05001071 default:
1072 printf("Ignoring malformed menu command: %.*s\n",
1073 (int)(*c - s), s);
1074 }
1075
1076 eol_or_eof(c);
1077
1078 return 0;
1079}
1080
1081/*
1082 * Parses a label and adds it to the list of labels for a menu.
1083 *
1084 * A label ends when we either get to the end of a file, or
1085 * get some input we otherwise don't have a handler defined
1086 * for.
1087 *
1088 */
1089static int parse_label(char **c, struct pxe_menu *cfg)
1090{
1091 struct token t;
Rob Herring36f306c2012-03-28 05:51:37 +00001092 int len;
Jason Hobbs06283a62011-08-31 10:37:30 -05001093 char *s = *c;
1094 struct pxe_label *label;
1095 int err;
1096
1097 label = label_create();
1098 if (!label)
1099 return -ENOMEM;
1100
1101 err = parse_sliteral(c, &label->name);
1102 if (err < 0) {
1103 printf("Expected label name: %.*s\n", (int)(*c - s), s);
1104 label_destroy(label);
1105 return -EINVAL;
1106 }
1107
1108 list_add_tail(&label->list, &cfg->labels);
1109
1110 while (1) {
1111 s = *c;
1112 get_token(c, &t, L_KEYWORD);
1113
1114 err = 0;
1115 switch (t.type) {
1116 case T_MENU:
1117 err = parse_label_menu(c, cfg, label);
1118 break;
1119
1120 case T_KERNEL:
Rob Herringa0854ad2012-03-28 05:51:35 +00001121 case T_LINUX:
Jason Hobbs06283a62011-08-31 10:37:30 -05001122 err = parse_sliteral(c, &label->kernel);
1123 break;
1124
1125 case T_APPEND:
1126 err = parse_sliteral(c, &label->append);
Rob Herring36f306c2012-03-28 05:51:37 +00001127 if (label->initrd)
1128 break;
1129 s = strstr(label->append, "initrd=");
1130 if (!s)
1131 break;
1132 s += 7;
1133 len = (int)(strchr(s, ' ') - s);
1134 label->initrd = malloc(len + 1);
1135 strncpy(label->initrd, s, len);
1136 label->initrd[len] = '\0';
1137
Jason Hobbs06283a62011-08-31 10:37:30 -05001138 break;
1139
1140 case T_INITRD:
Rob Herring36f306c2012-03-28 05:51:37 +00001141 if (!label->initrd)
1142 err = parse_sliteral(c, &label->initrd);
Jason Hobbs06283a62011-08-31 10:37:30 -05001143 break;
1144
1145 case T_LOCALBOOT:
1146 err = parse_integer(c, &label->localboot);
1147 break;
1148
1149 case T_EOL:
1150 break;
1151
1152 default:
1153 /*
1154 * put the token back! we don't want it - it's the end
1155 * of a label and whatever token this is, it's
1156 * something for the menu level context to handle.
1157 */
1158 *c = s;
1159 return 1;
1160 }
1161
1162 if (err < 0)
1163 return err;
1164 }
1165}
1166
1167/*
1168 * This 16 comes from the limit pxelinux imposes on nested includes.
1169 *
1170 * There is no reason at all we couldn't do more, but some limit helps prevent
1171 * infinite (until crash occurs) recursion if a file tries to include itself.
1172 */
1173#define MAX_NEST_LEVEL 16
1174
1175/*
1176 * Entry point for parsing a menu file. nest_level indicates how many times
1177 * we've nested in includes. It will be 1 for the top level menu file.
1178 *
1179 * Returns 1 on success, < 0 on error.
1180 */
1181static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level)
1182{
1183 struct token t;
1184 char *s, *b, *label_name;
1185 int err;
1186
1187 b = p;
1188
1189 if (nest_level > MAX_NEST_LEVEL) {
1190 printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
1191 return -EMLINK;
1192 }
1193
1194 while (1) {
1195 s = p;
1196
1197 get_token(&p, &t, L_KEYWORD);
1198
1199 err = 0;
1200 switch (t.type) {
1201 case T_MENU:
1202 err = parse_menu(&p, cfg, b, nest_level);
1203 break;
1204
1205 case T_TIMEOUT:
1206 err = parse_integer(&p, &cfg->timeout);
1207 break;
1208
1209 case T_LABEL:
1210 err = parse_label(&p, cfg);
1211 break;
1212
1213 case T_DEFAULT:
1214 err = parse_sliteral(&p, &label_name);
1215
1216 if (label_name) {
1217 if (cfg->default_label)
1218 free(cfg->default_label);
1219
1220 cfg->default_label = label_name;
1221 }
1222
1223 break;
1224
Rob Herringf13fec52012-05-25 10:43:16 +00001225 case T_INCLUDE:
1226 err = handle_include(&p, b + ALIGN(strlen(b), 4), cfg,
1227 nest_level + 1);
1228 break;
1229
Jason Hobbs06283a62011-08-31 10:37:30 -05001230 case T_PROMPT:
1231 err = parse_integer(&p, &cfg->prompt);
1232 break;
1233
1234 case T_EOL:
1235 break;
1236
1237 case T_EOF:
1238 return 1;
1239
1240 default:
1241 printf("Ignoring unknown command: %.*s\n",
1242 (int)(p - s), s);
1243 eol_or_eof(&p);
1244 }
1245
1246 if (err < 0)
1247 return err;
1248 }
1249}
1250
1251/*
1252 * Free the memory used by a pxe_menu and its labels.
1253 */
1254static void destroy_pxe_menu(struct pxe_menu *cfg)
1255{
1256 struct list_head *pos, *n;
1257 struct pxe_label *label;
1258
1259 if (cfg->title)
1260 free(cfg->title);
1261
1262 if (cfg->default_label)
1263 free(cfg->default_label);
1264
1265 list_for_each_safe(pos, n, &cfg->labels) {
1266 label = list_entry(pos, struct pxe_label, list);
1267
1268 label_destroy(label);
1269 }
1270
1271 free(cfg);
1272}
1273
1274/*
1275 * Entry point for parsing a pxe file. This is only used for the top level
1276 * file.
1277 *
1278 * Returns NULL if there is an error, otherwise, returns a pointer to a
1279 * pxe_menu struct populated with the results of parsing the pxe file (and any
1280 * files it includes). The resulting pxe_menu struct can be free()'d by using
1281 * the destroy_pxe_menu() function.
1282 */
1283static struct pxe_menu *parse_pxefile(char *menucfg)
1284{
1285 struct pxe_menu *cfg;
1286
1287 cfg = malloc(sizeof(struct pxe_menu));
1288
1289 if (!cfg)
1290 return NULL;
1291
1292 memset(cfg, 0, sizeof(struct pxe_menu));
1293
1294 INIT_LIST_HEAD(&cfg->labels);
1295
1296 if (parse_pxefile_top(menucfg, cfg, 1) < 0) {
1297 destroy_pxe_menu(cfg);
1298 return NULL;
1299 }
1300
1301 return cfg;
1302}
1303
1304/*
1305 * Converts a pxe_menu struct into a menu struct for use with U-boot's generic
1306 * menu code.
1307 */
1308static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
1309{
1310 struct pxe_label *label;
1311 struct list_head *pos;
1312 struct menu *m;
1313 int err;
1314
1315 /*
1316 * Create a menu and add items for all the labels.
1317 */
1318 m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print);
1319
1320 if (!m)
1321 return NULL;
1322
1323 list_for_each(pos, &cfg->labels) {
1324 label = list_entry(pos, struct pxe_label, list);
1325
1326 if (menu_item_add(m, label->name, label) != 1) {
1327 menu_destroy(m);
1328 return NULL;
1329 }
1330 }
1331
1332 /*
1333 * After we've created items for each label in the menu, set the
1334 * menu's default label if one was specified.
1335 */
1336 if (cfg->default_label) {
1337 err = menu_default_set(m, cfg->default_label);
1338 if (err != 1) {
1339 if (err != -ENOENT) {
1340 menu_destroy(m);
1341 return NULL;
1342 }
1343
1344 printf("Missing default: %s\n", cfg->default_label);
1345 }
1346 }
1347
1348 return m;
1349}
1350
1351/*
1352 * Try to boot any labels we have yet to attempt to boot.
1353 */
1354static void boot_unattempted_labels(struct pxe_menu *cfg)
1355{
1356 struct list_head *pos;
1357 struct pxe_label *label;
1358
1359 list_for_each(pos, &cfg->labels) {
1360 label = list_entry(pos, struct pxe_label, list);
1361
1362 if (!label->attempted)
1363 label_boot(label);
1364 }
1365}
1366
1367/*
1368 * Boot the system as prescribed by a pxe_menu.
1369 *
1370 * Use the menu system to either get the user's choice or the default, based
1371 * on config or user input. If there is no default or user's choice,
1372 * attempted to boot labels in the order they were given in pxe files.
1373 * If the default or user's choice fails to boot, attempt to boot other
1374 * labels in the order they were given in pxe files.
1375 *
1376 * If this function returns, there weren't any labels that successfully
1377 * booted, or the user interrupted the menu selection via ctrl+c.
1378 */
1379static void handle_pxe_menu(struct pxe_menu *cfg)
1380{
1381 void *choice;
1382 struct menu *m;
1383 int err;
1384
1385 m = pxe_menu_to_menu(cfg);
1386 if (!m)
1387 return;
1388
1389 err = menu_get_choice(m, &choice);
1390
1391 menu_destroy(m);
1392
Jason Hobbs6f40f272011-11-07 03:07:15 +00001393 /*
1394 * err == 1 means we got a choice back from menu_get_choice.
1395 *
1396 * err == -ENOENT if the menu was setup to select the default but no
1397 * default was set. in that case, we should continue trying to boot
1398 * labels that haven't been attempted yet.
1399 *
1400 * otherwise, the user interrupted or there was some other error and
1401 * we give up.
1402 */
Jason Hobbs06283a62011-08-31 10:37:30 -05001403
Jason Hobbs6f40f272011-11-07 03:07:15 +00001404 if (err == 1)
1405 label_boot(choice);
1406 else if (err != -ENOENT)
1407 return;
Jason Hobbs06283a62011-08-31 10:37:30 -05001408
1409 boot_unattempted_labels(cfg);
1410}
1411
1412/*
1413 * Boots a system using a pxe file
1414 *
1415 * Returns 0 on success, 1 on error.
1416 */
1417static int
1418do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1419{
1420 unsigned long pxefile_addr_r;
1421 struct pxe_menu *cfg;
1422 char *pxefile_addr_str;
1423
Rob Herringcfb48a32012-05-25 10:47:39 +00001424 do_getfile = do_get_tftp;
1425
Jason Hobbs06283a62011-08-31 10:37:30 -05001426 if (argc == 1) {
1427 pxefile_addr_str = from_env("pxefile_addr_r");
1428 if (!pxefile_addr_str)
1429 return 1;
1430
1431 } else if (argc == 2) {
1432 pxefile_addr_str = argv[1];
1433 } else {
Simon Glass4c12eeb2011-12-10 08:44:01 +00001434 return CMD_RET_USAGE;
Jason Hobbs06283a62011-08-31 10:37:30 -05001435 }
1436
1437 if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
1438 printf("Invalid pxefile address: %s\n", pxefile_addr_str);
1439 return 1;
1440 }
1441
1442 cfg = parse_pxefile((char *)(pxefile_addr_r));
1443
1444 if (cfg == NULL) {
1445 printf("Error parsing config file\n");
1446 return 1;
1447 }
1448
1449 handle_pxe_menu(cfg);
1450
1451 destroy_pxe_menu(cfg);
1452
1453 return 0;
1454}
1455
1456static cmd_tbl_t cmd_pxe_sub[] = {
1457 U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
1458 U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
1459};
1460
1461int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1462{
1463 cmd_tbl_t *cp;
1464
1465 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001466 return CMD_RET_USAGE;
Jason Hobbs06283a62011-08-31 10:37:30 -05001467
1468 /* drop initial "pxe" arg */
1469 argc--;
1470 argv++;
1471
1472 cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub));
1473
1474 if (cp)
1475 return cp->cmd(cmdtp, flag, argc, argv);
1476
Simon Glass4c12eeb2011-12-10 08:44:01 +00001477 return CMD_RET_USAGE;
Jason Hobbs06283a62011-08-31 10:37:30 -05001478}
1479
1480U_BOOT_CMD(
1481 pxe, 3, 1, do_pxe,
1482 "commands to get and boot from pxe files",
1483 "get - try to retrieve a pxe file using tftp\npxe "
1484 "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"
1485);
Rob Herringcfb48a32012-05-25 10:47:39 +00001486
1487/*
1488 * Boots a system using a local disk syslinux/extlinux file
1489 *
1490 * Returns 0 on success, 1 on error.
1491 */
1492int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1493{
1494 unsigned long pxefile_addr_r;
1495 struct pxe_menu *cfg;
1496 char *pxefile_addr_str;
1497 char *filename;
1498 int prompt = 0;
1499
1500 if (strstr(argv[1], "-p")) {
1501 prompt = 1;
1502 argc--;
1503 argv++;
1504 }
1505
1506 if (argc < 4)
1507 return cmd_usage(cmdtp);
1508
1509 if (argc < 5) {
1510 pxefile_addr_str = from_env("pxefile_addr_r");
1511 if (!pxefile_addr_str)
1512 return 1;
1513 } else {
1514 pxefile_addr_str = argv[4];
1515 }
1516
1517 if (argc < 6)
1518 filename = getenv("bootfile");
1519 else {
1520 filename = argv[5];
1521 setenv("bootfile", filename);
1522 }
1523
1524 if (strstr(argv[3], "ext2"))
1525 do_getfile = do_get_ext2;
1526 else if (strstr(argv[3], "fat"))
1527 do_getfile = do_get_fat;
1528 else {
1529 printf("Invalid filesystem: %s\n", argv[3]);
1530 return 1;
1531 }
1532 fs_argv[1] = argv[1];
1533 fs_argv[2] = argv[2];
1534
1535 if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
1536 printf("Invalid pxefile address: %s\n", pxefile_addr_str);
1537 return 1;
1538 }
1539
1540 if (get_pxe_file(filename, (void *)pxefile_addr_r) < 0) {
1541 printf("Error reading config file\n");
1542 return 1;
1543 }
1544
1545 cfg = parse_pxefile((char *)(pxefile_addr_r));
1546
1547 if (cfg == NULL) {
1548 printf("Error parsing config file\n");
1549 return 1;
1550 }
1551
1552 if (prompt)
1553 cfg->prompt = 1;
1554
1555 handle_pxe_menu(cfg);
1556
1557 destroy_pxe_menu(cfg);
1558
1559 return 0;
1560}
1561
1562U_BOOT_CMD(
1563 sysboot, 7, 1, do_sysboot,
1564 "command to get and boot from syslinux files",
1565 "[-p] <interface> <dev[:part]> <ext2|fat> [addr] [filename]\n"
1566 " - load and parse syslinux menu file 'filename' from ext2 or fat\n"
1567 " filesystem on 'dev' on 'interface' to address 'addr'"
1568);