building /lib/modules/$(uname -r)/build while compiling a kernel

16,121

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:

  1. 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

  2. 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

Share:
16,121
sven
Author by

sven

Updated on June 04, 2022

Comments

  • sven
    sven almost 2 years

    I am cross-compiling 3.4.0 kernel for an embedded device. Then I would like to install compat-wireless drivers which require /lib/modules/3.4/build directory and sub-files. Could anyone explain how can I build that directory so that when I do INSTALL_MOD_PATH=newmodules make modules_install it would load /lib/modules/$(uname -r)/build directory as well? I would appreciate for a clear explanation.

    I am using debian distro. I know I can install the kernel headers by apt-get install linux-headers-$(uname -r), but I doubt it would be a good idea since the kernel sources might not be identical.