2002-08-27 05:55:31 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2007-11-08 11:01:52 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief tftp, rarpboot, dhcp, nfs, cdp - Boot support
|
|
|
|
*/
|
|
|
|
|
2002-08-27 05:55:31 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2007-07-05 16:01:44 +00:00
|
|
|
#include <environment.h>
|
2007-07-05 16:01:32 +00:00
|
|
|
#include <driver.h>
|
2002-08-27 05:55:31 +00:00
|
|
|
#include <net.h>
|
2007-07-05 16:01:38 +00:00
|
|
|
#include <fs.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2007-09-28 08:47:19 +00:00
|
|
|
#include <libbb.h>
|
2008-03-31 19:48:27 +00:00
|
|
|
#include <libgen.h>
|
2002-08-27 05:55:31 +00:00
|
|
|
|
2005-04-05 23:32:21 +00:00
|
|
|
static int netboot_common (proto_t, cmd_tbl_t *, int , char *[]);
|
2002-08-27 05:55:31 +00:00
|
|
|
|
2009-08-19 13:15:51 +00:00
|
|
|
void netboot_update_env(void)
|
2007-07-05 16:01:34 +00:00
|
|
|
{
|
2007-07-05 16:01:34 +00:00
|
|
|
struct eth_device *eth_current = eth_get_current();
|
2007-07-05 16:01:34 +00:00
|
|
|
char tmp[22];
|
|
|
|
|
2007-07-05 16:01:34 +00:00
|
|
|
if (NetOurGatewayIP)
|
2009-06-11 13:33:49 +00:00
|
|
|
dev_set_param_ip(ð_current->dev, "gateway", NetOurGatewayIP);
|
2007-07-05 16:01:34 +00:00
|
|
|
|
|
|
|
if (NetOurSubnetMask)
|
2009-06-11 13:33:49 +00:00
|
|
|
dev_set_param_ip(ð_current->dev, "netmask", NetOurSubnetMask);
|
2007-07-05 16:01:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (NetOurHostName[0])
|
|
|
|
setenv ("hostname", NetOurHostName);
|
|
|
|
|
|
|
|
if (NetOurRootPath[0])
|
|
|
|
setenv ("rootpath", NetOurRootPath);
|
|
|
|
|
2007-07-05 16:01:34 +00:00
|
|
|
if (NetOurIP)
|
2009-06-11 13:33:49 +00:00
|
|
|
dev_set_param_ip(ð_current->dev, "ipaddr", NetOurIP);
|
2007-07-05 16:01:34 +00:00
|
|
|
|
2007-07-05 16:01:34 +00:00
|
|
|
if (NetServerIP)
|
2009-06-11 13:33:49 +00:00
|
|
|
dev_set_param_ip(ð_current->dev, "serverip", NetServerIP);
|
2007-07-05 16:01:34 +00:00
|
|
|
|
|
|
|
if (NetOurDNSIP) {
|
|
|
|
ip_to_string (NetOurDNSIP, tmp);
|
|
|
|
setenv ("dnsip", tmp);
|
|
|
|
}
|
2008-04-07 09:40:19 +00:00
|
|
|
#ifdef CONFIG_BOOTP_DNS2
|
2007-07-05 16:01:34 +00:00
|
|
|
if (NetOurDNS2IP) {
|
|
|
|
ip_to_string (NetOurDNS2IP, tmp);
|
|
|
|
setenv ("dnsip2", tmp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (NetOurNISDomain[0])
|
|
|
|
setenv ("domain", NetOurNISDomain);
|
|
|
|
}
|
|
|
|
|
2007-09-28 08:07:26 +00:00
|
|
|
static int do_tftpb (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
2002-08-27 05:55:31 +00:00
|
|
|
{
|
|
|
|
return netboot_common (TFTP, cmdtp, argc, argv);
|
|
|
|
}
|
|
|
|
|
2008-04-04 09:46:55 +00:00
|
|
|
static const __maybe_unused char cmd_tftp_help[] =
|
2007-10-04 11:05:56 +00:00
|
|
|
"Usage: tftp <file> [localfile]\n"
|
|
|
|
"Load a file via network using BootP/TFTP protocol.\n";
|
2007-07-05 16:01:55 +00:00
|
|
|
|
2007-10-04 11:05:56 +00:00
|
|
|
U_BOOT_CMD_START(tftp)
|
2007-07-05 16:01:52 +00:00
|
|
|
.cmd = do_tftpb,
|
2007-10-04 11:05:56 +00:00
|
|
|
.usage = "Load file using tftp protocol",
|
|
|
|
U_BOOT_CMD_HELP(cmd_tftp_help)
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_END
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2007-11-08 11:01:52 +00:00
|
|
|
/**
|
|
|
|
* @page tftp_command tftp
|
|
|
|
*
|
|
|
|
* Usage is: tftp \<filename\> [\<localfilename\>]
|
|
|
|
*
|
2007-11-09 13:05:23 +00:00
|
|
|
* Load a file via network using BootP/TFTP protocol. The loaded file you
|
|
|
|
* can find after download in you current ramdisk. Refer \b ls command.
|
|
|
|
*
|
|
|
|
* \<localfile> can be the local filename only, or also a device name. In the
|
|
|
|
* case of a device name, the will gets stored there. This works also for
|
|
|
|
* partitions of flash memory. Refer \b erase, \b unprotect for flash
|
|
|
|
* preparation.
|
|
|
|
*
|
|
|
|
* Note: This command is available only, if enabled in the menuconfig.
|
2007-11-08 11:01:52 +00:00
|
|
|
*/
|
|
|
|
|
2007-10-04 11:05:56 +00:00
|
|
|
#ifdef CONFIG_NET_RARP
|
2009-08-19 13:14:04 +00:00
|
|
|
extern void RarpRequest(void);
|
|
|
|
|
2007-09-28 08:07:26 +00:00
|
|
|
static int do_rarpb (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
2002-08-27 05:55:31 +00:00
|
|
|
{
|
2009-08-19 13:14:04 +00:00
|
|
|
int size;
|
|
|
|
|
|
|
|
if (NetLoopInit(RARP) < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
NetOurIP = 0;
|
|
|
|
RarpRequest(); /* Basically same as BOOTP */
|
|
|
|
|
|
|
|
if ((size = NetLoop()) < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* NetLoop ok, update environment */
|
|
|
|
netboot_update_env();
|
|
|
|
|
|
|
|
return 0;
|
2002-08-27 05:55:31 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_START(rarpboot)
|
|
|
|
.cmd = do_rarpb,
|
2007-07-05 16:02:05 +00:00
|
|
|
.usage = "boot image via network using rarp/tftp protocol",
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_HELP("[loadAddress] [bootfilename]\n")
|
|
|
|
U_BOOT_CMD_END
|
2007-10-04 11:05:56 +00:00
|
|
|
#endif /* CONFIG_NET_RARP */
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2007-07-05 16:01:24 +00:00
|
|
|
#ifdef CONFIG_NET_NFS
|
2007-09-28 08:07:26 +00:00
|
|
|
static int do_nfs (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
2004-02-24 02:00:03 +00:00
|
|
|
{
|
|
|
|
return netboot_common(NFS, cmdtp, argc, argv);
|
|
|
|
}
|
|
|
|
|
2008-04-04 09:46:55 +00:00
|
|
|
static const __maybe_unused char cmd_nfs_help[] =
|
2007-10-04 11:05:56 +00:00
|
|
|
"Usage: nfs <file> [localfile]\n"
|
|
|
|
"Load a file via network using nfs protocol.\n";
|
|
|
|
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_START(nfs)
|
|
|
|
.cmd = do_nfs,
|
2007-07-05 16:02:05 +00:00
|
|
|
.usage = "boot image via network using nfs protocol",
|
2007-10-04 11:05:56 +00:00
|
|
|
U_BOOT_CMD_HELP(cmd_nfs_help)
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_END
|
|
|
|
|
2007-07-05 16:01:24 +00:00
|
|
|
#endif /* CONFIG_NET_NFS */
|
2004-02-24 02:00:03 +00:00
|
|
|
|
2007-07-05 16:01:38 +00:00
|
|
|
int net_store_fd;
|
2007-07-05 16:01:32 +00:00
|
|
|
|
2009-10-17 07:58:29 +00:00
|
|
|
extern void TftpStart(char *); /* Begin TFTP get */
|
|
|
|
extern void NfsStart(char *);
|
2009-08-19 13:00:06 +00:00
|
|
|
|
2002-08-27 05:55:31 +00:00
|
|
|
static int
|
2005-04-05 23:32:21 +00:00
|
|
|
netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
|
2002-08-27 05:55:31 +00:00
|
|
|
{
|
|
|
|
int rcode = 0;
|
2007-07-05 16:01:24 +00:00
|
|
|
int size;
|
2007-10-04 11:05:56 +00:00
|
|
|
char *localfile;
|
|
|
|
char *remotefile;
|
2002-08-27 05:55:31 +00:00
|
|
|
|
2009-10-17 10:44:19 +00:00
|
|
|
if (argc < 2)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
2007-07-05 16:01:32 +00:00
|
|
|
|
2007-10-04 11:05:56 +00:00
|
|
|
remotefile = argv[1];
|
|
|
|
|
|
|
|
if (argc == 2)
|
2008-03-31 19:48:27 +00:00
|
|
|
localfile = basename(remotefile);
|
2007-10-04 11:05:56 +00:00
|
|
|
else
|
|
|
|
localfile = argv[2];
|
|
|
|
|
|
|
|
net_store_fd = open(localfile, O_WRONLY | O_CREAT);
|
2007-07-05 16:01:38 +00:00
|
|
|
if (net_store_fd < 0) {
|
|
|
|
perror("open");
|
|
|
|
return 1;
|
2002-08-27 05:55:31 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 12:20:13 +00:00
|
|
|
if (NetLoopInit(proto) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2009-08-19 13:00:06 +00:00
|
|
|
switch (proto) {
|
|
|
|
case TFTP:
|
2009-10-17 07:58:29 +00:00
|
|
|
TftpStart(remotefile);
|
2009-08-19 13:00:06 +00:00
|
|
|
break;
|
|
|
|
case NFS:
|
2009-10-17 07:58:29 +00:00
|
|
|
NfsStart(remotefile);
|
2009-08-19 13:00:06 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((size = NetLoop()) < 0) {
|
2008-03-10 22:56:47 +00:00
|
|
|
rcode = size;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-08-27 05:55:31 +00:00
|
|
|
|
|
|
|
/* NetLoop ok, update environment */
|
|
|
|
netboot_update_env();
|
|
|
|
|
2008-03-10 22:56:47 +00:00
|
|
|
out:
|
|
|
|
close(net_store_fd);
|
2002-08-27 05:55:31 +00:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2007-10-16 17:07:21 +00:00
|
|
|
#ifdef CONFIG_NET_CDP
|
2004-04-15 21:48:45 +00:00
|
|
|
|
|
|
|
static void cdp_update_env(void)
|
|
|
|
{
|
|
|
|
char tmp[16];
|
|
|
|
|
|
|
|
if (CDPApplianceVLAN != htons(-1)) {
|
|
|
|
printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN));
|
|
|
|
VLAN_to_string(CDPApplianceVLAN, tmp);
|
|
|
|
setenv("vlan", tmp);
|
|
|
|
NetOurVLAN = CDPApplianceVLAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CDPNativeVLAN != htons(-1)) {
|
|
|
|
printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN));
|
|
|
|
VLAN_to_string(CDPNativeVLAN, tmp);
|
|
|
|
setenv("nvlan", tmp);
|
|
|
|
NetOurNativeVLAN = CDPNativeVLAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-28 08:07:26 +00:00
|
|
|
static int do_cdp (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
2004-04-15 21:48:45 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2009-08-19 12:20:13 +00:00
|
|
|
if (NetLoopInit(CDP) < 0)
|
|
|
|
return 1;
|
|
|
|
|
2009-08-19 13:00:06 +00:00
|
|
|
r = NetLoop();
|
2004-04-15 21:48:45 +00:00
|
|
|
if (r < 0) {
|
|
|
|
printf("cdp failed; perhaps not a CISCO switch?\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cdp_update_env();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_START(cdp)
|
|
|
|
.cmd = do_cdp,
|
2007-07-05 16:01:55 +00:00
|
|
|
.usage = "Perform CDP network configuration",
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_HELP("[loadAddress] [host ip addr:bootfilename]\n")
|
|
|
|
U_BOOT_CMD_END
|
|
|
|
|
2007-10-16 17:07:21 +00:00
|
|
|
#endif /* CONFIG_NET_CDP */
|
2009-02-27 00:09:26 +00:00
|
|
|
|
|
|
|
static int do_ethact (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct eth_device *edev;
|
|
|
|
|
2009-09-09 09:44:35 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
edev = eth_get_current();
|
|
|
|
if (edev)
|
|
|
|
printf("%s%d\n", edev->dev.name, edev->dev.id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-17 10:44:19 +00:00
|
|
|
if (argc != 2)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
2009-02-27 00:09:26 +00:00
|
|
|
|
2009-06-10 17:44:14 +00:00
|
|
|
edev = eth_get_byname(argv[1]);
|
|
|
|
if (edev)
|
|
|
|
eth_set_current(edev);
|
|
|
|
else {
|
|
|
|
printf("no such net device: %s\n", argv[1]);
|
2009-02-27 00:09:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const __maybe_unused char cmd_ethact_help[] =
|
2009-09-09 09:44:35 +00:00
|
|
|
"Usage: ethact [ethx]\n";
|
2009-02-27 00:09:26 +00:00
|
|
|
|
|
|
|
U_BOOT_CMD_START(ethact)
|
|
|
|
.cmd = do_ethact,
|
|
|
|
.usage = "set current ethernet device",
|
|
|
|
U_BOOT_CMD_HELP(cmd_ethact_help)
|
|
|
|
U_BOOT_CMD_END
|
|
|
|
|