📄 basic_driver_configure_and_build.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="./style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="./design.css" /> <link rel="stylesheet" media="print" type="text/css" href="./print.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="clear"><ul class="toc"><li class="clear"><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#basic_driver_configure_and_build" class="toc">Basic Driver Configure and Build</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#create_a_new_driver_directory" class="toc">Create a New Driver Directory</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#copy_the_source_to_the_new_directory" class="toc">Copy the source to the New Directory</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#create_a_makefile_in_the_new_directory" class="toc">Create a Makefile in the New Directory</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#extend_the_makefile_in_the_root_drivers_char_directory" class="toc">Extend the Makefile in the Root Drivers/Char Directory</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#test_the_process_so_far" class="toc">Test the process so far</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#add_the_basic_config_options" class="toc">Add the basic Config options</a></span></div></li></ul></li></ul></li></ul></div></div><h3><a name="basic_driver_configure_and_build" id="basic_driver_configure_and_build">Basic Driver Configure and Build</a></h3><div class="level3"><p>The driver code is complete. The driver now needs to be added into the kernel source and the kernel build system modified to include the new driver.</p><p> The procedure used is as follows: </p><ul><li class="level1"><div class="li"> Create a new driver directory</div></li><li class="level1"><div class="li"> Add the source to the new directory</div></li><li class="level1"><div class="li"> Create a Makefile in the new directory</div></li><li class="level1"><div class="li"> Extend the root Makefile to include the new subdir</div></li><li class="level1"><div class="li"> Test a basic build</div></li><li class="level1"><div class="li"> Add a configuration option in the old Kconfig file</div></li><li class="level1"><div class="li"> Create a new Kconfig file</div></li><li class="level1"><div class="li"> Test again</div></li><li class="level1"><div class="li"> Test download to the target</div></li></ul></div><!-- SECTION [1-557] --><h3><a name="create_a_new_driver_directory" id="create_a_new_driver_directory">Create a New Driver Directory</a></h3><div class="level3"><p> The new driver will be created in a <strong>test</strong> directory. </p><pre class="code"> mkdir -p linux-2.6.x/drivers/char/test</pre></div><!-- SECTION [558-698] --><h3><a name="copy_the_source_to_the_new_directory" id="copy_the_source_to_the_new_directory">Copy the source to the New Directory</a></h3><div class="level3"><p> The new driver source is copied to the test directory. </p><pre class="code"> linux-2.6.x/drivers/char/test/simple_driver.c</pre></div><!-- SECTION [699-852] --><h3><a name="create_a_makefile_in_the_new_directory" id="create_a_makefile_in_the_new_directory">Create a Makefile in the New Directory</a></h3><div class="level3"><p> The new driver Makefile will be created in the drivers/char/test directory. </p><pre class="code"> # # basic Makefile # # place this in linux-2.6.x/drivers/char/test # # bypass the config system for now CONFIG_SCMD_DRIVER = y # add the driver obj-$(CONFIG_SCMD_DRIVER) += simple_driver.o </pre></div><!-- SECTION [853-1601] --><h3><a name="extend_the_makefile_in_the_root_drivers_char_directory" id="extend_the_makefile_in_the_root_drivers_char_directory">Extend the Makefile in the Root Drivers/Char Directory</a></h3><div class="level3"><p> The Makefile in the drivers/char directory is modified to add a reference to the new test directory. </p><pre class="code"> # # modify linux-2.6.x/drivers/char/Makefile # add the test sub directory note the trailing / obj-$(CONFIG_BLACKFIN_RTC) += blackfin_rtc.o obj-$(CONFIG_BLACKFIN_DPMC) += blackfin_dpmc.o obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o # # dummy config statement to be removed later CONFIG_DRIVER_TEST = y # trigger the inclusion of the test directory obj-$(CONFIG_DRIVER_TEST) += test/ # # </pre></div><!-- SECTION [1602-2578] --><h3><a name="test_the_process_so_far" id="test_the_process_so_far">Test the process so far</a></h3><div class="level3"><p> Build the kernel and the build information of the new driver should show up in the Makefile output. </p><pre class="code"> cd linux-2.6.x/ make > make.out grep simple_driver make.out</pre></div><!-- SECTION [2579-2782] --><h3><a name="add_the_basic_config_options" id="add_the_basic_config_options">Add the basic Config options</a></h3><div class="level3"><p> Edit the <strong>drivers/char/Kconfig</strong> file to enable the new directory to be selected by <strong>make menuconfig</strong>.</p><p>Remove the statements that bypassed the config system </p><pre class="code"> Comment out CONFIG_DRIVER_TEST = y in linux-2.6.x/drivers/char/Makefile </pre><pre class="code"> Comment out CONFIG_SCMD_DRIVER = y in linux-2.6.x/drivers/char/test/Makefile</pre><p> Add the new Config options </p><pre class="code"> Add to linux-2.6.x/drivers/char/Kconfig </pre><pre class="code">config DRIVER_TEST tristate "Driver Test" help Some Test Drivers source "drivers/char/test/Kconfig" </pre><p> Do this just before the last <strong>endmenu</strong> statement in the file </p><pre class="code"> Create a new config file in the test directory linux-2.6.x/drivers/char/test/Kconfig </pre><p> Put the following in the new file </p><pre class="code"># # Test Driver configuration # config SCMD_DRIVER tristate "Basic Test Driver" depends on DRIVER_TEST help A basic demo driver </pre><p> Now run make menuconfig and attempt to find and select the new driver.</p><p>Run <strong>make</strong> to include the driver in the kernel build.</p><pre class="code">cd linux-2.6.x/make</pre></div><!-- SECTION [2783-] --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -