Detailed explanation of network porting and debugging of u-boot in linux system

​Today I will tell you how to improve the transplantation and debugging of the u-boot network part.

1. Reply to the previous chapter

In the previous chapter, we have already talked about how to port the uboot.2022.10 version to our own imx6ull development board, but the network part was not recognized correctly after compiling and downloading. Today we will talk about the debugging of the network part.

After the uboot is compiled, power on and start, the serial port prints as follows:

U-Boot 2022.10-gaef9f25a-dirty (Apr 05 2023 - 17:49:18 +0800)

CPU:   Freescale i.MX6ULL rev1.1 792 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 26C
Reset cause: POR
Model: Freescale i.MX6 UltraLiteLite 14x14 EVK Board
Board: MX6ULL TOTO
DRAM:  512 MiB
Core:  65 devices, 17 uclasses, devicetree: separate
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... OK
In:    serial
Out:   serial
Err:   serial
Net:   Could not get PHY for FEC1: addr 1
Could not get PHY for FEC1: addr 1
Get shared mii bus on ethernet@2188000
Could not get PHY for FEC1: addr 2
Get shared mii bus on ethernet@2188000
Could not get PHY for FEC1: addr 2
No ethernet found.

Hit any key to stop autoboot: 
=> 

By printing the information, we can find that even the phy is not correctly identified. First of all, let’s review. In the previous article, we used the configuration parameters of NXP’s official default imx6ull development board. No parameters have been modified. Now the default configuration network is not correctly identified, indicating that our hardware design deviates from the official design. . Therefore, first of all, we need to check the schematic diagram to confirm whether the default network pins of NXP imx6ull are consistent with our own hardware schematic diagram.

2. Hardware schematic inspection

1. Confirm the phy address corresponding to the fec of the hardware schematic diagram

It can be obtained from the hardware schematic diagram of the imx6ull development board that the phy addr corresponding to ENET1 is: 0x0, and the phy addr corresponding to ENET2 is: 0x1.

picture

picture

2. Modify the phy address of the network card fec1

The device tree file imx6ull-14x14-evk.dtsi corresponding to imx6ull can be obtained from the device tree file. imx6ull  FEC1 corresponds to ethphy0 , and the phy address corresponding to ethphy0 defaults to 2 , which is inconsistent with the phy address given by our development board hardware , so modify the phy address corresponding to FEC1 in the device tree to 0

&fec1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet1>;
    phy-mode = "rmii";
    phy-handle = <&ethphy0>;
    phy-supply = <&reg_peri_3v3>;
    status = "okay";
};

&fec2 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet2>;
    phy-mode = "rmii";
    phy-handle = <&ethphy1>;
    phy-supply = <&reg_peri_3v3>;
    status = "okay";    

    mdio {
        #address-cells = <1>;
        #size-cells = <0>;

        ethphy0: ethernet-phy@2 {
            compatible = "ethernet-phy-id0022.1560";
            reg = <2>;
            ...
        };

        ethphy1: ethernet-phy@1 {
            compatible = "ethernet-phy-id0022.1560";
            reg = <1>;
            ...
        };
    };
};

Modify the phy address corresponding to the FEC1 node to 0x0, as follows;

mdio {
        #address-cells = <1>;
        #size-cells = <0>;

        ethphy0: ethernet-phy@0 {
            compatible = "ethernet-phy-id0022.1560";
            reg = <0>;
            micrel,led-mode = <1>;
            clocks = <&clks IMX6UL_CLK_ENET_REF>;
            clock-names = "rmii-ref";

        };
        ...
    }

Recompile, burn and verify, or report an error.

picture

3. Network initialization check

Next, only start from the network initialization entry initr_net function to see where there is a problem with network initialization.

init_sequence_r call in board_r file

picture

It can be seen that the initr_net function actually has two functions. One is to call eth_initialize to initialize the network, and the other is to call reset_phy to reset the phy. The specific implementation is as follows;

static int initr_net(void)
{
    puts("Net:   ");
    eth_initialize();
#if defined(CONFIG_RESET_PHY_R)
    debug("Reset Ethernet PHY\n");
    reset_phy();
#endif
    return 0;
}

Going on, we can see that only phy_micrel_ksz8xxx_init is called in the phy_init initialization function to initialize the phy of the ksz8 series produced by Micrel , as follows;

int phy_init(void)
{
...
#ifdef CONFIG_PHY_MICREL_KSZ8XXX
    phy_micrel_ksz8xxx_init();
#endif 
#ifdef CONFIG_PHY_MICREL_KSZ90X1
    phy_micrel_ksz90x1_init();
#endif
...
#ifdef CONFIG_PHY_SMSC
    phy_smsc_init();
#endif
...
    genphy_init();

    return 0;
}

Our hardware fec1 and fec2 both use LAN8720A produced by SMSC , so we modify it to call phy_smsc_init to initialize the phy chip LAN8720A.

The specific modification is to add the macro definition CONFIG_PHY_SMSC=y in the mx6ull_toto_defconfig file; then shield CONFIG_PHY_MICREL=y and CONFIG_PHY_MICREL_KSZ8XXX=y, as follows;

picture

picture

4. Fec part pin confirmation

Going on, in the fecmxc_probe function, it is found that the fec_gpio_reset() function is called to reset the fec network card, but the reset pin is not configured in the device tree file

picture

The fecmxc_of_to_plat function will parse the three definitions of phy in the device. So add the following three definitions to the device:

picture

In the hardware schematic diagram, find the eth1 and eth2phy reset pins corresponding to the pins of the imx6ull chip

picture

In the device tree file imx6ul-14x14-evk.dtsi, the specific configuration is as follows:

picture

5. Check whether there is multi-device pin multiplexing

The next thing to do is to check in the device tree file to see if the two GPIO pins just added have multiplexing in other devices.

picture

The search results are as above, the 7 and 8 pins of GPIO5 are used in the spi4 interface, and the status of the device is "okay" active, the solution is as follows, disable the spi4 interface.

picture

Another method is to delete the two lines of definition that use the two pins of gpio5, which will not be demonstrated here.

The compilation verification is as follows

picture

Only one network port will be used under uboot, so one is blocked

6. Use the default ENET2

Use imx6ull default network card ENET2 default network card in uboot , macro definition CONFIG_FEC_ENENT_DEV , path: /include/configs/mx6ull_toto.h

#ifdef CONFIG_CMD_NET
#define CONFIG_FEC_ENET_DEV     1
#endif

Set the status of the FEC1 node to disabled in the device tree file

&fec1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet1>;
    phy-mode = "rmii";
    phy-handle = <&ethphy0>;
    phy-supply = <&reg_peri_3v3>;
    phy-reset-gpios = <&gpio5 7 GPIO_ACTIVE_LOW>; // 复位引脚
    phy-reset-duration = <100>;
    phy-reset-post-delay = <100>;
    status = "disabled";    //禁用
};

3. Compile and burn, download and verify

The SecureCRT output is as follows:

U-Boot 2022.10-g8d3c4ea8-dirty (May 20 2023 - 11:49:18 +0800)

CPU:   Freescale i.MX6ULL rev1.1 792 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 34C
Reset cause: POR
Model: Freescale i.MX6 UltraLiteLite 14x14 EVK Board
Board: MX6ULL TOTO
DRAM:  512 MiB
Core:  61 devices, 17 uclasses, devicetree: separate
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... OK
In:    serial
Out:   serial
Err:   serial
Net:   
Error: ethernet@20b4000 address not set.

Error: ethernet@20b4000 address not set.
No ethernet found.

Hit any key to stop autoboot:  0 
=> 
=>

Prompt:
Error: ethernet@20b4000 address not set.
Error: ethernet@20b4000 address not set.
No ethernet found.

This is because the network environment variable is not set

  • manual setting 

  • System configuration , generated by default

1. Set network environment variables
setenv ethaddr 32:34:46:78:9A:DC    //设置开发板网卡1 MAC地址 
setenv eth1addr 32:34:46:78:9A:DD   //设置开发板网卡2 MAC地址 
setenv serverip 192.168.0.106       //设置服务器地址,一般是windows或Ubuntu地址
setenv ipaddr 192.168.0.123         //设置开发板IP地址 
setenv gatewayip 192.168.0.1        //设置开发板默认网关 
setenv netmask 255.255.255.0        //设置开发板子网掩码
setenv bootdelay 5                  //设置启动延时实际
saveenv                             //将改变覆盖到MMC

Note: The u-boot environment variables are set in MMC and will not be cleared with UBoot recompilation. If the modification is messy, you can use the following command to restore the default:

 
 

env default -a // restore default settings
saveenv // overwrite changes to MMC

2. Use software configuration, default generation

configs/mx6ull_toto_defconfig file, enable random generation of MAC address

CONFIG_NET_RANDOM_ETHADDR=y

Restart the development board, and the printed information is as follows;

 
 

U-Boot 2022.10-g8d3c4ea8-dirty (May 20 2023 - 11:49:18 +0800)

CPU:   Freescale i.MX6ULL rev1.1 792 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 45C
Reset cause: WDOG
Model: Freescale i.MX6 UltraLiteLite 14x14 EVK Board
Board: MX6ULL TOTO
DRAM:  512 MiB
Core:  61 devices, 17 uclasses, devicetree: separate
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... OK
In:    serial
Out:   serial
Err:   serial
Net:   eth1: ethernet@20b4000 [PRIME]
Hit any key to stop autoboot:  0 
=> 
=> 

3. Verify that the network is connected

Use the ping command to verify that the network is working properly

=> ping 192.168.0.106
Using ethernet@20b4000 device

ARP Retry count exceeded; starting again
ping failed; host 192.168.0.106 is not alive
=> 

ping test failed

  • Reason 1: It may be that the Windows firewall is not turned off,

  • Reason 2: LAN8720 initialization needs to be reset, modify the SMSC driver.

    The reason on my side is that ubootLAN8720 initialization is not reset, modify it in the drivers/net/phy/phy.c file:

 
 

int genphy_config_aneg(struct phy_device *phydev)
{
    int result;

    /* SOFT RESET */
    phy_reset(phydev);

    if (phydev->autoneg != AUTONEG_ENABLE)
        return genphy_setup_forced(phydev);

    result = genphy_config_advert(phydev);
    ...
    ...
}

Compile and restart the development board again, and the Ping is successful.

=> ping 192.168.0.106
Using ethernet@20b4000 device
host 192.168.0.106 is alive
=> 

Four, FEC1 network card 1 debugging

It is a little more complicated to use the ENET1 network card. Instead of simply changing the status under the fec2 node to "disabled", you need to modify and add the device tree arch/arm/dts/imx6ul-14x14-evk.dtsi file.

1. Block or delete fec2 node content

/*
&fec2 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet2>;
    phy-mode = "rmii";
    phy-handle = <&ethphy1>;
    phy-supply = <&reg_peri_3v3>;
    phy-reset-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
    phy-reset-duration = <200>;
    phy-reset-post-delay = <100>;
    status = "okay";    

    mdio {
        #address-cells = <1>;
        #size-cells = <0>;

        ethphy0: ethernet-phy@0 {
            compatible = "ethernet-phy-id0022.1560";
            reg = <0>;
            micrel,led-mode = <1>;
            clocks = <&clks IMX6UL_CLK_ENET_REF>;
            clock-names = "rmii-ref";

        };

        ethphy1: ethernet-phy@1 {
            compatible = "ethernet-phy-id0022.1560";
            reg = <1>;
            micrel,led-mode = <1>;
            clocks = <&clks IMX6UL_CLK_ENET2_REF>;
            clock-names = "rmii-ref";
        };
    };
};
*/

2. Add mdio child node under fec1 node
 
 

&fec1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet1>;
    phy-mode = "rmii";
    phy-handle = <&ethphy0>;
    phy-supply = <&reg_peri_3v3>;
    phy-reset-gpios = <&gpio5 7 GPIO_ACTIVE_LOW>;
    phy-reset-duration = <100>;
    phy-reset-post-delay = <100>;
    status = "okay";

    mdio {
        #address-cells = <1>;
        #size-cells = <0>;

        ethphy0: ethernet-phy@0 {
            compatible = "ethernet-phy-id0022.1560";
            reg = <0>;
            micrel,led-mode = <1>;
            clocks = <&clks IMX6UL_CLK_ENET_REF>;
            clock-names = "rmii-ref";
        };
    };
};

3. Add MDIO and MDC pin configuration

Add MDIO and MDC pin configuration in the pinctrl node corresponding to the ENET1 network card

  • Multiplex GPIO1_IO07 as ENET1_MDC pin

  • Multiplex GPIO1_IO06 as ENET1_MDIO pin

 
 

pinctrl_enet1: enet1grp {
    fsl,pins = <
        MX6UL_PAD_GPIO1_IO07__ENET1_MDC     0x1b0b0
        MX6UL_PAD_GPIO1_IO06__ENET1_MDIO    0x1b0b0
        ...
        MX6UL_PAD_ENET1_TX_CLK__ENET1_REF_CLK1  0x4001b031
    >;
};

4. Modify the ENET device to enet0

Modify the macro CONFIG_FEC_ENET_DEV to 0 in include/configs/mu6ull_toto.h, use enet0

#ifdef CONFIG_CMD_NET
#define CONFIG_FEC_ENET_DEV     0
#endif

Compile, download and restart the development board, the printed information is as follows;

U-Boot 2022.10-g8d3c4ea8-dirty (May 20 2023 - 14:19:23 +0800)
CPU:   Freescale i.MX6ULL rev1.1 792 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 40C
Reset cause: WDOG
Model: Freescale i.MX6 UltraLiteLite 14x14 EVK Board
Board: MX6ULL TOTO
DRAM:  512 MiB
Core:  60 devices, 17 uclasses, devicetree: separate
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... OK
In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@2188000
Hit any key to stop autoboot:  0
=>
=> ping 192.168.0.106
Using ethernet@2188000 device
host 192.168.0.106 is alive
=>

So far, imx6ull can use both FEC1 and FEC2 separately under uboot. Interested friends can try how uboot makes fec1 and fec2 two network cards work at the same time.

Guess you like

Origin blog.csdn.net/weixin_41114301/article/details/132590883