Mokon
Posts: 1
Joined: Thu Jan 24, 2013 3:27 am

Busybox Ethernet Configuration

Thu Jan 24, 2013 3:36 am

I posted this over at the rpi stack exchange but no one has been able to solve it yet so I'm hoping some here will have an idea.

So I have a custom minimal Linux kernel I have created which boots fine on the RPI. I'm using busybox for my init process. However I am having some trouble with the ethernet port. (This is on the model B RPI). In my init scripts I have the interface being configured with an IP address I know. (At some point in the future I'll enable DHCP on it.) The problem is the calls to ifconfig are failing. The reason they are failing is because the smsc95xx ethernet interface is not up yet. A few lines down in the boot up process (after I see the ifconfig fail) I see the ethernet interface come up. I assume the kernel is finally detecting this ethernet connection and bringing the port up. If I continue on with the command line I can manually configure the ethernet port.

I thought this might be due to me not calling ifconfig at the right runlevel but it seems the busybox inittab does not use runlevels.

Anyways does anyone have an idea how I can run this configuration at the correct moment? I have reproduced a few parts of my script that make my image. Specifically the inittab portion:

Code: Select all

mkdir ${ROOTFS}/etc                                                             
echo "::sysinit:/etc/init.d/rcS                                                 
::askfirst:-/bin/sh                                                             
::restart:/sbin/init                                                            
::ctrlaltdel:/sbin/reboot                                                       
::shutdown:/bin/umount -a -r" > ${ROOTFS}/etc/inittab                           
                                                                                
mkdir ${ROOTFS}/etc/init.d                                                      
                                                                                
echo "#!/bin/sh                                                                 
echo \"Running rcS\"                                                            
# mount -t proc proc /proc                                                      
ifconfig eth0 up                                                                
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255       
route add default gw 192.168.1.1                                                
telnetd -l /bin/login                                                           
/etc/motd                                                                       
/bin/sh" > ${ROOTFS}/etc/init.d/rcS                                             
chmod +x ${ROOTFS}/etc/init.d/rcS    

summers
Posts: 63
Joined: Mon Jan 30, 2012 4:27 pm

Re: Busybox Ethernet Configuration

Fri Feb 01, 2013 11:02 am

Come across things like that in the past.

Living in the busybox work the king of thing you need to do is develop a test for is the ethernet up yet, if yes - then bring it up, if not then sleep and try again.

Kind of way to do this - when the eternet module gets loaded it will create some pseduo file structurs, probably under /proc or similar. Test for this file.

Guess an quicker dirtier way of doing this would be something like:

(sleep 30 ; ifconfig eth0 up) &

e.g. set the ifconfig to run in the background in 30 seconds time. Can't recall if you can do the "()&" in busybox though ...

nismoryco
Posts: 1
Joined: Thu Feb 02, 2012 7:05 am

Re: Busybox Ethernet Configuration

Fri Apr 19, 2013 2:48 am

I had the same problem. I added the following code in my network startup script. Call the function before calling ifconfig.

Code: Select all

wait_for_interface() {
   COUNTER=0
   while [ $COUNTER -lt 10 ]; do
      if [ "`cat /proc/net/dev | grep eth0 | awk '{print $1}' | sed -e 's/://'`" = "" ]; then
         echo "Waiting for network ..."
         sleep 1
         let COUNTER=COUNTER+1
      else
         COUNTER=10
      fi
   done
}

Return to “Linux Kernel”