Missing ch340 / usbserial modules for uart converter in resin 2.2.0

Hi,

I want to work with usb serial converter that uses driver ch341 and depends on usbserial module. In desktop linux it is present in /lib/modules/4.10.0-28-generic/kernel/drivers/usb/serial/. However in ResinOS 2.2.0 the folder does not exist. That I assume is that by choice those modules were not built in into kernel. What is the idea on how to add them / load them into kernel? Of course to load them correctly they should be compiled with the kernel version of ResinOS.

Kind regards,
llap

Hi @llap, there’s an experimental project to show how to add your custom kernel modules. It’s very work in progress, and feedback is appreciated.

We are also working on a quite different approach to add kernel modules, will keep everyone posted here in the forums, that should fix a lot of these more complicated issues by a much more powerful solution.

I am trying to connect it all (by the way I am trying to build module that in standard is in kernel tree, wouldnt it be easier for me just to compile the exact same kernel as I am using intel? Can you provide the link to the kernel you are using?).

  1. I have cloned mentioned repository (kernel-module-build)
  2. I have checked version of kernel for 2.2.0.dev which is 4.8.17
  3. I have downloaded file ch431.c from kernel version from source code
    https://github.com/torvalds/linux/tree/v4.8/drivers/usb/serial
  4. I have changed Makefiles and Dockerfile

[[Dockerfile]]

FROM resin/intel-nuc-debian
RUN apt-get update && apt-get install -y curl wget build-essential
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN ./build.sh intel-nuc '2.2.0+rev1.dev' ch341
CMD ./run.sh

[[Makefile]]

KERNEL_TREE_PATH?=/lib/modules/$(shell uname -r)/build
EXTRA_CFLAGS="-DDEBUG"

obj-m+=ch341.o
all: ch341.ko

ch341.ko: ch341.c
                make -C $(KERNEL_TREE_PATH) M=$(PWD) modules
clean:
                make -C $(KERNEL_TREE_PATH) M=$(PWD) clean

.PHONY: all clean

I get the result

Step 5/6 : RUN ./build.sh intel-nuc '2.2.0+rev1.dev' ch341
 ---> Running in 4b0607a3ef86
Building images/intel-nuc/2.2.0+rev1.dev/kernel_modules_headers.tar.gz...
--2017-08-05 16:26:35--  https://files.resin.io/images/intel-nuc/2.2.0%2Brev1.dev/kernel_modules_headers.tar.gz
Resolving files.resin.io (files.resin.io)... 34.226.173.211, 54.152.194.198
Connecting to files.resin.io (files.resin.io)|34.226.173.211|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9883956 (9.4M) [application/x-tar]
Saving to: ‘kernel_modules_headers.tar.gz’

     0K .......... .......... .......... .......... ..........  0%  201K 48s

  9650K ..                                                    100% 4388G=4.6s

2017-08-05 16:26:40 (2.05 MB/s) - ‘kernel_modules_headers.tar.gz’ saved [9883956/9883956]

make: Entering directory '/tmp/tmp.zmkPme4h3t'
  CC [M]  /usr/src/app/ch341_intel-nuc_2.2.0+rev1.dev/ch341.o
/bin/sh: 1: scripts/basic/fixdep: not found
scripts/Makefile.build:295: recipe for target '/usr/src/app/ch341_intel-nuc_2.2.0+rev1.dev/ch341.o' failed
make[1]: *** [/usr/src/app/ch341_intel-nuc_2.2.0+rev1.dev/ch341.o] Error 127
Makefile:1473: recipe for target '_module_/usr/src/app/ch341_intel-nuc_2.2.0+rev1.dev' failed
make: Leaving directory '/tmp/tmp.zmkPme4h3t'
make: *** [_module_/usr/src/app/ch341_intel-nuc_2.2.0+rev1.dev] Error 2
 ---> f598afc579b1

Hey, looks like that is might be an library linking issue, the fixdep tool is looking for /lib/ld-linux-x86-64.so.2 but that should be symlinked to /lib64/ld-linux-x86-64.so.2, and it’s not. Since it doesn’t find the relevant library, it cannot run. It’s fixed up by having this line somewhere in your Dockerfile before the build step.

RUN ln -s /lib64/ld-linux-x86-64.so.2 /lib/ld-linux-x86-64.so.2

I’ve tried it out, and the module seems to be building fine with that. The rest of the changes you made seem to be spot on. Hope this will help!

Will be following up with this issue to see what’s up with those libraries.

Hey @imrehg, you mentioned in your post that you are working on different approach to adding kernel modules. Do you have any updates on that?

@llap we are adding support for host apps, these will allow you to customise the host using the same Dockerfile + git push solution we provide for user apps. The feature is currently in for review.

Hey @joe is that functionality operational? Or anytime soon?

@llap it should be available in the next month or so.

@llap actually i have the same issue with a Pi 3. Have you a more recent working solution?
The RUN of build.sh for some reason doesnt have enough permissions. And if i try to use ‘sudo’ the command is not found.
But im in a different case, because im using a docker-compose and then ive to modify the Dockerfile.
Ill post a little bit of structure

-docker-compose
-main
    |
    --build.sh 
    --ch341_module

My compose:

version: '2'
services:
  nostromo:
build: ./main
privileged: true
restart: always
labels:
  io.balena.features.kernel-modules: '1'
  io.balena.features.firmware: '1'
  io.balena.features.dbus: '1'
  io.balena.features.supervisor-api: '1'
  io.balena.features.belena-api: '1'
  io.balena.update.strategy: download-then-kill
  io.balena.update.handover-timeout: ''

My piece of dockerfile:

COPY build.sh /usr/src/app
WORKDIR /usr/src/app
RUN ln -s /lib64/ld-linux-x86-64.so.2 /lib/ld-linux-x86-64.so.2
RUN ./build.sh %%BALENA_MACHINE_NAME%% '2.43.0+rev1.dev' ch341

and the error:

Some services failed to build:
    nostromo: The command '/bin/sh -c ./build.sh raspberrypi3 '2.43.0+rev1.dev' ch341' returned a non-zero code: 126

Hello @patonz91, you likely need to make your sh file executable by adding a line like “RUN chmod +x /usr/src/app/build.sh” in your Dockerfile after the initial COPY.

Thank you @alanb128 seems to work (the build). they both posted the solutions without this command before the run, i think the docker-compose works different.
Btw, the module now use the serial and its loaded but my app (johnny-five app) cant comunicate with the board as the module wont exist in the container or something like that.

lsmod used on the Host Os

$ lsmod | grep ch34
ch341                  16384  0
usbserial              40960  1 ch341

And i got the same result on the service.

Im using a Pi 3 with an usb cable to an arduino nano clone (i need the ch34 driver for that reason) and im controlling the board with the firmata protocol. Without the balenaOS system and Pi3 it works perfectly in both windows and ubuntu OS.
Its the same as described here https://medium.com/@tomasmigone/interfacing-raspberry-pi-3-and-arduino-with-remote-monitoring-and-upgradeability-eec512ad3dc2 but with a clone board.

  • UDEV=on on dockerfile
  • privileged: true on docker-compose
  • FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:10-run is the base image

Do you mean that code within the container cannot see the arduino clone? Likely you will have to add that into the container using the docker-compose devices field: https://docs.docker.com/compose/compose-file/compose-file-v2/#devices

Let me know if this does not help.

@CameronDiver no, it doesnt work. should i use
CMD like this?

CMD modprobe i2c-dev && modprobe usbserial && chmod +x run.sh && ./run.sh && npm start

because after a purge data ( had pins locked) the lsmod wont show the module loaded in the host OS but only in the container:

19.12.19 21:02:25 (+0000)  nostromo  OS Version is 2.43.0+rev1
19.12.19 21:02:25 (+0000)  nostromo  Loading module from ch341_module_raspberrypi3_2.43.0+rev1.dev
19.12.19 21:02:25 (+0000)  nostromo  ch341                  16384  0
19.12.19 21:02:25 (+0000)  nostromo  usbserial              40960  1 ch341

and the nodejs app wont start totally.

That CMD line should work, it definitely needs to be the CMD and not RUN so that it’s executed at runtime. What is the output?

For a faster debugging im opening to support access if u want. but simply for now the script work until e load of the module, the npm start didnt show up @CameronDiver

If you enable support access and provide me with the dashboard link I’ll be happy to take a look.

Did, i hope :smiley:

I still need the dashboard link to your device, otherwise I can’t find it.

sent u a private mex btw: https://dashboard.balena-cloud.com/devices/3ae398f61d26d6654cb688c0eec67e4d/summary

Can you post the contents of run.sh please? It looks to me as if perhaps that script is not exiting, and that’s why the npm start never happens.