building /lib/modules/$(uname -r)/build while compiling a kernel
Typically /lib/modules/$(uname -r)/build is a soft-link to the directory where performed the build. So the way to do this is to simply do a
make modules_install INSTALL_MOD_PATH=/some/root/
in the build directory of the kernel where /some/root is where you want your cross compile pieces to end up. This will create a link to your kernel build path in /some/root/lib/modules/$(uname -r) ... verify that.
Now when you build the compat_wireless drivers specify the kernel build directory in the Makefile as /some/root using the KLIB_BUILD variable (read the Makefile)
make modules KLIB_BUILD=/some/root/lib/modules/$(uname -r)/build
this should do the trick for you.
EDIT A
In answer to your comment below:
Keep "newmodules" outside the kernel directory it's a bad idea to put it in the kernel directory. so mkdir newmodules somewhere like /home/foo or /tmp or something. This is one of the reasons your build link is screwed up
ALSO .../build is a soft link /to/kernel/build/location it will only copy over as a soft-link. You also need to copy over the actual kernel source / kernel build directory to your microSD, using the same relative location. For example,
Let's say your kernel source is in:
/usr/src/linux-3.5.0/
Your kernel build directory is:
/usr/src/linux-3.5.0-build/
Your newmodules (after following 1.) is in:
/tmp/newmodules/
So under /tmp/newmodules/ you see the modules installed in a tree like:
lib/modules/$(uname -r)/
when you do an ls -al in this directory, you'll see that build is a soft link to:
build -> /usr/src/linux-3.5.0-build/
Now let's say your microSD is mounted under /mnt/microSD
then you need to do the following
mkdir -p /mnt/microSD/usr/src
cp -a /usr/src/linux-3.5.0 /usr/src/linux-3.5.0-build /mnt/microSD/usr/src
cp -a /tmp/newmodules/lib /mnt/microSD/lib
Now you have all the content you need to bring over to your embedded environment. I take it you are doing the compat_wireless build on your target system rather than cross compiling it?
NOTE
If your kernel build is the same as the kernel source then just copy over the kernel source and ignore the linux-3.5.0-build
in copy instructions above
/lib/modules/version/build/ not existent
This is because you have not yet downloaded the linux headers of your particular kernel version.
Assuming your kernel version is 4.15.0-32-generic
, install the required header files using sudo apt install linux-headers-4.15.0-32-generic
In your case you can get it byyum install kernel-devel kernel-headers
while building kernel modules why do we need /lib/modules?
while building kernel modules why do we need /lib/modules?
Its not a compulsory to give above option i.e /lib/modules
The main intention is to get configured source-code directory
.
You can set to directly configured source-code or u can provide above i.e /lib/modules/ which having softlink for built source-code.
KDIR,
you can either set full kernel source directory (configured and compiled) or just kernel headers directory (minimum needed).
Two solutions
1)Full kernel sources
2)Only kernel headers (linux-headers-* packages in
Debian/Ubuntu distributions)
where in both case The sources or headers must be configured
.Many macros or functions depend on the configuration
-C
option calls the kernel Makefile
, passing the module
.
directory in the M variable ,the kernel Makefile knows how to compile a module
for e.g if you configure your kernel for Arm architecture or machine
then configured kernel Makefile
will tell how to compile and for which arhitecture your modules should be built.
To be compiled, a kernel module needs access to the kernel
.
headers, containing the defnitions of functions, types and
constants
Can it be build solely?
No you cant build solely since you module should should know for which kernel you want to build it and which configuration it needs to be compiled so that while inserting your module
All respective symbols and configuration should be matched. All this can be done through toplevel Makefile of configured kernel
.
.ko file not being built when building kernel modules
I have now found the solution, I removed some lines from the makefile as I believed them to be redundant as I thought that they were only used if you were directly invoking the makefile from the kernel build directory. The correct makefile is below.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
kernel module doesn't search for include library when -I is used
That's because make is not actually running in your directory, when it compiles things.
The -C
option in this command:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
tells make to change it's current working directory to that path. Thus, include
is no longer the include
directory in your current directory.
You should write it like this:
EXTRA_CFLAGS += -I'$M/include' -Werror -Wall \
-Wno-missing-braces -Wno-error=unused-function
all:
$(MAKE) -C "/lib/modules/$$(uname -r)/build" M='$(CURDIR)' modules
clean:
$(MAKE) -C "/lib/modules/$$(uname -r)/build" M='$(CURDIR)' clean
You should always use $(MAKE)
, and never make
, when running a sub-make. And using make's shell
function is not really needed since a recipe is already running in a shell. And, PWD
is just inherited from the calling shell and might be inaccurate.
Related Topics
Add Timestamp to Cat Output from Shell Script
Can't Use Gpg-Agent as an Ssh Agent
Socket Programming Send() Return Value
How to Install and Run Tacotron2 on Ubuntu Wsl
Where Is User's Cron Job Stored After "Crontab -E"
What Are Coding Conventions for Using Floating-Point in Linux Device Drivers
See What Process Last Touched a File
Do I Have to Pthread_Join Each Thread I Create
Process Niceness (Priority) Setting Has No Effect on Linux
Elf File Tls and Load Program Sections
How to Highlight The Differences Between Subsequent Lines in a File
Linux Shell Kill Signal Sigkill && Kill
How to Make Linux Ignore a Keyboard While Keeping It Available for My Program to Read
Find Syslog Max Message Length
How to Find Performance of Individual Functions in a Process Using Perf Tool