Skip to content

Commit a003f57

Browse files
committed
build: enable MTK feed and local bootloader sources
1 parent d23a61f commit a003f57

2 files changed

Lines changed: 94 additions & 20 deletions

File tree

SCRIPTS/02_prepare_package.sh

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ replace_with_custom_package_wrapper() {
5555
echo "[BOOT] Replaced $label with custom OpenWrt package wrapper"
5656
}
5757

58+
configure_package_use_source_dir() {
59+
local pkg_dir=$1
60+
local source_dir_rel=$2
61+
local label=$3
62+
local makefile="$pkg_dir/Makefile"
63+
local temp_file
64+
65+
if [ ! -d "$source_dir_rel" ] || [ ! -f "$makefile" ]; then
66+
return 1
67+
fi
68+
69+
temp_file="$(mktemp)"
70+
awk -v source_dir="$source_dir_rel" '
71+
/^USE_SOURCE_DIR:=/ { next }
72+
/^include \$\(INCLUDE_DIR\)\/package\.mk/ && !inserted {
73+
print "USE_SOURCE_DIR:=$(TOPDIR)/" source_dir
74+
inserted=1
75+
}
76+
{ print }
77+
END {
78+
if (!inserted) {
79+
print "USE_SOURCE_DIR:=$(TOPDIR)/" source_dir
80+
}
81+
}
82+
' "$makefile" > "$temp_file"
83+
mv "$temp_file" "$makefile"
84+
echo "[BOOT] Configured $label wrapper to use local source dir $source_dir_rel"
85+
}
86+
5887
### feeds 优化 ###
5988
# 先尝试 GitHub 镜像,失败后回退到 git.openwrt.org
6089
rewrite_feeds() {
@@ -83,7 +112,7 @@ disable_mtk_feed() {
83112
}
84113

85114
mtk_feed_source_dir="./.mtk-feed-source"
86-
mtk_feed_mode="${MTK_FEED_MODE:-disabled}"
115+
mtk_feed_mode="${MTK_FEED_MODE:-auto}"
87116
mtk_feed_branch="${MTK_FEED_BRANCH:-master}"
88117
mtk_feed_version_dir="${MTK_FEED_VERSION_DIR:-24.10}"
89118
mtk_feed_official_url="${MTK_FEED_OFFICIAL_URL:-https://git01.mediatek.com/openwrt/feeds/mtk-openwrt-feeds.git}"
@@ -246,10 +275,6 @@ if ! ./scripts/feeds update -a; then
246275
./scripts/feeds update -a
247276
fi
248277

249-
if ! ./scripts/feeds install -a; then
250-
echo "Feeds 安装部分失败,请检查上游仓库状态。" >&2
251-
fi
252-
253278
### 基础部分 ###
254279
prepare_mtk_feed_source
255280

@@ -258,35 +283,47 @@ if [ "$mtk_feed_mode" != "disabled" ]; then
258283
apply_mtk_feed_overlay
259284
fi
260285

286+
if ! ./scripts/feeds install -a; then
287+
echo "Feeds 安装部分失败,请检查上游仓库状态。" >&2
288+
fi
289+
261290
### Custom Bootloader (Yuzhii0718) & GPT for A/B Partition ###
262291
restore_openwrt_boot_package arm-trusted-firmware-mediatek || true
263292
restore_openwrt_boot_package uboot-mediatek || true
264293

265294
if [ -d "../bl-mt798x-dhcpd" ]; then
266295
echo "[BOOT] Found custom bootloader repo: bl-mt798x-dhcpd"
267-
atf_wrapper_replaced=0
296+
atf_custom_applied=0
268297

269298
# 1. Replace Arm Trusted Firmware (ATF)
270299
if replace_with_custom_package_wrapper \
271300
"../bl-mt798x-dhcpd/atf-20260123" \
272301
"./package/boot/arm-trusted-firmware-mediatek" \
273302
"ATF"; then
274-
atf_wrapper_replaced=1
303+
atf_custom_applied=1
304+
elif configure_package_use_source_dir \
305+
"./package/boot/arm-trusted-firmware-mediatek" \
306+
"../bl-mt798x-dhcpd/atf-20260123" \
307+
"ATF"; then
308+
atf_custom_applied=1
275309
fi
276310

277311
# 2. Replace U-Boot
278312
replace_with_custom_package_wrapper \
279313
"../bl-mt798x-dhcpd/uboot-mtk-20250711" \
280314
"./package/boot/uboot-mediatek" \
315+
"U-Boot" || configure_package_use_source_dir \
316+
"./package/boot/uboot-mediatek" \
317+
"../bl-mt798x-dhcpd/uboot-mtk-20250711" \
281318
"U-Boot" || true
282319

283320
# 3. Inject media-specific GPT definitions for block-device targets when requested
284-
if [ "$atf_wrapper_replaced" -eq 1 ] && [ -n "$BPI_R4_GPT_LAYOUT" ] && [ -f "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ]; then
285-
mkdir -p ./package/boot/arm-trusted-firmware-mediatek/src/gpt
286-
cp "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ./package/boot/arm-trusted-firmware-mediatek/src/gpt/
321+
if [ "$atf_custom_applied" -eq 1 ] && [ -n "$BPI_R4_GPT_LAYOUT" ] && [ -f "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ]; then
322+
mkdir -p ../bl-mt798x-dhcpd/atf-20260123/src/gpt
323+
cp "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ../bl-mt798x-dhcpd/atf-20260123/src/gpt/
287324
echo "[GPT] Injected GPT layout: $BPI_R4_GPT_LAYOUT"
288-
elif [ -n "$BPI_R4_GPT_LAYOUT" ] && [ "$atf_wrapper_replaced" -ne 1 ]; then
289-
echo "[GPT] Skipping GPT layout injection because no custom ATF package wrapper was applied"
325+
elif [ -n "$BPI_R4_GPT_LAYOUT" ] && [ "$atf_custom_applied" -ne 1 ]; then
326+
echo "[GPT] Skipping GPT layout injection because no custom ATF source was applied"
290327
elif [ -n "$BPI_R4_GPT_LAYOUT" ]; then
291328
echo "[GPT] Requested GPT layout '$BPI_R4_GPT_LAYOUT' not found, skipping"
292329
else

SCRIPTS/02_prepare_package_minimal.sh

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ replace_with_custom_package_wrapper() {
5555
echo "[BOOT] Replaced $label with custom OpenWrt package wrapper"
5656
}
5757

58+
configure_package_use_source_dir() {
59+
local pkg_dir=$1
60+
local source_dir_rel=$2
61+
local label=$3
62+
local makefile="$pkg_dir/Makefile"
63+
local temp_file
64+
65+
if [ ! -d "$source_dir_rel" ] || [ ! -f "$makefile" ]; then
66+
return 1
67+
fi
68+
69+
temp_file="$(mktemp)"
70+
awk -v source_dir="$source_dir_rel" '
71+
/^USE_SOURCE_DIR:=/ { next }
72+
/^include \$\(INCLUDE_DIR\)\/package\.mk/ && !inserted {
73+
print "USE_SOURCE_DIR:=$(TOPDIR)/" source_dir
74+
inserted=1
75+
}
76+
{ print }
77+
END {
78+
if (!inserted) {
79+
print "USE_SOURCE_DIR:=$(TOPDIR)/" source_dir
80+
}
81+
}
82+
' "$makefile" > "$temp_file"
83+
mv "$temp_file" "$makefile"
84+
echo "[BOOT] Configured $label wrapper to use local source dir $source_dir_rel"
85+
}
86+
5887
disable_mtk_feed() {
5988
for feed_file in feeds.conf feeds.conf.default; do
6089
if [ -f "$feed_file" ]; then
@@ -66,7 +95,7 @@ disable_mtk_feed() {
6695
}
6796

6897
mtk_feed_source_dir="./.mtk-feed-source"
69-
mtk_feed_mode="${MTK_FEED_MODE:-disabled}"
98+
mtk_feed_mode="${MTK_FEED_MODE:-auto}"
7099
mtk_feed_branch="${MTK_FEED_BRANCH:-master}"
71100
mtk_feed_version_dir="${MTK_FEED_VERSION_DIR:-24.10}"
72101
mtk_feed_official_url="${MTK_FEED_OFFICIAL_URL:-https://git01.mediatek.com/openwrt/feeds/mtk-openwrt-feeds.git}"
@@ -258,26 +287,34 @@ restore_openwrt_boot_package uboot-mediatek || true
258287

259288
if [ -d "../bl-mt798x-dhcpd" ]; then
260289
echo "[BOOT] Found custom bootloader repo: bl-mt798x-dhcpd"
261-
atf_wrapper_replaced=0
290+
atf_custom_applied=0
262291

263292
if replace_with_custom_package_wrapper \
264293
"../bl-mt798x-dhcpd/atf-20260123" \
265294
"./package/boot/arm-trusted-firmware-mediatek" \
266295
"ATF"; then
267-
atf_wrapper_replaced=1
296+
atf_custom_applied=1
297+
elif configure_package_use_source_dir \
298+
"./package/boot/arm-trusted-firmware-mediatek" \
299+
"../bl-mt798x-dhcpd/atf-20260123" \
300+
"ATF"; then
301+
atf_custom_applied=1
268302
fi
269303

270304
replace_with_custom_package_wrapper \
271305
"../bl-mt798x-dhcpd/uboot-mtk-20250711" \
272306
"./package/boot/uboot-mediatek" \
307+
"U-Boot" || configure_package_use_source_dir \
308+
"./package/boot/uboot-mediatek" \
309+
"../bl-mt798x-dhcpd/uboot-mtk-20250711" \
273310
"U-Boot" || true
274311

275-
if [ "$atf_wrapper_replaced" -eq 1 ] && [ -n "${BPI_R4_GPT_LAYOUT:-}" ] && [ -f "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ]; then
276-
mkdir -p ./package/boot/arm-trusted-firmware-mediatek/src/gpt
277-
cp "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ./package/boot/arm-trusted-firmware-mediatek/src/gpt/
312+
if [ "$atf_custom_applied" -eq 1 ] && [ -n "${BPI_R4_GPT_LAYOUT:-}" ] && [ -f "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ]; then
313+
mkdir -p ../bl-mt798x-dhcpd/atf-20260123/src/gpt
314+
cp "../PATCH/gpt/$BPI_R4_GPT_LAYOUT" ../bl-mt798x-dhcpd/atf-20260123/src/gpt/
278315
echo "[GPT] Injected GPT layout: $BPI_R4_GPT_LAYOUT"
279-
elif [ -n "${BPI_R4_GPT_LAYOUT:-}" ] && [ "$atf_wrapper_replaced" -ne 1 ]; then
280-
echo "[GPT] Skipping GPT layout injection because no custom ATF package wrapper was applied"
316+
elif [ -n "${BPI_R4_GPT_LAYOUT:-}" ] && [ "$atf_custom_applied" -ne 1 ]; then
317+
echo "[GPT] Skipping GPT layout injection because no custom ATF source was applied"
281318
elif [ -n "${BPI_R4_GPT_LAYOUT:-}" ]; then
282319
echo "[GPT] Requested GPT layout '$BPI_R4_GPT_LAYOUT' not found, skipping"
283320
else

0 commit comments

Comments
 (0)