uboot 中nand write 与nand write.yaffs

nand write会计算ECC并将其烧录到oob中。

nand write.yaffs不计算ECC,因为yaffs image中自带了含ECC的OOB数据,直接将其烧录到oob区即可。

 

1. nand write.yaffs

(common/cmd_nand.c: int do_nand())
nand_write_skip_bad(nand, off, &rwsize,
                        (u_char *)addr,
                        WITH_YAFFS_OOB);
      
  ------------>
  (drivers/mtd/nand/nand_util.c: int nand_write_skip_bad())
  ops.mode = MTD_OOB_RAW;
  ops.datbuf = p_buffer;
  ops.oobbuf = ops.datbuf + pagesize;
  rval = nand->write_oob(nand, offset, &ops); (call nand_write_oob() )
  
        -------------->
      (drivers/mtd/nand/nand_base.c: static int nand_write_oob())
      ret = nand_do_write_ops(mtd, to, ops);
     ----------->
     (drivers/mtd/nand/nand_base.c: static int nand_do_write_ops())
      uint8_t *oob = ops->oobbuf;
      uint8_t *buf = ops->datbuf;
      uint8_t *wbuf = buf;
               if (unlikely(oob)) {
      size_t len = min(oobwritelen, oobmaxlen);
      oob = nand_fill_oob(chip, oob, len, ops);  //prepare chip->oob_poi
      oobwritelen -= len;
     }
     ret = chip->write_page(mtd, chip, wbuf, page, cached,
                       (ops->mode == MTD_OOB_RAW)); (call nand_write_page())
           ---------->
            (drivers/mtd/nand/nand_base.c: static int nand_write_page())
            if (unlikely(raw)){ //here raw=1 unlikely(raw) is true
            chip->ecc.write_page_raw(mtd, chip, buf); (call nand_write_page_raw())
         }
                ------------->
          (drivers/mtd/nand/nand_base.c: static void nand_write_page_raw())
          chip->write_buf(mtd, buf, mtd->writesize);
          chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);

       

2. nand write
  
(common/cmd_nand.c: int do_nand())
ret = nand_write_skip_bad(nand, off, &rwsize,
                              (u_char *)addr, 0);
  ------------>
  (drivers/mtd/nand/nand_util.c: int nand_write_skip_bad())
  if (!need_skip && !(flags & WITH_YAFFS_OOB)) {
   rval = nand_write (nand, offset, length, buffer);
   if (rval == 0)
    return 0;

   *length = 0;
   printf ("NAND write to offset %llx failed %d\n",
    offset, rval);
   return rval;
  }
        -------------->
      (drivers/mtd/nand/nand_base.c: static int nand_write())
       chip->ops.len = len;
    chip->ops.datbuf = (uint8_t *)buf;
    chip->ops.oobbuf = NULL;

    ret = nand_do_write_ops(mtd, to, &chip->ops);

     -----------> 
     (drivers/mtd/nand/nand_base.c: static int nand_do_write_ops())
      uint8_t *oob = ops->oobbuf;
      uint8_t *buf = ops->datbuf;
      uint8_t *wbuf = buf;
               if (unlikely(oob)) {
      size_t len = min(oobwritelen, oobmaxlen);
      oob = nand_fill_oob(chip, oob, len, ops);
      oobwritelen -= len;
     }
     ret = chip->write_page(mtd, chip, wbuf, page, cached,
                       (ops->mode == MTD_OOB_RAW)); (call nand_write_page())
             ---------->  
          (drivers/mtd/nand/nand_base.c: static int nand_write_page())
       if (unlikely(raw)){ //here raw=0, unlikely(raw) is false
        chip->ecc.write_page_raw(mtd, chip, buf);
       }else{
        chip->ecc.write_page(mtd, chip, buf); (call nand_write_page_swecc())
       }
        ----------->
        (drivers/mtd/nand/nand_base.c: static void nand_write_page_swecc())
            /* Software ecc calculation */
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize)
        chip->ecc.calculate(mtd, p, &ecc_calc[i]);

        for (i = 0; i < chip->ecc.total; i++)
        chip->oob_poi[eccpos[i]] = ecc_calc[i];

        chip->ecc.write_page_raw(mtd, chip, buf);(call nand_write_page_raw())
                                     ---------->
         (drivers/mtd/nand/nand_base.c: static void nand_write_page_raw())
          chip->write_buf(mtd, buf, mtd->writesize);
          chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);

你可能感兴趣的:(uboot 中nand write 与nand write.yaffs)