u32 nv_read_write_test(void) { u32 i; u32 ret; struct nv_ctrl_file_info_stru* ctrl_info = (struct nv_ctrl_file_info_stru*)NV_GLOBAL_CTRL_INFO_ADDR; struct nv_ref_data_info_stru* ref_info = (struct nv_ref_data_info_stru*)(NV_GLOBAL_CTRL_INFO_ADDR+NV_GLOBAL_CTRL_INFO_SIZE\ +NV_GLOBAL_FILE_ELEMENT_SIZE*ctrl_info->file_num); u8* pdata; pdata = (u8*)nv_malloc(3072); if(NULL == pdata) { return NV_ERROR; } for(i = 0;i<ctrl_info->ref_count;i++) { printf("*****************read & write 0x%x****************\n",ref_info->itemid); ret = bsp_nvm_read(ref_info->itemid,pdata,ref_info->nv_len); if(ret) { nv_free(pdata); return ret; } ret = bsp_nvm_write(ref_info->itemid,pdata,ref_info->nv_len); if(ret) { nv_free(pdata); return ret; } ref_info++; } nv_free(pdata); return NV_OK; }
u32 nv_write_test02(void) { u32 ret = NV_OK; u32 i = 0; u32 read_data = 0; u32 write_data = 0; for(i = 0;i<100;i++) { printf("\n****************第%d次读写开始**************************\n",i); write_data = i+60; ret = bsp_nvm_write(0xd007,(u8*)&write_data,sizeof(u32)); if(NV_OK != ret) { printf("****write error*****i = %d\n",i); return ret; } ret = bsp_nvm_read(0xd007,(u8*)&read_data,sizeof(u32)); if(ret) { printf("****read error*****i = %d\n",i); return ret; } } return NV_OK; }
u32 nv_write_test06(void) { u32 ret = NV_ERROR; u32 itemid = 0xd007; u32 data = 56; ret = bsp_nvm_write(itemid,(u8*)&data,sizeof(u32)); return ret; }
u32 nv_write_test07(u32 count, u32 data) { u32 ret = NV_ERROR; u32 itemid = 0xD007; u32 i = 0; for(i = 0;i < count; i++) { ret = bsp_nvm_write(itemid,(u8*)&data,sizeof(u32)); } return ret; }
u32 nv_write_test05(void) { u32 ret = NV_ERROR; u32 itemid = 0xd007; u32 data = 56; ret = bsp_nvm_write(itemid,(u8*)&data,sizeof(u16)); if(ret == BSP_ERR_NV_ITEM_LEN_ERR) { return NV_OK; } return ret; }
/* **破坏0xD007的数据,后写入NV 0xD007 **注:串口有CRC校验不过的打印 ** 串口有从工作分区中加载数据的log打印则认为通过 */ u32 nv_crc_write_test01(void) { struct nv_global_ddr_info_stru* ddr_info = (struct nv_global_ddr_info_stru*)NV_GLOBAL_INFO_ADDR; struct nv_ref_data_info_stru ref_info = {}; struct nv_file_list_info_stru file_info = {}; u32 ret = 0; u32 nvid = 0xD007; u32 data = 0; u32 new_data = 0; if(!NV_CRC_CHECK_YES) { printf("CRC mark = 0x%x\n",NV_CRC_CHECK_YES); } ret = nv_search_byid(nvid, (u8 *)NV_GLOBAL_CTRL_INFO_ADDR, &ref_info, &file_info); if(ret) { printf("11111 ret = 0x%x\n", ret); return ret; } data = *(u32 *)(NV_GLOBAL_CTRL_INFO_ADDR + ddr_info->file_info[ref_info.file_id - 1].offset + ref_info.nv_off); data += 2; *(u32 *)(NV_GLOBAL_CTRL_INFO_ADDR + ddr_info->file_info[ref_info.file_id - 1].offset + ref_info.nv_off) = data; nv_flush_cache((void*)NV_GLOBAL_INFO_ADDR, (u32)NV_GLOBAL_INFO_SIZE); ret = bsp_nvm_read(nvid, (u8 *)&data, sizeof(u32)); if(ret) { printf("5555 ret = 0x%x\n", ret); return ret; } data+=2; ret = bsp_nvm_write(nvid, (u8 *)&data, sizeof(u32)); if(ret) { printf("3333 ret = 0x%x\n", ret); return ret; } ret = bsp_nvm_read(nvid, (u8 *)&new_data, sizeof(u32)); if(ret) { printf("6666 ret = 0x%x\n", ret); return ret; } if(new_data != data) { printf("7777 new_data = 0x%x, data = 0x%x ret = 0x%x\n", new_data, data,ret); return ret; } return NV_OK; }
u32 nv_write_test04(void) { u32 ret = NV_ERROR; u32 itemid = 0xffff; u32 datalen = 0; ret = bsp_nvm_write(itemid,(u8*)&datalen,sizeof(u32)); if(ret == BSP_ERR_NV_NO_THIS_ID) { return NV_OK; } return ret; }
u32 nv_write_test03(void) { u32 ret = NV_ERROR; u32 itemid = 0xd007; u8* pdata = NULL; ret = bsp_nvm_write(itemid,pdata,sizeof(u32)); if(ret == BSP_ERR_NV_INVALID_PARAM) { return NV_OK; } return ret; }
u32 nv_crc_write_test04(void) { struct nv_ref_data_info_stru nvArray[10] = {}; u32 count = 0; u32 i = 0; u32 ret = 0; u8 *pOldNvData = NULL; u8 *pNewNvData = NULL; pOldNvData = (u8 *)nv_malloc(NV_MAX_UNIT_SIZE); pNewNvData = (u8 *)nv_malloc(NV_MAX_UNIT_SIZE); if((pOldNvData == NULL)||(pNewNvData == NULL)) { nv_printf("malloc error 1111\n"); return NV_ERROR; } count = nv_test_find_edge_nv(nvArray); for(i = 0; i < count; i++) { ret = bsp_nvm_read(nvArray[i].itemid, (u8 *)pOldNvData, nvArray[i].nv_len); if(ret) { nv_printf("read error 222, nvid = 0x%x\n", nvArray[i].itemid); return ret; } pOldNvData[0]+=2; ret = bsp_nvm_write(nvArray[i].itemid, (u8 *)pOldNvData, nvArray[i].nv_len); if(ret) { nv_printf("read error 3333, nvid = 0x%x\n", nvArray[i].itemid); return ret; } ret = bsp_nvm_read(nvArray[i].itemid, (u8 *)pNewNvData, nvArray[i].nv_len); if((ret)||(pNewNvData[0] != pOldNvData[0])) { nv_printf("read error 4444, nvid = 0x%x\n", nvArray[i].itemid); return ret; } ret = nv_check_ddr_crc(); if(ret) { nv_printf("read error 5555, nvid = 0x%x\n", nvArray[i].itemid); return ret; } } nv_free(pOldNvData); nv_free(pNewNvData); return NV_OK; }
/************************************************************************ *函数原型 : PRIVATE int breathled_nv_save(void) *描述 : 呼吸灯控制参数NV读取初始化 *输入 : 无 *输出 : 无 *返回值 : BR_OK OR BR_ERRO *修改历史 : 1.日 期 : 20131205 修改内容 : 新生成函数 *************************************************************************/ PRIVATE int breathled_nv_save(void) { int ret = 0; printk(KERN_DEBUG"[*Breath-Led*] %s: led parameter nv save.\n", __func__); ret = bsp_nvm_write(NV_ID_LED_PARA, (unsigned char *)(&led_attr_default), sizeof(led_attr_default)); if(NV_OK != ret) { printk(KERN_ERR"[*Breath-Led*] %s: led parameter nv write fail.\n", __func__); return BR_ERROR; } return BR_OK; }
/*循环写入一个NV,测试双核的互斥是否有效*/ u32 nv_crc_write_test05(void) { u32 ret = 0; u32 nvid = 0xD007; u32 data = 0; u32 i = 0; for(i = 0; i < 1000; i++) { printf("\n****************第%d次测试开始**************************\n", i); ret = bsp_nvm_read(nvid, (u8 *)&data, sizeof(u32)); if(ret) { nv_printf("read fail ,ret = 0x%x\n", ret); return ret; } data++; printf("\n****************第%d次测试开始 11111**************************\n", i); DelayMs(g_crc_delay_ctrl, 0); ret = bsp_nvm_write(nvid, (u8 *)&data, sizeof(u32)); if(ret) { nv_printf("write fail ,ret = 0x%x\n", ret); return ret; } } printf("\n****************第%d次测试开始 2222**************************\n", i); data = 20; ret = bsp_nvm_write(nvid, (u8 *)&data, sizeof(u32)); if(ret) { nv_printf("write fail 22222,ret = 0x%x\n", ret); return ret; } return NV_OK; }
/* **测试关机写功能, 需要重新出版本将NV 0xD007的优先级设置为1~6 */ u32 nv_flush_test_00(void) { u32 ret = 0; u32 nvid = 0xD007; u32 data = 0; u32 new_data = 0; ret = bsp_nvm_read(nvid, (u8 *)&data, sizeof(u32)); if(ret) { printf("1111 ret = 0x%x\n", ret); return ret; } data+=2; ret = bsp_nvm_write(nvid, (u8 *)&data, sizeof(u32)); if(ret) { printf("2222 ret = 0x%x\n", ret); return ret; } /*关机写接口*/ ret = bsp_nvm_flush(); if(ret) { printf("3333 ret = 0x%x\n",__func__,ret); return ret; } ret = nv_resume_ddr_from_img(); if(ret) { printf("4444 ret = 0x%x\n", ret); return ret; } ret = bsp_nvm_read(nvid, (u8 *)&new_data, sizeof(u32)); if(ret) { printf("5555 ret = 0x%x\n", ret); return ret; } if(new_data != data) { printf("6666 new_data = 0x%x, data = 0x%x\n", new_data, data); } return NV_OK; }
u32 nv_function_test(void) { u32 i; u32 ret; struct nv_ctrl_file_info_stru* ctrl_info = (struct nv_ctrl_file_info_stru*)NV_GLOBAL_CTRL_INFO_ADDR; struct nv_ref_data_info_stru* ref_info = (struct nv_ref_data_info_stru*)(NV_GLOBAL_CTRL_INFO_ADDR+NV_GLOBAL_CTRL_INFO_SIZE\ +NV_GLOBAL_FILE_ELEMENT_SIZE*ctrl_info->file_num); u8* pdata; u32 start,end; start = bsp_get_slice_value(); pdata = (u8*)nv_malloc(3072); if(NULL == pdata) { return NV_ERROR; } for(i = 0;i<100;i++) { printf("*****************read & write 0x%x****************\n",ref_info->itemid); ret = bsp_nvm_read(ref_info->itemid,pdata,ref_info->nv_len); if(ret) { nv_free(pdata); return ret; } ret = bsp_nvm_write(ref_info->itemid,pdata,ref_info->nv_len); if(ret) { nv_free(pdata); return ret; } ref_info++; } end = bsp_get_slice_value(); nv_free(pdata); printf("[%s]:slice 0x%x\n",__func__,end-start); return NV_OK; }
u32 nv_write_test_08(u32 itemid) { struct nv_file_list_info_stru file_info = {}; struct nv_ref_data_info_stru ref_info = {}; u8* pData = NULL; u32 ret = 0; pData = (u8*)nv_malloc(2*2048); if(NULL == pData) { nv_printf("alloc error\n"); return NV_ERROR; } ret = nv_search_byid(itemid, (u8 *)NV_GLOBAL_CTRL_INFO_ADDR, &ref_info, &file_info); if(ret) { nv_printf("nv_search_byid error\n"); nv_free(pData); return ret; } ret = bsp_nvm_read(itemid, pData, ref_info.nv_len); if(ret) { nv_printf("bsp_nvm_read error, ret = 0x%x 1111\n", ret); return ret; } pData[0]++; ret = bsp_nvm_write(itemid, pData, ref_info.nv_len); if(ret) { nv_printf("bsp_nvm_read error, ret = 0x%x 2222\n", ret); return ret; } nv_free(pData); return NV_OK; }
/* **测试CRC校验码在写入前后是否一致 **同时测试写入的数据是否正确的写入 */ u32 nv_crc_write_test00(void) { struct nv_ctrl_file_info_stru* ctrl_info = (struct nv_ctrl_file_info_stru*)NV_GLOBAL_CTRL_INFO_ADDR; struct nv_global_ddr_info_stru* ddr_info = (struct nv_global_ddr_info_stru*)NV_GLOBAL_INFO_ADDR; struct nv_ref_data_info_stru ref_info = {}; struct nv_file_list_info_stru file_info = {}; u32 ret = 0; u32 nvid = 0xD007; u32 old_data = 0; u32 new_data = 0; u32 skip_crc_count = 0; u32 off = 0; u32 old_crc = 0; u32 new_crc = 0; u32 *pCrcCode = 0; if(!NV_CRC_CHECK_YES) { printf("CRC mark = 0x%x\n",NV_CRC_CHECK_YES); return NV_ERROR; } ret = nv_search_byid(nvid, (u8 *)NV_GLOBAL_CTRL_INFO_ADDR, &ref_info, &file_info); if(ret) { printf("11111 ret = 0x%x\n", ret); return ret; } off = ref_info.nv_off + ddr_info->file_info[ref_info.file_id -1].offset; skip_crc_count = (off - ctrl_info->ctrl_size)/NV_CRC32_CHECK_SIZE; pCrcCode = NV_DDR_CRC_CODE_OFFSET; old_crc = pCrcCode[skip_crc_count]; nv_flush_cache((void*)NV_GLOBAL_INFO_ADDR, (u32)NV_GLOBAL_INFO_SIZE); ret = bsp_nvm_read(nvid, (u8 *)&old_data, sizeof(u32)); if(ret ) { printf("2222 ret = 0x%x\n", ret); return ret; } old_data += 3; ret = bsp_nvm_write(nvid, (u8*)&old_data, sizeof(u32)); if(ret) { printf("3333 ret = 0x%x\n", ret); return ret; } new_crc = *(u32 *)(NV_DDR_CRC_CODE_OFFSET + skip_crc_count); ret = bsp_nvm_read(nvid, (u8 *)&new_data, sizeof(u32)); if(ret) { printf("5555 ret = 0x%x\n", ret); return ret; } if((old_crc == new_crc)||(new_data != old_data)) { printf("4444 ret = 0x%x\n", ret); return NV_ERROR; } return NV_OK; }
/* **破坏DDR中的NV 0xD007 数据,破坏工作分区中的数据,后写入NV 0xD007 **注:串口有CRC校验不过的打印 ** 串口有从工作分区中加载数据的log打印则认为通过 */ u32 nv_crc_write_test02(void) { struct nv_ctrl_file_info_stru* ctrl_info = (struct nv_ctrl_file_info_stru*)NV_GLOBAL_CTRL_INFO_ADDR; struct nv_global_ddr_info_stru* ddr_info = (struct nv_global_ddr_info_stru*)NV_GLOBAL_INFO_ADDR; struct nv_ref_data_info_stru ref_info = {}; struct nv_file_list_info_stru file_info = {}; u32 ret = 0; u32 nvid = 0xD007; u32 data = 0; u32 new_data = 0; if(!NV_CRC_CHECK_YES) { printf("CRC mark = 0x%x\n",NV_CRC_CHECK_YES); } ret = nv_search_byid(nvid, (u8 *)NV_GLOBAL_CTRL_INFO_ADDR, &ref_info, &file_info); if(ret) { printf("11111 ret = 0x%x\n", ret); return ret; } ret = bsp_nvm_read(nvid, (u8 *)&data, sizeof(u32)); if(ret) { printf("2222 ret = 0x%x\n", ret); return ret; } data+=2; *(u32 *)(NV_GLOBAL_CTRL_INFO_ADDR + ddr_info->file_info[ref_info.file_id - 1].offset + ref_info.nv_off) = data; nv_flush_cache((void*)NV_GLOBAL_INFO_ADDR, (u32)NV_GLOBAL_INFO_SIZE); ret = nv_test_destory_img_data((s8 *)NV_IMG_PATH, (s8 *)(NV_IMG_FLAG_PATH), ctrl_info->ctrl_size); if(ret) { printf("[%s]: 3333 ret = 0x%x\n",__func__,ret); return ret; } /*NV数据 CRC校验*/ ret = nv_check_ddr_crc(); if(!ret) { printf("[%s]: 4444 ret = 0x%x\n",__func__,ret); return NV_ERROR; } ret = bsp_nvm_write(nvid, (u8 *)&data, sizeof(u32)); if(ret) { printf("3333 ret = 0x%x\n", ret); return ret; } ret = bsp_nvm_read(nvid, (u8 *)&new_data, sizeof(u32)); if(ret) { printf("6666 ret = 0x%x\n", ret); return ret; } if(new_data != data) { printf("7777 new_data = 0x%x, data = 0x%x ret = 0x%x\n", new_data, data,ret); return ret; } return NV_OK; }