第一步:nvram lib数据结构定义
vendor\mediatek\proprietary\custom\k71v1_64_bsp\cgen\cfgfileinc\CFG_LOGO_File.h
//cczheng add for logo nvram start #ifndef _CFG_LOGO_FILE_H #define _CFG_LOGO_FILE_H typedef struct { unsigned char Array[1024]; }LOGOINDEX_CUSTOM_PARAM_STRUCT; #define CFG_FILE_LOGO_INDEX_REC_SIZE sizeof(LOGOINDEX_CUSTOM_PARAM_STRUCT) #define CFG_FILE_LOGO_INDEX_REC_TOTAL 1 //end #endif
第二步:nvram lib 默认值定义
vendor\mediatek\proprietary\custom\k71v1_64_bsp\cgen\cfgdefault\CFG_LOGO_Default.h
//cczheng add for logo nvram start #ifndef _CFG_LOGO_DEFAULT_FILE_H #define _CFG_LOGO_DEFAULT_FILE_H #include "../cfgfileinc/CFG_LOGO_File.h" LOGOINDEX_CUSTOM_PARAM_STRUCT stLogoDefault = { 0x01,0x00,0x00,0x00,0x0,0x0,0x0,0x0 };//end #endif
第三步:nvram lib id定义
这里的添加节点顺序很关键,需要一一对应,在 AP_CFG_CUSTOM_FILE_MAX_LID 之前添加
vendor\mediatek\proprietary\custom\k71v1_64_bsp\cgen\inc\Custom_NvRam_LID.h
typedef enum { .... AP_CFG_RDCL_FILE_AUDIO_FUNC_SWITCH_PARAM_LID, AP_CFG_CUSTOM_FILE_FUEL_GAUGE_LID, AP_CFG_CUSTOM_FILE_SMARTPA_CALIB_LID, AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID,//cczheng add for logo nvram AP_CFG_CUSTOM_FILE_MAX_LID, } CUSTOM_CFG_FILE_LID; /* smartpa calib version */ #define AP_CFG_CUSTOM_FILE_SMARTPA_CALIB_LID_VERNO "000" // cczheng add for logo nvram start #define AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID_VERNO "000" #endif /* CFG_FILE_LID_H */
第四步:nvram lib id的数据结构和版本号声明
需要和上面的位置对应,添加到最后
vendor\mediatek\proprietary\custom\k71v1_64_bsp\cgen\inc\Custom_NvRam_data_item.h
#ifndef CUSTOM_NVRAM_DATA_ITEM_H #define CUSTOM_NVRAM_DATA_ITEM_H #include "custom_cfg_module_file.h" #include "Custom_NvRam_LID.h" #include "../cfgfileinc/CFG_LOGO_File.h" .... // cczheng add for logo nvram start LID_BIT VER_LID(AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID) LOGOINDEX_CUSTOM_PARAM_STRUCT *CFG_FILE_LOGO_INDEX_REC_TOTAL { };//end END_NVRAM_DATA
第五步:nvram lib内容加入nvram数组中
vendor\mediatek\proprietary\custom\k71v1_64_bsp\cgen\inc\CFG_file_info_custom.h
//cczheng #include "../cfgfileinc/CFG_LOGO_File.h" #include "../cfgdefault/CFG_LOGO_Default.h" const TCFG_FILE g_akCFG_File_Custom[]= { .... { "/mnt/vendor/nvdata/APCFG/APRDCL/smartpa_calib", VER(AP_CFG_CUSTOM_FILE_SMARTPA_CALIB_LID), CFG_FILE_SMARTPA_CALIB_CONFIG_SIZE, CFG_FILE_SMARTPA_CALIB_CONFIG_TOTAL, SIGNLE_DEFUALT_REC, (char *)&smartpa_calib_ConfigDefault, DataReset, NULL }, //cczheng add for logo nvram start { "/mnt/vendor/nvdata/APCFG/APRDEB/LOGO_INDEX", VER(AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID), CFG_FILE_LOGO_INDEX_REC_SIZE, // CFG_FILE_LOGO_INDEX_REC_TOTAL, DEFAULT_ZERO, 0, DataReset, NULL CFG_FILE_LOGO_INDEX_REC_TOTAL, SIGNLE_DEFUALT_REC, (char *)&stLogoDefault, DataReset, NULL },//end };
第六步:nvram lib id需要备份到BinRegion
vendor\mediatek\proprietary\external\nvram\libcustom_nvram\CFG_file_info.c
FileName aBackupToBinRegion[] = { ... {"smartpa_calib", AP_CFG_CUSTOM_FILE_SMARTPA_CALIB_LID}, #endif {"LOGO_INDEX", AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID},//cczheng add for logo nvram }; ... }; pfConvertFunc aNvRamConvertFuncTable[] = { .... NULL,//AP_CFG_RDEB_OMADM_USB_LID NULL,//AP_CFG_REEB_PRODUCT_INFO_LID NULL,//AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID cczheng add ... }; const TABLE_FOR_SPECIAL_LID g_new_nvram_lid[] = { #ifdef MTK_MLC_NAND_SUPPORT { AP_CFG_REEB_PRODUCT_INFO_LID, 0, 2 * 1024 * 1024 }, { AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID, 2 * 1024 * 1024, 1024 * 1024 },//cczheng add #else { AP_CFG_REEB_PRODUCT_INFO_LID, 0, 1024 * 1024 }, { AP_CFG_CUSTOM_FILE_LOGO_INDEX_LID, 1024 * 1024, 1024 * 1024 },//cczheng add #endif ...... };
第七步:整编后烧写验证
adb shell
cd /mnt/vendor/nvdata/APCFG/APRDEB
可以看到 LOGO_INDEX
BT_Addr GPS LOGO_INDEX WIFI WIFI_CUSTOM
或者过滤日志
2020-11-30 16:29:16.116 484-484/? D/NVRAM: NVM_Init Max Lid: 79 2020-11-30 16:29:16.116 484-484/? D/NVRAM: [NVRAM]: info nvram_gpt_flag =1 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/FILE_VER,0 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDEB/BT_Addr,1 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/AUXADC,2 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_Para,3 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_3A,4 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING,5 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_DEFECT,6 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SENSOR,7 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_LENS,8 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/UART,9 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/FACTORY,10 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/BWCS,11 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/HWMON_ACC,12 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/HWMON_GYRO,13 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDEB/OMADM_USB,14 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/Voice_Recognize_Param,15 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/Audio_AudEnh_Control_Opt,16 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/Audio_VOIP_Param,17 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/HWMON_PS,18 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/MD_Type,19 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/EXT_MD_Type,20 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/SDIO,21 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_VERSION,22 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_FEATURE,23 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_GEOMETRY,24 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/APCFG/APRDCL/MD_SBP,25 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING2,26 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING3,27 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING4,28 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING5,29 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING6,30 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING7,31 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING8,32 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING9,33 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING10,34 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING11,35 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_SHADING12,36 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE,37 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE2,38 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE3,39 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE4,40 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE5,41 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE6,42 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE7,43 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE8,44 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE9,45 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE10,46 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE11,47 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_PLINE12,48 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_AF,49 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgfile =/mnt/vendor/nvdata/media/CAMERA_FLASH_CALIBRATION,50 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Sph,51 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/APCFG/APRDEB/GPS,52 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_CompFlt,53 2020-11-30 16:29:16.116 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Effect,54 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/APCFG/APRDEB/WIFI,55 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/APCFG/APRDEB/WIFI_CUSTOM,56 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Sph_Med,57 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Vol_custom,58 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Sph_Dual_Mic,59 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Wb_Sph,60 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/APCFG/APRDEB/PRODUCT_INFO,61 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/APCFG/APRDEB/LOGO_INDEX,62 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Headphone_CompFlt,63 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_gain_table,64 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_ver1_Vol_custom,65 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Hd_Record_Param,66 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Hd_Record_Scene_Table,67 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Buffer_DC_Calibration_Param,68 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/VibSpk_CompFlt,69 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/MusicDRC_CompFlt,70 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/RingToneDRC_CompFlt,71 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_MAGI_CONFERENCE,72 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_HAC_Param,73 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_Sph_Lpbk,74 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/Audio_BT_Gain,75 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/media/AUDIO_FUNC_SWITCH_Param,76 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/APCFG/APRDCL/FG,77 2020-11-30 16:29:16.117 484-484/? D/NVRAM: deal with cfgcustfile =/mnt/vendor/nvdata/APCFG/APRDCL/smartpa_calib,78
===============================================================================
20201201 更新
采用上面的方式添加节点ID到 k71v1_64_bsp 项目名称中,后来遇到的问题
读取 nvram 数据正常,写入 nvram 数据时总是失败,错误日志如下
总是提示 write file error!
D/NVRAM: NVM_GetLIDByName /mnt/vendor/nvdata/APCFG/APRDEB/LOGO_INDEX
D/NVRAM: NVRAM: NVM_GetLIDByName Lid =62
D/NVRAM: 62 is in new nvram partition!!!
D/NVRAM: New NVRAM partition name is /dev/block/platform/bootdevice/by-name/proinfo.
D/NVRAM: RecNum is :1
D/NVRAM: write file error!
D/NVRAM: 62 is in new nvram partition!!!
解决办法
vendor\mediatek\proprietary\bootable\bootloader\lk\platform\mt6765\write_protect.c
注释里面的 set_write_protect(); 调用
if (!bypass_wp) { //set_write_protect(); pal_log_err("write protect Done! \n"); } else pal_log_err("Bypass write protect! \n");
问题根本原因是正常开机情况下, product info 会被 EMMC 写保护挡下 power on write protect权限问题
可以继续优化 如何兼容开机客制化读写nvram 和 power on write protect feature.
通常做法是自行定义控制power on write protect对nvram 和product info 分区的开启和关闭。
如果不采用上面的添加节点方式,而是直接将节点添加到 vendor\mediatek\proprietary\custom\common 目录下,则不会出现写入失败的情况,但是会出现保存成功后回厂或者再次刷机保存数据会丢失。