Create a Patch for Linux Kernel customizations

April 5th, 2008

Purpose:

If you have been using Linux for over two to three years than chances are that you may have been in a situation where you need to modify your Kernel’s Makeconfig or Kconfig files or adding a new device driver for your hardware from your hardware vendor which is not yet into the mainstream kernel (www.kernel.org).

Once you do all of the above then you may need to generate a patch (for the changes that you just made) so that other users can simply apply that patch rather than going into the kernel sources and manually modify all those files. This blog posting will explain in a simple way how you can do that. Although I think there might be several postings which will explain you how to do that but they may not be clear or may not cover your case specifically.

Let’s start with an example:

I downloaded Kernel source 2.6.24 into my /usr/src/linux directory. Suppose I need to add a framebuffer driver support, say for example, for my VIA’s Unichrome Graphic chipset. I copy the framebuffer driver source directory (provided by VIA) into my kernel directory as follow:

cd /usr/src/linux

cp -a /usr/src/fbdev-via-unichrome /usr/src/linux/driver/video/via

Note: The directory /usr/src/linux/driver/video/via did not existed when we installed 2.6.24 kernel source initally.

After this suppose we need to make changes to files Kconfig and Makefile in /usr/src/linux/drivers/video directory.

Say I add the following line in the Makefile:

obj-$(CONFIG_FB_VIA) += via/

and the following line in the Kconfig:

config FB_VIA
tristate “VIA UniChrome/Chrome 9 HC display support”
depends on FB && PCI
select FB_CFB_FILLRECT
select FB_CFB_COPYAREA
select FB_CFB_IMAGEBLIT
select FRAMEBUFFER_CONSOLE
help
This is the frame buffer device driver for the VIA CLE266, CN400, CN700, CN800,
CN896, CX700, PMN800, PMN880, P4M800CE-Pro, P4M890, P4M900, VN800, VN896 and
VX700 chipsets.

The above are examples from the www.viaarena.com website.

That’s it! Our kernel is now ready to be compiled and installed to get the framebuffer support for the VIA graphic chipset. However, what if there are several users who want to do the same since they also happen to have the same VIA graphic chipset and the driver has still not made into the mainstream kernel.

Here are the steps to generate a patch after your making your own Kernel modifications:

Step 1: Download and prepare kernel sources

Download again the 2.6.24 kernel source (same as you did above) against which you want to build the patch and name directory to something like linux-pristine. For example, your /usr/src directory should now look something like this:

debian:/usr/src# ls -l

total 57316

drwxr-xr-x 20 root root 4096 2008-02-11 03:48 linux-pristine

drwxr-xr-x 20 root root 4096 2008-02-11 03:48 linux-source-2.6.24

lrwxrwxrwx 1 root src 19 2008-04-06 00:20 linux -> linux-source-2.6.24

debian:/usr/src#

Basically, you now have two kernel source 2.6.24 directories:

One with changes that you made to incorporate VIA’s framebuffer driver called as linux (a link to linux-source-2.6.24 directory)

and

the other original 2.6.24 kernel sources (straight from www.kernel.org website) that you just downloaded called as linux-pristine

Step 2: Clean both the kernel directories

We need to make sure that we remove any object or executables files in both the kernel directories. Give the following commands:

debian:/usr/src# cd linux
debian:/usr/src/linux# make mrproper
debian:/usr/src/linux# make clean
debian:/usr/src/linux# cd ../linux-pristine/
debian:/usr/src/linux-pristine# make mrproper
debian:/usr/src/linux-pristine# make clean
debian:/usr/src/linux-pristine#

Step 3: Generate patch

Now give the following commands to create the patch:

debian:# cd /usr/src

debian:/usr/src# diff -Nur linux-pristine/drivers/video/ linux/drivers/video/ > patch-2.6.24-viafb

The format of the diff command is:

diff -options oldfile newfile > patch

where -options = -Nur

oldfile = linux-pristine/drivers/video/

newfile = linux/drivers/video/

patch = patch-2.6.24-viafb

Your patch is now ready and you can view your patch by using your favourite editor like gedit, less, nano, etc.

debian:/usr/src# less patch-2.6.24-viafb

Step 4: Test your patch

We need to make sure that the patch we just generated is correct or now. There is a simple way to do it.

Make a temporary copy of your linux-pristine directory as follow:

debian:/usr/src# cp -r linux-pristine/ /tmp/linux-test-patch

Now patch this kernel source by the patch that you just created in Step 3 above.

debian: cd /tmp/linux-test-patch/

debian:/tmp/linux-test-patch# patch -p1 < /usr/src/patch-2.6.24-viafb

You should be seeing some output as follow:

*******************************
patching file drivers/video/Kconfig
patching file drivers/video/Makefile
patching file drivers/video/via/accel.c
… … … … … … … … … … … … … … … …
patching file drivers/video/via/via_utility.h
patching file drivers/video/via/vt1622a.c
patching file drivers/video/via/vt1622.c
patching file drivers/video/via/vt1625.c
patching file drivers/video/via/vt1636.c
patching file drivers/video/via/vt1636.h
debian:/tmp/linux-test-patch#

*******************************

Finally give the following command to test your patch:

debian:/tmp# diff -rq linux-test-patch/drivers/video/ /usr/src/linux/drivers/video/

If your patch was successfully created in Step 3 than you should not see any output after giving the above command. Basically the above command makes sure that there is no difference in any of the files after you patched your kernel.

Note: If you want to see the explanations of the options of the “diff” command, please see the man page:

debian:/ man diff

Step 5: Tell your users how to use your patch

Just ask your users to patch their 2.6.24 kernel by giving the following command:

debian:/usr/src/linux-source-2.6.24# patch -p1 < /usr/src/patch-2.6.24-viafb

Congratulations! You have successfully created a patch that you can distribute to other users who do not want to make changes manually to the kernel sources as you did initially. Treat yourself with something you like to eat or just sit back and relax and enjoy seeing people using your patch.

As usual, please leave a comment/feedback, if you have any.

Some Venture/Business Ideas?

March 10th, 2008

Purpose:

I am going to write down some of the ideas that I have for new venture. Although right now these are just ideas but I hope that someday I will be able to fulfill them. If you happen to read this post and are interested, then just leave a comment. We can talk further. The world is full of surprises, who knows one of these ideas may clicked!

Idea #1 - Web 2.0 social networking site for cars

Ever bought a used car or took your car to a mechanic shop for repairs in your local area? For most of them the experience is quite frustrating and horrifying mostly because of information asymmetry and lack of proper knowledge about cars in general. Most of the time people feel that they have been cheated by the dealer or the mechanic and trust me most of time they have been.

The idea is to creating a social web-based community like the MySpace or Facebook, based on Web 2.0 principles, for car owners where they can discuss any topic related to cars like how to perform small repairs on your car by yourself, where and how to buy used car in your surrounding area, finding a reliable and honest car mechanic in your zip code, how to maintain cars in general, etc. The revenue generating model will be:

a) Ad programs like Google AdSense or Microsoft AdCenter which are for most of the Web 2.0 websites.

b) Also another option is to charge car dealers a minimal amount of fees if they want to have access to the customer database beyond a certain number of records. the idea is to give the basic service for free but charge a premium for additional services/features.

Idea #2 - Never loose your cell phone

Summary
Ever lost your cell phone while you are out in public places and public transportation? Imagine a device that will beep, when you are away from your cell phone by more than a specified distance. The idea is to have a small transmitter (almost invisible) attached on your cell phone which will emit radio signals and the owner of the cell phone will have another small/micro device which will act as a receiver for those radio signals. The receiver will beep/alert, if it detects that the cell phone is ‘x’ (which can be specified) meters away from the receiver. This way one will never loose his/her cell phone.

Detailed Description
It is estimated that by 2010 over 1 billion people will be using different kinds of hand held devices such as cell phones, PDAs, and next generation hand-held entertainment devices. Although the cost of these devices is getting lower day by day, the amount of information that we store on these devices is increasing at an exponential rate every day. Hence the data that you store on these devices is a lot more important than the cost of the cell phone or the PDA.

Just imagine that you are travelling in a train during rush-hour to your work located in San Francisco financial district from Foster City and you forgot your cell phone on the seat because you were in a hurry to catch a cab from the train stop. Probably the first thing that will come to your mind is that how can you retrieve all your data which may worth hundred of thousand of dollars. It could lead to a serious loss of your valuable time in order to get back all the data that you lost. In some case you will never be able to get back your data.

Wouldn’t it be nice if we had something with us which would inform us that we have forgotten our cell phone, just a few seconds back? Due to advancement in technology, these days we can easily make a small transmitter (say with a dimension of 0.2cm x 0.2cm x .1cm) which can be attached on our cell phone or on any hand-held device. We will have a small receiver which we can either put it in our wallet or just stick it on our wrist-watch or perhaps just attach it on our ring in hand. The idea is that your receiver with you will alert you, say with a beep, as soon as you are 5 meters away from your cell phone. You can specify the distance, above which the receiver will beep to alert you. Moreover you can turn this alert feature off when you are at home or at office.

The best thing about this product is its multi-utility value i.e. it is not for a specific product. You can use it on your MP3 player like iPods, GPS system, satellite phones and even on your laptop. We already discussed that the markets for hand held is very big and still it has a lot of growth potential. With cell phones getting smaller and smaller in size and people’s life getting busier, I think loosing your cell phone will become much for common than what it is right now.
Hence I think that this product has a great chance of success, considering that the cost to manufacture something like this is very inexpensive these days.

VFS: Kernel Panic Error - ACPI and APIC Issues - Part 1

March 4th, 2008

I guess most of us who have been an ardent user of Linux O.S. must have seen dreaded “Kernel Panic” error messages at some point of time and generally those are very difficult to solve and takes away lot of time researching on it.There are many reasons for Kernel Panic error messages and one of them is related to ACPI and APCI, which I am going to talk about in this post. ACPI has superseded the old APM.

Typically you will see error messages like this:

“kernel panic - not syncing: VFS: unable to mount root fs on unknown-block(0,0)”

Solution

Try passing the following kernel parameters (all at once) in your GRUB (menu.lst) or LILO (lilo.conf) configuration file:

“acpi=off pci=noacpi noapic nolapic”

There are 90% chances that your problem will solve if it is related to ACPI and APIC. Once you can boot your system by giving above parameters, try eliminating each one of them, one by one, to find which parameter actually is required. However, there could be more than one parameter that you will end up using. For example, in my case I had to give “acpi=off nolapic” to resolve my Kernel panic error.

If you are still getting Kernel panic even after giving the above four parameters, then try these addtional parameters in permutation and combination with the above four to see if you resolve the issue:

“pnpbios, pci=usepirqmask, pci=biosirq”

If you are still not able to solve it, then I suspect that it might not be an APCI and ACPI related issue. However, I strongly encourage you to boot from a Knoppix live CD or Ubuntu live CD and look at the “Help” section before it starts booting. In the help section they suggest many kernel parameters that you may have to give because of broken firmware or buggy BIOS in order to boot your system.

In my next part of this post, I will explain and also give some useful pointers as to why we need to give those parameters to safely boot the Linux Kernel and how can we boot the kernel without giving those parameters because in some situation (when you are using a laptop) you simply cannot give up ACPI features.

Install Splashy on Debian Stable (Etch)

March 1st, 2008

I know there are many people who do not like the slow development process of the Debian Linux Operating System (O.S) just like me. People who use stable distribution of Debian miss on lots of new featured-rich packages as compared to users of other Linux O.S. The reason why people still stick to the stable Debian system is because of its rock-solid stability.

One of the packages that is missing from the current Debian Stable release (Etch) is “splashy“.

Here are detailed instructions which explains how to install latest Splashy package on your Etch system:

Splashy is a native Debian package, so all you need to do is to download the current sources, untar and then build a .deb package from the untarred sources.

Step 1:
Go to http://packages.debian.org/source/lenny/splashy and download the three source files namely

splashy_0.3.8-1.dsc
splashy_0.3.8.orig.tar.gz
splashy_0.3.8-1.diff.gz

into a folder say /usr/src/root/splashy_build

or you can use “wget” command also like this:

debian# wget http://ftp.us.debian.org/…/splashy…{dsc,tar.gz}

Step 2:
Give the following commands:

cd /usr/src/splashy_build
dpkg-source -x splashy*.dsc
cd splashy-VERSION (in this example, VERSION=
3.8-1)
debuild -uc -us
cd ..
dpkg -i splashy*.deb libsplashy*.deb

Step 3:
Test your splashy by giving command:

debian# splashy test

You should be able to see a Tux image and a progress bar.

Step 4:
Add the following line:

splash vga=791 quiet

in your /boot/grub/menu.lst file

Your line should read something like this:

title Debian GNU/Linux, kernel 2.6.18-4-686
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-4-686 root=/dev/hda1 ro splash vga=791 quiet
initrd /boot/initrd.img-2.6.18-4-686

This will enable the splashy to start whenever you boot your system. Without the above line your splashy simply wouldn’t work.

What if you get error messages when you boot your system or you are not able to run splashy at all?
Don’t worry chances are that you will run into Splashy error messages on Debian Etch if you are not using an initrd/initramfs image. Please refer to Issue #1 - Splashy not working; Splashy Error Messages during boot in my blog entry.

Hope this helps.

As usual, please leave a comment/feedback.

GNU/Linux Debian Issues - Solution/Resolved

February 26th, 2008

Purpose:
I have been a fan of Debian Linux operating system since last 3 years. The purpose of this post is to continuously list issues that I was able to resolve either by asking the Open Source community or by researching on the Internet or just by playing around with the problem. I hope that this post will help many people to solve similar/same issues and thus will save their valuable time.

Issue #1 - Splashy not working; Splashy Error Messages during boot
Date: 02/25/2008

Package: Splashy (Version 0.3.8-1)

OS version: Debian GNU/Linux 4.0 (codename etch)

Kernel: 2.6.24 (Debian Source)

Error Messages:
Splashy Error: Connection refused
Splashy ERROR: Couldn’t splashy_start_splashy(). Error -2
Splashy ERROR: Couldn’t splashy_start_splashy(). Error -3
Splashy ERROR: Couldn’t splashy_start_splashy(). Error -7
Cannot create /dev/fb0 or No such device

Also see this posting in which I posted my query to the splashy mailing list.

Resolution:
Rename /etc/rcS.d/S03udev to /etc/rcS.d/S03audev.

Command to be given:

debian# mv /etc/rcS.d/S03udev /etc/rcS.d/S03audev.

You can test whether splashy is working properly or not by giving the following command:

debian# splashy test

The above solution was suggested by Mike Kelland who happens to be on the same splashy mailing list as I am.

Also some of you might be wondering how to install splashy on Debian stable (Etch) since Splashy is only available in Lenny and Sid repository as of this writing. Please see my post on how to install splashy on Debian Stable.

Update:

Ok, you must be wondering why this issue occurs in the first place, right? Why don’t the developers fix this issue?

Here is mystery:
The way splashy is supposed to work is that it should start from initramfs (which superseded initrd) in the 2.6 kernel series. What is the difference between initrd and initramfs? I think that deserves a separate post/entry (may be for some later time, eh?). Any how, if you use initramfs to boot your kernel then you should not get any error messages. Debian system by default likes to use am initramfs during boot, but many people do not prefer to use an initramfs during the boot and thus built all the support for IDE controller and Filesystems into the Kernel itself (instead of modules), just like the way I like it. This is how you make your boot process free from using initramfs.

So in short if you don’t see an “initrd” entry into your /boot/grub/menu.lst, for example:

title Debian GNU/Linux, kernel 2.6.18-4-686
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-4-686 root=/dev/hda1 ro

instead of

title Debian GNU/Linux, kernel 2.6.18-4-686
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-4-686 root=/dev/hda1 ro
initrd /boot/initrd.img-2.6.18-4-686

it means that you are not using initramfs and you should follow the tip mentioned in the resolution section above.

Note: It is important to know that while the menu.lst file still says “initrd”, it actually means “initramfs”. For some reasons it is still being called by this name even when they switched to newer much improved “initramfs” in 2.6 Kernel. This thing kept me confused for a long time until someone just mentioned in one of my query.

In conclusion, if you don’t use initramfs/initrd during your boot process, then udev and splashy interferes with each other and you have to make sure that splashy is being called after udev script in the /etc/rcS.d directory. The only disadvantage is that you might end up seeing some text messages before splashy actually loads itself.

Also, I had a discussion with one of the splashy developer/maintainer regarding this issue which might give you further insight.

Issue #2 - Ethernet card does no get IP address

Coming soon…

As usual, please leave a comment/feedback.