Solve the problem that the device node cannot be automatically created under /dev after loading the driver on the development board

When making the linux root file system, the /etc/init.d/rcS file will be created, as follows:

#!/bin/sh

echo "----------myrootfs start-------------------"

/bin/mount -a
/sbin/dev -s 

echo "----------myrootfs end-------------------"

Every time you boot, the above script file will be executed, where /bin/mount -a is to mount the file system in fstab, and /sbin/dev -s is to create a device node

However, if you want to insmod a driver, the driver is loaded successfully, but no device node is created under /dev, the reason is: /sbin/dev -s is only executed once when the system starts, and then the driver is loaded, /sbin/mdev and It will not be executed again, so no device node is created under /dev.

Solution:

Change /sbin/dev -s in the /etc/init.d/rcS file to:

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

Restarting the development board can solve the problem.

And its principle is:

mdev is a simplified version of udev that comes with busybox, suitable for embedded applications. It is characterized by ease of use. Its function is to automatically generate the node files required by the driver when the system is started, hot-swapped or dynamically loaded. When building the root file system of embedded linux based on busybox, it is the best choice to use it. Use '-s' as a parameter to call mdev written in the /sbin directory (actually a link, the function is to pass parameters to the busybox program in the /bin directory and call it), mdev scans all files in /sys/class and /sys/block If there is a file named "dev" in the directory, and the file contains the device number, then mdev will use this information to create a device node file for this device under /dev. Generally, "mdev -s" is only executed once at startup.

Run the command at startup: echo /sbin/mdev > /proc/sys/kernel/hotplug, then when a hotplug event occurs, the kernel will call mdev located in the /sbin directory. At this time, mdev uses ACTION and DEVPATH in the environment variable (these two variables are built-in by the system) to determine the action of this hot plug event and the directory in /sys that is affected. Then it will check whether there is a "dev" attribute file in this directory, and if so, use this information to create a device node file for this device under /dev.

 

 

Guess you like

Origin blog.csdn.net/wenyue043/article/details/100550666