QNX调试笔记[IMX6Q/TQIMX6Q]---网卡驱动调试

采用QNX7.0,采用的BSP为sabreARD.

1.配置mux引脚

由于sabreARD BSP使用的网卡芯片与天嵌的不同,使用的时AR8035,因此需要对引脚进行配置。
在BSP startup 中找到了

mx6q_init_enet();

函数,即为网卡引脚配置函数,根据TQIMX的原理图,将配置函数修改如下:

void mx6q_init_enet(void)
{
    uint32_t reg;
    //modified to TQIMX.6q by zoutianming 2018.8.30

    // RGMII MDIO - transfers control info between MAC and PHY
    pinmux_set_swmux(SWMUX_ENET_MDIO, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_input(SWINPUT_ENET_IPP_IND_MAC0_MDIO,0);

    // RGMII MDC - output from MAC to PHY, provides clock reference for MDIO
    pinmux_set_swmux(SWMUX_ENET_MDC, MUX_CTL_MUX_MODE_ALT1);

    // RGMII TXC - output from MAC, provides clock used by RGMII_TXD[3:0], RGMII_TX_CTL
    pinmux_set_swmux(SWMUX_RGMII_TXC, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_TXC, MX6X_PAD_SETTINGS_ENET);

    // RGMII TXD[3:0] - Transmit Data Output
    pinmux_set_swmux(SWMUX_RGMII_TD0, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_TD0, MX6X_PAD_SETTINGS_ENET);

    pinmux_set_swmux(SWMUX_RGMII_TD1, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_TD1, MX6X_PAD_SETTINGS_ENET);

    pinmux_set_swmux(SWMUX_RGMII_TD2, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_TD2, MX6X_PAD_SETTINGS_ENET);

    pinmux_set_swmux(SWMUX_RGMII_TD3, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_TD3, MX6X_PAD_SETTINGS_ENET);

    // RGMII TX_CTL - contains TXEN on TXC rising edge, TXEN XOR TXERR on TXC falling edge
    pinmux_set_swmux(SWMUX_RGMII_TX_CTL, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_TX_CTL, MX6X_PAD_SETTINGS_ENET);

    // set ENET_REF_CLK to mux mode 1 - TX_CLK, this is a 125MHz input which is driven by the PHY
    pinmux_set_swmux(SWMUX_ENET_REF_CLK, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWMUX_ENET_REF_CLK, MX6X_PAD_SETTINGS_ENET);

    pinmux_set_swmux(SWMUX_RGMII_RXC, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_RXC, MX6X_PAD_SETTINGS_ENET);
    pinmux_set_input(SWINPUT_ENET_IPP_IND_MAC0_RXCLK,0);

    pinmux_set_swmux(SWMUX_RGMII_RD0, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_RD0, MX6X_PAD_SETTINGS_ENET);
    pinmux_set_input(SWINPUT_ENET_IPP_IND_MAC_RXDATA_0,0);

    pinmux_set_swmux(SWMUX_RGMII_RD1, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_RD1, MX6X_PAD_SETTINGS_ENET);
    pinmux_set_input(SWINPUT_ENET_IPP_IND_MAC_RXDATA_1,0);

    pinmux_set_swmux(SWMUX_RGMII_RD2, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_RD2, MX6X_PAD_SETTINGS_ENET);
    pinmux_set_input(SWINPUT_ENET_IPP_IND_MAC_RXDATA_2,0);

    pinmux_set_swmux(SWMUX_RGMII_RD3, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_RD3, MX6X_PAD_SETTINGS_ENET);
    pinmux_set_input(SWINPUT_ENET_IPP_IND_MAC_RXDATA_3,0);

    pinmux_set_swmux(SWMUX_RGMII_RX_CTL, MUX_CTL_MUX_MODE_ALT1);
    pinmux_set_padcfg(SWPAD_RGMII_RX_CTL, MX6X_PAD_SETTINGS_ENET);
    pinmux_set_input(SWINPUT_ENET_IPP_IND_MAC0_RXEN,0);

    /////

    //RST GPIO1_25
    pinmux_set_swmux(SWMUX_ENET_CRS_DV, MUX_CTL_MUX_MODE_ALT5);
    out32(MX6X_GPIO1_BASE + MX6X_GPIO_GDIR, in32(MX6X_GPIO1_BASE + MX6X_GPIO_GDIR) | (1<<25));

    /* RGMII Phy interrupt set to GPIO4[5] */
    pinmux_set_swmux(SWMUX_ENET_RXD1, MUX_CTL_MUX_MODE_ALT5);
    out32(MX6X_GPIO1_BASE + MX6X_GPIO_GDIR, in32(MX6X_GPIO1_BASE + MX6X_GPIO_GDIR) & ~(1<<26));

   /* set up GPIO_16 for timestamps */
    pinmux_set_swmux(SWMUX_ENET_RXD1, MUX_CTL_MUX_MODE_ALT2 | MUX_CTL_SION);
    pinmux_set_input(SWINPUT_ENET_IPG_CLK_RMII, 1);

    /* set ENET_REF_CLK to PLL (not in RevC docs, new definition */
    //reg = in32(MX6X_IOMUXC_BASE + MX6X_IOMUX_GPR1);
    //reg |= (1<<21);
    //out32(MX6X_IOMUXC_BASE + MX6X_IOMUX_GPR1, reg);

    //pinmux_set_swmux(SWMUX_GPIO_0, MUX_CTL_MUX_MODE_ALT0);

    ///


}

2.修改build文件

以上改动后,网卡依然不能使用。
分析src/hardware/devnp/mx6x下的网卡驱动发现,源码中使用了log语句输出日志。
QNX使用slog2info,可以查看日志输出,发现网卡有如下提示:

You must specify a MAC address

搜索发现,来源于mx6q_init函数

    if (mx6q->dying) {
        log(LOG_ERR, "%s(): dying", __FUNCTION__);
        return EOK;
    }

    // Sort out MAC address
    memcpy(cfg->current_address, LLADDR(ifp->if_sadl), ifp->if_addrlen);
    if (memcmp (cfg->current_address, "\0\0\0\0\0\0", 6) == 0) {
        log(LOG_ERR, "%s():You must specify a MAC address", __FUNCTION__);
        return EINVAL;
    }

    // write to MX6Q_PADDR1 and MX6Q_PADDR2 from cfg->current_address
    set_phys_addr(mx6q);

根据注释,这个MAC地址应该来自bootloader或者命令行,但是这个BSP的IPL bootloader中并没有MAC地址相关的设定,因此只能在build文件中输入MAC地址参数,将网卡启动命令更改为如下,即增加了自己设定的MAC地址

    display_msg Starting Networking
    io-pkt-v6-hc -dmx6x mac=fc047aae8fb1 
    if_up -p fec0
    ifconfig fec0 up
    dhclient -nw fec0

3.增加网卡芯片复位语句
根据https://blog.csdn.net/xjhhjx/article/details/78383808

static int
mx6q_attach(struct device *parent, struct device *self, void *aux)

的mx6q_init_phy()前,增加硬件复位代码

    // Do one time PHY initialization 
    //hardware reset of as3805
    // reset phy by hardware
uint32_t* gpio_base_addr = (uint32_t*)mmap_device_memory (NULL, /*MX6X_GPIO_SIZE,*/MX6Q_MAP_SIZE,
                             PROT_READ | PROT_WRITE |
                             PROT_NOCACHE,
                             MAP_SHARED,
                             /*MX6X_GPIO1_BASE*/0x0209C000); //GPIO1
*(gpio_base_addr + 0) &= (~(1<<25));
nic_delay(1);
*(gpio_base_addr + 0) |= 1<<25;
/* unmap the address have been mapped*/
munmap_device_memory(gpio_base_addr, MX6Q_MAP_SIZE);    

重新上电后,即可正常联网了。不过查看slog2info,还会报125MHz信号的错误,等有时间再看看。、

参考资料

[1]http://www.qnx.com/developers/docs/7.0.0/#com.qnx.doc.core_networking/topic/native_drvr.html
[2]https://blog.csdn.net/xjhhjx/article/details/78383808

你可能感兴趣的:(QNX,IMX6Q)