The most exciting thing about this world is its ever changing quality.

Friday, June 26, 2009

Patch the patches

If you have suffered the pain of patching Linux kernel for either driver changes or target device support, I am sure you are just as unimpressed as I am when the patch fails with absolutely no indications, no logs, no nothing, in the middle of file update. With some very careful tracing, it turns out to be that your applications requires you to change the same files which are set for patching, especially those from third parties.

Now here is a clean thread,
1. You have a target device, for argument sake, you need to change some of the kernel driver files to accommodate those hardware various, or even just you fancy ideas of changing Linux itself. After all, that's what you are expecting from open source OS, isn't it?

2. In parallel, you wanted to patch your existing Linux source distribution with some other third party addon, such as RTAI or Xenomai.

In my case, I had a problem that both of them require changes in xxx_gpio.c file, and same lines! The third requirement is, I do not want to manually do the file copy thing or scripted file copying thing every time when I rebuild the whole lot. After a nice lunch time beer, this is what I have done.

Step 1. file_ver0.c => Apply third party changes (only because they are normally dumber!) => file_ver1.c
Step 2. file_ver1.c => Apply your changes on top of third party changes => file_ver2.c
Step 3. Do a diff -u file_ver0.c file_ver2.c > diff.txt
Step 4. Replace the patch section of this file in the original .patch file with content in diff.txt.
Step 5. Or create your own patch file and do patch -p1 < whatever.patch

Ok, this is done once for all.

No comments: