有关需求需要在recovery下读写imei svn,但是通过读写nvram操作相关节点并不能成功,下面主要实现代码和编译异常,而且跟同事沟通的时候了解到即便是可以编译通过也无法调用libnvram.so的相关函数。若有大神路过,请指点一二。
实现代码:
//#include "../../../../external/nvram/libnvram/libnvram.h"//这里已经引入了相关的头文件 #include "libnvram.h" #include "CFG_PRODUCT_INFO_File.h"//struct #include "Custom_NvRam_LID.h"//lid #include "CFG_module_file.h"//module
int read_write(){ int result; F_ID imei_imeisv_nvram_id; int test_fd; int rec_size; int rec_num; nvram_ef_imei_imeisv_struct* imei_imeisv_struct; bool IsRead = true,IsWrite = false; printf("read:\n"); imei_imeisv_nvram_id = NVM_GetFileDesc(AP_CFG_REEB_PRODUCT_INFO_LID, &rec_size, &rec_num,IsRead);//IsRead=true if(imei_imeisv_nvram_id.iFileDesc < 0){ printf("NVM_GetFileDesc failed\n"); return 0; } result = read(imei_imeisv_nvram_id.iFileDesc,&imei_imeisv_struct,rec_num*rec_size); if(result != rec_num*rec_size){ printf("Get file failed\n"); return 0; } printf("---------read---------\n"); printf("svn:%s\n",imei_imeisv_struct->svn); ui->Print("svn:%s\n",imei_imeisv_struct->svn); printf("------------------\n"); if(!NVM_CloseFileDesc(imei_imeisv_nvram_id)) { printf("NVM_CloseFileDesc failed\n"); } printf("write:\n"); imei_imeisv_nvram_id = NVM_GetFileDesc(AP_CFG_REEB_PRODUCT_INFO_LID, &rec_size, &rec_num,IsWrite);//IsWrite=false if(imei_imeisv_nvram_id.iFileDesc < 0){ printf("NVM_GetFileDesc failed\n"); return 0; } imei_imeisv_struct->svn = 55; printf("--------write----------\n"); result = write(imei_imeisv_nvram_id.iFileDesc,&imei_imeisv_struct,rec_num*rec_size); if(result != rec_num*rec_size){ printf("write file failed\n"); return 0; } if(!NVM_CloseFileDesc(imei_imeisv_nvram_id)) { printf("NVM_CloseFileDesc failed\n"); } return 0; }
Android.mk相关修改:
LOCAL_C_INCLUDES := $(MTK_PATH_SOURCE)/external/nvram/libnvram LOCAL_SHARED_LIBRARIES := libnvram
下面是编译异常:
bootable/recovery/recovery.cpp:2088: error: undefined reference to 'NVM_GetFileDesc' bootable/recovery/recovery.cpp:2104: error: undefined reference to 'NVM_CloseFileDesc' bootable/recovery/recovery.cpp:2109: error: undefined reference to 'NVM_GetFileDesc' bootable/recovery/recovery.cpp:2121: error: undefined reference to 'NVM_CloseFileDesc' collect2: error: ld returned 1 exit status
时间: 2024-10-05 05:01:14