147 lines
8.9 KiB
HTML
147 lines
8.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
|
||
<title>Tasks</title>
|
||
<meta name="generator" content="DocBook XSL Stylesheets V1.40">
|
||
<link rel="home" href="index.html" title="Kernel Hacking HOWTO">
|
||
<link rel="up" href="index.html" title="Kernel Hacking HOWTO">
|
||
<link rel="previous" href="indexs05.html" title="Tools">
|
||
<link rel="next" href="indexs07.html" title="Basic Functions">
|
||
</head>
|
||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||
<div class="navheader">
|
||
<table width="100%" summary="Navigation header">
|
||
<tr><th colspan="3" align="center">Tasks</th></tr>
|
||
<tr>
|
||
<td width="20%" align="left">
|
||
<a href="indexs05.html">Prev</a> </td>
|
||
<th width="60%" align="center"> </th>
|
||
<td width="20%" align="right"> <a href="indexs07.html">Next</a>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
<hr>
|
||
</div>
|
||
<div class="sect1">
|
||
<a name="tasks"></a><div class="titlepage"><div><h2 class="title" style="clear: both">
|
||
<a name="tasks"></a>Tasks</h2></div></div>
|
||
<p>This chapter provides descriptions of some common kernel related tasks.</p>
|
||
<div class="sect2">
|
||
<a name="generalkernel"></a><div class="titlepage"><div><h3 class="title">
|
||
<a name="generalkernel"></a>General Kernel</h3></div></div>
|
||
<p>The information in this section is a summary of <a href="http://www.linuxdoc.org/HOWTO/Kernel-HOWTO.html" target="_top">the kernel-HOWTO</a>
|
||
</p>
|
||
<div class="sect3">
|
||
<a name="compilekernel"></a><div class="titlepage"><div><h4 class="title">
|
||
<a name="compilekernel"></a>Kernel Compilation and Installation</h4></div></div>
|
||
<p>This section briefly outlines the procedure for generating a bootable kernel image from source code.</p>
|
||
<div class="itemizedlist"><ul>
|
||
<li><p>
|
||
<a name="id46573217"></a>Unpack the source code: <b>tar xIvf linux-2.4.16 -C /usr/src</b>.</p></li>
|
||
<li><p>
|
||
<a name="id46573227"></a><b>make config</b> and answer the list of questions with "y" to build an option into the kernel, "n" to leave it out and "m" to build it as a module. "?" gets you help on most options.</p></li>
|
||
<li><p>
|
||
<a name="id46573235"></a>Review the <tt>.config</tt> file found in the top level source directory and change as necessary.</p></li>
|
||
<li><p>
|
||
<a name="id46573244"></a><b>make bzImage modules</b>
|
||
</p></li>
|
||
<li><p>
|
||
<a name="id46573250"></a>Become root and <b>make modules_install</b>
|
||
</p></li>
|
||
<li><p>
|
||
<a name="id46573257"></a>Copy <tt>System.map</tt> to <tt>/boot/System-2.4.14.map</tt>
|
||
</p></li>
|
||
<li><p>
|
||
<a name="id46573268"></a>Copy <tt>~/arch/i386/boot/bzImage</tt> to <tt>/boot/bzImage-2.4.14</tt> (or whatever kernel version you are using).</p></li>
|
||
<li><p>
|
||
<a name="id46573280"></a>Edit <tt>/etc/lilo.conf</tt> and add a new entry for your new image, using one of the existing ones as a template. Keep at least one of the old entries in case the new kernel does not boot.</p></li>
|
||
<li><p>
|
||
<a name="id46573290"></a>Run <b>/sbin/lilo</b>, as root.</p></li>
|
||
<li><p>
|
||
<a name="id46573298"></a>Shutdown and reboot, be sure to select your new kernel at the boot loader prompt, if you did not set it up to boot by default.</p></li>
|
||
<li><p>
|
||
<a name="id46573303"></a>Enjoy the new kernel!</p></li>
|
||
</ul></div>
|
||
<p>Note that you can set the default kernel for the next reboot only by re-running lilo with the <b>-R</b> switch followed by the appropriate image label.</p>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<a name="generalhacking"></a><div class="titlepage"><div><h3 class="title">
|
||
<a name="generalhacking"></a>General Hacking</h3></div></div>
|
||
<p>This section is still very incomplete...</p>
|
||
<div class="sect3">
|
||
<a name="printk"></a><div class="titlepage"><div><h4 class="title">
|
||
<a name="printk"></a>Print messages to kernel logs</h4></div></div>
|
||
<p>The <tt>printk()</tt> function can be used to output tracing/debugging info to the kernel logs.</p>
|
||
</div>
|
||
<div class="sect3">
|
||
<a name="newmodule"></a><div class="titlepage"><div><h4 class="title">
|
||
<a name="newmodule"></a>Creating a new module</h4></div></div>
|
||
<p>See forthcoming revised <a href="http://www.dirac.org/linux/writing/" target="_top">Linux Module Programming Guide</a>.</p>
|
||
</div>
|
||
<div class="sect3">
|
||
<a name="configoptions"></a><div class="titlepage"><div><h4 class="title">
|
||
<a name="configoptions"></a>Configuration options</h4></div></div>
|
||
<p>The easiest way to add boot time options is to find the existing kernel option that matches your requirements most closely and copy that. Take a look at and edit the Config.in file in the associated directory. Then surround your option specific code with inclusion guards.</p>
|
||
</div>
|
||
<div class="sect3">
|
||
<a name="bootparams"></a><div class="titlepage"><div><h4 class="title">
|
||
<a name="bootparams"></a>Boot time parameters</h4></div></div>
|
||
<p>It is possible to pass information to the kernel at boot time in the form of command line options. For information about the current list of options, see <tt>~/Documentation/kernel-parameters.txt</tt> and the <a href="http://www.linuxdoc.org/HOWTO/BootPrompt-HOWTO.html" target="_top">Linux BootPrompt-HOWTO</a>.</p>
|
||
<p>Some drivers make use of this facility to set base addresses where hardware auto-detection is not possible or not implemented. Boot time parameters are especially useful when drivers or features are compiled into the kernel and not as a module, where options can be given when the module is loaded.</p>
|
||
<p>At version 2.3.13 the kernel initialisation code changed significantly for the better. Previously, the initialisation code was covered in <tt>#ifdef SOME_CONFIG_OPTION</tt> statements, to ensure only the required initialisation code is compiled into the final image. Now a different approach is taken, known as "init calls", where the initialisation functions are registered and stored in a special location in the ELF executable format. At system start up, each of the registered functions is called in turn (although it is not possible to specify the order of execution, so some <tt>#ifdef</tt> statements remain).</p>
|
||
<p>A similar approach is used to parse boot time options. To associate a particular boot time string with its own handling function, a call is made to <tt>__setup()</tt>. This could be done from <tt>~/init/main.c</tt>.</p>
|
||
<p>For example, to add support for a command line option <b>uptime</b>, which sets initial uptime to a specified number of jiffies:</p>
|
||
<pre class="programlisting">
|
||
static int __init riguptime(char *line){
|
||
jiffies = simple_strtol(line, (char **)(line + sizeof(line)), (unsigned int)10);
|
||
return 0;
|
||
}
|
||
|
||
__setup("uptime=", riguptime);
|
||
</pre>
|
||
<p>So if the kernel was booted with <b>uptime=12345</b> as a command line option, <tt>*line</tt> (passed to <tt>riguptime()</tt>) would point to a null-terminated string containing "12345". This string is converted to a value of type long by the <tt>simple_strtol()</tt> macro.</p>
|
||
</div>
|
||
<div class="sect3">
|
||
<a name="syscall"></a><div class="titlepage"><div><h4 class="title">
|
||
<a name="syscall"></a>Adding a system call</h4></div></div>
|
||
<p>It should be possible to do just about everything you could need to without doing this. Really.</p>
|
||
<p>OK so you <i>still</i> want to? ("Don't try this at home kids!")</p>
|
||
<p>See <a href="http://fossil.wpi.edu/docs/howto_add_systemcall.html" target="_top">this tutorial</a> (but needs adapting for 2.4.x).</p>
|
||
</div>
|
||
<div class="sect3">
|
||
<a name="procentry"></a><div class="titlepage"><div><h4 class="title">
|
||
<a name="procentry"></a>Add a /proc entry</h4></div></div>
|
||
<p>One of the ways to avoid adding another system call is to use the <tt>/proc</tt> interface. This section will describe a simple example.</p>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<a name="bughunting"></a><div class="titlepage"><div><h3 class="title">
|
||
<a name="bughunting"></a>Bug Hunting</h3></div></div>
|
||
<p>The scenario: You have just upgraded to the latest and greatest kernel, only to find it Oopses on your machine. The Linux-Kernel mailing list gets several posts a day along the lines of "2.4.xx" oopses/fails to boot. What is wrong?" Most of these posts never get answered, sometimes even the ones with a little more information (including the dreaded <tt>.config</tt> file) get no response.</p>
|
||
<p>Generally, the posts that do get answered and resolved are those where the user has done some "home work" and is some way towards locating the problem.</p>
|
||
<p>So where do you start with tracking down the problem?</p>
|
||
<p>For now, see <tt>Documentation/BUG-HUNTING</tt> until this section gets finished.</p>
|
||
</div>
|
||
</div>
|
||
<div class="navfooter">
|
||
<hr>
|
||
<table width="100%" summary="Navigation footer">
|
||
<tr>
|
||
<td width="40%" align="left">
|
||
<a href="indexs05.html">Prev</a> </td>
|
||
<td width="20%" align="center"><a href="index.html">Home</a></td>
|
||
<td width="40%" align="right"> <a href="indexs07.html">Next</a>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td width="40%" align="left">Tools </td>
|
||
<td width="20%" align="center"><a href="index.html">Up</a></td>
|
||
<td width="40%" align="right"> Basic Functions</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
</body>
|
||
</html>
|