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 VFS_CODE="yaffs_vfs_multi.c"
57 MTD1_CODE="yaffs_mtdif1_multi.c"
58 MTD2_CODE="yaffs_mtdif2_multi.c"
59 YPORTENV="yportenv_multi.h"
60 KCONFIG_SRC="Kconfig_multi"
61 elif [ $MULTIORSINGLE = s ]; then
62 VFS_CODE="yaffs_vfs_single.c"
63 MTD1_CODE="yaffs_mtdif1_single.c"
64 MTD2_CODE="yaffs_mtdif2_single.c"
65 YPORTENV="yportenv_single.h"
66 KCONFIG_SRC="Kconfig_single"
69 echo "*** Warning ***"
70 echo "You have chosen to use the single kernel variant of the yaffs VFS glue code"
71 echo "that only works with the latest Linux kernel tree. If you are using an older"
72 echo "version of Linux then you probably wanted to use the multi-version variant by"
73 echo "re-running the patch-ker.sh script using m as a the second argument."
74 echo " ie $0 $COPYORLINK m $LINUXDIR"
77 echo "unknown multi/single version selection"
82 # Check if kerneldir contains a Makefile
83 if [ ! -f $LINUXDIR/Makefile ]
85 echo "Directory $LINUXDIR does not exist or is not a kernel source directory";
90 VERSION=`grep -s VERSION <$LINUXDIR/Makefile | head -n 1 | sed s/'VERSION = '//`
91 PATCHLEVEL=`grep -s PATCHLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'PATCHLEVEL = '//`
92 SUBLEVEL=`grep -s SUBLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'SUBLEVEL = '//`
94 # Can we handle this version?
95 if [ $VERSION$PATCHLEVEL -lt 26 ]
97 echo "Cannot patch kernel version $VERSION.$PATCHLEVEL.$SUBLEVEL, must be 2.6.x or higher"
102 KCONFIG=$LINUXDIR/fs/Kconfig
103 KCONFIGOLD=$LINUXDIR/fs/Kconfig.pre.yaffs
104 YAFFS_PATCHED_STRING=`grep -s yaffs <$KCONFIG | head -n 1`
106 MAKEFILE=$LINUXDIR/fs/Makefile
107 MAKEFILEOLD=$LINUXDIR/fs/Makefile.pre.yaffs
109 if [ ! -z "$YAFFS_PATCHED_STRING" ]
112 echo "$KCONFIG already mentions YAFFS, so we will not change it"
114 # Change the fs/Kconfig file
115 # Save the old Kconfig
116 # Copy all stuff up to JFFS
117 # Insert some YAFFS stuff
118 # Copy all the rest of the stuff
121 echo "Updating $KCONFIG"
122 mv -f $KCONFIG $KCONFIGOLD
123 sed -n -e "/[Jj][Ff][Ff][Ss]/,99999 ! p" $KCONFIGOLD >$KCONFIG
125 # echo "# Patched by YAFFS" >>$KCONFIG
126 echo "source \"fs/yaffs2/Kconfig\"">>$KCONFIG
128 sed -n -e "/[Jj][Ff][Ff][Ss]/,99999 p" $KCONFIGOLD >>$KCONFIG
130 # now do fs/Makefile -- simply add the target at the end
131 echo "Updating $MAKEFILE"
132 cp -f $MAKEFILE $MAKEFILEOLD
134 # echo "# Patched by YAFFS" >>$MAKEFILE
135 echo "obj-\$(CONFIG_YAFFS_FS) += yaffs2/" >>$MAKEFILE
139 YAFFSDIR=$LINUXDIR/fs/yaffs2
143 echo "$YAFFSDIR exists, so not patching. If you want to replace what is"
144 echo "already there then delete $YAFFSDIR and re-run this script"
145 echo " eg. \"rm -rf $YAFFSDIR\" "
147 rm yaffs*.mod.c 2> /dev/null
148 mkdir $LINUXDIR/fs/yaffs2
149 $CPY $PWD/Makefile.kernel $LINUXDIR/fs/yaffs2/Makefile
150 $CPY $PWD/$KCONFIG_SRC $LINUXDIR/fs/yaffs2/Kconfig
151 $CPY $PWD/*.c $PWD/*.h $LINUXDIR/fs/yaffs2
152 rm $LINUXDIR/fs/yaffs2/yaffs_vfs*.c $LINUXDIR/fs/yaffs2/yaffs_mtdif[12]*.c
153 rm $LINUXDIR/fs/yaffs2/yportenv*.h
154 rm $LINUXDIR/fs/yaffs2/moduleconfig.h
155 $CPY $PWD/$VFS_CODE $LINUXDIR/fs/yaffs2/yaffs_vfs.c
156 $CPY $PWD/$MTD1_CODE $LINUXDIR/fs/yaffs2/yaffs_mtdif1.c
157 $CPY $PWD/$MTD2_CODE $LINUXDIR/fs/yaffs2/yaffs_mtdif2.c
158 $CPY $PWD/$YPORTENV $LINUXDIR/fs/yaffs2/yportenv.h