Cross compile module linux

Cross Compiling Linux Arm Kernel with new driver module

I am trying to include a driver for use on my arch linux arm machine. I tried using these steps to include the driver module, but my cross-compiled kernel with the added driver doesn’t load.

1) Include the driver I want to add by making it have < M >beside it's name in make ARCH=arm menuconfig 2) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- (the path for my cross-compiling toolchain) 3) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- modules 4) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- install 5) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- modules_install 6) copy my uImage from: arch/arm/boot to my boot location: /tftpboot/ 

Then when my embedded linux arm tries to load the kernel uImage, it hangs with: EDIT: Changed the entry point address to 80008000, so now it hangs with:

Filename '/tftpboot/uImage'. Load address: 0x81800000 Loading: ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# #################################### done 

Booting kernel from Legacy Image at 81800000 .

Image Name: 2.6.35-ModifiedEntry
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 3174784 Bytes = 3 MiB
Load Address: 80008000
Entry Point: 80008000
Verifying Checksum . OK
Loading Kernel Image . OK
OK Starting kernel . Am I cross-compiling my kernel wrong? It cannot load the uImage. All I want to do is cross compile my kernel for the linux arm machine with a newly included driver (included in the config from make menuconfig). Am I missing any additional steps?

Источник

Cross compiling Linux ARM kernel modules

This guide will allow you to cross-compile a loadable kernel module (LKM; a.k.a. device driver) for a ARM Linux system.

Читайте также:  Linux password from hash

1. Target system

I will use this configuration as an example, but you can apply the same method for other environments.

2. Download linux kernel source

You must download the exact version which is running in the qemu.

Note that source for 3.2.0 is named linux-3.2.tar.gz , not linux-3.2.0.tar.gz .

3. Download cross compiler toolchain

Linaro’s prebuilt toolchain generally works well. Download one from https://releases.linaro.org/components/toolchain/binaries.

Pick a version, and choose the appropriate architecture. In our case, it would be arm-linux-gnueabihf (ARM 32-bit, linux, little endian, hard float).

There are three kinds of files: gcc-linaro- , runtime-gcc-linaro- , and sysroot-eglibc-linaro- . You only need the first one. For more info, refer to this Linaro wiki page.

For instance, go to 4.9-2017.01/arm-linux-gnueabihf/ directory and download gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz .

4. Take out kernel build config

We need to build the kernel first, and then build a kernel module. But to compile a kernel, we must have the exact build configuration of the currently running Linux system. Fortunately, you can get a copy from a running system. Look at these locations:

Copy the file out of the qemu using scp or something.

5. Build the kernel

You need auto-generated files in order to build a kernel module. Otherwise you may encounter an error message like this:

/home/ubuntu/linux-3.2/include/linux/kconfig.h:4:32: fatal error: generated/autoconf.h: No such file or directory #include ^ 

To build a kernel with given config file,

cd cp .config make ARCH=arm CROSS_COMPILE=/bin/arm-linux-gnueabihf- oldconfig make ARCH=arm CROSS_COMPILE=/bin/arm-linux-gnueabihf- 

Complete kernel build may not be necessary because what you need is generated header files.

6. Build the module

Write a Makefile as follows:

PWD := $(shell pwd) obj-m += hello.o all: make ARCH=arm CROSS_COMPILE=$(CROSS) -C $(KERNEL) SUBDIRS=$(PWD) modules clean: make -C $(KERNEL) SUBDIRS=$(PWD) clean 

And create a hello world module.

// hello.c #include #include  int init_module(void)  printk(KERN_INFO "Hello world.\n"); return 0; > void cleanup_module(void)  printk(KERN_INFO "Goodbye world.\n"); > 
make KERNEL= CROSS=/bin/arm-linux-gnueabihf- 

Then you will get hello.ko compatible with the running ARM Linux.

Источник

Cross Compile Linux Kernel Module

I am looking into cross compiling a kernel module for an ARM linux. I have my toolchain installed. But there’s something I am not quite getting from various how-tos. The module I want to build is gadgetfs . The kernel version on my host is 3.5.0-34-generic while on the target it’s 3.6.9-0.1 Now what kernel sources or headers do I actually need to download and install, and where? I downloaded linux-3.6.9.tar.bz2 from kernel.org and extracted it. In drivers/usb/gadget/ there’s a Makefile and according to this site I need to append these lines to it, then run make :

KDIR := /lib/modules/`uname -r`/build PWD := `pwd` obj-m := dummy_hcd.o gadgetfs.o default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules 

But what do i have to replace uname -r with? Cause this would give me my host’s kernel version. But my target version is different. Where is the /lib/modules/3.6.9 folder? CROSS_COMPILE and ARCH is both set.

1 Answer 1

You need to cross compile (or download pre-compiled) matching version of Linux for your target on your host machine with right configuration since Linux doesn’t have a stable binary API. Host’s kernel version is not relevant.

After having target build available on your host you can build a module via

make -C kernel_build_dir M=`pwd` ARCH=arm CROSS_COMPILE= modules 

under that module’s directory.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.13.43531

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Кросскомпиляция модуля helloworld

Добрый день.
Пытаюсь собрать модуль helloworld под другую машину. Хост x86_64, таргет armhf.
Установил кросскомилятор /usr/bin/arm-linux-gnueabihf-gcc, скачал исходники ядра под данную машину ~/projects/linux-3.4.113/
Пытаюсь собрать (пробовал через makefile, переменные, но поскольку ничего не получилось, пытаюсь уже в лоб):
/usr/bin/arm-linux-gnueabihf-gcc -I~/projects/linux-3.4.113/ -c ./helloworld.c (и много всяких мелких вариаций похожей команды)
На что раз за разом получаю ругань о том, что linux/modules.h не найден.
Может кто объяснить что я делаю не так, и как надо правильно? Исходный код helloworld:

/* * hello-1.c - The simplest kernel module. */ #include /* Needed by all modules */ #include /* Needed for KERN_INFO */ int init_module(void) < printk(KERN_INFO "Hello world 1.\n"); /* * A non 0 return means init_module failed; module can't be loaded. */ return 0; >void cleanup_module(void)
CC := g++ TOOLCHAIN := arm-linux-gnueabihf PT := CFL := -Wextra -std=c++11 TPATH := /usr/bin/ LPATH := /usr/$(TOOLCHAIN)/ ARCH := arm all: helloworld.c $(TPATH)$(TOOLCHAIN)-$(CC) $(CFL) $(ARCH) -o helloworld.c 

может -I~/projects/linux-3.4.113/include по крайней мере пути к хеадерам ядра идут начиная с этой точки.

Пробовал и такой вариант. Пробовал даже в коде модуля написать «путь до хидера», он их подхватывал, но разумеется дальше шли проблемы с тем, что он не находил вложенные хидеры.

там надо смотреть чего не хватает. например в обычном include в системе есть папка asm, которая то же из kernel-headers идет. соответственно она должна находится по указанному пути. но ее там нет, может потребоваться символические ссылки сделать. так же попробуйте взять пакет kernel-headers для нужного вам ядра и развернуть его куда нибудь отдельно

Да, в этой папке нет asm. Она есть в /usr/arm-linux-gnueabihf/include, ее я тоже пробовал через -I добавлять.

Собрать модуль ручками — это довольно нетривиальная задача. Даже если у тебя получится его скомпилировать, слинковать самостоятельно ты его почти наверняка не сможешь. Так что так ни кто не делает. Просто запиши обычный ядерный Makefile и собирай через него, как-то так: make M=$PWD -C ~/projects/linux-3.4.113/ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-gcc . Да, кроме самих исходников нужен будет конфиг ядра и подготовить дерево исходников для сборки модулей примерно так: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-gcc modules_prepare

Источник

Оцените статью
Adblock
detector