Kernel If loading firmware

Source: Internet
Author: User

Kenernal How to load firmware unfamiliar, just someone carried out the study, reproduced included http://blog.csdn.net/linphusen/article/details/5667647

Objective

Some time ago, the porting of WiFi drive to the Android kernel, found that firmware load always error, asked a few people, are not very understanding, no way, had to study for themselves. Principle Analysis

Essentially, firmware needs to do two things:

1, notify the user state program, I need to download firmware;

2, the User state program to the user state of the data copy to the kernel layer;

3, the kernel writes the kernel-state data to the device, such as the WiFi module;

The third step should not be difficult, the key is to see how Linux inside is how to achieve the first to second step, implementation mechanism

Simply put, its mechanism is divided into the following parts:

1, by a certain way, notify the user state program, such as the Init program, as shown in the figure:

is obviously through the kobject_uevent way to notify the application layer, and its mechanism I have time to explain in detail, simply, is to a socket broadcast a message, only need to open the socket in the application layer monitoring netlink_kobject_uevent Group of messages, you can receive it.

How the user-state init is done.

You can see that the INIT program opens a socket and then binds it, and finally it listens to the data on the socket through a select, and finally calls HANDLE_DEVICE_FD to process the received message; When the kernel sends a KOBJ_ADD message, it is filtered To determine if the message is firmware to be loaded, and then call the

Handle_firmware_event to deal with;

2, how to download the user-state data to the kernel;

Essentially it was the kernel that created two files, a file a used to flag the start and end of the download, another file B is used to receive data from the user layer, when the user state of the program to write a file 1, the Flag User state program has to write the program to the inside, and to write 0 of the time, the sign of the successful end of the download, If write-1 means that the download failed, let's look at how the two files were created and how the data was written to the kernel, see figure:

This diagram is basically the process of two files being created, and the function that will be invoked when the two files are accessed by the user-state program, such as for the flag file, if the data is written to it, it will trigger the function Firmware_loading_store function, if Writing the data in the bin file will trigger the write function of the bin file type.

The process of user state write data is about this: when the user state receives the KOBJ_ADD message, it will eventually call the Handle_firmware_event function;

Its process is:

A, first to the sign file inside write 1;

b, reading data from user space;

C, write data to the files created by the kernel;

D, if successfully written to 0, otherwise write-1;

Let's see how the kernel accepts these files, and the kernel creates a bin file to receive user-state data, and here's a look at this process:

For files with sysfs_kobj_bin_attr attributes, when the inode is initialized, it is given a set of bin_fops file operations, so when the upper layer calls write, it goes to the kernel's bin_fops.write function The function of the thing is very simple, that is, the user state of the data to Bb->buffer, and Bb->buffer is actually in the open when the allocation of space, in this case, to achieve the user state of the data to the kernel copy; The process is not over.

There is also a step in how the Bb->buffer itself interacts with the WiFi driver. This is just a middle tier, its data must be written to the WiFi driver should be complete, and this step is actually through the flush_write to complete, the following look at this process:

It is clear to see that flush_write do is to bb->buffer content copy to the WiFi driver allocated space fw->data inside, to this point, user-state data has been fully written to the WiFi driver Space out;

3, kernel-state data to WiFi module

This is relatively simple, through the function Sdio_writesb use the Sdio bus to write data to the module inside;

Summary

                  Firmware The main load is the use of uevent communication mechanism to achieve user-state and kernel-state interaction, in addition to the SYS file system in the file creation, I load WiFi firmware always error because the Android file system requires WiFi firmware hel Each is placed inside the/etc/firmware, and the real firmware Sd8686.bin is placed inside the/ETC/FIRMWARE/MRVL, which is estimated to be the result of the Marvel modification

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.