[NVRAM]如何客制化NVRAM item并且备份(附带修改BT、WIFI 地址sample code)

来源:互联网 发布:实况2016优化 编辑:程序博客网 时间:2024/06/18 12:54

[NVRAM]如何客制化NVRAM item并且备份(附带修改BT、WIFI 地址sample code)

1、请先在DCC上下载《Customization in NvRAM》这个文档,文档中有详细nvram的读写方法。
2、确认读写NVRAM LID方法:请在您的project中打开/alps/mediate/source/cgen/xxxxxxx_ENUM文

3、确认读写NVRAM LID方法:其中AP_CFG_RDEB_FILE_WIFI_LID对应的值则为wifi文件所对应的LID,
AP_CFG_RDEB_FILE_BT_ADDR_LID对应为BT的LID.
4、使用nvram的读写API写入BT WIFI地址。(BT WIFI所需的结构体定义如下所示)
5、使用nvram的备份接口进行备份。
Nvram备份接口如下:FileOp_BackupToBinRegion_All();
path:alps\mediatek\source\external\nvram\libfile_op\libfile_op.h
NOTE:调用FileOp_BackupToBinRegion_All();一定检测其返回值来判定最终写入是否OK。
BT WIFI所对应的结构体如下:
/alps/mediatek/custom/common/cgen/cfgdefault/CFG_BT_Default.h
static ap_nvram_btradio_mt6610_struct stBtDefault =
{
{0x00, 0x00, 0x46, 0x66, 0x20, 0x01}, //BT addr
{0x60, 0x00},
{0x23, 0x10, 0x00, 0x00},
{0x06, 0x80, 0x00, 0x06, 0x03, 0x06},
{0x03, 0x40, 0x1F, 0x40, 0x1F, 0x00, 0x04},
{0x80, 0x00},
{0xFF, 0xFF, 0xFF}
};
/alps/mediatek/custom/eagle75v1_2/cgen/cfgdefault/CFG_WIFI_Default.h
WIFI_CFG_PARAM_STRUCT stWifiCfgDefault =
{
0x0103, /* Own Version */
0x0000, /* Peer Version */
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* MAC ADDRESS */
{ 0x00, 0x00 }, /* COUNTRY CODE */
{ 0x28, { 0x00, 0x00, 0x00 },
0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24,
0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A,
0x1A, 0x1A, 0x1A, 0x1A }, /* TX_PWR_PARAM_T */
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 }, /* aucEFUSE */
0x01, // TX_PWR_PARAM_T is VALID
0x00, // 5G band is unsupported
0x00, // 2.4GHz band edge power disabled
0x00,
0x00,
0x00,
0x00,
0x00,
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 }, /* aucReserved2 */
0x0001, /* Own Version */
0x0000, /* Peer Version */
0x0,
0x0,
0x0,
0x0,
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, /* aucTailReserved */
};
sample code
MTK:
#include "libnvram.h"
#include " CFG_WIFI_Default.h "
#include "Custom_NvRam_LID.h"
#define MAX_RETRY_COUNT 20
int main(void)
{
int read_nvram_ready_retry = 0;
char nvram_init_val[32] = {0};
/*make sure nvram restore form bin complete*/
while(read_nvram_ready_retry < MAX_RETRY_COUNT)
{
read_nvram_ready_retry++;
property_get("nvram_init",nvram_init_val,NULL);
if(strcmp(nvram_init_val,"Ready") == 0)
{
break;
}
else
{
usleep(500*1000);
}
}
NVRAM_LOG("Get nvram restore ready retry cc=%d\n",read_nvram_ready_retry);
if(read_nvram_ready_retry >= MAX_RETRY_COUNT)
{
printf("Get nvram restore ready faild\n");
NVRAM_LOG("Get nvram restore ready faild!!!\n");
}
/*how to read nvram wifi struct*/
F_ID fid ;
int rec_size = 0;
int rec_num = 0;
Int your_file_lid = AP_CFG_RDEB_FILE_WIFI_LID;
bool isread = ture;//ture for read
WIFI_CFG_PARAM_STRUCT * pstWifiCfg_value = NULL;
pstWifiCfg_value =( WIFI_CFG_PARAM_STRUCT *) malloc(sizeof(WIFI_CFG_PARAM_STRUCT));
If(pstWifiCfg_value == NULL)
return false;
fid = NVM_GetFileDesc(file_lid, &rec_size, &rec_num, isread );
If(fid. iFileDesc <0)
return false;
If(rec_size != read(fid.iFileDesc, pstWifiCfg_valu,rec_size)){
free(pstWifiCfg_valu );
return false;}
//…………………………………………………………………………………………
free(your_lid_struct);
if(!NVM_CloseFileDesc(fid))
return false;
//………………………读出pstWifiCfg_value之后可以按照WIFI_CFG_PARAM_STRUCT结构,修改相应
的wifi地址值。
//……………..修改wifi之后,再按上面的流程,将WIFI_CFG_PARAM_STRUCT写入nvram。
最后:
If(!FileOp_BackupToBinRegion_All())//此API风险较高,因此只能在产线内使用,一定要检测其
返回值是否OK,如果false则需要继续调用一次,直至成功。
reture false;
return true;
}

0 0