cmd_pxe.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  1. /*
  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. #include "menu.h"
  25. #define MAX_TFTP_PATH_LEN 127
  26. const char *pxe_default_paths[] = {
  27. "default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC,
  28. "default-" CONFIG_SYS_ARCH,
  29. "default",
  30. NULL
  31. };
  32. /*
  33. * Like getenv, but prints an error if envvar isn't defined in the
  34. * environment. It always returns what getenv does, so it can be used in
  35. * place of getenv without changing error handling otherwise.
  36. */
  37. static char *from_env(const char *envvar)
  38. {
  39. char *ret;
  40. ret = getenv(envvar);
  41. if (!ret)
  42. printf("missing environment variable: %s\n", envvar);
  43. return ret;
  44. }
  45. /*
  46. * Convert an ethaddr from the environment to the format used by pxelinux
  47. * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
  48. * the beginning of the ethernet address to indicate a hardware type of
  49. * Ethernet. Also converts uppercase hex characters into lowercase, to match
  50. * pxelinux's behavior.
  51. *
  52. * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
  53. * environment, or some other value < 0 on error.
  54. */
  55. static int format_mac_pxe(char *outbuf, size_t outbuf_len)
  56. {
  57. uchar ethaddr[6];
  58. if (outbuf_len < 21) {
  59. printf("outbuf is too small (%d < 21)\n", outbuf_len);
  60. return -EINVAL;
  61. }
  62. if (!eth_getenv_enetaddr_by_index("eth", eth_get_dev_index(),
  63. ethaddr))
  64. return -ENOENT;
  65. sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x",
  66. ethaddr[0], ethaddr[1], ethaddr[2],
  67. ethaddr[3], ethaddr[4], ethaddr[5]);
  68. return 1;
  69. }
  70. /*
  71. * Returns the directory the file specified in the bootfile env variable is
  72. * in. If bootfile isn't defined in the environment, return NULL, which should
  73. * be interpreted as "don't prepend anything to paths".
  74. */
  75. static int get_bootfile_path(const char *file_path, char *bootfile_path,
  76. size_t bootfile_path_size)
  77. {
  78. char *bootfile, *last_slash;
  79. size_t path_len = 0;
  80. if (file_path[0] == '/')
  81. goto ret;
  82. bootfile = from_env("bootfile");
  83. if (!bootfile)
  84. goto ret;
  85. last_slash = strrchr(bootfile, '/');
  86. if (last_slash == NULL)
  87. goto ret;
  88. path_len = (last_slash - bootfile) + 1;
  89. if (bootfile_path_size < path_len) {
  90. printf("bootfile_path too small. (%d < %d)\n",
  91. bootfile_path_size, path_len);
  92. return -1;
  93. }
  94. strncpy(bootfile_path, bootfile, path_len);
  95. ret:
  96. bootfile_path[path_len] = '\0';
  97. return 1;
  98. }
  99. static int (*do_getfile)(const char *file_path, char *file_addr);
  100. static int do_get_tftp(const char *file_path, char *file_addr)
  101. {
  102. char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
  103. tftp_argv[1] = file_addr;
  104. tftp_argv[2] = (void *)file_path;
  105. if (do_tftpb(NULL, 0, 3, tftp_argv))
  106. return -ENOENT;
  107. return 1;
  108. }
  109. static char *fs_argv[5];
  110. static int do_get_ext2(const char *file_path, char *file_addr)
  111. {
  112. #ifdef CONFIG_CMD_EXT2
  113. fs_argv[0] = "ext2load";
  114. fs_argv[3] = file_addr;
  115. fs_argv[4] = (void *)file_path;
  116. if (!do_ext2load(NULL, 0, 5, fs_argv))
  117. return 1;
  118. #endif
  119. return -ENOENT;
  120. }
  121. static int do_get_fat(const char *file_path, char *file_addr)
  122. {
  123. #ifdef CONFIG_CMD_FAT
  124. fs_argv[0] = "fatload";
  125. fs_argv[3] = file_addr;
  126. fs_argv[4] = (void *)file_path;
  127. if (!do_fat_fsload(NULL, 0, 5, fs_argv))
  128. return 1;
  129. #endif
  130. return -ENOENT;
  131. }
  132. /*
  133. * As in pxelinux, paths to files referenced from files we retrieve are
  134. * relative to the location of bootfile. get_relfile takes such a path and
  135. * joins it with the bootfile path to get the full path to the target file. If
  136. * the bootfile path is NULL, we use file_path as is.
  137. *
  138. * Returns 1 for success, or < 0 on error.
  139. */
  140. static int get_relfile(const char *file_path, void *file_addr)
  141. {
  142. size_t path_len;
  143. char relfile[MAX_TFTP_PATH_LEN+1];
  144. char addr_buf[10];
  145. int err;
  146. err = get_bootfile_path(file_path, relfile, sizeof(relfile));
  147. if (err < 0)
  148. return err;
  149. path_len = strlen(file_path);
  150. path_len += strlen(relfile);
  151. if (path_len > MAX_TFTP_PATH_LEN) {
  152. printf("Base path too long (%s%s)\n",
  153. relfile,
  154. file_path);
  155. return -ENAMETOOLONG;
  156. }
  157. strcat(relfile, file_path);
  158. printf("Retrieving file: %s\n", relfile);
  159. sprintf(addr_buf, "%p", file_addr);
  160. return do_getfile(relfile, addr_buf);
  161. }
  162. /*
  163. * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
  164. * 'bootfile' was specified in the environment, the path to bootfile will be
  165. * prepended to 'file_path' and the resulting path will be used.
  166. *
  167. * Returns 1 on success, or < 0 for error.
  168. */
  169. static int get_pxe_file(const char *file_path, void *file_addr)
  170. {
  171. unsigned long config_file_size;
  172. char *tftp_filesize;
  173. int err;
  174. err = get_relfile(file_path, file_addr);
  175. if (err < 0)
  176. return err;
  177. /*
  178. * the file comes without a NUL byte at the end, so find out its size
  179. * and add the NUL byte.
  180. */
  181. tftp_filesize = from_env("filesize");
  182. if (!tftp_filesize)
  183. return -ENOENT;
  184. if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0)
  185. return -EINVAL;
  186. *(char *)(file_addr + config_file_size) = '\0';
  187. return 1;
  188. }
  189. #define PXELINUX_DIR "pxelinux.cfg/"
  190. /*
  191. * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
  192. * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
  193. * from the bootfile path, as described above.
  194. *
  195. * Returns 1 on success or < 0 on error.
  196. */
  197. static int get_pxelinux_path(const char *file, void *pxefile_addr_r)
  198. {
  199. size_t base_len = strlen(PXELINUX_DIR);
  200. char path[MAX_TFTP_PATH_LEN+1];
  201. if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
  202. printf("path (%s%s) too long, skipping\n",
  203. PXELINUX_DIR, file);
  204. return -ENAMETOOLONG;
  205. }
  206. sprintf(path, PXELINUX_DIR "%s", file);
  207. return get_pxe_file(path, pxefile_addr_r);
  208. }
  209. /*
  210. * Looks for a pxe file with a name based on the pxeuuid environment variable.
  211. *
  212. * Returns 1 on success or < 0 on error.
  213. */
  214. static int pxe_uuid_path(void *pxefile_addr_r)
  215. {
  216. char *uuid_str;
  217. uuid_str = from_env("pxeuuid");
  218. if (!uuid_str)
  219. return -ENOENT;
  220. return get_pxelinux_path(uuid_str, pxefile_addr_r);
  221. }
  222. /*
  223. * Looks for a pxe file with a name based on the 'ethaddr' environment
  224. * variable.
  225. *
  226. * Returns 1 on success or < 0 on error.
  227. */
  228. static int pxe_mac_path(void *pxefile_addr_r)
  229. {
  230. char mac_str[21];
  231. int err;
  232. err = format_mac_pxe(mac_str, sizeof(mac_str));
  233. if (err < 0)
  234. return err;
  235. return get_pxelinux_path(mac_str, pxefile_addr_r);
  236. }
  237. /*
  238. * Looks for pxe files with names based on our IP address. See pxelinux
  239. * documentation for details on what these file names look like. We match
  240. * that exactly.
  241. *
  242. * Returns 1 on success or < 0 on error.
  243. */
  244. static int pxe_ipaddr_paths(void *pxefile_addr_r)
  245. {
  246. char ip_addr[9];
  247. int mask_pos, err;
  248. sprintf(ip_addr, "%08X", ntohl(NetOurIP));
  249. for (mask_pos = 7; mask_pos >= 0; mask_pos--) {
  250. err = get_pxelinux_path(ip_addr, pxefile_addr_r);
  251. if (err > 0)
  252. return err;
  253. ip_addr[mask_pos] = '\0';
  254. }
  255. return -ENOENT;
  256. }
  257. /*
  258. * Entry point for the 'pxe get' command.
  259. * This Follows pxelinux's rules to download a config file from a tftp server.
  260. * The file is stored at the location given by the pxefile_addr_r environment
  261. * variable, which must be set.
  262. *
  263. * UUID comes from pxeuuid env variable, if defined
  264. * MAC addr comes from ethaddr env variable, if defined
  265. * IP
  266. *
  267. * see http://syslinux.zytor.com/wiki/index.php/PXELINUX
  268. *
  269. * Returns 0 on success or 1 on error.
  270. */
  271. static int
  272. do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  273. {
  274. char *pxefile_addr_str;
  275. unsigned long pxefile_addr_r;
  276. int err, i = 0;
  277. do_getfile = do_get_tftp;
  278. if (argc != 1)
  279. return CMD_RET_USAGE;
  280. pxefile_addr_str = from_env("pxefile_addr_r");
  281. if (!pxefile_addr_str)
  282. return 1;
  283. err = strict_strtoul(pxefile_addr_str, 16,
  284. (unsigned long *)&pxefile_addr_r);
  285. if (err < 0)
  286. return 1;
  287. /*
  288. * Keep trying paths until we successfully get a file we're looking
  289. * for.
  290. */
  291. if (pxe_uuid_path((void *)pxefile_addr_r) > 0 ||
  292. pxe_mac_path((void *)pxefile_addr_r) > 0 ||
  293. pxe_ipaddr_paths((void *)pxefile_addr_r) > 0) {
  294. printf("Config file found\n");
  295. return 0;
  296. }
  297. while (pxe_default_paths[i]) {
  298. if (get_pxelinux_path(pxe_default_paths[i],
  299. (void *)pxefile_addr_r) > 0) {
  300. printf("Config file found\n");
  301. return 0;
  302. }
  303. i++;
  304. }
  305. printf("Config file not found\n");
  306. return 1;
  307. }
  308. /*
  309. * Wrapper to make it easier to store the file at file_path in the location
  310. * specified by envaddr_name. file_path will be joined to the bootfile path,
  311. * if any is specified.
  312. *
  313. * Returns 1 on success or < 0 on error.
  314. */
  315. static int get_relfile_envaddr(const char *file_path, const char *envaddr_name)
  316. {
  317. unsigned long file_addr;
  318. char *envaddr;
  319. envaddr = from_env(envaddr_name);
  320. if (!envaddr)
  321. return -ENOENT;
  322. if (strict_strtoul(envaddr, 16, &file_addr) < 0)
  323. return -EINVAL;
  324. return get_relfile(file_path, (void *)file_addr);
  325. }
  326. /*
  327. * A note on the pxe file parser.
  328. *
  329. * We're parsing files that use syslinux grammar, which has a few quirks.
  330. * String literals must be recognized based on context - there is no
  331. * quoting or escaping support. There's also nothing to explicitly indicate
  332. * when a label section completes. We deal with that by ending a label
  333. * section whenever we see a line that doesn't include.
  334. *
  335. * As with the syslinux family, this same file format could be reused in the
  336. * future for non pxe purposes. The only action it takes during parsing that
  337. * would throw this off is handling of include files. It assumes we're using
  338. * pxe, and does a tftp download of a file listed as an include file in the
  339. * middle of the parsing operation. That could be handled by refactoring it to
  340. * take a 'include file getter' function.
  341. */
  342. /*
  343. * Describes a single label given in a pxe file.
  344. *
  345. * Create these with the 'label_create' function given below.
  346. *
  347. * name - the name of the menu as given on the 'menu label' line.
  348. * kernel - the path to the kernel file to use for this label.
  349. * append - kernel command line to use when booting this label
  350. * initrd - path to the initrd to use for this label.
  351. * attempted - 0 if we haven't tried to boot this label, 1 if we have.
  352. * localboot - 1 if this label specified 'localboot', 0 otherwise.
  353. * list - lets these form a list, which a pxe_menu struct will hold.
  354. */
  355. struct pxe_label {
  356. char num[4];
  357. char *name;
  358. char *menu;
  359. char *kernel;
  360. char *append;
  361. char *initrd;
  362. char *fdt;
  363. int attempted;
  364. int localboot;
  365. int localboot_val;
  366. struct list_head list;
  367. };
  368. /*
  369. * Describes a pxe menu as given via pxe files.
  370. *
  371. * title - the name of the menu as given by a 'menu title' line.
  372. * default_label - the name of the default label, if any.
  373. * timeout - time in tenths of a second to wait for a user key-press before
  374. * booting the default label.
  375. * prompt - if 0, don't prompt for a choice unless the timeout period is
  376. * interrupted. If 1, always prompt for a choice regardless of
  377. * timeout.
  378. * labels - a list of labels defined for the menu.
  379. */
  380. struct pxe_menu {
  381. char *title;
  382. char *default_label;
  383. int timeout;
  384. int prompt;
  385. struct list_head labels;
  386. };
  387. /*
  388. * Allocates memory for and initializes a pxe_label. This uses malloc, so the
  389. * result must be free()'d to reclaim the memory.
  390. *
  391. * Returns NULL if malloc fails.
  392. */
  393. static struct pxe_label *label_create(void)
  394. {
  395. struct pxe_label *label;
  396. label = malloc(sizeof(struct pxe_label));
  397. if (!label)
  398. return NULL;
  399. memset(label, 0, sizeof(struct pxe_label));
  400. return label;
  401. }
  402. /*
  403. * Free the memory used by a pxe_label, including that used by its name,
  404. * kernel, append and initrd members, if they're non NULL.
  405. *
  406. * So - be sure to only use dynamically allocated memory for the members of
  407. * the pxe_label struct, unless you want to clean it up first. These are
  408. * currently only created by the pxe file parsing code.
  409. */
  410. static void label_destroy(struct pxe_label *label)
  411. {
  412. if (label->name)
  413. free(label->name);
  414. if (label->kernel)
  415. free(label->kernel);
  416. if (label->append)
  417. free(label->append);
  418. if (label->initrd)
  419. free(label->initrd);
  420. if (label->fdt)
  421. free(label->fdt);
  422. free(label);
  423. }
  424. /*
  425. * Print a label and its string members if they're defined.
  426. *
  427. * This is passed as a callback to the menu code for displaying each
  428. * menu entry.
  429. */
  430. static void label_print(void *data)
  431. {
  432. struct pxe_label *label = data;
  433. const char *c = label->menu ? label->menu : label->name;
  434. printf("%s:\t%s\n", label->num, c);
  435. }
  436. /*
  437. * Boot a label that specified 'localboot'. This requires that the 'localcmd'
  438. * environment variable is defined. Its contents will be executed as U-boot
  439. * command. If the label specified an 'append' line, its contents will be
  440. * used to overwrite the contents of the 'bootargs' environment variable prior
  441. * to running 'localcmd'.
  442. *
  443. * Returns 1 on success or < 0 on error.
  444. */
  445. static int label_localboot(struct pxe_label *label)
  446. {
  447. char *localcmd;
  448. localcmd = from_env("localcmd");
  449. if (!localcmd)
  450. return -ENOENT;
  451. if (label->append)
  452. setenv("bootargs", label->append);
  453. debug("running: %s\n", localcmd);
  454. return run_command_list(localcmd, strlen(localcmd), 0);
  455. }
  456. /*
  457. * Boot according to the contents of a pxe_label.
  458. *
  459. * If we can't boot for any reason, we return. A successful boot never
  460. * returns.
  461. *
  462. * The kernel will be stored in the location given by the 'kernel_addr_r'
  463. * environment variable.
  464. *
  465. * If the label specifies an initrd file, it will be stored in the location
  466. * given by the 'ramdisk_addr_r' environment variable.
  467. *
  468. * If the label specifies an 'append' line, its contents will overwrite that
  469. * of the 'bootargs' environment variable.
  470. */
  471. static int label_boot(struct pxe_label *label)
  472. {
  473. char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
  474. char initrd_str[22];
  475. int bootm_argc = 3;
  476. label_print(label);
  477. label->attempted = 1;
  478. if (label->localboot) {
  479. if (label->localboot_val >= 0)
  480. label_localboot(label);
  481. return 0;
  482. }
  483. if (label->kernel == NULL) {
  484. printf("No kernel given, skipping %s\n",
  485. label->name);
  486. return 1;
  487. }
  488. if (label->initrd) {
  489. if (get_relfile_envaddr(label->initrd, "ramdisk_addr_r") < 0) {
  490. printf("Skipping %s for failure retrieving initrd\n",
  491. label->name);
  492. return 1;
  493. }
  494. bootm_argv[2] = initrd_str;
  495. strcpy(bootm_argv[2], getenv("ramdisk_addr_r"));
  496. strcat(bootm_argv[2], ":");
  497. strcat(bootm_argv[2], getenv("filesize"));
  498. } else {
  499. bootm_argv[2] = "-";
  500. }
  501. if (get_relfile_envaddr(label->kernel, "kernel_addr_r") < 0) {
  502. printf("Skipping %s for failure retrieving kernel\n",
  503. label->name);
  504. return 1;
  505. }
  506. if (label->append) {
  507. setenv("bootargs", label->append);
  508. printf("append: %s\n", label->append);
  509. }
  510. bootm_argv[1] = getenv("kernel_addr_r");
  511. /*
  512. * fdt usage is optional:
  513. * It handles the following scenarios. All scenarios are exclusive
  514. *
  515. * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in
  516. * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm,
  517. * and adjust argc appropriately.
  518. *
  519. * Scenario 2: If there is an fdt_addr specified, pass it along to
  520. * bootm, and adjust argc appropriately.
  521. *
  522. * Scenario 3: fdt blob is not available.
  523. */
  524. bootm_argv[3] = getenv("fdt_addr_r");
  525. /* if fdt label is defined then get fdt from server */
  526. if (bootm_argv[3] && label->fdt) {
  527. if (get_relfile_envaddr(label->fdt, "fdt_addr_r") < 0) {
  528. printf("Skipping %s for failure retrieving fdt\n",
  529. label->name);
  530. return 1;
  531. }
  532. } else
  533. bootm_argv[3] = getenv("fdt_addr");
  534. if (bootm_argv[3])
  535. bootm_argc = 4;
  536. do_bootm(NULL, 0, bootm_argc, bootm_argv);
  537. #ifdef CONFIG_CMD_BOOTZ
  538. /* Try booting a zImage if do_bootm returns */
  539. do_bootz(NULL, 0, bootm_argc, bootm_argv);
  540. #endif
  541. return 1;
  542. }
  543. /*
  544. * Tokens for the pxe file parser.
  545. */
  546. enum token_type {
  547. T_EOL,
  548. T_STRING,
  549. T_EOF,
  550. T_MENU,
  551. T_TITLE,
  552. T_TIMEOUT,
  553. T_LABEL,
  554. T_KERNEL,
  555. T_LINUX,
  556. T_APPEND,
  557. T_INITRD,
  558. T_LOCALBOOT,
  559. T_DEFAULT,
  560. T_PROMPT,
  561. T_INCLUDE,
  562. T_FDT,
  563. T_ONTIMEOUT,
  564. T_INVALID
  565. };
  566. /*
  567. * A token - given by a value and a type.
  568. */
  569. struct token {
  570. char *val;
  571. enum token_type type;
  572. };
  573. /*
  574. * Keywords recognized.
  575. */
  576. static const struct token keywords[] = {
  577. {"menu", T_MENU},
  578. {"title", T_TITLE},
  579. {"timeout", T_TIMEOUT},
  580. {"default", T_DEFAULT},
  581. {"prompt", T_PROMPT},
  582. {"label", T_LABEL},
  583. {"kernel", T_KERNEL},
  584. {"linux", T_LINUX},
  585. {"localboot", T_LOCALBOOT},
  586. {"append", T_APPEND},
  587. {"initrd", T_INITRD},
  588. {"include", T_INCLUDE},
  589. {"fdt", T_FDT},
  590. {"ontimeout", T_ONTIMEOUT,},
  591. {NULL, T_INVALID}
  592. };
  593. /*
  594. * Since pxe(linux) files don't have a token to identify the start of a
  595. * literal, we have to keep track of when we're in a state where a literal is
  596. * expected vs when we're in a state a keyword is expected.
  597. */
  598. enum lex_state {
  599. L_NORMAL = 0,
  600. L_KEYWORD,
  601. L_SLITERAL
  602. };
  603. /*
  604. * get_string retrieves a string from *p and stores it as a token in
  605. * *t.
  606. *
  607. * get_string used for scanning both string literals and keywords.
  608. *
  609. * Characters from *p are copied into t-val until a character equal to
  610. * delim is found, or a NUL byte is reached. If delim has the special value of
  611. * ' ', any whitespace character will be used as a delimiter.
  612. *
  613. * If lower is unequal to 0, uppercase characters will be converted to
  614. * lowercase in the result. This is useful to make keywords case
  615. * insensitive.
  616. *
  617. * The location of *p is updated to point to the first character after the end
  618. * of the token - the ending delimiter.
  619. *
  620. * On success, the new value of t->val is returned. Memory for t->val is
  621. * allocated using malloc and must be free()'d to reclaim it. If insufficient
  622. * memory is available, NULL is returned.
  623. */
  624. static char *get_string(char **p, struct token *t, char delim, int lower)
  625. {
  626. char *b, *e;
  627. size_t len, i;
  628. /*
  629. * b and e both start at the beginning of the input stream.
  630. *
  631. * e is incremented until we find the ending delimiter, or a NUL byte
  632. * is reached. Then, we take e - b to find the length of the token.
  633. */
  634. b = e = *p;
  635. while (*e) {
  636. if ((delim == ' ' && isspace(*e)) || delim == *e)
  637. break;
  638. e++;
  639. }
  640. len = e - b;
  641. /*
  642. * Allocate memory to hold the string, and copy it in, converting
  643. * characters to lowercase if lower is != 0.
  644. */
  645. t->val = malloc(len + 1);
  646. if (!t->val)
  647. return NULL;
  648. for (i = 0; i < len; i++, b++) {
  649. if (lower)
  650. t->val[i] = tolower(*b);
  651. else
  652. t->val[i] = *b;
  653. }
  654. t->val[len] = '\0';
  655. /*
  656. * Update *p so the caller knows where to continue scanning.
  657. */
  658. *p = e;
  659. t->type = T_STRING;
  660. return t->val;
  661. }
  662. /*
  663. * Populate a keyword token with a type and value.
  664. */
  665. static void get_keyword(struct token *t)
  666. {
  667. int i;
  668. for (i = 0; keywords[i].val; i++) {
  669. if (!strcmp(t->val, keywords[i].val)) {
  670. t->type = keywords[i].type;
  671. break;
  672. }
  673. }
  674. }
  675. /*
  676. * Get the next token. We have to keep track of which state we're in to know
  677. * if we're looking to get a string literal or a keyword.
  678. *
  679. * *p is updated to point at the first character after the current token.
  680. */
  681. static void get_token(char **p, struct token *t, enum lex_state state)
  682. {
  683. char *c = *p;
  684. t->type = T_INVALID;
  685. /* eat non EOL whitespace */
  686. while (isblank(*c))
  687. c++;
  688. /*
  689. * eat comments. note that string literals can't begin with #, but
  690. * can contain a # after their first character.
  691. */
  692. if (*c == '#') {
  693. while (*c && *c != '\n')
  694. c++;
  695. }
  696. if (*c == '\n') {
  697. t->type = T_EOL;
  698. c++;
  699. } else if (*c == '\0') {
  700. t->type = T_EOF;
  701. c++;
  702. } else if (state == L_SLITERAL) {
  703. get_string(&c, t, '\n', 0);
  704. } else if (state == L_KEYWORD) {
  705. /*
  706. * when we expect a keyword, we first get the next string
  707. * token delimited by whitespace, and then check if it
  708. * matches a keyword in our keyword list. if it does, it's
  709. * converted to a keyword token of the appropriate type, and
  710. * if not, it remains a string token.
  711. */
  712. get_string(&c, t, ' ', 1);
  713. get_keyword(t);
  714. }
  715. *p = c;
  716. }
  717. /*
  718. * Increment *c until we get to the end of the current line, or EOF.
  719. */
  720. static void eol_or_eof(char **c)
  721. {
  722. while (**c && **c != '\n')
  723. (*c)++;
  724. }
  725. /*
  726. * All of these parse_* functions share some common behavior.
  727. *
  728. * They finish with *c pointing after the token they parse, and return 1 on
  729. * success, or < 0 on error.
  730. */
  731. /*
  732. * Parse a string literal and store a pointer it at *dst. String literals
  733. * terminate at the end of the line.
  734. */
  735. static int parse_sliteral(char **c, char **dst)
  736. {
  737. struct token t;
  738. char *s = *c;
  739. get_token(c, &t, L_SLITERAL);
  740. if (t.type != T_STRING) {
  741. printf("Expected string literal: %.*s\n", (int)(*c - s), s);
  742. return -EINVAL;
  743. }
  744. *dst = t.val;
  745. return 1;
  746. }
  747. /*
  748. * Parse a base 10 (unsigned) integer and store it at *dst.
  749. */
  750. static int parse_integer(char **c, int *dst)
  751. {
  752. struct token t;
  753. char *s = *c;
  754. get_token(c, &t, L_SLITERAL);
  755. if (t.type != T_STRING) {
  756. printf("Expected string: %.*s\n", (int)(*c - s), s);
  757. return -EINVAL;
  758. }
  759. *dst = simple_strtol(t.val, NULL, 10);
  760. free(t.val);
  761. return 1;
  762. }
  763. static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level);
  764. /*
  765. * Parse an include statement, and retrieve and parse the file it mentions.
  766. *
  767. * base should point to a location where it's safe to store the file, and
  768. * nest_level should indicate how many nested includes have occurred. For this
  769. * include, nest_level has already been incremented and doesn't need to be
  770. * incremented here.
  771. */
  772. static int handle_include(char **c, char *base,
  773. struct pxe_menu *cfg, int nest_level)
  774. {
  775. char *include_path;
  776. char *s = *c;
  777. int err;
  778. err = parse_sliteral(c, &include_path);
  779. if (err < 0) {
  780. printf("Expected include path: %.*s\n",
  781. (int)(*c - s), s);
  782. return err;
  783. }
  784. err = get_pxe_file(include_path, base);
  785. if (err < 0) {
  786. printf("Couldn't retrieve %s\n", include_path);
  787. return err;
  788. }
  789. return parse_pxefile_top(base, cfg, nest_level);
  790. }
  791. /*
  792. * Parse lines that begin with 'menu'.
  793. *
  794. * b and nest are provided to handle the 'menu include' case.
  795. *
  796. * b should be the address where the file currently being parsed is stored.
  797. *
  798. * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
  799. * a file it includes, 3 when parsing a file included by that file, and so on.
  800. */
  801. static int parse_menu(char **c, struct pxe_menu *cfg, char *b, int nest_level)
  802. {
  803. struct token t;
  804. char *s = *c;
  805. int err = 0;
  806. get_token(c, &t, L_KEYWORD);
  807. switch (t.type) {
  808. case T_TITLE:
  809. err = parse_sliteral(c, &cfg->title);
  810. break;
  811. case T_INCLUDE:
  812. err = handle_include(c, b + strlen(b) + 1, cfg,
  813. nest_level + 1);
  814. break;
  815. default:
  816. printf("Ignoring malformed menu command: %.*s\n",
  817. (int)(*c - s), s);
  818. }
  819. if (err < 0)
  820. return err;
  821. eol_or_eof(c);
  822. return 1;
  823. }
  824. /*
  825. * Handles parsing a 'menu line' when we're parsing a label.
  826. */
  827. static int parse_label_menu(char **c, struct pxe_menu *cfg,
  828. struct pxe_label *label)
  829. {
  830. struct token t;
  831. char *s;
  832. s = *c;
  833. get_token(c, &t, L_KEYWORD);
  834. switch (t.type) {
  835. case T_DEFAULT:
  836. if (!cfg->default_label)
  837. cfg->default_label = strdup(label->name);
  838. if (!cfg->default_label)
  839. return -ENOMEM;
  840. break;
  841. case T_LABEL:
  842. parse_sliteral(c, &label->menu);
  843. break;
  844. default:
  845. printf("Ignoring malformed menu command: %.*s\n",
  846. (int)(*c - s), s);
  847. }
  848. eol_or_eof(c);
  849. return 0;
  850. }
  851. /*
  852. * Parses a label and adds it to the list of labels for a menu.
  853. *
  854. * A label ends when we either get to the end of a file, or
  855. * get some input we otherwise don't have a handler defined
  856. * for.
  857. *
  858. */
  859. static int parse_label(char **c, struct pxe_menu *cfg)
  860. {
  861. struct token t;
  862. int len;
  863. char *s = *c;
  864. struct pxe_label *label;
  865. int err;
  866. label = label_create();
  867. if (!label)
  868. return -ENOMEM;
  869. err = parse_sliteral(c, &label->name);
  870. if (err < 0) {
  871. printf("Expected label name: %.*s\n", (int)(*c - s), s);
  872. label_destroy(label);
  873. return -EINVAL;
  874. }
  875. list_add_tail(&label->list, &cfg->labels);
  876. while (1) {
  877. s = *c;
  878. get_token(c, &t, L_KEYWORD);
  879. err = 0;
  880. switch (t.type) {
  881. case T_MENU:
  882. err = parse_label_menu(c, cfg, label);
  883. break;
  884. case T_KERNEL:
  885. case T_LINUX:
  886. err = parse_sliteral(c, &label->kernel);
  887. break;
  888. case T_APPEND:
  889. err = parse_sliteral(c, &label->append);
  890. if (label->initrd)
  891. break;
  892. s = strstr(label->append, "initrd=");
  893. if (!s)
  894. break;
  895. s += 7;
  896. len = (int)(strchr(s, ' ') - s);
  897. label->initrd = malloc(len + 1);
  898. strncpy(label->initrd, s, len);
  899. label->initrd[len] = '\0';
  900. break;
  901. case T_INITRD:
  902. if (!label->initrd)
  903. err = parse_sliteral(c, &label->initrd);
  904. break;
  905. case T_FDT:
  906. if (!label->fdt)
  907. err = parse_sliteral(c, &label->fdt);
  908. break;
  909. case T_LOCALBOOT:
  910. label->localboot = 1;
  911. err = parse_integer(c, &label->localboot_val);
  912. break;
  913. case T_EOL:
  914. break;
  915. default:
  916. /*
  917. * put the token back! we don't want it - it's the end
  918. * of a label and whatever token this is, it's
  919. * something for the menu level context to handle.
  920. */
  921. *c = s;
  922. return 1;
  923. }
  924. if (err < 0)
  925. return err;
  926. }
  927. }
  928. /*
  929. * This 16 comes from the limit pxelinux imposes on nested includes.
  930. *
  931. * There is no reason at all we couldn't do more, but some limit helps prevent
  932. * infinite (until crash occurs) recursion if a file tries to include itself.
  933. */
  934. #define MAX_NEST_LEVEL 16
  935. /*
  936. * Entry point for parsing a menu file. nest_level indicates how many times
  937. * we've nested in includes. It will be 1 for the top level menu file.
  938. *
  939. * Returns 1 on success, < 0 on error.
  940. */
  941. static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level)
  942. {
  943. struct token t;
  944. char *s, *b, *label_name;
  945. int err;
  946. b = p;
  947. if (nest_level > MAX_NEST_LEVEL) {
  948. printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL);
  949. return -EMLINK;
  950. }
  951. while (1) {
  952. s = p;
  953. get_token(&p, &t, L_KEYWORD);
  954. err = 0;
  955. switch (t.type) {
  956. case T_MENU:
  957. cfg->prompt = 1;
  958. err = parse_menu(&p, cfg, b, nest_level);
  959. break;
  960. case T_TIMEOUT:
  961. err = parse_integer(&p, &cfg->timeout);
  962. break;
  963. case T_LABEL:
  964. err = parse_label(&p, cfg);
  965. break;
  966. case T_DEFAULT:
  967. case T_ONTIMEOUT:
  968. err = parse_sliteral(&p, &label_name);
  969. if (label_name) {
  970. if (cfg->default_label)
  971. free(cfg->default_label);
  972. cfg->default_label = label_name;
  973. }
  974. break;
  975. case T_INCLUDE:
  976. err = handle_include(&p, b + ALIGN(strlen(b), 4), cfg,
  977. nest_level + 1);
  978. break;
  979. case T_PROMPT:
  980. eol_or_eof(&p);
  981. break;
  982. case T_EOL:
  983. break;
  984. case T_EOF:
  985. return 1;
  986. default:
  987. printf("Ignoring unknown command: %.*s\n",
  988. (int)(p - s), s);
  989. eol_or_eof(&p);
  990. }
  991. if (err < 0)
  992. return err;
  993. }
  994. }
  995. /*
  996. * Free the memory used by a pxe_menu and its labels.
  997. */
  998. static void destroy_pxe_menu(struct pxe_menu *cfg)
  999. {
  1000. struct list_head *pos, *n;
  1001. struct pxe_label *label;
  1002. if (cfg->title)
  1003. free(cfg->title);
  1004. if (cfg->default_label)
  1005. free(cfg->default_label);
  1006. list_for_each_safe(pos, n, &cfg->labels) {
  1007. label = list_entry(pos, struct pxe_label, list);
  1008. label_destroy(label);
  1009. }
  1010. free(cfg);
  1011. }
  1012. /*
  1013. * Entry point for parsing a pxe file. This is only used for the top level
  1014. * file.
  1015. *
  1016. * Returns NULL if there is an error, otherwise, returns a pointer to a
  1017. * pxe_menu struct populated with the results of parsing the pxe file (and any
  1018. * files it includes). The resulting pxe_menu struct can be free()'d by using
  1019. * the destroy_pxe_menu() function.
  1020. */
  1021. static struct pxe_menu *parse_pxefile(char *menucfg)
  1022. {
  1023. struct pxe_menu *cfg;
  1024. cfg = malloc(sizeof(struct pxe_menu));
  1025. if (!cfg)
  1026. return NULL;
  1027. memset(cfg, 0, sizeof(struct pxe_menu));
  1028. INIT_LIST_HEAD(&cfg->labels);
  1029. if (parse_pxefile_top(menucfg, cfg, 1) < 0) {
  1030. destroy_pxe_menu(cfg);
  1031. return NULL;
  1032. }
  1033. return cfg;
  1034. }
  1035. /*
  1036. * Converts a pxe_menu struct into a menu struct for use with U-boot's generic
  1037. * menu code.
  1038. */
  1039. static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
  1040. {
  1041. struct pxe_label *label;
  1042. struct list_head *pos;
  1043. struct menu *m;
  1044. int err;
  1045. int i = 1;
  1046. char *default_num = NULL;
  1047. /*
  1048. * Create a menu and add items for all the labels.
  1049. */
  1050. m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print,
  1051. NULL, NULL);
  1052. if (!m)
  1053. return NULL;
  1054. list_for_each(pos, &cfg->labels) {
  1055. label = list_entry(pos, struct pxe_label, list);
  1056. sprintf(label->num, "%d", i++);
  1057. if (menu_item_add(m, label->num, label) != 1) {
  1058. menu_destroy(m);
  1059. return NULL;
  1060. }
  1061. if (cfg->default_label &&
  1062. (strcmp(label->name, cfg->default_label) == 0))
  1063. default_num = label->num;
  1064. }
  1065. /*
  1066. * After we've created items for each label in the menu, set the
  1067. * menu's default label if one was specified.
  1068. */
  1069. if (default_num) {
  1070. err = menu_default_set(m, default_num);
  1071. if (err != 1) {
  1072. if (err != -ENOENT) {
  1073. menu_destroy(m);
  1074. return NULL;
  1075. }
  1076. printf("Missing default: %s\n", cfg->default_label);
  1077. }
  1078. }
  1079. return m;
  1080. }
  1081. /*
  1082. * Try to boot any labels we have yet to attempt to boot.
  1083. */
  1084. static void boot_unattempted_labels(struct pxe_menu *cfg)
  1085. {
  1086. struct list_head *pos;
  1087. struct pxe_label *label;
  1088. list_for_each(pos, &cfg->labels) {
  1089. label = list_entry(pos, struct pxe_label, list);
  1090. if (!label->attempted)
  1091. label_boot(label);
  1092. }
  1093. }
  1094. /*
  1095. * Boot the system as prescribed by a pxe_menu.
  1096. *
  1097. * Use the menu system to either get the user's choice or the default, based
  1098. * on config or user input. If there is no default or user's choice,
  1099. * attempted to boot labels in the order they were given in pxe files.
  1100. * If the default or user's choice fails to boot, attempt to boot other
  1101. * labels in the order they were given in pxe files.
  1102. *
  1103. * If this function returns, there weren't any labels that successfully
  1104. * booted, or the user interrupted the menu selection via ctrl+c.
  1105. */
  1106. static void handle_pxe_menu(struct pxe_menu *cfg)
  1107. {
  1108. void *choice;
  1109. struct menu *m;
  1110. int err;
  1111. m = pxe_menu_to_menu(cfg);
  1112. if (!m)
  1113. return;
  1114. err = menu_get_choice(m, &choice);
  1115. menu_destroy(m);
  1116. /*
  1117. * err == 1 means we got a choice back from menu_get_choice.
  1118. *
  1119. * err == -ENOENT if the menu was setup to select the default but no
  1120. * default was set. in that case, we should continue trying to boot
  1121. * labels that haven't been attempted yet.
  1122. *
  1123. * otherwise, the user interrupted or there was some other error and
  1124. * we give up.
  1125. */
  1126. if (err == 1) {
  1127. err = label_boot(choice);
  1128. if (!err)
  1129. return;
  1130. } else if (err != -ENOENT) {
  1131. return;
  1132. }
  1133. boot_unattempted_labels(cfg);
  1134. }
  1135. /*
  1136. * Boots a system using a pxe file
  1137. *
  1138. * Returns 0 on success, 1 on error.
  1139. */
  1140. static int
  1141. do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1142. {
  1143. unsigned long pxefile_addr_r;
  1144. struct pxe_menu *cfg;
  1145. char *pxefile_addr_str;
  1146. do_getfile = do_get_tftp;
  1147. if (argc == 1) {
  1148. pxefile_addr_str = from_env("pxefile_addr_r");
  1149. if (!pxefile_addr_str)
  1150. return 1;
  1151. } else if (argc == 2) {
  1152. pxefile_addr_str = argv[1];
  1153. } else {
  1154. return CMD_RET_USAGE;
  1155. }
  1156. if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
  1157. printf("Invalid pxefile address: %s\n", pxefile_addr_str);
  1158. return 1;
  1159. }
  1160. cfg = parse_pxefile((char *)(pxefile_addr_r));
  1161. if (cfg == NULL) {
  1162. printf("Error parsing config file\n");
  1163. return 1;
  1164. }
  1165. handle_pxe_menu(cfg);
  1166. destroy_pxe_menu(cfg);
  1167. return 0;
  1168. }
  1169. static cmd_tbl_t cmd_pxe_sub[] = {
  1170. U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
  1171. U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
  1172. };
  1173. int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1174. {
  1175. cmd_tbl_t *cp;
  1176. if (argc < 2)
  1177. return CMD_RET_USAGE;
  1178. /* drop initial "pxe" arg */
  1179. argc--;
  1180. argv++;
  1181. cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub));
  1182. if (cp)
  1183. return cp->cmd(cmdtp, flag, argc, argv);
  1184. return CMD_RET_USAGE;
  1185. }
  1186. U_BOOT_CMD(
  1187. pxe, 3, 1, do_pxe,
  1188. "commands to get and boot from pxe files",
  1189. "get - try to retrieve a pxe file using tftp\npxe "
  1190. "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n"
  1191. );
  1192. /*
  1193. * Boots a system using a local disk syslinux/extlinux file
  1194. *
  1195. * Returns 0 on success, 1 on error.
  1196. */
  1197. int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1198. {
  1199. unsigned long pxefile_addr_r;
  1200. struct pxe_menu *cfg;
  1201. char *pxefile_addr_str;
  1202. char *filename;
  1203. int prompt = 0;
  1204. if (strstr(argv[1], "-p")) {
  1205. prompt = 1;
  1206. argc--;
  1207. argv++;
  1208. }
  1209. if (argc < 4)
  1210. return cmd_usage(cmdtp);
  1211. if (argc < 5) {
  1212. pxefile_addr_str = from_env("pxefile_addr_r");
  1213. if (!pxefile_addr_str)
  1214. return 1;
  1215. } else {
  1216. pxefile_addr_str = argv[4];
  1217. }
  1218. if (argc < 6)
  1219. filename = getenv("bootfile");
  1220. else {
  1221. filename = argv[5];
  1222. setenv("bootfile", filename);
  1223. }
  1224. if (strstr(argv[3], "ext2"))
  1225. do_getfile = do_get_ext2;
  1226. else if (strstr(argv[3], "fat"))
  1227. do_getfile = do_get_fat;
  1228. else {
  1229. printf("Invalid filesystem: %s\n", argv[3]);
  1230. return 1;
  1231. }
  1232. fs_argv[1] = argv[1];
  1233. fs_argv[2] = argv[2];
  1234. if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) {
  1235. printf("Invalid pxefile address: %s\n", pxefile_addr_str);
  1236. return 1;
  1237. }
  1238. if (get_pxe_file(filename, (void *)pxefile_addr_r) < 0) {
  1239. printf("Error reading config file\n");
  1240. return 1;
  1241. }
  1242. cfg = parse_pxefile((char *)(pxefile_addr_r));
  1243. if (cfg == NULL) {
  1244. printf("Error parsing config file\n");
  1245. return 1;
  1246. }
  1247. if (prompt)
  1248. cfg->prompt = 1;
  1249. handle_pxe_menu(cfg);
  1250. destroy_pxe_menu(cfg);
  1251. return 0;
  1252. }
  1253. U_BOOT_CMD(
  1254. sysboot, 7, 1, do_sysboot,
  1255. "command to get and boot from syslinux files",
  1256. "[-p] <interface> <dev[:part]> <ext2|fat> [addr] [filename]\n"
  1257. " - load and parse syslinux menu file 'filename' from ext2 or fat\n"
  1258. " filesystem on 'dev' on 'interface' to address 'addr'"
  1259. );