板子每次重新烧录Android系统两个网口的MAC地址都会改变,可以通过cpu串号计算出两个MAC地址,这样可以保证MAC固定不变且不重复。 1、修改sunxi-gmac.c路径:/OKT507-android-source/longan/kernel/linux-4.9/drivers/net/ethernet/allwinner/sunxi-gmac.c ·添加头文件 ·修改随机生成MAC的部分,将函数geth_check_addr复制一份,分别将两个函数修改成geth_check_addr0和geth_check_addr1,修改内容如下 ·此处分别添加0和1 2、修改etherdevice.h路径:/OKT507-android-source/longan/kernel/linux-4.9/include/linux/etherdevice.h ·添加头文件 ·箭头处的路径为绝对路径,要根据自己的实际情况修改。 ·添加计算MAC地址的内容 static inline int gmac0_mac_from_cpu_serial(u8 *gaddr) { u32 inbuf[16]={0}; u32 outbuf[4]={0}; int ret; ret = sunxi_get_serial((u8 *)inbuf); printk("************Seria_forlinxl\t\t: %04x-----%08x-----%08x\n",inbuf[2], inbuf[1], inbuf[0]); md5_transform(outbuf, inbuf); printk("************Serial_md5_output\t\t: %08x-----%08x-----%08x\n",outbuf[0],outbuf[1],outbuf[2]); gaddr[0] = (outbuf[0] >> 24) & 0xfe;/* clear multicast bit */ gaddr[1] = (outbuf[0] >> 16) | 0x02;/* set local assignment bit (IEEE802) */ gaddr[2] = outbuf[0] >> 8; gaddr[3] = outbuf[0]; gaddr[4] = outbuf[1] >> 24; gaddr[5] = outbuf[1] >> 16;
return 0; }
static inline int gmac1_mac_from_cpu_serial(u8 *gaddr) { u32 inbuf[16]={0}; u32 outbuf[4]={0}; int ret; ret = sunxi_get_serial((u8 *)inbuf); printk("************Seria_forlinxl\t\t: %04x-----%08x-----%08x\n",inbuf[2], inbuf[1], inbuf[0]); md5_transform(outbuf, inbuf); printk("************Serial_md5_output\t\t: %08x-----%08x-----%08x\n",outbuf[0],outbuf[1],outbuf[2]); gaddr[0] = (outbuf[1] >> 8) & 0xfe;/* clear multicast bit */ gaddr[1] = outbuf[1] | 0x02;/* set local assignment bit (IEEE802) */ gaddr[2] = outbuf[2] >> 24; gaddr[3] = outbuf[2] >> 16; gaddr[4] = outbuf[2] >> 8; gaddr[5] = outbuf[2];
return 0; }
|
|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )
GMT+8, 2024-11-22 10:27
Powered by Discuz! X3.4
© 2001-2013 Comsenz Inc.