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