How do I add the `switch` section to /etc/board.json?

OpenWrt 22.03.4 is running on a MT7621 CPU, and I tried to add a switch to board.json, but it never worked.

dts as follows:

&gmac0 {
        nvmem-cells = <&macaddr_factory_e000>;
        nvmem-cell-names = "mac-address";
};

&gmac1 {
        status = "okay";
        label = "wan";
        phy-handle = <&ethphy0>;

        nvmem-cells = <&macaddr_factory_e006>;
        nvmem-cell-names = "mac-address";
        mac-address-increment = <1>;
};

&mdio {
        ethphy0: ethernet-phy@0 {
                reg = <0>;
        };
};

&switch0 {
        status = "okay";

        ports {
                port@1 {
                        status = "okay";
                        label = "lan1";
                };

                port@2 {
                        status = "okay";
                        label = "lan2";
                };

                port@3 {
                        status = "okay";
                        label = "lan3";
                };

                port@4 {
                        status = "okay";
                        label = "lan4";
                };
        };
};

Here's how I operate:

  1. Add board name to /etc/board.d/02_network:
# vi /etc/board.d/02_network
ramips_setup_interfaces()
{
        local board="$1"

        case $board in
        my-board)
                ucidef_add_switch "switch0" \
                        "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0" "5@eth1"
                ;;

        ...
}

...
  1. Delete /etc/board.json
# rm -f /etc/board.json /etc/config/network
  1. Reboot
# reboot

After the machine booted, I looked at the /etc/board.json file, without switch section:

# cat /etc/board.json
{
        "model": {
                "id": "mediatek,mt7621-soc",
                "name": "my-board"
        },
        "network": {
                "lan": {
                        "ports": [
                                "lan1",
                                "lan2",
                                "lan3",
                                "lan4"
                        ],
                        "protocol": "static"
                },
                "wan": {
                        "device": "wan",
                        "protocol": "dhcp"
                }
        },
        "system": {
                "hostname": "my-board-ffff"
        }
}

Add normal as follows:

{
        "model": {
                ...
        },
        "switch": {
                "switch0": {
                        "enable": true,
                        "reset": true,
                        "ports": [
                                ...
                        ],
                        "roles": [
                                ...
                        ]
                }
        },
        "network": {
                "lan": {
                        ...
                },
                "wan": {
                        ...
                }
        }
}

How do I add the switch to board.json?

I guess the case for your device simply isn't matched. Remove the /etc/board.json again and trace the execution of /bin/board_detect (sh -x /bin/board_detect) to figure out why your code is not reached.

2 Likes

hi @jow, I execution sh -x /bin/board_detect and found that the board name mismatch, thank you!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.