VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   1) #! /bin/sh
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100   2) # SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   3) # Script to apply kernel patches.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   4) #   usage: patch-kernel [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   5) #     The source directory defaults to /usr/src/linux, and the patch
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   6) #     directory defaults to the current directory.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   7) # e.g.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   8) #   scripts/patch-kernel . ..
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   9) #      Update the kernel tree in the current directory using patches in the
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  10) #      directory above to the latest Linus kernel
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  11) #   scripts/patch-kernel . .. -ac
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  12) #      Get the latest Linux kernel and patch it with the latest ac patch
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  13) #   scripts/patch-kernel . .. 2.4.9
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  14) #      Gets standard kernel 2.4.9
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  15) #   scripts/patch-kernel . .. 2.4.9 -ac
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  16) #      Gets 2.4.9 with latest ac patches
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  17) #   scripts/patch-kernel . .. 2.4.9 -ac11
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  18) #      Gets 2.4.9 with ac patch ac11
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  19) #   Note: It uses the patches relative to the Linus kernels, not the
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  20) #   ac to ac relative patches
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  21) #
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  22) # It determines the current kernel version from the top-level Makefile.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  23) # It then looks for patches for the next sublevel in the patch directory.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  24) # This is applied using "patch -p1 -s" from within the kernel directory.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  25) # A check is then made for "*.rej" files to see if the patch was
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  26) # successful.  If it is, then all of the "*.orig" files are removed.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  27) #
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  28) #       Nick Holloway <Nick.Holloway@alfie.demon.co.uk>, 2nd January 1995.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  29) #
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  30) # Added support for handling multiple types of compression. What includes
38385f8f01803 (Masahiro Yamada    2014-04-28 16:26:18 +0900  31) # gzip, bzip, bzip2, zip, compress, and plaintext.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  32) #
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  33) #       Adam Sulmicki <adam@cfar.umd.edu>, 1st January 1997.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  34) #
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  35) # Added ability to stop at a given version number
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  36) # Put the full version number (i.e. 2.3.31) as the last parameter
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  37) #       Dave Gilbert <linux@treblig.org>, 11th December 1999.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  38) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  39) # Fixed previous patch so that if we are already at the correct version
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  40) # not to patch up.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  41) #
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  42) # Added -ac option, use -ac or -ac9 (say) to stop at a particular version
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  43) #       Dave Gilbert <linux@treblig.org>, 29th September 2001.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  44) #
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  45) # Add support for (use of) EXTRAVERSION (to support 2.6.8.x, e.g.);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  46) # update usage message;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  47) # fix some whitespace damage;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  48) # be smarter about stopping when current version is larger than requested;
f4b09ebc8baa5 (Adrian Bunk        2006-01-03 13:37:51 +0100  49) #	Randy Dunlap <rdunlap@xenotime.net>, 2004-AUG-18.
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  50) #
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  51) # Add better support for (non-incremental) 2.6.x.y patches;
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  52) # If an ending version number if not specified, the script automatically
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  53) # increments the SUBLEVEL (x in 2.6.x.y) until no more patch files are found;
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  54) # however, EXTRAVERSION (y in 2.6.x.y) is never automatically incremented
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  55) # but must be specified fully.
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  56) #
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  57) # patch-kernel does not normally support reverse patching, but does so when
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  58) # applying EXTRAVERSION (x.y) patches, so that moving from 2.6.11.y to 2.6.11.z
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  59) # is easy and handled by the script (reverse 2.6.11.y and apply 2.6.11.z).
f4b09ebc8baa5 (Adrian Bunk        2006-01-03 13:37:51 +0100  60) #	Randy Dunlap <rdunlap@xenotime.net>, 2005-APR-08.
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  61) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  62) PNAME=patch-kernel
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  63) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  64) # Set directories from arguments, or use defaults.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  65) sourcedir=${1-/usr/src/linux}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  66) patchdir=${2-.}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  67) stopvers=${3-default}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  68) 
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100  69) if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  70) cat << USAGE
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  71) usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  72)   source directory defaults to /usr/src/linux,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  73)   patch directory defaults to the current directory,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  74)   stopversion defaults to <all in patchdir>.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  75) USAGE
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  76) exit 1
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  77) fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  78) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  79) # See if we have any -ac options
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  80) for PARM in $*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  81) do
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  82)   case $PARM in
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  83) 	  -ac*)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  84) 		  gotac=$PARM;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  85) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  86) 	esac;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  87) done
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  88) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  89) # ---------------------------------------------------------------------------
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  90) # arg1 is filename
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  91) noFile () {
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  92) 	echo "cannot find patch file: ${patch}"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  93) 	exit 1
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  94) }
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  95) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  96) # ---------------------------------------------------------------------------
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  97) backwards () {
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  98) 	echo "$PNAME does not support reverse patching"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700  99) 	exit 1
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 100) }
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 101) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 102) # ---------------------------------------------------------------------------
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 103) # Find a file, first parameter is basename of file
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 104) # it tries many compression mechanisms and sets variables to say how to get it
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 105) findFile () {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 106)   filebase=$1;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 107) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 108)   if [ -r ${filebase}.gz ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 109) 		ext=".gz"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 110) 		name="gzip"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 111) 		uncomp="gunzip -dc"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 112)   elif [ -r ${filebase}.bz  ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 113) 		ext=".bz"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 114) 		name="bzip"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 115) 		uncomp="bunzip -dc"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 116)   elif [ -r ${filebase}.bz2 ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 117) 		ext=".bz2"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 118) 		name="bzip2"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 119) 		uncomp="bunzip2 -dc"
354fa22fce767 (Shawn Landden      2012-03-12 15:13:37 -0700 120)   elif [ -r ${filebase}.xz ]; then
354fa22fce767 (Shawn Landden      2012-03-12 15:13:37 -0700 121)                 ext=".xz"
354fa22fce767 (Shawn Landden      2012-03-12 15:13:37 -0700 122)                 name="xz"
354fa22fce767 (Shawn Landden      2012-03-12 15:13:37 -0700 123)                 uncomp="xz -dc"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 124)   elif [ -r ${filebase}.zip ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 125) 		ext=".zip"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 126) 		name="zip"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 127) 		uncomp="unzip -d"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 128)   elif [ -r ${filebase}.Z ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 129) 		ext=".Z"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 130) 		name="uncompress"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 131) 		uncomp="uncompress -c"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 132)   elif [ -r ${filebase} ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 133) 		ext=""
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 134) 		name="plaintext"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 135) 		uncomp="cat"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 136)   else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 137) 	return 1;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 138)   fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 139) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 140)   return 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 141) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 142) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 143) # ---------------------------------------------------------------------------
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 144) # Apply a patch and check it goes in cleanly
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 145) # First param is patch name (e.g. patch-2.4.9-ac5) - without path or extension
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 146) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 147) applyPatch () {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 148)   echo -n "Applying $1 (${name})... "
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 149)   if $uncomp ${patchdir}/$1${ext} | patch -p1 -s -N -E -d $sourcedir
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 150)   then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 151)     echo "done."
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 152)   else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 153)     echo "failed.  Clean up yourself."
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 154)     return 1;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 155)   fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 156)   if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 157)   then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 158)     echo "Aborting.  Reject files found."
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 159)     return 1;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 160)   fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 161)   # Remove backup files
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 162)   find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
38385f8f01803 (Masahiro Yamada    2014-04-28 16:26:18 +0900 163) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 164)   return 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 165) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 166) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 167) # ---------------------------------------------------------------------------
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 168) # arg1 is patch filename
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 169) reversePatch () {
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 170) 	echo -n "Reversing $1 (${name}) ... "
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 171) 	if $uncomp ${patchdir}/"$1"${ext} | patch -p1 -Rs -N -E -d $sourcedir
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 172) 	then
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 173) 		echo "done."
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 174) 	else
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 175) 		echo "failed.  Clean it up."
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 176) 		exit 1
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 177) 	fi
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 178) 	if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 179) 	then
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 180) 		echo "Aborting.  Reject files found."
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 181) 		return 1
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 182) 	fi
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 183) 	# Remove backup files
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 184) 	find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 185) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 186) 	return 0
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 187) }
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 188) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 189) # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 190) # force $TMPFILEs below to be in local directory: a slash character prevents
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 191) # the dot command from using the search path.
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 192) TMPFILE=`mktemp ./.tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 193) grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 194) tr -d [:blank:] < $TMPFILE > $TMPFILE.1
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 195) . $TMPFILE.1
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 196) rm -f $TMPFILE*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 197) if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 198) then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 199)     echo "unable to determine current kernel version" >&2
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 200)     exit 1
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 201) fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 202) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 203) NAME=`grep ^NAME $sourcedir/Makefile`
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 204) NAME=${NAME##*=}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 205) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 206) echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION} ($NAME)"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 207) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 208) # strip EXTRAVERSION to just a number (drop leading '.' and trailing additions)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 209) EXTRAVER=
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 210) if [ x$EXTRAVERSION != "x" ]
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 211) then
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 212) 	EXTRAVER=${EXTRAVERSION#.}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 213) 	EXTRAVER=${EXTRAVER%%[[:punct:]]*}
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 214) 	#echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 215) fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 216) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 217) #echo "stopvers=$stopvers"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 218) if [ $stopvers != "default" ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 219) 	STOPSUBLEVEL=`echo $stopvers | cut -d. -f3`
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 220) 	STOPEXTRA=`echo $stopvers | cut -d. -f4`
0758416325dc7 (Erkki Lintunen     2008-08-06 22:11:33 +0200 221) 	STOPFULLVERSION=${stopvers%%.$STOPEXTRA}
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 222) 	#echo "#___STOPSUBLEVEL=/$STOPSUBLEVEL/, STOPEXTRA=/$STOPEXTRA/"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 223) else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 224) 	STOPSUBLEVEL=9999
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 225) 	STOPEXTRA=9999
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 226) fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 227) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 228) # This all assumes a 2.6.x[.y] kernel tree.
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 229) # Don't allow backwards/reverse patching.
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 230) if [ $STOPSUBLEVEL -lt $SUBLEVEL ]; then
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 231) 	backwards
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 232) fi
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 233) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 234) if [ x$EXTRAVER != "x" ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 235) 	CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 236) else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 237) 	CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 238) fi
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 239) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 240) if [ x$EXTRAVER != "x" ]; then
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 241) 	echo "backing up to: $VERSION.$PATCHLEVEL.$SUBLEVEL"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 242) 	patch="patch-${CURRENTFULLVERSION}"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 243) 	findFile $patchdir/${patch} || noFile ${patch}
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 244) 	reversePatch ${patch} || exit 1
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 245) fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 246) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 247) # now current is 2.6.x, with no EXTRA applied,
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 248) # so update to target SUBLEVEL (2.6.SUBLEVEL)
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 249) # and then to target EXTRAVER (2.6.SUB.EXTRAVER) if requested.
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 250) # If not ending sublevel is specified, it is incremented until
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 251) # no further sublevels are found.
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 252) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 253) if [ $STOPSUBLEVEL -gt $SUBLEVEL ]; then
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 254) while :				# incrementing SUBLEVEL (s in v.p.s)
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 255) do
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 256)     CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 257)     EXTRAVER=
177525d26e318 (Andreas Mohr       2011-04-03 20:58:28 +0200 258)     if [ x$STOPFULLVERSION = x$CURRENTFULLVERSION ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 259)         echo "Stopping at $CURRENTFULLVERSION base as requested."
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 260)         break
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 261)     fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 262) 
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 263)     SUBLEVEL=$(($SUBLEVEL + 1))
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 264)     FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 265)     #echo "#___ trying $FULLVERSION ___"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 266) 
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 267)     if [ $(($SUBLEVEL)) -gt $(($STOPSUBLEVEL)) ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 268) 	echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 269) 	exit 1
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 270)     fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 271) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 272)     patch=patch-$FULLVERSION
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 273)     # See if the file exists and find extension
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 274)     findFile $patchdir/${patch} || noFile ${patch}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 275) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 276)     # Apply the patch and check all is OK
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 277)     applyPatch $patch || break
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 278) done
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 279) #echo "#___sublevel all done"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 280) fi
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 281) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 282) # There is no incremental searching for extraversion...
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 283) if [ "$STOPEXTRA" != "" ]; then
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 284) while :				# just to allow break
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 285) do
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 286) # apply STOPEXTRA directly (not incrementally) (x in v.p.s.x)
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 287) 	FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$STOPEXTRA"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 288) 	#echo "#... trying $FULLVERSION ..."
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 289) 	patch=patch-$FULLVERSION
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 290) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 291) 	# See if the file exists and find extension
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 292) 	findFile $patchdir/${patch} || noFile ${patch}
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 293) 
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 294) 	# Apply the patch and check all is OK
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 295) 	applyPatch $patch || break
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 296) 	#echo "#___extraver all done"
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 297) 	break
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 298) done
1922163c8dfe7 (Randy Dunlap       2005-05-05 16:15:43 -0700 299) fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 300) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 301) if [ x$gotac != x ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 302)   # Out great user wants the -ac patches
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 303) 	# They could have done -ac (get latest) or -acxx where xx=version they want
22d6a6a018d89 (Andreas Mohr       2007-11-17 21:51:25 +0100 304) 	if [ $gotac = "-ac" ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 305) 	  # They want the latest version
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 306) 		HIGHESTPATCH=0
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 307) 		for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 308) 		do
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 309) 			ACVALUE=`echo $PATCHNAMES | sed -e 's/^.*patch-[0-9.]*-ac\([0-9]*\).*/\1/'`
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 310) 			# Check it is actually a recognised patch type
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 311) 			findFile $patchdir/patch-${CURRENTFULLVERSION}-ac${ACVALUE} || break
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 312) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 313) 		  if [ $ACVALUE -gt $HIGHESTPATCH ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 314) 			  HIGHESTPATCH=$ACVALUE
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 315) 		  fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 316) 		done
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 317) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 318) 		if [ $HIGHESTPATCH -ne 0 ]; then
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 319) 			findFile $patchdir/patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH} || break
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 320) 			applyPatch patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 321) 		else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 322) 		  echo "No -ac patches found"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 323) 		fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 324) 	else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 325) 	  # They want an exact version
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 326) 		findFile $patchdir/patch-${CURRENTFULLVERSION}${gotac} || {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 327) 		  echo "Sorry, I couldn't find the $gotac patch for $CURRENTFULLVERSION.  Hohum."
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 328) 			exit 1
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 329) 		}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 330) 		applyPatch patch-${CURRENTFULLVERSION}${gotac}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 331) 	fi
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 332) fi