由于对网卡这块不是很熟悉,误以为网卡驱动也可以简单的配置下DTS就可以正常工作了,实际移植中遇到了些问题。闲话少说,下面开始tqimx6q的网卡驱动移植。
DTS编写
首先在我们的DTS中添加网卡配置,参考sabrelite的DTS,我们可以如下编写:
&fec {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet_1>;
phy-mode = "rgmii";
status = "okay";
};
开始以为添加以上内容后编译并烧写DTB就可以正常工作了,实则不然,还需要添加PHY相关的配置代码。
PHY配置
打开arch/arm/mach-imx/mach-imx6q.c,在宏PHY_ID_AR8031附近做如下修改:
static int ar8035_phy_fixup(struct phy_device *dev)
{
u16 val;
/* Ar803x phy SmartEEE feature cause link status generates glitch,
* which cause ethernet link down/up issue, so disable SmartEEE
*/
phy_write(dev, 0xd, 0x3);
phy_write(dev, 0xe, 0x805d);
phy_write(dev, 0xd, 0x4003);
val = phy_read(dev, 0xe);
phy_write(dev, 0xe, val & ~(1 << 8));
/*
* Enable 125MHz clock from CLK_25M on the AR8031. This
* is fed in to the IMX6 on the ENET_REF_CLK (V22) pad.
* Also, introduce a tx clock delay.
*
* This is the same as is the AR8031 fixup.
*/
ar8031_phy_fixup(dev);
/*check phy power*/
val = phy_read(dev, 0x0);
if (val & BMCR_PDOWN)
phy_write(dev, 0x0, val & ~BMCR_PDOWN);
return 0;
}
#define PHY_ID_AR8035 0x004dd072
static void __init imx6q_enet_phy_init(void)
{
if (IS_BUILTIN(CONFIG_PHYLIB)) {
phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,
ksz9021rn_phy_fixup);
phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,
ksz9031rn_phy_fixup);
phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,
ar8031_phy_fixup);
phy_register_fixup_for_uid(PHY_ID_AR8035, 0xffffffff,
ar8035_phy_fixup);
}
}
即添加AR8035的ID,并初始化AR8035的寄存器,具体的含义我还没有来得及分析,以上修改参考了:
http://lxr.free-electrons.com/source/arch/arm/mach-imx/mach-imx6q.c
完成以上修改之后重新编译uImage和dtb,然后烧写开发板即可。
测试方法
寻求网卡的测试方法目标应该很明确,就是能ping通外网即可,下面是我在tqimx6q上的测试步骤。
Step1. 查看网卡信息
执行命令:
ifconfig -a
效果如下:
@tqimx6q #ifconfig -a
eth0 Link encap:Ethernet HWaddr AA:EF:AE:8A:EA:05
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Step2. 使能网卡eth0,执行命令:
ifconfig eth0 up
效果如下:
@tqimx6q #ifconfig eth0 up
fec 2188000.ethernet eth0: Freescale FEC PHY driver [Generic PHY] (mii_bus:phy_addr=2188000.ethernet:00, irq=-1)
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
@tqimx6q #libphy: 2188000.ethernet:00 - Link is Up - 100/Full
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
Step3. 动态获取IP,执行指令:
udhcpc
效果如下:
@tqimx6q #udhcpc
udhcpc (v1.22.1) started
Sending discover...
Sending select for 192.168.0.106...
Lease of 192.168.0.106 obtained, lease time 86400
Step4. 将动态获取的IP设置给网卡eth0,执行指令:
ifconfig eth0 192.168.0.106
之后可以通过命令查看网卡配置信息:
ifconfig eth0
效果如下:
@tqimx6q #ifconfig eth0 192.168.0.106
@tqimx6q #ifconfig eth0
eth0 Link encap:Ethernet HWaddr AA:EF:AE:8A:EA:05
inet addr:192.168.0.106 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a8ef:aeff:fe8a:ea05/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:253 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24238 (23.6 KiB) TX bytes:1152 (1.1 KiB)
Step5. 设置网关,执行指令:
route add default gw 192.168.0.1
Step6. 通过ping指令测试网络状态,执行指令:
ping 8.8.8.8
效果如下:
@tqimx6q #ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=43 time=77.409 ms
64 bytes from 8.8.8.8: seq=1 ttl=43 time=83.292 ms
64 bytes from 8.8.8.8: seq=2 ttl=43 time=88.236 ms
64 bytes from 8.8.8.8: seq=3 ttl=43 time=80.713 ms
64 bytes from 8.8.8.8: seq=4 ttl=43 time=74.452 ms
64 bytes from 8.8.8.8: seq=5 ttl=43 time=78.627 ms
可见,tqimx6q已经可以ping通谷歌的DNS服务器了。至此,网卡的移植工作就完成了,
上一篇:I.MX6Q(TQIMX6Q/TQE9)学习笔记——新版BSP之CAN移植
下一篇:I.MX6Q(TQIMX6Q/TQE9)学习笔记——新版BSP之USB HOST移植
推荐阅读最新更新时间:2024-11-09 12:59
设计资源 培训 开发板 精华推荐
- 揭秘正确选择探头的5大要素 (泰克原装探头促销,高贵不贵,199元起)
- 一起“充电”,DIY自己专属应急灯
- 泰克福袋:示伴功倍,万能福袋派送中
- 直播主题: 助力“双碳”目标 — ADI 智能工厂方案
- 有奖国产芯直播:先楫800MHz RISC-V MCU高能秀,岂止控4只伺服电机,干货多多
- ELEXCON 2022 深圳国际电子展11月6日(新档期)开幕,速领门票!更有N重好礼等你拿!
- 直播已结束【借助 TI DLP 技术,开始您的下一代4K显示应用设计】
- Microchip 有奖直播|满足汽车电池管理系统 (BMS) 不断发展的安全标准
- TI工业月技术方案深度学习
- 有奖直播|安森美图像传感器,助力汽车、机器视觉和人工智能领域发展