1. Viewing Devices from the /dev Directory
In Linux systems, the vast majority of devices are exposed in the /dev directory in the form of device files. These device files are essentially "entry points for accessing devices", not ordinary files that actually store data.
Execute ls -l /dev on the development board and you will see output similar to the following:
lckfb@linaro-alip:~$ ls -l /dev
total 8
drwxr-xr-x 3 root root 480 Dec 9 19:02 block
drwxr-xr-x 1 root root 60 Jan 1 1970 bus
crw-rw---- 1 root video 248, 0 Dec 9 19:02 cec0
drwxr-xr-x 1 root root 5300 Dec 9 19:02 char
crw--w---- 1 root tty 5, 1 Dec 9 19:03 console
crw------- 1 root root 10, 124 Dec 9 19:02 cpu_dma_latency
crw-rw-rw- 1 root root 10, 126 Dec 9 19:02 crypto
drwxr-xr-x 9 root root 180 Dec 9 19:02 disk
drwxr-xr-x 1 root root 100 Jan 1 1970 dma_heap
drwxr-xr-x 1 root root 140 Dec 9 19:02 dri
crw------- 1 root root 240, 0 Dec 9 19:02 drm_dp_aux0
lrwxrwxrwx 1 root root 13 Dec 9 19:02 fd -> /proc/self/fd
crw-rw-rw- 1 root root 1, 7 Dec 9 19:02 full
crw-rw-rw- 1 root root 10, 229 Dec 9 19:02 fuse
crw------- 1 root root 254, 0 Dec 9 19:02 gpiochip0
crw------- 1 root root 254, 1 Dec 9 19:02 gpiochip1
..........
crw------- 1 root root 10, 183 Dec 9 19:02 hwrng
crw-rw---- 1 root i2c 89, 1 Dec 9 19:02 i2c-1
crw-rw---- 1 root i2c 89, 10 Dec 9 19:02 i2c-10
.........
crw------- 1 root root 245, 0 Dec 9 19:02 iio:device0
lrwxrwxrwx 1 root root 12 Dec 9 19:02 initctl -> /run/initctl
drwxr-xr-x 2 root root 180 Dec 9 19:02 input
crw-r--r-- 1 root root 1, 11 Dec 9 19:02 kmsg
lrwxrwxrwx 1 root root 28 Dec 9 19:02 log -> /run/systemd/journal/dev-log
brw-rw---- 1 root disk 7, 0 Dec 9 19:02 loop0
................
crw-rw---- 1 root disk 10, 237 Dec 9 19:02 loop-control
crw-rw---- 1 root video 10, 122 Dec 9 19:02 mali0
crw-rw----+ 1 root video 249, 0 Dec 9 19:02 media0
crw-rw----+ 1 root video 249, 1 Dec 9 19:02 media1
.....................
crw-r----- 1 root kmem 1, 1 Dec 9 19:02 mem
brw-rw---- 1 root disk 179, 0 Dec 9 19:02 mmcblk0
brw-rw---- 1 root disk 179, 32 Dec 9 19:02 mmcblk0boot0
brw-rw---- 1 root disk 179, 64 Dec 9 19:02 mmcblk0boot1
brw-rw---- 1 root disk 179, 1 Dec 9 19:02 mmcblk0p1
brw-rw---- 1 root disk 179, 2 Dec 9 19:02 mmcblk0p2
brw-rw---- 1 root disk 179, 3 Dec 9 19:02 mmcblk0p3
brw-rw---- 1 root disk 179, 4 Dec 9 19:02 mmcblk0p4
brw-rw---- 1 root disk 179, 5 Dec 9 19:02 mmcblk0p5
brw-rw---- 1 root disk 179, 6 Dec 9 19:02 mmcblk0p6
brw-rw---- 1 root disk 179, 7 Dec 9 19:02 mmcblk0p7
brw-rw---- 1 root disk 179, 8 Dec 9 19:02 mmcblk0p8
crw------- 1 root root 235, 0 Dec 9 19:02 mmcblk0rpmb
crw-rw---- 1 root video 241, 0 Dec 9 19:02 mpp_service
crw-rw-rw- 1 root root 1, 3 Dec 9 19:02 null
crw-r----- 1 root kmem 1, 4 Dec 9 19:02 port
crw-rw-rw- 1 root tty 5, 2 Dec 12 14:34 ptmx
crw------- 1 root root 246, 0 Dec 9 19:02 ptp0
drwxr-xr-x 2 root root 0 Dec 9 19:02 pts
brw-rw---- 1 root disk 1, 0 Dec 9 19:02 ram0
crw-rw-rw- 1 root root 1, 8 Dec 9 19:02 random
crw-rw-r--+ 1 root netdev 10, 242 Dec 9 19:02 rfkill
crw-rw---- 1 root video 10, 123 Dec 9 19:02 rga
lrwxrwxrwx 1 root root 4 Dec 9 19:02 rtc -> rtc0
crw------- 1 root root 250, 0 Dec 9 19:02 rtc0
drwxr-xrwt 2 root root 40 Dec 9 19:02 shm
drwxr-xr-x 3 root root 260 Dec 9 19:02 snd
lrwxrwxrwx 1 root root 15 Dec 9 19:02 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Dec 9 19:02 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Dec 9 19:02 stdout -> /proc/self/fd/1
crw------- 1 root root 10, 127 Dec 9 19:02 sw_sync
crw------- 1 root root 244, 0 Dec 9 19:02 tee0
crw------- 1 root root 244, 16 Dec 9 19:02 teepriv0
crw-rw-rw- 1 root tty 5, 0 Dec 9 19:02 tty
crw--w---- 1 root tty 4, 0 Dec 9 19:02 tty0
crw--w---- 1 root tty 4, 1 Dec 9 19:02 tty1
..................
crw------- 1 root root 10, 121 Dec 9 19:02 ubi_ctrl
crw------- 1 root root 10, 239 Dec 9 19:02 uhid
crw------- 1 root root 10, 223 Dec 9 19:02 uinput
crw-rw-rw- 1 root root 1, 9 Dec 9 19:02 urandom
drwxr-xr-x 3 root root 60 Dec 9 19:02 usb-ffs
crw------- 1 root root 237, 0 Dec 9 19:02 usbmon0
crw------- 1 root root 237, 1 Dec 9 19:02 usbmon1
crw------- 1 root root 237, 2 Dec 9 19:02 usbmon2
drwxr-xr-x 3 root root 60 Dec 9 19:02 v4l
crw-rw----+ 1 root video 81, 65 Dec 9 19:02 v4l-subdev0
crw-rw----+ 1 root video 81, 70 Dec 9 19:02 v4l-subdev1
..................
crw-rw---- 1 root tty 7, 0 Dec 9 19:02 vcs
crw-rw---- 1 root tty 7, 1 Dec 9 19:02 vcs1
.................
crw-rw---- 1 root tty 7, 70 Dec 9 19:02 vcsu6
crw-rw---- 1 root tty 7, 71 Dec 9 19:02 vcsu7
crw------- 1 root root 10, 125 Dec 9 19:02 vendor_storage
crw------- 1 root root 10, 137 Dec 9 19:02 vhci
crw-rw----+ 1 root video 81, 0 Dec 9 19:02 video0
crw-rw----+ 1 root video 81, 1 Dec 9 19:02 video1
.................
crw------- 1 root root 10, 130 Dec 9 19:02 watchdog
crw------- 1 root root 243, 0 Dec 9 19:02 watchdog0
crw-rw-rw- 1 root root 1, 5 Dec 9 19:02 zero
brw-rw---- 1 root disk 254, 0 Dec 9 19:02 zram02
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
The most important ones are :
- First column letters (device type):
crw-rw-rw- 1 root root 1, 3 Dec 9 19:02 null
^
|
File type: c = character device
brw-rw---- 1 root disk 179, 0 Dec 9 19:02 mmcblk0
^
|
File type: b = block device2
3
4
5
6
7
8
9
c: Character deviceb: Block deviced: Directoryl: Symbolic link- Other types are not elaborated here
For driver developers, the most common devices to work with are:
- Devices starting with
ccharacter devices (such as/dev/null,/dev/ttyS0,/dev/gpiochip0, etc.)- Devices starting with
bblock devices (such as/dev/mmcblk0,/dev/zram0, etc.)
- The pair of numbers in the 3rd and 2nd from last columns (major and minor device numbers):
crw-rw-rw- 1 root root 1, 3 Dec 9 19:02 null
^ ^
| |
Major number Minor number2
3
4
These two numbers together form the device number, used in the kernel to uniquely identify a device and its corresponding driver. For example:
/dev/null:1, 3/dev/mmcblk0:179, 0Subsequent chapters will specifically introduce the meaning of major and minor device numbers, allocation methods, and how driver programs register and use them.
2. Classification by Access Method
The most fundamental classification in Linux is by access method, dividing devices into:
- Character Device
- Block Device
2.1 Character Device
Character devices perform sequential read/write in byte stream (stream) mode:
- Generally do not require alignment to fixed-size "blocks".
- Usually do not have complex buffering or random access optimization.
Typical examples:
- Serial ports:
/dev/ttyS0,/dev/ttyUSB0 - Console:
/dev/console - Some simple control or debugging devices:
/dev/null,/dev/zero,/dev/random - User-defined character devices:
/dev/mychar, etc.
In ls -l output:
- Starts with
c:
crw-rw---- 1 dialout 4, 64 ... /dev/ttyS0User space typically uses system calls like open, read, write, ioctl to access character devices:
int fd = open("/dev/ttyS0", O_RDWR);
write(fd, buf, len);
read(fd, buf, len);
close(fd);2
3
4
Subsequent chapters will focus on this type of device.
2.2 Block Device
Block devices read and write in units of data blocks, with block sizes typically being 512 bytes or multiples thereof. Characteristics:
- Support efficient random access and caching mechanisms.
- Mainly used for various storage media.
Typical examples:
- eMMC / SD cards:
/dev/mmcblk0,/dev/mmcblk0p1 - USB drives, SATA/USB disks:
/dev/sda,/dev/sdb
In ls -l output:
- Starts with
b:
brw-rw---- 1 root disk 179, 0 Dec 9 19:02 /dev/mmcblk0Usually, high-level data read/write is not performed directly on block devices, but rather:
- Create a file system (such as ext4, vfat) on the block device;
- Mount it to a certain directory:
mount /dev/mmcblk0p1 /mnt- Access files under
/mntthrough ordinary file interfaces.
Block device drivers work with file systems, involving more content. This chapter does not focus on this.
3. Network Devices and Other Types
Character devices and block devices are primarily exposed to user space through /dev.
In addition, there are some device types that do not present as traditional device files, primarily used through specialized subsystems.
3.1 Network Device
Network devices, such as Ethernet, WiFi, etc., usually appear as network interfaces:
- For example:
eth0,end0,wlan0,lo, etc. - Can be viewed with:
ip link showNetwork devices:
- Do not correspond to ordinary
/devdevice files. - Interact with the kernel network subsystem through socket interfaces, for example:
socket(AF_INET, SOCK_STREAM, 0);Network drivers typically implement struct net_device related interfaces, belonging to a separate subsystem. This tutorial will not expand on this for now.
3.2 Other Devices
Some device types have dedicated frameworks in the kernel and are exposed to user space in specific ways:
- Input devices (keyboards, touch screens, etc.):
- Bottom layer is usually character devices:
/dev/input/eventX - User space often uses upper-level libraries like
libinput, Xorg, Wayland.
- Bottom layer is usually character devices:
- Audio devices:
- ALSA framework: such as
/dev/snd/* - Provides PCM, control, and other interfaces.
- ALSA framework: such as
- Graphics devices (GPU / graphics cards):
- DRM/KMS system: such as
/dev/dri/card0
- DRM/KMS system: such as
These devices are generally still based on character devices or other abstractions inside the kernel, but externally use their respective subsystems and APIs.
4. Device Classification from sysfs Perspective
In addition to /dev, modern Linux kernels also organize and display devices hierarchically through sysfs (usually mounted at /sys).
Use ls /sys/class/ on the development board:
lckfb@linaro-alip:~$ ls /sys/class/
android_usb devcoredump dvb input net pwm scsi_disk tpm usb_role
ata_device devfreq extcon iommu nvme regulator scsi_host tpmrm vc
ata_link devfreq-event gpio leds nvme-generic retimer sound tty video4linux
ata_port devlink hdmirx mdio_bus nvme-subsystem rfkill spidev typec vtconsole
backlight dma hidraw mem pci_bus rk_modem spi_host typec_mux wakeup
bdi dma_heap hwmon misc phy rkwifi spi_master ubi watchdog
block drm i2c-adapter mpp_class power_supply rpmsg spi_transport udc zram-control
bluetooth drm_dp_aux_dev i2c-dev mtd ptp rtc tee usbmon
bsg dsmc ieee80211 mtd ptp scsi_device thermal usb_power_delivery2
3
4
5
6
7
8
9
10
Visible typical directories, such as:
block: Block device classtty: Terminal/serial port device classnet: Network interfaceinput: Input device classmmc_host: MMC host controller
The class under these directories represents a type of device or subsystem; each entry under a class corresponds to a specific device instance and is linked via symbolic links to physical devices in /sys/devices.
Subsequent chapters will provide detailed introductions to this.
6. Summary
- Common device classifications in Linux:
- Character device: Accessed in byte/stream mode, such as serial ports, some control devices;
- Block device: Accessed in fixed-size data blocks, mainly used for various storage media;
- There are also network devices, input devices, audio devices, etc., used through dedicated subsystems and interfaces.
- In
/dev:- Device files starting with
crepresent character devices; - Device files starting with
brepresent block devices; - The subsequent major and minor device numbers are used to uniquely identify a device and its corresponding driver.
- Device files starting with
- In
/sys/class, you can observe the organization of different types of devices from a device model perspective.