免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1275 | 回复: 0
打印 上一主题 下一主题

Nand flash layout In ViVi [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-30 18:06 |只看该作者 |倒序浏览
project     : Nand flash layout
instruction : Nand flash format imformation
1 block  = 32 pages
1 sector = 512 bytes
1 pages  = 512 bytes
--  _________________________________0x0400_0000 ( total: 64 M )
--  |  Partition Table          |---> (the upmost 1 block)
--  |___________________________|____0x03FF_C000 ( Partition Table )
--  |                           |
--  |                           |
--  |      root (61.67M)        |
--  |                           |
--  |___________________________|____0x0025_0000
--  |      kernel(2M)           |
--  |___________________________|____0x0005_0000
--  |      param (64K)          |
--  |___________________________|____0x0004_0000
--  |      eboot(128K)          |
--  |___________________________|____0x0002_0000
--  |      vivi (128K)          |
--  |___________________________|____0x0000_0000 ( Nand Flash base )
(1) the default MTD partitions:
mtd_partition_t default_mtd_partitions[] = {    /*struct mtd_partition_t was defined at include/priv_data.h*/
    {
        name:        "vivi",
        offset:        0,
        size:        0x00020000,
        flag:        0
    }, {
        name:        "eboot",
        offset:        0x00020000,
        size:        0x00020000,
        flag:        0
    },{
        name:        "param",
        offset:        0x00040000,
        size:        0x00010000,
        flag:        0
    },{
        name:        "kernel",
        offset:        0x00050000,
        size:        0x00200000,
        flag:        0
    }, {
        name:        "root",
        offset:        0x00250000,
        size:        0x03DAC000,
        flag:        0
    }
};
(2) Partition Table detailed:
|---- 8 bytes----||-- 4 bytes--|-4bytes-|-4bytes-||- Nx12 bytes-|| --- 4 bytes ---- | ................... || ..........
--------------------------------------------------------------------------------------------------------------------------
| bon_part_magic ||-- Offset --|--Size--|--flag--|| ... ... ... || P1 num_bad_block | 1 ... num_bad_block || P2 ... ...
--------------------------------------------------------------------------------------------------------------------------
|----------------||----------- part 1 -----------||-- ... ... --|| -------  the bad block of part 1 ------|| P2 ... ...
typedef struct {
    ulong offset;
    ulong size;
    ulong flag;
    ulong num_bad_block;
    unsigned short *bad_blocks;
} bon_partition_t;
(3) the code fragment for writting partition in ViVi.
int write_partition(struct mtd_info *mtd, ulong offset)
{
    unsigned char oobbuf[NAND_OOB_SIZE];
    char buf[NAND_SECTOR_SIZE];
    struct erase_info erase;
    unsigned int *s;
    int i, k;
    size_t retlen;
    if (mtd->read_oob(mtd, offset, NAND_OOB_SIZE, &retlen, oobbuf))
        return -1;
    if (oobbuf[5] != 0xFF) return -1;
    if (mtd->read(mtd, offset, NAND_SECTOR_SIZE, &retlen, buf)) {
        printk("read error: mark bad: offset = %lX\n", offset);
        mark_bad(mtd, offset);
        return -1;
    }
    erase.addr = offset;
    erase.len = mtd->erasesize;
    if (mtd->erase(mtd, &erase) write(mtd, offset, NAND_SECTOR_SIZE, &retlen, buf))
        return -1;
    if (retlen != NAND_SECTOR_SIZE) {
        printk("write error: offset = %lu\n", offset);
        mark_bad(mtd, offset);
        return -1;
    }
    return 0;
}
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/94861/showart_1915497.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP