mtd/patches patchin.sh,1.30,1.31

Artem Bityuckiy dedekind at infradead.org
Sat Dec 11 12:06:51 EST 2004


Update of /home/cvs/mtd/patches
In directory phoenix.infradead.org:/tmp/cvs-serv28719

Modified Files:
	patchin.sh 
Log Message:
Update the script to support JFFS3. Make some additional cleanups.


Index: patchin.sh
===================================================================
RCS file: /home/cvs/mtd/patches/patchin.sh,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- patchin.sh	20 Nov 2004 08:47:31 -0000	1.30
+++ patchin.sh	11 Dec 2004 17:06:49 -0000	1.31
@@ -23,6 +23,7 @@
 #
 # $Id$
 #
+# 09-12-2004 dedekind add JFFS3 installing capability, reformat, clean-up
 # 24-05-2004 havasi Patch fs/Kconfig
 # 05-05-2004 tglx Include include/mtd
 # 12-06-2003 dwmw2 Leave out JFFS1, do Makefile.common only if it exists.
@@ -31,8 +32,240 @@
 # 03-08-2003 tglx -c option for copying files to kernel tree instead of linking
 #		  moved file selection to variables
 
+
+# 
+# Finds the first and last lines numbers of block of Kconfig file entries
+# containing pattern $2. $1 contains the file name where to search for.
+#
+# Returns the result in FIRSLINE and LASTLINE variables.
+#
+function find_lines () {
+	# find the line number of the first and the last $2 entries
+	FIRSTLINE=`grep -m1 -n $2 $1 | sed -e 's/:.*//'`;
+	if [ "x$FIRSTLINE" = "x" ]; then
+		FIRSTLINE=0;
+		LASTLINE=0;
+		return 0;
+	fi;
+	LASTLINE=`grep -n $2 $1 | sed -n -e '$s/:.*// p'`;
+	let LASTLINE=$LASTLINE+1;
+	LASTLINEADD=`sed -n $1 -e "$LASTLINE,$ p" | sed -n -e '/^\(choice\)\|\(config\)\|\(menu\)\s*/{=; q}'`;
+	if [ "x$LASTLINEADD" = "x" ]; then
+		let LASTLINEADD=`cat $1 | wc -l`-$LASTLINE+2;
+	fi;
+	let LASTLINE=$LASTLINE+$LASTLINEADD-2;
+}
+
+#
+# Patch the Kconfig file. Helper function for patch_Kconfig ().
+# 
+# Function requires the following positional parameters:
+# 
+# $1:	the path to the input Kconfig file from which the function
+#	should fetch new the Kconfig entries;
+# $2:	the path to the target linux Kconfig file which should be
+#	patched; if the parameter value is '', just insert to the end of
+#	the target Kconfig file;
+# $3:	the line number of the first entry in the in the input file;
+# $4:	the line number of the last line in the input file;
+# $5:	the menu name in target Kconfig file where the new entries should
+#	be added.
+#
+function do_patch_Kconfig () {
+	local INFILE=$1;
+	local OUTFILE=$2;
+	local FIRSTLINE=$3;
+	local LASTLINE=$4;
+	local MENUNAME=$5;
+
+	# read the entries from the input file
+	local ENTRIES=`sed -n "$INFILE" -e "$FIRSTLINE,$LASTLINE p"`;
+
+	# determine the menu line number
+	local MENULINE='';
+	local TOTALOUT=`cat $OUTFILE | wc -l`;
+	if [ "x$MENUNAME" != "x" ]; then
+		MENULINE=`grep menu $OUTFILE | grep -m1 -n "$MENUNAME" $OUTFILE | sed -e 's/:.*//'`;
+	else
+		let MENULINE=$TOTALOUT;
+	fi;
+	
+	# copy lines 0-MENULINE from the target file to the temporary file
+	TMPFILE="Kconfig.$$";
+	sed -n "$OUTFILE" -e "0,$MENULINE p" > $TMPFILE;
+	echo >> $TMPFILE;
+	# append our lines
+	sed -n "$INFILE" -e "$FIRSTLINE,$LASTLINE p" >> $TMPFILE;
+	# append lines MENULINE+1-TOTALOUT from the target files to the temporary file
+	if [ $MENULINE -ne $TOTALOUT ]; then
+		let MENULINE=$MENULINE+1;
+		sed -n "$OUTFILE" -e "$MENULINE,$TOTALOUT p" >> $TMPFILE;
+	fi;
+	# replace the target file by the temporary which now contains our entries
+	mv $TMPFILE $OUTFILE;
+
+	return 0;
+}
+
+#
+# Patch the Kconfig file. This function assubes that there is some input Kconfig file
+# (on placed in mtd) containing, among other, a block of continguous entries for
+# some subsystem # (JFFS2, etc). Function reads this block and inserts it to the
+# target Kconfig file (in Linux sources). Before inserting it removes older entries
+# from the target Kconfig.
+#
+# Input positional parameters:
+# 
+# $1:	the path to the input Kconfig file from which the function
+#	should fetch new the Kconfig entries;
+# $2:	the path to the target linux Kconfig file which should be
+#	patched; if the parameter value is '', just insert to the end of
+#	the target Kconfig file;
+# $3:	The patched subsystem name;
+# $4:	the pattern in the target Kconfig file after which the new entries should
+#	be inserted.
+# 
+function patch_Kconfig () {
+	local INFILE=$1;
+	local OUTFILE=$2
+	local SUBSYS=$3;
+	local MENUNAME=$4;
+	
+	if [ ! -f $INFILE ] || [ ! -r $INFILE ]; then
+		echo -n "Error: the proper input file $INFILE does not exist";
+		return 1;
+	fi;
+	
+	if [ ! -f $OUTFILE ] || [ ! -r $OUTFILE ] || [ ! -w $OUTFILE ]; then
+		echo -n "Error: the proper output Kconfig file $INFILE does not exist";
+		return 1;
+	fi;
+
+	find_lines $OUTFILE "$SUBSYS";
+	if [ $FIRSTLINE -gt $LASTLINE ]; then
+		# Bug in find_lines function. Fix it.
+		echo -n "Internal error: last > first";
+		return 1;
+	fi;
+	local TOTALIN=`cat $OUTFILE | wc -l`;
+	if [ $LASTLINE -gt $TOTALIN ]; then
+		# Bug in find_lines function. Fix it.
+		echo -n "Internal error: last > total";
+		return 1;
+	fi;
+	
+	# remove older PATTERN-related entries from Kconfig
+	TMPFILE=$OUTFILE.$$;
+	if [ $LASTLINE -ne "0" ]; then
+		cat $OUTFILE | sed -n -e "$FIRSTLINE,$LASTLINE ! p" > $TMPFILE;
+		mv $TMPFILE $OUTFILE;
+	fi;
+
+	find_lines "$INFILE" "$SUBSYS";
+	if [ $FIRSTLINE -gt $LASTLINE ]; then
+		# Bug in find_lines function. Fix it.
+		echo -n "Internal error: last > first";
+		return 1;
+	fi;
+	local TOTALIN=`cat $INFILE | wc -l`;
+	if [ $LASTLINE -gt $TOTALIN ]; then
+		# Bug in find_lines function. Fix it.
+		echo -n "Internal error: last > total";
+		return 1;
+	fi;
+	do_patch_Kconfig $INFILE $OUTFILE $FIRSTLINE $LASTLINE $MENUNAME;
+}
+
+#
+# Patch old kernels with JFFS/JFFS2 filesystems
+# 
+function legacy_fs_patch () {
+	local PATCHDONE=`grep -s jffs2 fs/Makefile | head -n 1`
+	if [ "$PATCHDONE" = "" ]; then
+		echo "Add JFFS2 to Makefile and Config.in manually. JFFS2 is included as of 2.4.12"
+		return 0;
+	fi;
+	
+	local JFFS=`grep -n JFFS fs/Config.in | grep -v JFFS3 | head -n 1 | sed s/:.*//`
+	local CRAMFS=`grep -n CRAMFS fs/Config.in | head -n 1 | sed s/:.*//`
+	let JFFS=JFFS-1
+	let CRAMFS=CRAMFS-1
+	sed "$JFFS"q fs/Config.in >Config.tmp
+	cat $TOPDIR/fs/Config.in >>Config.tmp
+	sed 1,"$CRAMFS"d fs/Config.in >>Config.tmp
+	mv -f Config.tmp fs/Config.in
+	
+	if [ -f include/linux/crc32.h ] 
+	then
+		# check, if it is already defined there
+		local CRC32=`grep -s 'crc32(' include/linux/crc32.h | head -n 1`
+		if [ "$CRC32" = "" ]
+		then
+			# patch in header from fs/jffs2
+			local LASTLINE=`grep -n '#endif' include/linux/crc32.h | head -n 1 | sed s/:.*//`
+			let LASTLINE=LASTLINE-1
+			sed "$LASTLINE"q include/linux/crc32.h >Crc32.tmp
+			cat fs/jffs2/crc32.h >>Crc32.tmp
+			echo "#endif" >>Crc32.tmp
+			mv -f Crc32.tmp include/linux/crc32.h
+		fi
+	else
+		rm -f include/linux/crc32.h
+		$LNCP $TOPDIR/fs/jffs2/crc32.h include/linux
+	fi
+}
+
+#
+# Display usage of this script
+#
+usage () {
+	echo "usage:  $0 [-c] [-j] kernelpath"
+	echo "   -c  -- copy files to kernel tree instead of building links"
+	echo "   -j  -- include JFFS2 file system (depricated option)" 
+	echo "   -2  -- include JFFS2 file system"
+	echo "   -3  -- include JFFS3 file system (experimental, you probably don't want this)"
+	echo "   -b  -- Check files out for write from BK" 
+	exit 1
+}
+
+# Function to patch kernel source
+function patchit () {
+	for DIR in $PATCH_DIRS 
+	do
+		echo $DIR
+		mkdir -p $DIR
+		cd $TOPDIR/$DIR
+		FILES=`ls $PATCH_FILES 2>/dev/null`
+		if [ "$BK" = "yes" -a -d $LINUXDIR/$DIR/SCCS ]; then
+		    pushd $LINUXDIR/$DIR
+		    rm -f $FILES
+		    bk co -ql $FILES
+		    popd
+		fi
+		for FILE in $FILES 
+		do
+			# If there's a Makefile.common it goes in place of Makefile
+			if [ "$FILE" = "Makefile" -a -r $TOPDIR/$DIR/Makefile.common ]; then
+			    if test $PATCHLEVEL -lt 5; then
+				rm -f $LINUXDIR/$DIR/Makefile.common 2>/dev/null
+				$LNCP $TOPDIR/$DIR/Makefile.common $LINUXDIR/$DIR/Makefile.common
+				SRCFILE=Makefile.24
+			    else
+				SRCFILE=Makefile.common
+			    fi
+			else
+			    SRCFILE=$FILE
+			fi
+			rm -f $LINUXDIR/$DIR/$FILE 2>/dev/null
+			$LNCP $TOPDIR/$DIR/$SRCFILE $LINUXDIR/$DIR/$FILE
+		done
+		cd $LINUXDIR
+	done	
+}
+
 # Preset variables
-FILESYSTEMS="no"
+JFFS2_FS="no"
+JFFS3_FS="no"
 BK="no"
 VERSION=0
 PATCHLEVEL=0
@@ -44,21 +277,20 @@
 LNCP="ln -sf"
 METHOD="Link"
 
-
 # MTD - files and directories
 MTD_DIRS="drivers/mtd drivers/mtd/chips drivers/mtd/devices drivers/mtd/maps drivers/mtd/nand include/linux/mtd include/mtd"
 MTD_FILES="*.[ch] Makefile Rules.make"
 
 # JFFS2 files and directories
-FS_DIRS="fs/jffs2"
-FS_FILES="*.[ch] Makefile Rules.make"
+JFFS2_DIRS="fs/jffs2"
+JFFS2_FILES="*.[ch] Makefile Rules.make"
 # kernel version < 2.4.20 needs zlib headers
-FS_INC_BEL2420="jffs*.h workqueue.h z*.h rb*.h suspend.h"
+JFFS2_INC_BEL2420="jffs*.h workqueue.h z*.h rb*.h suspend.h"
 # kernel version < 2.5.x
-FS_INC_BEL25="jffs2*.h workqueue.h rb*.h suspend.h"
+JFFS2_INC_BEL25="jffs2*.h workqueue.h rb*.h suspend.h"
 # kernelversion >= 2.5
-FS_INC_25="jffs2*.h"
-FS_INC_DIR="include/linux"
+JFFS2_INC_25="jffs2*.h"
+JFFS2_INC_DIR="include/linux"
 
 # shared ZLIB patch
 ZLIB_DIRS="lib/zlib_deflate lib/zlib_inflate"
@@ -68,66 +300,32 @@
 RSLIB_FILES="*.[ch]"
 RSLIB_INC_DIR="include/linux"
 RSLIB_INC="rslib.h"
+
 # Documentation
 DOC_DIRS="Documentation/DocBook"
 DOC_FILES="*.tmpl"
 
+# Experimental stuff
+JFFS3_DIRS="fs/jffs3"
+JFFS3_FILES="*.[ch] Makefile Rules.make"
+JFFS3_INC="jffs3*.h"
+JFFS3_INC_DIR="include/linux"
+
 # Make text utils not suck
 export LANG=C
 export LC_ALL=C
 
-# Display usage of this script
-usage () {
-	echo "usage:  $0 [-c] [-j] kernelpath"
-	echo "   -c  -- copy files to kernel tree instead of building links"
-	echo "   -j  -- include jffs2 filesystem" 
-	echo "   -b  -- Check files out for write from BK" 
-	exit 1
-}
-
-# Function to patch kernel source
-patchit () {
-for DIR in $PATCH_DIRS 
-do
-	echo $DIR
-	mkdir -p $DIR
-	cd $TOPDIR/$DIR
-	FILES=`ls $PATCH_FILES 2>/dev/null`
-	if [ "$BK" = "yes" -a -d $LINUXDIR/$DIR/SCCS ]; then
-	    pushd $LINUXDIR/$DIR
-	    rm -f $FILES
-	    bk co -ql $FILES
-	    popd
-	fi
-	for FILE in $FILES 
-	do
-		# If there's a Makefile.common it goes in place of Makefile
-		if [ "$FILE" = "Makefile" -a -r $TOPDIR/$DIR/Makefile.common ]; then
-		    if test $PATCHLEVEL -lt 5; then
-			rm -f $LINUXDIR/$DIR/Makefile.common 2>/dev/null
-			$LNCP $TOPDIR/$DIR/Makefile.common $LINUXDIR/$DIR/Makefile.common
-			SRCFILE=Makefile.24
-		    else
-			SRCFILE=Makefile.common
-		    fi
-		else
-		    SRCFILE=$FILE
-		fi
-		rm -f $LINUXDIR/$DIR/$FILE 2>/dev/null
-		$LNCP $TOPDIR/$DIR/$SRCFILE $LINUXDIR/$DIR/$FILE
-	done
-	cd $LINUXDIR
-done	
-}
-
-
+#
 # Start of script
+#
 
 # Get commandline options
-while getopts cjb opt
+while getopts cjb23 opt
 do
     case "$opt" in
-      j)  FILESYSTEMS=yes;;
+      j)  JFFS2_FS=yes;;
+      2)  JFFS2_FS=yes;;
+      3)  JFFS3_FS=yes;;
       c)  LNCP="cp -f"; METHOD="Copy";;
       b)  BK=yes;;
       \?)
@@ -174,7 +372,7 @@
 MTD_FILES="$MTD_FILES $CONFIG"
 
 # Have we to use ZLIB PATCH ? 
-if [ "$FILESYSTEMS" = "yes" ]
+if [ "$JFFS2_FS" = "yes" ]
 then
 	PATCHDONE=`grep -s zlib_deflate $LINUXDIR/lib/Makefile | head -n 1`
 	if test $PATCHLEVEL -eq 4 -a $SUBLEVEL -lt 20 
@@ -205,26 +403,34 @@
 
 # Check which header files we need depending on kernel version
 HDIR="include/linux"
+
+if test $JFFS3_FS -eq 'yes' && test $PATCHLEVEL -lt 6
+then
+	echo "JFFS3 works only with >= 2.6 kernels"
+	exit 1
+fi;
+
 if test $PATCHLEVEL -eq 4 
 then	
 	# 2.4 below 2.4.20 zlib headers are neccecary
 	if test $SUBLEVEL -lt 20
 	then
-		JFFS2_H=$FS_INC_BEL2420
+		JFFS2_H=$JFFS2_INC_BEL2420
 	else
-		JFFS2_H=$FS_INC_BEL25
+		JFFS2_H=$JFFS2_INC_BEL25
 	fi
 else
 	#	>= 2.5
-	JFFS2_H=$FS_INC_25
+	JFFS2_H=$JFFS2_INC_25
 fi
 
-echo Patching $LINUXDIR 
-echo Include Filesytems: $FILESYSTEMS
-echo Zlib-Patch needed: $ZLIBPATCH
-echo RS-Lib-Patch needed: $RSLIBPATCH
-echo Documentation Patch needed: $DOCPATCH
-echo Method: $METHOD
+echo "Patching $LINUXDIR"
+echo "Include JFFS2 file system: $JFFS2_FS"
+echo "Include JFFS3 file system (experimental): $JFFS3_FS"
+echo "Zlib-Patch needed: $ZLIBPATCH"
+echo "RS-Lib-Patch needed: $RSLIBPATCH"
+echo "Documentation Patch needed: $DOCPATCH"
+echo "Method: $METHOD"
 read -p "Can we start now ? [y/N]" ANSWER
 echo ""
 
@@ -248,68 +454,20 @@
 PATCH_FILES=$MTD_FILES
 patchit;
 
-# check, if we have to include JFFS(2)
-if [ "$FILESYSTEMS" = "yes" ]
-then
-	echo "Patching JFFS(2)"
-	
-	PATCH_DIRS=$FS_DIRS
-	PATCH_FILES=$FS_FILES
-	patchit;
-
-	PATCH_DIRS=$FS_INC_DIR
-	PATCH_FILES=$JFFS2_H
-	patchit;
-
-	# this is the ugly part	
-	PATCHDONE=`grep -s jffs2 fs/Makefile | head -n 1`
-	if [ "$PATCHDONE" = "" ]
-	then
-		echo "Add JFFS2 to Makefile and Config.in manually. JFFS2 is included as of 2.4.12"	
-	else
-		if test $PATCHLEVEL -lt 5
-		then
-			JFFS=`grep -n JFFS fs/Config.in | head -n 1 | sed s/:.*//`
-			CRAMFS=`grep -n CRAMFS fs/Config.in | head -n 1 | sed s/:.*//`
-			let JFFS=JFFS-1
-			let CRAMFS=CRAMFS-1
-			sed "$JFFS"q fs/Config.in >Config.tmp
-			cat $TOPDIR/fs/Config.in >>Config.tmp
-			sed 1,"$CRAMFS"d fs/Config.in >>Config.tmp
-			mv -f Config.tmp fs/Config.in
-			
-			if [ -f include/linux/crc32.h ] 
-			then
-				# check, if it is already defined there
-				CRC32=`grep -s 'crc32(' include/linux/crc32.h | head -n 1`
-				if [ "$CRC32" = "" ]
-				then
-					# patch in header from fs/jffs2
-					LASTLINE=`grep -n '#endif' include/linux/crc32.h | head -n 1 | sed s/:.*//`
-					let LASTLINE=LASTLINE-1
-					sed "$LASTLINE"q include/linux/crc32.h >Crc32.tmp
-					cat fs/jffs2/crc32.h >>Crc32.tmp
-					echo "#endif" >>Crc32.tmp
-					mv -f Crc32.tmp include/linux/crc32.h
-				fi
-			else
-				rm -f include/linux/crc32.h
-				$LNCP $TOPDIR/fs/jffs2/crc32.h include/linux
-			fi
-		
-                else
-			JFFS=`grep -n JFFS fs/Kconfig | head -n 1 | sed s/:.*//`
-			CRAMFS=`grep -n CRAMFS fs/Kconfig | head -n 1 | sed s/:.*//`
-			let JFFS=JFFS-1
-			let CRAMFS=CRAMFS-1
-			sed "$JFFS"q fs/Kconfig >Kconfig.tmp
-			cat $TOPDIR/fs/Kconfig >>Kconfig.tmp
-			sed 1,"$CRAMFS"d fs/Kconfig >>Kconfig.tmp
-			mv -f Kconfig.tmp fs/Kconfig
-                fi
+# some BUG() definitions were moved to asm/bug.h in the 2.5 kernels
+# so fake having one to avoid build errors.
+if test $PATCHLEVEL -lt 5; then
+	if [ ! -r $LINUXDIR/include/asm/bug.h ]; then
+		touch $LINUXDIR/include/asm/bug.h
 	fi
 fi
 
+if test $PATCHLEVEL -lt 5
+then 
+	# FIXME: SED/AWK experts should know how to do it automagic
+	echo "Please update Documentation/Configure.help from $TOPDIR/Documentation/Configure.help"
+fi
+
 if [ "$ZLIBPATCH" = "yes" ]
 then
 	echo "Patching ZLIB"
@@ -374,20 +532,41 @@
 PATCH_FILES=$DOC_FILES
 patchit;
 
+# check, if we have to include JFFS2
+if [ "$JFFS2_FS" = "yes" ]
+then
+	echo "Patching JFFS2"
+	
+	PATCH_DIRS=$JFFS2_DIRS
+	PATCH_FILES=$JFFS2_FILES
+	patchit;
 
-echo "Patching done"
+	PATCH_DIRS=$JFFS2_INC_DIR
+	PATCH_FILES=$JFFS2_H
+	patchit;
 
-# some BUG() definitions were moved to asm/bug.h in the 2.5 kernels
-#  so fake having one to avoid build errors.
-if test $PATCHLEVEL -lt 5; then
-	if [ ! -r $LINUXDIR/include/asm/bug.h ]; then
-		touch $LINUXDIR/include/asm/bug.h
-	fi
+	if test $PATCHLEVEL -lt 5; then 
+		legacy_fs_patch;
+	else
+		patch_Kconfig "$TOPDIR/fs/Kconfig" "fs/Kconfig" "JFFS2" "Miscellaneous filesystems";
+	fi;
 fi
 
-if test $PATCHLEVEL -lt 5
-then 
-	# FIXME: SED/AWK experts should know how to do it automagic
-	echo "Please update Documentation/Configure.help from $TOPDIR/Documentation/Configure.help"
+# check, if we have to include experimental stuff
+if [ "$JFFS3_FS" = "yes" ]
+then
+	echo "Patching JFFS3 (experimental)"
+	
+	PATCH_DIRS=$JFFS3_DIRS;
+	PATCH_FILES=$JFFS3_FILES;
+	patchit;
+
+	PATCH_DIRS=$JFFS3_INC_DIR;
+	PATCH_FILES=$JFFS3_INC;
+	patchit;
+	
+	patch_Kconfig "$TOPDIR/fs/Kconfig" "fs/Kconfig" "JFFS3" "Miscellaneous filesystems";
 fi
 
+echo "Patching done"
+





More information about the linux-mtd-cvs mailing list