Sunday 11 March 2012

Compiling custom module from external patch in Ubuntu 11.10 (asm58 sensors patch)


The result of the following commands is that you gain a copy of the default ubuntu kernel packages, with just your patch added (one module and one help file).

  • Install the required packages (linux sources and required programs/files to build the new kernel package).
  • Install the dependencies required for building the kernel
$ apt-get build-dep linux kernel-wedge fakeroot makedumpfile
  • Install the kernel source code
$ apt-get install linux-source
  • Extract the current ubuntu kernel source (into an allready prepared directories - by linux-source package)
$ cd /usr/src/
$ tar -xjf linux-source-x.y.z.tar.bz2
$ cd linux-source-x.y.z
$ wget http://n.neonatus.net/files/asm58-linux-3.0.0.patch
patch -p1 <asm58-linux-3.0.0.patch
  • My builds always failed with the error of not being able to touch a certain file so for that reason I create a directory beforehand so that the build goes through without an error
$ mkdir debian/stamps
  • Prepare to build the source
$ fakeroot debian/rules clean
  • Build the kernel packages
$  AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-generic-pae
You could also use binary - to build binary packages for all flavours - or select your flavour according to your hardware - they are listed in the debian.master/config/$ARCH/ directory.
  • If you are lucky enough to have multiple cores or processors utilize them during build add "DEB_BUILD_OPTIONS=parallel=2" variable in front of the command where 2 is the number of cores/processors you have available to the OS like this:
$ DEB_BUILD_OPTIONS=parallel=2 AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-generic-pae
During the build the kernel configure script will ask you to define the following:
 Asus Mozart-2 (SENSORS_ASM58) [N/m/y/?] (NEW)
Enter the letter m and press enter, which signifies to build the object as module so you can load/unload it at need. 

Now we wait... and wait... (hope you have a fast computer, or you'll) wait some more...
When the compiling finishes you will be left with a couple of new *.deb packages in your /usr/src directory, which you can install with dpkg command.
$ dpkg -i ../linux-headers-3.0.0-16-generic-pae_3.0.0-16.29_i386.deb
$ dpkg -i ../linux-image-3.0.0-16-generic-pae_3.0.0-16.29_i386.deb
Reboot and (if not allready selected) select the new kernel in the grub boot menu.
Log into the newly booted system and verify if all is fine by loading the asm58 module:

$ modprobe asm58
and verify that it is loaded ok:
$ lsmod |grep asm58
asm58                  13122  0
Now you can use the functionality of the newly compiled module by configuring lm-sensors - run sensors-detect and afterwards verify that the command sensors returns values from the sensor.


Good luck, and write a comment if you need help ;)

#Links:

No comments: