toptensoftware / flashy

All-In-One Reboot, Flash and Monitor Tool for Raspberry Pi bare metal
Other
4 stars 0 forks source link

Failed to reopen serial port on Linux host #1

Open rsta2 opened 1 year ago

rsta2 commented 1 year ago

Hi Brad,

I tried Flashy v2 now on a Linux host and I got the following:

$ flashy /dev/ttyUSB0 --status
Opening /dev/ttyUSB0 at 115.200 baud... ok
Waiting for device... ok
Found device: 
    - Raspberry Pi 4 Model B
    - Serial: 10000000-49c09c28
    - CPU Clock: 600MHz (range: 600-1500MHz)
    - Bootloader: rpi4-aarch32 v2.0.15, max packet size: 4096
Closing serial port... ok
^C
$ make flash 
flashy \
        /dev/ttyUSB0 \
        --flashBaud:921600 \
        --userBaud:115200 \
        --reboot: \
         \
        kernel7l.hex
Opening /dev/ttyUSB0 at 115.200 baud... ok
Waiting for device... ok
Found device: 
    - Raspberry Pi 4 Model B
    - Serial: 10000000-49c09c28
    - CPU Clock: 600MHz (range: 600-1500MHz)
    - Bootloader: rpi4-aarch32 v2.0.15, max packet size: 4096
Sending request for 921.600 baud... ok
Closing serial port... ok
Opening /dev/ttyUSB0 at 921.600 baud... ok
Waiting for device.../usr/lib/node_modules/@toptensoftware/flashy/serial.js:96
                throw new FlashyError(`Failed to open serial port: ${err.message}`);
                      ^

FlashyError: Failed to open serial port: Error Resource temporarily unavailable Cannot lock port
    at SerialPort.<anonymous> (/usr/lib/node_modules/@toptensoftware/flashy/serial.js:96:23)
    at SerialPort._error (/usr/lib/node_modules/@toptensoftware/flashy/node_modules/@serialport/stream/lib/index.js:198:14)
    at /usr/lib/node_modules/@toptensoftware/flashy/node_modules/@serialport/stream/lib/index.js:242:12

Node.js v20.3.1
make: *** [../../Rules.mk:294: flash] Fehler 1
$ uname -a
Linux 6.4.2-1-default #1 SMP PREEMPT_DYNAMIC Mon Jul 10 10:03:25 UTC 2023 (b97b894) x86_64 x86_64 x86_64 GNU/Linux
$ 

There seems to be a problem with locking the port, which only arises, when an kernel image is about to be loaded (not with --status) and only, when the serial port is reopened with a different baud rate. With 115200 baud loading works fine:

$ make flash 
flashy \
        /dev/ttyUSB0 \
        --flashBaud:115200 \
        --userBaud:115200 \
        --reboot: \
         \
        kernel7l.hex
Opening /dev/ttyUSB0 at 115.200 baud... ok
Waiting for device... ok
Found device: 
    - Raspberry Pi 4 Model B
    - Serial: 10000000-49c09c28
    - CPU Clock: 600MHz (range: 600-1500MHz)
    - Bootloader: rpi4-aarch32 v2.0.15, max packet size: 4096
Sending 'kernel7l.hex':
.................................................................................
Transfered 306171 bytes in 27.1 seconds.
Sending go command 0x32768 with delay 0ms... ok
Closing serial port... ok
^Cmake: *** [../../Rules.mk:294: flash] Unterbrechung
$

Another problem is, that Flashy does not terminate automatically. I have to press Ctrl-C to cancel it. I had this problem already with Flashy v1, where adding an explicit process.exit(0) did help.

Rene

toptensoftware commented 1 year ago

Hey Rene,

Thanks for reporting - I'll check out both issues as soon as I get a chance.

(I've not actually tested on a real linux machine, only Ubuntu WSL).

Brad

toptensoftware commented 1 year ago

Hi Rene,

Just tried here on Ubuntu 20.04 and it seems to work fine.

My guess is a couple of retries on re-opening the serial port should solve it, but I'd like to reproduce it first.

Also, I'm not seeing any issues with it not terminating.

Brad

brad@UbuntuDev:~/Projects/flashy/flashy$ node flashy /dev/ttyUSB0 ../blink/kernel7.img
Opening /dev/ttyUSB0 at 115,200 baud... ok
Waiting for device... ok
Found device: 
    - Raspberry Pi 3 Model B+
    - Serial: 00000000-bc1b1209
    - CPU Clock: 600MHz (range: 600-1400MHz)
    - Bootloader: rpi2-aarch32 v2.0.15, max packet size: 4096
Sending request for 1,000,000 baud... ok
Closing serial port... ok
Opening /dev/ttyUSB0 at 1,000,000 baud... ok
Waiting for device... ok
Sending '../blink/kernel7.img':
...............
Transfered 59372 bytes in 0.7 seconds.
Sending go command 0x32768 with delay 0ms... ok
Closing serial port... ok

brad@UbuntuDev:~/Projects/flashy/flashy$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:    20.04
Codename:   focal

brad@UbuntuDev:~/Projects/flashy/flashy$ node --version
v10.19.0
[  757.560369] usb 1-10.4: new full-speed USB device number 10 using xhci_hcd
[  757.938984] usb 1-10.4: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[  757.938986] usb 1-10.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  757.938987] usb 1-10.4: Product: FT232R USB UART
[  757.938988] usb 1-10.4: Manufacturer: FTDI
[  757.938989] usb 1-10.4: SerialNumber: A50285BI
[  757.956783] ftdi_sio 1-10.4:1.0: FTDI USB Serial Device converter detected
[  757.956803] usb 1-10.4: Detected FT232RL
[  757.957376] usb 1-10.4: FTDI USB Serial Device converter now attached to ttyUSB0
rsta2 commented 1 year ago

I'm running openSUSE Tumbleweed, which has very recent versions of the Linux kernel and most packages.

$ dmesg
[ 1290.943164] usb 1-2.2: new full-speed USB device number 9 using xhci_hcd
[ 1291.039267] usb 1-2.2: New USB device found, idVendor=10c4, idProduct=ea60, bcdDevice= 1.00
[ 1291.039283] usb 1-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1291.039288] usb 1-2.2: Product: CP2102 USB to UART Bridge Controller
[ 1291.039292] usb 1-2.2: Manufacturer: Silicon Labs
[ 1291.039295] usb 1-2.2: SerialNumber: 0001
[ 1291.172504] usbcore: registered new interface driver usbserial_generic
[ 1291.172524] usbserial: USB Serial support registered for generic
[ 1291.182346] usbcore: registered new interface driver cp210x
[ 1291.182376] usbserial: USB Serial support registered for cp210x
[ 1291.182412] cp210x 1-2.2:1.0: cp210x converter detected
[ 1291.186564] usb 1-2.2: cp210x converter now attached to ttyUSB0
$ node --version
v20.3.1
$ uname -a
Linux 6.4.2-1-default #1 SMP PREEMPT_DYNAMIC Mon Jul 10 10:03:25 UTC 2023 (b97b894) x86_64 x86_64 x86_64 GNU/Linux
$ 

The behavior, that I have to press Ctrl-C to terminate Flashy, started about a month ago.

Rene

toptensoftware commented 1 year ago

Thanks Rene. I'll see if I can repro it in a VM.

(fwiw: I tested with Raspbian Pi 2 flashing a Pi 3 and it worked fine there too)

toptensoftware commented 1 year ago

I believe this is an issue in the serial port module related to node v20 and tumbleweed.

I don't think there's much I can do about this, except to suggest rolling back to Node v18 where the issue doesn't seem to occur.

I've logged an issue with the serial port module here: https://github.com/serialport/node-serialport/issues/2656

rsta2 commented 1 year ago

OK Brad, I understand. Thank you so far.

toptensoftware commented 1 year ago

fwiw, here's how to work around this by installing node 18 with nvm (Node Version Manager).

  1. Install NVM: (full instructions)
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
  1. Logout and back in to reload bash profile (or, source ~/.profile)

  2. Install node 18 and switch to it

nvm install 18 && nvm use 18
  1. Install flashy (note: no sudo)
npm install -g @toptensoftware/flashy
  1. Check flashy exits cleanly:
flashy /dev/ttyUSB0 --status

To switch back to system installed node, use nvm use system, but you'll need to nvm use 18 before using flashy again.

toptensoftware commented 1 year ago

@rsta2: I'm not very familiar with OpenSuse and couldn't figure out how to install node 18 via yast or zypper. If you know how I'd be interested to hear.

rsta2 commented 1 year ago

YaST currently only provides node 20. Unfortunately I'm not very familiar with node and never installed different versions of it, so I'm afraid I cannot help you. I think, I will wait until this problem has been fixed in the serialport package.

toptensoftware commented 1 year ago

Understood. Hopefully they can get it sorted soon.

(I'd not done much with node versions either but the steps above were pretty easy and seemed to solve it)

Also, just to let you know this happens on Ubuntu 22.04 too - so not specific to Suse.

rsta2 commented 1 year ago

Thanks for info.