Author Topic: FTDI_SIO  (Read 9541 times)

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
FTDI_SIO
« on: July 26, 2020, 06:41:01 am »
Has anyone tried to connect an FTDI device to the cosmo ? I cannot get it to create a /dev/ttyUSB0
Here's what my lsusb shows :

Code: [Select]
drbytes@cosmopda:~$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 016: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP2102/CP2109 UART Bridge Controller [CP210x family]
Bus 001 Device 010: ID 045e:07b2 Microsoft Corp. 2.4GHz Transceiver v8.0 used by mouse Wireless Desktop 900
Bus 001 Device 013: ID 1908:2070 GEMBIRD
Bus 001 Device 012: ID 2109:0102 VIA Labs, Inc.
Bus 001 Device 011: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
Bus 001 Device 009: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 008: ID 0bda:5411 Realtek Semiconductor Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


But no ttyUSB0 or something like that is created for the device
Code: [Select]
Bus 001 Device 016: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP2102/CP2109 UART Bridge Controller [CP210x family] as I can see when I ls /dev/tty* :

Code: [Select]
drbytes@cosmopda:~$ ls /dev/tty*
/dev/tty    /dev/tty13  /dev/tty19  /dev/tty24  /dev/tty3   /dev/tty35  /dev/tty40  /dev/tty46  /dev/tty51  /dev/tty57  /dev/tty62  /dev/ttyC1   /dev/ttyGS3  /dev/ttyp2  /dev/ttyp8  /dev/ttype
/dev/tty0   /dev/tty14  /dev/tty2   /dev/tty25  /dev/tty30  /dev/tty36  /dev/tty41  /dev/tty47  /dev/tty52  /dev/tty58  /dev/tty63  /dev/ttyC2   /dev/ttyS0   /dev/ttyp3  /dev/ttyp9  /dev/ttypf
/dev/tty1   /dev/tty15  /dev/tty20  /dev/tty26  /dev/tty31  /dev/tty37  /dev/tty42  /dev/tty48  /dev/tty53  /dev/tty59  /dev/tty7   /dev/ttyC3   /dev/ttyS1   /dev/ttyp4  /dev/ttypa
/dev/tty10  /dev/tty16  /dev/tty21  /dev/tty27  /dev/tty32  /dev/tty38  /dev/tty43  /dev/tty49  /dev/tty54  /dev/tty6   /dev/tty8   /dev/ttyGS0  /dev/ttyS2   /dev/ttyp5  /dev/ttypb
/dev/tty11  /dev/tty17  /dev/tty22  /dev/tty28  /dev/tty33  /dev/tty39  /dev/tty44  /dev/tty5   /dev/tty55  /dev/tty60  /dev/tty9   /dev/ttyGS1  /dev/ttyp0   /dev/ttyp6  /dev/ttypc
/dev/tty12  /dev/tty18  /dev/tty23  /dev/tty29  /dev/tty34  /dev/tty4   /dev/tty45  /dev/tty50  /dev/tty56  /dev/tty61  /dev/ttyC0  /dev/ttyGS2  /dev/ttyp1   /dev/ttyp7  /dev/ttypd

When I try to get ftdi module loaded :

Code: [Select]
drbytes@cosmopda:~$ sudo modprobe ftdi_sio
sudo: unable to resolve host cosmopda: Name or service not known
modprobe: FATAL: Module ftdi_sio not found in directory /lib/modules/4.4.146

So can someone tell me how to proceed?

cam1965

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • http://
Re: FTDI_SIO
« Reply #1 on: July 26, 2020, 08:18:38 am »
This module is not enabled or  compiled in this kernel. Unless you compile the kernel , there is nothing to do. Compile is a pain. ( I have my own compiled ). Some links are not in the kernel tree. Some modifications are needed. Please see my posts here about compiling. Even in my kernel  I didn't enable this module.  ( Only my DVB TV and external camera and other modules that I use.). I can only say that this is a hard , very hard work. Good luck.

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: FTDI_SIO
« Reply #2 on: July 26, 2020, 08:36:36 am »
Thx for the reply.

Interestingly adding support for my rtl-sdr is something I planned to tackle next week, seeing your posts you've already made some headway.
Have you shared your kernel work online somewhere? Or perhaps you can point me to some documentation/repo's?

thx

cam1965

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • http://
Re: FTDI_SIO
« Reply #3 on: July 26, 2020, 09:12:53 am »
My kernel needs force loading of  the connectivity modules at startup  to work. (force loading of the wlan, radio and other  modules ( please see my posts ). It is too complicated. And after my compilation , some kernel tree  modifications  was made ( including wlan , radio, bluetooth - basically the connectivity modules back into kernel tree ).My kernel source tree was the previous tree without these modifications) . If my  kernel was a monolithic it would work for you. But it is not. The best thing is you try to compile the kernel yourself . With this  new tree ( modifications mentioned ) the compilation of these vendors modules were not compiled successful.  I am using the previous kernel source tree ( with some commits ). The kernel source is in https://github.com/gemian/cosmo-linux-kernel-4.4 .
After these modifications  made by the developer : https://github.com/gemian/cosmo-linux-kernel-4.4/tree/master/drivers/misc/mediatek ( Move MediaTek connectivity modules back into kernel tree ), I have not compiled these connectivity modules ( vendor modules ) successfully. ( After some modifications I have compiled successfully, but linux after loading wlan was rebooting randomly some times . So I have returned  to the previous kernel tree ). Good luck.  Sorry about my English. I am from Brazil.
« Last Edit: July 26, 2020, 09:28:29 am by cam1965 »

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: FTDI_SIO
« Reply #4 on: July 26, 2020, 09:43:17 am »
Super info.

I also received this link with a ton of useful info: https://github.com/gemian/gemian/wiki/KernelCompilation


Varti

  • Administrator
  • Hero Member
  • *****
  • Posts: 1280
    • View Profile
Re: FTDI_SIO
« Reply #5 on: July 26, 2020, 09:46:56 am »
From what I have read on the net, the FTDI module might be included in linux-modules-extra. Check if this package is already installed.

Varti
Planet Gemini PDA WiFi/LTE with Mediatek x27
SL-C1000 running Arch Linux ARM May2017, K30225 Wi-Fi CF Card, 64GB SDXC card
and many other Zauruses!

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: FTDI_SIO
« Reply #6 on: July 26, 2020, 02:05:29 pm »
So these are the steps I followed to get it to compile on the cosmo it self, no modifications to the config by using the current kernel config on the device:


Code: [Select]
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev git bc
mkdir cosmo
cd cosmo/
git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git
mkdir KERNEL_OUT
cat /proc/config.gz | gunzip > KERNEL_OUT/.config
make O=../KERNEL_OUT -C cosmo-linux-kernel-4.4 menuconfig -j8
make O=../KERNEL_OUT -C cosmo-linux-kernel-4.4 -j8

That starts to compile the kernel but I run into issues :

Code: [Select]
  CC      arch/arm64/kvm/guest.o
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/fs/exec.c: In function 'get_task_comm':
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/fs/exec.c:1086:32: error: argument to 'sizeof' in 'strncpy' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
  strncpy(buf, tsk->comm, sizeof(tsk->comm));

and further down :

Code: [Select]
In file included from /home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/linux/sctp.h:57,
                 from /home/drbytes/cosmo/cosmo-linux-kernel-4.4/security/lsm_audit.c:31:
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:306:1: error: alignment 4 of 'struct sctp_paddr_change' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:580:1: error: alignment 4 of 'struct sctp_setpeerprim' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:579:26: error: 'sspp_addr' offset 4 in 'struct sctp_setpeerprim' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage sspp_addr;
                          ^~~~~~~~~
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:593:1: error: alignment 4 of 'struct sctp_prim' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:592:26: error: 'ssp_addr' offset 4 in 'struct sctp_prim' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage ssp_addr;
                          ^~~~~~~~
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:640:1: error: alignment 4 of 'struct sctp_paddrparams' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:634:26: error: 'spp_address' offset 4 in 'struct sctp_paddrparams' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage spp_address;
                          ^~~~~~~~~~~
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:747:1: error: alignment 4 of 'struct sctp_paddrinfo' is less than 8 [-Werror=packed-not-aligned]
 } __attribute__((packed, aligned(4)));
 ^
/home/drbytes/cosmo/cosmo-linux-kernel-4.4/include/uapi/linux/sctp.h:741:26: error: 'spinfo_address' offset 4 in 'struct sctp_paddrinfo' isn't aligned to 8 [-Werror=packed-not-aligned]
  struct sockaddr_storage spinfo_address;
                          ^~~~~~~~~~~~~~
  CC      security/selinux/nlmsgtab.o
  CC      security/selinux/netif.o
cc1: all warnings being treated as errors

Too bad that a fresh git can't get off the ground.
« Last Edit: July 26, 2020, 02:08:00 pm by drbytes »

cam1965

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • http://
Re: FTDI_SIO
« Reply #7 on: July 26, 2020, 02:13:38 pm »
As I said to you , I had to modify a lot of files and links. Please use at first time gcc-7 and not -j8. And compile inside cosmo. But I will say again: It is a pain to compile. I took a week or more to finish my first compilation, because I had to modify and link a lot of files  files to the correct directories. Good luck.

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: FTDI_SIO
« Reply #8 on: July 26, 2020, 04:16:54 pm »
It is a bit fiddly, I agree.

However ...

Code: [Select]
root@cosmopda:~# cat /var/log/messages | grep ftdi
Jul 26 22:05:29 cosmopda kernel: [ 4011.761624]  (1)[18323:modprobe]usbcore: registered new interface driver ftdi_sio

So I have been able to build it as a module (cross compiled), copied it over, depmodded it and finally modprobed it.
Still no ttyUSB0 tho, so I'm missing something.

I thnk it is VCP UART drivers.
<M>   USB CP210x family of UART Bridge Controllers
Code: [Select]
build trng...
  LD      drivers/misc/mediatek/built-in.o
  LD      drivers/misc/built-in.o
  CC [M]  drivers/usb/serial/cp210x.o
  LD      drivers/built-in.o
  LINK    vmlinux
  LD      vmlinux.o
« Last Edit: July 26, 2020, 04:40:28 pm by drbytes »

cam1965

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • http://
Re: FTDI_SIO
« Reply #9 on: July 26, 2020, 04:55:03 pm »
When I did this in the past ( cross compiling ) the module was loaded, but only this was done and the device was not recognized ( in my case the dvb tv modules). When I did the same inside cosmo ( only compiled the module ) , the module was not loaded ( modprobe shows an exe error or something , because the kernel was different,  really I dont´t  remember ). The only real solution was when I compiled the full kernel and loaded the module.   Maybe if you download kernel-headers and compile the module with kernel headers and not the kernel source tree  it will work. But sometimes this specific module needs other module to work.
« Last Edit: July 26, 2020, 05:05:00 pm by cam1965 »

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: FTDI_SIO
« Reply #10 on: July 26, 2020, 05:06:08 pm »
Success !!!

Code: [Select]
drbytes@cosmopda:~$ ls /dev/ttyU*
/dev/ttyUSB0
drbytes@cosmopda:~$

Code: [Select]
Jul 26 23:03:04 cosmopda kernel: [ 1445.533536]  (1)[9259:kworker/1:1]usb 1-1: cp210x converter now attached to ttyUSB0

And it shows my serial console:

Code: [Select]
drbytes@cosmopda:~$ sudo picocom -b 9600 /dev/ttyUSB0
sudo: unable to resolve host cosmopda: Name or service not known
picocom v3.1

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        :
omap is        :
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready
Hi. I'm a nodemcu running the Garage Door code
Current state: Closed. MQTT: GarageESP/Door/Status
MQTT: Publish to GarageESP/Door/Status -> OK
Message will repeat in 5000.
Hi. I'm a nodemcu running the Garage Door code
Current state: Closed. MQTT: GarageESP/Door/Status
MQTT: Publish to GarageESP/Door/Status -> OK
Message will repeat in 5000.


I'll document how I did it tomorrow, but it's all just cross compiling with another debian machine and some guess work.
It's still wonky, though, it takes a couple of tries before it will show up.




« Last Edit: July 26, 2020, 05:29:11 pm by drbytes »

cam1965

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • http://
Re: FTDI_SIO
« Reply #11 on: July 26, 2020, 05:39:51 pm »
congratulations. I saw a message when you did a command (  unable to resolve host cosmopda: Name or service not known ) .  Just edit /etc/hosts and in the first line change to :
127.0.0.1 cosmopda

« Last Edit: July 26, 2020, 05:44:05 pm by cam1965 »

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: FTDI_SIO
« Reply #12 on: July 26, 2020, 06:03:07 pm »
Ah ha, thx for the tip, I hate that message.

So here's how I did it:

I'll post it here in case I need to do this in the future and I've forgotten it :)
Install debian in a virtual machine and execute these commands :

Code: [Select]
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc git
mkdir cosmo
cd cosmo
mkdir KERNEL_OUT
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b nougat-release --depth 1
This is the cosmo kernel used in the 24/07 build
Code: [Select]
git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git
cd cosmo-linux-kernel-4.4/

Edit the Makefile
Code: [Select]
nano Makefile --> Find "KBUILD_CFLAGS" and change the line
Code: [Select]
KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ to
Code: [Select]
KBUILD_CFLAGS   := -w -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
Import the latest kernel config, it's the one that is in the 24/07 build
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 k71v1_64_bsp_defconfigConfigure your kernel and save to the default .config location
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfigbuild it
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
Your module should be in ../KERNEL_OUT/drivers, just scp it over to your cosmo, depmod and modprobe it.

Enjoy



cam1965

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • http://
Re: FTDI_SIO
« Reply #13 on: July 26, 2020, 07:06:46 pm »
Hi.
Instead of  git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b nougat-release --depth 1  please change to  :  sudo apt-get install   gcc-aarch64-linux-gnu because later you did make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
And also in the first lines
 mkdir cosmo
cd cosmo
mkdir KERNEL_OUT

please change to only mkdir KERNEL_OUT. Because the KERNEL_OUT is not inside Cosmo directory.
 
I am surprised that these cross compilation works fine without any changes in this kernel source tree. In the  previous kernel source tree I had to change and link some files to the correct directory. This is very good. Unfortunately if compiling inside cosmo , a lot of changes are still needed.
« Last Edit: July 26, 2020, 08:00:26 pm by cam1965 »

Varti

  • Administrator
  • Hero Member
  • *****
  • Posts: 1280
    • View Profile
Re: FTDI_SIO
« Reply #14 on: July 27, 2020, 02:19:07 am »
Congratulations! May I ask you if you could open a new thread here with a copy of these steps and with a title like "How to crosscompile the Cosmo Linux' kernel"? I'd pin that topic for future reference, I believe it will be useful for other people too. Thanks.

Varti
Planet Gemini PDA WiFi/LTE with Mediatek x27
SL-C1000 running Arch Linux ARM May2017, K30225 Wi-Fi CF Card, 64GB SDXC card
and many other Zauruses!