瑞芯微Rockchip开发者社区
直播中

申换换

7年用户 1513经验值
私信 关注
[经验]

从芯片eFuse中读取出来的RK3368 Chip ID

Platform: RK3368

OS: Android 6.0

Kernel: 3.10.0

rk3368的Chip ID是从芯片eFuse中读取出来的。然后赋值给system_serial_low和system_serial_high.
/proc/cpuinfo中的Serial字段就是用的这两个值。

arch/arm64/boot/dts/rk3368.dtsi

efuse_256@ffb00000 {
	compatible = "rockchip,rk3368-efuse-256";
	reg = <0x0 0xffb00000 0x0 0x8>;
};

arch/arm/mach-rockchip/efuse.c

static void __init rk3288_efuse_init(void)
{
int ret;
pr_err("%s\n", func);

ret = rk3288_efuse_readregs(0, 32, efuse_buf);
if (ret == 32) {
	if (efuse_buf[2] == 0x33 && efuse_buf[3] == 0x86)
		efuse.get_leakage = rk3368_get_leakage;
	else
		efuse.get_leakage = rk3288_get_leakage;
	efuse.efuse_version = rk3288_get_efuse_version();
	efuse.process_version = rk3288_get_process_version();
	rockchip_set_cpu_version((efuse_buf[6] >> 4) & 3);
	rk3288_set_system_serial();
} else {
	pr_err("failed to read eFuse, return %d\n", ret);
}

}

static void __init rk3288_set_system_serial(void)
{
int i;
u8 buf[16];

for (i = 0; i < 8; i++) {
	buf[i] = efuse_buf[8 + (i << 1)];
	buf[i + 8] = efuse_buf[7 + (i << 1)];
}

system_serial_low = crc32(0, buf, 8);
system_serial_high = crc32(system_serial_low, buf + 8, 8);

}

所以可以用Chip ID来生成wifi或者以太网的mac地址:

Wi-Fi:
net/rfkill/rfkill-wlan.c

static int create_wifi_addr_from_system_serial()
{
if (system_serial_low != 0 && system_serial_high != 0) {
wifi_custom_mac_addr[0] = (system_serial_high >> 8) & 0xfe;/* clear multicast bit /
wifi_custom_mac_addr[1] = system_serial_high | 0x02;/
set local assignment bit (IEEE802) */
wifi_custom_mac_addr[2] = system_serial_low >> 24;
wifi_custom_mac_addr[3] = system_serial_low >> 16;
wifi_custom_mac_addr[4] = system_serial_low >> 8;
wifi_custom_mac_addr[5] = system_serial_low;
}
return 0;
}

int rockchip_wifi_mac_addr(unsigned char *buf)
{
char mac_buf[20] = {0};
[url=home.php?mod=space&uid=1999721]@@[/url] -620,6 +635,11 @@ int rockchip_wifi_mac_addr(unsigned char *buf)
wifi_custom_mac_addr[2],wifi_custom_mac_addr[3],wifi_custom_mac_addr[4],wifi_custom_mac_addr[5]);
LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);

 // from the system serial number
 if (!is_valid_ether_addr(wifi_custom_mac_addr)) {
 create_wifi_mac_from_system_serial(wifi_custom_mac_addr);
}

#ifdef ENABLE_WIFI_RAND_MAC


以太网:

drivers/net/ethernet/rockchip/eth_mac.c

int eth_mac_from_system_serial(u8 *addr)
{
if (system_serial_low != 0 && system_serial_high != 0) {
pr_info("[eth]Create an address from the system serial number.\n");
addr[0] = (system_serial_high >> 24) & 0xfe;/* clear multicast bit */
addr[1] = (system_serial_high >> 16) | 0x02;/* set local assignment bit (IEEE802) */
addr[2] = system_serial_low >> 24;
addr[3] = system_serial_low >> 16;
addr[4] = system_serial_low >> 8;
addr[5] = system_serial_low;
}
return 0;
}

+++ b/drivers/net/ethernet/rockchip/gmac/stmmac_main.c
@@ -1691,6 +1691,8 @@ static void stmmac_check_ether_addr(struct stmmac_priv *priv)
if (!is_valid_ether_addr(priv->dev->dev_addr))
eth_mac_idb(priv->dev->dev_addr);
if (!is_valid_ether_addr(priv->dev->dev_addr))

+ ```
eth_mac_from_system_serial(priv->dev->dev_addr);
  • if (!is_valid_ether_addr(priv->dev->dev_addr))
                      eth_hw_addr_random(priv->dev);
      }
    

原作者:D00PING

更多回帖

发帖
×
20
完善资料,
赚取积分