Jump to content

[Solved] Recompile a kernel module with one custom modification?


temach

Recommended Posts

I have a non compliant usb device that I want to work with my Orange Pi Lite board.

I know how to make it work under Arch linux. For that I need to edit source for the usb generic hid driver (kernel/drivers/hid/hid-core.c), recompile the usb kernel module and reinstall it to intramfs (mkinitcpio -p linux). To recompile kernel module I followed this guide: https://wiki.archlinux.org/index.php/Compile_kernel_module

 

What procedure do I need to follow under Armbian?

 

One way is to set up a development environment on a PC, with Virtual Box running Ubuntu Xenial, etc. Recompile the whole armbian and copy the compiled kernel module over to Orange Pi Lite.

 

But it takes a long time. Is there any way to recompile a kernel modue directly on the board?

 

Thanks for your time.

Link to comment
Share on other sites

I know how to make it work under Arch linux. For that I need to edit source for the usb generic hid driver (kernel/drivers/hid/hid-core.c), recompile the usb kernel module and reinstall it to intramfs (mkinitcpio -p linux).

hid-core.c is a built-in object, so full kernel recompilation is required. Compiling the kernel on the board itself is possible, but there is no automation for this process yet, so you have to do everything manually - clone the sources, grab and apply the patches, grab the kernel config, compile and install resulting packages.

Link to comment
Share on other sites

In the end I decided to go with creating a x-compile environment to get a patched hid.ko.gz

However I just noticed that my current armbian does not have a hid.ko.gz module. It has only g_hid.ko.gz

 

So would I go about installing a hid.ko.gz module?

 

my current setup: (uname -r)

Linux orangepilite 3.4.112-sun8i #10 SMP PREEMPT Sun Oct 23 16:06:55 CEST 2016 armv7l GNU/Linux

Legacy Debian Jessie

Link to comment
Share on other sites

Alright, I will just leave the instructions here for the record:

 

So I went with x-compiling.

 

(looks like now there is a vargrand config to set up the x-compile environment, so you can use that)

 

Installed VitrualBox & put Ubuntu Xenial on it.

sudo apt-get install linux-headers-$(uname -r) build-essentials

Then according to https://github.com/igorpecovnik/lib

I git cloned the lib

Then edited the compile.sh with the following options:

 

 

 

KERNEL_ONLY="yes" # leave empty to select each time, set to "yes" or "no" to skip dialog prompt
KERNEL_CONFIGURE="no" # change provided kernel configuration
CLEAN_LEVEL="make,debs" # comma-separated list of clean targets: "make" = make clean for selected kernel and u-boot,
# "debs" = delete packages in "./output/debs" for current branch and family,
# "alldebs" - delete all packages in "./output/debs", "images" = delete "./output/images",
# "cache" = delete "./output/cache", "sources" = delete "./sources"

DEST_LANG="en_US.UTF-8" # sl_SI.UTF-8, en_US.UTF-8

# advanced
KERNEL_KEEP_CONFIG="no" # do not overwrite kernel config before compilation
EXTERNAL="no" # build and install extra applications and drivers
EXTERNAL_NEW="no" # compile and install or install prebuilt additional packages
CREATE_PATCHES="yes" # wait that you make changes to uboot and kernel source and creates patches
FORCE_CHECKOUT="yes" # ignore manual changes to source
BUILD_ALL="no" # cycle through available boards and make images or kernel/u-boot packages.
# set KERNEL_ONLY to "yes" or "no" to build all packages/all images
BUILD_DESKTOP="no"
BOARD="orangepilite"
BRANCH="default"
RELEASE="jessie"

 

 

 

Then I run ./compile.sh with sudo.

 

Then when the script got to kernel compilation, I was prompted to edit the code and continue.

So I went ahead and modified the sources/linux-sun8i/sun8i/drivers/hid-core.c

Then I hit enter to let compilation continue and it told me that a patch was generated.

 

However that patch did not seem to get applied. So I moved the patch into userpatches/kernel/sun8i-default/my-kernel-patch.patch

and restarted the whole compile process (this time I compiled with CREATE_PATCHES="no")

 

In the end I got the deb files in the output

 

 

.
├── extra
├── jessie
│   └── linux-jessie-root-orangepilite_5.24_armhf.deb
├── linux-firmware-image-sun8i_5.24_armhf.deb
├── linux-headers-sun8i_5.24_armhf.deb
├── linux-image-sun8i_5.24_armhf.deb
└── linux-u-boot-orangepilite_5.24_armhf.deb

 

 

 

I used scp to copy them over to the orange pi lite.

After reading this thread: https://forum.armbian.com/index.php/topic/1315-custom-kernel-and-apt-get-update/

I realised that I only needed the headers, image and firmware debs. So I went ahead and installed them

with "sudo dpkg -i *.deb" (after removing u-boot deb package).

 

Then I pinned them, so they dont get changed on the next "apt-get upgrade".

And it works!

Thanks everyone!

 

Overall the toolchain is a bit difficult to grasp (argh, and the constant recompiles are off putting!), but serious kudos to you for creating and maintaning it! Because it actually works!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines