January 16, 2023

Kyu networking -- Look at the Uboot source for the orange pi emac driver

We will want to look at both the emac driver itself and the phy driver. First we run ctags in the U-boot "root" directory.
The emac driver is:
drivers/net/sun8i_emac.c
Immediately the advantage of having done a build for the target we are interested in comes into focus. We can do "ls *.o" and see that the above file is the only file of the dozens in this directory which was actually compiled. In particular, there is a file "sunxi_emac.c" which is highly suggestive, but as it turns out entirely irrelevant.

mdio routines

The sun8i_emac driver defines several routines, then registers them with the mdio subsystem:
	bus->read = sun8i_mdio_read;
        bus->write = sun8i_mdio_write;
        bus->priv = (void *)priv;
        bus->reset = sun8i_mdio_reset;

        return  mdio_register(bus);
The routine mdio_register() is in common/miiphyutil.c

I also see the following calls:

phy_connect()		in drivers/net/phy/phy.c
phy_connect_dev()	in drivers/net/phy/phy.c
phy_config()		in drivers/net/phy/phy.c
The last call is just a call to an "optional" board specific helper:
board_phy_config(phydev);
Of course ctags gives 1000 options for this call, all in "board/vendor..." I take a look in the "board" directory looking for orangepi, allwinner, and then notice "sunxi". Indeed this is it with "board.o" inside. The only thing in board/sunxi/board.c having to do with "phy" is for USB.


Have any comments? Questions? Drop me a line!

Kyu / [email protected]