SVN: geninitrd/trunk/geninitrd

glen glen at pld-linux.org
Fri May 21 16:23:13 CEST 2010


Author: glen
Date: Fri May 21 16:23:12 2010
New Revision: 11482

Modified:
   geninitrd/trunk/geninitrd
Log:
- extract CONFIG_BLK_DEV_RAM_SIZE from configs kernel module if possible
- based on extract-ikconfig from linux/scripts/extract-ikconfig

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Fri May 21 16:23:12 2010
@@ -270,6 +270,41 @@
 	fi
 }
 
+# extract-ikconfig - Extract the .config file from a kernel image
+#
+# The obscure use of the "tr" filter is to work around older versions of
+# "grep" that report the byte offset of the line instead of the pattern.
+#
+# (c) 2009, Dick Streefland <dick at streefland.net>
+# Licensed under the terms of the GNU General Public License.
+#
+# Ripped and adjusted for geninitrd from linux-2.6.34/scripts/extract-ikconfig
+extract-ikconfig() {
+	local img=$(mktemp)
+	local kofile=$(modinfo -k $kernel -n configs)
+	case "$kofile" in
+	'')
+		return
+		;;
+	*.gz)
+		gzip -dc "$kofile" > $img
+		;;
+	*)
+		cat "$kofile" > $img
+		;;
+	esac
+
+	local cf1='IKCFG_ST\037\213\010'
+	local cf2='0123456789'
+	local pos
+
+	if pos=$(tr "$cf1\n$cf2" "\n$cf2=" < "$img" | grep -abo "^$cf2"); then
+		pos=${pos%%:*}
+		tail -c+$(($pos+8)) "$img" | gzip -dcq
+	fi
+	rm -f $img
+}
+
 # Finds module dependencies
 #
 # @param	$module
@@ -1312,8 +1347,10 @@
 	die "Filesystem $INITRDFS not supported by $PROGRAM"
 esac
 
-# TODO: figure out this automatically
-CONFIG_BLK_DEV_RAM_SIZE=4096
+CONFIG_BLK_DEV_RAM_SIZE=$(extract-ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}')
+if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then
+	CONFIG_BLK_DEV_RAM_SIZE=4096
+fi
 
 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
 debug 	"image size: $IMAGESIZE KiB ($DESTDIR)"


More information about the pld-cvs-commit mailing list