AndreRenaud / buildroot-r36s

Other
1 stars 3 forks source link

How to connect with usb ethernet cable #1

Open manyids2 opened 2 months ago

manyids2 commented 2 months ago

Thank you so much for your work! I followed the instructions at https://ignavus.net/r36s and everything just worked! I am now trying to use imgui instead of go-sdl to build by own application, and it would greatly expedite the process if I could use the amazing run_on_unit.sh script, and I bought a usb-ethernet cable, but how do I figure out the IP I should ssh to? Or should I just solder a UART connection anyway?

AndreRenaud commented 2 months ago

Hey. I'm glad it all worked for you. I must admit that after I got it all going, I don't think I went back and ran it all from scratch, so the fact that it all worked perfectly is mildly surprising. Good to hear.

The run_on_unit.sh does assume that you've got the ethernet adapter all set up, yes. Without the serial console, it is tricky to know what is happening. If you don't want to solder it up (and that's reasonable, since it's all working, so there isn't much need), then the easiest way to discover the IP address is either by going to your DHCP server and seeing who it has given a lease out to, or using a tool like arp-scan to find the device.

Basically, if you're on the same local network as the R36S, then before you power it up, run sudo arp-scan --localnet, then power it on and run sudo arp-scan --localnet again, you should see a new device there, and it'll show both MAC & IP address.

If you're lucky, the ethernet dongle you've got has the MAC address printed on its label, otherwise there's a bit of guess work involved.

See https://www.kali.org/tools/arp-scan/ for more info & let me know if this works for you.

BTW - where did you find out about that page? I wrote it up, but didn't actually post it anywhere, and my website has been basically dead for 20 years, so I'm a bit surprised it showed up in Google or anything.

manyids2 commented 2 months ago

Hi, thank you so much for the reply!

I found it by searching for mainline linux for all the handhelds i could find on aliexpress. I unfortunately could not use arp-scan as it needs a xxx.xxx.x.x type of address which I could not find. However, I used the SDL program (r36s-demo-app) to display the network devices using go's net module. It only shows a loopback device lo, so I'm guessing I need to set it up for usb-ethernet somehow in busybox's init.d folder. Unfortunately, on internet I could only find ways of setting up using the ip command, which I could not find in busybox config, so finally, I am trying to code up a minimal terminal with os/exec and showing the command's outputs. Having something working to start with is such a superpower though, so thank you again!

AndreRenaud commented 2 months ago

That sounds like your USB Ethernet adapter may not be supported by the kernel config I put in place. I think I spent some time minimising it to make the image smaller, but I may have dropped a driver you need in the process.

Can you plug the adapter into your PC and run lsusb, and tell me the VID:PID of the device you've got?

manyids2 commented 2 months ago

Hi, thank you again! output of lsusb:

Bus 002 Device 003: ID 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
manyids2 commented 2 months ago

Also, the whole output of lsusb -v :

Bus 002 Device 005: ID 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.20
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         9
  idVendor           0x0b95 ASIX Electronics Corp.
  idProduct          0x1790 AX88179 Gigabit Ethernet
  bcdDevice            2.00
  iManufacturer           1 ASIX
  iProduct                2 AX88179A
  iSerial                 3 00E60794
  bNumConfigurations      3
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0046
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              184mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           4
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol      0 
      iInterface              4 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              11
        bMaxBurst               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               5
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               5
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x05  EP 5 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               2
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0068
    bNumInterfaces          2
    bConfigurationValue     2
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              184mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass     13 
      bInterfaceProtocol      0 
      iInterface              0 
      CDC Header:
        bcdCDC               1.10
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      CDC Ethernet:
        iMacAddress                      5 (??)
        bmEthernetStatistics    0x00000000
        wMaxSegmentSize               1514
        wNumberMCFilters            0x0000
        bNumberPowerFilters              0
      CDC NCM:
        bcdNcmVersion        1.00
        bmNetworkCapabilities 0x2b
          8-byte ntb input size
          max datagram size
          net address
          packet filter
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              11
        bMaxBurst               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 
      bInterfaceProtocol      1 
      iInterface              0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 
      bInterfaceProtocol      1 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               5
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               5
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0062
    bNumInterfaces          2
    bConfigurationValue     3
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              184mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      6 Ethernet Networking
      bInterfaceProtocol      0 
      iInterface              0 
      CDC Header:
        bcdCDC               1.10
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      CDC Ethernet:
        iMacAddress                      5 (??)
        bmEthernetStatistics    0x00000000
        wMaxSegmentSize               1514
        wNumberMCFilters            0x0000
        bNumberPowerFilters              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              11
        bMaxBurst               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               5
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               5
AndreRenaud commented 2 months ago

That device is supported by CONFIG_USB_NET_AX88179_178A, which is enabled, so it should be showing up.... it might be that putting the serial console on it now is the best option. https://github.com/AndreRenaud/linux-r36s/blob/r36s-v6.10/drivers/net/usb/ax88179_178a.c#L1876

Unfortunately this will be something entirely trivial, but without the debug console it'll be hard to work it out.

manyids2 commented 2 months ago

Understood, I will try it and post an update.

AndreRenaud commented 2 months ago

I booted up my unit, and realised that I haven't configured buildroot to automatically bring up ethernet interfaces. For testing purposes, you could try rebuilding buildroot with BR2_SYSTEM_DHCP=eth0 set (ie: run make menuconfig, navigate to "System Configuration"/"Network interface to configure through DHCP", and set it to eth0. Then do a rebuild & retry that image?

The downside to this is that I think it might stall during boot if you don't have an ethernet device plugged in. But at least enough to get started.

manyids2 commented 2 months ago

Hey, so I tried it, but unfortunately, still no result. I think I may have turned on random packages trying to get it to work, so will try that again with a clean build. I finished my caveman style minimal terminal though, and am able to connect a keyboard and run commands and check outputs [ enter to run, shift+enter for new command ] - https://github.com/manyids2/r36s-term So I now have a kinda debug console to check outputs of things like lsusb, /sys/devices... etc. Now looking through information on how to set up the connection.

AndreRenaud commented 2 months ago

If you run ifconfig -a now, you should see an eth0 device? If that's the case, you should be able to run udhcpc -i eth0 and hopefully it'll get an IP address.

manyids2 commented 2 months ago

Hey, tried it, still no luck. Cloned the repo and build afresh, and turned on net-tools and dhcp, configured for eth0. Still only shows loopback device (lo), never eth0, tried both ethernet and wifi dongles. Sorry for all the trouble, and thank you again for all the help, I think it will take me quite a while to figure this out.

AndreRenaud commented 2 months ago

There are two USB ports on the R36S - one is only for charging. Can you try using the other port and see if it behaves differently? Does lsusb on the R36S show the device?

manyids2 commented 1 month ago

Hi, Sorry for the late response, I thought I would get somewhere but got caught up in some weird errors ( not sure if it is possible, but I had a kind of 'ghost' /dev/sda that even responded to fdisk, but it was not writing to the sd card, took a while to figure out, but after a reboot, it was ok ) Wrt lsusb, yes, it does show the device, but since it is busybox lsusb, it does not show the names of the devices. I am using the 'OTG' port and not the charging one. The charging one does not seem to have host capability. Also, I tried with the stock ArkOS, and the usb wifi worked with it. I wonder if it has something to do with loading to ramdisk. I will try with booting into a partition on sd card and follow some init scripts from different firmwares to check how they set up /dev, etc... and get back.

AndreRenaud commented 1 month ago

Oh, you're using wireless ethernet, not wired? Most wireless ethernet devices require firmware (which won't be present in this minimal image), and the wpa_supplicant tools (which also aren't present).

Can you send the lsusb output through?

manyids2 commented 1 month ago

Hey, here is the lsusb output (the device used is https://www.coolblue.nl/en/product/837913/act-usb-c-3-port-hub-with-ethernet.html , with a keyboard attached to type into the console) :

Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 007: ID 0b95:1790
Bus 001 Device 002: ID 0bda:5411
Bus 001 Device 008: ID 046d:c534

PS: I tried both wired and wireless (I assume wireless ethernet means the usual usb wifi dongle) It is not possible to try without the hub, as I need at least 2 usbs, one for keyboard to input and one for the ethernet/dongle

AndreRenaud commented 1 month ago

The ethernet dongle is the second one on the list - 0b95:01790. It should be ok - it's an ASIX AX88179-based dongle, which has the built-in drivers.

Can you send through the output of dmesg & ifconfig -a ?

manyids2 commented 1 month ago

Output of ifconfig -a:

ifconfig -a

lo _ Link encap:Local Loopback
inet addr:127.0.0.1 Masi-255.0.0.0
inet6 addr. ::1/128 ScopeHost
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns.0 carrier-0
Collisions:0 trqueuelen:1000
RX bytes:576 (576.0 B) TX bytes:576 (576.0 B)

For the output of dmesg, I need to update a few things for the terminal program, will send you the output shortly.

manyids2 commented 1 month ago

Hi, I figure it will be easier for me to mount the sd card as a read/write partition and store logs rather than the current method of just plugging in a keyboard and OCR'ing the screen. So will get back to you.

manyids2 commented 1 month ago

Hey, I finally managed to get it done :) Thank you so much for all the help.

I had to add some firmware in the linux kernel under device handers, network somewhere (searching for ralink, corresponding to the usb wifi dongle i had)

Further, to register it for ifconfig, I added board/r36s/overlay/etc/network/interfaces as:

auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant.conf
    post-up ifdown eth0
iface default inet dhcp

I added wpa_supplicant to the target packages, added wpa_suppicant.conf:

# Giving configuration update rights to wpa_cli
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

# network section generated by wpa_passphrase
network={
    ssid="SSID"
    psk="PASS"
    id_str="home"
}

Finally, I started it with board/r36s/etc/init.d/S98wpasupplicant:

#!/bin/sh
#
# Start wpa_supplicant
#

case "$1" in
start)
    wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
    ;;
stop)
    killall wpa_supplicant
    ;;
restart | reload)
    "$0" stop
    "$0" start
    ;;
*)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    ;;
esac

exit $?

Then I was able to ssh into it, and ifconfig -a shows the wlan0 interface as expected.

PS: I assume the ethernet will also work now as defined in interfaces, but I haven't tested as wifi is more convenient for me than ethernet

AndreRenaud commented 1 month ago

Nicely done. Can you tell me what the firmware you required was? Were you able to get that put in there via an existing buildroot package, or did you have to find it externally? If it's already in buildroot, it'd be easy enough to add it to the defconfig.

Having a default /etc/wpa_supplicant.conf in the board directory that can be tweaked with the SSID/PSK also wouldn't be too bad.

manyids2 commented 1 month ago

i have the defconfigs and linux configs if youd like, I will push it to a repo, for now (in linux config, not buildroot):

CONFIG_RT2X00=m CONFIG_RT2500USB=m CONFIG_RT73USB=m CONFIG_RT2800USB=m CONFIG_RT2800USB_RT33XX=y CONFIG_RT2800USB_RT35XX=y CONFIG_RT2800USB_RT3573=y CONFIG_RT2800USB_RT53XX=y CONFIG_RT2800USB_RT55XX=y CONFIG_RT2800USB_UNKNOWN=y CONFIG_RT2800_LIB=m CONFIG_RT2X00_LIB_USB=m CONFIG_RT2X00_LIB=m CONFIG_RT2X00_LIB_FIRMWARE=y CONFIG_RT2X00_LIB_CRYPTO=y CONFIG_RT2X00_LIB_LEDS=y CONFIG_RT2X00_DEBUG=y

manyids2 commented 1 month ago

Additionally, I found a gist online for a terminal based on vterm and sdl which I packaged with cmake, and I created the buildroot packages for it (which basically just install the below repos)

https://github.com/manyids2/sdl-vterm https://github.com/manyids2/libvterm-cmake

This gave me a full terminal for debugging, especially the dmesg part, as the previous toy terminal was too minimal for things like piping and grepping. The above one is fully fledged, can even run things like vim on it as it just delegates to libvterm (doesn't have a package on buildroot, but above repo works)

manyids2 commented 1 month ago

Hey, sorry, the above was incomplete wrt the firmware, i also had to add linux-firmware from buildroot and support for the ralink series (searching menuconfig)

BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT61=y BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT73=y BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT2XX=y

( else, we get error from dmesg: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'. )