/** * 作用:nandc模块提供对外通过分区名来查找分区表的函数接口 * * 参数: * @partition_name ---分区表的名 * 描述:通过分区名返回分区表信息,查找成功返回分区表指针,查找不成功返回NULL * */ struct ST_PART_TBL * find_partition_by_name(const char *partition_name) { struct ST_PART_TBL * ptable = NULL; ptable_ensure(); ptable = ptable_get_ram_data(); /*遍历所有的分区表信息*/ while(0 != strcmp(PTABLE_END_STR, ptable->name)) { /*查找到就退出*/ if(0 == strcmp(partition_name, ptable->name)) { break; } ptable++; } /*如果不为空就表示查找得所要的分区表信息*/ if(0 == strcmp(PTABLE_END_STR, ptable->name)) { NAND_TRACE(("ERROR: can't find partition %s, function %s\n", partition_name, __FUNCTION__)); return NULL; } return ptable; }
/** * 作用:擦除所有的yaffs文件系统分区 * * 参数: * 无 * * * 描述:擦除所有的yaffs文件系统分区,在升级的过程中使用,擦除所有的yaffs文件系统的分区 */ void bsp_erase_yaffs_partitons(void) { struct ST_PART_TBL * ptable = NULL; struct ptentry ptn; int ret = NANDC_ERROR; ptable_ensure(); ptable = ptable_get_ram_data(); /*遍历所有的分区信息*/ while(0 != strcmp(PTABLE_END_STR, ptable->name)) { /*查找YAFFS文件系统的分区*/ if(ptable->property & DATA_YAFFS) { /* coverity[buffer_size_warning] */ strncpy(ptn.name, ptable->name, 16); ptn.start = ptable->offset; ptn.length = ptable->capacity; NAND_TRACE(("earsing %s, start 0x%x, length 0x%x\n", ptn.name, ptn.start, ptn.length)); ret = flash_erase(&ptn); if(ret) { NAND_TRACE(("[%s] ERROR: erase %s failed, ret = %d\n", __FUNCTION__, ptn.name, ret)); return; } } ptable++; } }
/********************************************************************************** * FUNC NAME: * ptable_parse_mtd_partitions() - external API: get mtd partitions from flash table * * PARAMETER: * @mtd_parts -[output] pointer to mtd partitions * @nr_parts - [output] number of mtd partitions * * * DESCRIPTION: * get mtd partitions from flash table * * CALL FUNC: * *********************************************************************************/ u32 ptable_parse_mtd_partitions(struct mtd_partition** mtd_parts, u32 *nr_parts) { struct ST_PART_TBL * ptable = NULL; struct mtd_partition *parts = NULL; u32 npart; u32 last_end = 0; u32 last_id = 0; if(!(mtd_parts && nr_parts)) { goto ERRO; } /*ensure that there's a ram table exist*/ /*lint -save -e539*/ ptable_ensure(); /*lint -restore*/ ptable_adapt(); #ifdef __FASTBOOT__ /*show all ptable info*/ #ifndef BSP_CONFIG_EDA ptable_show(NULL); #endif #endif ptable = ptable_get_ram_data(); /*get number of partitions*/ npart = 0; while(0 != strcmp(PTABLE_END_STR, ptable->name)) { if(ptable->capacity) /* skip empty part */ { npart++; } ptable++; } /*this memory never free */ parts = himalloc(sizeof(struct mtd_partition) * npart); if(NULL == parts) { hiout(("ptable_to_mtd_partition, error malloc\r\n")); goto ERRO; } memset(parts, 0x00 , (sizeof(struct mtd_partition) * npart)); /*lint -save -e613*/ *mtd_parts = parts; /*lint -restore*/ *nr_parts = npart; /*get address again*/ ptable = ptable_get_ram_data(); /*置0以后重新计算实际转移到MTD的分区数*/ npart = 0; /*form flash table to mtd partitions */ while(0 != strcmp(PTABLE_END_STR, ptable->name)) { /*not first partition (PTABLE_HEAD_STR)*/ if((last_end != ptable->offset) && (0 != last_id)) { hiout(("ptable check error! ")); hiout((ptable->name)); hiout(("\r\n")); goto ERRO; } #ifdef __KERNEL__ if(ptable->property & MOUNT_MTD){ #endif parts->name = ptable->name; parts->offset = ptable->offset; parts->size = ptable->capacity; parts++; npart++; #ifdef __KERNEL__ } #endif last_end = ptable->offset + ptable->capacity; last_id = ptable->image; ptable++; } *nr_parts = npart; return NANDC_OK; ERRO: if(NULL != parts) { hifree(parts); } return NANDC_ERROR; }