Changeset 14261


Ignore:
Timestamp:
2009-01-29T14:39:22+01:00 (9 years ago)
Author:
agb
Message:

[kernel] generic/2.6.28: fix yaffs cvs patch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/target/linux/generic-2.6/patches-2.6.28/511-yaffs-cvs-2009-01-23.patch

    r14158 r14261  
    749749-yaffs-y += yaffs_mtdif.o yaffs_mtdif2.o 
    750750+yaffs-y += yaffs_mtdif.o yaffs_mtdif1.o yaffs_mtdif2.o 
    751 --- a/fs/yaffs2/yaffs_mtdif1-compat.c 
    752 +++ /dev/null 
    753 @@ -1,434 +0,0 @@ 
    754 -From ian@brightstareng.com Fri May 18 15:06:49 2007 
    755 -From ian@brightstareng.com Fri May 18 15:08:21 2007 
    756 -Received: from 206.173.66.57.ptr.us.xo.net ([206.173.66.57] helo=zebra.brightstareng.com) 
    757 -       by apollo.linkchoose.co.uk with esmtp (Exim 4.60) 
    758 -       (envelope-from <ian@brightstareng.com>) 
    759 -       id 1Hp380-00011e-T6 
    760 -       for david.goodenough@linkchoose.co.uk; Fri, 18 May 2007 15:08:21 +0100 
    761 -Received: from localhost (localhost.localdomain [127.0.0.1]) 
    762 -       by zebra.brightstareng.com (Postfix) with ESMTP 
    763 -       id 4819F28C004; Fri, 18 May 2007 10:07:49 -0400 (EDT) 
    764 -Received: from zebra.brightstareng.com ([127.0.0.1]) 
    765 - by localhost (zebra [127.0.0.1]) (amavisd-new, port 10024) with ESMTP 
    766 - id 05328-06; Fri, 18 May 2007 10:07:16 -0400 (EDT) 
    767 -Received: from pippin (unknown [192.168.1.25]) 
    768 -       by zebra.brightstareng.com (Postfix) with ESMTP 
    769 -       id 8BEF528C1BC; Fri, 18 May 2007 10:06:53 -0400 (EDT) 
    770 -From: Ian McDonnell <ian@brightstareng.com> 
    771 -To: David Goodenough <david.goodenough@linkchoose.co.uk> 
    772 -Subject: Re: something tested this time -- yaffs_mtdif1-compat.c 
    773 -Date: Fri, 18 May 2007 10:06:49 -0400 
    774 -User-Agent: KMail/1.9.1 
    775 -References: <200705142207.06909.ian@brightstareng.com> <200705171131.53536.ian@brightstareng.com> <200705181334.32166.david.goodenough@linkchoose.co.uk> 
    776 -In-Reply-To: <200705181334.32166.david.goodenough@linkchoose.co.uk> 
    777 -Cc: Andrea Conti <alyf@alyf.net>, 
    778 - Charles Manning <manningc2@actrix.gen.nz> 
    779 -MIME-Version: 1.0 
    780 -Content-Type: Multipart/Mixed; 
    781 -  boundary="Boundary-00=_5LbTGmt62YoutxM" 
    782 -Message-Id: <200705181006.49860.ian@brightstareng.com> 
    783 -X-Virus-Scanned: by amavisd-new at brightstareng.com 
    784 -Status: R 
    785 -X-Status: NT 
    786 -X-KMail-EncryptionState: 
    787 -X-KMail-SignatureState: 
    788 -X-KMail-MDN-Sent: 
    789 - 
    790 ---Boundary-00=_5LbTGmt62YoutxM 
    791 -Content-Type: text/plain; 
    792 -  charset="iso-8859-15" 
    793 -Content-Transfer-Encoding: 7bit 
    794 -Content-Disposition: inline 
    795 - 
    796 -David, Andrea, 
    797 - 
    798 -On Friday 18 May 2007 08:34, you wrote: 
    799 -> Yea team.  With this fix in place (I put it in the wrong place 
    800 -> at first) I can now mount and ls the Yaffs partition without 
    801 -> an error messages! 
    802 - 
    803 -Good news! 
    804 - 
    805 -Attached is a newer yaffs_mtdif1.c with a bandaid to help the 
    806 -2.6.18 and 2.6.19 versions of MTD not trip on the oob read. 
    807 -See the LINUX_VERSION_CODE conditional in 
    808 -nandmtd1_ReadChunkWithTagsFromNAND. 
    809 - 
    810 --imcd 
    811 - 
    812 ---Boundary-00=_5LbTGmt62YoutxM 
    813 -Content-Type: text/x-csrc; 
    814 -  charset="iso-8859-15"; 
    815 -  name="yaffs_mtdif1.c" 
    816 -Content-Transfer-Encoding: 7bit 
    817 -Content-Disposition: attachment; 
    818 -       filename="yaffs_mtdif1.c" 
    819 - 
    820 -/* 
    821 - * YAFFS: Yet another FFS. A NAND-flash specific file system. 
    822 - * yaffs_mtdif1.c  NAND mtd interface functions for small-page NAND. 
    823 - * 
    824 - * Copyright (C) 2002 Aleph One Ltd. 
    825 - *   for Toby Churchill Ltd and Brightstar Engineering 
    826 - * 
    827 - * This program is free software; you can redistribute it and/or modify 
    828 - * it under the terms of the GNU General Public License version 2 as 
    829 - * published by the Free Software Foundation. 
    830 - */ 
    831 - 
    832 -/* 
    833 - * This module provides the interface between yaffs_nand.c and the 
    834 - * MTD API.  This version is used when the MTD interface supports the 
    835 - * 'mtd_oob_ops' style calls to read_oob and write_oob, circa 2.6.17, 
    836 - * and we have small-page NAND device. 
    837 - * 
    838 - * These functions are invoked via function pointers in yaffs_nand.c. 
    839 - * This replaces functionality provided by functions in yaffs_mtdif.c 
    840 - * and the yaffs_TagsCompatability functions in yaffs_tagscompat.c that are 
    841 - * called in yaffs_mtdif.c when the function pointers are NULL. 
    842 - * We assume the MTD layer is performing ECC (useNANDECC is true). 
    843 - */ 
    844 - 
    845 -#include "yportenv.h" 
    846 -#include "yaffs_guts.h" 
    847 -#include "yaffs_packedtags1.h" 
    848 -#include "yaffs_tagscompat.h"  // for yaffs_CalcTagsECC 
    849 - 
    850 -#include "linux/kernel.h" 
    851 -#include "linux/version.h" 
    852 -#include "linux/types.h" 
    853 -#include "linux/mtd/mtd.h" 
    854 - 
    855 -/* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ 
    856 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) 
    857 - 
    858 -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1-compat.c 13022 2008-10-22 06:51:06Z nbd $"; 
    859 - 
    860 -#ifndef CONFIG_YAFFS_9BYTE_TAGS 
    861 -# define YTAG1_SIZE 8 
    862 -#else 
    863 -# define YTAG1_SIZE 9 
    864 -#endif 
    865 - 
    866 -#if 0 
    867 -/* Use the following nand_ecclayout with MTD when using 
    868 - * CONFIG_YAFFS_9BYTE_TAGS and the older on-NAND tags layout. 
    869 - * If you have existing Yaffs images and the byte order differs from this, 
    870 - * adjust 'oobfree' to match your existing Yaffs data. 
    871 - * 
    872 - * This nand_ecclayout scatters/gathers to/from the old-yaffs layout with the 
    873 - * pageStatus byte (at NAND spare offset 4) scattered/gathered from/to 
    874 - * the 9th byte. 
    875 - * 
    876 - * Old-style on-NAND format: T0,T1,T2,T3,P,B,T4,T5,E0,E1,E2,T6,T7,E3,E4,E5 
    877 - * We have/need PackedTags1 plus pageStatus: T0,T1,T2,T3,T4,T5,T6,T7,P 
    878 - * where Tn are the tag bytes, En are MTD's ECC bytes, P is the pageStatus 
    879 - * byte and B is the small-page bad-block indicator byte. 
    880 - */ 
    881 -static struct nand_ecclayout nand_oob_16 = { 
    882 -       .eccbytes = 6, 
    883 -       .eccpos = { 8, 9, 10, 13, 14, 15 }, 
    884 -       .oobavail = 9, 
    885 -       .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } } 
    886 -}; 
    887 -#endif 
    888 - 
    889 -/* Write a chunk (page) of data to NAND. 
    890 - * 
    891 - * Caller always provides ExtendedTags data which are converted to a more 
    892 - * compact (packed) form for storage in NAND.  A mini-ECC runs over the 
    893 - * contents of the tags meta-data; used to valid the tags when read. 
    894 - * 
    895 - *  - Pack ExtendedTags to PackedTags1 form 
    896 - *  - Compute mini-ECC for PackedTags1 
    897 - *  - Write data and packed tags to NAND. 
    898 - * 
    899 - * Note: Due to the use of the PackedTags1 meta-data which does not include 
    900 - * a full sequence number (as found in the larger PackedTags2 form) it is 
    901 - * necessary for Yaffs to re-write a chunk/page (just once) to mark it as 
    902 - * discarded and dirty.  This is not ideal: newer NAND parts are supposed 
    903 - * to be written just once.  When Yaffs performs this operation, this 
    904 - * function is called with a NULL data pointer -- calling MTD write_oob 
    905 - * without data is valid usage (2.6.17). 
    906 - * 
    907 - * Any underlying MTD error results in YAFFS_FAIL. 
    908 - * Returns YAFFS_OK or YAFFS_FAIL. 
    909 - */ 
    910 -int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, 
    911 -       int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * etags) 
    912 -{ 
    913 -       struct mtd_info * mtd = dev->genericDevice; 
    914 -       int chunkBytes = dev->nDataBytesPerChunk; 
    915 -       loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; 
    916 -       struct mtd_oob_ops ops; 
    917 -       yaffs_PackedTags1 pt1; 
    918 -       int retval; 
    919 - 
    920 -       /* we assume that PackedTags1 and yaffs_Tags are compatible */ 
    921 -       compile_time_assertion(sizeof(yaffs_PackedTags1) == 12); 
    922 -       compile_time_assertion(sizeof(yaffs_Tags) == 8); 
    923 - 
    924 -       yaffs_PackTags1(&pt1, etags); 
    925 -       yaffs_CalcTagsECC((yaffs_Tags *)&pt1); 
    926 - 
    927 -       /* When deleting a chunk, the upper layer provides only skeletal 
    928 -        * etags, one with chunkDeleted set.  However, we need to update the 
    929 -        * tags, not erase them completely.  So we use the NAND write property 
    930 -        * that only zeroed-bits stick and set tag bytes to all-ones and 
    931 -        * zero just the (not) deleted bit. 
    932 -        */ 
    933 -#ifndef CONFIG_YAFFS_9BYTE_TAGS 
    934 -       if (etags->chunkDeleted) { 
    935 -               memset(&pt1, 0xff, 8); 
    936 -               /* clear delete status bit to indicate deleted */ 
    937 -               pt1.deleted = 0; 
    938 -       } 
    939 -#else 
    940 -       ((__u8 *)&pt1)[8] = 0xff; 
    941 -       if (etags->chunkDeleted) { 
    942 -               memset(&pt1, 0xff, 8); 
    943 -               /* zero pageStatus byte to indicate deleted */ 
    944 -               ((__u8 *)&pt1)[8] = 0; 
    945 -       } 
    946 -#endif 
    947 - 
    948 -       memset(&ops, 0, sizeof(ops)); 
    949 -       ops.mode = MTD_OOB_AUTO; 
    950 -       ops.len = (data) ? chunkBytes : 0; 
    951 -       ops.ooblen = YTAG1_SIZE; 
    952 -       ops.datbuf = (__u8 *)data; 
    953 -       ops.oobbuf = (__u8 *)&pt1; 
    954 - 
    955 -       retval = mtd->write_oob(mtd, addr, &ops); 
    956 -       if (retval) { 
    957 -               yaffs_trace(YAFFS_TRACE_MTD, 
    958 -                       "write_oob failed, chunk %d, mtd error %d\n", 
    959 -                       chunkInNAND, retval); 
    960 -       } 
    961 -       return retval ? YAFFS_FAIL : YAFFS_OK; 
    962 -} 
    963 - 
    964 -/* Return with empty ExtendedTags but add eccResult. 
    965 - */ 
    966 -static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval) 
    967 -{ 
    968 -       if (etags) { 
    969 -               memset(etags, 0, sizeof(*etags)); 
    970 -               etags->eccResult = eccResult; 
    971 -       } 
    972 -       return retval; 
    973 -} 
    974 - 
    975 -/* Read a chunk (page) from NAND. 
    976 - * 
    977 - * Caller expects ExtendedTags data to be usable even on error; that is, 
    978 - * all members except eccResult and blockBad are zeroed. 
    979 - * 
    980 - *  - Check ECC results for data (if applicable) 
    981 - *  - Check for blank/erased block (return empty ExtendedTags if blank) 
    982 - *  - Check the PackedTags1 mini-ECC (correct if necessary/possible) 
    983 - *  - Convert PackedTags1 to ExtendedTags 
    984 - *  - Update eccResult and blockBad members to refect state. 
    985 - * 
    986 - * Returns YAFFS_OK or YAFFS_FAIL. 
    987 - */ 
    988 -int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, 
    989 -       int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags) 
    990 -{ 
    991 -       struct mtd_info * mtd = dev->genericDevice; 
    992 -       int chunkBytes = dev->nDataBytesPerChunk; 
    993 -       loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; 
    994 -       int eccres = YAFFS_ECC_RESULT_NO_ERROR; 
    995 -       struct mtd_oob_ops ops; 
    996 -       yaffs_PackedTags1 pt1; 
    997 -       int retval; 
    998 -       int deleted; 
    999 - 
    1000 -       memset(&ops, 0, sizeof(ops)); 
    1001 -       ops.mode = MTD_OOB_AUTO; 
    1002 -       ops.len = (data) ? chunkBytes : 0; 
    1003 -       ops.ooblen = YTAG1_SIZE; 
    1004 -       ops.datbuf = data; 
    1005 -       ops.oobbuf = (__u8 *)&pt1; 
    1006 - 
    1007 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) 
    1008 -       /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; 
    1009 -        * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. 
    1010 -        */ 
    1011 -       ops.len = (ops.datbuf) ? ops.len : ops.ooblen; 
    1012 -#endif 
    1013 -       /* Read page and oob using MTD. 
    1014 -        * Check status and determine ECC result. 
    1015 -        */ 
    1016 -       retval = mtd->read_oob(mtd, addr, &ops); 
    1017 -       if (retval) { 
    1018 -               yaffs_trace(YAFFS_TRACE_MTD, 
    1019 -                       "read_oob failed, chunk %d, mtd error %d\n", 
    1020 -                       chunkInNAND, retval); 
    1021 -       } 
    1022 - 
    1023 -       switch (retval) { 
    1024 -       case 0: 
    1025 -               /* no error */ 
    1026 -               break; 
    1027 - 
    1028 -       case -EUCLEAN: 
    1029 -               /* MTD's ECC fixed the data */ 
    1030 -               eccres = YAFFS_ECC_RESULT_FIXED; 
    1031 -               dev->eccFixed++; 
    1032 -               break; 
    1033 - 
    1034 -       case -EBADMSG: 
    1035 -               /* MTD's ECC could not fix the data */ 
    1036 -               dev->eccUnfixed++; 
    1037 -               /* fall into... */ 
    1038 -       default: 
    1039 -               rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); 
    1040 -               etags->blockBad = (mtd->block_isbad)(mtd, addr); 
    1041 -               return YAFFS_FAIL; 
    1042 -       } 
    1043 - 
    1044 -       /* Check for a blank/erased chunk. 
    1045 -        */ 
    1046 -       if (yaffs_CheckFF((__u8 *)&pt1, 8)) { 
    1047 -               /* when blank, upper layers want eccResult to be <= NO_ERROR */ 
    1048 -               return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); 
    1049 -       } 
    1050 - 
    1051 -#ifndef CONFIG_YAFFS_9BYTE_TAGS 
    1052 -       /* Read deleted status (bit) then return it to it's non-deleted 
    1053 -        * state before performing tags mini-ECC check. pt1.deleted is 
    1054 -        * inverted. 
    1055 -        */ 
    1056 -       deleted = !pt1.deleted; 
    1057 -       pt1.deleted = 1; 
    1058 -#else 
    1059 -       (void) deleted; /* not used */ 
    1060 -#endif 
    1061 - 
    1062 -       /* Check the packed tags mini-ECC and correct if necessary/possible. 
    1063 -        */ 
    1064 -       retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); 
    1065 -       switch (retval) { 
    1066 -       case 0: 
    1067 -               /* no tags error, use MTD result */ 
    1068 -               break; 
    1069 -       case 1: 
    1070 -               /* recovered tags-ECC error */ 
    1071 -               dev->tagsEccFixed++; 
    1072 -               eccres = YAFFS_ECC_RESULT_FIXED; 
    1073 -               break; 
    1074 -       default: 
    1075 -               /* unrecovered tags-ECC error */ 
    1076 -               dev->tagsEccUnfixed++; 
    1077 -               return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL); 
    1078 -       } 
    1079 - 
    1080 -       /* Unpack the tags to extended form and set ECC result. 
    1081 -        * [set shouldBeFF just to keep yaffs_UnpackTags1 happy] 
    1082 -        */ 
    1083 -       pt1.shouldBeFF = 0xFFFFFFFF; 
    1084 -       yaffs_UnpackTags1(etags, &pt1); 
    1085 -       etags->eccResult = eccres; 
    1086 - 
    1087 -       /* Set deleted state. 
    1088 -        */ 
    1089 -#ifndef CONFIG_YAFFS_9BYTE_TAGS 
    1090 -       etags->chunkDeleted = deleted; 
    1091 -#else 
    1092 -       etags->chunkDeleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); 
    1093 -#endif 
    1094 -       return YAFFS_OK; 
    1095 -} 
    1096 - 
    1097 -/* Mark a block bad. 
    1098 - * 
    1099 - * This is a persistant state. 
    1100 - * Use of this function should be rare. 
    1101 - * 
    1102 - * Returns YAFFS_OK or YAFFS_FAIL. 
    1103 - */ 
    1104 -int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) 
    1105 -{ 
    1106 -       struct mtd_info * mtd = dev->genericDevice; 
    1107 -       int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; 
    1108 -       int retval; 
    1109 - 
    1110 -       yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo); 
    1111 - 
    1112 -       retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); 
    1113 -       return (retval) ? YAFFS_FAIL : YAFFS_OK; 
    1114 -} 
    1115 - 
    1116 -/* Check any MTD prerequists. 
    1117 - * 
    1118 - * Returns YAFFS_OK or YAFFS_FAIL. 
    1119 - */ 
    1120 -static int nandmtd1_TestPrerequists(struct mtd_info * mtd) 
    1121 -{ 
    1122 -       /* 2.6.18 has mtd->ecclayout->oobavail */ 
    1123 -       /* 2.6.21 has mtd->ecclayout->oobavail and mtd->oobavail */ 
    1124 -       int oobavail = mtd->ecclayout->oobavail; 
    1125 - 
    1126 -       if (oobavail < YTAG1_SIZE) { 
    1127 -               yaffs_trace(YAFFS_TRACE_ERROR, 
    1128 -                       "mtd device has only %d bytes for tags, need %d", 
    1129 -                       oobavail, YTAG1_SIZE); 
    1130 -               return YAFFS_FAIL; 
    1131 -       } 
    1132 -       return YAFFS_OK; 
    1133 -} 
    1134 - 
    1135 -/* Query for the current state of a specific block. 
    1136 - * 
    1137 - * Examine the tags of the first chunk of the block and return the state: 
    1138 - *  - YAFFS_BLOCK_STATE_DEAD, the block is marked bad 
    1139 - *  - YAFFS_BLOCK_STATE_NEEDS_SCANNING, the block is in use 
    1140 - *  - YAFFS_BLOCK_STATE_EMPTY, the block is clean 
    1141 - * 
    1142 - * Always returns YAFFS_OK. 
    1143 - */ 
    1144 -int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, 
    1145 -       yaffs_BlockState * pState, int *pSequenceNumber) 
    1146 -{ 
    1147 -       struct mtd_info * mtd = dev->genericDevice; 
    1148 -       int chunkNo = blockNo * dev->nChunksPerBlock; 
    1149 -       yaffs_ExtendedTags etags; 
    1150 -       int state = YAFFS_BLOCK_STATE_DEAD; 
    1151 -       int seqnum = 0; 
    1152 -       int retval; 
    1153 - 
    1154 -       /* We don't yet have a good place to test for MTD config prerequists. 
    1155 -        * Do it here as we are called during the initial scan. 
    1156 -        */ 
    1157 -       if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK) { 
    1158 -               return YAFFS_FAIL; 
    1159 -       } 
    1160 - 
    1161 -       retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); 
    1162 -       if (etags.blockBad) { 
    1163 -               yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, 
    1164 -                       "block %d is marked bad", blockNo); 
    1165 -               state = YAFFS_BLOCK_STATE_DEAD; 
    1166 -       } 
    1167 -       else if (etags.chunkUsed) { 
    1168 -               state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; 
    1169 -               seqnum = etags.sequenceNumber; 
    1170 -       } 
    1171 -       else { 
    1172 -               state = YAFFS_BLOCK_STATE_EMPTY; 
    1173 -       } 
    1174 - 
    1175 -       *pState = state; 
    1176 -       *pSequenceNumber = seqnum; 
    1177 - 
    1178 -       /* query always succeeds */ 
    1179 -       return YAFFS_OK; 
    1180 -} 
    1181 - 
    1182 -#endif /*KERNEL_VERSION*/ 
    1183 - 
    1184 ---Boundary-00=_5LbTGmt62YoutxM-- 
    1185 - 
    1186 - 
    1187 - 
    1188751--- a/fs/yaffs2/yaffs_fs.c 
    1189752+++ b/fs/yaffs2/yaffs_fs.c 
Note: See TracChangeset for help on using the changeset viewer.