几个Uboot命令

时间:2022-06-06 12:35:24

1 nand scrub

这个命令会擦除坏块信息,将坏块标识成好的,但此时这个坏块有潜在有危险,在特定条件下仍会造成数据的丢失,所以应该谨慎使用.

Run U-boot and then use the following commands to clean the NAND device.

  1. Run the command nand bad to generate a list of the blocks on the device that the driver believes to be bad. Keep a copy of this list—it will be used later to remark the bad blocks manually.

  2. For each of the bad blocks on the list, run: nand dump <block-number>

  3. If the output of the dump command looks like "real" data, then it is safe to assume that it is a good block. If the block is all zeros (both in-band and out-of-band) then it is very likely to be a genuinely bad block. Keep a record of all the blocks that are genuinely bad.

  4. Run nand scrub to erase ALL of the blocks on the NAND device. This will also set most of the bad blocks to "good".

  5. Run nand bad again to obtain a revised list of bad blocks. Compare this list with the list of "genuinely bad" blocks (that is, blocks containing all zeros), obtained at step 3.

  6. For each block on the "genuinely bad" list that is no longer marked as bad by nand bad, run nand markbad &lt;block-number&gt;

Simply running nand scrub without first identifying which blocks are genuinely bad (using nand bad and nand markbad commands, as described above) will silently convert soft bad blocks to false good blocks, which will cause unrecoverable problems with reading and writing data.

2 mtdparts

The mtdparts command offers an easy to use and powerful interface to define the contents of the environment variable of the same name that can be passed as boot argument to the Linux kernel:

=> help mtdparts
mtdparts
- list partition table
mtdparts delall
- delete all partitions
mtdparts del part-id
- delete partition (e.g. part-id = nand0,1)
mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]
- add partition
mtdparts default
- reset partition table to defaults

大家都知道nand flahs 是有坏块的,假设有两个分区P1(block0,block1),P2(block2,block3,)假设要写一个数据(大小为2block),则会写到P1的block0,block1上.

但此时,如果block1为坏块,则数据会写至block0,block2,跳过坏块block1,但此时数据横跨两个区.

为了避免这种情况,可以使用这个命令:mtdparts.此时uboot 会进行边界检查,上例这种情况数据只会写到block0中,不会写至block2中.