About me

我的相片
I'm a web and software developer from Kaohsiung, Taiwan.
I design and implement user interfaces, also contribute to open source projects.
http://penkia.net/portfolio

2008年10月20日 星期一

ko2config.pl 和後續

幾個月前我寫了一隻 write once, run once 的 perl script, 用來把系統中的 kernel module 轉成 config 檔.
#!/usr/bin/perl
# ko2config.pl - convert *.ko to CONFIG

# set your kernel and source path here
chomp($path = "/lib/modules/".`uname -r`);
$k_path = "linux-source-2.6.24";

# get modules list from system
my @list = `find $path/kernel | grep ko`;

for (@list) {
# obtain file name
chomp($a = (split/\//, $_)[-1]);
print "$a = ";

# find CONFIG_* via Makefile
$a =~ s/\.ko$/.o/;
$lconfig = `grep '+= $a' -R $k_path`;
$config = "CONFIG_$1" if $lconfig =~ /CONFIG_(.*)[)] \+=/;

print $config, "\n";}

剛剛看到 LKML 上一篇 Script to build-in used modules, based on streamline_config.pl 在做類似的事情.
The aim of this is to provide a semi-automatic method to produce a custom kernel that has everything needed for your hardware built in, so you don't need an initrd.
非常有趣. 只能說 Linux kernel 的 Makefile 博大精深, 沒有這麼簡單阿. XD

沒有留言: