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 elif [ $MULTIORSINGLE = s ]; then
60 VFS_CODE="yaffs_vfs_single.c"
61 MTD1_CODE="yaffs_mtdif1_single.c"
62 MTD2_CODE="yaffs_mtdif2_single.c"
65 echo "*** Warning ***"
66 echo "You have chosen to use the single kernel variant of the yaffs VFS glue code"
67 echo "that only works with the latest Linux kernel tree. If you are using an older"
68 echo "version of Linux then you probably wanted to use the multi-version variant by"
69 echo "re-running the patch-ker.sh script using m as a the second argument."
70 echo " ie $0 $COPYORLINK m $LINUXDIR"
73 echo "unknown multi/single version selection"
78 # Check if kerneldir contains a Makefile
79 if [ ! -f $LINUXDIR/Makefile ]
81 echo "Directory $LINUXDIR does not exist or is not a kernel source directory";
86 VERSION=`grep -s VERSION <$LINUXDIR/Makefile | head -n 1 | sed s/'VERSION = '//`
87 PATCHLEVEL=`grep -s PATCHLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'PATCHLEVEL = '//`
88 SUBLEVEL=`grep -s SUBLEVEL <$LINUXDIR/Makefile | head -n 1 | sed s/'SUBLEVEL = '//`
90 # Can we handle this version?
91 if [ $VERSION -ne 2 -o $PATCHLEVEL -lt 6 ]
93 echo "Cannot patch kernel version $VERSION.$PATCHLEVEL.$SUBLEVEL, must be 2.6.x or higher"
98 KCONFIG=$LINUXDIR/fs/Kconfig
99 KCONFIGOLD=$LINUXDIR/fs/Kconfig.pre.yaffs
100 YAFFS_PATCHED_STRING=`grep -s yaffs <$KCONFIG | head -n 1`
102 MAKEFILE=$LINUXDIR/fs/Makefile
103 MAKEFILEOLD=$LINUXDIR/fs/Makefile.pre.yaffs
105 if [ ! -z "$YAFFS_PATCHED_STRING" ]
108 echo "$KCONFIG already mentions YAFFS, so we will not change it"
110 # Change the fs/Kconfig file
111 # Save the old Kconfig
112 # Copy all stuff up to JFFS
113 # Insert some YAFFS stuff
114 # Copy all the rest of the stuff
117 echo "Updating $KCONFIG"
118 mv -f $KCONFIG $KCONFIGOLD
119 sed -n -e "/[Jj][Ff][Ff][Ss]/,99999 ! p" $KCONFIGOLD >$KCONFIG
121 echo "# Patched by YAFFS" >>$KCONFIG
122 echo "source \"fs/yaffs2/Kconfig\"">>$KCONFIG
124 sed -n -e "/[Jj][Ff][Ff][Ss]/,99999 p" $KCONFIGOLD >>$KCONFIG
126 # now do fs/Makefile -- simply add the target at the end
127 echo "Updating $MAKEFILE"
128 cp -f $MAKEFILE $MAKEFILEOLD
130 echo "# Patched by YAFFS" >>$MAKEFILE
131 echo "obj-\$(CONFIG_YAFFS_FS) += yaffs2/" >>$MAKEFILE
135 YAFFSDIR=$LINUXDIR/fs/yaffs2
139 echo "$YAFFSDIR exists, so not patching. If you want to replace what is"
140 echo "already there then delete $YAFFSDIR and re-run this script"
141 echo " eg. \"rm -rf $YAFFSDIR\" "
143 mkdir $LINUXDIR/fs/yaffs2
144 $CPY $PWD/Makefile.kernel $LINUXDIR/fs/yaffs2/Makefile
145 $CPY $PWD/Kconfig $LINUXDIR/fs/yaffs2
146 $CPY $PWD/*.c $PWD/*.h $LINUXDIR/fs/yaffs2
147 rm $LINUXDIR/fs/yaffs2/yaffs_vfs*.c $LINUXDIR/fs/yaffs2/yaffs_mtdif[12]*.c
148 $CPY $PWD/$VFS_CODE $LINUXDIR/fs/yaffs2/yaffs_vfs.c
149 $CPY $PWD/$MTD1_CODE $LINUXDIR/fs/yaffs2/yaffs_mtdif1.c
150 $CPY $PWD/$MTD2_CODE $LINUXDIR/fs/yaffs2/yaffs_mtdif2.c