Jump to content

Compiling module for wireless card


Tony3

Recommended Posts

I am after compiling a module for a wireless card. I got plenty of errors, thus decided to go to the basis and test the creation of a "hello" module.

I am using the image: Armbian_22.11.4_Orangepi5_jammy_legacy_5.10.110_xfce_desktop.img

 

vi hello.c

-------------------------------------------------

#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk("Hello Orange Pi -- init\n");
return 0;
}
static void hello_exit(void)
{
printk("Hello Orange Pi -- exit\n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

------------------------------------------

orangepi@orangepi:~$ vim Makefile
ifneq ($(KERNELRELEASE),)
obj-m:=hello.o
else
KDIR :=/lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
all:
    make -C $(KDIR) M=$(PWD) modules
clean:
    rm -f *.ko *.o *.mod.o *.mod *.symvers *.cmd *.mod.c *.order
endif

------------------------------------------------

 

Then try to compile the module :

 make -C /lib/modules/$(uname -r)/build M=$(pwd) modules

 

Running that command the first time after a fresh install of the jammy image, I realised that the directory /usr/src/linux-headers-5.10.110-rockchip-rk3588//scripts/mod

was missing the modpost program.

So I created it with the command:  sudo make M=scripts/mod

 

Then I run again 

make -C /lib/modules/$(uname -r)/build M=$(pwd) modules and got the log

--------------------------------
make: Entering directory '/usr/src/linux-headers-5.10.110-rockchip-rk3588'
arch/arm64/Makefile:44: Detected assembler with broken .inst; disassembly will be unreliable
  CC [M]  /home/eric/installed/TestCompileModule/hello.o
  MODPOST /home/eric/installed/TestCompileModule/Module.symvers
ERROR: modpost: "_mcount" [/home/eric/installed/TestCompileModule/hello.ko] undefined!
make[1]: *** [scripts/Makefile.modpost:169: /home/eric/installed/TestCompileModule/Module.symvers] Error 1
make[1]: *** Deleting file '/home/eric/installed/TestCompileModule/Module.symvers'
make: *** [Makefile:1822: modules] Error 2
make: Leaving directory '/usr/src/linux-headers-5.10.110-rockchip-rk3588'

------------------------------------ 

 

There are few errors in it:

  - "assembler with broken .inst; disassembly will be unreliable", is this important?

  - "ERROR: modpost: "_mcount"", This seems blocking as there is no .ko generated

 

Any idea about what I am missing?

 

Thank you.

 

Link to comment
Share on other sites

9 hours ago, Tony3 said:

I am after compiling a module for a wireless card. I got plenty of errors, thus decided to go to the basis and test the creation of a "hello" module.

I think you are going the complex route. The armbian build system is incredible, all you need is setup a VM with ubuntu and the build system will generate a custom image with your kernel customizations. Please submit a PR if you can validate the build and hardware - this distribution needs more modules. I recently submitted a PR that got accepted for MediaTek USB devices. 

Link to comment
Share on other sites

Actually I managed to build my wireless module by only using the linx header files.

It did not work initially, because I had forgotten to run "make scripts" in the "linux header" directory, after running that, my "_mcount" error disappeared.

Thanks for your advices.

Link to comment
Share on other sites

I have the same kind of problem, trying to build a rtl8821CU module for the Rock5B.
I have installed the whole firmware package through

armbian-config

.

Then:

sudo apt update
sudo apt upgrade
sudo apt install build-essential dkms
sudo apt install git
git clone https://github.com/whitebatman2/rtl8821CU.git
cd rtl8821CU
sudo make
make ARCH=aarch64 CROSS_COMPILE= -C /lib/modules/6.2.0-rc1-station-m6/build M=/home/poddingue/rtl8821CU  modules
make[1]: Entering directory '/usr/lib/modules/6.2.0-rc1-station-m6/build'
make[1]: *** No rule to make target 'modules'.  Stop.
make[1]: Leaving directory '/usr/lib/modules/6.2.0-rc1-station-m6/build'
make: *** [Makefile:1923: modules] Error 2


but it fails...
`uname -r` gives me `6.2.0-rc1-station-m6`.
 

ll /lib/modules/6.2.0-rc1-station-m6/
total 1392
drwxr-xr-x 11 root root   4096 Mar 20 15:19 kernel
-rw-r--r--  1 root root 320711 Mar 17 14:22 modules.alias
-rw-r--r--  1 root root 327286 Mar 17 14:22 modules.alias.bin
-rw-r--r--  1 root root  16981 Mar 17 14:22 modules.builtin
-rw-r--r--  1 root root  37042 Mar 17 14:22 modules.builtin.alias.bin
-rw-r--r--  1 root root  18873 Mar 17 14:22 modules.builtin.bin
-rw-r--r--  1 root root 117401 Mar 17 14:22 modules.builtin.modinfo
-rw-r--r--  1 root root  79754 Mar 17 14:22 modules.dep
-rw-r--r--  1 root root 123183 Mar 17 14:22 modules.dep.bin
-rw-r--r--  1 root root    243 Mar 17 14:22 modules.devname
-rw-r--r--  1 root root  38207 Mar 17 14:22 modules.order
-rw-r--r--  1 root root    703 Mar 17 14:22 modules.softdep
-rw-r--r--  1 root root 136364 Mar 17 14:22 modules.symbols
-rw-r--r--  1 root root 170537 Mar 17 14:22 modules.symbols.bin

 

Link to comment
Share on other sites

11 часов назад, gounthar сказал:

I have the same kind of problem, trying to build a rtl8821CU module for the Rock5B.

 

You are using an old version of the kernel. Use the latest version of the images, there is already the necessary module there.

 

https://github.com/150balbes/build/blob/ed6c18895b1ed1429ea1a22210a826039d177d58/config/kernel/linux-station-m3-current.config#L2939

Link to comment
Share on other sites

2 часа назад, gounthar сказал:

I guess there is no other alternative to the existing image?

 

Clone my GIT and build the kernel (you can additionally change the configuration as you wish) - get a DEB package for manual installation\updating of the kernel on any system. The assembly can be done on the rock 5b itself, the assembly time is small.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines