Bananian

How to write, compile and run modules on Bananian v15.01 ?

7 2709
stelmik  
Edited by stelmik at Tue Mar 3, 2015 04:18

Dear All,

I try to write and run my first module on Bananian v15.01 (device: Banana Pro) with no success.

I have Bananian installed and updated with command:

  1. bananian-update
  2. apt-get update
  3. apt-get upgrade
  4. apt-get dist-upgrade
Copy the Code
Kernel:

  1. # uname -a
  2. Linux centrala 3.4.104+ #1 SMP PREEMPT Thu Jan 8 15:40:40 CET 2015 armv7l GNU/Linux
Copy the Code
I make local copy of kernel sources with command:

  1. git clone https://github.com/Bananian/linux-bananapi
Copy the Code
and place it in location /usr/src/linux-bananapi .
Then I switch to kernel version 3.4.104+ :

  1. cd /usr/src/linux-bananapi
  2. git checkout 927bb45085b36b96b50e977b57d36c43bf0f21a9
Copy the Code
and copy configuration
  1. zcat /proc/config.gz > /usr/src/linux-bananapi/.config
Copy the Code
After that I read I need to generate Module.symvers file.
I call:

  1. make menuconfig
  2. make scripts
  3. make modules
Copy the Code
I tried too:

  1. make oldconfig
  2. make scripts
  3. make modules
Copy the Code
It generate Module.symvers. :-)

I link above sources with command:
  1. ln -s /usr/src/linux-bananapi /lib/modules/3.4.104+/build
Copy the Code
After that I create new directory for my first module: /home/stelmik/mymodule and create file mymodule.c with content:

  1. #include <linux/module.h>
  2. #include <linux/init.h>

  3. static int __init mymodule_init(void)
  4. {
  5.     printk ("My module worked!\n");
  6.     return 0;
  7. }

  8. static void __exit mymodule_exit(void)
  9. {
  10.     printk ("Unloading my module.\n");
  11.     return;
  12. }

  13. module_init(mymodule_init);
  14. module_exit(mymodule_exit);

  15. MODULE_LICENSE("GPL");
Copy the Code
and other file Makefile with content:
  1. obj-m += mymodule.o
Copy the Code
Then I compile it with command:
  1. make -C /lib/modules/3.4.104+/build SUBDIRS=$PWD modules
Copy the Code
with no errors.

When I try to:
  1. insmod mymodule.ko
Copy the Code
then I get error:

  1. Error: could not insert module mymodule.ko: Invalid module format
Copy the Code

  1. # modinfo mymodule.ko
  2. filename:       /home/stelmik/mymodule/mymodule.ko
  3. license:        GPL
  4. srcversion:     3DED4FC68B29C9603509125
  5. depends:
  6. vermagic:       3.4.104+ SMP preempt mod_unload modversions ARMv7 p2v8
Copy the Code
My question(s):
Why I get error message "Invalid module format" (I think I have kernel 3.4.104+ sources)
Where is my mistake?
What to do to make it working?

I based on discussion in threads:
http://forum.lemaker.org/thread-8852-1-1-1.html
http://forum.lemaker.org/thread- ... anian_distrib_.html
http://forum.lemaker.org/forum.p ... amp;extra=#pid65957
http://forum.lemaker.org/thread-11797-1-1-.html
http://forum.lemaker.org/2657-1- ... ly_on_bananian.html
http://forum.lemaker.org/thread-10427-1-1-.html
but I didn't find there any solution. :-(
igorpec  
Edited by igorpec at Tue Mar 3, 2015 19:18

Something is missing in kernel configuration ... or even sources, bad kernel script, ... What exactly is hard to tell without deep analysis.

You will need to put more hours / days to find out. Kernel can be quite a messy place

My kernel is fixed - unfortunately I don't have any proper log of fixing to share. Anyway - headers are here, scripts are fixed, you don't need to do anything. Just compile and load module the standard way. It sure need further fixing but generally it's working.

Banana hardware is fully supported (R1 was added yesterday, kernel is updated, image not). I am not 100% sure that it works with Bananian since I use zImage kernel type but you can convert it to uImage or simply use my image pack.

http://mirror.igorpecovnik.com/k ... ananapi-default.tar (with R1 support)

igorpec  
Two more things that I recall and are somehow not logical:

- when compiling you must sometimes use to declare architecture. You need to use ARCH=arm and not ARCH=armv7 which can be default
- module example doesn't work because of some bad script but I succeed in many drivers compilation anyway.

stelmik  
Thank you Igor :-)

I will try with declaring architecture, but I think I tried it when decribed method failed.

stelmik  
I compile modules directly on Banana Pro with Bananian v15.01.
Inside Makefile file there is setting ARCH to (uname -m)
On my Banana Pro:
  1. # uname -m
  2. armv7l
Copy the Code
And when I
  1. # uname -a
  2. Linux centrala 3.4.104+ #1 SMP PREEMPT Thu Jan 8 15:40:40 CET 2015 armv7l GNU/Linux
Copy the Code
Are you sure that I should "make" with ARCH=arm ?

igorpec  
To get things working with my kernel pack ... I am sure. Kernel naming of directory is arm not armv7

/usr/src/linux-headers-3.4.106-orangepi/arch/armv7/Makefile

I am not quite sure what's the proper way of declaring architecture. For now I leave build as is.

stelmik  
I tried to compile kernel with ARCH=arm but it didn't solve problem.
All the time when I compile and then try to add any module I get error message:
  1. # insmod <module_name>.ko
  2. Error: could not insert module <module_name>.ko: Invalid module format
Copy the Code
and inside syslog:
  1. <module_name>: disagrees about version of symbol module_layout
Copy the Code
I don't understand why the author(s) of the compilation hasn't helped with solving the problem. I'm not the first person who has the problem with compilation of modules on Bananian v15.01. In the forum, there is many threads with no working solutions. :-(

stelmik  
Igor, if I will not solve the problem I will use your kernel pack. :-)

You have to log in before you can reply Login | Sign Up

Points Rules