Tuesday, September 15, 2009

How to compile the Linux Kernel (2.6.31)

Step 1: Download the latest stable kernel from the http://www.kernel.org/
( As on 16-Sep-2009, The latest stable kernel version is 2.6.31)

Step 2: unpack the downloaded source file. To unpack the source file you can use
$ tar -xvzf (file name) -----> [ if the downloaded file is .gz file ]
$ tar -xvjf (file name) ------> [ If the downloaded file is .bz2 file ]

The above commands will automatically create a new directory, in the current working directory. If you want the unpacked source code in some other directory, then you need to mantion the destination directory in the above command.

Step 3: Kernel Building
For detailed build instructions on how to build the kernel , please go through the file "README". in the kernel source directory. For quick instrcutions use the following informaiton
Select the kernel options that are needed for your development using
The kernel options can be selected using the commad
$ cd (kernel source directory)
$ make menuconfig
Build the kernel
$ make





I encountered the following issues during the kernel build
Issue 1:
During the compilation of linux-2.6.31 kernel, I got the following error ( with default configuaration )
- drivers/message/fusion/mptsas.c: In function `mptsas_port_delete':
- drivers/message/fusion/mptsas.c: 105: sorry, unimplemented: inlining failed in call to 'mptsas_set_rphy': function body not available
- drivers/message/fusion/mptsas.c: 467: sorry, unimplemented: called from here

Reason:
The 'mptsas_set_rphy' function is defined after the 'mptsas_port_delete' function in the file.
Solution :
Moved the 'mptsas_set_rphy' function definition before to the function 'mptsas_port_delete' function definition.

Issue 2:
drivers/built-in.o(.init.text+0x3bad): In function `con_init':
include/trace/events/kmem.h:47: undefined reference to `.L1452'
Temporary Hack:
This problem was due to the result of allocating the memory using kzalloc() in con_init() function in the drivers/char/vt.c file.
The compilation problem is occuring for the statement
vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT);
To resolve the compilation issue, this statement was re-coded as in the previous kernel versions ( i.e allocating the memory for this structure using the bootmem )
vc_cons[currcons].d = vc = alloc_bootmem(sizeof(struct vc_data));
Now the compilation issue is resolved. ( Need to check during the boot time for any side-effects ).

During the boot time, if we got any issue, then the memory allocation for the screen buffer also need to be changed to allocate using the bootmem, and change reset the flag vc->vc_kmallocated to zero.




See my future blogs for related topics like
- How to burn the kernel Image onto the custome board
- How build the file system for the new board
- How to compile the toolchain in host system for the custom board

etc.,