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) < 0) {
printk("erase error: mark bad: offset = %lX\n", offset);
mark_bad(mtd, offset);
return -1;
}
memcpy(buf, bon_part_magic, 8);
s = (unsigned int *)(buf+8);
*s++ = num_part;
for (i = 0; i < num_part; i++) {
*s++ = parts[i].offset;
*s++ = parts[i].size;
*s++ = parts[i].flag;
}
for (i = 0; i < num_part; i++) {
*s++ = parts[i].num_bad_block;
for (k = 0; k < parts[i].num_bad_block; k++) {
*s++ = parts[i].bad_blocks[k];
printk("k = %d block = %d\n", k, parts[i].bad_blocks[k]);
}
}
if (mtd->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;
}
阅读(1367) | 评论(0) | 转发(0) |