Finally I got kernel module compiled and "insmod"ed:
Code: Select all
root@FriendlyARM:~/hello-1# make
make -C /lib/modules/3.4.39-h3/build M=/root/hello-1 modules
make[1]: Entering directory '/root/linux-3.4'
CC [M] /root/hello-1/hello-1.o
Building modules, stage 2.
MODPOST 1 modules
CC /root/hello-1/hello-1.mod.o
LD [M] /root/hello-1/hello-1.ko
make[1]: Leaving directory '/root/linux-3.4'
root@FriendlyARM:~/hello-1#
root@FriendlyARM:~/hello-1# insmod hello-1.ko
root@FriendlyARM:~/hello-1#
root@FriendlyARM:~/hello-1# dmesg | tail -2
[ 13.650331] PHY: gmac0-0:00 - Link is Up - 100/Full
[ 222.084963] Hello World :)
root@FriendlyARM:~/hello-1#
I followed the instructions on Neo Wiki page, the "git clone" completed in 1:47min on my home 120Mbps connection.
I had to replace "mingw32" by "mingw-w64" and compiled the whole package on a PC running a 64-bit Linux (Ubuntu 16.04 LTS in my case):
http://wiki.friendlyarm.com/wiki/index.php/NanoPi_NEO#Make_Your_Own_Ubuntu-Core_with_Qt-EmbeddedThen I copied the whole (2GB!) directory "linux-3-4" via "scp" over to my NanoPi Neo.
And did these needed steps:
Code: Select all
root@FriendlyARM:~# cd /lib/modules/`uname -r`
root@FriendlyARM:/lib/modules/3.4.39-h3# ln -sf /root/linux-3.4 build
root@FriendlyARM:/lib/modules/3.4.39-h3# ln -sf /root/linux-3.4 source
root@FriendlyARM:/lib/modules/3.4.39-h3#
I tried to compile hello world sample module:
Code: Select all
#include <linux/module.h>
#include <linux/kernel.h>
int hello_init(void)
{
pr_alert("Hello World :)\n");
return 0;
}
void hello_exit(void)
{
pr_alert("Goodbye World!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
With this Makefile:
Code: Select all
obj-m += hello-1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Got a compile error on missing "linux/compiler-gcc5.h".
Added a link to compiler-gcc4.h for that in "linux-3-4/include/linux".
Next compile error was on x86 executables encountered -- it seems that I am the very first trying to compile loadable kernel modules with Nanopi Neo or M1! I had to recompile these programs (without the ".x86" suffix on Nanopi Neo):
Code: Select all
root@FriendlyARM:~# find linux-3.4/scripts -name "*.x86" -print
linux-3.4/scripts/mod/modpost.x86
linux-3.4/scripts/mod/mk_elfconfig.x86
linux-3.4/scripts/basic/fixdep.x86
linux-3.4/scripts/recordmcount.x86
root@FriendlyARM:~#
That was all that was necessary to compile loadable kernel module and insmod it as shown above.
I am not done completely, since unlike on Ubuntu and Raspberry Pi Zero I am not able to rmmod that module:
Code: Select all
root@FriendlyARM:~/hello-1# lsmod
Module Size Used by
hello_1 807 0
root@FriendlyARM:~/hello-1# rmmod hello_1
rmmod: ERROR: ../libkmod/libkmod-module.c:793 kmod_module_remove_module() could not remove 'hello_1': Device or resource busy
rmmod: ERROR: could not remove module hello_1: Device or resource busy
root@FriendlyARM:~/hello-1#
Too late now, will work on that tomorrow,
Hermann.