Abstract:
On the time otp driver initializes, it will check the mac bits of eFuse, when the value is invalid, generate a random mac, and program it to eFuse.
Environment:
i.mx6dl
android-4.2.2
kernel-3.0.35
Changes:
1. kernel_imx/arch/arm/mach-mx6/mx6_fec.c
----------------------------------------------------------------
void __init imx6_init_fec(struct fec_platform_data fec_data)
{
fec_get_mac_addr(fec_data.mac);
if (!is_valid_ether_addr(fec_data.mac))
fec_data.mac[0] = 0x10; // changed by xxx
if (cpu_is_mx6sl())
imx6sl_add_fec(&fec_data);
else
imx6q_add_fec(&fec_data);
}
2. kernel_imx/drivers/char/fsl_otp.c
----------------------------------------------------------------
//add by xxx
static void check_otp_mac(void)
{
unsigned int index_mac0 = 34;
unsigned int index_mac1 = 35;
u32 value_mac0 = 0;
u32 value_mac1 = 0;
u32 value_random_mac0 = 0;
u32 value_random_mac1 = 0;
char otp_mac[6], random_mac[6];
memset(otp_mac, 0, sizeof(otp_mac));
memset(random_mac, 0, sizeof(random_mac));
mutex_lock(&otp_mutex);
//get
if (otp_read_prepare(otp_data)) {
mutex_unlock(&otp_mutex);
return 0;
}
value_mac0 = __raw_readl(REGS_OCOTP_BASE + HW_OCOTP_CUSTn(index_mac0));
value_mac1 = __raw_readl(REGS_OCOTP_BASE + HW_OCOTP_CUSTn(index_mac1));
otp_read_post(otp_data);
mutex_unlock(&otp_mutex);
if(value_mac0 != 0 && value_mac1 != 0)
{
otp_mac[5] = value_mac0 & 0xff;
otp_mac[4] = (value_mac0 >> 8) & 0xff;
otp_mac[3] = (value_mac0 >> 16) & 0xff;
otp_mac[2] = (value_mac0 >> 24) & 0xff;
otp_mac[1] = value_mac1 & 0xff;
otp_mac[0] = (value_mac1 >> 8) & 0xff;
}
printk("otp_mac=%pM\n", otp_mac);
//check
if (!is_valid_ether_addr(otp_mac))
{
random_ether_addr(random_mac);
printk("get random mac:%pM\n", random_mac);
//set
value_random_mac0 = 0;
value_random_mac0 = value_random_mac0 | random_mac[2];
value_random_mac0 = (value_random_mac0 << 8) | random_mac[3];
value_random_mac0 = (value_random_mac0 << 8) | random_mac[4];
value_random_mac0 = (value_random_mac0 << 8) | random_mac[5];
value_random_mac1 = 0;
value_random_mac1 = value_random_mac1 | random_mac[0];
value_random_mac1 = (value_random_mac1 << 8) | random_mac[1];
mutex_lock(&otp_mutex);
if (otp_write_prepare(otp_data)) {
mutex_unlock(&otp_mutex);
return 0;
}
otp_write_bits(index_mac0, value_random_mac0, 0x3e77);
otp_write_bits(index_mac1, value_random_mac1, 0x3e77);
otp_write_post(otp_data);
mutex_unlock(&otp_mutex);
}
}
//end
3. kernel_imx/drivers/char/fsl_otp.c
----------------------------------------------------------------
static int __devinit fsl_otp_probe(struct platform_device *pdev)
{
...
retval = sysfs_create_group(otp_kobj, &attr_group);
if (retval)
goto error;
mutex_init(&otp_mutex);
//add by xxx
check_otp_mac();
//end