News:

Re-organized the forum to more cleanly delineate the development section, as the end user support side appears to have taken a life of its own!

Author Topic: Devices and /dev  (Read 3616 times)

  • No avatar
  • *****
February 08, 2011, 04:21:39 am
By now we've explained a fair bit of how the boot sequence works, and how some of our files relate to each other.

We haven't covered devices yet though.

What are devices?  Essentially they're hardware that the kernel knows how to talk to.

Read up here -  http://en.wikipedia.org/wiki/Device_file

In our hardware, we can see what devices we have by checking /proc on a running system.
Note that /proc will need to be mounted properly or we won't be able to see it.

So, make sure we've done this in our init script.

Code: [Select]
mount -t proc none /proc

We can check what drivers are loaded now with an easy

Code: [Select]
cat /proc/devices

On our system, we have the following compiled in

Code: [Select]
Character Devices:
1 mem
2 pty
3 ttyP
4 ttyS
5 cua
10 misc
14 sound
81 video_capture
89 i2c
108 ppp
162 raw
180 usb
188 ttyUSB

Block devices:
31 Blkmem

Character devices read or write one character by character similar to how we type.
Block devices read or write in blocks or chunks of data.

From the above, we can see some things of interest.

Our video_capture sits at 81
Our sound sits at 14

Lets take a look at /dev now

Code: [Select]
dev # ls -al
total 0
drwxr-xr-x 1 root root      32 Jan  1  1970 .
drwxr-xr-x 1 root root      32 Jan  1  1970 ..
crw------- 1 root root   5,  1 Jan  1  1970 console
crw------- 1 root root 196,  1 Jan  1  1970 display
lrwxrwxrwx 1 root root       4 Jan  1  1970 dsp -> dsp1
crw------- 1 root root  14,  3 Jan  1  1970 dsp0
crw------- 1 root root  14, 19 Jan  1  1970 dsp1
crw------- 1 root root  29,  0 Jan  1  1970 fb0
brw------- 1 root root   3,  0 Jan  1  1970 hda
brw------- 1 root root   3,  1 Jan  1  1970 hda1
brw------- 1 root root   3,  2 Jan  1  1970 hda2
brw------- 1 root root   3, 64 Jan  1  1970 hdb
crw------- 1 root root  89,  0 Jan  1  1970 i2c0
crw------- 1 root root  89,  1 Jan  1  1970 i2c1
crw------- 1 root root 191,  1 Jan  1  1970 key
crw------- 1 root root 192,  0 Jan  1  1970 keypad
crw------- 1 root root   6,  0 Jan  1  1970 lp0
lrwxrwxrwx 1 root root       6 Jan  1  1970 mixer -> mixer1
crw------- 1 root root  14,  0 Jan  1  1970 mixer0
crw------- 1 root root  14, 16 Jan  1  1970 mixer1
crw------- 1 root root  10,  1 Jan  1  1970 mouse
crw------- 1 root root  90,  0 Jan  1  1970 mtd0
crw------- 1 root root  90,  2 Jan  1  1970 mtd1
brw------- 1 root root  30,  0 Jan  1  1970 mtdblock0
brw------- 1 root root  30,  1 Jan  1  1970 mtdblock1
brw------- 1 root root  93,  0 Jan  1  1970 nftla
brw------- 1 root root  93,  1 Jan  1  1970 nftlA1
crw------- 1 root root   1,  3 Jan  1  1970 null
crw------- 1 root root 108,  0 Jan  1  1970 ppp
crw------- 1 root root 108,  1 Jan  1  1970 ppp1
crw------- 1 root root   5,  2 Jan  1  1970 ptmx
drwxr-xr-x 1 root root      32 Jan  1  1970 pts
crw------- 1 root root   2,  0 Jan  1  1970 ptyp0
crw------- 1 root root   2,  1 Jan  1  1970 ptyp1
crw------- 1 root root   2,  2 Jan  1  1970 ptyp2
crw------- 1 root root   2,  3 Jan  1  1970 ptyp3
crw------- 1 root root   2,  4 Jan  1  1970 ptyp4
crw------- 1 root root   2,  5 Jan  1  1970 ptyp5
crw------- 1 root root   2,  6 Jan  1  1970 ptyp6
crw------- 1 root root   2,  7 Jan  1  1970 ptyp7
crw------- 1 root root   2,  8 Jan  1  1970 ptyp8
crw------- 1 root root   2,  9 Jan  1  1970 ptyp9
brw------- 1 root root  31,  0 Jan  1  1970 rom0
brw------- 1 root root  31,  1 Jan  1  1970 rom1
brw------- 1 root root  31,  2 Jan  1  1970 rom2
brw------- 1 root root   8,  0 Jan  1  1970 sda
brw------- 1 root root   8,  1 Jan  1  1970 sda1
brw------- 1 root root   8,  2 Jan  1  1970 sda2
brw------- 1 root root   8, 16 Jan  1  1970 sdb
brw------- 1 root root   8, 17 Jan  1  1970 sdb1
brw------- 1 root root   8, 18 Jan  1  1970 sdb2
crw------- 1 root root 124,  0 Jan  1  1970 smartcard0
crw------- 1 root root 124,  1 Jan  1  1970 smartcard1
crw------- 1 root root   5,  0 Jan  1  1970 tty
crw------- 1 root root   4,  1 Jan  1  1970 tty1
crw------- 1 root root   3,  0 Jan  1  1970 ttyp0
crw------- 1 root root   3,  1 Jan  1  1970 ttyp1
crw------- 1 root root   3,  2 Jan  1  1970 ttyp2
crw------- 1 root root   3,  3 Jan  1  1970 ttyp3
crw------- 1 root root   3,  4 Jan  1  1970 ttyp4
crw------- 1 root root   3,  5 Jan  1  1970 ttyp5
crw------- 1 root root   3,  6 Jan  1  1970 ttyp6
crw------- 1 root root   3,  7 Jan  1  1970 ttyp7
crw------- 1 root root   3,  8 Jan  1  1970 ttyp8
crw------- 1 root root   3,  9 Jan  1  1970 ttyp9
crw------- 1 root root   4, 64 Jan  1  1970 ttyS0
crw------- 1 root root   4, 65 Jan  1  1970 ttyS1
crw------- 1 root root   4, 66 Jan  1  1970 ttyS2
crw------- 1 root root   4, 67 Jan  1  1970 ttyS3
crw------- 1 root root   1,  9 Jan  1  1970 urandom
drwxr-xr-x 1 root root      32 Jan  1  1970 usb
crw------- 1 root root 231,  0 Jan  1  1970 usi
crw------- 1 root root  81,  0 Jan  1  1970 video0
crw------- 1 root root  81,  1 Jan  1  1970 video1

Remember that device number 81 for video_capture?

Code: [Select]
crw------- 1 root root  81,  0 Jan  1  1970 video0
crw------- 1 root root  81,  1 Jan  1  1970 video1

Thats right, /dev maps the devices to the device numbers so we have nice names to use.
So instead of opening device 81:0, we can refer to /dev/video0

The numbers used are defined by IANA in the kernel.  For a complete list of numbers used, refer to this document - http://www.kernel.org/pub/linux/docs/device-list/devices.txt

Lets see if we're missing any /dev links for our drivers.

Code: [Select]
1 mem - 1:3 /dev/null 1:9 /dev/urandom
2 pty - 2:0 - 2:9 /dev/ptyp0..9
3 ttyP - 3:0 - 3:9 /dev/ttyP0..9 *the /dev/hdX are block devices, and we don't have any.
4 ttyS - 4:0 - 4:9 /dev/ttyS0..9
5 cua - 5:0 /dev/tty 5:1 /dev/console
10 misc - 10:1 /dev/mouse (which we don't have, but its a recommended default to have)
14 sound - 14:3 /dev/dsp0 14:19 /dev/dsp1 (digital audio)
81 video_capture - 81:0 /dev/video0 81:1 /dev/video1 (video4linux)
89 i2c - 89:0 /dev/i2c0 89:1 /dev/i2c1
108 ppp - 108:0 /dev/ppp 108:1 /dev/ppp1
162 raw - No device name
180 usb - No device name
188 ttyUSB - No device name

Seems we don't have 162, 180 and 188 defined in our /dev