D
D
dlinyj2013-07-05 15:27:36
linux
dlinyj, 2013-07-05 15:27:36

Kernel module for OpenWRT. PowerPC

I am compiling OpenWRT Trunk for one specific piece of hardware on a PowerPC processor (the latter is not very important, I just give it for reference).

And I need to write a driver. I have little experience in developing kernel modules for x86 machines running Ubuntu (I took courses, wrote test game modules).
Now I want to try to write at least the "Hello World" module. I started with an excellent post by comrade Ariman . But I immediately came across the fact that I have a different folder structure

Namely
В статье сказанно:

Заходим в target/linux/ar71xx/files/drivers и выполняем там mkdir video, создав директорию для нашего драйвера. Buildroot раскидывает содержимое files по соответствующим директориям дерева исходников. Помещаем файл usblcd.c в только что созданную папку.


В моём случае папка будет иметь вид: ~/trunk/openwrt-trunk/target/linux/mpc83xx/files, но в ней уже нет папки drivers. Там просто выглядит всё так:

[email protected]:~/trunk/openwrt-trunk/target/linux/mpc83xx/files$ ls
scripts


В папке только скрипты. Следовательно тут ждал меня облом



As a result, I googled alternatives, found a great example: sites.google.com/site/guenterbartsch/blog/myfirstlinuxkernelmodule . It would seem that you need to be happy! I rewrote the Makefile for my needs (relative paths checked and rechecked) of the following form:

OPENWRT = /home/dlinyj/trunk/openwrt-trunk
KERNEL = /home/dlinyj/trunk/openwrt-trunk/build_dir/linux-mpc83xx/linux-3.3.8
PWD := $(shell pwd)

LD= /home/dlinyj/trunk/openwrt-trunk/staging_dir/toolchain-powerpc_gcc-4.6-linaro_uClibc-0.9.33.2/bin/powerpc-openwrt-linux-uclibc-ld
CROSS_COMPILE="powerpc-openwrt-linux-uclibc-"
EXTRA_LDSFLAGS="-I/home/dlinyj/trunk/openwrt-trunk/build_dir/linux-mpc83xx -include symtab.h"
KBUILD_HAVE_NLS=no
CONFIG_SHELL="/bin/bash" 

TARGET = hellok

CC=/home/dlinyj/trunk/openwrt-trunk/staging_dir/toolchain-powerpc_gcc-4.6-linaro_uClibc-0.9.33.2/bin/powerpc-openwrt-linux-uclibc-gcc
obj-m := $(TARGET).o

all:
        make -C /home/dlinyj/trunk/openwrt-trunk/build_dir/linux-mpc83xx/linux-3.3.8/ ARCH="powerpc"  M=$(PWD) modules



Fully consistent with the source material. I run make and get:

[email protected]:~/myprg_ppc/first_hello$ make
make: The `all' target requires no commands to be executed.


I edit the all line, add: all: $(TARGET).o

Then I get the following result:

[email protected]:~/myprg_ppc/first_hello$ make
/home/dlinyj/trunk/openwrt-trunk/staging_dir/toolchain-powerpc_gcc-4.6-linaro_uClibc-0.9.33.2/bin/powerpc-openwrt-linux-uclibc-gcc    -c -o hellok.o hellok.c
powerpc-openwrt-linux-uclibc-gcc: warning: environment variable 'STAGING_DIR' not defined
hellok.c:1:26: fatal error: linux/module.h: No such file or directory
compilation terminated.
make: *** [hellok.o] Ошибка 1


It is clear what it swears at, the first line in the source goes

#include <linux/module.h>  /* Needed by all modules */


But why the hell does she not find it when I described everything ... In general, I would be extremely grateful if someone tells me from which side to approach this problem. Povazyuket muzzle on the table. For I have been fighting for two days now, I have broken many copies, but I still don’t know how to approach (and the deadlines are already being pressed together with the authorities) ZY

. The main thing is that in the system itself, some drivers managed to be finalized with a file so that it starts up, but writing your own, and even the module, is impossible :(.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
theaspin, 2013-07-05
@theaspin

The files directory in target/linux/mpc83xx contains files that will be copied to the kernel directory before compilation. For each platform, the structure and files will be different. If there is no drivers directory, you need to create it.

D
dlinyj, 2013-07-10
@dlinyj

jcmvbkbc
Thank you very much for your help. Config here . But the open-wrt version, to my shame, I don’t know how to look. And I remember that there were some mega-hemorrhoids for assembling it (some configs ruled)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question