Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

96boardsctl reset shows usage on Raspberry Pi #2

Open
meermanr opened this issue Jun 21, 2017 · 1 comment
Open

96boardsctl reset shows usage on Raspberry Pi #2

meermanr opened this issue Jun 21, 2017 · 1 comment

Comments

@meermanr
Copy link

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
Copy link
Collaborator

glikely commented Apr 8, 2020

Should be resolved now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants