S
S
smithana2017-07-31 20:54:52
linux
smithana, 2017-07-31 20:54:52

Is it possible to build a driver (kernel module) for Linux x86 in Linux x64?

Good afternoon,
on Windows, with the Windows Driver Kit compilers, I can compile a driver for almost any version of Windows.
Is there a similar possibility for Linux? e.g. Ubuntu.
I already understood how to compile for a different version of the kernel. For example, I had Ubuntu 16 on the 4.4 kernel and needed a driver for the 4.8 kernel.
Using the commands:
apt-cache search linux-image
sudo apt-get install linux-image-your_version_choice
sudo apt-get install linux-image-extra-your_version_choice
I changed the kernel to 4.8 and built the driver.
Is this correct?
But more questions are caused by the need to build a driver for x86 in the x64 distribution.
I didn't find anything concrete about this.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2017-07-31
@smithana

All you need to build a module for a kernel of any architecture of any version is the compiler for that architecture, the kernel sources, and the .config for that kernel.
The steps are:
- unpack/check out the kernel sources of the desired version
- create and configure the kernel build directory: create a directory, copy .config into it, execute

make -C <каталог исходников ядра> \
O=<каталог сборки ядра> \
ARCH=<целевая архитектура> \
CROSS_COMPILE=<префикс кросс-компилятора> \
silentoldconfig

- assemble the kernel:
make -C <каталог исходников ядра> \
O=<каталог сборки ядра> \
ARCH=<целевая архитектура> \
CROSS_COMPILE=<префикс кросс-компилятора> \
vmlinux

- build the module using the directory created in the previous step:
make -C <каталог сборки ядра> \
M=<каталог исходников модуля> \
ARCH=<целевая архитектура> \
CROSS_COMPILE=<префикс кросс-компилятора> \
modules

CROSS_COMPILE can be omitted if the host compiler is to be used. For x86 ARCH=x86

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question