Write driver-Ubuntu7.10 compile the kernel 2.6.24

Source: Internet
Author: User
Write driver-Ubuntu7.10 compile the kernel 2.6.24 -- general Linux technology-Linux programming and kernel information. For details, refer to the following section. After Ubuntu 7.10 is installed, the version displayed by executing uname-r is the Linux-headers-2.6.22-14-generic. View/usr/src/with "ls-l" there are two file directories: Linux-headers-2.6.22-14-generic and Linux-headers-2.6.22-14. With Ubuntu source updates and configuration (I used to hand in and European official sources, of course there are Chinese official sources) after the kernel will be upgraded to Linux-headers-2.6.22-15-generic. /Usr/src/Adds two file directories: Linux-headers-2.6.22-15-generic and Linux-headers-2.6.22-15.

At this time, the Hello driver cannot be compiled according to the Linux device driver program (the third edition), and the kernel tree needs to be created. In fact, the driver compilation commands (Makefile files) in version 2.4 and version 2.6 are different, and the generated driver file extensions are different. 2.4 is. o, and 2.6 is. ko. Simply compile the kernel and use a relatively higher stable version, and select the 2.6.24 kernel.

1. Installation preparation:

Includes: libncurses5-dev (required by menuconfig) and essential
Sudo apt-get install build-essential bin86 kernel-package
Sudo apt-get install libqt3-headers libqt3-mt-dev
Sudo apt-get install make
Sudo apt-get install gcc

Install all the software packages starting with ncurses in the new version. In addition, to check whether the system has such two commands, use the tab key

Mkinitramfs mkisofs

2. Download The linux-2.6.24 Kernel

Download the linux-2.6.24.tar.bz2 Kernel on www.kernel.org and put it in/usr/src /.

Sudo-s-H to Super User mode.

Cd/usr/src to enter the directory.

Tar jxvf linux-2.6.24.tar.bz2 unzipping the file.

Cd/usr/src/linux-2.6.24

3. Configure the kernel

Run the following command to copy the configuration file of the current kernel.
Cp/boot/config-'linux-headers-2.6.22-15-generic './. config

Sudo make menuconfig

Select "Load an Alternate Configuration File", and then select the. config File you just copied as the Configuration File. Then confirm. When you choose to exit, you will be prompted to ask "Do you wish to save your new kernel configuration? "Select yes.

4. Start Compilation
In this case, there is a space problem. Compiling will generate a 500 GB space under/usr/src, and the kernel modules copied to/lib/modules will also be MB. Enough space!

Make
Make bzImage // compile the kernel and save it to/usr/src/linux-2.6.24.4/arch/i386/boot/
Make modules // compilation Module
Make modules_install // installation Module

At this time, the kernel tree has been established and the hello driver program has been compiled successfully.

// Hello. c
# Include
# Include
MODULE_LICENSE ("Dual BSD/GPL ");
Static int hello_init (void)
{
Printk (KERN_ALERT "Hello, world \ n ");
Return 0;
}
Static void hello_exit (void)
{
Printk (KERN_ALERT "Goodbye, cruel world \ n ");
}
Module_init (hello_init );
Module_exit (hello_exit );

// Makefile
Obj-m: = hello. o
KERNELDIR: =/lib/modules/2.6.24/build
PWD: = $ (shell pwd)
Modules:
$ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules
Modules_install:
$ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules_install

If the Makefile format is incorrect when make is complete, the solution is to set $ (MAKE)-C $ (KERNELDIR) M =$ (PWD) modules_install move to the beginning of the line, and then press the Tab key to automatically align, and then in make. Makefile is usually prone to Tab and space issues, separated by the Tab key.

If you don't want to use a new kernel, you can use it for the compilation logic. You have to use the new kernel to compile it, including loading it into grub.

5. Compilation completed

Sudo mkinitramfs-o/boot/initrd-2.6.24.img 2.6.24

At this time, you may be prompted to not find such a folder "/lib/firmware/2.6.24". You need to create such a folder manually.

Mkdir/lib/firmware/2.6.24

Make install // After kernel installation is complete, add the following files under/boot (use ls-l * 24 * for details)

-Rw-r -- 1 root 85203 2008-config-2.6.24

-Rw-r -- 1 root 37968871 2008-initrd-2.6.24.img
-Rw-r -- 1 root 4014080 2008-initrd. img-2.6.24

-Rw-r -- 1 root 932315 2008-System. map-2.6.24

-Rw-r -- 1 root 1858864 2008-vmlinuz-2.6.24
Add a new startup Item to/boot/grub/menu. lst. For example, add the following text to my menu. lst:

Title Ubuntu, kernel 2.6.24

Root (hd0, 0)
Kernel/boot/vmlinuz-2.6.24 root = UUID = d7e2cf74-ebf5-4c78-ac2c-9f85a9809eae ro
Initrd/boot/initrd-2.6.24.img

You can use the new kernel from the new startup.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.