Skip to content

Commit a60d740

Browse files
committed
ci: add MTK feed mirror fallback by commit
1 parent c734d1f commit a60d740

6 files changed

Lines changed: 319 additions & 25 deletions

File tree

.github/workflows/BPI-R4-Minimal-MTK-Bootloader-Test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
openwrt/dl
3636
openwrt/staging_dir
3737
openwrt/build_dir
38-
# mtk-feed # disabled for now; upstream URL currently 404
38+
# .mtk-feed-source is commit-specific and prepared on demand
3939
bl-mt798x-dhcpd
4040
key: ${{ runner.os }}-openwrt-minimal-${{ hashFiles('SCRIPTS/01_get_ready_minimal.sh', 'SCRIPTS/02_prepare_package_minimal.sh', 'SCRIPTS/BPI-R4/02_target_only_minimal.sh', 'SEED/BPI-R4-MINIMAL/config.seed') }}
4141
restore-keys: |
@@ -44,6 +44,7 @@ jobs:
4444
- name: Build with Podman
4545
env:
4646
INPUT_MEDIA: ${{ inputs.media || 'sd' }}
47+
MTK_FEED_MODE: auto
4748
run: |
4849
CURRENT_UID=$(id -u)
4950
CURRENT_GID=$(id -g)
@@ -120,6 +121,7 @@ jobs:
120121
-w /build \
121122
-e CURRENT_UID=$CURRENT_UID \
122123
-e CURRENT_GID=$CURRENT_GID \
124+
-e MTK_FEED_MODE=$MTK_FEED_MODE \
123125
-e BPI_R4_GPT_LAYOUT=$GPT_LAYOUT \
124126
ubuntu:24.04 \
125127
bash build_script.sh

.github/workflows/OpenWrt-Matrix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ jobs:
9090
bundle_kind: dummy
9191
base_name: dummy
9292
gpt_layout: dummy
93+
MTK_FEED_MODE: auto
9394

9495
runs-on: ubuntu-24.04
9596
if: github.event.repository.owner.id == github.event.sender.id

SCRIPTS/01_get_ready.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ clone_repo $dockerman_repo master dockerman &
6060
clone_repo $docker_lib_repo master docker_lib &
6161
clone_repo $luci_theme_design_repo master luci_theme_design_repo &
6262
# 等待所有后台任务完成
63-
# MTK Official Feed (disabled for now; upstream URL currently unavailable / 404)
64-
# clone_repo "https://git01.mediatek.com/openwrt/feeds/mtk-openwrt-feeds.git" "master" "mtk-feed" &
63+
# MTK feed is provisioned later in the prepare step with official-first, mirror-fallback handling.
6564

6665
# Custom Bootloader with DHCPD/WebUI (Yuzhii0718)
6766
clone_repo "https://github.com/Yuzhii0718/bl-mt798x-dhcpd.git" "master" "bl-mt798x-dhcpd" &

SCRIPTS/01_get_ready_minimal.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ clone_repo() {
1414

1515
latest_release="$(curl -s https://github.com/openwrt/openwrt/tags | grep -Eo 'v[0-9\.]+\-*r*c*[0-9]*.tar.gz' | grep 'v24.10' | sed -n 1p | sed 's/.tar.gz//g')"
1616
openwrt_repo="https://github.com/openwrt/openwrt.git"
17-
# mtk_feed_repo="https://git01.mediatek.com/openwrt/feeds/mtk-openwrt-feeds.git" # disabled: upstream currently 404
17+
# MTK feed is provisioned in the prepare step with official-first, mirror-fallback handling.
1818
custom_bootloader_repo="https://github.com/Yuzhii0718/bl-mt798x-dhcpd.git"
1919

2020
# Check if openwrt source exists and is a git repo
@@ -43,7 +43,6 @@ if [ ! -d "openwrt/.git" ]; then
4343

4444
# 4. Clone other repos (if missing)
4545
clone_repo "$openwrt_repo" openwrt-24.10 openwrt_snap &
46-
# clone_repo "$mtk_feed_repo" master mtk-feed &
4746
clone_repo "$custom_bootloader_repo" master bl-mt798x-dhcpd &
4847

4948
wait
@@ -61,8 +60,7 @@ else
6160
echo "[MINIMAL] openwrt source detected."
6261
# Ensure sub-repos exist
6362
clone_repo "$openwrt_repo" openwrt-24.10 openwrt_snap
64-
# clone_repo "$mtk_feed_repo" master mtk-feed
6563
clone_repo "$custom_bootloader_repo" master bl-mt798x-dhcpd
6664
fi
6765

68-
echo "[MINIMAL] OpenWrt base and custom bootloader sources are ready. (MTK feed currently disabled)"
66+
echo "[MINIMAL] OpenWrt base and custom bootloader sources are ready. MTK feed provisioning is handled in the prepare step."

SCRIPTS/02_prepare_package.sh

Lines changed: 156 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,161 @@ rewrite_feeds() {
7575
disable_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+
85233
rewrite_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
103251
fi
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 ###
115262
restore_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.
156303
rm -rf ./package/firmware/wireless-regdb/patches/*
157304
cp ../PATCH/kernel/mtk_wifi/500-tx_power.patch ./package/firmware/wireless-regdb/patches/ 2>/dev/null || true
158305
if [ -f "../PATCH/kernel/mtk_wifi/regdb.Makefile" ]; then

0 commit comments

Comments
 (0)