@@ -75,13 +75,161 @@ rewrite_feeds() {
7575disable_mtk_feed () {
7676 for feed_file in feeds.conf feeds.conf.default; do
7777 if [ -f " $feed_file " ]; then
78- sed_in_place ' /^src-git\(-full\)\? mtk /d' " $feed_file "
78+ sed_in_place ' /^src-\( git\|link\) \(-full\)\? mtk /d' " $feed_file "
7979 fi
8080 done
8181
8282 rm -rf ./feeds/mtk ./feeds/mtk.index
8383}
8484
85+ mtk_feed_source_dir=" ./.mtk-feed-source"
86+ mtk_feed_mode=" ${MTK_FEED_MODE:- disabled} "
87+ mtk_feed_branch=" ${MTK_FEED_BRANCH:- master} "
88+ mtk_feed_version_dir=" ${MTK_FEED_VERSION_DIR:- 24.10} "
89+ mtk_feed_official_url=" ${MTK_FEED_OFFICIAL_URL:- https:// git01.mediatek.com/ openwrt/ feeds/ mtk-openwrt-feeds.git} "
90+ mtk_feed_mirror_url=" ${MTK_FEED_MIRROR_URL:- https:// github.com/ GainStrongService/ mtk-openwrt-feeds.git} "
91+ mtk_feed_mapping_url=" ${MTK_FEED_MAPPING_URL:- https:// raw.githubusercontent.com/ GainStrongService/ mtk-openwrt-feeds/ master/ mtk-openwrt-feeds-commit-sha-mapping-table.md} "
92+
93+ configure_mtk_feed_link () {
94+ local abs_source_dir
95+ abs_source_dir=" $( cd " $mtk_feed_source_dir " && pwd -P) "
96+
97+ for feed_file in feeds.conf feeds.conf.default; do
98+ if [ -f " $feed_file " ]; then
99+ sed_in_place ' /^src-\(git\|link\)\(-full\)\? mtk /d' " $feed_file "
100+ printf ' src-link mtk %s\n' " $abs_source_dir " >> " $feed_file "
101+ fi
102+ done
103+ }
104+
105+ resolve_mtk_official_head () {
106+ git ls-remote " $mtk_feed_official_url " " refs/heads/$mtk_feed_branch " | awk ' NR==1 {print $1}'
107+ }
108+
109+ resolve_mtk_mirror_full_sha () {
110+ local official_sha=$1
111+ local official_short mirror_short
112+
113+ official_short=" ${official_sha: 0: 8} "
114+ mirror_short=" $(
115+ curl -fsSL " $mtk_feed_mapping_url " | awk -F' |' -v sha=" $official_short " '
116+ function trim(s) {
117+ gsub(/^[[:space:]]+|[[:space:]]+$/, "", s)
118+ return s
119+ }
120+ trim($2) == sha {
121+ print trim($3)
122+ exit
123+ }
124+ '
125+ ) "
126+
127+ if [ -z " $mirror_short " ]; then
128+ return 1
129+ fi
130+
131+ curl -fsSL \
132+ -H ' Accept: application/vnd.github+json' \
133+ -H ' User-Agent: yaof-bpi-r4-ci' \
134+ " https://api.github.com/repos/GainStrongService/mtk-openwrt-feeds/commits/$mirror_short " \
135+ | jq -r ' .sha // empty'
136+ }
137+
138+ checkout_mtk_mirror_commit () {
139+ local target_sha=$1
140+
141+ rm -rf " $mtk_feed_source_dir "
142+ git init " $mtk_feed_source_dir " > /dev/null 2>&1
143+ git -C " $mtk_feed_source_dir " remote add origin " $mtk_feed_mirror_url "
144+ git -C " $mtk_feed_source_dir " fetch --depth 1 origin " $target_sha " > /dev/null 2>&1
145+ git -C " $mtk_feed_source_dir " checkout --detach FETCH_HEAD > /dev/null 2>&1
146+ }
147+
148+ prepare_mtk_feed_source () {
149+ local official_head mirror_sha
150+
151+ case " $mtk_feed_mode " in
152+ disabled)
153+ echo " [MTK] Feed disabled"
154+ disable_mtk_feed
155+ return 0
156+ ;;
157+ official)
158+ echo " [MTK] Using official feed: $mtk_feed_official_url @$mtk_feed_branch "
159+ rm -rf " $mtk_feed_source_dir "
160+ git clone --depth 1 -b " $mtk_feed_branch " " $mtk_feed_official_url " " $mtk_feed_source_dir "
161+ ;;
162+ auto|mirror)
163+ if [ " $mtk_feed_mode " = " auto" ]; then
164+ echo " [MTK] Trying official feed: $mtk_feed_official_url @$mtk_feed_branch "
165+ rm -rf " $mtk_feed_source_dir "
166+ if git clone --depth 1 -b " $mtk_feed_branch " " $mtk_feed_official_url " " $mtk_feed_source_dir " ; then
167+ echo " [MTK] Official feed clone succeeded"
168+ configure_mtk_feed_link
169+ return 0
170+ fi
171+ echo " [MTK] Official feed clone failed; falling back to mirror"
172+ else
173+ rm -rf " $mtk_feed_source_dir "
174+ fi
175+
176+ official_head=" $( resolve_mtk_official_head) "
177+ if [ -z " $official_head " ]; then
178+ echo " [MTK] Unable to resolve official head from $mtk_feed_official_url @$mtk_feed_branch " >&2
179+ return 1
180+ fi
181+ echo " [MTK] Official head is $official_head "
182+
183+ if checkout_mtk_mirror_commit " $official_head " ; then
184+ echo " [MTK] Mirror contains matching commit $official_head "
185+ else
186+ mirror_sha=" $( resolve_mtk_mirror_full_sha " $official_head " ) "
187+ if [ -z " $mirror_sha " ]; then
188+ echo " [MTK] Unable to map official commit $official_head to mirror commit" >&2
189+ return 1
190+ fi
191+ checkout_mtk_mirror_commit " $mirror_sha "
192+ echo " [MTK] Mirror fallback commit is $mirror_sha "
193+ fi
194+ ;;
195+ * )
196+ echo " [MTK] Unsupported MTK_FEED_MODE: $mtk_feed_mode " >&2
197+ return 1
198+ ;;
199+ esac
200+
201+ configure_mtk_feed_link
202+ }
203+
204+ apply_mtk_feed_overlay () {
205+ local overlay_dir=" ./feeds/mtk/$mtk_feed_version_dir "
206+ local patch_dir patch_file
207+
208+ if [ ! -d " $overlay_dir " ]; then
209+ echo " [MTK] Overlay directory $overlay_dir not found" >&2
210+ return 1
211+ fi
212+
213+ if [ -d " $overlay_dir /files" ]; then
214+ echo " [MTK] Applying files overlay from $overlay_dir /files"
215+ cp -af " $overlay_dir /files/." .
216+ fi
217+
218+ for patch_dir in patches-base patches-feeds; do
219+ if [ ! -d " $overlay_dir /$patch_dir " ]; then
220+ continue
221+ fi
222+
223+ while IFS= read -r patch_file; do
224+ [ -n " $patch_file " ] || continue
225+ echo " [MTK] Applying patch $patch_file "
226+ patch -f -p1 -i " $patch_file "
227+ done << EOF
228+ $( find " $overlay_dir /$patch_dir " -type f -name ' *.patch' | sort)
229+ EOF
230+ done
231+ }
232+
85233rewrite_feeds " https://github.com/openwrt/packages.git;openwrt-24.10" \
86234 " https://github.com/openwrt/luci.git;openwrt-24.10" \
87235 " https://github.com/openwrt/routing.git;openwrt-24.10" \
@@ -103,13 +251,12 @@ if ! ./scripts/feeds install -a; then
103251fi
104252
105253# ## 基础部分 ###
106- # 可选:接入 MediaTek 的 OpenWrt feeds 或本地 SDK(当前默认禁用,因上游地址 404)
107- # 如后续恢复可用,可重新启用下面逻辑:
108- # MTK_FEED_URL=${MTK_FEED_URL:-https://git01.mediatek.com/openwrt/feeds/mtk-openwrt-feeds.git}
109- # MTK_FEED_BRANCH=${MTK_FEED_BRANCH:-master}
110- # if ! grep -qE "^src-git mtk " feeds.conf.default; then
111- # echo "src-git mtk ${MTK_FEED_URL};${MTK_FEED_BRANCH}" >> feeds.conf.default
112- # fi
254+ prepare_mtk_feed_source
255+
256+ if [ " $mtk_feed_mode " != " disabled" ]; then
257+ ./scripts/feeds update mtk
258+ apply_mtk_feed_overlay
259+ fi
113260
114261# ## Custom Bootloader (Yuzhii0718) & GPT for A/B Partition ###
115262restore_openwrt_boot_package arm-trusted-firmware-mediatek || true
@@ -152,7 +299,7 @@ if [ -d "../bl-mt798x-dhcpd" ]; then
152299
153300
154301# ## WiFi regdb Optimization (OpenWrt tree only) ###
155- # Former MTK feed-specific sync is intentionally disabled together with MTK feed integration .
302+ # MTK feed preparation is handled earlier; keep the remaining tree tweaks local here .
156303rm -rf ./package/firmware/wireless-regdb/patches/*
157304cp ../PATCH/kernel/mtk_wifi/500-tx_power.patch ./package/firmware/wireless-regdb/patches/ 2> /dev/null || true
158305if [ -f " ../PATCH/kernel/mtk_wifi/regdb.Makefile" ]; then
0 commit comments