最近需要修改高通SN号,但是工具写入的SN在设置serial number中不生效,所以只能研究SN的产生过程,过程中看了两篇比较好的文档在本篇后面附上
修改高通SN号,需要修改地方有3
1:添加文件/persist/.sc_serialno.bin,其中写入ro.sc.serialno=SN 如ro.sc.serialno=99999999
2:在高通的btnvtool工具代码main函数修改如下:
diff --git a/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp b/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp
index 53f361f..6f96b3a 100755
--- a/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp
+++ b/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp
@@ -112,13 +112,14 @@ int main(int argc, char *argv[])
{"board-address", required_argument, NULL, 'b'},
{"reference-clock", required_argument, NULL, 'r'},
{"enable-clock-sharing", required_argument, NULL, 'c'},
+ {"set-serial_number", no_argument, NULL, 's'},
{"print-all-nv", no_argument, NULL, 'p'},
{"on-boot-config", no_argument, NULL, 'O'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
- c = getopt_long (argc, argv, ":b:c:r:Op",
+ c = getopt_long (argc, argv, ":b:c:r:Ops",
long_options, &option_index);
if (c == -1)
break;
@@ -347,7 +348,51 @@ int main(int argc, char *argv[])
fprintf (stderr, "--clock-sharing: %s \n",
my_nv_item.bt_soc_clk_sharing_type?"Enabled":"Disabled" );
break;
-
+ case 's':
+//add for serial number set
+ {
+ FILE *fp_src = fopen("/persist/.sc_serialno.bin","r");
+ if(fp_src == NULL){
+ fprintf (stderr, "/persist/.sc_serialno.bin not exist !!!\n");
+ }else{
+ char buffer_src[24]={'\0'};
+ fgets(buffer_src,24,fp_src);
+ fclose(fp_src);
+ if(0 != strncmp(buffer_src,"ro.sc.serialno=",15)){
+ fprintf (stderr, "/persist/.sc_serialno.bin file err1 !!!\n");
+ return 0;
+ }else{
+ for(int i=15;i<23;i++){
+ fprintf (stderr, "[%d]!!!\n",buffer_src[i]);
+ if(!(buffer_src[i] >= '0' && buffer_src[i] <= '9')){
+ fprintf (stderr, "/persist/.sc_serialno.bin file err2 !!!\n");
+ return 0;
+ }
+ }
+ char buffer_a_line[50]={0};
+ long cur_pos=0;
+ bool prop_exist = false;
+ FILE *fp_dst = fopen("/vendor/default.prop","r+");
+ if(fp_dst != NULL){
+ while(fgets(buffer_a_line,50,fp_dst)){
+ if(0 == strncmp(buffer_a_line,"ro.sc.serialno",sizeof("ro.sc.serialno")-1)){
+ fseek(fp_dst,0,SEEK_SET);
+ fseek(fp_dst,cur_pos,SEEK_CUR);
+ fputs(buffer_src,fp_dst);
+ prop_exist = true;
+ break;
+ }
+ cur_pos = ftell(fp_dst);
+ }
+ if(prop_exist == false){
+ fputs(buffer_src,fp_dst);
+ }
+ fclose(fp_dst);
+ }
+ }
+ }
+ }
+ break;
default:
printf ("%s: Unrecognized option: %c\n\n", argv[0], optopt);
/* fall through */
@@ -364,6 +409,7 @@ int main(int argc, char *argv[])
printf (" -O\t--on-boot-config\t\tOn boot BD address generation\n");
printf ("\noption flags:\n");
printf (" -h\t--help\t\t\t\tprint this usage message\n");
+ printf (" -s\t\t\t\tset serial_number\n");
return 1;
break;
}
此段代码将/persist/.sc_serialno.bin中的内容写入/vendor/default.prop中。
这个/vendor/default.prop文件中的属性内容在系统启动时由init进程执行时会读入共享内存中,所以可以通过property_get可以获取到ro.sc.serialno=99999999
3:由于系统会使用ro.serialno的值作为SN号,所以修改init.cpp代码,使得系统将属性ro.sc.serialno的值传给ro.serialno
diff --git a/system/core/init/init.cpp b/system/core/init/init.cpp
index e5aa0e2..eb25e23 100755
--- a/system/core/init/init.cpp
+++ b/system/core/init/init.cpp
@@ -471,7 +471,7 @@ static void export_kernel_boot_props() {
const char *dst_prop;
const char *default_value;
} prop_map[] = {
+ //{ "ro.boot.serialno", "ro.serialno", "", },
- { "ro.boot.serialno", "ro.serialno", "", },
{ "ro.boot.mode", "ro.bootmode", "unknown", },
{ "ro.boot.baseband", "ro.baseband", "unknown", },
{ "ro.boot.bootloader", "ro.bootloader", "unknown", },
@@ -1076,9 +1076,6 @@ int main(int argc, char** argv) {
signal_handler_init();
property_load_boot_defaults();
+ std::string value = GetProperty("ro.sc.serialno", "");
+ std::string value_2 = GetProperty("ro.boot.serialno", "");
+ property_set("ro.serialno", (!value.empty()) ? value.c_str() : value_2.c_str());
export_oem_lock_status();
start_property_service();
修改完此三处后,如下动作使其生效:
1:编译mmm vendor/qcom/proprietary/bt/hci_qcomm_init/
生成最新的out/target/product/msm8998/vendor/bin/btnvtool
将其放入/vendor/bin/中:adb push btnvtool /vendor/bin
2:创建/persist/.sc_serialno.bin文件:echo "ro.sc.serialno=99999999" > /persist/.sc_serialno.bin
3:执行btnvtool工具: ./vendor/bin/btnvtool -s
查看/vendor/default.prop是多了一行:ro.sc.serialno=99999999
4:然后重启机器,开机后在设置中查看serial number是99999999
修改完成。
http://blog.csdn.net/u013686019/article/details/53239302
http://yobin.sinaapp.com/topic/2780/android%E7%9A%84deviceid%E7%9A%84%E6%B7%BB%E5%8A%A0