Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 804 of 93611. Introduction to Embedded LinuxFree lesson

Device Node Creation and Devtmpfs

Populate the dev directory using devtmpfs or manual node creation to allow kernel-space hardware drivers to communicate with user-space applications.

In this lesson, you will learn how the Linux kernel automates the population of the /dev directory to bridge the gap between kernel-space drivers and user-space applications.

The Problem: Bridging User and Kernel Space

When a kernel driver registers a character device (like a sensor or a UART port), the kernel assigns it a major and minor number. However, user-space applications cannot simply "guess" these numbers to open a file descriptor. They need a representative file—a device node—located in the /dev directory to communicate with the driver.

Manual Node Creation

Historically, developers used the mknod command to create these nodes manually:

mknod /dev/my_sensor c 240 0

This tells the kernel: create a character device (c) at /dev/my_sensor with major number 240 and minor number 0. In embedded systems with hundreds of devices, manual creation is error-prone, inflexible, and creates a significant maintenance burden.

The Solution: Devtmpfs

devtmpfs is a small, specialized virtual filesystem that automatically manages the creation and removal of device nodes. When a kernel driver calls device_create(), devtmpfs intercepts the request and instantly creates the corresponding entry in /dev with the correct permissions and ownership.

To leverage this, you must ensure your kernel configuration has CONFIG_DEVTMPFS and CONFIG_DEVTMPFS_MOUNT enabled. When these are active, the kernel handles the heavy lifting during the boot process:

  1. Kernel Boot: The kernel mounts devtmpfs at /dev early in the initialization phase.
  2. Driver Loading: As hardware drivers initialize and register their presence (e.g., via a Platform Driver), the kernel automatically generates the device node.
  3. User Access: User-space applications can immediately open /dev/node_name without requiring manual intervention from an init script.

This mechanism ensures that your /dev directory remains perfectly synchronized with the hardware actually present on your board, regardless of whether a module is loaded or a device is hot-plugged.

Key Takeaway: devtmpfs eliminates the need for manual mknod calls by dynamically populating the /dev directory as drivers register, ensuring a seamless interface between hardware drivers and user-space applications.