Development work, often need to add some new drivers, but sometimes do not want to write makefile, or the driver needs to be compiled into the kernel, then how can we add the driver into the BSP, just follow the original compilation steps to get the desired KO file, or directly compiled to uimage it? The following three steps are required to add a new driver:
One, write your driver file, is new_driver.c, and put it in the directory you want to put, such as drivers/misc/.
Second, modify the Drivers/misc/makefile, its format, open to know, as follows:
1obj-$ (config_plat_nomadik) + = gpio-NOMADIK.O2obj-$ (config_gpio_rdc321x) + = rdc321x-gpio.o3obj-$ (config_gpio_janz_ttl) + = janz-TTL.O4obj-$ (config_gpio_sx150x) + =SX150X.O5obj-$ (config_gpio_vx855) + =vx855_gpio.o6obj-$ (Config_gpio_ml_ioh) + =ml_ioh_gpio.o7obj-$ (config_da9052_gpio_enable) + = da9052-gpio.o8obj-$ (config_ab8500_gpio) + = ab8500-gpio.o9obj-$ (config_gpio_tps65910) + = tps65910-gpio.oTenobj-$ (config_new_driver) + = NEW_DRIVER.O
The tenth line is the one that needs to be added, where does this config_new_driver manifest itself? Look at the next step.
Third, modify the Drivers/misc/kconfig. This file will be shown when make menuconfig, or if you do some default configuration, then directly make can compile. As follows:
1 config New_driver2TriState"New Driver"3 defaultm4 Help5 some new driver ' s information. 6 7 8 config Debug_gpio9 BOOL "Debug GPIO calls"Ten depends on Debug_kernel One Help A Say Y Here to add some extra checks and diagnostics to GPIO calls. - These checks help ensure that GPIOs has been properly initialized -Before they is used, and that sleeping calls is not made from thenon-sleeping contexts. They can make bitbanged serial protocols -Slower. The diagnostics HelpCatchThe type of Setup errors -That is most common when setting upNewPlatforms or boards.
To explain briefly, TriState is a tri-state that can be compiled into a kernel, module, or not compiled. Here's the default m. is compiled into a module by default. The reminder on make Menuconfig is <>new driver. <> can choose Y,n,m.
Line 9th of the above code, not tristate, but bool. It is not <> in the menuconfig; but []. only Y and N are selected. is either compiled into the kernel or not compiled.
Depends on is a dependency, that is, if Debug_kernel is selected or is valid, the Debug_gpio option appears.
Help is something that helps or describes information. You can write yourself casually.
OK, so far your new driver can be loaded in. If you want to make sure that the configuration is good, you can open the. config file under the Linux directory, which is the ultimate file. Find out if config_new_driver is defined as Y or M, or not.
Compile Tips:make menuconfig or specify schema make Arch=arm menuconfig, which is a text-to-graphic interface that can be configured as required.
Make uimage directly to the kernel.
Make modules. Compile the module. is configured as M, is compiled into a KO file. (The wrong module was written that day, thought the command was wrong)
Reference:
http://lhsblog01.blog.163.com/blog/static/102004519201022110295858/
Http://www.cnblogs.com/taomaomao/archive/2012/01/05/2312816.html
Thank you!
Adding a new driver to the Linux BSP