<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>andreas.goelzer.de &#187; kernel</title>
	<atom:link href="http://andreas.goelzer.de/tag/kernel/feed" rel="self" type="application/rss+xml" />
	<link>http://andreas.goelzer.de</link>
	<description>Electronics and small programs and other stuff</description>
	<lastBuildDate>Tue, 29 Nov 2011 21:08:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>kernel config based on lsmod output</title>
		<link>http://andreas.goelzer.de/kernel-config-based-on-lsmod-output</link>
		<comments>http://andreas.goelzer.de/kernel-config-based-on-lsmod-output#comments</comments>
		<pubDate>Mon, 06 Oct 2008 11:35:20 +0000</pubDate>
		<dc:creator>Andreas Goelzer</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://andreas.goelzer.de/?p=23</guid>
		<description><![CDATA[Update (October 7th, 2011): Kernels from 2.6.32 onwards should have the option to &#8220;make localmodconfig&#8221; and &#8220;make localyesconfig&#8221;. This post describes a dirty hack to get a result similar to &#8220;make localyesconfig&#8221;. If possible, use the official way instead of &#8230; <a href="http://andreas.goelzer.de/kernel-config-based-on-lsmod-output">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><b>Update (October 7th, 2011):</b> <i>Kernels from 2.6.32 onwards should have the option to &#8220;make localmodconfig&#8221; and &#8220;make localyesconfig&#8221;. This post describes a dirty hack to get a result similar to &#8220;make localyesconfig&#8221;. If possible, use the official way instead of my python script.</i></p>
<p>After reading about the amazing <a href="http://lwn.net/Articles/299483/">5-seconds bootup</a> I decided to once again compile a kernel myself. Compiling a kernel is almost trivial these days, but customizing the configuration can still be quite confusing. For example, the names of the modules in lsmod aren&#8217;t the ones you select as config options. To map them, I found some scripts in the <a href="http://wiki.linuxquestions.org/wiki/Configuring_linux_kernel">LQWiki</a>, but they weren&#8217;t that easily to use, and also programming in bash is just painful.</p>
<p>So i wrote a python variant, that takes an input config(for example your distributions config) and changes the reply to &#8220;y&#8221; for all config options if the respective module is loaded(ie. if ext3 is loaded, CONFIG_EXT3_FS=y will be set).</p>
<p>In almost all cases you still want to tweak the resulting config file with make menuconfig. Also keep in mind that some things don&#8217;t work that easily if compiled in, for example if firmware has to be loaded from a file, the disk should be accessible.<br />
<pre lang="python" line="1">#!/usr/bin/python
# -*- coding: utf-8 -*-
&quot;&quot;&quot;
Script to modify kernel config based on lsmod output
Copyright (C) 2008  Andreas Goelzer
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 
 
Based on a previous config and the output of lsmod, this script determines
which modules could be compiled in and generates a new config.
See http://andreas.goelzer.de/kernel-config-based-on-lsmod-output for updates
&quot;&quot;&quot;

import re;
from optparse import OptionParser;
from os import popen;
from sys import stderr, stdout, stdin;

parser = OptionParser(version=&quot;%prog 0.31&quot;);
parser.add_option(&quot;-i&quot;, &quot;--infile&quot;, dest=&quot;cfgfile&quot;,
                  help=&quot;input config file&quot;, default=&quot;.config&quot;, metavar=&quot;FILE&quot;);
parser.add_option(&quot;-o&quot;, &quot;--outfile&quot;, dest=&quot;outfile&quot;,
                  help=&quot;output config file&quot;, default=&quot;-&quot;, metavar=&quot;FILE&quot;);
parser.add_option(&quot;-l&quot;, &quot;--logfile&quot;, dest=&quot;logfile&quot;,
                  help=&quot;file to log errors to&quot;, default=&quot;-&quot;, metavar=&quot;FILE&quot;);
parser.add_option(&quot;-s&quot;, &quot;--sourcedir&quot;, dest=&quot;sourcedir&quot;,
                  help=&quot;kernel source tree&quot;, default=&quot;.&quot;, metavar=&quot;DIR&quot;);
#parser.add_option(&quot;-v&quot;, &quot;--verbose&quot;,
                  #action=&quot;store_true&quot;, dest=&quot;verbose&quot;, default=False,
                  #help=&quot;print debug messages&quot;);

(options, args) = parser.parse_args();
if(options.outfile == '-'): of = stdout;
else: of = open(options.outfile, 'w');
if(options.logfile != '-'): stderr = open(options.logfile, 'w');


loadedmods=popen('lsmod | tail -n+2').readlines();
getmodname=re.compile(r&quot;^(?P&lt;modname&gt;\w*)&quot;);

#prob. need to replace kernel with sth. like (kernel|ubuntu) for an ubuntu kernel source
parsepath=re.compile(r&quot;/kernel(?P&lt;path&gt;/.*/)(?P&lt;file&gt;.*).ko&quot;)

wantin=[];
for module in loadedmods:
	modname = re.search(getmodname,module).group('modname');
	moduleprops=re.search(parsepath,popen('modinfo -n ' + modname).read());
	if(moduleprops):
		#search the makefile for the module name
		try:
			f=open(options.sourcedir + moduleprops.group('path') + 'Makefile' , 'r');
		except IOError:
			stderr.write('Could not find Makefile for ' + modname + '\n');
			continue
		cont=f.read();
		f.close();
		m=re.search(r&quot;obj-\$\((?P&lt;cfgname&gt;[A-Z0-9_]*)\)\W*\+=\W*&quot;+moduleprops.group('file')+r&quot;\.o&quot;,cont);
		if(m):wantin.append(m.group('cfgname'));
		else:stderr.write('Could not determine config name for ' + modname + '\n');
	else:
		stderr.write('Could not parse modinfo for ' + modname + '\n');



if(options.cfgfile != '-'): 
	f=open(options.cfgfile, 'r');
	lines=f.readlines();
	f.close();
else:
	lines=stdin.readlines();

confparse = re.compile(r&quot;\W*(?P&lt;iscomment&gt;#?)\W*(?P&lt;cfgname&gt;CONFIG_[A-Z0-9_]*)\W*=?\W*(?P&lt;answer&gt;[nmy]?)&quot;);

for line in lines:
	matches = re.search(confparse,line);
	if(matches and matches.group('cfgname') in wantin): 
		of.write(matches.group('cfgname')+'=y\n');
	else: 
		#if(matches and matches.group('answer') == 'm'):of.write(matches.group('cfgname')+'=n\n');
		of.write(line);</pre><hr /><a href='http://andreas.goelzer.de/download/customconfig.py'><img src="http://andreas.goelzer.de/wp-content/plugins/kfile/fileicons/file-source-alt.png" width="16" height="16" alt="filetype" class="icon16" /> customconfig.py</a> (3.41 kiB, 2009-05-19)<br/><hr /></p>
<p>To use the script, call it for example like <code>./customconfig.py -i /boot/config-2.6.24-21-generic -o .config</code> if it is located in a linux kernel directory. Then modify the resulting config to suit your needs with <code>make menuconfig</code>, and then you can proceed to compile your kernel.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreas.goelzer.de/kernel-config-based-on-lsmod-output/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 3/8 queries in 0.028 seconds using disk: basic
Object Caching 227/234 objects using disk: basic

Served from: andreas.goelzer.de @ 2012-02-05 04:55:38 -->
