To thoroughly understand the device drivers of linuxand uclinux, I felt that I had to find a copy of devices.txt. The above details the distribution of 0 to 255 Linux master device numbers, and the corresponding device numbers of various devices. It is very useful for me to develop non-standard Linux devices. The devices in uClinux are the same as those in Linux. Therefore, this document applies to uClinux. This document can be found. As a common development manual, this document must be printed and saved.
I wrote a driver for the buttons on my development board. I want to start uClinux like other standard Linux devices, the/dev directory contains a device such as/dev/key. At first, I had no idea why the keyboard options were not found in the char device and input core menus of menuconfig, but the keyboard driver was indeed compiled into the system. Later, after comparing Linux and uClinux, I found that the key issue was not the config In the char/directory. in file, not in linux-2.4.x/ARCH/armnommu/config. in file, but in the drivers/Char/MAKEFILE file.
Briefly speaking, this file does not specify the structure of the char device sub-menu of menuconfig, but specifies the compilation rules of the files under the drivers/Char directory. In this file, add some condition judgments and assign values to some variables based on condition judgments to compile specific devices into the uClinux kernel.
The following are some definitions in makefile.
Compilation target definition:
The obj-$ (config_tc) + = tc. O statement is used to define the compilation target and is the most important part of the subdirectory makefile. Compile the target to define the target file list that needs to be compiled to the Linux kernel under the sub-directory (for this makefile, it is for the/linux-2.4.x/Drivers/Char subdirectory. In order to compile only after the user selects this function, all target definitions combine the judgment on configuration variables. As mentioned above, the value range of each configuration variable is Y, n, m, and null. obj-$ (config_tc) corresponds to OBJ-y, obj-N, obj-m, respectively, OBJ -. If config_tc is configured as Y, TC. O enters the obj-y list. OBJ-Y is the list of target files included in the Linux Kernel vmlinux, obj-m is the list of target files compiled into modules, and obj-N and obj-are ignored. The configuration system compiles and links these lists based on their attributes. The target files in export-objs all use export_symbol () to define public symbols so that they can be used by the load module. In the last part of the TC. c file, there is "export_symbol (search_tc_card);", indicating that TC. O has signed output. "Obj-y + =" indicates what to append if the variable is true, and "obj-Y: =" indicates what to append if the variable is true.
It should be noted that there are two formats for the definition of the compilation target, namely the old definition and the new definition. The old definition is the variables used by rules. Make. The new definition is obj-y, obj-M, obj-N, and obj -. The new definition is recommended for the Linux kernel, but because rules. Make does not understand the new definition, it is necessary to convert the adaptation segment in the makefile into an old definition.
In addition, makefiles in the Linux and uClinux source code trees are divided into two types: Autoconf and automake according to configure. the in template is automatically generated, and the other type is makefile manually written by the developer. Therefore, for the former, modifying any statements or judgment conditions in the file is futile. Because each time a new configuration is created or the previous configuration is modified, the makefile will be rewritten or regenerated. It is impossible to achieve satisfactory compilation configuration through this method. But the latter is different. Because it is not automatically generated by the kernel, this file will not change regardless of the number of configuration modifications. Therefore, we can modify the statements or judgment conditions in makefile to build our own compilation configuration. This is useful for adding your own non-standard devices.
Adaptive segment: the role of an adaptive segment is to convert a new definition into an old definition. In the following example, the adaptation segment is to convert obj-y and obj-m to Rochelle. Make to understand l_target, l_objs, lx_objs, m_objs, and mx_objs.
Rochelle objs: = $ (sort $ (filter-out $ (export-objs), $ (obj-y) defines the Rochelle objs generation method: filter out export-objs (TC. o), then sort and remove duplicate file names. Some special functions of GNU make are used here. For specific meanings, refer to the Make document (Info make ).
Obviously, the menuconfig graphic configuration menu does not have any keyboard options, so we can see that there is no keyboard. O in obj-y. How is the keyboard driver compiled into Char. O?
Note that the four variables keymap = defkeymap. okeybd = pc_keyb.oconsole = console. oserial = serial. O are assigned values. They indicate the ing table of the keyboard code and scan code, the keyboard driver, the console driver, and the serial driver respectively. The above is the default value of the four variables.
In the following section, first judge whether the variable arch is equal to sh. If it is true, then the variable is empty. Then, in the next level of logic judgment, judge whether the variable config_sh_hp600 is true. If it is true, the keyboard ing table is applicable to the default ing table (defkeymap. o), but the keyboard driver is changed to hp600_keyb.o and scan_keyb.o, And the console driver remains unchanged. However, you must note that the serial port is not included in the judgment statement in this part, because the serial port driver is listed separately in the following situation: obj-$ (config_68328_serial) + = 68328serial. O.
In addition, it should be noted that, to view the Linux or uClinux variable configuration, you can see the linux-2.4.x/include/Linux/Autoconf. h. uClinux-Dist/config. in And linux-2.4.x/config. in.
And ifeq (..) if it is equal to XXX, then xxx; ifneq (..) that is, if it is not equal to XXX, then xxx; ifdef () indicates that if XXX is true, then xxx; ifndef () indicates that if XXX is false, then XXX.
Ifeq ($ (ARCH), SH) If arch = SH, then... Keymap = keybd = console = ifeq ($ (config_sh_hp600), Y) If config_sh_hp600 = Y, then... Keymap = defkeymap. O keybd = scan_keyb.o hp600_keyb.o console = console. O endifendif
Ifeq ($ (ARCH), MIPS) ifneq ($ (config_pc_keyb), Y) If config_pc_keyb! = Y, so... Keybd = endifendif
Ifeq ($ (ARCH), m68k) ifdef config_amiga if config_amiga is true (that is, the variable is Y), then... Keybd = amikeyb. o else ifndef config_mac if config_amiga is false, then... Keybd = endif serial = endif
The following section is very important. Ifndef config_sun_keyboard if the variable is false, judge the variable config_vt
OBJ-$ (config_vt) + = keyboard. o $ (keymap) $ (keybd) else obj-$ (config_pci) + = keyboard. the o $ (keymap) endif result is that config_sun_keyboard (Sun's PC keyboard) is usually false (we will not use it), so config_vt is a virtual console. Generally we need to select config_vt = Y, append the keyboard. o, $ (keymap), and $ (keybd ). The two variables are defined at the beginning: defkeymap. O and pc_keyb.o. Therefore, the standard keyboard driver is automatically compiled into Char. O and then compiled into the kernel.
Therefore, I can automatically add my key driver to the kernel based on this principle. The following is a statement that I added to automatically compile my own key driver into the kernel.
Ifeq ($ (config_arch_s 3c44b0), Y) keybd = key. okeymap = mykeymap. O console = console. oendif
This makefile is roughly explained here. In fact, it's just for yourself.