Larry Martin | 21 Jun 21:44 2013

Re: Linaro linux-source has no makefiles - help?

I can now natively compile kernel modules in my Linaro image on Air Storm. 
This is a summary of the steps:

* Follow the instructions to download a Linaro image and write it to an SD
card (mine was 8 GB):

http://gumstix.org/getting-started-guide/241-get-an-image.html
http://gumstix.org/getting-started-guide/242-create-a-bootable-microsd-card.html

* Assemble a system with network and a Storm COM.  Boot and get into the
console.  Verify that the image already includes the linux-headers package:

     # ls /usr/src
     linux-headers-3.5.0-2-linaro-omap
     ...

* install the linux-sources package.  I am not sure if this is necessary, or
which other packages may have been necessary.  I don't think I really needed
git or the Debian developer tools.

     # apt-get install linux-source

This creates a skeleton in /usr/src/linux-source-3.2.0, along with a big
source tarball.  Unfortunately, my kernel is not 3.2.0:

     # uname -r
     3.5.0-2-linaro-omap

* Get the Gumstix sources for 3.5.0.  This is the same as the ZIP button on
https://github.com/gumstix/linux/tree/omap-3.5

     # cd
     # apt-get install wget
     # mkdir build
     # cd build
     # wget https://github.com/gumstix/linux/archive/omap-3.5.zip
     # unzip omap-3.5.zip

* Review some critical links:

     Make sure /lib/modules/blah/build points to
/usr/src/linux-headers~blah.
         The particulars may vary by system and over time.
     # ls -l /lib/modules/3.5.0-2-linaro-omap/build
     lrwxrwxrwx 1 root root 42 Dec 10  2012
/lib/modules/3.5.0-2-linaro-omap/build ->
/usr/src/linux-headers-3.5.0-2-linaro-omap

     Make sure /usr/src/linux-headers~blah/source points to the base of your
source tree
         The particulars may vary by system and over time.
     # ls -l /usr/src/linux-headers-3.5.0-2-linaro-omap/source
     lrwxrwxrwx 1 root root 26 Jun 21 16:05
/usr/src/linux-headers-3.5.0-2-linaro-omap/source ->
/root/build/linux-omap-3.5

* Make a basic config builder.  I am not sure if the later step that makes
defconfig overwrites this or not

     # cd
     # cat > get_config
     ## see https://wiki.linaro.org/Resources/HowTo/KernelDeploy

BASE="https://git.linaro.org/gitweb?p=ubuntu/linux-linaro-oneiric.git;a=blob_plain;"

COMMON_UBUNTU="${BASE}f=debian.linaro/config/config.common.ubuntu;hb=HEAD"

FLAVOR_OMAP="${BASE}f=debian.linaro/config/armel/config.flavour.linaro-omap;hb=HEAD"
     curl "$COMMON_UBUNTU" "$COMMON_ARMEL" "$FLAVOR_OMAP" > .config
     ^D
     # chmod a+x get_config

* You should now have all the sources and makefiles you need, and
/usr/linux-source-blah seems irrelevant.
Run basic make commands in the correct places:

     # cd /usr/src/linux-headers-3.5.0-2-linaro-omap
     # make scripts
     # cd ~/build/linux-omap-3.5
     # ~/get_config
     # make ARCH=arm CROSS_COMPILE="" omap2plus_defconfig

* Make sure your top level Makefile agrees with your kernel 
  (thanks to the kernel module Programming Guide:
http://linux.die.net/lkmpg/x380.html)

     # cd ~/build/linux-omap-3.5
     # uname -r
     3.5.0-2-linaro-omap
     # head Makefile
     VERSION = 3
     PATCHLEVEL = 5
     SUBLEVEL = 0
     EXTRAVERSION = -2-linaro-omap

     Edit the Makefile if necessary, using vi if you have not installed
anything else.
     Note that EXTRAVERSION is a string that holds everything after the
N.N.N pattern.

* Make modules, just to be sure stuff builds.  You can ^C out after a few
compiles work.
Modules built this way will not load into your kernel.  This is just a quick
check that
everything is in place.

     # cd ~/build/linux-omap-3.5
     # make ARCH=arm CROSS_COMPILE="" modules

* Now make the modules you care about.  This form of the Make command sets
your build environment 
to the -C path but points back your sources via the M path.

     # cd ~/build/linux-omap-3.5/drivers/usb/gadget
     # make ARCH=arm CROSS_COMPILE="" -C
/lib/modules/3.5.0-2-linaro-omap/build M=`pwd` modules
     ...
     CC      /root/build/linux-omap-3.5/drivers/usb/gadget/g_printer.mod.o
     LD [M]  /root/build/linux-omap-3.5/drivers/usb/gadget/g_printer.ko
     ...

(thanks to:
http://forums.opensuse.org/english/other-forums/development/programming-scripting/427677-kernel-module-devlopment-insmod-issues.html)

* Try your module

     # insmod g_printer.ko
     # lsmod
     Module                  Size  Used by
     g_printer              30375  0

If insmod fails, look in dmesg for detailed error messages and Google them.

That's my guide to native kernel module compilation on Linaro.

Thanks,
Larry

--
View this message in context: http://gumstix.8.x6.nabble.com/Linaro-linux-source-has-no-makefiles-help-tp4967421p4967434.html
Sent from the Gumstix mailing list archive at Nabble.com.

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

Gmane