常用命令
ifconfig eth0 up 打开eth0 网卡
ifconfig eth0 down 关闭eth0 网卡
ifconfig eth0 promisc 设置网卡eth0为混杂模式
ifconfig eth0 -promisc 取消网卡eth0的混杂模式
ifconfig eth0 192.168.1.100 设置ip地址
ifconfig eth0 hw ether 4A:13:E4:F9:79:74 设置mac地址
ifconfig eth0 192.168.1.100 设置静态ip地址
udhcpc -i eth0 动态获取ip地址
代码路径
内核代码
gmac代码:
gmac代码:
drivers/net/ethernet/allwinner/
sunxi-gmac.c sunxi_gmac_ops.c
phy代码:(一般用内核generic的代码)
linux-4.9/drivers/net/phy
phy.c phy_device.c mdio_bus.c ...
配置代码
linux-4.9的适配
board.dts
730 gmac0: eth@05020000 {
731 phy-rst = <&r_pio PH 19 1 1 1 0>;
732 use_ephy25m = <1>;
733 phy-mode = "rgmii";
734 tx-delay = <7>;
735 rx-delay = <0>;
736 status = "okay";
737 };
调试工具
1.ethtool
ethtool -s eth0 speed 1000 duplex full autoneg on //设置1000M全双工自适应
2.brctl
root@TinaLinux:/# brctl --help
BusyBox v1.27.2 () multi-call binary.
Usage: brctl COMMAND [BRIDGE [INTERFACE]]
Manage ethernet bridges
Commands:
show Show a list of bridges
addbr BRIDGE Create BRIDGE
delbr BRIDGE Delete BRIDGE
addif BRIDGE IFACE Add IFACE to BRIDGE
delif BRIDGE IFACE Delete IFACE from BRIDGE
setageing BRIDGE TIME Set ageing time
setfd BRIDGE TIME Set bridge forward delay
sethello BRIDGE TIME Set hello time
setmaxage BRIDGE TIME Set max message age
setpathcost BRIDGE COST Set path cost
setportprio BRIDGE PRIO Set port priority
setbridgeprio BRIDGE PRIO Set bridge priority
stp BRIDGE [1/yes/on|0/no/off] STP on/off
root@TinaLinux:/# brctl addif br-lan eth0
[ 4312.718522] br-lan: port 1(eth0) entered blocking state
[ 4312.724433] br-lan: port 1(eth0) entered disabled state
[ 4312.730790] device eth0 entered promiscuous mode
root@TinaLinux:/# brctl delif br-lan eth0
[ 4270.518067] device eth0 left promiscuous mode
[ 4270.523335] br-lan: port 1(eth0) entered disabled state
eth0加入和移除网桥时都会有混杂模式的打印
br-lan网桥的配置
> Networking support > Networking options
<*> 802.1d Ethernet Bridging //CONFIG_BRIDGE=y
常用命令
ifconfig eth0 up 打开eth0 网卡
ifconfig eth0 down 关闭eth0 网卡
ifconfig eth0 promisc 设置网卡eth0为混杂模式
ifconfig eth0 -promisc 取消网卡eth0的混杂模式
ifconfig eth0 192.168.1.100 设置ip地址
ifconfig eth0 hw ether 4A:13:E4:F9:79:74 设置mac地址
ifconfig eth0 192.168.1.100 设置静态ip地址
udhcpc -i eth0 动态获取ip地址
代码路径
内核代码
gmac代码:
gmac代码:
drivers/net/ethernet/allwinner/
sunxi-gmac.c sunxi_gmac_ops.c
phy代码:(一般用内核generic的代码)
linux-4.9/drivers/net/phy
phy.c phy_device.c mdio_bus.c ...
配置代码
linux-4.9的适配
board.dts
730 gmac0: eth@05020000 {
731 phy-rst = <&r_pio PH 19 1 1 1 0>;
732 use_ephy25m = <1>;
733 phy-mode = "rgmii";
734 tx-delay = <7>;
735 rx-delay = <0>;
736 status = "okay";
737 };
调试工具
1.ethtool
ethtool -s eth0 speed 1000 duplex full autoneg on //设置1000M全双工自适应
2.brctl
root@TinaLinux:/# brctl --help
BusyBox v1.27.2 () multi-call binary.
Usage: brctl COMMAND [BRIDGE [INTERFACE]]
Manage ethernet bridges
Commands:
show Show a list of bridges
addbr BRIDGE Create BRIDGE
delbr BRIDGE Delete BRIDGE
addif BRIDGE IFACE Add IFACE to BRIDGE
delif BRIDGE IFACE Delete IFACE from BRIDGE
setageing BRIDGE TIME Set ageing time
setfd BRIDGE TIME Set bridge forward delay
sethello BRIDGE TIME Set hello time
setmaxage BRIDGE TIME Set max message age
setpathcost BRIDGE COST Set path cost
setportprio BRIDGE PRIO Set port priority
setbridgeprio BRIDGE PRIO Set bridge priority
stp BRIDGE [1/yes/on|0/no/off] STP on/off
root@TinaLinux:/# brctl addif br-lan eth0
[ 4312.718522] br-lan: port 1(eth0) entered blocking state
[ 4312.724433] br-lan: port 1(eth0) entered disabled state
[ 4312.730790] device eth0 entered promiscuous mode
root@TinaLinux:/# brctl delif br-lan eth0
[ 4270.518067] device eth0 left promiscuous mode
[ 4270.523335] br-lan: port 1(eth0) entered disabled state
eth0加入和移除网桥时都会有混杂模式的打印
br-lan网桥的配置
> Networking support > Networking options
<*> 802.1d Ethernet Bridging //CONFIG_BRIDGE=y
举报