From e5a18fdcf66a4c49a7fe91d083837b190c8b8c1c Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Sat, 22 Feb 2020 12:03:35 +0800 Subject: [PATCH 1/6] ncurses: Do not pass both -fPIC and -fpic --- package/libs/ncurses/Makefile | 20 ++++++++++++----- .../patches/103-ncurses-ar-determinism.patch | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 package/libs/ncurses/patches/103-ncurses-ar-determinism.patch diff --git a/package/libs/ncurses/Makefile b/package/libs/ncurses/Makefile index 904d3c1551..e22eb2b893 100644 --- a/package/libs/ncurses/Makefile +++ b/package/libs/ncurses/Makefile @@ -9,9 +9,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ncurses PKG_VERSION:=6.1 -PKG_RELEASE:=1 +PKG_RELEASE:=5 -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=@GNU/$(PKG_NAME) PKG_HASH:=aa057eeeb4a14d470101eff4597d5833dcef5965331be3528c08d99cebaa0d17 @@ -41,7 +40,7 @@ define Package/libncurses URL:=http://www.gnu.org/software/ncurses/ PROVIDES:=libncursesw DEPENDS:= +terminfo - ABI_VERSION:=$(PKG_VERSION) + ABI_VERSION:=6 endef define Package/libncurses-dev @@ -76,6 +75,11 @@ CONFIGURE_ARGS += \ --enable-widec \ --with-build-cppflags=-D_GNU_SOURCE +CONFIGURE_VARS += \ + cf_try_fPIC=no + +HOST_CFLAGS += $(HOST_FPIC) + HOST_CONFIGURE_ARGS += \ --without-cxx \ --without-cxx-binding \ @@ -127,8 +131,10 @@ endef define Package/libncurses/install $(INSTALL_DIR) $(1)/usr/lib for lib in ncurses panel menu form; do \ - $(CP) $(PKG_INSTALL_DIR)/usr/lib/lib$$$${lib}w.so* $(1)/usr/lib/; \ - ln -s lib$$$${lib}w.so $(1)/usr/lib/lib$$$${lib}.so; \ + $(CP) $(PKG_INSTALL_DIR)/usr/lib/lib$$$${lib}w.so.* $(1)/usr/lib/; \ + for so in $(1)/usr/lib/lib$$$${lib}w.so.*; do \ + ln -s $$$${so##*/} $$$${so%w.so*}.so$$$${so##*w.so}; \ + done; \ done endef @@ -146,7 +152,9 @@ endef define Build/InstallDev $(CP) $(PKG_INSTALL_DIR)/* $(1) for lib in ncurses panel menu form; do \ - ln -s lib$$$${lib}w.so $(1)/usr/lib/lib$$$${lib}.so; \ + for so in $(1)/usr/lib/lib$$$${lib}w.so*; do \ + ln -s $$$${so##*/} $$$${so%w.so*}.so$$$${so##*w.so}; \ + done; \ done ln -s . $(1)/usr/include/ncursesw $(TARGET_CROSS)ar rc $(1)/usr/lib/libtinfo.a diff --git a/package/libs/ncurses/patches/103-ncurses-ar-determinism.patch b/package/libs/ncurses/patches/103-ncurses-ar-determinism.patch new file mode 100644 index 0000000000..d4c8f11703 --- /dev/null +++ b/package/libs/ncurses/patches/103-ncurses-ar-determinism.patch @@ -0,0 +1,22 @@ +--- a/aclocal.m4 ++++ b/aclocal.m4 +@@ -451,7 +451,7 @@ AC_REQUIRE([CF_PROG_AR]) + + AC_CACHE_CHECK(for options to update archives, cf_cv_ar_flags,[ + cf_cv_ar_flags=unknown +- for cf_ar_flags in -curvU -curv curv -crv crv -cqv cqv -rv rv ++ for cf_ar_flags in -curvD -curv curv -crv crv -cqv cqv -rv rv + do + + # check if $ARFLAGS already contains this choice +--- a/configure ++++ b/configure +@@ -4503,7 +4503,7 @@ if test "${cf_cv_ar_flags+set}" = set; t + else + + cf_cv_ar_flags=unknown +- for cf_ar_flags in -curvU -curv curv -crv crv -cqv cqv -rv rv ++ for cf_ar_flags in -curvD -curv curv -crv crv -cqv cqv -rv rv + do + + # check if $ARFLAGS already contains this choice From 97700ac6f69180631d18d182c716b1b211f6be68 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Sat, 22 Feb 2020 12:18:50 +0800 Subject: [PATCH 2/6] luci-app-adbyby-plus: fix checked date display --- .../luasrc/model/cbi/adbyby.lua | 2 +- .../root/etc/init.d/adbyby | 330 ++++++++---------- 2 files changed, 145 insertions(+), 187 deletions(-) diff --git a/package/lean/luci-app-adbyby-plus/luasrc/model/cbi/adbyby.lua b/package/lean/luci-app-adbyby-plus/luasrc/model/cbi/adbyby.lua index 66e570dedc..386c480855 100644 --- a/package/lean/luci-app-adbyby-plus/luasrc/model/cbi/adbyby.lua +++ b/package/lean/luci-app-adbyby-plus/luasrc/model/cbi/adbyby.lua @@ -8,7 +8,7 @@ local DL = SYS.exec("head -1 /tmp/adbyby/data/lazy.txt | awk -F' ' '{print $3,$4 local DV = SYS.exec("head -1 /tmp/adbyby/data/video.txt | awk -F' ' '{print $3,$4}'") or "" local NR = SYS.exec("grep -v '^!' /usr/share/adbyby/data/rules.txt | wc -l") local NU = SYS.exec("cat /usr/share/adbyby/data/user.txt | wc -l") -local UD = SYS.exec("cat /tmp/adbyby.updated") or " " +local UD = NXFS.readfile("/tmp/adbyby.updated") or "1970-01-01 00:00:00" local ND = SYS.exec("cat /usr/share/adbyby/dnsmasq.adblock | wc -l") m = Map("adbyby") diff --git a/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby b/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby index e37e4b0a4d..e8db437fed 100755 --- a/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby +++ b/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby @@ -1,209 +1,167 @@ -#!/bin/sh /etc/rc.common -START=99 -STOP=10 +local NXFS = require "nixio.fs" +local SYS = require "luci.sys" +local HTTP = require "luci.http" +local DISP = require "luci.dispatcher" -EXTRA_COMMANDS="add_rule del_rule reload_rule" -PROG_PATH=/usr/share/adbyby -DATA_PATH=$PROG_PATH/data -WAN_FILE=/var/etc/dnsmasq-adbyby.d/03-adbyby-ipset.conf -CRON_FILE=/etc/crontabs/root -CONFIG=adbyby -ipt_n="iptables -t nat" +local DL = SYS.exec("head -1 /tmp/adbyby/data/lazy.txt | awk -F' ' '{print $3,$4}'") or "" +local DV = SYS.exec("head -1 /tmp/adbyby/data/video.txt | awk -F' ' '{print $3,$4}'") or "" +local NR = SYS.exec("grep -v '^!' /usr/share/adbyby/data/rules.txt | wc -l") +local NU = SYS.exec("cat /usr/share/adbyby/data/user.txt | wc -l") +local UD = NXFS.readfile("/tmp/adbyby.updated") or "1970-01-01 00:00:00" +local ND = SYS.exec("cat /usr/share/adbyby/dnsmasq.adblock | wc -l") +m = Map("adbyby") +m.title = translate("Adbyby Plus +") +m.description = translate("Adbyby Plus + can filter all kinds of banners, popups, video ads, and prevent tracking, privacy theft and a variety of malicious websites
Plus + version combination mode can operation with Adblock Plus Host£¬filtering ads without losing bandwidth") -get_config() -{ - config_get_bool enable $1 enable - config_get_bool cron_mode $1 cron_mode - config_get wan_mode $1 wan_mode - config_get_bool block_ios $1 block_ios 0 - config_get_bool mem_mode $1 mem_mode 1 -} +m:section(SimpleSection).template = "adbyby/adbyby_status" -add_rules() -{ - rm -f $DATA_PATH/user.bin - grep -v ^! $PROG_PATH/rules.txt > $DATA_PATH/user.txt - cp $PROG_PATH/rules.txt $DATA_PATH/rules.txt -} +s = m:section(TypedSection, "adbyby") +s.anonymous = true +s:tab("basic", translate("Base Setting")) -add_cron() -{ - if [ $cron_mode -eq 1 ]; then - sed -i '/adblock.sh/d' $CRON_FILE - echo '0 6 * * * /usr/share/adbyby/adblock.sh > /tmp/adupdate.log 2>&1' >> $CRON_FILE - crontab $CRON_FILE - fi -} +o = s:taboption("basic", Flag, "enable") +o.title = translate("Enable") +o.default = 0 +o.rmempty = false -del_cron() -{ - sed -i '/adblock.sh/d' $CRON_FILE - /etc/init.d/cron restart -} +o = s:taboption("basic", ListValue, "wan_mode") +o.title = translate("Running Mode") +o:value("0", translate("Global Mode£¨The slowest, the best effects£©")) +o:value("1", translate("Plus + Mode£¨Filter domain name list and blacklist website.Recommended£©")) +o:value("2", translate("No filter Mode (Must set in Client Filter Mode Settings manually)")) +o.default = 1 +o.rmempty = false -ip_rule() -{ +o = s:taboption("basic", Button, "restart") +o.title = translate("Adbyby and Rule state") +o.inputtitle = translate("Restart Adbyby") +o.description = string.format("Last Update Checked£º %s
Lazy Rule£º%s
Video Rule£º%s", UD, DL, DV) +o.inputstyle = "reload" +o.write = function() + SYS.call("rm -rf /tmp/adbyby.updated && /usr/share/adbyby/admem.sh > /tmp/adupdate.log 2>&1 &") + SYS.call("sleep 5") + HTTP.redirect(DISP.build_url("admin", "services", "adbyby")) +end - ipset -N adbyby_esc hash:ip - $ipt_n -A ADBYBY -m set --match-set adbyby_esc dst -j RETURN - - for i in $(seq 0 100) - do - local ip=$(uci_get_by_type acl_rule ipaddr '' $i) - local mode=$(uci_get_by_type acl_rule filter_mode '' $i) - case "$mode" in - disable) - $ipt_n -A ADBYBY -s $ip -j RETURN - ;; - global) - $ipt_n -A ADBYBY -s $ip -p tcp -j REDIRECT --to-ports 8118 - $ipt_n -A ADBYBY -s $ip -j RETURN - ;; - esac - done - - - - case $wan_mode in - 0) - ;; - 1) - ipset -N adbyby_wan hash:ip - $ipt_n -A ADBYBY -m set ! --match-set adbyby_wan dst -j RETURN - ;; - 2) - $ipt_n -I ADBYBY -j RETURN - ;; - esac - - echo "create blockip hash:net family inet hashsize 1024 maxelem 65536" > /tmp/blockip.ipset - awk '!/^$/&&!/^#/{printf("add blockip %s'" "'\n",$0)}' /usr/share/adbyby/blockip.conf >> /tmp/blockip.ipset - ipset -! restore < /tmp/blockip.ipset 2>/dev/null - iptables -I FORWARD -m set --match-set blockip dst -j DROP - iptables -I OUTPUT -m set --match-set blockip dst -j DROP -} +s:tab("advanced", translate("Advance Setting")) -add_dns() -{ - mkdir -p /var/etc/dnsmasq-adbyby.d - mkdir -p /tmp/dnsmasq.d - awk '!/^$/&&!/^#/{printf("ipset=/%s/'"adbyby_esc"'\n",$0)}' $PROG_PATH/adesc.conf > /var/etc/dnsmasq-adbyby.d/06-dnsmasq.esc - awk '!/^$/&&!/^#/{printf("address=/%s/'"0.0.0.0"'\n",$0)}' $PROG_PATH/adblack.conf > /var/etc/dnsmasq-adbyby.d/07-dnsmasq.black - cat > /tmp/dnsmasq.d/dnsmasq-adbyby.conf < $WAN_FILE - if ls /var/etc/dnsmasq-adbyby.d/* >/dev/null 2>&1; then - mkdir -p /tmp/dnsmasq.d - cp /usr/share/adbyby/dnsmasq.adblock /var/etc/dnsmasq-adbyby.d/04-dnsmasq.adblock - cp /usr/share/adbyby/dnsmasq.ads /var/etc/dnsmasq-adbyby.d/05-dnsmasq.ads - fi - fi - - sed -i '/mesu.apple.com/d' /etc/dnsmasq.conf && [ $block_ios -eq 1 ] && echo 'address=/mesu.apple.com/0.0.0.0' >> /etc/dnsmasq.conf -} +o = s:taboption("advanced", Flag, "cron_mode") +o.title = translate("Update the rule at 6 a.m. every morning and restart adbyby") +o.default = 0 +o.rmempty = false +o.description = translate(string.format("Adblock Plus Host List£º %s Lines

", ND)) -del_dns() -{ - rm -f /tmp/dnsmasq.d/dnsmasq-adbyby.conf - rm -f /var/etc/dnsmasq-adbyby.d/* - rm -f /tmp/adbyby_host.conf -} +updatead = s:taboption("advanced", Button, "updatead", translate("Manually force update
Adblock Plus Host List"), translate("Note: It needs to download and convert the rules. The background process may takes 60-120 seconds to run.
After completed it would automatically refresh, please do not duplicate click!")) +updatead.inputtitle = translate("Manually force update") +updatead.inputstyle = "apply" +updatead.write = function() + SYS.call("nohup sh /usr/share/adbyby/adblock.sh > /tmp/adupdate.log 2>&1 &") +end +o = s:taboption("advanced", Flag, "block_ios") +o.title = translate("Block Apple iOS OTA update") +o.default = 0 +o.rmempty = false -add_rule() -{ - $ipt_n -N ADBYBY - $ipt_n -A ADBYBY -d 0.0.0.0/8 -j RETURN - $ipt_n -A ADBYBY -d 10.0.0.0/8 -j RETURN - $ipt_n -A ADBYBY -d 127.0.0.0/8 -j RETURN - $ipt_n -A ADBYBY -d 169.254.0.0/16 -j RETURN - $ipt_n -A ADBYBY -d 172.16.0.0/12 -j RETURN - $ipt_n -A ADBYBY -d 192.168.0.0/16 -j RETURN - $ipt_n -A ADBYBY -d 224.0.0.0/4 -j RETURN - $ipt_n -A ADBYBY -d 240.0.0.0/4 -j RETURN - ip_rule - $ipt_n -A ADBYBY -p tcp -j REDIRECT --to-ports 8118 - $ipt_n -I PREROUTING -p tcp --dport 80 -j ADBYBY -} +s:tab("help", translate("Plus+ Domain List")) -del_rule() -{ - $ipt_n -D PREROUTING -p tcp --dport 80 -j ADBYBY 2>/dev/null - $ipt_n -F ADBYBY 2>/dev/null - $ipt_n -X ADBYBY 2>/dev/null - iptables -D FORWARD -m set --match-set blockip dst -j DROP 2>/dev/null - iptables -D OUTPUT -m set --match-set blockip dst -j DROP 2>/dev/null - ipset -F adbyby_esc 2>/dev/null - ipset -X adbyby_esc 2>/dev/null - ipset -F adbyby_wan 2>/dev/null - ipset -X adbyby_wan 2>/dev/null - ipset -F blockip 2>/dev/null - ipset -X blockip 2>/dev/null -} +local conf = "/usr/share/adbyby/adhost.conf" +o = s:taboption("help", TextValue, "conf") +o.description = translate("£¨!£©Note that you should fill to the domain name ONLY. For example, http://www.baidu.com only needs to write to baidu.com. One line for each") +o.rows = 13 +o.wrap = "off" +o.cfgvalue = function(self, section) + return NXFS.readfile(conf) or "" +end +o.write = function(self, section, value) + NXFS.writefile(conf, value:gsub("\r\n", "\n")) + --SYS.call("/etc/init.d/adbyby restart") +end -reload_rule() -{ - config_load adbyby - config_foreach get_config adbyby - del_rule - iptables-save | grep ADBYBY >/dev/null || \ - add_rule -} +s:tab("esc", translate("Bypass Domain List")) -start() -{ - config_load adbyby - config_foreach get_config adbyby - [ $enable -eq 0 ] && exit 0 - add_cron - [ ! -d "/tmp/adbyby/data" ] && cp -a /usr/share/adbyby /tmp/ && rm -f /tmp/adbyby.updated - /usr/share/adbyby/admem.sh & - add_rules - /tmp/adbyby/adbyby &>/dev/null & - add_dns - iptables-save | grep ADBYBY >/dev/null || \ - add_rule - /etc/init.d/dnsmasq reload -} +local escconf = "/usr/share/adbyby/adesc.conf" +o = s:taboption("esc", TextValue, "escconf") +o.description = translate("£¨!£©Will Never filter these Domain") +o.rows = 13 +o.wrap = "off" +o.cfgvalue = function(self, section) + return NXFS.readfile(escconf) or "" +end +o.write = function(self, section, value) + NXFS.writefile(escconf, value:gsub("\r\n", "\n")) + --SYS.call("/etc/init.d/adbyby restart") +end -stop() -{ - config_load adbyby - config_foreach get_config adbyby - del_rule - del_cron - del_dns - kill -9 $(ps | grep 'admem.sh' | grep -v grep | awk '{print $1}') >/dev/null 2>&1 - kill -9 $(ps | grep '/tmp/adbyby/adbyby' | grep -v grep | awk '{print $1}') >/dev/null 2>&1 - /etc/init.d/dnsmasq reload -} +s:tab("black", translate("Black Domain List")) -boot() -{ - mkdir -p /tmp/adbyby && cp -a /usr/share/adbyby /tmp/ - start -} +local blackconf = "/usr/share/adbyby/adblack.conf" +o = s:taboption("black", TextValue, "blackconf") +o.description = translate("£¨!£©Will Always block these Domain") +o.rows = 13 +o.wrap = "off" +o.cfgvalue = function(self, section) + return NXFS.readfile(blackconf) or "" +end +o.write = function(self, section, value) + NXFS.writefile(blackconf, value:gsub("\r\n", "\n")) + --SYS.call("/etc/init.d/adbyby restart") +end +s:tab("block", translate("Black IP List")) -uci_get_by_name() { - local ret=$(uci get $CONFIG.$1.$2 2>/dev/null) - echo ${ret:=$3} -} +local blockconf = "/usr/share/adbyby/blockip.conf" +o = s:taboption("block", TextValue, "blockconf") +o.description = translate("£¨!£©Will Always block these IP") +o.rows = 13 +o.wrap = "off" +o.cfgvalue = function(self, section) + return NXFS.readfile(blockconf) or " " +end +o.write = function(self, section, value) + NXFS.writefile(blockconf, value:gsub("\r\n", "\n")) + --SYS.call("/etc/init.d/adbyby restart") +end -uci_get_by_type() { - local index=0 - if [ -n $4 ]; then - - index=$4 - fi - local ret=$(uci get $CONFIG.@$1[$index].$2 2>/dev/null) - echo ${ret:=$3} -} +s:tab("user", translate("User-defined Rule")) +local file = "/usr/share/adbyby/rules.txt" +o = s:taboption("user", TextValue, "rules") +o.description = translate("Each line of the beginning exclamation mark is considered an annotation.") +o.rows = 13 +o.wrap = "off" +o.cfgvalue = function(self, section) + return NXFS.readfile(file) or "" +end +o.write = function(self, section, value) + NXFS.writefile(file, value:gsub("\r\n", "\n")) +end + +t=m:section(TypedSection,"acl_rule",translate("Client Filter Mode Settings"), +translate("Filter mode settings can be set to specific LAN clients ( No filter , Global filter ) . Does not need to be set by default.")) +t.template="cbi/tblsection" +t.sortable=true +t.anonymous=true +t.addremove=true + +e=t:option(Value,"ipaddr",translate("IP Address")) +e.width="40%" +e.datatype="ip4addr" +e.placeholder="0.0.0.0/0" +luci.ip.neighbors({ family = 4 }, function(entry) + if entry.reachable then + e:value(entry.dest:string()) + end +end) + +e=t:option(ListValue,"filter_mode",translate("Filter Mode")) +e.width="40%" +e.default="disable" +e.rmempty=false +e:value("disable",translate("No filter")) +e:value("global",translate("Global filter")) + +return m From 5e271e43e3df640adee5d5bf84045d7c354c7267 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Sat, 22 Feb 2020 12:22:01 +0800 Subject: [PATCH 3/6] luci-app-adbyby-plus: less debug logs --- .../root/etc/init.d/adbyby | 330 ++++++++++-------- 1 file changed, 186 insertions(+), 144 deletions(-) diff --git a/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby b/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby index e8db437fed..212dba9b6c 100755 --- a/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby +++ b/package/lean/luci-app-adbyby-plus/root/etc/init.d/adbyby @@ -1,167 +1,209 @@ +#!/bin/sh /etc/rc.common -local NXFS = require "nixio.fs" -local SYS = require "luci.sys" -local HTTP = require "luci.http" -local DISP = require "luci.dispatcher" +START=99 +STOP=10 -local DL = SYS.exec("head -1 /tmp/adbyby/data/lazy.txt | awk -F' ' '{print $3,$4}'") or "" -local DV = SYS.exec("head -1 /tmp/adbyby/data/video.txt | awk -F' ' '{print $3,$4}'") or "" -local NR = SYS.exec("grep -v '^!' /usr/share/adbyby/data/rules.txt | wc -l") -local NU = SYS.exec("cat /usr/share/adbyby/data/user.txt | wc -l") -local UD = NXFS.readfile("/tmp/adbyby.updated") or "1970-01-01 00:00:00" -local ND = SYS.exec("cat /usr/share/adbyby/dnsmasq.adblock | wc -l") +EXTRA_COMMANDS="add_rule del_rule reload_rule" +PROG_PATH=/usr/share/adbyby +DATA_PATH=$PROG_PATH/data +WAN_FILE=/var/etc/dnsmasq-adbyby.d/03-adbyby-ipset.conf +CRON_FILE=/etc/crontabs/root +CONFIG=adbyby +ipt_n="iptables -t nat" -m = Map("adbyby") -m.title = translate("Adbyby Plus +") -m.description = translate("Adbyby Plus + can filter all kinds of banners, popups, video ads, and prevent tracking, privacy theft and a variety of malicious websites
Plus + version combination mode can operation with Adblock Plus Host£¬filtering ads without losing bandwidth") -m:section(SimpleSection).template = "adbyby/adbyby_status" +get_config() +{ + config_get_bool enable $1 enable + config_get_bool cron_mode $1 cron_mode + config_get wan_mode $1 wan_mode + config_get_bool block_ios $1 block_ios 0 + config_get_bool mem_mode $1 mem_mode 1 +} -s = m:section(TypedSection, "adbyby") -s.anonymous = true +add_rules() +{ + rm -f $DATA_PATH/user.bin + grep -v ^! $PROG_PATH/rules.txt > $DATA_PATH/user.txt + cp $PROG_PATH/rules.txt $DATA_PATH/rules.txt +} -s:tab("basic", translate("Base Setting")) -o = s:taboption("basic", Flag, "enable") -o.title = translate("Enable") -o.default = 0 -o.rmempty = false +add_cron() +{ + if [ $cron_mode -eq 1 ]; then + sed -i '/adblock.sh/d' $CRON_FILE + echo '0 6 * * * /usr/share/adbyby/adblock.sh > /tmp/adupdate.log 2>&1' >> $CRON_FILE + crontab $CRON_FILE + fi +} -o = s:taboption("basic", ListValue, "wan_mode") -o.title = translate("Running Mode") -o:value("0", translate("Global Mode£¨The slowest, the best effects£©")) -o:value("1", translate("Plus + Mode£¨Filter domain name list and blacklist website.Recommended£©")) -o:value("2", translate("No filter Mode (Must set in Client Filter Mode Settings manually)")) -o.default = 1 -o.rmempty = false +del_cron() +{ + sed -i '/adblock.sh/d' $CRON_FILE + /etc/init.d/cron restart +} -o = s:taboption("basic", Button, "restart") -o.title = translate("Adbyby and Rule state") -o.inputtitle = translate("Restart Adbyby") -o.description = string.format("Last Update Checked£º %s
Lazy Rule£º%s
Video Rule£º%s", UD, DL, DV) -o.inputstyle = "reload" -o.write = function() - SYS.call("rm -rf /tmp/adbyby.updated && /usr/share/adbyby/admem.sh > /tmp/adupdate.log 2>&1 &") - SYS.call("sleep 5") - HTTP.redirect(DISP.build_url("admin", "services", "adbyby")) -end +ip_rule() +{ -s:tab("advanced", translate("Advance Setting")) + ipset -N adbyby_esc hash:ip + $ipt_n -A ADBYBY -m set --match-set adbyby_esc dst -j RETURN + + for i in $(seq 0 100) + do + local ip=$(uci_get_by_type acl_rule ipaddr '' $i) + local mode=$(uci_get_by_type acl_rule filter_mode '' $i) + case "$mode" in + disable) + $ipt_n -A ADBYBY -s $ip -j RETURN + ;; + global) + $ipt_n -A ADBYBY -s $ip -p tcp -j REDIRECT --to-ports 8118 + $ipt_n -A ADBYBY -s $ip -j RETURN + ;; + esac + done + + + + case $wan_mode in + 0) + ;; + 1) + ipset -N adbyby_wan hash:ip + $ipt_n -A ADBYBY -m set ! --match-set adbyby_wan dst -j RETURN + ;; + 2) + $ipt_n -I ADBYBY -j RETURN + ;; + esac + + echo "create blockip hash:net family inet hashsize 1024 maxelem 65536" > /tmp/blockip.ipset + awk '!/^$/&&!/^#/{printf("add blockip %s'" "'\n",$0)}' /usr/share/adbyby/blockip.conf >> /tmp/blockip.ipset + ipset -! restore < /tmp/blockip.ipset 2>/dev/null + iptables -I FORWARD -m set --match-set blockip dst -j DROP + iptables -I OUTPUT -m set --match-set blockip dst -j DROP +} -o = s:taboption("advanced", Flag, "cron_mode") -o.title = translate("Update the rule at 6 a.m. every morning and restart adbyby") -o.default = 0 -o.rmempty = false -o.description = translate(string.format("Adblock Plus Host List£º %s Lines

", ND)) +add_dns() +{ + mkdir -p /var/etc/dnsmasq-adbyby.d + mkdir -p /tmp/dnsmasq.d + awk '!/^$/&&!/^#/{printf("ipset=/%s/'"adbyby_esc"'\n",$0)}' $PROG_PATH/adesc.conf > /var/etc/dnsmasq-adbyby.d/06-dnsmasq.esc + awk '!/^$/&&!/^#/{printf("address=/%s/'"0.0.0.0"'\n",$0)}' $PROG_PATH/adblack.conf > /var/etc/dnsmasq-adbyby.d/07-dnsmasq.black + cat > /tmp/dnsmasq.d/dnsmasq-adbyby.conf < $WAN_FILE + if ls /var/etc/dnsmasq-adbyby.d/* >/dev/null 2>&1; then + mkdir -p /tmp/dnsmasq.d + cp /usr/share/adbyby/dnsmasq.adblock /var/etc/dnsmasq-adbyby.d/04-dnsmasq.adblock + cp /usr/share/adbyby/dnsmasq.ads /var/etc/dnsmasq-adbyby.d/05-dnsmasq.ads + fi + fi + + sed -i '/mesu.apple.com/d' /etc/dnsmasq.conf && [ $block_ios -eq 1 ] && echo 'address=/mesu.apple.com/0.0.0.0' >> /etc/dnsmasq.conf +} -updatead = s:taboption("advanced", Button, "updatead", translate("Manually force update
Adblock Plus Host List"), translate("Note: It needs to download and convert the rules. The background process may takes 60-120 seconds to run.
After completed it would automatically refresh, please do not duplicate click!")) -updatead.inputtitle = translate("Manually force update") -updatead.inputstyle = "apply" -updatead.write = function() - SYS.call("nohup sh /usr/share/adbyby/adblock.sh > /tmp/adupdate.log 2>&1 &") -end +del_dns() +{ + rm -f /tmp/dnsmasq.d/dnsmasq-adbyby.conf + rm -f /var/etc/dnsmasq-adbyby.d/* + rm -f /tmp/adbyby_host.conf +} -o = s:taboption("advanced", Flag, "block_ios") -o.title = translate("Block Apple iOS OTA update") -o.default = 0 -o.rmempty = false -s:tab("help", translate("Plus+ Domain List")) +add_rule() +{ + $ipt_n -N ADBYBY + $ipt_n -A ADBYBY -d 0.0.0.0/8 -j RETURN + $ipt_n -A ADBYBY -d 10.0.0.0/8 -j RETURN + $ipt_n -A ADBYBY -d 127.0.0.0/8 -j RETURN + $ipt_n -A ADBYBY -d 169.254.0.0/16 -j RETURN + $ipt_n -A ADBYBY -d 172.16.0.0/12 -j RETURN + $ipt_n -A ADBYBY -d 192.168.0.0/16 -j RETURN + $ipt_n -A ADBYBY -d 224.0.0.0/4 -j RETURN + $ipt_n -A ADBYBY -d 240.0.0.0/4 -j RETURN + ip_rule + $ipt_n -A ADBYBY -p tcp -j REDIRECT --to-ports 8118 + $ipt_n -I PREROUTING -p tcp --dport 80 -j ADBYBY +} -local conf = "/usr/share/adbyby/adhost.conf" -o = s:taboption("help", TextValue, "conf") -o.description = translate("£¨!£©Note that you should fill to the domain name ONLY. For example, http://www.baidu.com only needs to write to baidu.com. One line for each") -o.rows = 13 -o.wrap = "off" -o.cfgvalue = function(self, section) - return NXFS.readfile(conf) or "" -end -o.write = function(self, section, value) - NXFS.writefile(conf, value:gsub("\r\n", "\n")) - --SYS.call("/etc/init.d/adbyby restart") -end +del_rule() +{ + $ipt_n -D PREROUTING -p tcp --dport 80 -j ADBYBY 2>/dev/null + $ipt_n -F ADBYBY 2>/dev/null + $ipt_n -X ADBYBY 2>/dev/null + iptables -D FORWARD -m set --match-set blockip dst -j DROP 2>/dev/null + iptables -D OUTPUT -m set --match-set blockip dst -j DROP 2>/dev/null + ipset -F adbyby_esc 2>/dev/null + ipset -X adbyby_esc 2>/dev/null + ipset -F adbyby_wan 2>/dev/null + ipset -X adbyby_wan 2>/dev/null + ipset -F blockip 2>/dev/null + ipset -X blockip 2>/dev/null +} -s:tab("esc", translate("Bypass Domain List")) +reload_rule() +{ + config_load adbyby + config_foreach get_config adbyby + del_rule + iptables-save | grep ADBYBY >/dev/null || \ + add_rule +} -local escconf = "/usr/share/adbyby/adesc.conf" -o = s:taboption("esc", TextValue, "escconf") -o.description = translate("£¨!£©Will Never filter these Domain") -o.rows = 13 -o.wrap = "off" -o.cfgvalue = function(self, section) - return NXFS.readfile(escconf) or "" -end -o.write = function(self, section, value) - NXFS.writefile(escconf, value:gsub("\r\n", "\n")) - --SYS.call("/etc/init.d/adbyby restart") -end +start() +{ + config_load adbyby + config_foreach get_config adbyby + [ $enable -eq 0 ] && exit 0 + add_cron + [ ! -d "/tmp/adbyby/data" ] && cp -a /usr/share/adbyby /tmp/ && rm -f /tmp/adbyby.updated + /usr/share/adbyby/admem.sh &>/dev/null & + add_rules + /tmp/adbyby/adbyby &>/dev/null & + add_dns + iptables-save | grep ADBYBY >/dev/null || \ + add_rule + /etc/init.d/dnsmasq reload +} -s:tab("black", translate("Black Domain List")) +stop() +{ + config_load adbyby + config_foreach get_config adbyby + del_rule + del_cron + del_dns + kill -9 $(ps | grep 'admem.sh' | grep -v grep | awk '{print $1}') >/dev/null 2>&1 + kill -9 $(ps | grep '/tmp/adbyby/adbyby' | grep -v grep | awk '{print $1}') >/dev/null 2>&1 + /etc/init.d/dnsmasq reload +} -local blackconf = "/usr/share/adbyby/adblack.conf" -o = s:taboption("black", TextValue, "blackconf") -o.description = translate("£¨!£©Will Always block these Domain") -o.rows = 13 -o.wrap = "off" -o.cfgvalue = function(self, section) - return NXFS.readfile(blackconf) or "" -end -o.write = function(self, section, value) - NXFS.writefile(blackconf, value:gsub("\r\n", "\n")) - --SYS.call("/etc/init.d/adbyby restart") -end +boot() +{ + mkdir -p /tmp/adbyby && cp -a /usr/share/adbyby /tmp/ + start +} -s:tab("block", translate("Black IP List")) -local blockconf = "/usr/share/adbyby/blockip.conf" -o = s:taboption("block", TextValue, "blockconf") -o.description = translate("£¨!£©Will Always block these IP") -o.rows = 13 -o.wrap = "off" -o.cfgvalue = function(self, section) - return NXFS.readfile(blockconf) or " " -end -o.write = function(self, section, value) - NXFS.writefile(blockconf, value:gsub("\r\n", "\n")) - --SYS.call("/etc/init.d/adbyby restart") -end +uci_get_by_name() { + local ret=$(uci get $CONFIG.$1.$2 2>/dev/null) + echo ${ret:=$3} +} -s:tab("user", translate("User-defined Rule")) +uci_get_by_type() { + local index=0 + if [ -n $4 ]; then + + index=$4 + fi + local ret=$(uci get $CONFIG.@$1[$index].$2 2>/dev/null) + echo ${ret:=$3} +} -local file = "/usr/share/adbyby/rules.txt" -o = s:taboption("user", TextValue, "rules") -o.description = translate("Each line of the beginning exclamation mark is considered an annotation.") -o.rows = 13 -o.wrap = "off" -o.cfgvalue = function(self, section) - return NXFS.readfile(file) or "" -end -o.write = function(self, section, value) - NXFS.writefile(file, value:gsub("\r\n", "\n")) -end - -t=m:section(TypedSection,"acl_rule",translate("Client Filter Mode Settings"), -translate("Filter mode settings can be set to specific LAN clients ( No filter , Global filter ) . Does not need to be set by default.")) -t.template="cbi/tblsection" -t.sortable=true -t.anonymous=true -t.addremove=true - -e=t:option(Value,"ipaddr",translate("IP Address")) -e.width="40%" -e.datatype="ip4addr" -e.placeholder="0.0.0.0/0" -luci.ip.neighbors({ family = 4 }, function(entry) - if entry.reachable then - e:value(entry.dest:string()) - end -end) - -e=t:option(ListValue,"filter_mode",translate("Filter Mode")) -e.width="40%" -e.default="disable" -e.rmempty=false -e:value("disable",translate("No filter")) -e:value("global",translate("Global filter")) - -return m From 445949adbf7537a37fd88c73b60aabb777fd84d1 Mon Sep 17 00:00:00 2001 From: LGA1150 <9155358+LGA1150@users.noreply.github.com> Date: Sat, 22 Feb 2020 12:26:41 +0800 Subject: [PATCH 4/6] ramips: add JD-Cloud router support (#3239) * generic: support mtd-mac-address-ascii It supports formats of both 001122334455 and 00:11:22:33:44:55 Signed-off-by: Yousong Zhou * ramips: add JDCloud Co-authored-by: Yousong Zhou --- .../681-NET-add-of_get_mac_address_mtd.patch | 107 ++++++++++--- .../681-NET-add-of_get_mac_address_mtd.patch | 107 ++++++++++--- .../ramips/dts/mt7621_jdcloud_re-sp-01b.dts | 144 ++++++++++++++++++ target/linux/ramips/image/mt7621.mk | 8 + .../mt7621/base-files/etc/board.d/02_network | 1 + 5 files changed, 319 insertions(+), 48 deletions(-) create mode 100644 target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts diff --git a/target/linux/generic/pending-4.14/681-NET-add-of_get_mac_address_mtd.patch b/target/linux/generic/pending-4.14/681-NET-add-of_get_mac_address_mtd.patch index 2b89a05238..9de3097cca 100644 --- a/target/linux/generic/pending-4.14/681-NET-add-of_get_mac_address_mtd.patch +++ b/target/linux/generic/pending-4.14/681-NET-add-of_get_mac_address_mtd.patch @@ -32,17 +32,67 @@ Signed-off-by: Felix Fietkau { struct property *pp = of_find_property(np, name, NULL); -@@ -47,6 +48,79 @@ static const void *of_get_mac_addr(struc +@@ -47,6 +48,138 @@ static const void *of_get_mac_addr(struc return NULL; } ++typedef int(*mtd_mac_address_read)(struct mtd_info *mtd, loff_t from, u_char *buf); ++ ++static int read_mtd_mac_address(struct mtd_info *mtd, loff_t from, u_char *mac) ++{ ++ size_t retlen; ++ ++ return mtd_read(mtd, from, 6, &retlen, mac); ++} ++ ++static int read_mtd_mac_address_ascii(struct mtd_info *mtd, loff_t from, u_char *mac) ++{ ++ size_t retlen; ++ char buf[17]; ++ ++ if (mtd_read(mtd, from, 12, &retlen, buf)) { ++ return -1; ++ } ++ if (sscanf(buf, "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", ++ &mac[0], &mac[1], &mac[2], &mac[3], ++ &mac[4], &mac[5]) == 6) { ++ if (mac[0] == '\0' && mac[1] == '\0') { /* First 2 bytes are zero, probably a bug. Trying to re-read */ ++ buf[4] = '\0'; /* Make it null-terminated */ ++ if (sscanf(buf, "%4hx", mac) == 1) ++ *(uint16_t*)mac = htons(*(uint16_t*)mac); ++ } ++ return 0; ++ } ++ if (mtd_read(mtd, from+12, 5, &retlen, buf+12)) { ++ return -1; ++ } ++ if (sscanf(buf, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", ++ &mac[0], &mac[1], &mac[2], &mac[3], ++ &mac[4], &mac[5]) == 6) { ++ return 0; ++ } ++ return -1; ++} ++ ++static struct mtd_mac_address_property { ++ char *name; ++ mtd_mac_address_read read; ++} mtd_mac_address_properties[] = { ++ { ++ .name = "mtd-mac-address", ++ .read = read_mtd_mac_address, ++ }, { ++ .name = "mtd-mac-address-ascii", ++ .read = read_mtd_mac_address_ascii, ++ }, ++}; ++ +static const void *of_get_mac_address_mtd(struct device_node *np) +{ +#ifdef CONFIG_MTD + struct device_node *mtd_np = NULL; + struct property *prop; -+ size_t retlen; -+ int size, ret; ++ int size, ret = -1; + struct mtd_info *mtd; + const char *part; + const __be32 *list; @@ -51,28 +101,37 @@ Signed-off-by: Felix Fietkau + u8 mac[ETH_ALEN]; + void *addr; + u32 inc_idx; ++ int i; + -+ list = of_get_property(np, "mtd-mac-address", &size); -+ if (!list || (size != (2 * sizeof(*list)))) ++ for (i = 0; i < ARRAY_SIZE(mtd_mac_address_properties); i++) { ++ list = of_get_property(np, mtd_mac_address_properties[i].name, &size); ++ if (!list || (size != (2 * sizeof(*list)))) ++ continue; ++ ++ phandle = be32_to_cpup(list++); ++ if (phandle) ++ mtd_np = of_find_node_by_phandle(phandle); ++ ++ if (!mtd_np) ++ continue; ++ ++ part = of_get_property(mtd_np, "label", NULL); ++ if (!part) ++ part = mtd_np->name; ++ ++ mtd = get_mtd_device_nm(part); ++ if (IS_ERR(mtd)) ++ continue; ++ ++ ret = mtd_mac_address_properties[i].read(mtd, be32_to_cpup(list), mac); ++ put_mtd_device(mtd); ++ if (!ret) { ++ break; ++ } ++ } ++ if (ret) { + return NULL; -+ -+ phandle = be32_to_cpup(list++); -+ if (phandle) -+ mtd_np = of_find_node_by_phandle(phandle); -+ -+ if (!mtd_np) -+ return NULL; -+ -+ part = of_get_property(mtd_np, "label", NULL); -+ if (!part) -+ part = mtd_np->name; -+ -+ mtd = get_mtd_device_nm(part); -+ if (IS_ERR(mtd)) -+ return NULL; -+ -+ ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac); -+ put_mtd_device(mtd); ++ } + + if (of_property_read_u32(np, "mtd-mac-address-increment-byte", &inc_idx)) + inc_idx = 5; @@ -112,7 +171,7 @@ Signed-off-by: Felix Fietkau /** * Search the device tree for the best MAC address to use. 'mac-address' is * checked first, because that is supposed to contain to "most recent" MAC -@@ -64,11 +138,18 @@ static const void *of_get_mac_addr(struc +@@ -64,11 +192,18 @@ static const void *of_get_mac_addr(struc * addresses. Some older U-Boots only initialized 'local-mac-address'. In * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists * but is all zeros. diff --git a/target/linux/generic/pending-4.19/681-NET-add-of_get_mac_address_mtd.patch b/target/linux/generic/pending-4.19/681-NET-add-of_get_mac_address_mtd.patch index 13f5640590..ab43007e24 100644 --- a/target/linux/generic/pending-4.19/681-NET-add-of_get_mac_address_mtd.patch +++ b/target/linux/generic/pending-4.19/681-NET-add-of_get_mac_address_mtd.patch @@ -32,17 +32,67 @@ Signed-off-by: Felix Fietkau { struct property *pp = of_find_property(np, name, NULL); -@@ -48,6 +49,79 @@ static const void *of_get_mac_addr(struc +@@ -48,6 +49,138 @@ static const void *of_get_mac_addr(struc return NULL; } ++typedef int(*mtd_mac_address_read)(struct mtd_info *mtd, loff_t from, u_char *buf); ++ ++static int read_mtd_mac_address(struct mtd_info *mtd, loff_t from, u_char *mac) ++{ ++ size_t retlen; ++ ++ return mtd_read(mtd, from, 6, &retlen, mac); ++} ++ ++static int read_mtd_mac_address_ascii(struct mtd_info *mtd, loff_t from, u_char *mac) ++{ ++ size_t retlen; ++ char buf[17]; ++ ++ if (mtd_read(mtd, from, 12, &retlen, buf)) { ++ return -1; ++ } ++ if (sscanf(buf, "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", ++ &mac[0], &mac[1], &mac[2], &mac[3], ++ &mac[4], &mac[5]) == 6) { ++ if (mac[0] == '\0' && mac[1] == '\0') { /* First 2 bytes are zero, probably a bug. Trying to re-read */ ++ buf[4] = '\0'; /* Make it null-terminated */ ++ if (sscanf(buf, "%4hx", mac) == 1) ++ *(uint16_t*)mac = htons(*(uint16_t*)mac); ++ } ++ return 0; ++ } ++ if (mtd_read(mtd, from+12, 5, &retlen, buf+12)) { ++ return -1; ++ } ++ if (sscanf(buf, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", ++ &mac[0], &mac[1], &mac[2], &mac[3], ++ &mac[4], &mac[5]) == 6) { ++ return 0; ++ } ++ return -1; ++} ++ ++static struct mtd_mac_address_property { ++ char *name; ++ mtd_mac_address_read read; ++} mtd_mac_address_properties[] = { ++ { ++ .name = "mtd-mac-address", ++ .read = read_mtd_mac_address, ++ }, { ++ .name = "mtd-mac-address-ascii", ++ .read = read_mtd_mac_address_ascii, ++ }, ++}; ++ +static const void *of_get_mac_address_mtd(struct device_node *np) +{ +#ifdef CONFIG_MTD + struct device_node *mtd_np = NULL; + struct property *prop; -+ size_t retlen; -+ int size, ret; ++ int size, ret = -1; + struct mtd_info *mtd; + const char *part; + const __be32 *list; @@ -51,28 +101,37 @@ Signed-off-by: Felix Fietkau + u8 mac[ETH_ALEN]; + void *addr; + u32 inc_idx; ++ int i; + -+ list = of_get_property(np, "mtd-mac-address", &size); -+ if (!list || (size != (2 * sizeof(*list)))) ++ for (i = 0; i < ARRAY_SIZE(mtd_mac_address_properties); i++) { ++ list = of_get_property(np, mtd_mac_address_properties[i].name, &size); ++ if (!list || (size != (2 * sizeof(*list)))) ++ continue; ++ ++ phandle = be32_to_cpup(list++); ++ if (phandle) ++ mtd_np = of_find_node_by_phandle(phandle); ++ ++ if (!mtd_np) ++ continue; ++ ++ part = of_get_property(mtd_np, "label", NULL); ++ if (!part) ++ part = mtd_np->name; ++ ++ mtd = get_mtd_device_nm(part); ++ if (IS_ERR(mtd)) ++ continue; ++ ++ ret = mtd_mac_address_properties[i].read(mtd, be32_to_cpup(list), mac); ++ put_mtd_device(mtd); ++ if (!ret) { ++ break; ++ } ++ } ++ if (ret) { + return NULL; -+ -+ phandle = be32_to_cpup(list++); -+ if (phandle) -+ mtd_np = of_find_node_by_phandle(phandle); -+ -+ if (!mtd_np) -+ return NULL; -+ -+ part = of_get_property(mtd_np, "label", NULL); -+ if (!part) -+ part = mtd_np->name; -+ -+ mtd = get_mtd_device_nm(part); -+ if (IS_ERR(mtd)) -+ return NULL; -+ -+ ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac); -+ put_mtd_device(mtd); ++ } + + if (of_property_read_u32(np, "mtd-mac-address-increment-byte", &inc_idx)) + inc_idx = 5; @@ -112,7 +171,7 @@ Signed-off-by: Felix Fietkau /** * Search the device tree for the best MAC address to use. 'mac-address' is * checked first, because that is supposed to contain to "most recent" MAC -@@ -65,11 +139,18 @@ static const void *of_get_mac_addr(struc +@@ -65,11 +193,18 @@ static const void *of_get_mac_addr(struc * addresses. Some older U-Boots only initialized 'local-mac-address'. In * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists * but is all zeros. diff --git a/target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts b/target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts new file mode 100644 index 0000000000..4392a8d1fe --- /dev/null +++ b/target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/dts-v1/; + +#include "mt7621.dtsi" + +#include +#include + +/ { + compatible = "jdcloud,re-sp-01b", "mediatek,mt7621-soc"; + model = "JDCloud RE-SP-01B"; + + aliases { + led-boot = &led_red; + led-failsafe = &led_red; + led-running = &led_green; + led-upgrade = &led_blue; + label-mac-device = ðernet; + }; + + chosen { + bootargs = "console=ttyS0,115200"; + }; + + keys { + compatible = "gpio-keys"; + + reset { + label = "reset"; + gpios = <&gpio0 18 GPIO_ACTIVE_LOW>; + linux,code = ; + }; + }; + + leds { + compatible = "gpio-leds"; + + led_red: red { + label = "jdcloud:red:sys"; + gpios = <&gpio0 6 GPIO_ACTIVE_LOW>; + panic-indicator; + }; + + led_green: green { + label = "jdcloud:green:sys"; + gpios = <&gpio0 8 GPIO_ACTIVE_LOW>; + }; + + led_blue: blue { + label = "jdcloud:blue:sys"; + gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; + }; + }; +}; + +&sdhci { + status = "okay"; +}; + +&spi0 { + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + spi-max-frequency = <50000000>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "u-boot"; + reg = <0x0 0x30000>; + read-only; + }; + + config: partition@30000 { + label = "config"; + reg = <0x30000 0x10000>; + read-only; + }; + + factory: partition@40000 { + label = "factory"; + reg = <0x40000 0x10000>; + read-only; + }; + + partition@50000 { + compatible = "denx,uimage"; + label = "firmware"; + reg = <0x50000 0x1ab0000>; + }; + + partition@1b00000 { + label = "mini"; + reg = <0x1b00000 0x400000>; + read-only; + }; + + partition@1f00000 { + label = "oem"; + reg = <0x1f00000 0x100000>; + read-only; + }; + }; + }; +}; + +ðernet { + mtd-mac-address-ascii = <&config 0x4429>; +}; + +&pcie { + status = "okay"; +}; + +&pcie0 { + wifi@0,0 { + reg = <0x0000 0 0 0 0>; + mtd-mac-address-ascii = <&config 0x4429>; + mediatek,mtd-eeprom = <&factory 0x0>; + }; +}; + +&pcie1 { + wifi@0,0 { + reg = <0x0000 0 0 0 0>; + mtd-mac-address-ascii = <&config 0x4429>; + mtd-mac-address-increment = <0x80>; + mtd-mac-address-increment-byte = <3>; + mediatek,mtd-eeprom = <&factory 0x8000>; + ieee80211-freq-limit = <5000000 6000000>; + }; +}; + +&state_default { + gpio { + ralink,group = "uart2", "uart3", "wdt"; + ralink,function = "gpio"; + }; +}; diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk index 336b0fdea8..b21ebd4c84 100644 --- a/target/linux/ramips/image/mt7621.mk +++ b/target/linux/ramips/image/mt7621.mk @@ -385,6 +385,14 @@ define Device/jcg_jhr-ac876m endef TARGET_DEVICES += jcg_jhr-ac876m +define Device/jdcloud_re-sp-01b + IMAGE_SIZE := 27328k + DEVICE_VENDOR := JDCloud + DEVICE_MODEL := RE-SP-01B + DEVICE_PACKAGES := kmod-fs-ext4 kmod-mt7603 kmod-mt7615e kmod-sdhci-mt7620 kmod-usb3 wpad-openssl +endef +TARGET_DEVICES += jdcloud_re-sp-01b + define Device/lenovo_newifi-d1 IMAGE_SIZE := 32448k DEVICE_VENDOR := Newifi diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network index f53c8f11ea..978e8df648 100755 --- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network +++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network @@ -124,6 +124,7 @@ ramips_setup_interfaces() ucidef_add_switch_attr "switch0" "enable" "false" ucidef_set_interface_lan "eth0" ;; + jdcloud,re-sp-01b|\ mikrotik,rbm33g) ucidef_add_switch "switch0" \ "1:lan" "2:lan" "0:wan" "6@eth0" From d268405cb9e4e980d636c00da43f37c16aeef5b7 Mon Sep 17 00:00:00 2001 From: AmadeusGhost <42570690+AmadeusGhost@users.noreply.github.com> Date: Sat, 22 Feb 2020 12:39:52 +0800 Subject: [PATCH 5/6] ramips: sync source code (#3260) This commit sync ramips source code from openwrt master. 1. ramips: gsw_mt7621: disable PORT 5 MAC RX/TX flow control by default 2. ramips: allow to set switchdev by board in ramips_set_preinit_iface 3. kernel: fix typos in KernelPackage description --- package/kernel/linux/modules/hwmon.mk | 2 +- package/kernel/linux/modules/input.mk | 4 +- package/kernel/linux/modules/netdevices.mk | 2 +- package/kernel/linux/modules/sound.mk | 2 +- .../lib/preinit/07_set_preinit_iface_ramips | 67 ++++++--- .../ramips/dts/mt7621_iodata_wn-ax1167gr2.dts | 25 ++++ .../ramips/dts/mt7621_iodata_wn-dx1167r.dts | 31 ++++ .../ramips/dts/mt7621_iodata_wn-xx-xr.dtsi | 140 ++++++++++++++++++ .../ramips/dts/mt7628an_hiwifi_hc5761a.dts | 13 +- .../net/ethernet/mediatek/gsw_mt7621.c | 12 +- target/linux/ramips/image/mt7621.mk | 60 +++++++- target/linux/ramips/modules.mk | 2 +- .../mt7621/base-files/etc/board.d/02_network | 12 +- .../mt7621/base-files/lib/upgrade/iodata.sh | 55 +++++++ .../mt7621/base-files/lib/upgrade/platform.sh | 5 + .../mt76x8/base-files/etc/board.d/02_network | 5 +- 16 files changed, 392 insertions(+), 45 deletions(-) create mode 100644 target/linux/ramips/dts/mt7621_iodata_wn-ax1167gr2.dts create mode 100644 target/linux/ramips/dts/mt7621_iodata_wn-dx1167r.dts create mode 100644 target/linux/ramips/dts/mt7621_iodata_wn-xx-xr.dtsi create mode 100644 target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh diff --git a/package/kernel/linux/modules/hwmon.mk b/package/kernel/linux/modules/hwmon.mk index 31836fbceb..c0a477856e 100644 --- a/package/kernel/linux/modules/hwmon.mk +++ b/package/kernel/linux/modules/hwmon.mk @@ -324,7 +324,7 @@ define KernelPackage/pmbus-zl6100 $(call AddDepends/hwmon, +kmod-pmbus-core) endef -define KernelPackage/hwmon-sht21/description +define KernelPackage/pmbus-zl6100/description Kernel module for Intersil / Zilker Labs ZL6100 and compatible digital DC-DC controllers endef diff --git a/package/kernel/linux/modules/input.mk b/package/kernel/linux/modules/input.mk index 99257b6725..8c5eaf5549 100644 --- a/package/kernel/linux/modules/input.mk +++ b/package/kernel/linux/modules/input.mk @@ -119,7 +119,7 @@ define KernelPackage/input-gpio-encoder AUTOLOAD:=$(call AutoProbe,rotary_encoder) endef -define KernelPackage/gpio-encoder/description +define KernelPackage/input-gpio-encoder/description Kernel module to use rotary encoders connected to GPIO pins endef @@ -166,7 +166,7 @@ define KernelPackage/input-matrixkmap AUTOLOAD:=$(call AutoProbe,matrix-keymap) endef -define KernelPackage/input-matrix/description +define KernelPackage/input-matrixkmap/description Kernel module support for input matrix devices endef diff --git a/package/kernel/linux/modules/netdevices.mk b/package/kernel/linux/modules/netdevices.mk index 13fc999bac..c0ab09230b 100644 --- a/package/kernel/linux/modules/netdevices.mk +++ b/package/kernel/linux/modules/netdevices.mk @@ -279,7 +279,7 @@ define KernelPackage/switch-rtl8366-smi AUTOLOAD:=$(call AutoLoad,42,rtl8366_smi) endef -define KernelPackage/switch-rtl8366_smi/description +define KernelPackage/switch-rtl8366-smi/description Realtek RTL8366 series SMI switch interface support endef diff --git a/package/kernel/linux/modules/sound.mk b/package/kernel/linux/modules/sound.mk index c83e553d8f..8d63ddfc53 100644 --- a/package/kernel/linux/modules/sound.mk +++ b/package/kernel/linux/modules/sound.mk @@ -301,7 +301,7 @@ define KernelPackage/sound-dummy AUTOLOAD:=$(call AutoLoad,32,snd-dummy) endef -define KernelPackage/sound_dummy/description +define KernelPackage/sound-dummy/description Dummy sound device for Alsa when no hardware present endef diff --git a/target/linux/ramips/base-files/lib/preinit/07_set_preinit_iface_ramips b/target/linux/ramips/base-files/lib/preinit/07_set_preinit_iface_ramips index 003a4dda7b..68c1285eb4 100644 --- a/target/linux/ramips/base-files/lib/preinit/07_set_preinit_iface_ramips +++ b/target/linux/ramips/base-files/lib/preinit/07_set_preinit_iface_ramips @@ -3,27 +3,54 @@ # Copyright (C) 2013 OpenWrt.org # -ramips_set_preinit_iface() { - RT3X5X=$(grep -E "(RT3.5|RT5350|MT7628|MT7688|MT7620|MT7621)" /proc/cpuinfo) +. /lib/functions.sh - if [ -n "${RT3X5X}" ]; then - # The ethernet switch driver enables VLAN by default, but - # failsafe uses eth0, making the device unreachable: - # https://dev.openwrt.org/ticket/18768 - case "${RT3X5X}" in - *MT7620*) - ralink_switchdev=mt7620 - ;; - *MT7621*) - ralink_switchdev=mt7530 - ;; - *) - ralink_switchdev=rt305x - ;; - esac - swconfig dev $ralink_switchdev set reset 1 - swconfig dev $ralink_switchdev set enable_vlan 0 - swconfig dev $ralink_switchdev set apply 1 +ramips_switchdev_from_soc() { + # The ethernet switch driver enables VLAN by default, but + # failsafe uses eth0, making the device unreachable: + # https://dev.openwrt.org/ticket/18768 + + local switchdev + local RT3X5X=$(grep -E "(RT3.5|RT5350|MT7628|MT7688|MT7620|MT7621)" /proc/cpuinfo) + + [ -n "$RT3X5X" ] || return 1 + + case "$RT3X5X" in + *MT7620*) + switchdev=mt7620 + ;; + *MT7621*) + switchdev=mt7530 + ;; + *) + switchdev=rt305x + ;; + esac + + echo "$switchdev" +} + +ramips_switchdev_from_board() { + # For these devices, external ethernet switch should be used + # instead of the SoC internal switch. + + local switchdev + local board=$(board_name) + + case "$board" in + esac + + echo "$switchdev" +} + +ramips_set_preinit_iface() { + local switchdev=$(ramips_switchdev_from_board) + [ -n "$switchdev" ] || switchdev=$(ramips_switchdev_from_soc) + + if [ -n "$switchdev" ]; then + swconfig dev $switchdev set reset 1 + swconfig dev $switchdev set enable_vlan 0 + swconfig dev $switchdev set apply 1 fi ifname=eth0 diff --git a/target/linux/ramips/dts/mt7621_iodata_wn-ax1167gr2.dts b/target/linux/ramips/dts/mt7621_iodata_wn-ax1167gr2.dts new file mode 100644 index 0000000000..251caf4250 --- /dev/null +++ b/target/linux/ramips/dts/mt7621_iodata_wn-ax1167gr2.dts @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/dts-v1/; + +#include "mt7621_iodata_wn-xx-xr.dtsi" + +/ { + compatible = "iodata,wn-ax1167gr2", "mediatek,mt7621-soc"; + model = "I-O DATA WN-AX1167GR2"; +}; + +&partitions { + partition@6b00000 { + label = "Backup"; + reg = <0x6b00000 0x1480000>; + read-only; + }; +}; + +&pcie1 { + wifi@0,0 { + compatible = "mediatek,mt76"; + reg = <0x0000 0 0 0 0>; + mediatek,mtd-eeprom = <&factory 0x0>; + }; +}; diff --git a/target/linux/ramips/dts/mt7621_iodata_wn-dx1167r.dts b/target/linux/ramips/dts/mt7621_iodata_wn-dx1167r.dts new file mode 100644 index 0000000000..ee69b97e44 --- /dev/null +++ b/target/linux/ramips/dts/mt7621_iodata_wn-dx1167r.dts @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/dts-v1/; + +#include "mt7621_iodata_wn-xx-xr.dtsi" + +/ { + compatible = "iodata,wn-dx1167r", "mediatek,mt7621-soc"; + model = "I-O DATA WN-DX1167R"; +}; + +&partitions { + partition@6b00000 { + label = "idmkey"; + reg = <0x6b00000 0x0100000>; + read-only; + }; + + partition@6c00000 { + label = "Backup"; + reg = <0x6c00000 0x1380000>; + read-only; + }; +}; + +&pcie1 { + wifi@0,0 { + compatible = "mediatek,mt76"; + reg = <0x0000 0 0 0 0>; + mediatek,mtd-eeprom = <&factory 0x0>; + }; +}; diff --git a/target/linux/ramips/dts/mt7621_iodata_wn-xx-xr.dtsi b/target/linux/ramips/dts/mt7621_iodata_wn-xx-xr.dtsi new file mode 100644 index 0000000000..8b3329113f --- /dev/null +++ b/target/linux/ramips/dts/mt7621_iodata_wn-xx-xr.dtsi @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "mt7621.dtsi" + +#include +#include + +/ { + aliases { + led-boot = &led_power; + led-failsafe = &led_power; + led-running = &led_power; + led-upgrade = &led_power; + }; + + chosen { + bootargs = "console=ttyS0,57600"; + }; + + leds { + compatible = "gpio-leds"; + + wps { + label = "iodata:green:wps"; + gpios = <&gpio0 8 GPIO_ACTIVE_LOW>; + }; + + led_power: power { + label = "iodata:green:power"; + gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>; + }; + }; + + keys { + compatible = "gpio-keys"; + + reset { + label = "reset"; + gpios = <&gpio0 6 GPIO_ACTIVE_LOW>; + linux,code = ; + }; + + repeater { + label = "repeater"; + gpios = <&gpio0 7 GPIO_ACTIVE_LOW>; + linux,code = ; + linux,input-type = ; + }; + + wps { + label = "wps"; + gpios = <&gpio0 18 GPIO_ACTIVE_LOW>; + linux,code = ; + }; + }; +}; + +&nand { + status = "okay"; + + partitions: partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "u-boot"; + reg = <0x0 0x0100000>; + read-only; + }; + + partition@100000 { + label = "u-boot-env"; + reg = <0x0100000 0x0100000>; + read-only; + }; + + factory: partition@200000 { + label = "factory"; + reg = <0x0200000 0x0100000>; + }; + + partition@300000 { + label = "SecondBoot"; + reg = <0x0300000 0x0100000>; + read-only; + }; + + partition@400000 { + label = "kernel"; + reg = <0x0400000 0x0400000>; + }; + + partition@800000 { + label = "ubi"; + reg = <0x0800000 0x2e00000>; + }; + + partition@3600000 { + label = "Config"; + reg = <0x3600000 0x0100000>; + read-only; + }; + + partition@3700000 { + label = "firmware_2"; + reg = <0x3700000 0x3200000>; + }; + + partition@6900000 { + label = "Config_2"; + reg = <0x6900000 0x0100000>; + read-only; + }; + + partition@6a00000 { + label = "persist"; + reg = <0x6a00000 0x0100000>; + }; + }; +}; + +ðernet { + mtd-mac-address = <&factory 0xe000>; +}; + +&pcie { + status = "okay"; +}; + +&state_default { + gpio { + ralink,group = "uart2", "uart3", "wdt"; + ralink,function = "gpio"; + }; +}; + +&xhci { + status = "disabled"; +}; diff --git a/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts b/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts index 1f7715bb38..903029d10d 100644 --- a/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts +++ b/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts @@ -32,11 +32,22 @@ linux,default-trigger = "phy1tpt"; }; }; + + gpio_export { + compatible = "gpio-export"; + #size-cells = <0>; + + usb_power { + gpio-export,name = "usb_power"; + gpio-export,output = <0>; + gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; + }; + }; }; &state_default { gpio { - ralink,group = "i2c", "refclk", "wdt", "p3led_an", "wled_an"; + ralink,group = "i2c", "refclk", "wdt", "p2led_an", "p3led_an", "wled_an"; ralink,function = "gpio"; }; }; diff --git a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7621.c b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7621.c index 89be239007..232bcd8cf4 100644 --- a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7621.c +++ b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7621.c @@ -98,15 +98,9 @@ static void mt7621_hw_init(struct mt7620_gsw *gsw, struct device_node *np) mt7530_mdio_w32(gsw, 0x7000, 0x3); usleep_range(10, 20); - if ((rt_sysc_r32(SYSC_REG_CHIP_REV_ID) & 0xFFFF) == 0x0101) { - /* (GE1, Force 1000M/FD, FC ON, MAX_RX_LENGTH 1536) */ - mtk_switch_w32(gsw, 0x2305e30b, GSW_REG_MAC_P0_MCR); - mt7530_mdio_w32(gsw, 0x3600, 0x5e30b); - } else { - /* (GE1, Force 1000M/FD, FC ON, MAX_RX_LENGTH 1536) */ - mtk_switch_w32(gsw, 0x2305e33b, GSW_REG_MAC_P0_MCR); - mt7530_mdio_w32(gsw, 0x3600, 0x5e33b); - } + /* (GE1, Force 1000M/FD, FC OFF, MAX_RX_LENGTH 1536) */ + mtk_switch_w32(gsw, 0x2305e30b, GSW_REG_MAC_P0_MCR); + mt7530_mdio_w32(gsw, 0x3600, 0x5e30b); /* (GE2, Link down) */ mtk_switch_w32(gsw, 0x8000, GSW_REG_MAC_P1_MCR); diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk index b21ebd4c84..f41457da9d 100644 --- a/target/linux/ramips/image/mt7621.mk +++ b/target/linux/ramips/image/mt7621.mk @@ -65,6 +65,28 @@ define Build/iodata-factory fi endef +define Build/iodata-mstc-header + ( \ + data_size_crc="$$(dd if=$@ ibs=64 skip=1 2>/dev/null | \ + gzip -c | tail -c 8 | od -An -tx8 --endian little | tr -d ' \n')"; \ + echo -ne "$$(echo $$data_size_crc | sed 's/../\\x&/g')" | \ + dd of=$@ bs=8 count=1 seek=7 conv=notrunc 2>/dev/null; \ + ) + dd if=/dev/zero of=$@ bs=4 count=1 seek=1 conv=notrunc 2>/dev/null + ( \ + header_crc="$$(dd if=$@ bs=64 count=1 2>/dev/null | \ + gzip -c | tail -c 8 | od -An -N4 -tx4 --endian little | tr -d ' \n')"; \ + echo -ne "$$(echo $$header_crc | sed 's/../\\x&/g')" | \ + dd of=$@ bs=4 count=1 seek=1 conv=notrunc 2>/dev/null; \ + ) +endef + +define Build/netis-tail + echo -n $(1) >> $@ + echo -n $(UIMAGE_NAME)-yun | $(STAGING_DIR_HOST)/bin/mkhash md5 | \ + sed 's/../\\\\x&/g' | xargs echo -ne >> $@ +endef + define Build/ubnt-erx-factory-image if [ -e $(KDIR)/tmp/$(KERNEL_INITRAMFS_IMAGE) -a "$$(stat -c%s $@)" -lt "$(KERNEL_SIZE)" ]; then \ echo '21001:6' > $(1).compat; \ @@ -336,6 +358,38 @@ define Device/iodata_wn-ax1167gr endef TARGET_DEVICES += iodata_wn-ax1167gr +define Device/iodata_wn-ax1167gr2 + BLOCKSIZE := 128k + PAGESIZE := 2048 + UBINIZE_OPTS := -E 5 + UIMAGE_MAGIC := 0x434f4d42 + KERNEL_SIZE := 4096k + IMAGE_SIZE := 51200k + DEVICE_VENDOR := I-O DATA + DEVICE_MODEL := WN-AX1167GR2 + KERNEL_INITRAMFS := $(KERNEL_DTB) | custom-initramfs-uimage 3.10(XBC.1)b10 | \ + iodata-mstc-header + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata + DEVICE_PACKAGES := kmod-mt7615e wpad-openssl +endef +TARGET_DEVICES += iodata_wn-ax1167gr2 + +define Device/iodata_wn-dx1167r + BLOCKSIZE := 128k + PAGESIZE := 2048 + UBINIZE_OPTS := -E 5 + UIMAGE_MAGIC := 0x434f4d43 + KERNEL_SIZE := 4096k + IMAGE_SIZE := 51200k + DEVICE_VENDOR := I-O DATA + DEVICE_MODEL := WN-DX1167R + KERNEL_INITRAMFS := $(KERNEL_DTB) | custom-initramfs-uimage 3.10(XIK.1)b10 | \ + iodata-mstc-header + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata + DEVICE_PACKAGES := kmod-mt7615e wpad-openssl +endef +TARGET_DEVICES += iodata_wn-dx1167r + define Device/iodata_wn-gx300gr IMAGE_SIZE := 7616k DEVICE_VENDOR := I-O DATA @@ -602,8 +656,9 @@ define Device/netis_wf2881 FILESYSTEMS := squashfs KERNEL_SIZE := 4096k IMAGE_SIZE := 129280k - KERNEL := $(KERNEL_DTB) | pad-offset $$(BLOCKSIZE) 64 | uImage lzma UBINIZE_OPTS := -E 5 + UIMAGE_NAME := WF2881_0.0.00 + KERNEL_INITRAMFS := $(KERNEL_DTB) | netis-tail WF2881 | uImage lzma IMAGES += factory.bin IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi | \ @@ -611,7 +666,6 @@ define Device/netis_wf2881 DEVICE_VENDOR := NETIS DEVICE_MODEL := WF2881 DEVICE_PACKAGES := kmod-mt76x2 kmod-usb3 kmod-usb-ledtrig-usbport wpad-openssl - SUPPORTED_DEVICES += wf-2881 endef TARGET_DEVICES += netis_wf2881 @@ -619,8 +673,6 @@ define Device/phicomm_k2p IMAGE_SIZE := 15744k DEVICE_VENDOR := Phicomm DEVICE_MODEL := K2P - DEVICE_ALT0_VENDOR := Phicomm - DEVICE_ALT0_MODEL := KE 2P SUPPORTED_DEVICES += k2p DEVICE_PACKAGES := luci-app-mtwifi endef diff --git a/target/linux/ramips/modules.mk b/target/linux/ramips/modules.mk index b604110b1e..89bdc6c95c 100644 --- a/target/linux/ramips/modules.mk +++ b/target/linux/ramips/modules.mk @@ -20,7 +20,7 @@ define KernelPackage/pwm-mediatek-ramips AUTOLOAD:=$(call AutoProbe,pwm-mediatek-ramips) endef -define KernelPackage/pwm-mediatek/description +define KernelPackage/pwm-mediatek-ramips/description Kernel modules for MediaTek Pulse Width Modulator endef diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network index 978e8df648..58605aca70 100755 --- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network +++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network @@ -77,6 +77,8 @@ ramips_setup_interfaces() elecom,wrc-1900gst|\ elecom,wrc-2533gst|\ iodata,wn-ax1167gr|\ + iodata,wn-ax1167gr2|\ + iodata,wn-dx1167r|\ iodata,wn-gx300gr|\ iodata,wnpr2600g|\ iptime,a8004t) @@ -228,6 +230,12 @@ ramips_setup_macs() xiaoyu,xy-c5) wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1) ;; + iodata,wn-ax1167gr2|\ + iodata,wn-dx1167r|\ + xiaomi,mir3g-v2) + wan_mac=$(mtd_get_mac_binary factory 0xe006) + label_mac=$wan_mac + ;; iodata,wnpr2600g) wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr) label_mac=$wan_mac @@ -273,10 +281,6 @@ ramips_setup_macs() lan_mac=$(mtd_get_mac_binary factory 0xe006) label_mac=$lan_mac ;; - xiaomi,mir3g-v2) - wan_mac=$(mtd_get_mac_binary factory 0xe006) - label_mac=$wan_mac - ;; zbtlink,zbt-we1326) wan_mac=$(mtd_get_mac_binary factory 0xe006) label_mac=$(mtd_get_mac_binary factory 0x4) diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh new file mode 100644 index 0000000000..d7a3477f0a --- /dev/null +++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh @@ -0,0 +1,55 @@ +# +# Copyright (C) 2019 OpenWrt.org +# + +. /lib/functions.sh + +iodata_mstc_prepare_fail() { + echo "failed to check and prepare the environment, rebooting..." + umount -a + reboot -f +} + +# I-O DATA devices manufactured by MSTC (MitraStar Technology Corp.) +# have two important flags: +# - bootnum: switch between two os images +# use 1st image in OpenWrt +# - debugflag: enable/disable debug +# users can interrupt Z-Loader for recovering the device if enabled +iodata_mstc_upgrade_prepare() { + local persist_mtd="$(find_mtd_part persist)" + local factory_mtd="$(find_mtd_part factory)" + + if [ -z "$persist_mtd" -o -z "$factory_mtd" ]; then + echo 'cannot find mtd partition(s), "factory" or "persist"' + iodata_mstc_prepare_fail + fi + + local bootnum=$(hexdump -s 4 -n 1 -e '"%x"' ${persist_mtd}) + local debugflag=$(hexdump -s 65141 -n 1 -e '"%x"' ${factory_mtd}) + + if [ "$bootnum" != "1" -a "$bootnum" != "2" ]; then + echo "failed to get bootnum, please check the value at 0x4 in ${persist_mtd}" + iodata_mstc_prepare_fail + fi + if [ "$debugflag" != "0" -a "$debugflag" != "1" ]; then + echo "failed to get debugflag, please check the value at 0xFE75 in ${factory_mtd}" + iodata_mstc_prepare_fail + fi + echo "current: bootnum => ${bootnum}, debugflag => ${debugflag}" + + if [ "$bootnum" = "2" ]; then + if ! (echo -ne "\x01" | dd bs=1 count=1 seek=4 conv=notrunc of=${persist_mtd} 2>/dev/null); then + echo "failed to set bootnum" + iodata_mstc_prepare_fail + fi + echo "### switch to 1st os-image on next boot ###" + fi + if [ "$debugflag" = "0" ]; then + if ! (echo -ne "\x01" | dd bs=1 count=1 seek=65141 conv=notrunc of=${factory_mtd} 2>/dev/null); then + echo "failed to set debugflag" + iodata_mstc_prepare_fail + fi + echo "### enable debug ###" + fi +} diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh index ff19577bb3..f6b5c86431 100755 --- a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh +++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh @@ -55,6 +55,11 @@ platform_do_upgrade() { xiaomi,mir3p) nand_do_upgrade "$1" ;; + iodata,wn-ax1167gr2|\ + iodata,wn-dx1167r) + iodata_mstc_upgrade_prepare + nand_do_upgrade "$1" + ;; ubiquiti,edgerouterx|\ ubiquiti,edgerouterx-sfp) platform_upgrade_ubnt_erx "$1" diff --git a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network index 6ba23f9451..913a0817dc 100755 --- a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network +++ b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network @@ -60,7 +60,6 @@ ramips_setup_interfaces() "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0" ;; hiwifi,hc5661a|\ - hiwifi,hc5761a|\ mediatek,mt7628an-eval-board|\ mercury,mac1200r-v2|\ totolink,lr1200|\ @@ -69,6 +68,10 @@ ramips_setup_interfaces() ucidef_add_switch "switch0" \ "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0" ;; + hiwifi,hc5761a) + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "4:wan" "6@eth0" + ;; iptime,a3) ucidef_add_switch "switch0" \ "2:lan:2" "3:lan:1" "0:wan" "6@eth0" From 62ec3bfa9de27bffd60de389f8f445b2807021b3 Mon Sep 17 00:00:00 2001 From: Max Zhao Date: Sat, 22 Feb 2020 12:45:34 +0800 Subject: [PATCH 6/6] luci-app-ssr-plus: support custom url to update chnroute (#3221) * luci-app-ssr-plus: support custom url to update chnroute * Update ssr-plus.po * Update update.lua * Update advanced.lua * Update Makefile Co-authored-by: coolsnowwolf <31687149+coolsnowwolf@users.noreply.github.com> --- package/lean/luci-app-ssr-plus/Makefile | 3 +- .../luasrc/controller/shadowsocksr.lua | 30 +++++++++++-------- .../model/cbi/shadowsocksr/advanced.lua | 10 +++++++ .../luci-app-ssr-plus/po/zh-cn/ssr-plus.po | 9 ++++++ .../root/usr/share/shadowsocksr/update.lua | 12 +++++--- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/package/lean/luci-app-ssr-plus/Makefile b/package/lean/luci-app-ssr-plus/Makefile index 9d826919f9..680b2c13dd 100644 --- a/package/lean/luci-app-ssr-plus/Makefile +++ b/package/lean/luci-app-ssr-plus/Makefile @@ -2,7 +2,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-ssr-plus PKG_VERSION:=150 -PKG_RELEASE:=1 +PKG_RELEASE:=2 + PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) include $(INCLUDE_DIR)/package.mk diff --git a/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua b/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua index 16312f2517..d882b2ed2e 100644 --- a/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua +++ b/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua @@ -99,21 +99,25 @@ else retstring ="-1" end elseif set == "ip_data" then -refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" -sret=luci.sys.call(refresh_cmd) -icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") -if sret== 0 and tonumber(icount)>1000 then - oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") - if tonumber(icount) ~= tonumber(oldcount) then - luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt") - retstring=tostring(tonumber(icount)) + if (luci.model.uci.cursor():get_first('shadowsocksr', 'global', 'chnroute', '0') == '1') then + refresh_cmd="wget-ssl --no-check-certificate -O - " .. luci.model.uci.cursor():get_first('shadowsocksr', 'global', 'chnroute_url', 'https://pexcn.me/daily/chnroute/chnroute.txt') .. ' > /tmp/china_ssr.txt 2>/dev/null' else - retstring ="0" + refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" end -else - retstring ="-1" -end -luci.sys.exec("rm -f /tmp/china_ssr.txt ") + sret=luci.sys.call(refresh_cmd) + icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") + if sret== 0 and tonumber(icount)>1000 then + oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") + if tonumber(icount) ~= tonumber(oldcount) then + luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt") + retstring=tostring(tonumber(icount)) + else + retstring ="0" + end + else + retstring ="-1" + end + luci.sys.exec("rm -f /tmp/china_ssr.txt ") else if nixio.fs.access("/usr/bin/wget-ssl") then refresh_cmd="wget-ssl --no-check-certificate -O - ".. luci.model.uci.cursor():get_first('shadowsocksr', 'global', 'adblock_url','https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt') .." > /tmp/adnew.conf" diff --git a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua index c72cc58751..7e1070cb1e 100644 --- a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua +++ b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua @@ -54,6 +54,16 @@ o.rmempty = false o = s:option(Value, "adblock_url", translate("adblock_url")) o.default = "https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt" +-- [[ chnroute ]] +s = m:section(TypedSection, "global", translate("Chnroute Setting")) +s.anonymous = true + +o = s:option(Flag, "chnroute", translate("Enable custom chnroute")) +o.rmempty = false + +o = s:option(Value, "chnroute_url", translate("Update url")) +o.default = "https://cdn.jsdelivr.net/gh/17mon/china_ip_list/china_ip_list.txt" + -- [[ SOCKS Proxy ]]-- if nixio.fs.access("/usr/bin/srelay") then s = m:section(TypedSection, "socks5_proxy", translate("SOCKS Proxy")) diff --git a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po index 48088fecb9..4dfe6366c0 100644 --- a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po +++ b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po @@ -337,6 +337,15 @@ msgstr "å¯ç”¨è¿›ç¨‹è‡ªåŠ¨å®ˆæŠ¤" msgid "Advertising Data" msgstr "ã€å¹¿å‘Šå±è”½ã€‘æ•°æ®åº“" +msgid "Chnroute Setting" +msgstr "国内IP段数æ®åº“更新设置" + +msgid "Enable custom chnroute" +msgstr "å¯ç”¨è‡ªå®šä¹‰æ›´æ–°åœ°å€" + +msgid "Update url" +msgstr "更新链接" + msgid "DNS Server IP and Port" msgstr "DNSæœåŠ¡å™¨åœ°å€å’Œç«¯å£" diff --git a/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua b/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua index 8c2958ad99..8ac39a2ec0 100644 --- a/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua +++ b/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua @@ -42,13 +42,17 @@ else end log('正在更新ã€å›½å†…IP段】数æ®åº“') -refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" +if (ucic:get_first('shadowsocksr', 'global', 'chnroute','0') == '1' ) then + refresh_cmd="wget-ssl --no-check-certificate -O - ".. ucic:get_first('shadowsocksr', 'global', 'chnroute_url','https://cdn.jsdelivr.net/gh/17mon/china_ip_list/china_ip_list.txt') .." > /tmp/china_ssr.txt 2>/dev/null" +else + refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" +end sret=luci.sys.call(refresh_cmd) icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") - if sret== 0 then +if sret== 0 then icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") if tonumber(icount)>1000 then - oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") + oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") if tonumber(icount) ~= tonumber(oldcount) then luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt") -- retstring=tostring(math.ceil(tonumber(icount)/2)) @@ -57,7 +61,7 @@ icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") log('ä½ å·²ç»æ˜¯æœ€æ–°æ•°æ®ï¼Œæ— éœ€æ›´æ–°ï¼') end else - log('更新失败ï¼') + log('更新失败ï¼') end luci.sys.exec("rm -f /tmp/china_ssr.txt") else