This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Swapping eth0 and eth1 on AM335x board is not working

Other Parts Discussed in Thread: AM3354

I have a custom board with an AM3354 processor, the design is based on the EVM and has dual Ethernet jacks.


I've configured each port to a different subnet address and confirmed that I can ping each one from my Ubuntu machine and vice versa. What I want to do now is change which Ethernet jack is identified as "eth0" and which one is "eth1".

On my PCB's silkscreen, P64 comes up as "eth0" and P74 comes up as "eth1":

My goal here is to get P74 to come up as "eth0" instead of P64.

By default my device tree is set as such:

&cpsw_emac0 {
	phy_id = <&davinci_mdio>, <1>;
	phy-mode = "rmii";
};

&cpsw_emac1 {
	phy_id = <&davinci_mdio>, <3>;
	phy-mode = "rmii";
};

P64 is MII bus address 1 and relates to "eth0". I can confirm this by plugging in the Ethernet cable to P64 and checking the results of ifconfig ie:

[root /]# ifconfig
eth0      Link encap:Ethernet  HWaddr d0:ff:50:29:e9:0c
          inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
          UP 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)
          Interrupt:56

Then I plug in the cable and I can see the TX bytes have increased:

[root /]# ifconfig
eth0      Link encap:Ethernet  HWaddr d0:ff:50:29:e9:0c
          inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::d2ff:50ff:fe29:e90c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:578 (578.0 B)
          Interrupt:56

And then I execute a "ping" test to the Ubuntu machine I'm connected to it is successful:

[root /]# ping 192.168.0.1 -c 3
PING 192.168.0.1 (192.168.0.1): 56 data bytes
64 bytes from 192.168.0.1: seq=0 ttl=64 time=0.838 ms
64 bytes from 192.168.0.1: seq=1 ttl=64 time=0.425 ms
64 bytes from 192.168.0.1: seq=2 ttl=64 time=0.433 ms

--- 192.168.0.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.425/0.565/0.838 ms

Now when I update the device tree such that the address of each "ethX" port are inverted, ie:

&cpsw_emac0 {
	phy_id = <&davinci_mdio>, <3>;
	phy-mode = "rmii";
};

&cpsw_emac1 {
	phy_id = <&davinci_mdio>, <1>;
	phy-mode = "rmii";
};

I can see that "eth0" now is on P74 as per the ifconfig/plugin Ethernet cable/ifconfig test:

eth0      Link encap:Ethernet  HWaddr d0:ff:50:29:e9:0c
          inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
          ...
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Insert cable:

[root /]# ifconfig
eth0      Link encap:Ethernet  HWaddr d0:ff:50:29:e9:0c
          inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
          ...
          RX bytes:0 (0.0 B)  TX bytes:578 (578.0 B)

But now the ping commands fail:

[root /]# ping 192.168.0.1 -c 3
PING 192.168.0.1 (192.168.0.1): 56 data bytes

--- 192.168.0.1 ping statistics ---
3 packets transmitted, 0 packets received, 100% packet loss

So what am I missing? The "ethX" names clearly switched hardware jacks as expected, but now pings don't work anymore. Is there another step required?

  • Trying out a suggestion I received, I reverted the device tree change (swapping the phy-id address of cpsw_emac0 and 1) and instead tried to swap the devices in the am33xx.dtsi file. I changed this:

    			cpsw_emac0: slave@4a100200 {
    				/* Filled in by U-Boot */
    				mac-address = [ 00 00 00 00 00 00 ];
    			};
    
    			cpsw_emac1: slave@4a100300 {
    				/* Filled in by U-Boot */
    				mac-address = [ 00 00 00 00 00 00 ];
    			};

    to this:

    			cpsw_emac1: slave@4a100200 {
    				/* Filled in by U-Boot */
    				mac-address = [ 00 00 00 00 00 00 ];
    			};
    
    			cpsw_emac0: slave@4a100300 {
    				/* Filled in by U-Boot */
    				mac-address = [ 00 00 00 00 00 00 ];
    			};

    However the results were the same. When I plug the Ethernet cable into the correct port I see the txbytes go up, so I know the logical "flip" from eth1 to eth0 took place, but all ping commands still fail.

  • Hi Mike,

    I will forward this to the Ethernet experts. Not sure if this can be done though.

  • Biser,

        Thanks for forwarding this on, I've seen other posts online about doing it via udev rules, so I know there is some way to do this, just need to figure out what is missing.

     

    I've captured some Wireshark logs which show that when the names "eth0" and "eth1" are switched there is no communication over Ethernet.

    Both logs were captured using the same procedure:

    1) no cable connected originally

    2) Start wireshark on the Ubuntu machine (ethernet attached only to the Ubuntu machine)

    3) power on AM335x board, run "ifconfig" verify there's no RX/TX data

    4) Insert Ethernet cable into "eth0" port (that's P64 in the "normal" case and P74 in the "inverted" case)

    See this message:

    [root /]# [   85.481473] libphy: 4a101000.mdio:03 - Link is Up - 100/Full
    [   85.495349] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

    5) check ifconfig again to verify data is sent on "eth0"

    6) issue ping command from am335x board to the Ubuntu machine (192.168.0.1). Both with the "-I eth0" flag and without.

    7) verify the data was sent with ifconfig

    8) On the Ubuntu box issue a ping command to the board (192.168.0.6)

     

    The trans scripts of these commands can be see in the attached logs.

     * Wireshark normal transfer: (renamed from .pcap because TI forums don't understand that)

    normal_eth_port_wireshark_capture.dat

     * Transcript normal transfer:

    Normal_Ethernet_commands_transcript.txt
    *****************************************
    *****************************************
    *****************************************
    
          On The AM335x based board:
    
    *****************************************
    *****************************************
    *****************************************
    
    [root /]#
    [root /]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fc
              inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
              UP 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)
              Interrupt:56
    
    eth1      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fe
              inet addr:192.168.3.7  Bcast:192.168.3.255  Mask:255.255.255.0
              UP 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
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:40 errors:0 dropped:0 overruns:0 frame:0
              TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:2704 (2.6 KiB)  TX bytes:2704 (2.6 KiB)
    
    [root /]#
    [root /]#
    [root /]# [   72.490758] libphy: 4a101000.mdio:01 - Link is Up - 100/Full
    [   72.497404] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
    
    [root /]#
    [root /]#
    [root /]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fc
              inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::7aa5:4ff:feca:76fc/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 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:0 (0.0 B)  TX bytes:648 (648.0 B)
              Interrupt:56
    
    eth1      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fe
              inet addr:192.168.3.7  Bcast:192.168.3.255  Mask:255.255.255.0
              UP 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
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:6074 errors:0 dropped:0 overruns:0 frame:0
              TX packets:6074 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:261085 (254.9 KiB)  TX bytes:261085 (254.9 KiB)
    
    [root /]#
    [root /]#
    [root /]#
    [root /]# ping -I eth0 192.168.0.1 -c 2
    PING 192.168.0.1 (192.168.0.1): 56 data bytes
    64 bytes from 192.168.0.1: seq=0 ttl=64 time=0.894 ms
    64 bytes from 192.168.0.1: seq=1 ttl=64 time=0.462 ms
    
    --- 192.168.0.1 ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max = 0.462/0.678/0.894 ms
    [root /]#
    [root /]#
    [root /]# ping 192.168.0.1 -c 3
    PING 192.168.0.1 (192.168.0.1): 56 data bytes
    64 bytes from 192.168.0.1: seq=0 ttl=64 time=0.568 ms
    64 bytes from 192.168.0.1: seq=1 ttl=64 time=0.481 ms
    64 bytes from 192.168.0.1: seq=2 ttl=64 time=0.499 ms
    
    --- 192.168.0.1 ping statistics ---
    3 packets transmitted, 3 packets received, 0% packet loss
    round-trip min/avg/max = 0.481/0.516/0.568 ms
    [root /]#
    [root /]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fc
              inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::7aa5:4ff:feca:76fc/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:7 errors:0 dropped:0 overruns:0 frame:0
              TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:610 (610.0 B)  TX bytes:1258 (1.2 KiB)
              Interrupt:56
    
    eth1      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fe
              inet addr:192.168.3.7  Bcast:192.168.3.255  Mask:255.255.255.0
              UP 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
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:16424 errors:0 dropped:0 overruns:0 frame:0
              TX packets:16424 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:653670 (638.3 KiB)  TX bytes:653670 (638.3 KiB)
    
    [root /]#
    
    
    *****************************************
    *****************************************
    *****************************************
    
          On The Ubuntu machine:
    
    *****************************************
    *****************************************
    *****************************************
    
    mike@mike-Qosmio-X770:~/Desktop$ ping -I eth0 192.168.0.6 -c 3
    PING 192.168.0.6 (192.168.0.6) from 192.168.0.1 eth0: 56(84) bytes of data.
    64 bytes from 192.168.0.6: icmp_req=1 ttl=64 time=0.294 ms
    64 bytes from 192.168.0.6: icmp_req=2 ttl=64 time=0.260 ms
    64 bytes from 192.168.0.6: icmp_req=3 ttl=64 time=0.316 ms
    
    --- 192.168.0.6 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2000ms
    rtt min/avg/max/mdev = 0.260/0.290/0.316/0.023 ms
    mike@mike-Qosmio-X770:~/Desktop$ 
    
    

     * Wireshark inverted transfer: (renamed from .pcap because TI forums don't understand that)

    inverted_eth_port_wireshark_capture.dat

     * Transcript inverted transfer:

    Inverted_Ethernet_commands_transcript.txt
    *****************************************
    *****************************************
    *****************************************
    
          On The AM335x based board:
    
    *****************************************
    *****************************************
    *****************************************
    
    
    [root /]#
    [root /]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fe
              inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
              UP 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)
              Interrupt:56
    
    eth1      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fc
              inet addr:192.168.3.7  Bcast:192.168.3.255  Mask:255.255.255.0
              UP 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
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:40 errors:0 dropped:0 overruns:0 frame:0
              TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:2704 (2.6 KiB)  TX bytes:2704 (2.6 KiB)
    
    [root /]# [   85.481473] libphy: 4a101000.mdio:03 - Link is Up - 100/Full
    [   85.495349] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
    
    [root /]#
    [root /]#
    [root /]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fe
              inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::7aa5:4ff:feca:76fe/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:508 (508.0 B)
              Interrupt:56
    
    eth1      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fc
              inet addr:192.168.3.7  Bcast:192.168.3.255  Mask:255.255.255.0
              UP 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
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:7021 errors:0 dropped:0 overruns:0 frame:0
              TX packets:7021 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:300657 (293.6 KiB)  TX bytes:300657 (293.6 KiB)
    
    [root /]#
    [root /]#
    [root /]#
    [root /]# ping -I eth0 192.168.0.1 -c 2
    PING 192.168.0.1 (192.168.0.1): 56 data bytes
    
    --- 192.168.0.1 ping statistics ---
    2 packets transmitted, 0 packets received, 100% packet loss
    [root /]#
    [root /]#
    [root /]# ping 192.168.0.1 -c 3
    PING 192.168.0.1 (192.168.0.1): 56 data bytes
    
    --- 192.168.0.1 ping statistics ---
    3 packets transmitted, 0 packets received, 100% packet loss
    [root /]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fe
              inet addr:192.168.0.6  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::7aa5:4ff:feca:76fe/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:1008 (1008.0 B)
              Interrupt:56
    
    eth1      Link encap:Ethernet  HWaddr 78:a5:04:ca:76:fc
              inet addr:192.168.3.7  Bcast:192.168.3.255  Mask:255.255.255.0
              UP 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
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:20909 errors:0 dropped:0 overruns:0 frame:0
              TX packets:20909 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:805502 (786.6 KiB)  TX bytes:805502 (786.6 KiB)
    
    [root /]#
    
    
    *****************************************
    *****************************************
    *****************************************
    
          On The Ubuntu machine:
    
    *****************************************
    *****************************************
    *****************************************
    
    mike@mike-Qosmio-X770:~$ ping -I eth0 192.168.0.6 -c 3
    PING 192.168.0.6 (192.168.0.6) from 192.168.0.1 eth0: 56(84) bytes of data.
    From 192.168.0.1 icmp_seq=1 Destination Host Unreachable
    From 192.168.0.1 icmp_seq=2 Destination Host Unreachable
    From 192.168.0.1 icmp_seq=3 Destination Host Unreachable
    
    --- 192.168.0.6 ping statistics ---
    3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 1999ms
    pipe 3
    mike@mike-Qosmio-X770:~$ cd Desktop/
    
    

    • Below are the steps on how to swap the logical interface names. Before starting please undo the interface swapping in the dts file. This is a command line example and done from a system that is up.

     

    • Based on how the driver comes up, eth0 is always registered on the first physical interface, if dual mac mode is enabled then the second interface is registered as eth1. The logical device names can be changed with these steps. Should end up with eth0 and eth2 after this is done. In this example eth2  which was eth1 is down.
      • ifconfig -a
      • ifconfig eth0 down
      • ip link set dev eth0 name eth2
      • ifconfig -a
      • ip link set dev eth1 name eth0
      • ifconfig -a
      • ifup eth0
      • iperf -c <ip address of server> -t 30 -i 2
  • Excellent suggestion! This did indeed flip the Ethernet port names, one note

    Schuyler Patton said:
      • ifup eth0

    that line didn't work for some reason, i couldn't "ifup eth0" the line after reconfiguring, I had to "ifconfig eth0 up" but then everything worked as expected.

    The only reason this solution concerns me is because, as far as I can tell, there's no guarantee that it will swap the ports correctly. If the first Ethernet PHY (P64 on my board) is always registered as "eth0", then this works. On the off chance it isn't, then we're flipping the Ethernet names when they shouldn't not be.

    Is there anyway to double check the bus address connected with the logical "ethX" name?

  • Making sure that the interface is the correct name is critical as you point out. The device names are completed by the kernel during a registration process. In fact depending on how your system is designed the first ethernet driver is going to get that name eth0. If the cpsw driver initializes first then that it will be eth0.
    There are probably several ways but I have not looked into this. One method might be on boot before swapping is grab the MAC address for each interface with this command and store it off, perhaps claiming this is port 0 and port 1 MAC address.
    You can read the mac address for an interface using one of these two methods, but again probably more than one way to do this.
    cat /sys/devices/ocp.3/4a100000.ethernet/net/eth0/address or
    hexdump -C /proc/device-tree/ocp/ethernet\@4a100000/slave@4a100200\mac-address
    Then you will have to write a script that takes that stored interfaces and sets or verifies the interface names how you want.
  • I need to amend the previous post, the hexdump of the device tree is the value passed in from u-boot for the ethernet mac ids interface, not the current state. So you could /sys/fs method and verify against the device tree entry. Again this will rely on some scripting magic and could be system dependent on how the MAC ids are assigned for your product.