Kernel Module Compilation Howto

Looking for discussion about hardware compatibility? Look no further.

Moderator: Lillian.W@AST

spinningplanet
Posts: 15
youtube meble na wymiar Warszawa
Joined: Wed Nov 02, 2016 11:04 am

Kernel Module Compilation Howto

Post by spinningplanet »

Does anyone know of an Asustor Kernel Module Compilation Howto? I need to compile this Exar USB Serial Driver so I can communicate with my solar Charge Controller from my AS1002T NAS: https://github.com/kasbert/epsolar-trac ... _common-1a

Asustor support gave me an overview such as compile kernel with new device source but I need a bit more of an explanation than that. Can anyone help? I'm familiar with Linux but new to cross compiling. Here's what Asustor support said:
Hi, thank you for your question, and we have pass your need to our technical staff. And please follow the suggestions they replied:
The driver will need to be compiled with our Kernel , then compile the code by our tool chain. The brief steps are as below:
1. Download the tool chain. The tool chain can be obtained from http://developer.asustor.com
2. Download the kernel source code. The linux kernel can be obtained from https://sourceforge.net/projects/asgpl/
3. Use the makefile for our GPL, and add the driver module to the kernel source code location. Setup the kernel configuration, and set this driver as "module"
4. Compile the kernel , and it will also build the module for this driver.
5. Find the driver module location, then transfer to NAS :
/usr/local/bin
6. Follow the commands to install the driver module.
# rmmod cdc-acm
# modprobe -r usbserial
# modprobe usbserial
# insmod ./xr_usb_serial_common.ko

We hope that it helps you fix the problem. Thank you.
brynn :-)
User avatar
orion
Posts: 3485
Joined: Wed May 29, 2013 11:09 am

Re: Kernel Module Compilation Howto

Post by orion »

I did not try to create another device driver module before for my NAS. However the tips that you attached seem to be clear. It's better that you can describe the errors on which step you encountered.
User avatar
father.mande
Posts: 1815
Joined: Sat Sep 12, 2015 2:55 am
Location: La Rochelle (France)

Re: Kernel Module Compilation Howto

Post by father.mande »

Hi,

You start in interesting job if it's the first time you (try) to build modules :D

I don't use the "support" methodology ... but I am certainly not so expert than us
It's not easy to shortly write a response with all the detail of operations and all possible error, mistake ... especially when adding cross-compile ... that I have abandoned from years (except for creating a first working environment on a platform or for very limited platform as IoT support for ex. )
I use the "native" method

the steps are (shortly and sorry but no time to enter in detail ... ask support) :
I start at this point without cross-compile (replace by an Ubuntu 14.04 chroot INSIDE the NAS (in this case a 1002T) with the build-essential package and curl for an easy menu approach to configure kernel)
get GPL source, extract it in a safe place (not cleared at boot) with write right
copy the config file in the base of the GPL source rename it .config
run
make oldconfig (validation + generation of basic libs)
then
make menuconfig
... in this menu select the modules you need with M to generate modules
At end (save new config)
generate the module
make path_to/module.ko (or all the modules in a folder ... depends of your request) be attention to dependency between modules
IT'S ABSOLUTELY NOT necessary to rebuild all the kernel and modules to add only one or two ... (so conflict with support recommendation)
and you win hours ... (if you have doubt rebuild all modules but not all kernel)
move the module to the good place ... /usr/local/bin don't appear to be a safe place it's not binary files ... the default place is /lib/modules/KERNEL_VERSION/ but clear at each boot and linked to builtin
... creating a fake APKG can be good (so you can also later load modules automatically at boot)
last insert it
... suggest to don't use modprobre (only rrmod and insmod) to avoid future problem if a true modprobe is delivered in a new ADM or through any APKG (ex. Entware)
... the modprobe provide in Asustor is the castrated Busybox version ... so absolutely NO interest ...

So I can't help you any more ... and suggest you to follow support recommendation to get also help ...

F.Y.I. reason of my choice :
chroot will be done only ONE time and can be used for lot of other usages ...
creating native module is less of 10 mns
No need to have another platform with cross-compile tools to build something (only the NAS and a ssh console)
deferring the action during the night or reducing the priority to don't impact normal usage is in "a" command ...
screen or tmux can be used if you don't want to stay connected (even time is short)

BUT I repeat ... using Asustor solution if it's the first time you run this kind of things ... is better ... because you can have professional help.

Philippe.
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
spinningplanet
Posts: 15
Joined: Wed Nov 02, 2016 11:04 am

Re: Kernel Module Compilation Howto

Post by spinningplanet »

Thanks for your great advice guys. First I'll try without cross-compile and will let you know how things go.
User avatar
father.mande
Posts: 1815
Joined: Sat Sep 12, 2015 2:55 am
Location: La Rochelle (France)

Re: Kernel Module Compilation Howto

Post by father.mande »

Hi,
spinningplanet wrote:Thanks for your great advice guys. First I'll try without cross-compile and will let you know how things go.
Just having a short look ... seems that usbserial is builtin in the kernel (kallsyms is referring to the call function in ... ) ... don't know if it's due to my ADM version ?
my version is ADM 2.6.5 R9N1 so without source in Asustor GPL source ...
but loading module write a clear message ...
usbserial: exports duplicate symbol usb_serial_resume (owned by kernel)

So perhaps your job is limited to the extra module ...

Philippe.
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
User avatar
father.mande
Posts: 1815
Joined: Sat Sep 12, 2015 2:55 am
Location: La Rochelle (France)

Re: Kernel Module Compilation Howto

Post by father.mande »

Hi,

LAST due to the small works (no usbserial.ko to generate) need to do a test (I have 10 minutes free) ... I have created the xr_usb_serial_common.ko module and load it ... seems without problem ...

Code: Select all

# lsmod
Module                  Size  Used by
xr_usb_serial_common    22973  0
cifs                  244312  0
snd_seq_midi            4006  0
without error in syslog :

Code: Select all

[2689130.253147] usbcore: registered new interface driver cdc_xr_usb_serial
[2689130.259879] xr_usb_serial_common: Exar USB UART (serial port) driver
Even if I have absolutely NO IDEA of the usage :lol: :lol:
So you can expect a good result ... after it's another story ...

Philippe.
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
spinningplanet
Posts: 15
Joined: Wed Nov 02, 2016 11:04 am

Re: Kernel Module Compilation Howto

Post by spinningplanet »

I'm trying to compile on my Fedora Linux and have made some progress. Here's the steps so far:

Downloaded the tool chain: arm-marvell-linux-gnueabi.tar.gz from http://developer.asustor.com
Downloaded the kernel source code: GPL_linux-4.1.0.tar.bz2 from https://sourceforge.net/projects/asgpl/
Downloaded the driver source: xr_usb_serial_common_lnx-3.6-and-newer-pak.zip from https://www.exar.com/design-tools/software-drivers

Decompressed files into /home/user/asustor and installed required packages for cross compilation

Created a minimal kernel config with:

Code: Select all

make tinyconfig ARCH=arm KERNEL_SRC=/home/user/Downloads/asustor/linux-4.1.0 CROSS_COMPILE=arm-marvell-linux-gnueabi-
Made the kernel without issues with:

Code: Select all

make ARCH=arm KERNEL_SRC=/home/user/Downloads/asustor/linux-4.1.0 CROSS_COMPILE=arm-marvell-linux-gnueabi-
Changed to xr_usb_serial_common_lnx-3.6-and-newer-pak folder and ran:

Code: Select all

make ARCH=arm KERNEL_SRC=/home/user/Downloads/asustor/linux-4.1.0 CROSS_COMPILE=arm-marvell-linux-gnueabi- KERNELDIR=/home/user/Downloads/asustor/linux-4.1.0
And get all these errors:

Code: Select all

[root@localhost xr_usb_serial_common_lnx-3.6-and-newer-pak]# make ARCH=arm KERNEL_SRC=/home/user/Downloads/asustor/linux-4.1.0 CROSS_COMPILE=arm-marvell-linux-gnueabi- KERNELDIR=/home/user/Downloads/asustor/linux-4.1.0
make -C /home/user/Downloads/asustor/linux-4.1.0 M=/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak
make[1]: Entering directory '/home/user/Downloads/asustor/linux-4.1.0'
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "usb_deregister" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_std_termios" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "put_tty_driver" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_unregister_driver" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_register_driver" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_register_driver" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_set_operations" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "__tty_alloc_driver" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_register_device" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_get_intf" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_driver_claim_interface" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "device_create_file" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_alloc_urb" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_alloc_coherent" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_init" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "__mutex_init" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_ifnum_to_if" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "__kmalloc" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "__memzero" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "memcmp" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_termios_baud_rate" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "__udivsi3" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_flip_buffer_push" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_insert_flip_string_fixed_flag" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "_set_bit" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "_test_and_clear_bit" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_control_msg" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_standard_install" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_open" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_close" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_hangup" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_tty_wakeup" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "system_wq" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "queue_work_on" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_tty_hangup" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_submit_urb" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "kfree" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_put_intf" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_driver_release_interface" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_free_urb" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_unregister_device" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "cancel_work_sync" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_kill_urb" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_vhangup" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_tty_get" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "mutex_unlock" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "device_remove_file" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "mutex_lock" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "memcpy" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "sprintf" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "tty_port_put" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
WARNING: "usb_free_coherent" [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.ko] undefined!
  CC      /home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.o
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:8:1: error: variable '__this_module' has initializer but incomplete type
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:9:2: error: unknown field 'name' specified in initializer
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:9:2: warning: excess elements in struct initializer [enabled by default]
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:9:2: warning: (near initialization for '__this_module') [enabled by default]
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:10:2: error: unknown field 'init' specified in initializer
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:10:2: warning: excess elements in struct initializer [enabled by default]
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:10:2: warning: (near initialization for '__this_module') [enabled by default]
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:14:2: error: unknown field 'arch' specified in initializer
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:14:10: error: 'MODULE_ARCH_INIT' undeclared here (not in a function)
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:14:2: warning: excess elements in struct initializer [enabled by default]
/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.c:14:2: warning: (near initialization for '__this_module') [enabled by default]
scripts/Makefile.modpost:113: recipe for target '/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.o' failed
make[2]: *** [/home/user/Downloads/asustor/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.mod.o] Error 1
Makefile:1387: recipe for target 'modules' failed
make[1]: *** [modules] Error 2
make[1]: Leaving directory '/home/user/Downloads/asustor/linux-4.1.0'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2
I know I may be doing it totally the wrong way because I've never had to cross compile for arm before. Let me know what you think.

brynn :-)
User avatar
orion
Posts: 3485
Joined: Wed May 29, 2013 11:09 am

Re: Kernel Module Compilation Howto

Post by orion »

Hi brynn,

I think you are in the right direction. The problem is basically caused by kernel version mismatch: Exar driver source code can only support kernel 3.6.x or 2.6.x. The driver source code that you downloaded is for kernel 3.6.x. And you are using kernel 4.1.x.

Luckily, your AS1 model should adopt kernel 3.10.x (I'm not sure about it because I don't own AS1). You should download kernel 3.10.x (https://sourceforge.net/p/asgpl/activit ... 7582d81bb3) to have a try. Or you'll need to solve those kernel symbol errors.

EDIT: I just tried it under kernel 3.10.x. Everything seem fine during compiling process.
User avatar
father.mande
Posts: 1815
Joined: Sat Sep 12, 2015 2:55 am
Location: La Rochelle (France)

Re: Kernel Module Compilation Howto

Post by father.mande »

Hi,

Yes using 3.10.70 kernel for Arm also seem it works (no error

and just to reduce your works ... NO NEED to generate the kernel (because Asustor don't generate the full modules structure ... so you work (for you or for the wind ... not for real usgae )
just generate your own module (or if you have done one ... generate only the modules (make modules))

Philippe.
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
User avatar
father.mande
Posts: 1815
Joined: Sat Sep 12, 2015 2:55 am
Location: La Rochelle (France)

Re: Kernel Module Compilation Howto

Post by father.mande »

Hi,

To complete,

I have generate on Ubuntu x86_64 (amd64)
... the cross-compile
... get the GPL source 3.10.70
... get the config file for arm kernel
... make oldconfig
... get the xr_usb_serial_common source
... generate the module
... transfer to Asustor 1002T
... load it
... all seems OK no error, same message as with native module

... so the only (but interesting) things to use native is to don't need a Linux box , no need to install cross-compile tools ... and without risk of error (kernel is same ... and no parameters due to the architecture, cross-compile, etc. )

Philippe.
N.B. I don't put here module created ... because it's better for you ... for the future to fully know and manage it, but if your problem persist ... don't hesitate to ask it :D
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
Post Reply

Return to “Hardware Compatibility”