Linux Drivers
#Device Types
Character: This is for an unbuffered I/O with a rich range of functions and a thin layer between the application code and the driver. It is the first choice when implementing custom device drivers.
Block: This has an interface tailored for block I/O to and from mass storage devices. There is a thick layer of buffering designed to make disk reads and writes as fast as possible, which makes it unsuitable for anything else.
Network: This is similar to a block device but is used for transmitting and receiving network packets rather than disk blocks.
#Device Nodes
device nodes can be created in several ways:
devtmpfs: The device node is created when the device driver registers a new device interface using a base name supplied by the driver (ttyAMA) and an instance number.
udev or mdev (without devtmpfs): Essentially the same as with devtmpfs, except that a user space daemon program has to extract the device name from sysfs and create the node.
mknod: If you are using static device nodes, they are created manually using mknod.
#Makefile
KVERS = $(shell uname -r) #kernel modules obj-m += globalmem.o #specific flags for the module complication EXTRA_CFLAGS = -g -O0 all: make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules clean: make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean
#Install the linux header files
sudo apt-get install linux-headers-generic
or sudo apt-get install linux-headers-$(uname -r)
#device node
mknod create a special or ordinary file
mknod /dev/device_name c major_dev_num minor_dev_num
e.g. sudo mknod /dev/dev_test c 220 0
To remove the device just call sudo rm /dev/dev_test
#Test device by commands
echo "mmmx mcm" > /dev/dev_test
cat /dev/dev_test
Error "Permission denied"
fix it by : sudo chmod 666 /dev/dev_test
浙公网安备 33010602011771号