Blame view
cmd/pxe.c
4.97 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
06283a640 Add pxe command |
2 3 |
/* * Copyright 2010-2011 Calxeda, Inc. |
1fb7d0e61 pxe: detect image... |
4 |
* Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. |
06283a640 Add pxe command |
5 |
*/ |
1a4596601 Add GPL-2.0+ SPDX... |
6 |
|
06283a640 Add pxe command |
7 8 |
#include <common.h> #include <command.h> |
144499823 common: Move func... |
9 |
#include <fs.h> |
77f4e477a common: Move do_t... |
10 |
#include <net.h> |
06283a640 Add pxe command |
11 |
|
2373cba3d cmd: Prepare sysb... |
12 |
#include "pxe_utils.h" |
06283a640 Add pxe command |
13 |
|
2373cba3d cmd: Prepare sysb... |
14 |
#ifdef CONFIG_CMD_NET |
39f985536 pxe: add support ... |
15 |
const char *pxe_default_paths[] = { |
58d9ff936 net: Fix build re... |
16 |
#ifdef CONFIG_SYS_SOC |
2455efa2e cmd: pxe: add boa... |
17 18 19 |
#ifdef CONFIG_SYS_BOARD "default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC "-" CONFIG_SYS_BOARD, #endif |
39f985536 pxe: add support ... |
20 |
"default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC, |
58d9ff936 net: Fix build re... |
21 |
#endif |
39f985536 pxe: add support ... |
22 23 24 25 |
"default-" CONFIG_SYS_ARCH, "default", NULL }; |
0e3f3f8a3 Prevent null poin... |
26 |
static int do_get_tftp(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr) |
669df7e42 pxe: add support ... |
27 28 29 30 |
{ char *tftp_argv[] = {"tftp", NULL, NULL, NULL}; tftp_argv[1] = file_addr; |
23b7194e6 pxe: make string ... |
31 |
tftp_argv[2] = (void *)file_path; |
669df7e42 pxe: add support ... |
32 |
|
0e3f3f8a3 Prevent null poin... |
33 |
if (do_tftpb(cmdtp, 0, 3, tftp_argv)) |
669df7e42 pxe: add support ... |
34 35 36 37 |
return -ENOENT; return 1; } |
b81fdb048 pxe: allow compil... |
38 |
|
06283a640 Add pxe command |
39 40 41 42 43 |
/* * Looks for a pxe file with a name based on the pxeuuid environment variable. * * Returns 1 on success or < 0 on error. */ |
4a0bd1020 pxe: Ensure all m... |
44 |
static int pxe_uuid_path(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r) |
06283a640 Add pxe command |
45 46 47 48 49 50 51 |
{ char *uuid_str; uuid_str = from_env("pxeuuid"); if (!uuid_str) return -ENOENT; |
0e3f3f8a3 Prevent null poin... |
52 |
return get_pxelinux_path(cmdtp, uuid_str, pxefile_addr_r); |
06283a640 Add pxe command |
53 54 55 56 57 58 59 60 |
} /* * Looks for a pxe file with a name based on the 'ethaddr' environment * variable. * * Returns 1 on success or < 0 on error. */ |
4a0bd1020 pxe: Ensure all m... |
61 |
static int pxe_mac_path(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r) |
06283a640 Add pxe command |
62 63 64 65 66 67 68 69 |
{ char mac_str[21]; int err; err = format_mac_pxe(mac_str, sizeof(mac_str)); if (err < 0) return err; |
0e3f3f8a3 Prevent null poin... |
70 |
return get_pxelinux_path(cmdtp, mac_str, pxefile_addr_r); |
06283a640 Add pxe command |
71 72 73 74 75 76 77 78 79 |
} /* * Looks for pxe files with names based on our IP address. See pxelinux * documentation for details on what these file names look like. We match * that exactly. * * Returns 1 on success or < 0 on error. */ |
4a0bd1020 pxe: Ensure all m... |
80 |
static int pxe_ipaddr_paths(cmd_tbl_t *cmdtp, unsigned long pxefile_addr_r) |
06283a640 Add pxe command |
81 82 83 |
{ char ip_addr[9]; int mask_pos, err; |
049a95a77 net: cosmetic: Ch... |
84 |
sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr)); |
06283a640 Add pxe command |
85 86 |
for (mask_pos = 7; mask_pos >= 0; mask_pos--) { |
0e3f3f8a3 Prevent null poin... |
87 |
err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r); |
06283a640 Add pxe command |
88 89 90 91 92 93 94 95 96 |
if (err > 0) return err; ip_addr[mask_pos] = '\0'; } return -ENOENT; } |
06283a640 Add pxe command |
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
/* * Entry point for the 'pxe get' command. * This Follows pxelinux's rules to download a config file from a tftp server. * The file is stored at the location given by the pxefile_addr_r environment * variable, which must be set. * * UUID comes from pxeuuid env variable, if defined * MAC addr comes from ethaddr env variable, if defined * IP * * see http://syslinux.zytor.com/wiki/index.php/PXELINUX * * Returns 0 on success or 1 on error. */ static int do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *pxefile_addr_str; |
834c9384a cmd_pxe.c: fix st... |
115 |
unsigned long pxefile_addr_r; |
39f985536 pxe: add support ... |
116 |
int err, i = 0; |
06283a640 Add pxe command |
117 |
|
669df7e42 pxe: add support ... |
118 |
do_getfile = do_get_tftp; |
06283a640 Add pxe command |
119 |
if (argc != 1) |
4c12eeb8b Convert cmd_usage... |
120 |
return CMD_RET_USAGE; |
06283a640 Add pxe command |
121 |
|
06283a640 Add pxe command |
122 123 124 125 126 127 |
pxefile_addr_str = from_env("pxefile_addr_r"); if (!pxefile_addr_str) return 1; err = strict_strtoul(pxefile_addr_str, 16, |
31839dc2d cmd: pxe: Fix che... |
128 |
(unsigned long *)&pxefile_addr_r); |
06283a640 Add pxe command |
129 130 131 132 133 134 135 |
if (err < 0) return 1; /* * Keep trying paths until we successfully get a file we're looking * for. */ |
4a0bd1020 pxe: Ensure all m... |
136 137 138 |
if (pxe_uuid_path(cmdtp, pxefile_addr_r) > 0 || pxe_mac_path(cmdtp, pxefile_addr_r) > 0 || pxe_ipaddr_paths(cmdtp, pxefile_addr_r) > 0) { |
06283a640 Add pxe command |
139 140 141 142 143 |
printf("Config file found "); return 0; } |
39f985536 pxe: add support ... |
144 |
while (pxe_default_paths[i]) { |
0e3f3f8a3 Prevent null poin... |
145 |
if (get_pxelinux_path(cmdtp, pxe_default_paths[i], |
4a0bd1020 pxe: Ensure all m... |
146 |
pxefile_addr_r) > 0) { |
39f985536 pxe: add support ... |
147 148 149 150 151 152 |
printf("Config file found "); return 0; } i++; } |
06283a640 Add pxe command |
153 154 155 156 157 |
printf("Config file not found "); return 1; } |
06283a640 Add pxe command |
158 159 |
/* |
06283a640 Add pxe command |
160 161 162 163 164 165 166 167 168 169 |
* Boots a system using a pxe file * * Returns 0 on success, 1 on error. */ static int do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned long pxefile_addr_r; struct pxe_menu *cfg; char *pxefile_addr_str; |
669df7e42 pxe: add support ... |
170 |
do_getfile = do_get_tftp; |
06283a640 Add pxe command |
171 172 173 174 175 176 177 178 |
if (argc == 1) { pxefile_addr_str = from_env("pxefile_addr_r"); if (!pxefile_addr_str) return 1; } else if (argc == 2) { pxefile_addr_str = argv[1]; } else { |
4c12eeb8b Convert cmd_usage... |
179 |
return CMD_RET_USAGE; |
06283a640 Add pxe command |
180 181 182 183 184 185 186 |
} if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) { printf("Invalid pxefile address: %s ", pxefile_addr_str); return 1; } |
4a0bd1020 pxe: Ensure all m... |
187 |
cfg = parse_pxefile(cmdtp, pxefile_addr_r); |
06283a640 Add pxe command |
188 |
|
31839dc2d cmd: pxe: Fix che... |
189 |
if (!cfg) { |
06283a640 Add pxe command |
190 191 192 193 |
printf("Error parsing config file "); return 1; } |
d7884e047 cmd_pxe.c: Pass a... |
194 |
handle_pxe_menu(cmdtp, cfg); |
06283a640 Add pxe command |
195 196 |
destroy_pxe_menu(cfg); |
1411157d8 net: cosmetic: Fi... |
197 |
copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name)); |
ded2e20ef pxe: clear Bootfi... |
198 |
|
06283a640 Add pxe command |
199 200 201 202 203 204 205 |
return 0; } static cmd_tbl_t cmd_pxe_sub[] = { U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""), U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "") }; |
0e350f81e common: commands:... |
206 |
static int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
06283a640 Add pxe command |
207 208 209 210 |
{ cmd_tbl_t *cp; if (argc < 2) |
4c12eeb8b Convert cmd_usage... |
211 |
return CMD_RET_USAGE; |
06283a640 Add pxe command |
212 |
|
e5a9a4076 pxe: fix handling... |
213 |
is_pxe = true; |
06283a640 Add pxe command |
214 215 216 217 218 219 220 221 |
/* drop initial "pxe" arg */ argc--; argv++; cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub)); if (cp) return cp->cmd(cmdtp, flag, argc, argv); |
4c12eeb8b Convert cmd_usage... |
222 |
return CMD_RET_USAGE; |
06283a640 Add pxe command |
223 |
} |
31839dc2d cmd: pxe: Fix che... |
224 225 226 227 228 229 |
U_BOOT_CMD(pxe, 3, 1, do_pxe, "commands to get and boot from pxe files", "get - try to retrieve a pxe file using tftp " "pxe boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r " |
06283a640 Add pxe command |
230 |
); |
b81fdb048 pxe: allow compil... |
231 |
#endif |