rk3399 android7.1两种方式读取sn和eth mac地址(这里只列出关键接口,详细代码可以到具体目录文件查看)。他们分别对应读写在不同的地方:idb和vendor storage;
具体代码在uboot下board/rockchip/rk33xx/rk33xx.c实现,,如果没有使用vendor_storage_read读取的代码可自行添加上去:
1、使用rkidb_get_sn读取,具体代码如下:
sn部分:
char tmp_buf[32];
/* rk sn size 30bytes, zero buff */
memset(tmp_buf, 0, 32);
if (rkidb_get_sn(tmp_buf)) {
setenv("fbt_sn#", tmp_buf);
}
eth mac部分:
memset(ethaddr, sizeof(ethaddr), 0);
printf("MAC: boot init with mac address:[ %s ]
", env_str);
if (rkidb_get_mac_address(macaddr) == true) {
sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
printf("mac address: %s
", ethaddr);
2、使用vendor_storage_read读取,具体代码如下:
#define SN_ID 1
#define LAN_MAC_ID 3
sn部分:
memset(sn2_buf, 0, 32);
ret = vendor_storage_init(); //初始化vendor storage分区
if (ret) {
printf("SN: vendor_storage_init failed %d
", ret);
return -ENODEV;
}
ret = vendor_storage_read(SN_ID, sn2_buf, 32); //get sn from vendor storage
if (ret < 0) {
printf("SN: read size %d
", ret);
return -EINVAL;
} else if(strncmp(env_sn, sn2_buf, strlen(sn2_buf)) != 0) {
printf("SN: sn from vendor storage: %s
", sn2_buf);
}
eth mac部分:
ret = vendor_storage_init();
if (ret) {
printf("LAN MAC: vendor_storage_init failed %d
", ret);
return -ENODEV;
}
ret = vendor_storage_read(LAN_MAC_ID, lanmac, 6);
if (ret < 0) {
printf("LAN MAC: read size %d
", ret);
return -EINVAL;
}
sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
lanmac[0], lanmac[1], lanmac[2], lanmac[3], lanmac[4], lanmac[5]);
printf("MAC: get mac from vendor storage: %s
", ethaddr);
写号工具:
1、如果代码使用rkidb_get_sn接口读的话,对应使用以下烧写工具写号:
UpgradeDllTool_1.37
2、如果代码使用vendor_storage_read接口读的话,对应使用以下烧写工具写号:
RKDevInfoWriteTool
原作者:平仄散人
|