Subversion Repositories livecd

Rev

Rev 102 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 102 Rev 104
Line 458... Line 458...
458
 
458
 
459
# load network modules, if NFSROOT is set
459
# load network modules, if NFSROOT is set
460
# Urs Beyerle, PSI
460
# Urs Beyerle, PSI
461
#
461
#
462
 
462
 
-
 
463
# 1. load network driver defined by kernel parameter nic
-
 
464
#
463
load_network_modules()
465
load_network_module_nic()
464
{
466
{
465
    # mii maybe need by NIC
-
 
466
    echolog "load module mii"
-
 
467
    modprobe_module mii
-
 
468
 
-
 
469
    FOUND_NIC=""
-
 
470
 
-
 
471
    # 1. load network driver defined by kernel parameter nic
-
 
472
    NIC="`cmdline_value nic`"
-
 
473
    if [ -n "$NIC" ]; then
467
    if [ -n "$NIC" ] && [ "$NIC" != "auto" ]; then
474
	echolog "load module $NIC"
468
	echolog "load module $NIC"
475
	modprobe_module nic
469
	modprobe_module $NIC
-
 
470
        # FOUND_NIC="yes" # we are not yet sure ;-)
476
    fi
471
    fi
-
 
472
}
477
 
473
 
478
    # 2. detecting network card from pcitable list
474
# 2. detecting network card from pcitable list
-
 
475
#
-
 
476
load_network_module_pcitable()
-
 
477
{
479
    PCITABLE=/bin/pcitable
478
    PCITABLE=/bin/pcitable
480
    NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
479
    NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
481
	| while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
480
	| while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
482
	| awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
481
	| awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
483
    
482
    
484
    if [ -n "$NICS" ]; then
483
    if [ -n "$NICS" ]; then
485
	echolog "found network card(s): $NICS"
484
	echolog "found network card(s): $NICS"
486
	for nic in $NICS; do
485
	for driver in $NICS; do
487
	    echolog "load module $nic"
486
	    echolog "load module $driver"
488
	    modprobe_module $nic
487
	    modprobe_module $driver
489
	    FOUND_NIC="yes"
488
	    FOUND_NIC="$driver"
490
	done
489
	done
491
    fi
490
    fi
-
 
491
}
492
 
492
 
493
    # 3. probe for more network card drivers, if no ethX devices found
493
found_nic()
-
 
494
{
494
    for iface in eth0 eth1 eth2 eth3; do
495
    for iface in eth0 eth1 eth2 eth3; do
495
	ifconfig $iface > /dev/null 2>&1
496
	ifconfig $iface > /dev/null 2>&1
496
	if [ $? -eq 0 ]; then  FOUND_NIC="yes"; break; fi
497
	if [ $? -eq 0 ]; then  FOUND_NIC="yes"; break; fi
497
    done
498
    done
-
 
499
}
-
 
500
 
-
 
501
# 3. probe for more network card drivers, if no ethX devices found
-
 
502
#
498
    if [ -z $FOUND_NIC ]; then
503
load_network_module_auto()
-
 
504
{
-
 
505
    echolog "auto-detection of network driver ..."
499
	KERNEL="`uname -r`"
506
    KERNEL="`uname -r`"
500
	NETDRIVERS="`cat /lib/modules/$KERNEL/netdrivers`"
507
    NETDRIVERS="`find /lib/modules/$KERNEL/kernel/drivers/net | grep -v mii | grep .ko | cut -d"/" -f8 | cut -d"." -f1 | uniq`"
501
	for driver in $NETDRIVERS; do
508
    for driver in $NETDRIVERS; do
502
	    modprobe_module $driver
509
	modprobe_module $driver > /dev/null 2>&1
-
 
510
	for iface in eth0 eth1 eth2 eth3; do
503
	    ifconfig $iface > /dev/null 2>&1
511
	    ifconfig $iface > /dev/null 2>&1
504
	    if [ $? -eq 0 ]; then 
512
	    if [ $? -eq 0 ]; then 
505
		echolog "load $driver"
513
		echolog "load $driver"
-
 
514
		# tr brocken in busybox
506
		FOUND_NIC="yes"
515
		# FOUND_NIC="`echo $driver | tr '-' '_'`"
-
 
516
		FOUND_NIC="`echo $driver | cut -d"-" -f1`"
507
		break
517
		break 2
508
	    fi
518
	    fi
509
	    rmmod $driver
-
 
510
	done
519
	done
-
 
520
	rmmod $driver > /dev/null 2>&1
511
    fi
521
    done
-
 
522
 
-
 
523
    # clean up: remove unused modules until driver "mii"
-
 
524
    LOADED_DRIVERS="`lsmod | grep -v Module | grep -v $FOUND_NIC | cut -d" " -f1`"
-
 
525
    for driver in $LOADED_DRIVERS; do
-
 
526
	[ "$driver" = "mii" ]  && break
-
 
527
	[ "$driver" = "ntfs" ] && break
-
 
528
	[ "$driver" = "vfat" ] && break
-
 
529
	rmmod $driver > /dev/null 2>&1
-
 
530
    done
512
		
531
}
-
 
532
 
513
    # 4. ask the user for a network driver
533
# 4. ask the user for a network driver
-
 
534
#
514
    if [ -z $FOUND_NIC ]; then
535
load_network_module_ask()
-
 
536
{
515
	echo "ERROR: No network card detected!"
537
    echo "ERROR: No network card detected!"
516
	echo "Type in your network card driver (e.g. tg3, e1000). "
538
    echo "Type in your network card driver (e.g. tg3, e1000). "
517
	echo "Or ask your system administrator for help."
539
    echo "Or ask your system administrator for help."
518
	echo -n "Network card driver: "
540
    echo -n "Network card driver: "
519
	read nic
541
    read driver
520
	echo "Load module $nic"
542
    echo "Load module $driver"
-
 
543
    modprobe_module $driver
-
 
544
}
-
 
545
 
-
 
546
# Try to find a network driver
-
 
547
#
-
 
548
load_network_modules()
-
 
549
{
-
 
550
    # mii maybe need by NIC
-
 
551
    echolog "load module mii"
521
	modprobe_module $nic
552
    modprobe_module mii
-
 
553
 
-
 
554
    FOUND_NIC=""
-
 
555
    NIC="`cmdline_value nic`"
-
 
556
    load_network_module_nic
-
 
557
    [ "$NIC" != "auto" ] && load_network_module_pcitable
522
    fi
558
    found_nic
-
 
559
    [ -z $FOUND_NIC ] && load_network_module_auto
-
 
560
    [ -z $FOUND_NIC ] && load_network_module_ask
-
 
561
 
-
 
562
    # remove mii, if not needed
-
 
563
    rmmod mii > /dev/null 2>&1
523
}
564
}
524
 
565
 
525
# get DHCP lease
566
# get DHCP lease
526
# Urs Beyerle, PSI
567
# Urs Beyerle, PSI
527
#
568
#