8caa2e821d5f3331344be1a5e171ed0e14a83b5c
[yaffs2.git] / direct / u-boot / patch-u-boot.sh
1 #!/bin/sh
2 #
3 # YAFFS: Yet another FFS. A NAND-flash specific file system.
4 #
5 # Copyright (C) 2002-2010 Aleph One Ltd.
6 #
7 # Created by Charles Manning <charles@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 yaffs2 into u-boot
14 #
15 #  args: 
16 #         u-boot-path  : Full path to u-boot sources to be patched
17 #
18 #  Inspired yaffs kernel patching script
19
20 set -e -x
21
22 UBOOTDIR=$1
23
24 # Display usage of this script
25 usage () {
26         echo "usage:  $0 u-boot-path"
27         exit 1
28 }
29
30 not_u_boot () {
31         echo "$1 does not seem to be a u-boot directory"
32         exit 1
33 }
34
35
36 if [ -z $UBOOTDIR ]
37 then
38     usage;
39 fi
40
41 # Basic sanity check:
42 # Check it has a Makefile, common and fs sub-directories
43
44 if [ ! -f "$UBOOTDIR/Makefile" ]
45 then
46         not_u_boot
47 fi
48
49 if [ ! -d "$UBOOTDIR/common" ]
50 then
51         not_u_boot
52 fi
53
54 if [ ! -d "$UBOOTDIR/fs" ]
55 then
56         not_u_boot
57 fi
58
59
60 YAFFS_IN_MAKEFILE=`grep -s libyaffs2 <$UBOOTDIR/Makefile | head -n 1`
61 YAFFS_IN_COMMON=`grep -s yaffs2 <$UBOOTDIR/common/Makefile | head -n 1`
62 LIB_A=`grep -s libnet\.a <$UBOOTDIR/Makefile | head -n 1`
63
64 if [ ! -z "$LIB_A" ]
65 then
66     A_OR_O="a"
67 else
68     A_OR_O="o"
69 fi
70
71 # Patch Makefile if it does not mention yaffs2
72 if [ ! -z "$YAFFS_IN_MAKEFILE" ]
73 then
74     echo "$UBOOTDIR/Makefile already makes yaffs library"
75 else
76    # Update the Makefile
77    mv -f $UBOOTDIR/Makefile $UBOOTDIR/Makefile.old
78    sed -n -e "/libnet/,99999 ! p" < $UBOOTDIR/Makefile.old > $UBOOTDIR/Makefile
79    echo "LIBS += fs/yaffs2/libyaffs2.$A_OR_O" >> $UBOOTDIR/Makefile
80    sed -n -e "/libnet/,99999 p" < $UBOOTDIR/Makefile.old >> $UBOOTDIR/Makefile
81 fi
82
83 # Patch common/Makefile if it does not mention yaffs2
84 if [ ! -z "$YAFFS_IN_COMMON" ]
85 then
86     echo "$UBOOTDIR/common/Makefile already makes yaffs commands"
87 else
88    # Update the Makefile
89    mv -f $UBOOTDIR/common/Makefile $UBOOTDIR/common/Makefile.old
90    sed -n -e "/cmd_jffs/,99999 ! p" <$UBOOTDIR/common/Makefile.old > $UBOOTDIR/common/Makefile
91    echo "COBJS-\$(CONFIG_YAFFS2) += cmd_yaffs2.o" >> $UBOOTDIR/common/Makefile
92    sed -n -e "/cmd_jffs/,99999 p" <$UBOOTDIR/common/Makefile.old >> $UBOOTDIR/common/Makefile
93 fi
94
95
96 #
97 # Ensure the direct code is up to date
98 #
99
100 RUN_DIR=`pwd`
101 cd ..
102 ./handle_common.sh copy
103 cd $RUN_DIR
104
105 #
106 # Copy in the files we need
107 #
108
109 cp common/* $UBOOTDIR/common/
110
111 mkdir -p $UBOOTDIR/fs/yaffs2
112 cp ../*.[ch] $UBOOTDIR/fs/yaffs2/
113 cp fs/yaffs2/*.[ch] $UBOOTDIR/fs/yaffs2/
114
115 sed -e "s/A_OR_O/$A_OR_O/" < fs/yaffs2/Makefile > $UBOOTDIR/fs/yaffs2/Makefile
116
117
118