Bug 8116

Summary: 2015.05-rc2 raspberrypi2_defconfig network interface not coming up
Product: buildroot Reporter: Albert <albert.david>
Component: OtherAssignee: Yann E. MORIN <yann.morin.1998>
Status: RESOLVED FIXED    
Severity: minor CC: buildroot
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:

Description Albert 2015-05-16 03:55:49 UTC
in 2015.05-rc2, default configuration of raspberrypi2(raspberrypi2_defconfig) network interface doesnt show up after boot, but adding a "sleep 1" in S40network(before line "/sbin/ifup -a") fixes the problem.
Comment 1 Peter Korsgaard 2015-05-16 07:03:26 UTC
It is because the rpi uses a usb<>ethernet adapter, and USB initialization happens after (or rather in parallel) with the rootfs getting mounted and init running - So eth0 isn't available by the time ifup runs.

Busybox ifup/ifdown isn't made to handle such dynamic setups, but perhaps we could add a wait-for-eth0 init script for the rpi that does something like:

etc/init.d/S40eth0
#!/bin/sh
#
# Wait for (usb based) eth0 to get detected
#

case "$1" in
  start)
        echo -n "Waiting for eth0 ... "
        while [ ! -d /sys/class/net/eth0 ]; do sleep 1; done
        echo "done"
        ;;
  stop)
        ;;
  restart|reload)
        "$0" stop
        "$0" start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
Comment 2 Floris Bos 2015-05-16 10:58:19 UTC
Was wondering if we shouldn't just (offer an option to) enable busybox's ifplugd?

While the Pi is one of the few that has Ethernet through USB, I think this also affects other platforms that have their Wifi through USB.
Comment 3 Peter Korsgaard 2015-05-16 13:16:52 UTC
(In reply to comment #2)
> Was wondering if we shouldn't just (offer an option to) enable busybox's
> ifplugd?
> 
> While the Pi is one of the few that has Ethernet through USB, I think this also
> affects other platforms that have their Wifi through USB.

Ifplugd is nice, but it wouldn't fix anything here as the problem is that eth0 isn't available yet when S40network runs, so ifplugd would also fail.
Comment 4 Floris Bos 2015-05-16 13:24:41 UTC
>Ifplugd is nice, but it wouldn't fix anything here as the problem is that eth0
>isn't available yet when S40network runs, so ifplugd would also fail.

Thought it also had an option for dealing with interfaces that do not exist yet.


http://git.busybox.net/busybox/tree/networking/ifplugd.c

"-M  Monitor creation/destruction of interface
     (otherwise it must exist)"

Although I haven't tested it.
Comment 5 Peter Korsgaard 2015-05-16 13:33:44 UTC
(In reply to comment #4)
> >Ifplugd is nice, but it wouldn't fix anything here as the problem is that eth0
> >isn't available yet when S40network runs, so ifplugd would also fail.
> 
> Thought it also had an option for dealing with interfaces that do not exist
> yet.
> 
> 
> http://git.busybox.net/busybox/tree/networking/ifplugd.c
> 
> "-M  Monitor creation/destruction of interface
>      (otherwise it must exist)"
> 
> Although I haven't tested it.

Ahh, you're right. I've never noticed that option. Sorry!
Comment 6 Thomas Petazzoni 2015-07-07 15:53:23 UTC
Yann, is this something you would like to fix in the default raspberrypi2_defconfig, for improve the out of the box user experience for users?
Comment 7 Peter Korsgaard 2015-10-16 09:46:17 UTC
Fixed in git by:

commit 49964858f45d2243c513e6d362e992ad89ec7a45
Author: Yann E. MORIN <yann.morin.1998@free.fr>
Date:   Sat Oct 3 14:31:45 2015 +0100

    package/initscripts: S40network: wait for network interfaces to appear
    
    On some machines, the network interface is slow to appear. For example,
    on the Raspberry Pi, the network interface eth0 is an ethernet-over-USB,
    and our standard boot process is too fast, so our network startup script
    is called before the USB bus is compeltely enumerated, thus it can't
    configure eth0.
    
    Closes #8116.
    
    [Peter: move to S40network, handle multiple interfaces]
    Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
    Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Comment 8 Benoît Thébaudeau 2015-10-16 20:00:53 UTC
I had experienced the same issue, and I had fixed it using BusyBox's ifplugd with -M as suggested in comment #2. eth0 should be more "allow-hotplug" than "auto" on RPi.

However, some services started quickly after S40network and configured to use eth0 might be unhappy if it is not yet up, but it is the same issue if the Ethernet cable is plugged later. So their configurations have to be adjusted anyway.

At least, there is now a configurable choice between the sleeping S40network and ifplugd.
Comment 9 Yann E. MORIN 2015-10-16 20:52:01 UTC
[--SNIP--]
> At least, there is now a configurable choice between the sleeping S40network
> and ifplugd.

The sleeping solution is to make our RPi defconfig (as well as all our default
configs) "just work" out-of-the-box, nothing more.

Any more serious system would probably have to use something along the lines
of connman (my personal favourite) or NetworkManager or ifplugd. Or even
custom startup scripts.