[U-Boot-Users] PATCH cmd_net.c check ethernet availability
Andrew Dyer
amdyer at gmail.com
Mon Oct 24 19:39:26 CEST 2005
We have a board where the ethernet is on a plugin module and may or
may not be present at boot time. If eth_initialize() doesn't detect the network
and a net command is run the system crashes. This patch adds a function
to cmd_net.c to check the availability of the ethernet device before trying to
access it. If the net device is not found it will print a message
and return -1.
* Add check to cmd_net functions to make sure ethernet device is valid
before calling Net_Loop()
Patch by Andrew Dyer, 24 Oct 2005
Signed-off-by: Andrew Dyer <amdyer at gmail.com>
--
Hardware, n.:
The parts of a computer system that can be kicked.
-------------- next part --------------
Index: common/cmd_net.c
===================================================================
RCS file: /home/cvsroot/Projects/u-boot/common/cmd_net.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -p -u -r1.1.1.1 -r1.2
--- common/cmd_net.c 28 Jun 2005 17:32:26 -0000 1.1.1.1
+++ common/cmd_net.c 24 Oct 2005 17:21:39 -0000 1.2
@@ -151,6 +151,17 @@ static void netboot_update_env (void)
#endif
}
+static int
+net_check_device(void)
+{
+ if(eth_get_dev() == NULL) {
+ printf("No network device available.\n");
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
static int
netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
{
@@ -158,6 +169,9 @@ netboot_common (proto_t proto, cmd_tbl_t
int rcode = 0;
int size;
+ if (net_check_device() < 0)
+ return -1;
+
/* pre-set load_addr */
if ((s = getenv("loadaddr")) != NULL) {
load_addr = simple_strtoul(s, NULL, 16);
@@ -226,6 +240,9 @@ int do_ping (cmd_tbl_t *cmdtp, int flag,
if (argc < 2)
return -1;
+ if(net_check_device() < 0)
+ return -1;
+
NetPingIP = string_to_ip(argv[1]);
if (NetPingIP == 0) {
printf ("Usage:\n%s\n", cmdtp->usage);
@@ -275,6 +292,9 @@ int do_cdp (cmd_tbl_t *cmdtp, int flag,
{
int r;
+ if(net_check_device() < 0)
+ return -1;
+
r = NetLoop(CDP);
if (r < 0) {
printf("cdp failed; perhaps not a CISCO switch?\n");
@@ -296,6 +316,9 @@ U_BOOT_CMD(
int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
char *toff;
+
+ if(net_check_device() < 0)
+ return -1;
if (argc < 2) {
NetNtpServerIP = getenv_IPaddr ("ntpserverip");
More information about the U-Boot
mailing list