S3C6410 uses ---21yaffs2's ECC

Publisher:bdwhscLatest update time:2020-12-25 Source: eefocusKeywords:S3C6410  ECC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. ECC Check


ECC: error Checking and correct, can check errors and correct errors.

Advantages: Extremely fast speed

Disadvantages: can only detect 2-bit errors and can only correct 1-bit errors


If you want to verify this, you need to turn on param.no_tags_ecc=0. The default param.no_tags_ecc=1 does not perform tags verification.

At the same time, the ECC check information should also be added to mkyaffs2image so that the ECC can be read from nand_flash for comparison.

nandmtd2_read_chunk_tags

        -->  yaffs_unpack_tags2

void yaffs_unpack_tags2(struct yaffs_ext_tags *t, struct yaffs_packed_tags2 *pt, int tags_ecc)

{

    enum yaffs_ecc_result ecc_result = YAFFS_ECC_RESULT_NO_ERROR;

    if (pt->t.seq_number != 0xffffffff && tags_ecc) {

        struct yaffs_ecc_other ecc;

        int result;

        yaffs_ecc_calc_other((unsigned char *)&pt->t, sizeof(struct yaffs_packed_tags2_tags_only), &ecc);

        result = yaffs_ecc_correct_other((unsigned char *)&pt->t,

                sizeof(struct yaffs_packed_tags2_tags_only), &pt->ecc, &ecc);

        switch (result) {

        case 0:

            ecc_result = YAFFS_ECC_RESULT_NO_ERROR;

            break;

        case 1:

            ecc_result = YAFFS_ECC_RESULT_FIXED;

            break;

        case -1:

            ecc_result = YAFFS_ECC_RESULT_UNFIXED;

            break;

        default:

            ecc_result = YAFFS_ECC_RESULT_UNKNOWN;

        }

    }

    yaffs_unpack_tags2_tags_only(t, &pt->t);


    t->ecc_result = ecc_result; //Save the result after verification, calling its function is to check


    yaffs_dump_packed_tags2(pt); // just print, don't care

    yaffs_dump_tags2(t); // just print, don't care

}

This part mainly verifies the result in yaffs_packed_tags2* pt, sizeof(yaffs_packed_tags2)=4*7=28

struct yaffs_packed_tags2_tags_only {

    unsigned seq_number;

    unsigned obj_id;

    unsigned chunk_id;

    unsigned n_bytes;

};

struct yaffs_ecc_other {

    unsigned char col_parity;

    unsigned line_parity;

    unsigned line_parity_prime;

};

struct yaffs_packed_tags2 {

    struct yaffs_packed_tags2_tags_only t;

    struct yaffs_ecc_other ecc;

};


Note: This check is only called by nandmtd2_read_chunk_tags, because the data in pt is stored in the OOB area of ​​nand flash, and the data in data area has been checked when reading.

Yaffs also uses the first 28 bytes of the OOB area as data, so this part also needs to be verified. However, nand_flash only verifies the data in the data area, so you need to write your own code to verify the 28 bytes of OOB.


2. Verification Algorithm

2. Generate the column_parity_table table

#include

#include

unsigned char entry(unsigned char x) 

    unsigned char b0, b1, b2, b3, b4, b5, b6, b7; 

    unsigned char p4, p2, p1, p4p, p2p, p1p; 

    unsigned char linep; 

    unsigned char result; 

      

    b0 = (x & 0x01) ? 1 : 0; 

    b1 = (x & 0x02) ? 1 : 0; 

    b2 = (x & 0x04) ? 1 : 0; 

    b3 = (x & 0x08) ? 1 : 0; 

    b4 = (x & 0x10) ? 1 : 0; 

    b5 = (x & 0x20) ? 1 : 0; 

    b6 = (x & 0x40) ? 1 : 0; 

    b7 = (x & 0x80) ? 1 : 0; 

      

    p4 = b7 ^ b6 ^ b5 ^ b4; p4p = b3 ^ b2 ^ b1 ^ b0; 

    p2 = b7 ^ b6 ^ b3 ^ b2; p2p = b5 ^ b4 ^ b1 ^ b0; 

    p1 = b7 ^ b5 ^ b3 ^ b1; p1p = b6 ^ b4 ^ b2 ^ b0; 

      

    linep = p1 ^ p1p; 

      

    result = 0; 

    if(p4) result |= 0x80; 

    if(p4p) result |= 0x40; 

    if(p2) result |= 0x20; 

    if(p2p) result |= 0x10; 

    if(p1) result |= 0x08; 

    if(p1p) result |= 0x04; 

    if(linep) result |= 0x01; 

      

    //result >>= 2; 

    //if(linep) result |= 0x40;       

    return result;       

}   

  

int main(int argc, char *argv[]) 

    unsigned i; 

      

    printf("const unsigned char column_parity_table[] = {"); 

    for(i = 0; i < 256; i++) 

    { 

        if((i & 0xf) == 0) printf("n"); 

        printf("0x%02x, ",entry((unsigned char) i)); 

    } 

    printf("n};n"); 

}




So each result is:

2.1 Verification steps

     a. Generate ECC through yaffs_ecc_calc_other, called new_ecc

     b. XOR new_ecc with old_ecc. If they are different, an error occurs.

     c. Similar to a binary tree, find the error and make corrections

void yaffs_ecc_calc_other(const unsigned char *data, unsigned n_bytes, struct yaffs_ecc_other *ecc_other)  //生成新的ECC

{

    unsigned int i;

    unsigned char col_parity = 0;

    unsigned line_parity = 0;

    unsigned line_parity_prime = 0;

    unsigned char b;


    for (i = 0; i < n_bytes; i++) {

        b = column_parity_table[*data++];

        col_parity ^= b;

        if (b & 0x01) {

            /* odd number of bits in the byte */

            line_parity ^= i;

            line_parity_prime ^= ~i;

        }


    }


    ecc_other->col_parity = (col_parity >> 2) & 0x3f;

    ecc_other->line_parity = line_parity;

    ecc_other->line_parity_prime = line_parity_prime;

}


3. 

int yaffs_ecc_correct_other(unsigned char *data, unsigned n_bytes,

             struct yaffs_ecc_other *read_ecc, const struct yaffs_ecc_other *test_ecc)     

{ //Compare with test_ecc and make corrections if they are different

    unsigned char delta_col; /* column parity delta */

    unsigned delta_line; /* line parity delta */

    unsigned delta_line_prime; /* line parity delta */

    unsigned bit;

    delta_col = read_ecc->col_parity ^ test_ecc->col_parity;

    delta_line = read_ecc->line_parity ^ test_ecc->line_parity;

    delta_line_prime = read_ecc->line_parity_prime ^ test_ecc->line_parity_prime;

    if ((delta_col | delta_line | delta_line_prime) == 0)

        return 0; /* no error */

    if (delta_line == ~delta_line_prime && (((delta_col ^ (delta_col >> 1)) & 0x15) == 0x15)) {

        bit = 0; //bit <0-7>, represents which bit is wrong

        if (delta_col & 0x20)                                   

            bit |= 0x04;

        if (delta_col & 0x08)

            bit |= 0x02;

        if (delta_col & 0x02)

            bit |= 0x01;

        if (delta_line >= n_bytes)

            return -1;

        data[delta_line] ^= (1 << bit); //Found the wrong bit, reverse it                                

        return 1; /* corrected */

    }

    if ((hweight32(delta_line) + hweight32(delta_line_prime) + hweight8(delta_col)) == 1) {

        /* Reccoverable error in ecc */

        *read_ecc = *test_ecc;

        return 1; /* corrected */

    }

    /* Unrecoverable error */

    return -1;

}


Keywords:S3C6410  ECC Reference address:S3C6410 uses ---21yaffs2's ECC

Previous article:About S3C2440 u-boot supports nand hw ecc
Next article:OOB layout of tq210 nand 8-bit HWECC and YAFFS2

Recommended ReadingLatest update time:2024-11-16 12:47

In-depth understanding of ARM architecture (S3C6410) --- Understanding S3C6410
The chip architecture is shown in the figure   The S3C64xx series of application processor chips are Samsung's main 16/32 RISC microprocessors. Samsung currently has launched the S3C6400 and S3C6410, both of which are based on the ARM11 architecture and are hardware pin compatible. It should be said that their fu
[Microcontroller]
In-depth understanding of ARM architecture (S3C6410) --- Understanding S3C6410
ARM11 learning based on S3C6410 (XI) DDR initialization
     Previously, programs were run in the internal stepping stone. But the size of the stepping stone is very small. The size of ARM11 is only 8K. It is definitely not possible to run large programs in such a small space. So external memory is needed. The external memory of ARM11 uses DDR. So the DDR must be initializ
[Microcontroller]
ARM11 learning based on S3C6410 (XI) DDR initialization
Chapter 9 Hardware Abstraction Layer: HAL
1. In traditional Linux systems, Linux drivers generally have two types of code: code for accessing hardware registers and business logic code. 2. Android's hierarchical structure: application layer, application framework layer, system runtime layer, Linux kernel layer 3. The purpose of adding HAL to Andro
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号