From 0e1af6876131ef098618636693b9f0a83ef447ea Mon Sep 17 00:00:00 2001 From: hanwckf Date: Tue, 19 Dec 2023 22:56:03 +0800 Subject: [PATCH] switch: add switch_ctl.init to restart mt753x ports when LAN reload --- package/mtk/applications/switch/Makefile | 4 +++- .../applications/switch/files/switch_ctl.init | 16 ++++++++++++++++ .../mtk/applications/switch/files/switch_ctl.sh | 8 ++++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 package/mtk/applications/switch/files/switch_ctl.init diff --git a/package/mtk/applications/switch/Makefile b/package/mtk/applications/switch/Makefile index cdfdf88d80..661e944010 100644 --- a/package/mtk/applications/switch/Makefile +++ b/package/mtk/applications/switch/Makefile @@ -42,8 +42,10 @@ endef define Package/switch/install $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_DIR) $(1)/lib/network - $(INSTALL_BIN) $(PKG_BUILD_DIR)/switch $(1)/usr/sbin + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) $(PKG_BUILD_DIR)/switch $(1)/usr/sbin/ $(INSTALL_BIN) ./files/switch_ctl.sh $(1)/usr/sbin/ + $(INSTALL_BIN) ./files/switch_ctl.init $(1)/etc/init.d/switch_ctl endef $(eval $(call BuildPackage,switch)) diff --git a/package/mtk/applications/switch/files/switch_ctl.init b/package/mtk/applications/switch/files/switch_ctl.init new file mode 100644 index 0000000000..eab3b660fa --- /dev/null +++ b/package/mtk/applications/switch/files/switch_ctl.init @@ -0,0 +1,16 @@ +#!/bin/sh /etc/rc.common + +START=99 +USE_PROCD=1 + +service_triggers() { + procd_add_reload_interface_trigger "lan" +} + +start_service() { + logger -t "switch_ctl" "restart mt753x all ports" + source "/usr/sbin/switch_ctl.sh" + sw_poweroff_ports "0 1 2 3 4" + sleep 3 + sw_poweron_ports "0 1 2 3 4" +} diff --git a/package/mtk/applications/switch/files/switch_ctl.sh b/package/mtk/applications/switch/files/switch_ctl.sh index 39f35258ec..2a75d356c7 100755 --- a/package/mtk/applications/switch/files/switch_ctl.sh +++ b/package/mtk/applications/switch/files/switch_ctl.sh @@ -1,6 +1,6 @@ #!/bin/sh -[ ! -x /usr/sbin/switch ] && exit 1 +[ ! -x /usr/sbin/switch ] && return # power off ports # $1 ports list, ex: "1 2 3" @@ -14,7 +14,7 @@ sw_poweroff_ports() { # register 0, bit 11 is power down control bit, set to 1 set_value=$(($ori_value | 0x800)) - switch phy cl22 w $p 0 $set_value + switch phy cl22 w $p 0 $set_value >/dev/null 2>&1 done } @@ -30,7 +30,7 @@ sw_poweron_ports() { # register 0, bit 11 is power down control bit, set to 0 set_value=$(($ori_value & ~0x800)) - switch phy cl22 w $p 0 $set_value + switch phy cl22 w $p 0 $set_value >/dev/null 2>&1 done } # restart Auto-neg on ports @@ -45,6 +45,6 @@ sw_restart_port() { # register 0, bit 9 is Restart Auto-Negotiation bit, set to 1 set_value=$(($ori_value | 0x200)) - switch phy cl22 w $p 0 $set_value + switch phy cl22 w $p 0 $set_value >/dev/null 2>&1 done }