96boards / 96boards-uart

96Boards UART adapter hardware design files
BSD 2-Clause "Simplified" License
8 stars 9 forks source link

`96boardsctl reset` shows usage on Raspberry Pi #2

Open meermanr opened 6 years ago

meermanr commented 6 years ago

I've compiled 96boardsctrl on my ARM-based Raspberry Pi running Raspbian Jesse Lite but found that it just shows its usage when I ask it to reset:

root@pi:/home/pi/96boards-uart/96boardsctl# ./96boardsctl reset

Usage: ./96boardsctl [OPTION]... command
Control the power button and reset lines with a 96boards USB console adaptor

  -h, --help                    Display this help and exit
  -o, --old                     Using old v0.3 prototype board
  -l, --list                    List available devices and exit
  -L, --long                    Use long 5s pulse, useful to force board to power off
  -p, --pulse-width=TIME        Length of signal pulse in ms
  -s, --serial <serial> Specify device to open by serial number

Commands:
  power                 Pulse the power button signal
  reset                 Pulse the reset button signal

This program causes the kernel's ftdi_sio driver to disconnect from the UART device
It can be reconnected by echoing the device name into /sys/bus/usb/drivers/ftdi_sio/bind

I believe this is because getopt_long() returns -1 when it has finished parsing options, but this is being assigned to an (unsigned) char which is always greater than zero, so the while loop never exits, causing the switch statements default to be chosen.

The following patch solved this for me:

index a2bead7..d2e0a7d 100644
--- a/96boardsctl/96boardsctl.c
+++ b/96boardsctl/96boardsctl.c
@@ -102,7 +102,7 @@ int main(int argc, char *argv[])

        ftdi_init(&ftdi);

-       while ((c = getopt_long(argc, argv, optstring, long_options, NULL)) >= 0) {
+       while ((c = getopt_long(argc, argv, optstring, long_options, NULL)) != (char) -1) {
                switch (c) {
                case 1:
                        if (count >= 3) {
glikely commented 4 years ago

Should be resolved now