s32 nv_flash_write(u8* ptr, u32 size, u32 count, FILE* fp) { s32 ret = -1; u32 len = size*count; struct nv_flash_file_header_stru* ffp = (struct nv_flash_file_header_stru*)fp; u32* sec_off = NULL; struct nv_file_info_stru* file_info; nv_file_debug(NV_FILE_WRITE_API,0,0,size,count); if((NULL == ffp)||(ffp->fp != ffp)) { nv_file_debug(NV_FILE_WRITE_API,1,0,size,count); goto nv_flash_write_err; } switch(ffp->flash_type) { case NV_FILE_BACKUP: sec_off = g_sec_info.nv_bak; file_info = &g_flash_info.bak_sec; break; case NV_FILE_SYS_NV: sec_off = g_sec_info.sys_nv; file_info = &g_flash_info.sys_nv; break; case NV_FILE_DEFAULT: sec_off = g_sec_info.nv_default; file_info = &g_flash_info.def_sec; break; default: return -1; } ret = (s32)nv_mtd_write(ffp,(ffp->off+ffp->seek),len,ptr); if(ret) { nv_file_debug(NV_FILE_WRITE_API,3,(u32)ret,len,ffp->flash_type); goto nv_flash_write_err; } ret = (s32)nv_count_file_sec_info(ffp->name,len,sec_off); if(ret) { nv_file_debug(NV_FILE_WRITE_API,4,(u32)ret,len,ffp->flash_type); goto nv_flash_write_err; } file_info->magic_num = NV_FILE_EXIST; file_info->len = len; file_info->off = 0; ffp->seek += len; return (s32)len; nv_flash_write_err: nv_mntn_record("\n[%s]\n",__func__); nv_flash_help(NV_FILE_WRITE_API); return BSP_ERR_NV_INVALID_PARAM; }
s32 nv_emmc_write(u8* ptr, u32 size, u32 count, FILE* fp) { u32 ret = NV_ERROR; u32 len = size*count; struct nv_emmc_file_header_stru* fd = (struct nv_emmc_file_header_stru*)fp; struct nv_file_info_stru* file_info; nv_file_debug(NV_FILE_WRITE_API,0,0,size,count); if((NULL == fd)||(fd->fp != fd)) { nv_file_debug(NV_FILE_WRITE_API,1,0,size,count); goto nv_flash_write_err; } switch(fd->emmc_type) { case NV_FILE_BACKUP: file_info = &g_emmc_info.bak_sec; break; case NV_FILE_SYS_NV: file_info = &g_emmc_info.sys_nv; break; case NV_FILE_DEFAULT: file_info = &g_emmc_info.def_sec; break; default: return -1; } ret = (u32)nv_mtd_write(fd,(fd->off+fd->seek),len,ptr); if(ret) { nv_file_debug(NV_FILE_WRITE_API,3,ret,len,fd->emmc_type); goto nv_flash_write_err; } file_info->magic_num = NV_FILE_EXIST; file_info->len = len; file_info->off = 0; fd->seek += len; return (s32)len; nv_flash_write_err: nv_mntn_record("\n[%s]\n",__func__); nv_emmc_help(NV_FILE_WRITE_API); return BSP_ERR_NV_INVALID_PARAM; }