/etc/init.d/init_gpio bug on ar300m (and anything but xe300)

Upon looking into why GPIO16 was exported on my ar300m (for Ar-300m i2c - #4 by gadgetoid) I came across /etc/init.d/init_gpio:

root@GL-AR300M:~# cat /etc/init.d/init_gpio
#!/bin/sh /etc/rc.common
START=01

set_xe300_usbpower()
{
    . /lib/functions/gl_util.sh
    model=$(get_model)
    #For xe300-no-battery, export gpio16 and turn on the USB power
    [ "$model" = "xe300" ] && [ -d  "/sys/bus/usb/devices/1-1.4/1-1.4:1.0/ttyUSB0/" ] ||  {
                echo 16 >/sys/class/gpio/export
                echo out >/sys/class/gpio/gpio16/direction
                echo 1 >/sys/class/gpio/gpio16/value
    }
}

start(){
        set_xe300_usbpower
}

The || at the end of [ "$model" = "xe300" ] && [ -d "/sys/bus/usb/devices/1-1.4/1-1.4:1.0/ttyUSB0/" ] || means that the export functions are always run regardless of the state of the previous two checks. Is this intended? In fact both of those tests are false on the ar300m yet the GPIO is still exported.

This script should be something like this:

root@GL-AR300M:~# cat /etc/init.d/init_gpio
#!/bin/sh /etc/rc.common
START=01

set_xe300_usbpower()
{
    . /lib/functions/gl_util.sh
    model=$(get_model)
    #For xe300-no-battery, export gpio16 and turn on the USB power
    [ "$model" = "xe300" ] && [ -d  "/sys/bus/usb/devices/1-1.4/1-1.4:1.0/ttyUSB0/" ] && {
                echo 16 >/sys/class/gpio/export
                echo out >/sys/class/gpio/gpio16/direction
                echo 1 >/sys/class/gpio/gpio16/value
    }
}

start(){
        set_xe300_usbpower
}
1 Like

This is a BUG, it will be fixed.

1 Like