]>
Commit | Line | Data |
---|---|---|
993c912d PC |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | ||
3 | #include <common.h> | |
4 | #include <command.h> | |
5 | #include <env.h> | |
6 | #include <fs.h> | |
7 | #include "pxe_utils.h" | |
8 | ||
9 | static char *fs_argv[5]; | |
10 | ||
09140113 SG |
11 | static int do_get_ext2(struct cmd_tbl *cmdtp, const char *file_path, |
12 | char *file_addr) | |
993c912d PC |
13 | { |
14 | #ifdef CONFIG_CMD_EXT2 | |
15 | fs_argv[0] = "ext2load"; | |
16 | fs_argv[3] = file_addr; | |
17 | fs_argv[4] = (void *)file_path; | |
18 | ||
19 | if (!do_ext2load(cmdtp, 0, 5, fs_argv)) | |
20 | return 1; | |
21 | #endif | |
22 | return -ENOENT; | |
23 | } | |
24 | ||
09140113 SG |
25 | static int do_get_fat(struct cmd_tbl *cmdtp, const char *file_path, |
26 | char *file_addr) | |
993c912d PC |
27 | { |
28 | #ifdef CONFIG_CMD_FAT | |
29 | fs_argv[0] = "fatload"; | |
30 | fs_argv[3] = file_addr; | |
31 | fs_argv[4] = (void *)file_path; | |
32 | ||
33 | if (!do_fat_fsload(cmdtp, 0, 5, fs_argv)) | |
34 | return 1; | |
35 | #endif | |
36 | return -ENOENT; | |
37 | } | |
38 | ||
09140113 SG |
39 | static int do_get_any(struct cmd_tbl *cmdtp, const char *file_path, |
40 | char *file_addr) | |
993c912d PC |
41 | { |
42 | #ifdef CONFIG_CMD_FS_GENERIC | |
43 | fs_argv[0] = "load"; | |
44 | fs_argv[3] = file_addr; | |
45 | fs_argv[4] = (void *)file_path; | |
46 | ||
47 | if (!do_load(cmdtp, 0, 5, fs_argv, FS_TYPE_ANY)) | |
48 | return 1; | |
49 | #endif | |
50 | return -ENOENT; | |
51 | } | |
52 | ||
53 | /* | |
54 | * Boots a system using a local disk syslinux/extlinux file | |
55 | * | |
56 | * Returns 0 on success, 1 on error. | |
57 | */ | |
09140113 SG |
58 | static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, |
59 | char *const argv[]) | |
993c912d PC |
60 | { |
61 | unsigned long pxefile_addr_r; | |
62 | struct pxe_menu *cfg; | |
63 | char *pxefile_addr_str; | |
64 | char *filename; | |
65 | int prompt = 0; | |
66 | ||
67 | is_pxe = false; | |
68 | ||
69 | if (argc > 1 && strstr(argv[1], "-p")) { | |
70 | prompt = 1; | |
71 | argc--; | |
72 | argv++; | |
73 | } | |
74 | ||
75 | if (argc < 4) | |
76 | return cmd_usage(cmdtp); | |
77 | ||
78 | if (argc < 5) { | |
79 | pxefile_addr_str = from_env("pxefile_addr_r"); | |
80 | if (!pxefile_addr_str) | |
81 | return 1; | |
82 | } else { | |
83 | pxefile_addr_str = argv[4]; | |
84 | } | |
85 | ||
51843eab | 86 | if (argc < 6) { |
993c912d | 87 | filename = env_get("bootfile"); |
51843eab | 88 | } else { |
993c912d PC |
89 | filename = argv[5]; |
90 | env_set("bootfile", filename); | |
91 | } | |
92 | ||
51843eab | 93 | if (strstr(argv[3], "ext2")) { |
993c912d | 94 | do_getfile = do_get_ext2; |
51843eab | 95 | } else if (strstr(argv[3], "fat")) { |
993c912d | 96 | do_getfile = do_get_fat; |
51843eab | 97 | } else if (strstr(argv[3], "any")) { |
993c912d | 98 | do_getfile = do_get_any; |
51843eab | 99 | } else { |
993c912d PC |
100 | printf("Invalid filesystem: %s\n", argv[3]); |
101 | return 1; | |
102 | } | |
103 | fs_argv[1] = argv[1]; | |
104 | fs_argv[2] = argv[2]; | |
105 | ||
106 | if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) { | |
107 | printf("Invalid pxefile address: %s\n", pxefile_addr_str); | |
108 | return 1; | |
109 | } | |
110 | ||
111 | if (get_pxe_file(cmdtp, filename, pxefile_addr_r) < 0) { | |
112 | printf("Error reading config file\n"); | |
113 | return 1; | |
114 | } | |
115 | ||
116 | cfg = parse_pxefile(cmdtp, pxefile_addr_r); | |
117 | ||
51843eab | 118 | if (!cfg) { |
993c912d PC |
119 | printf("Error parsing config file\n"); |
120 | return 1; | |
121 | } | |
122 | ||
123 | if (prompt) | |
124 | cfg->prompt = 1; | |
125 | ||
126 | handle_pxe_menu(cmdtp, cfg); | |
127 | ||
128 | destroy_pxe_menu(cfg); | |
129 | ||
130 | return 0; | |
131 | } | |
132 | ||
51843eab PC |
133 | U_BOOT_CMD(sysboot, 7, 1, do_sysboot, |
134 | "command to get and boot from syslinux files", | |
135 | "[-p] <interface> <dev[:part]> <ext2|fat|any> [addr] [filename]\n" | |
136 | " - load and parse syslinux menu file 'filename' from ext2, fat\n" | |
137 | " or any filesystem on 'dev' on 'interface' to address 'addr'" | |
993c912d | 138 | ); |