The difference between Uboot driver and Linux driver

The difference between Uboot driver and Linux driver

When we learn or transplant embedded Linux systems, we will come into contact with Uboot driver transplantation and Linux driver development. At this time, embedded Linux beginners will inevitably have questions, such as:

Uboot already has drivers for related chip platforms and external hardware devices. Why does the Linux kernel still need to integrate drivers? Let’s explain below.

Uboot driver

Uboot is one of the open source boot loaders. No matter what kind of boot loader it is, its core job is to start the embedded system (such as the Linux kernel), so Uboot needs to load data from non-volatile memories such as FLASH and MMC. Read out the Linux kernel and move the kernel to volatile memory such as DDR or RAM for execution.

Since Uboot needs to read and move the Linux kernel from non-volatile memory, Uboot itself needs to drive the non-volatile memory (such as MMC) and memory (such as DDR) first.

The above is just one of the scenarios. For example, Uboot also provides USB and network communication functions, which can facilitate subsequent program downloading and debugging. For example, you can use USB, or use the NFS file system or TFTP service to download the Linux kernel image through the network.

For example, Uboot supports command interaction, but it needs to use the processor serial port Uart to communicate with the terminal emulator on the computer to input and output commands in the simulated terminal, so Uboot must also be able to drive Uart.

Since Uboot ultimately works on a specific chip, the above driver must be written according to the rules of this chip. For example, if Uboot runs on Allwinner sunxi series chips, the MMC driver must be written according to the register rules of Allwinner sunxi series chips. For example, Uboot contains the driver sunxi_mmc.c and is marked "MMC driver for allwinner sunxi platform".


The Uboot driver only needs to meet the requirements of booting and loading the Linux kernel program, and the driver is usually relatively simple.

Linux driver

Linux belongs to the operating system kernel and needs to manage various hardware resources on the computer or read data from hardware devices, so the Linux kernel also needs drivers that can drive the hardware. For example, if you need to provide screen display to users, then the Linux kernel must be able to drive the screen. For example, if you need to provide input to the user, the Linux kernel needs to be able to drive keyboard, mouse, microphone, camera, USB disk and other devices. To be able to play audio, you need to be able to drive a speaker.

The driver in the Linux kernel is not used by the Linux kernel alone. In addition to using the Linux kernel itself, the driver also needs to be provided to other applications running in the system. Therefore, the Linux kernel driver also needs to provide a set of interfaces (open, read , write, close) to the application call. Not only that, in order to better separate drivers, the Linux kernel also requires a more complex driver framework.


Linux drivers need to manage hardware resources and provide user-level hardware operation interfaces for applications. Drivers are usually complex.

Why does the Linux kernel need drivers?

Going back to the question raised at the beginning: Uboot already has drivers for related chip platforms and external hardware devices. Why does the Linux kernel still need to integrate drivers and use device trees to manage drivers.

For example, Uboot has driven MMC, but the Linux kernel still needs to drive MMC by itself. Why is this? This is because the root file system rootfs is also located in MMC, so to mount the root file system from MMC, the Linux kernel must be able to access MMC, so an MMC driver is required.

You may also have questions, why does the Linux kernel not use Uboot's MMC driver?

There are three main reasons:

(1) During the working stage of Uboot, the MMC driver is implemented according to the Uboot bare metal rules and is a pure bare metal driver, so the Linux kernel cannot recognize the Uboot MMC driver.

(2) Even if the Linux kernel can recognize the Uboot driver, from the moment the Linux kernel is loaded into the memory by Uboot and triggered to run, Uboot's responsibilities are over, and all programs included in Uboot no longer run. So naturally the Uboot driver cannot be used, and ultimately all the computer's hardware needs to be controlled by the Linux kernel.

(3) Uboot’s bare-metal driver is hard-coded in the program, making it inflexible to use, inconvenient to manage hardware devices, and cannot support independent installation or uninstallation of the driver.

Special case:

As mentioned earlier, Uboot needs to use DDR (double data rate memory), so DDR is usually initialized in Uboot. There is no need to drive DDR again after the Linux kernel is started. Instead, the DDR configuration information passed by Uboot is used to read and write DDR.

Therefore, the DDR driver is a special case. After Linux starts, the Linux kernel itself is in DDR, so the Linux kernel cannot reinitialize DDR, otherwise the Linux kernel will be lost, so the Linux kernel must use the DDR driver provided by Uboot.

DDR is successfully initialized in Uboot. During the kernel startup process, the kernel will read the DDR configuration information passed by Uboot and use this information to correctly configure the memory controller and DDR.

DDR is a system-level hardware resource that does not need to be opened to applications and has no flexibility requirements. Therefore, it does not have much impact if the Linux kernel directly uses the DDR configuration provided by Uboot.

Differences in debugging methods

Uboot is a bare-metal program. To download the Uboot program to the chip and run it, you can only rely on debugging tools such as STLink and SWD, or use the USB transfer program solidified on the chip by the semiconductor chip manufacturer.

With the support of the Uboot driver, there are more ways to download the Linux kernel program to the chip, such as through the serial port, USB, Ethernet, SD card or U disk, or even wireless network, and the Linux kernel needs to be loaded into the memory by Uboot before it can be started. run.

Guess you like

Origin blog.csdn.net/jf_52001760/article/details/131486937