系统版本:Ubuntu18.04-64
编译器版本:gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)
uboot版本:2018.07 -linux4sam_6.0
板子型号:at91sama5d3x-xplained
MCU型号:sama5d36
内核中调试驱动,和uboot中会有些区别,因为内核启动过程是顺序启动的,硬件上电后,外部的器件要快速做好准备工作,内核代码初始化到这个器件如果器件没有完成上电复位,很可能会驱动失败,需要硬件和软件时序同步,这是非常重要的一点。
【Datasheet】PHY KSZ9031千兆网络芯片解读
[Linux 底层]U-boot ksz9031网络驱动调试
一、PHY在内核配置中需要使能对应的芯片厂商驱动Micrel公司PHY;
make menuconfig
Device Drivers --->
[*] Network device support --->
[*] Ethernet driver support --->
-*- MDIO bus device drivers ---- //MDIO控制器读取PHY寄存器
-*- PHY Device support and infrastructure --->
<*> Micrel PHYs //Micrel公司的ksz9031和ksz8081
二、修改设备树文件,硬件配置语言,所有的硬件相关信息都需要从设备树中获取。这是新内核的特性。
//arch/arm/boot/dts/at91-sama5d3_xplaint.dts
macb0: ethernet@f0028000 {
phy-mode = "rgmii";
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
ethernet-phy@0 {
reg = <0x0>;
};
};
三、把编译出的zImage烧录进板子,查看打印信息
CAN device driver interface
at91_can f000c000.can: device registered (reg_base=(ptrval), irq=42)
libphy: MACB_mii_bus: probed
Generic PHY f0028000.ethernet-ffffffff:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=f0028000.ethernet-ffffffff:01, irq=POLL)
macb f0028000.ethernet eth0: Cadence GEM rev 0x00020119 at 0xf0028000 irq 43 (ee:ab:c1:d2:e6:c6)
macb f802c000.ethernet: invalid hw address, using random
libphy: MACB_mii_bus: probed
Micrel KSZ8081 or KSZ8091 f802c000.ethernet-ffffffff:01: attached PHY driver [Micrel KSZ8081 or KSZ8091] (mii_bus:phy_addr=f802c000.ethernet-ffffffff:01, irq=49)
macb f802c000.ethernet eth1: Cadence MACB rev 0x0001010c at 0xf802c000 irq 44 (36:d7:c3:e6:2a:c7)
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver5d36
其中,Generic PHY f0028000.ethernet-ffffffff:01;获取到得ID为全FF,硬件地址01;这里获取芯片的ID错误了,可能出错的点有MDIO配置错误,或者设备树配置错误;
不用太担心,可以根据打印的信息,查找对应的代码,添加上一些标识在里面;比如:macb f0028000.ethernet: macb_probe phy_interface=2.接口方式,可以搜索出对应的代码,然后添加Jack标识,再次烧录,即可打印出添加的信息;
linux-at91-linux-4.19-at91driversnetethernetcadencemacb_main.c
static int macb_probe(struct platform_device *pdev)函数添加打印,
使用dev_info,用调试串口把信息打印出来,这是调试的必备手段;
图片
我们下面把PHY的接口方式,PHY ID都打印出来,看看和设备树是否能够对应上;
2、内核的网卡驱动找不到对应的PHY驱动
内核打印信息
macb f0028000.ethernet: Jack macb_probe phy_interface=2.
macb f0028000.ethernet: macb_mii_init name=f0028000.ethernet,id=ffffffff
libphy: MACB_mii_bus: probed
Generic PHY f0028000.ethernet-ffffffff:07: attached PHY driver [Generic PHY] (mii_bus:phy_addr=f0028000.ethernet-ffffffff:07, irq=POLL)
macb f0028000.ethernet eth0: Cadence GEM rev 0x00020119 at 0xf0028000 irq 46 (ee:ab:c1:d2:e6:c6)
macb f802c000.ethernet: invalid hw address, using random
macb f802c000.ethernet: Jack macb_probe phy_interface=7.
macb f802c000.ethernet: macb_mii_init name=f802c000.ethernet,id=ffffffff
libphy: MACB_mii_bus: probed
Generic PHY f802c000.ethernet-ffffffff:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=f802c000.ethernet-ffffffff:01, irq=POLL)
macb f802c000.ethernet eth1: Cadence MACB rev 0x0001010c at 0xf802c000 irq 47 (06:50:95:f8:63:dc)
全是id=ffffffff,怀疑是MDIO有问题
这里只匹配了Ksz8081的驱动;
phy_interface = 2;代表是MII接口
图片
四、继续添加打印信息,PHY外部最多可挂载32个PHY设备,内核是如何做识别的呢,使用for循环扫描的,如果读取到ID不为全FF,则认为是有效的设备,会对该设备进行驱动配对;再往前添加一些打印信息,看看扫描的过程是如何的;
libphy: mdiobus_scan i= 0
libphy: get_phy_device addr=0,get_phy_id=-1,
libphy: mdiobus_scan i= 1
libphy: get_phy_device addr=1,get_phy_id=-1,
libphy: mdiobus_scan i= 2
libphy: get_phy_device addr=2,get_phy_id=-1,
libphy: mdiobus_scan i= 3
libphy: get_phy_device addr=3,get_phy_id=-1,
libphy: mdiobus_scan i= 4
libphy: get_phy_device addr=4,get_phy_id=-1,
libphy: mdiobus_scan i= 5
libphy: get_phy_device addr=5,get_phy_id=-1,
libphy: mdiobus_scan i= 6
libphy: get_phy_device addr=6,get_phy_id=-1,
libphy: mdiobus_scan i= 7
libphy: get_phy_device addr=7,get_phy_id=-1,
libphy: mdiobus_scan i= 8
libphy: get_phy_device addr=8,get_phy_id=-1,
libphy: mdiobus_scan i= 9
libphy: get_phy_device addr=9,get_phy_id=-1,
libphy: mdiobus_scan i= 10
libphy: get_phy_device addr=10,get_phy_id=-1,
libphy: mdiobus_scan i= 11
libphy: get_phy_device addr=11,get_phy_id=-1,
libphy: mdiobus_scan i= 12
libphy: get_phy_device addr=12,get_phy_id=-1,
libphy: mdiobus_scan i= 13
libphy: get_phy_device addr=13,get_phy_id=-1,
libphy: mdiobus_scan i= 14
libphy: get_phy_device addr=14,get_phy_id=-1,
libphy: mdiobus_scan i= 15
libphy: get_phy_device addr=15,get_phy_id=-1,
libphy: mdiobus_scan i= 16
libphy: get_phy_device addr=16,get_phy_id=-1,
libphy: mdiobus_scan i= 17
libphy: get_phy_device addr=17,get_phy_id=-1,
libphy: mdiobus_scan i= 18
libphy: get_phy_device addr=18,get_phy_id=-1,
libphy: mdiobus_scan i= 19
libphy: get_phy_device addr=19,get_phy_id=-1,
libphy: mdiobus_scan i= 20
libphy: get_phy_device addr=20,get_phy_id=-1,
libphy: mdiobus_scan i= 21
libphy: get_phy_device addr=21,get_phy_id=-1,
libphy: mdiobus_scan i= 22
libphy: get_phy_device addr=22,get_phy_id=-1,
libphy: mdiobus_scan i= 23
libphy: get_phy_device addr=23,get_phy_id=-1,
libphy: mdiobus_scan i= 24
libphy: get_phy_device addr=24,get_phy_id=-1,
libphy: mdiobus_scan i= 25
libphy: get_phy_device addr=25,get_phy_id=-1,
libphy: mdiobus_scan i= 26
libphy: get_phy_device addr=26,get_phy_id=-1,
libphy: mdiobus_scan i= 27
libphy: get_phy_device addr=27,get_phy_id=-1,
libphy: mdiobus_scan i= 28
libphy: get_phy_device addr=28,get_phy_id=-1,
libphy: mdiobus_scan i= 29
libphy: get_phy_device addr=29,get_phy_id=-1,
libphy: mdiobus_scan i= 30
libphy: get_phy_device addr=30,get_phy_id=-1,
libphy: mdiobus_scan i= 31
libphy: get_phy_device addr=31,get_phy_id=-1,
libphy: Fixed MDIO Bus: probed
CAN device driver interface
at91_can f000c000.can: device registered (reg_base=(ptrval), irq=45)
macb f0028000.ethernet: Jack macb_probe phy_interface=2.
macb f0028000.ethernet: Jack macb_is_gem gem_ethtool_ops
macb f0028000.ethernet: Jack macb_mdc_clk_div =0x100000
macb f0028000.ethernet: Jack macb_dbw =0x300000,bp->phy_interface=2
libphy: MACB_mii_bus: probed
libphy: get_phy_device addr=0,get_phy_id=25278624,
Generic PHY f0028000.ethernet-ffffffff:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=f0028000.ethernet-ffffffff:00, irq=POLL)
macb f0028000.ethernet eth0: Cadence GEM rev 0x00020119 at 0xf0028000 irq 46 (ee:ab:c1:d2:e6:c6)
macb f802c000.ethernet: invalid hw address, using random
macb f802c000.ethernet: Jack macb_probe phy_interface=7.
macb f802c000.ethernet: Jack macb_is_gem macb_ethtool_ops
macb f802c000.ethernet: Jack macb_mdc_clk_div =0xc00
macb f802c000.ethernet: Jack macb_dbw =0xc00,bp->phy_interface=7
libphy: MACB_mii_bus: probed
libphy: get_phy_device addr=0,get_phy_id=2233697,
Micrel KSZ8081 or KSZ8091 f802c000.ethernet-ffffffff:00: attached PHY driver [Micrel KSZ8081 or KSZ8091] (mii_bus:phy_addr=f802c000.ethernet-ffffffff:00, irq=POLL)
macb f802c000.ethernet eth1: Cadence MACB rev 0x0001010c at 0xf802c000 irq 44 (86:82:71:07:ba:d2)
libphy: MACB_mii_bus: probed
libphy: get_phy_device addr=0,get_phy_id=25278624;其中在地址0上面读取到了PHY的ID,转化为16进制:0xF113644,和手册上面无法对应;但是为什么就是驱动识别不了呢?
更改设备树的PHY芯片地址;
//arch/arm/boot/dts/at91-sama5d3_xplaint.dts
GMAC外部PHY的地址为7,dts中配置的地址为0,地址不匹配,读取不了数据;
macb0: ethernet@f0028000 {
phy-mode = "rgmii";
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
ethernet-phy@0 {
reg = <0x0>;
};
};
改为:
macb0: ethernet@f0028000 {
phy-mode = "mii";
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
ethernet-phy@7{
reg = <0x7>;
};
};
再次下载尝试,打印识别芯片正常,驱动可以正确匹配;
libphy: MACB_mii_bus: probed
libphy: get_phy_device addr=3,get_phy_id=-1,
mdio_bus f0028000.ethernet-ffffffff: MDIO device at address 3 is missing.
libphy: get_phy_device addr=0,get_phy_id=-1,
libphy: get_phy_device addr=1,get_phy_id=-1,
libphy: get_phy_device addr=2,get_phy_id=-1,
libphy: get_phy_device addr=3,get_phy_id=-1,
libphy: get_phy_device addr=4,get_phy_id=-1,
libphy: get_phy_device addr=5,get_phy_id=-1,
libphy: get_phy_device addr=6,get_phy_id=-1,
libphy: get_phy_device addr=7,get_phy_id=2233890,
libphy: get_phy_device addr=8,get_phy_id=-1,
libphy: get_phy_device addr=9,get_phy_id=-1,
libphy: get_phy_device addr=10,get_phy_id=-1,
libphy: get_phy_device addr=11,get_phy_id=-1,
libphy: get_phy_device addr=12,get_phy_id=-1,
libphy: get_phy_device addr=13,get_phy_id=-1,
libphy: get_phy_device addr=14,get_phy_id=-1,
libphy: get_phy_device addr=15,get_phy_id=-1,
libphy: get_phy_device addr=16,get_phy_id=-1,
libphy: get_phy_device addr=17,get_phy_id=-1,
libphy: get_phy_device addr=18,get_phy_id=-1,
上一篇:[linux kernel] 内核下ksz8081驱动调试
下一篇:[linux kernel]内核图形化裁剪配置
推荐阅读最新更新时间:2024-11-13 16:32