cmd_pxe.c 33 KB

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