About hot swapping USB hotplug/proc/sys/kernel mdev udev busybox

Source: Internet
Author: User

This article is very good at http://blog.chinaunix.net/u1/38994/showart_2022040.html:

How to use the simplified udev program of busybox-mdev to dynamically create inserted USB flash drives, mouse drives, and other devices

Busybox mdev is a streamlined udev Management Program, which can be indirectly called by the kernel in hotplug mode, and then dynamically create devices under the/dev directory on the ARM platform
Node, because hotplug will be called before the kernel sends uevent, so if there are many dynamic pluggable devices that are frequent, then each time the kernel calls the ELF format user space
Hotplug generates an independent hotplug program for processing, so hotplug is a very cumbersome implementation method, but on our arm Development Board, pluggable devices do not have
As often as you think
At present, there is no need to port the full version of udev, so you can use mdev to manage dynamic nodes on non-complex embedded devices,
The method is also very simple, that is, add the following sentence to the RCS script to pass the Application Path of the user space to the kernel,
Echo/sbin/mdev>/proc/sys/kernel/hotplug
Then, the kernel calls the user space application/sbin/mdev passed in the above sentence to process the corresponding information when the device changes, the mdev application then adds or deletes devices in the/dev directory. You can refer to add the hotplug function to the kernel to monitor uevent information.

Another useful part of mdev is that it can dynamically organize registered devices through the proc and SYS file systems, and then generate their corresponding nodes under/dev,
Before using this function, you must mount the proc and SYS file systems, and then simply execute the following sentence to bend it:
Mdev-S

If you need to compile udev, the following is udev's: http://www.us.kernel.org/pub/linux/utils/kernel/hotplug/udev-145.tar.bz2



This buddy also said in detail:

Http: // 203.208.39.132/search? Q = cache: c8dppxqd5hwj: pushed



1, busybox

Add mdev support



2. Add

# Mount filesystem

/Bin/Mount-

# Start mdev

# Set the system's hotplug program to mdev

Echo/sbin/mdev>/proc/sys/kernel/hotplug



# Scan and create a node. This step is indispensable.


Mdev-S



The content of/etc/fstab is as follows:

Proc/proc defaults 0 0

None/tmp ramfs defaults 0 0

Mdev/dev ramfs defaults 0 0

Sysfs/sys sysfs defaults 0 0



RunMdev-S
: Call mdev written in the/sbin directory with '-S' as the parameter (in fact, it is a link and the function is to pass the parameter to the/bin directoryBusybox

Program and call it), mdev scans/sys/class and/sys/block
If the directory contains a file named "Dev" and the file contains a device number, mdev uses this information
Create a device node file. Generally, "mdev-s" is executed only once at startup ".



Hot swapping event: the command echo/sbin/mdev>/proc/sys/kernel/is run at startup/

Hotplug, when a hot swapping event is generated, the kernel will call mdev in the/sbin directory. In this case, mdev uses the action and
Devpath to determine the actions of the hot swapping event and the directory in/sys. Check whether the "Dev" attribute file exists in this directory.
This device creates a device node file under/dev.



Solve the "cannot create/proc/sys/kernel/hotplug: nonexistent directory" error when using mdev

Make sure that the following options are compiled during kernel Compilation:

Config_proc_fs = y

Config_proc_sysctl = y

Config_hotplug = y

Config_net = y

If config_hotplug and config_net are not selected or all are not selected, they will not be created in/proc/sys/kernel.

Hotplug file. (See kernel/sysctl. c)

//////////////////////////////////////// ////////////////

Here is a piece of translation:

 

Mdev entry (for details)

Busybox-1.7.0/docs/mdev.txt
Tekkamanninja mail: tekkamanninja@163.com-1-

-------------
Mdev Primer
Mdev entry
-------------
For those of us who know how to use mdev, a primer might seem lame.
This document may seem superficial to those who know how to use mdev.
Everyone else, mdev is a weird black box that they hear is awesome, but can't
But for others, mdev may be a mysterious black box, and even awesome.
Seem to get their head around how it works. Thus, a primer.
This document is insufficient to let them know how mdev works. Therefore, this is an entry-level document.
-----------
Basic use
Basic usage
-----------
Mdev has two primary uses: initial population and dynamic updates. Both
Mdev has two main applications: initialization object and dynamic update.
Require sysfs support in the kernel and have it mounted at/sys. For dynamic
Both applications require support from the kernel sysfs and must be mounted to/sys. To achieve dynamic updates,
Updates, you also need to have hotplugging enabled in your kernel.
You must also add hotging ging support during Kernel configuration ).
Here's a typical code snippet from the init script:
The following is a typical mdev code snippet in the system initialization script:
[1] Mount-T sysfs/sys
[2] echo/bin/mdev>/proc/sys/kernel/hotplug
[3] mdev-S

Of course, a more "full" setup wocould entail executing this before the previous
Of course, a more complete installation of mdev must also execute the following command before the above code snippets:
Code snippet:
[4] Mount-T tmpfs mdev/dev
[5] mkdir/dev/PTS
[6] Mount-T devpts/dev/PTS

The simple explanation here is that [1] You need to have/sys mounted before
Briefly describe the above Code: [1] You must mount/sys before executing mdev.
Executing mdev. Then you [2] instruct the kernel to execute/bin/mdev whenever
Then you [2] Run the command kernel/bin/mdev when adding or deleting devices,
A device is added or removed so that the device node can be created or
This allows you to create and delete device node files.
Destroyed. Then you [3] seed/dev with all the device nodes that were created
Finally, you [3] Set mdev to create all the device nodes when the system starts.
While the system was booting.
For the "full" setup, you want to [4] Make sure/Dev is a tmpfs filesystem
For more complete mdev installation, you must [4] ensure that/Dev is the tmpfs File System
(Assuming you're running out of Flash). Then you want to [5] Create
(Assume that the file system runs out of Flash ). And you must [5] Create

-------------
Mdev config (/etc/mdev. conf)
Mdev configuration (/etc/mdev. conf)
-------------
Mdev has an optional config file for controlling ownership/permissions
Device nodes if your system needs something more than the default root/root
660 permissions.
If your system requires more permissions than the default root/root 660,
You can use the optional configuration file of mdev to control the owner and permissions of the device node.
The file has the format:
The file format is as follows:
<Device RegEx> <uid >:< GID> <octal permissions>
For example:
For example:
HD [A-Z] [0-9] * 0: 3 660
The Config File Parsing stops at the first matching line. If no line is
This configuration file stops parsing at the First Matching row. If no matching row exists,
Matched, then the default of 0: 0 660 is used. To set your own default, simply
Use the default 0: 0 660. You can also create the following full match at the end
Create your own total match like so:
To set your own default settings:
. * 1:1 777
If you also enable support for executing your own commands, then the file has
If you want mdev to execute a custom command when matching a row is found, the file format is as follows:
The format:
<Device RegEx> <uid >:< GID> <octal permissions> [<@ | $ | *> <command>]
The special characters have the meaning:
The significance of special characters is as follows:
@ Run after creating the device.
@ Run the command after creating the device node.
$ Run before removing the device.
$ Run the command before deleting a device node.
* Run both after creating and before removing the device.
* Run the command after the device node is created and before the device node is deleted.
The command is executed via the system () function (which means you're giving
These commands are executed through the system function (system () (that is, you are running commands on Shell)
Command to the shell), so make sure you have a shell installed at/bin/sh.
So make sure that you have installed the shell in/bin/sh.
For your convenience, the shell env var $ mdev is set to the device name. So if
For convenience, the shell environment variable $ mdev is set to the device name. For example
The device 'hdc 'was matched, mdev wocould be set to "HDC ".
Mdev resolves to the device 'hdc 'to match, and mdev is set to "HDC ".

----------
Firmware
Firmware
----------
Some kernel device drivers need to request firmware at runtime in order
Some device drivers need to upload firmware to initialize the device correctly during running.
Properly initialize a device. Place all such firmware files into
Put all firmware files
/Lib/firmware/directory. At runtime, the kernel will invoke mdev with
/Lib/firmware/directory. At runtime, the kernel will call mdev according to the firmware file name,
Filename of the firmware which mdev will load out of/lib/firmware/and
Then mdev uses the sysfs interface to extract the firmware from/lib/firmware/
The kernel via the sysfs interface. The exact filename is hardcoded in
Load to the kernel. The specified file name is fixed in the kernel,
Kernel, so look there if you need to want to know what to name the file in
If necessary, you must know how to name this file in the user space.
Userspace.

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.