Why does u-boot always mark a locked block as bad?

I am developing a nand driver for u-boot. I think it works well, but the u-boot environment is not working as expected. Here's what I did for testing:

  • Remove the whole nand phrase with a code that is itself encoded, these codes are not related to u-boot. And no bad blocks were found. (Is it possible for nand flash to not have bad blocks?). Here is the code

    void nand_erase(u32 addr)
    {   
        if (addr & (BLOCK_SIZE - 1))
        {
            printf("not block align\n");
            return;
        }
        u32 row = addr / 2048;
    
        nand_select_chip();
        nand_cmd(0x60);
    
        NFADDR = row & 0xFF;            
        NFADDR = (row >> 8) & 0xFF;
        NFADDR = (row >> 16) & 0x07;
    
        nand_cmd(0xD0);
        nand_wait_ready();
    
        nand_cmd(0x70);
        u8 status = nand_read();
        if (status & 0x01)
        {
            printf("block 0x%x is bad", addr);
        }
    
        nand_deselect_chip();
    }
    
          

  • Run u-boot, it will suggest "bad CRC using default environment".

  • Now I use "setenv test 100" and "printenv test", it works well and "saveenv", it also suggests "OK".

  • And I use "nand bad", it doesn't show anything.

  • Reboot the board and u-boot

  • Now he says "readenv () failed using the default environment".

  • And I "printenv test" it fails. Then I wrote "nand bad", it shows the bad block in "CONFIG_ENV_OFFSET"

  • Then I changed CONFIG_ENV_OFFSET to a different value. and repeat step 1-7. It will show the bad block again in the new CONFIG_ENV_OFFSET file.

I checked my driver, write operation and read operation are good I think. Steps here:

  • "nand dump 0" and it shows all 0xff

  • "nand write 20000000 0 800" to write memory to nand flash.

  • Then "nand dump 0" shows the same values ​​as "md 20000000 100".

So you can see that after saving, the block in CONFIG_ENV_OFFSET will be marked as bad, I really don't know why

+3


source to share


1 answer


Now I'll find out. I have set ecc.mode = NAND_ECC_HW_SYNDROME but the XXX_syndrome function does not support ecc layout. It just writes ecc after the main data. Finally, it will override the first and second bytes of the oob area on every page, but u-boot checks those two bytes as a bad block marker, so here is the answer.



0


source







All Articles