search
what is linux firmwareApr 18, 2023 am 11:47 AM
linux

In Linux, firmware refers to "firmware", which is a program executed by the hardware device itself and is generally stored in the device flash. In a Linux system, the device driver is in the kernel state, while the firmware file is in the user state. Therefore, a safe, stable and reliable mechanism is needed to ensure that the device driver successfully loads the firmware file.

what is linux firmware

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is linux firmware

Firmware (firmware) is a program executed by the hardware device itself. Firmware is generally stored in the device flash. For cost and convenience reasons, the running program of the hardware device is usually packaged into a firmware file in a specific format, stored in the terminal system, and the hardware device is upgraded through the terminal system.

During the Linux kernel development process, developers debug peripheral driver devices, such as touch, charging, linear motors, storage, WIFI devices, etc. There are also situations where firmware needs to be updated. In a Linux system, the device driver is in the kernel state, while the firmware file is in the user state. Therefore, a safe, stable and reliable mechanism is needed to ensure that the device driver successfully loads the firmware file.

In order to solve the problem of device drivers stably loading user-mode firmware files from the kernel mode, the Linux system provides a firmware subsystem.

Linux firmware subsystem process introduction

The Linux firmware subsystem is implemented based on the sysfs and uevent mechanisms.

After the driver calls the firmware system function interface to apply for firmware, the firmware subsystem uses the firmware compilation kernel to obtain the firmware; if the acquisition fails, it uses the firmware cache to obtain the firmware; if it still fails to obtain, Use the default path kernel to directly search to obtain the firmware. If the acquisition still fails, report the uevent message to the init process. The init process receives the uevent message and filters out the messages whose subsystem type is firmware. The init process searches for the firmware based on the firmware information pointed to in the uevent message, and writes the obtained firmware content from the user state to the kernel state through the file node interface provided by sysfs, so that the driver can obtain the data of the firmware file.

Linux firmware system provides a variety of methods to obtain firmware files in different scenarios.

1) The method of directly compiling into the kernel;

2) The method of firmware caching;

3) The method of directly specifying the path according to the kernel:

4) Assist processing through the init process;

Linux firmware subsystem flow chart

what is linux firmware

Linux firmware subsystem main function interface

Main function interface:

The main types of application firmware interfaces are divided into synchronous and asynchronous.

Usually the process of applying for firmware is time-consuming, and the process of processing firmware upgrade is time-consuming, so it can be implemented using an asynchronous function interface, or first create a work queue in the driver and call the synchronous function interface to implement it.

Among them:

  • The kernel applies for firmware files by calling the request_firmware function.

  • After the kernel obtains the firmware file, it calls release_firmware to release the related memory.

what is linux firmware

Among them:

  • The request_firmware_direct interface only searches for firmware in the path specified by the kernel and does not use uevent Mechanism to obtain firmware.

  • The request_firmware_nowait interface obtains firmware through an asynchronous work queue, which can not block the driver probe time.

what is linux firmware

Linux firmware subsystem implementation process

request_firmware implementation Process

The request_firmware function sets different flag bits by calling the _request_firmware_prepare function to achieve different differential functions.

  • _request_firmware_prepare function:

After turning on the CONFIG_FW_LOADER macro switch, first determine whether the firmware file is compiled into the kernel by calling the fw_get_builtin_firmware function .

what is linux firmware

Then call the fw_lookup_and_allocate_buf function to determine whether the linked list in the global fw_cache structure has recorded the name of the currently requested firmware. If the name of the currently requested firmware does not exist, the corresponding memory space is dynamically allocated and the name of the currently requested firmware is added to the linked list in the global fw_cache structure.

  • fw_get_filesystem_firmware function

Mainly searches for firmware files through the default path provided by the kernel and calls the kernel_read_file_from_path function. If the firmware file is not found, the flag bit FW_OPT_USERHELPER is used to determine whether the USER_HELPER mode is enabled.

Among them:

The default path in the Firmware system is as follows:

what is linux firmware

The default path can be added through the kernel command line. Pass the module_param_string interface to the variable path to customize the new path.

what is linux firmware

USER_HELPER mode

This function is only supported after the kernel turns on CONFIG_FW_LOADER_USER_HELPER. The main function is to report uevent messages to the init process through the kernel, obtain firmware information through the init process, and write it to the underlying sysfs node.

fw_load_from_user_helper function:

First call the fw_create_instance function to create the device device, class file and attribute file, and allocate the firmware_priv structure.

Next, a directory will be created under /sys/class/firmware, which uses the device name as its directory name.

This directory contains three attributes:

  • loading:

    is set to 1: This attribute is started by setting 1 in the user space responsible for loading firmware;

    is set to 0: when the loading process is completed;

    is set to -1: the firmware loading process will be terminated.

  • #data:

    is used to receive firmware data. After loading is set, the user space process writes the firmware to this attribute.

  • device: The symbolic link of the corresponding entry under

    /sys/devices.

  • timeout:

    The default maximum timeout for applying firmware through uevent is 60S, and the upper layer write timeout is supported.

_request_firmware_load function:

First disable uevent reporting, add the device by calling the device_add function, and trigger the calling of the firmware_uevent function. Among them, fill in the information format reported by uevent, including the name of the firmware, timeout period, and whether it is asynchronous.

what is linux firmware

The next step is to enable the uevent reporting function, call the kobject_uevent function at the same time, and report the add action type to the upper layer ueventd.

what is linux firmware

Then call the fw_state_wait_timeout function and wait for the processing of the upper layer ueventd within the preset timeout period.

If the timeout reaches or wakes up after receiving the completion amount, the previously applied memory will be released, and memory information such as device and class will be released.

ueventd related firmware processing process

Ueventd is an important module in the init process. It mainly handles selinux, dev device creation, monitoring kernel reporting of uevent messages, and firmware loading. etc. content.

FirmwareHandler processing flow:

The HandleUevent method in FirmwareHandler mainly handles the interaction process between firmware loading and underlying nodes.

First determine whether the subsystem type of the uevent message is the firmware field before processing. This type will only be reported by the firmware module in the kernel.

HandleUevent mainly creates different sub-threads through a main thread, and processes firmware requests from different drivers from the kernel in parallel.

what is linux firmware

ProcessFirmwareEvent function

First, it loops to determine whether the firmware file retrieved in the path supported by ueventd exists; if it exists, write the underlying loading attribute file as 1 , and at the same time copy the obtained firmware file and write it to the underlying data file. After completion, 0 is written to the underlying loading attribute file.

At this point, the kernel has obtained the firmware file information written by the user space.

what is linux firmware

Among them:

ueventd supports the path to search for firmware by default:

from the firmware_directory specified in the ueventd.rc file.

what is linux firmware

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of what is linux firmware. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
什么是linux设备节点什么是linux设备节点Apr 18, 2022 pm 08:10 PM

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

Linux中open和fopen的区别有哪些Linux中open和fopen的区别有哪些Apr 29, 2022 pm 06:57 PM

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

linux中什么叫端口映射linux中什么叫端口映射May 09, 2022 pm 01:49 PM

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

什么是linux交叉编译什么是linux交叉编译Apr 29, 2022 pm 06:47 PM

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

linux中eof是什么linux中eof是什么May 07, 2022 pm 04:26 PM

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux怎么判断pcre是否安装linux怎么判断pcre是否安装May 09, 2022 pm 04:14 PM

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux怎么查询mac地址linux怎么查询mac地址Apr 24, 2022 pm 08:01 PM

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

linux中rpc是什么意思linux中rpc是什么意思May 07, 2022 pm 04:48 PM

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools