petalinux在zynq平台移植和双网口实现

petalinux在zynq平台的移植

硬件

1.zynq-7z010;

2.两个mavell,88E1510网卡

软件

1.petalinux2018.2;

2.linux-xlnx-xilinx-v2018;

3.0001-net-macb-Add-MDIO-driver-for-accessing-multiple-PHY-.patch补丁;

4.system-user.dtsi

petalinux环境的搭建

petalinux工程的创建

petalinux工程的配置

petalinux工程的编译

petalinux引导

参考ug1144-petalinux-tools-reference-guide2018.2;

说明:个人使用的Ubuntu,在ubuntu下启动tftp服务器,板子上电,uboot启动后设置serverip,ipaddr 环境变量后,

直接run netboot,就可以引导启动。

问题来了,linux 内核启动后,eth1 始终不通,出现下面现象,

root@i5Prj:~# ifconfig eth1 192.168.1.88 up

IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready;

根据之前VxWorks网口驱动调试的经验,感觉像设备数文件中关于MDIO的描述和内核中MDIO驱动的问题,立即xilinx官网论坛各种找,尝试了各个同行的经验,

1.给petalinux内核打补丁使用0001-net-macb-Add-MDIO-driver-for-accessing-multiple-PHY-.patch,感觉没生效,可能自己用的不对(有知道的同行欢迎指导)。

2.参考同行的经验,修改设备树中MDIO描述文件,失败。

最后没办法,通过petalinux-config使用自己下载的内核。(这里还的吐槽一下petalinux,个人不推荐使用默认的petalinux-config,因为你连它的内核在什么位置你都找不到!!!当然你可以通过petalinux-config 

Run petalinux-config, and go into linux Components Selection ---> sub-menu,
For kernel, select linux-kernel () ---> and then select ext-local-src
( ) linux-xlnx
( ) remote
(X) ext-local-src

将自己的内核代码放在指定的目录,这样你就可以找到自己的内核,因为我就是这样做的)

解决办法

第一步 改变内核路径:

改变了petalinux-config配置内核为自己的内核路径后,为自己的内核代码后(因为petalinux版本是2018.2,自己的内核代码也是2018.2的版本,尝试使用了2016.2的版本,结果编译失败,就再没有尝试)。

第二步 打补丁:

根据xilinx官网论坛https://forums.xilinx.com/t5/Embedded-Linux/Dual-Ethernet-over-MII-MDIO-not-working-in-Petalinux-SDK-2018-2/m-p/892810#M28854下载补丁,将下载的补丁放在/drivers/net/ethernet/cadences目录下,打补丁的方式参考了

https://blog.csdn.net/qq_22918577/article/details/49103865博主的方法。

执行 patch  -p1   < ./0001-net-macb-Add-MDIO-driver-for-accessing-multiple-PHY-.patch

第三步 修改system-user.dtsi,下面贴出我的设备树文件中关于MDIO的描述,

/include/ "system-conf.dtsi"
/ {
    mdio{
                #address-cells = <0x1>;
                #size-cells = <0x0>;
                compatible = "cdns,macb-mdio";
                reg = <0xe000b000 0x1000>;
               clocks = <&clkc 30>, <&clkc 30>, <&clkc 13>;               
                clock-names = "pclk", "hclk", "tx_clk"; /* Don't touch */
                ethernet_phy0: ethernet-phy@0 {
                      compatible = "marvell,88E1510";
                      device_type = "ethernet-phy";
                        reg = <0>;
                };
                ethernet_phy1: ethernet-phy@1 {
                      compatible = "marvell,88E1510";
                      device_type = "ethernet-phy";
                       reg = <1>;
                };
        };
};
    &gem0 {
            status = "okay";
            local-mac-address = [00 0a 35 00 00 00];
            phy-handle = <&ethernet_phy0>;

        };
    &gem1 {
            status = "okay";
            local-mac-address = [00 0a 35 00 00 01];
            phy-handle = <&ethernet_phy1>;
        };
究竟system-user.dtsi的配置成什么样,具体还得根据自己板子的硬件、驱动的源码解析进行相应的修改。

第四步 编译petalinux-build

第五步 引导启动petalinux

linux kernel 启动后,配置相应的PC的IP地址,我的板子这边配置为如下,

root@i5Prj:~# ifconfig eth0 192.168.0.88 up
root@i5Prj:~# ifconfig eth1 192.168.1.88 up
root@i5Prj:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0A:35:00:22:01  
          inet addr:192.168.0.88  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20a:35ff:fe00:2201%lo/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1206 (1.1 KiB)  TX bytes:3334 (3.2 KiB)
          Interrupt:30 Base address:0xb000 

eth1      Link encap:Ethernet  HWaddr 00:0A:35:00:00:01  
          inet addr:192.168.1.88  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20a:35ff:fe00:1%lo/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1894 (1.8 KiB)  TX bytes:2532 (2.4 KiB)
          Interrupt:31 Base address:0xc000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%1/128 Scope:Host
          UP LOOPBACK RUNNING  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:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@i5Prj:~# ping 192.168.1.2 
PING 192.168.1.2 (192.168.1.2): 56 data bytes
64 bytes from 192.168.1.2: seq=0 ttl=64 time=0.309 ms
64 bytes from 192.168.1.2: seq=1 ttl=64 time=0.252 ms
64 bytes from 192.168.1.2: seq=2 ttl=64 time=0.282 ms
64 bytes from 192.168.1.2: seq=3 ttl=64 time=0.248 ms

root@i5Prj:~# ping 192.168.0.2
PING 192.168.0.2 (192.168.0.2): 56 data bytes
64 bytes from 192.168.0.2: seq=0 ttl=64 time=0.312 ms
64 bytes from 192.168.0.2: seq=1 ttl=64 time=0.257 ms
64 bytes from 192.168.0.2: seq=2 ttl=64 time=0.242 ms
64 bytes from 192.168.0.2: seq=3 ttl=64 time=0.240 ms

两个网口终于都可以ping通了。

猜你喜欢

转载自blog.csdn.net/xu20151111/article/details/89561229