2002-08-27 13:55:31 +08: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Boot support
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <net.h>
|
|
|
|
|
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_NET)
|
|
|
|
|
2007-06-23 01:11:54 +08:00
|
|
|
#ifdef CONFIG_SHOW_BOOT_PROGRESS
|
|
|
|
# include <status_led.h>
|
|
|
|
extern void show_boot_progress (int val);
|
|
|
|
# define SHOW_BOOT_PROGRESS(arg) show_boot_progress (arg)
|
|
|
|
#else
|
|
|
|
# define SHOW_BOOT_PROGRESS(arg)
|
|
|
|
#endif
|
2002-08-27 13:55:31 +08:00
|
|
|
|
|
|
|
extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
|
|
|
|
|
2005-04-06 07:32:21 +08:00
|
|
|
static int netboot_common (proto_t, cmd_tbl_t *, int , char *[]);
|
2002-08-27 13:55:31 +08:00
|
|
|
|
|
|
|
int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return netboot_common (BOOTP, cmdtp, argc, argv);
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
bootp, 3, 1, do_bootp,
|
2004-06-09 20:42:26 +08:00
|
|
|
"bootp\t- boot image via network using BootP/TFTP protocol\n",
|
2003-06-28 05:31:46 +08:00
|
|
|
"[loadAddress] [bootfilename]\n"
|
|
|
|
);
|
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return netboot_common (TFTP, cmdtp, argc, argv);
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
tftpboot, 3, 1, do_tftpb,
|
2003-06-29 07:18:28 +08:00
|
|
|
"tftpboot- boot image via network using TFTP protocol\n",
|
2003-06-28 05:31:46 +08:00
|
|
|
"[loadAddress] [bootfilename]\n"
|
|
|
|
);
|
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return netboot_common (RARP, cmdtp, argc, argv);
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
rarpboot, 3, 1, do_rarpb,
|
2003-06-28 05:31:46 +08:00
|
|
|
"rarpboot- boot image via network using RARP/TFTP protocol\n",
|
|
|
|
"[loadAddress] [bootfilename]\n"
|
|
|
|
);
|
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_DHCP)
|
|
|
|
int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return netboot_common(DHCP, cmdtp, argc, argv);
|
|
|
|
}
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
dhcp, 3, 1, do_dhcp,
|
2004-06-09 20:42:26 +08:00
|
|
|
"dhcp\t- invoke DHCP client to obtain IP/boot params\n",
|
2003-06-28 05:31:46 +08:00
|
|
|
"\n"
|
|
|
|
);
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif /* CFG_CMD_DHCP */
|
|
|
|
|
2004-02-24 10:00:03 +08:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_NFS)
|
|
|
|
int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return netboot_common(NFS, cmdtp, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
nfs, 3, 1, do_nfs,
|
2004-06-09 20:42:26 +08:00
|
|
|
"nfs\t- boot image via network using NFS protocol\n",
|
2004-02-24 10:00:03 +08:00
|
|
|
"[loadAddress] [host ip addr:bootfilename]\n"
|
|
|
|
);
|
|
|
|
#endif /* CFG_CMD_NFS */
|
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
static void netboot_update_env (void)
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
2004-04-19 01:39:38 +08:00
|
|
|
char tmp[22];
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurGatewayIP) {
|
|
|
|
ip_to_string (NetOurGatewayIP, tmp);
|
|
|
|
setenv ("gatewayip", tmp);
|
|
|
|
}
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurSubnetMask) {
|
|
|
|
ip_to_string (NetOurSubnetMask, tmp);
|
|
|
|
setenv ("netmask", tmp);
|
|
|
|
}
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurHostName[0])
|
|
|
|
setenv ("hostname", NetOurHostName);
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurRootPath[0])
|
|
|
|
setenv ("rootpath", NetOurRootPath);
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurIP) {
|
|
|
|
ip_to_string (NetOurIP, tmp);
|
|
|
|
setenv ("ipaddr", tmp);
|
|
|
|
}
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetServerIP) {
|
|
|
|
ip_to_string (NetServerIP, tmp);
|
|
|
|
setenv ("serverip", tmp);
|
|
|
|
}
|
2003-06-06 03:27:42 +08:00
|
|
|
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurDNSIP) {
|
|
|
|
ip_to_string (NetOurDNSIP, tmp);
|
|
|
|
setenv ("dnsip", tmp);
|
|
|
|
}
|
2003-08-28 22:17:32 +08:00
|
|
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurDNS2IP) {
|
|
|
|
ip_to_string (NetOurDNS2IP, tmp);
|
|
|
|
setenv ("dnsip2", tmp);
|
|
|
|
}
|
2003-08-28 22:17:32 +08:00
|
|
|
#endif
|
2004-04-19 01:39:38 +08:00
|
|
|
if (NetOurNISDomain[0])
|
|
|
|
setenv ("domain", NetOurNISDomain);
|
2005-04-01 08:25:43 +08:00
|
|
|
|
2005-04-03 06:37:54 +08:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
|
2005-04-01 08:25:43 +08:00
|
|
|
if (NetTimeOffset) {
|
|
|
|
sprintf (tmp, "%d", NetTimeOffset);
|
|
|
|
setenv ("timeoffset", tmp);
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-03 06:37:54 +08:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
|
2005-04-01 08:25:43 +08:00
|
|
|
if (NetNtpServerIP) {
|
|
|
|
ip_to_string (NetNtpServerIP, tmp);
|
|
|
|
setenv ("ntpserverip", tmp);
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-27 13:55:31 +08:00
|
|
|
}
|
2004-04-19 01:39:38 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
static int
|
2005-04-06 07:32:21 +08:00
|
|
|
netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int rcode = 0;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
/* pre-set load_addr */
|
|
|
|
if ((s = getenv("loadaddr")) != NULL) {
|
|
|
|
load_addr = simple_strtoul(s, NULL, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* only one arg - accept two forms:
|
|
|
|
* just load address, or just boot file name.
|
|
|
|
* The latter form must be written "filename" here.
|
|
|
|
*/
|
|
|
|
if (argv[1][0] == '"') { /* just boot filename */
|
|
|
|
copy_filename (BootFile, argv[1], sizeof(BootFile));
|
|
|
|
} else { /* load address */
|
|
|
|
load_addr = simple_strtoul(argv[1], NULL, 16);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
|
|
|
|
copy_filename (BootFile, argv[2], sizeof(BootFile));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: printf ("Usage:\n%s\n", cmdtp->usage);
|
2007-06-23 01:11:54 +08:00
|
|
|
SHOW_BOOT_PROGRESS(-80);
|
2002-08-27 13:55:31 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-06-23 01:11:54 +08:00
|
|
|
SHOW_BOOT_PROGRESS(80);
|
|
|
|
if ((size = NetLoop(proto)) < 0) {
|
|
|
|
SHOW_BOOT_PROGRESS(-81);
|
2002-08-27 13:55:31 +08:00
|
|
|
return 1;
|
2007-06-23 01:11:54 +08:00
|
|
|
}
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2007-06-23 01:11:54 +08:00
|
|
|
SHOW_BOOT_PROGRESS(81);
|
2002-08-27 13:55:31 +08:00
|
|
|
/* NetLoop ok, update environment */
|
|
|
|
netboot_update_env();
|
|
|
|
|
2002-11-11 10:11:37 +08:00
|
|
|
/* done if no file was loaded (no errors though) */
|
2007-06-23 01:11:54 +08:00
|
|
|
if (size == 0) {
|
|
|
|
SHOW_BOOT_PROGRESS(-82);
|
2002-11-11 10:11:37 +08:00
|
|
|
return 0;
|
2007-06-23 01:11:54 +08:00
|
|
|
}
|
2002-11-11 10:11:37 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
/* flush cache */
|
|
|
|
flush_cache(load_addr, size);
|
|
|
|
|
|
|
|
/* Loading ok, check if we should attempt an auto-start */
|
|
|
|
if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
|
|
|
|
char *local_args[2];
|
|
|
|
local_args[0] = argv[0];
|
|
|
|
local_args[1] = NULL;
|
|
|
|
|
|
|
|
printf ("Automatic boot of image at addr 0x%08lX ...\n",
|
|
|
|
load_addr);
|
2007-06-23 01:11:54 +08:00
|
|
|
SHOW_BOOT_PROGRESS(82);
|
2002-08-27 13:55:31 +08:00
|
|
|
rcode = do_bootm (cmdtp, 0, 1, local_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUTOSCRIPT
|
|
|
|
if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
|
|
|
|
printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
|
2007-06-23 01:11:54 +08:00
|
|
|
SHOW_BOOT_PROGRESS(83);
|
2002-08-27 13:55:31 +08:00
|
|
|
rcode = autoscript (load_addr);
|
|
|
|
}
|
2007-06-23 01:11:54 +08:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_SHOW_BOOT_PROGRESS)
|
|
|
|
if (rcode < 0)
|
|
|
|
SHOW_BOOT_PROGRESS(-83);
|
|
|
|
else
|
|
|
|
SHOW_BOOT_PROGRESS(84);
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2003-06-06 03:27:42 +08:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_PING)
|
|
|
|
int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc < 2)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
NetPingIP = string_to_ip(argv[1]);
|
|
|
|
if (NetPingIP == 0) {
|
|
|
|
printf ("Usage:\n%s\n", cmdtp->usage);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NetLoop(PING) < 0) {
|
|
|
|
printf("ping failed; host %s is not alive\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("host %s is alive\n", argv[1]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-07-15 15:45:49 +08:00
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
ping, 2, 1, do_ping,
|
2004-06-09 20:42:26 +08:00
|
|
|
"ping\t- send ICMP ECHO_REQUEST to network host\n",
|
2003-07-15 15:45:49 +08:00
|
|
|
"pingAddress\n"
|
|
|
|
);
|
2003-06-06 03:27:42 +08:00
|
|
|
#endif /* CFG_CMD_PING */
|
|
|
|
|
2004-04-16 05:48:45 +08:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_cdp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = NetLoop(CDP);
|
|
|
|
if (r < 0) {
|
|
|
|
printf("cdp failed; perhaps not a CISCO switch?\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cdp_update_env();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
cdp, 1, 1, do_cdp,
|
2004-06-09 20:42:26 +08:00
|
|
|
"cdp\t- Perform CDP network configuration\n",
|
2004-04-16 05:48:45 +08:00
|
|
|
);
|
|
|
|
#endif /* CFG_CMD_CDP */
|
|
|
|
|
2005-04-01 08:25:43 +08:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
|
|
|
|
int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *toff;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
NetNtpServerIP = getenv_IPaddr ("ntpserverip");
|
|
|
|
if (NetNtpServerIP == 0) {
|
|
|
|
printf ("ntpserverip not set\n");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NetNtpServerIP = string_to_ip(argv[1]);
|
|
|
|
if (NetNtpServerIP == 0) {
|
|
|
|
printf ("Bad NTP server IP address\n");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toff = getenv ("timeoffset");
|
|
|
|
if (toff == NULL) NetTimeOffset = 0;
|
|
|
|
else NetTimeOffset = simple_strtol (toff, NULL, 10);
|
|
|
|
|
|
|
|
if (NetLoop(SNTP) < 0) {
|
|
|
|
printf("SNTP failed: host %s not responding\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
sntp, 2, 1, do_sntp,
|
|
|
|
"sntp\t- synchronize RTC via network\n",
|
|
|
|
"[NTP server IP]\n"
|
|
|
|
);
|
|
|
|
#endif /* CFG_CMD_SNTP */
|
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif /* CFG_CMD_NET */
|