1 #!/bin/sh 2 # 3 # YAFFS: Yet another FFS. A NAND-flash specific file system. 4 # 5 # Copyright (C) 2002 Aleph One Ltd. 6 # 7 # Created by Charles Manning <charles (at] aleph1.co.uk> 8 # 9 # This program is free software; you can redistribute it and/or modify 10 # it under the terms of the GNU General Public License version 2 as 11 # published by the Free Software Foundation. 12 # 13 # Patch YAFFS into the kernel 14 # 15 # args: kpath : Full path to kernel sources to be patched 16 # 17 # Somewhat "inspired by" the mtd patchin script 18 # 19 # $Id: patch-ker.sh,v 1.1 2005/07/31 09:04:13 marty Exp $ 20 21 VERSION=0 22 PATCHLEVEL=0 23 SUBLEVEL=0 24 LINUXDIR=$1 25 26 # To be a Linux directory, it must have a Makefile 27 28 29 # Display usage of this script 30 usage () { 31 echo "usage: $0 kernelpath" 32 exit 1 33 } 34 35 36 37 if [ -z $LINUXDIR ] 38 then 39 usage; 40 fi 41 42 # Check if kerneldir contains a Makefile 43 if [ ! -f $LINUXDIR/Makefile ] 44 then 45 echo "Directory $LINUXDIR does not exist or is not a kernel source directory"; 46 exit 1; 47 fi 48 49 # Get kernel version 50 VERSION=`grep -s VERSION <$LINUXDIR/Makefile | head -n 1 | sed s/'VERSION = '//` 51 PATCHLEVEL=`grep -s PATCHLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'PATCHLEVEL = '//` 52 SUBLEVEL=`grep -s SUBLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'SUBLEVEL = '//` 53 54 # Can we handle this version? 55 if [ $VERSION -ne 2 -o $PATCHLEVEL -lt 6 ] 56 then 57 echo "Cannot patch kernel version $VERSION.$PATCHLEVEL.$SUBLEVEL, must be 2.6.x or higher" 58 exit 1; 59 fi 60 61 62 KCONFIG=$LINUXDIR/fs/Kconfig 63 KCONFIGOLD=$LINUXDIR/fs/Kconfig.pre.yaffs 64 YAFFS_PATCHED_STRING=`grep -s yaffs <$KCONFIG | head -n 1` 65 66 MAKEFILE=$LINUXDIR/fs/Makefile 67 MAKEFILEOLD=$LINUXDIR/fs/Makefile.pre.yaffs 68 69 if [ ! -z "$YAFFS_PATCHED_STRING" ] 70 then 71 YAFFS_PATCHED=0 72 echo "$KCONFIG already mentions YAFFS, so we will not change it" 73 else 74 # Change the fs/Kconfig file 75 # Save the old Kconfig 76 # Copy all stuff up to JFFS 77 # Insert some YAFFS stuff 78 # Copy all the rest of the stuff 79 80 YAFFS_PATCHED=1 81 echo "Updating $KCONFIG" 82 mv -f $KCONFIG $KCONFIGOLD 83 sed -n -e "/JFFS/,99999 ! p" $KCONFIGOLD >$KCONFIG 84 echo "">>$KCONFIG 85 echo "# Patched by YAFFS" >>$KCONFIG 86 echo "source \"fs/yaffs2/Kconfig\"">>$KCONFIG 87 echo "">>$KCONFIG 88 sed -n -e "/JFFS/,99999 p" $KCONFIGOLD >>$KCONFIG 89 90 # now do fs/Makefile -- simply add the target at the end 91 echo "Updating $MAKEFILE" 92 cp -f $MAKEFILE $MAKEFILEOLD 93 echo "">>$MAKEFILE 94 echo "# Patched by YAFFS" >>$MAKEFILE 95 echo "obj-\$(CONFIG_YAFFS_FS) += yaffs2/" >>$MAKEFILE 96 97 fi 98 99 YAFFSDIR=$LINUXDIR/fs/yaffs2 100 101 if [ -e $YAFFSDIR ] 102 then 103 echo "$YAFFSDIR exists, not patching" 104 else 105 mkdir $LINUXDIR/fs/yaffs2 106 cp Makefile.kernel $LINUXDIR/fs/yaffs2/Makefile 107 cp Kconfig $LINUXDIR/fs/yaffs2 108 cp *.c *.h $LINUXDIR/fs/yaffs2 109 fi 110