3 # YAFFS: Yet another FFS. A NAND-flash specific file system.
5 # Copyright (C) 2002-2010 Aleph One Ltd.
7 # Created by Charles Manning <charles@aleph1.co.uk>
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.
13 # Patch YAFFS into the kernel
15 # args: l/c : link or copy
16 # kpath : Full path to kernel sources to be patched
18 # Somewhat "inspired by" the mtd patchin script
28 # To be a Linux directory, it must have a Makefile
31 # Display usage of this script
33 echo "usage: $0 c/l m/s kernelpath"
34 echo " if c/l is c, then copy. If l then link"
35 echo " if m/s is m, then use multi version code. If s then use single version code"
46 if [ $COPYORLINK = l ]; then
48 elif [ $COPYORLINK = c ]; then
51 echo "unknown copy or link type"
55 if [ $MULTIORSINGLE = m ]; then
56 VFSGLUE="yaffs_vfs_multi.c"
57 elif [ $MULTIORSINGLE = s ]; then
60 echo "*** Warning ***"
61 echo "You have chosen to use the single kernel variant of the yaffs VFS glue code"
62 echo "that only works with the latest Linux kernel tree. If you are using an older"
63 echo "version of Linux then you probably wanted to use the multi-version variant by"
64 echo "re-running the patch-ker.sh script using m as a the second argument."
65 echo " ie $0 $COPYORLINK m $LINUXDIR"
68 echo "unknown multi/single version selection"
73 # Check if kerneldir contains a Makefile
74 if [ ! -f $LINUXDIR/Makefile ]
76 echo "Directory $LINUXDIR does not exist or is not a kernel source directory";
81 VERSION=`grep -s VERSION <$LINUXDIR/Makefile | head -n 1 | sed s/'VERSION = '//`
82 PATCHLEVEL=`grep -s PATCHLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'PATCHLEVEL = '//`
83 SUBLEVEL=`grep -s SUBLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'SUBLEVEL = '//`
85 # Can we handle this version?
86 if [ $VERSION -ne 2 -o $PATCHLEVEL -lt 6 ]
88 echo "Cannot patch kernel version $VERSION.$PATCHLEVEL.$SUBLEVEL, must be 2.6.x or higher"
93 KCONFIG=$LINUXDIR/fs/Kconfig
94 KCONFIGOLD=$LINUXDIR/fs/Kconfig.pre.yaffs
95 YAFFS_PATCHED_STRING=`grep -s yaffs <$KCONFIG | head -n 1`
97 MAKEFILE=$LINUXDIR/fs/Makefile
98 MAKEFILEOLD=$LINUXDIR/fs/Makefile.pre.yaffs
100 if [ ! -z "$YAFFS_PATCHED_STRING" ]
103 echo "$KCONFIG already mentions YAFFS, so we will not change it"
105 # Change the fs/Kconfig file
106 # Save the old Kconfig
107 # Copy all stuff up to JFFS
108 # Insert some YAFFS stuff
109 # Copy all the rest of the stuff
112 echo "Updating $KCONFIG"
113 mv -f $KCONFIG $KCONFIGOLD
114 sed -n -e "/[Jj][Ff][Ff][Ss]/,99999 ! p" $KCONFIGOLD >$KCONFIG
116 echo "# Patched by YAFFS" >>$KCONFIG
117 echo "source \"fs/yaffs2/Kconfig\"">>$KCONFIG
119 sed -n -e "/[Jj][Ff][Ff][Ss]/,99999 p" $KCONFIGOLD >>$KCONFIG
121 # now do fs/Makefile -- simply add the target at the end
122 echo "Updating $MAKEFILE"
123 cp -f $MAKEFILE $MAKEFILEOLD
125 echo "# Patched by YAFFS" >>$MAKEFILE
126 echo "obj-\$(CONFIG_YAFFS_FS) += yaffs2/" >>$MAKEFILE
130 YAFFSDIR=$LINUXDIR/fs/yaffs2
134 echo "$YAFFSDIR exists, so not patching. If you want to replace what is"
135 echo "already there then delete $YAFFSDIR and re-run this script"
136 echo " eg. \"rm -rf $YAFFSDIR\" "
138 mkdir $LINUXDIR/fs/yaffs2
139 $CPY $PWD/Makefile.kernel $LINUXDIR/fs/yaffs2/Makefile
140 $CPY $PWD/Kconfig $LINUXDIR/fs/yaffs2
141 $CPY $PWD/*.c $PWD/*.h $LINUXDIR/fs/yaffs2
142 rm $LINUXDIR/fs/yaffs2/yaffs_vfs.c $LINUXDIR/fs/yaffs2/yaffs_vfs_multi.c
143 $CPY $PWD/$VFSGLUE $LINUXDIR/fs/yaffs2/yaffs_vfs_glue.c