OpenWrt support for Sitecom WLR-4100 v1 001

To build the image some additional files need to be modified. I more or less dropped my efforts for formally adding support for the device as wifi appears to be physically broken on my device and I wouldn't be able to test all features. I am still running my build and using it more or less as a managed switch and it appears to be reasonable stable:

I still have my modified source code, but it is based on OpenWRT master sometime after the 19.07 release. Here is my full .dts file and a diff of the changes to other files:

DTS:

/dts-v1/;

#include "rt3352.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
        compatible = "sitecom,wlr-4100-1001", "ralink,rt3352-soc";
        model = "Sitecom WLR-4100 v1 001";

        aliases {
                led-boot = &led_power;
                led-failsafe = &led_power;
                led-running = &led_power;
                led-upgrade = &led_power;
                mdio-gpio0 = &mdio0;
        };

        mdio0: mdio {
                compatible = "virtual,mdio-gpio";
                #address-cells = <1>;
                #size-cells = <0>;
                gpios = <&gpio0 23 GPIO_ACTIVE_HIGH &gpio0 22 GPIO_ACTIVE_HIGH>;
        };

        leds {
                compatible = "gpio-leds";

                led_power: power {
                        label = "wl-4100:amber:power";
                        gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
                };

                ops {
                        label = "wl-4100:white:ops";
                        gpios = <&gpio0 14 GPIO_ACTIVE_LOW>;
                };
        };

        keys {
                compatible = "gpio-keys-polled";
                poll-interval = <20>;

                ops {
                        label = "ops";
                        gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
                        linux,code = <KEY_WPS_BUTTON>;
                };

        };

        rtl8367rb {
                compatible = "realtek,rtl8367b", "rtl8367b";
                mii-bus = <&mdio0>;
                realtek,extif1 = <0 0 1 1 1 1 1 1 2>;
        };
};

&spi0 {
        status = "okay";

        m25p90@0 {
                compatible = "jedec,spi-nor";
                reg = <0>;
                spi-max-frequency = <10000000>;

                partitions {
                        compatible = "fixed-partitions";
                        #address-cells = <1>;
                        #size-cells = <1>;

                        partition@0 {
                                label = "u-boot";
                                reg = <0x0 0x30000>;
                                read-only;
                        };

                        partition@30000 {
                                label = "u-boot-env";
                                reg = <0x30000 0x10000>;
                        };

                        factory: partition@40000 {
                                label = "rf-data";
                                reg = <0x40000 0x10000>;
                                read-only;
                        };

                        partition@50000 {
                                compatible = "denx,uimage";
                                label = "firmware";
                                reg = <0x50000 0x7b0000>;
                        };

                };
        };
};

&pinctrl {
        state_default: pinctrl0 {
                gpio {
                        ralink,group = "i2c", "jtag", "uartf", "mdio";
                        ralink,function = "gpio";
                };
        };
};

&ethernet {
        mtd-mac-address = <&factory 0x4>;
        pinctrl-names = "default";
        pinctrl-0 = <&rgmii_pins>;

        port@5 {
                phy-mode = "rgmii";
        };

};

&esw {
        ralink,rgmii = <1>;
        mediatek,portmap = <0x3f>;
        ralink,fct2 = <0x0002500c>;
        ralink,fpa2 = <0x1f503ffa>;
};

&wmac {
        ralink,mtd-eeprom = <&factory 0>;
};

Diff:

bernardus@prutsbuntu:~/src/openwrt$ git diff HEAD
diff --git a/target/linux/ramips/image/rt305x.mk b/target/linux/ramips/image/rt305x.mk
index 7d145c3992..bb65e29f3b 100644
--- a/target/linux/ramips/image/rt305x.mk
+++ b/target/linux/ramips/image/rt305x.mk
@@ -962,6 +962,18 @@ define Device/sitecom_wl-351
 endef
 TARGET_DEVICES += sitecom_wl-351

+define Device/sitecom_wlr-4100-1001
+  SOC := rt3352
+  BLOCKSIZE := 64k
+  IMAGE_SIZE := 7872k
+  DEVICE_VENDOR := Sitecom
+  DEVICE_MODEL := WLR-4100 v1 001
+  DEVICE_PACKAGES := kmod-switch-rtl8367b kmod-swconfig swconfig kmod-mdio-gpio
+  SUPPORTED_DEVICES += wlr-4100-1001
+  DEFAULT := n
+endef
+TARGET_DEVICES += sitecom_wlr-4100-1001
+
 define Device/skyline_sl-r7205
   SOC := rt3052
   BLOCKSIZE := 64k
diff --git a/target/linux/ramips/rt305x/base-files/etc/board.d/02_network b/target/linux/ramips/rt305x/base-files/etc/board.d/02_network
index 56c786bc95..81fa5eaf78 100755
--- a/target/linux/ramips/rt305x/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/rt305x/base-files/etc/board.d/02_network
@@ -156,6 +156,10 @@ ramips_setup_interfaces()
                ucidef_add_switch "switch0" \
                        "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
                ;;
+       sitecom,wlr-4100-1001)
+               ucidef_add_switch "switch0" \
+                       "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
+               ;;
        sparklan,wcr-150gn)
                ucidef_add_switch "switch0" \
                        "0:lan" "6t@eth0"

Thanks @BAJansen
I saw that you have a github repository, but couldn't find the changes i needed.

Are these 2 files all I need to create a PR?
And do you have any advice on how to build a test image locally? Which approach did you take?

I made a Pullrequest using those 2 files. Would like to test it, but building locally wasn't much of a succes..

Added support for Sitecom wlr4100 v1 001 by JoostvdB94 · Pull Request #4985 · openwrt/openwrt (github.com)

Commented on your github pull request. Besides from just not seeing the switch and therefor no wan/lan it may also need some *.dlf factory image creation. Also in original firmware LABEL/LAN/WIFI use same mac address but the WAN address is a lower number that is magnitudes off other than a couple of numbers up/down.

By using this method and comparing 2 original firmware files from Sitecom I was able to make the header partly match but I'm not sure which other padding $$ | $$$$ Checksize etc is needed since the OEM webinterface still errors about it:

senao-header -r 0x0222 -p 0x004A -t 2

Other strange facts about this device is that the u-boot bootloader reports that the device is a esr9850v(EnGenius ), the Sitecom GPL sources a D-link 615 (see rev G/H).

Sorry for not being active. I'm willing to donate my router to someone who has time for it. I'm living in the Netherlands.