Home > System Tutorial > LINUX > body text

How to compile Linux kernel and drivers?

王林
Release: 2024-02-15 09:00:05
forward
888 people have browsed it

Linux is an open source operating system that can run on a variety of embedded devices, such as smartphones, tablets, routers, etc. In order to adapt Linux to different hardware platforms, we need to compile the Linux kernel and drivers to control and manage the hardware. This article will introduce how to compile the Linux kernel and drivers, including how to configure kernel options, how to compile kernel modules and kernel images, and how to load and unload driver modules.

如何编译 Linux 内核和驱动程序?

There are two methods for driver compilation:

\1. Compile into the kernel

\2. Compile into independent module

Establishment method:

1) Add your own driver directory to the driver directory of the Linux source tree, for example: now add a network device driver

    mkdir linux_tree/drivers/net/poker_driver -p

    cd linux_tree/drivers/net/poker_driver
Copy after login

2) Write driver source code

   vi poker_drv_part1.c

    vi poker_drv_part2.c

    vi poker_drv_part3.c
Copy after login

3) Write the source code directory Kconfig

vi Kconfig

      config POKER_DRV
      tristate "poker_driver support"
      default n
      ---help---
      If you say Y here, the kernel will support poker_driver.
      If you say M here, the kernel not support poker_driver, must 
perform "insmod poker_driver.ko".
      If you say N here, the kernel not support poker_driver.
Copy after login

4) Write source code directory Makefile

 vi Makefile

      obj-$(CONFIG_POKER_DRV) += poker_drv.o
      poker_drv-objs += poker_drv_part1.o poker_drv_part2.o poker_drv_part3.o
Copy after login

5) Modify superior Kconfig

vi linux_tree/drivers/net/Kconfig

      source "drivers/net/poker_driver/Kconfig"
Copy after login

6) Modify the superior Makefile

 vi linux_tree/drivers/net/Makefile

      obj-$(CONFIG_POKER_DRV) += poker_driver/
Copy after login

7) Configure the kernel

   make menuconfig

      Device Drivers  --->

         [*] Network device support  ---> 

          poker_driver support
Copy after login

\1. Compile into the kernel:

  poker_driver support

  linux_tree# make uImage
Copy after login

\2. Compile into independent module

  poker_driver support 

  linux_tree# make modules
Copy after login

Brackets problem:

[] Optional * Empty

Optional * M empty

Through the introduction of this article, we have learned about the compilation method of the Linux kernel and driver, as well as related tools and files. We can customize our own Linux system according to our own needs to adapt to different embedded devices. Compilation of Linux kernel and drivers is a basic and important skill. I hope this article can help you.

The above is the detailed content of How to compile Linux kernel and drivers?. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template