From e3d71839e16bfdf7e3e21355045d7d2765ad52e2 Mon Sep 17 00:00:00 2001 From: diskwu <27161916@qq.com> Date: Tue, 5 Apr 2022 16:27:02 +0800 Subject: [PATCH 1/2] set MAC address by UNIQUE_ID --- bsp/imx6ull-artpi-smart/drivers/drv_eth.c | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bsp/imx6ull-artpi-smart/drivers/drv_eth.c b/bsp/imx6ull-artpi-smart/drivers/drv_eth.c index 13679459f8..6a93f7acaa 100644 --- a/bsp/imx6ull-artpi-smart/drivers/drv_eth.c +++ b/bsp/imx6ull-artpi-smart/drivers/drv_eth.c @@ -299,6 +299,36 @@ static rt_err_t rt_imx6ul_eth_control(rt_device_t dev, int cmd, void *args) /* get MAC address */ if (args) { + OCOTP_Type *ocotp_base; + rt_uint32_t uid[2]; + rt_uint32_t uid_crc = 0; + + ocotp_base = (OCOTP_Type *)rt_ioremap((void*)OCOTP_BASE, 0x1000); + uid[0] = ocotp_base->CFG0; + uid[1] = ocotp_base->CFG1; + LOG_D("UNIQUE_ID is %x%x",uid[0], uid[1]); + uid_crc = uid[0] - uid[1]; + LOG_D("UNIQUE_ID change to 32 bits %x", uid_crc); + + if (imx6ul_device->enet_phy_base_addr == ENET1) + { + imx6ul_device->dev_addr[0] = 0xa8; + imx6ul_device->dev_addr[1] = 0x5e; + imx6ul_device->dev_addr[2] = 0x45; + imx6ul_device->dev_addr[3] = (uid_crc>>16) & 0x7f; + imx6ul_device->dev_addr[4] = (uid_crc>>8) & 0xff; + imx6ul_device->dev_addr[5] = uid_crc & 0xff; + } + else /*if (imx6ul_device->enet_phy_base_addr == ENET2)*/ + { + imx6ul_device->dev_addr[0] = 0xa8; + imx6ul_device->dev_addr[1] = 0x5e; + imx6ul_device->dev_addr[2] = 0x46; + imx6ul_device->dev_addr[3] = (uid_crc >> 16) & 0x7f; + imx6ul_device->dev_addr[4] = (uid_crc >> 8) & 0xff; + imx6ul_device->dev_addr[5] = uid_crc & 0xff; + } + rt_memcpy(args, imx6ul_device->dev_addr, MAX_ADDR_LEN); } else -- Gitee From 90c434807644801f6e48add1e3c5578f81931c68 Mon Sep 17 00:00:00 2001 From: diskwu <27161916@qq.com> Date: Sat, 9 Apr 2022 19:43:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8F=8A=E6=97=B6=E9=87=8A=E6=94=BE?= =?UTF-8?q?=E5=86=85=E5=AD=98=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/imx6ull-artpi-smart/drivers/drv_eth.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bsp/imx6ull-artpi-smart/drivers/drv_eth.c b/bsp/imx6ull-artpi-smart/drivers/drv_eth.c index 6a93f7acaa..582605fda3 100644 --- a/bsp/imx6ull-artpi-smart/drivers/drv_eth.c +++ b/bsp/imx6ull-artpi-smart/drivers/drv_eth.c @@ -306,6 +306,7 @@ static rt_err_t rt_imx6ul_eth_control(rt_device_t dev, int cmd, void *args) ocotp_base = (OCOTP_Type *)rt_ioremap((void*)OCOTP_BASE, 0x1000); uid[0] = ocotp_base->CFG0; uid[1] = ocotp_base->CFG1; + rt_iounmap(ocotp_base); LOG_D("UNIQUE_ID is %x%x",uid[0], uid[1]); uid_crc = uid[0] - uid[1]; LOG_D("UNIQUE_ID change to 32 bits %x", uid_crc); -- Gitee