return 0;
}
其中yaffs_devconfig(YAFFSFS_MNT_POINT, YAFFSFS_START_BLOCK, YAFFSFS_END_BLOCK),的参数是宏,如下:
#define YAFFSFS_MNT_POINT "/nand"
#define YAFFSFS_OFFSET (2*SIZE_1M) /* YAFFS2 file system start offset address */
#define YAFFSFS_SIZE (10*SIZE_1M) /* YAFFS2 file system size */
#define YAFFSFS_START_BLOCK ( YAFFSFS_OFFSET/NF_BLOCK_SIZE )
#define K9F2G08_BLOCK_SIZE 0x20000 /* Nandflash block size: 128K */
#define NF_BLOCK_SIZE K9F2G08_BLOCK_SIZE
#define YAFFSFS_END_BLOCK ( YAFFSFS_START_BLOCK+(YAFFSFS_SIZE/NF_BLOCK_SIZE) )
yaffs_devconfig()函数的代码如下:
位置:yaffs2/yaffs2/yaffscfg2k.c
int yaffs_devconfig(char *_mp, int start_block, int end_block)
{
struct yaffs_dev *dev = NULL;
char *mp = NULL;
dev = malloc(sizeof(*dev));
mp = strdup(_mp);
if (!dev || !mp)
{
/* Alloc error */
printf("Failed to allocate memory\n");
return -1;
}
/* Seems sane, so configure */
memset(dev, 0, sizeof(*dev));
dev->param.name = mp;
dev->param.is_yaffs2 = 1;
dev->param.total_bytes_per_chunk = NF_PAGE_SIZE;
dev->param.spare_bytes_per_chunk = NF_SPARE_SIZE;
dev->param.chunks_per_block = NF_BLOCK_SIZE / NF_PAGE_SIZE;
dev->param.start_block = start_block;
dev->param.end_block = end_block;
dev->param.n_reserved_blocks = 8;
dev->param.inband_tags = 0;
dev->param.use_nand_ecc = 0;
dev->param.no_tags_ecc = 0;
dev->param.n_caches=0;
dev->param.empty_lost_n_found = 1;
dev->param.skip_checkpt_rd = 0;
dev->param.skip_checkpt_wr = 0;
dev->param.refresh_period = 1000;
dev->param.initialise_flash_fn = ynf_init;
dev->param.erase_fn = ynf_erase_block;
dev->param.write_chunk_tags_fn = ynf_write_chunk_tags;
dev->param.read_chunk_tags_fn = ynf_read_chunk_tags;
dev->param.bad_block_fn = ynf_mark_block_bad;
dev->param.query_block_fn = ynf_query_block;
dev->driver_context = NULL;
yaffs_add_device(dev);
printf("Configures yaffs mount %s: start block %d, end block %d %s\n",
mp, start_block, end_block, dev->param.inband_tags ? "using inband tags" : "");
return 0;
}
其中主要是有一个重要的数据结构体struct yaffs_dev,如下
代码清单 struct yaffs_dev结构体
struct yaffs_dev {
struct yaffs_param param;
/* Context storage. Holds extra OS specific data for this device */
void *os_context;
void *driver_context;
struct list_head dev_list;
/* Runtime parameters. Set up by YAFFS. */
int data_bytes_per_chunk;
/* Non-wide tnode stuff */
u16 chunk_grp_bits; /* Number of bits that need to be resolved if
* the tnodes are not wide enough.
*/
u16 chunk_grp_size; /* == 2^^chunk_grp_bits */
/* Stuff to support wide tnodes */
u32 tnode_width;
u32 tnode_mask;
u32 tnode_size;
/* Stuff for figuring out file offset to chunk conversions */
u32 chunk_shift; /* Shift value */
u32 chunk_div; /* Divisor after shifting: 1 for 2^n sizes */
u32 chunk_mask; /* Mask to use for power-of-2 case */
int is_mounted;
int read_only;
int is_checkpointed;