Skip to content

Commit def3ffd

Browse files
update for support of release mainline-linux build (#60)
支持在Release发布包中构建主线Linux且集成
1 parent a19a078 commit def3ffd

7 files changed

Lines changed: 424 additions & 59 deletions

File tree

.github/workflows/ci-build.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ jobs:
196196
- name: 构建 Docker 镜像
197197
run: cd docker && docker build -t ${{ env.DOCKER_IMAGE }} .
198198

199-
- name: 应用 Linux Mainline 补丁
200-
run: cd third_party/linux_mainline && ../../scripts/apply_patches.sh linux_mainline
201-
202199
- name: Cache ccache for Linux Mainline
203200
uses: actions/cache@v4
204201
with:
@@ -219,26 +216,31 @@ jobs:
219216
-e CCACHE_COMPILERCHECK=content \
220217
${{ env.DOCKER_IMAGE }} \
221218
bash -c '
219+
git config --global --add safe.directory "*"
222220
ccache -M 2G && ccache -z
223221
mkdir -p /workspace/ccache-bin
224222
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-gcc
225223
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-g++
226224
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-ar
227225
export PATH="/workspace/ccache-bin:${PATH}"
228-
./scripts/build_helper/build-mainline-linux.sh
226+
./scripts/release-all.sh --mainline --stage 2
229227
ccache -s
230228
'
231229
232230
- name: 验证产物
233231
run: |
234-
[ -f out/mainline/linux/arch/arm/boot/zImage ] || exit 1
235-
file out/mainline/linux/arch/arm/boot/zImage | grep -q ARM
232+
[ -f out/release-latest/linux/arch/arm/boot/zImage ] || exit 1
233+
[ -f out/release-latest/linux/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb ] || exit 1
234+
file out/release-latest/linux/arch/arm/boot/zImage | grep -q ARM
235+
grep -q "Kernel Track: mainline" out/release-latest/linux/build_info.txt
236236
237237
- name: 上传产物
238238
uses: actions/upload-artifact@v4
239239
with:
240240
name: linux-mainline
241-
path: out/mainline/linux/arch/arm/boot/zImage
241+
path: |
242+
out/release-latest/linux/arch/arm/boot/zImage
243+
out/release-latest/linux/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb
242244
retention-days: 7
243245

244246
# BusyBox 构建

.github/workflows/ci-full.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,6 @@ jobs:
184184
- name: 构建 Docker 镜像
185185
run: cd docker && docker build -t ${{ env.DOCKER_IMAGE }} .
186186

187-
- name: 应用 Linux Mainline 补丁
188-
run: |
189-
if [ -f "patches/linux_mainline/linux_mainline-feat-imx6ull_patches-20260322.patch" ]; then
190-
cd third_party/linux_mainline
191-
git apply --3way ../../patches/linux_mainline/linux_mainline-feat-imx6ull_patches-20260322.patch || true
192-
cd ../..
193-
fi
194-
195187
- name: Cache ccache for Linux Mainline
196188
uses: actions/cache@v4
197189
with:
@@ -219,13 +211,15 @@ jobs:
219211
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-g++
220212
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-ar
221213
export PATH="/workspace/ccache-bin:${PATH}"
222-
./scripts/build_helper/build-mainline-linux.sh
214+
./scripts/release-all.sh --mainline --stage 2
223215
ccache -s
224216
'
225217
226218
- name: 验证产物
227219
run: |
228-
[ -f out/mainline/linux/arch/arm/boot/zImage ] || exit 1
220+
[ -f out/release-latest/linux/arch/arm/boot/zImage ] || exit 1
221+
[ -f out/release-latest/linux/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb ] || exit 1
222+
grep -q "Kernel Track: mainline" out/release-latest/linux/build_info.txt
229223
230224
# Stage 3+4: BusyBox + RootFS (合并)
231225
stage3-4:
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# build_release_mainline_linux.sh - Linux Mainline 发布构建脚本
2+
3+
## 概述
4+
5+
`build_release_mainline_linux.sh` 用于构建发布布局中的 Linux Mainline 内核。它服务于 `scripts/release-all.sh --mainline --stage 2`,输出目录由 `OUTPUT_DIR` 控制,release-all 默认写入 `out/release-latest/linux`
6+
7+
这个脚本不会追踪上游 `origin/HEAD`。Mainline 内核源码固定使用 superproject 记录的 `third_party/linux_mainline` gitlink commit;该提交由维护者周期性更新,避免普通 PR 因上游 mainline 变化而破坏构建。
8+
9+
## 使用方法
10+
11+
```bash
12+
./scripts/release_builder/build_release_mainline_linux.sh [--fast-build] [release_version]
13+
```
14+
15+
通常不直接调用,而是通过:
16+
17+
```bash
18+
./scripts/release-all.sh --mainline --stage 2
19+
./scripts/release-all.sh --mainline --stage 2 --fast-build
20+
```
21+
22+
## 参数说明
23+
24+
| 参数 | 说明 | 必需/可选 |
25+
|------|------|-----------|
26+
| `--fast-build` | 传递给 `build-mainline-linux.sh`,跳过输出目录 distclean | 可选 |
27+
| `release_version` | 写入 `build_info.txt` 的发布版本 | 可选 |
28+
| `--help`, `-h` | 显示帮助信息 | 可选 |
29+
30+
## 执行流程
31+
32+
1. 读取 superproject 锁定的 `third_party/linux_mainline` commit。
33+
2. 如果子模块未初始化或本地缺少锁定提交,则执行 `git submodule update --init --depth=1 third_party/linux_mainline`
34+
3. 清理 `third_party/linux_mainline` 并 checkout 到锁定提交。
35+
4. 创建临时 release 分支。
36+
5.`patches/linux_mainline/*.patch` 中按文件名排序选择最新补丁并应用;补丁冲突会使构建失败。
37+
6. 调用 `scripts/build_helper/build-mainline-linux.sh` 构建 `zImage` 和 DTB。
38+
7. 生成 `build_info.txt`,记录 `Kernel Track: mainline`、锁定提交和补丁信息。
39+
40+
## 依赖关系
41+
42+
### 依赖的脚本
43+
44+
- `scripts/build_helper/build-mainline-linux.sh`
45+
46+
### 依赖的目录
47+
48+
- `third_party/linux_mainline`
49+
- `patches/linux_mainline`
50+
51+
## 环境变量
52+
53+
| 变量 | 说明 | 默认值 |
54+
|------|------|--------|
55+
| `OUTPUT_DIR` | 内核构建输出目录 | `out/mainline/linux` |
56+
| `SOURCE_DATE_EPOCH` | 可重现构建时间戳 | `1609459200` |
57+
58+
## 输出产物
59+
60+
- `${OUTPUT_DIR}/arch/arm/boot/zImage`
61+
- `${OUTPUT_DIR}/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb`
62+
- `${OUTPUT_DIR}/vmlinux`
63+
- `${OUTPUT_DIR}/System.map`
64+
- `${OUTPUT_DIR}/build_info.txt`
65+
66+
## 注意事项
67+
68+
- 该脚本会对 `third_party/linux_mainline` 执行 `git reset --hard``git clean -ffdx`
69+
- 更新 Mainline 内核版本应通过更新 submodule gitlink commit 完成,而不是修改本脚本去追远程 HEAD。

scripts/build_helper/build-mainline-linux.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ARCH=arm
3232
CROSS_COMPILE=arm-none-linux-gnueabihf-
3333
DEFCONFIG=imx_aes_mainline_defconfig
3434
FAST_BUILD=0
35+
DEVICE_TREE="${DEFAULT_DEVICE_TREE:-imx6ull-aes}"
3536

3637
# Parse arguments
3738
for arg in "$@"; do
@@ -283,7 +284,7 @@ do_configure() {
283284
# Build Linux kernel
284285
do_build() {
285286
log_info "Building Linux kernel..."
286-
local cmd="make -C ${LINUX_SRC_DIR} ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} O=${OUTPUT_DIR} -j${NPROC}"
287+
local cmd="make -C ${LINUX_SRC_DIR} ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} O=${OUTPUT_DIR} -j${NPROC} zImage dtbs"
287288
echo -e "${YELLOW}[CMD]${NC} ${cmd}"
288289
${cmd}
289290
}
@@ -326,34 +327,44 @@ verify_build_artifacts() {
326327

327328
# 2. Verify zImage (compressed kernel image)
328329
if [ -f "${OUTPUT_DIR}/arch/arm/boot/zImage" ]; then
329-
SIZE=$(stat -c%s ${OUTPUT_DIR}/arch/arm/boot/zImage 2>/dev/null || stat -f%z ${OUTPUT_DIR}/arch/arm/boot/zImage 2>/dev/null)
330+
SIZE=$(stat -c%s "${OUTPUT_DIR}/arch/arm/boot/zImage" 2>/dev/null || stat -f%z "${OUTPUT_DIR}/arch/arm/boot/zImage" 2>/dev/null)
330331
log_info " ✓ zImage: ${SIZE} bytes"
331332
else
332333
log_error " ✗ zImage: not found"
333334
has_error=1
334335
fi
335336

336-
# 3. Verify .config file
337+
# 3. Verify board DTB
338+
local dtb_path="${OUTPUT_DIR}/arch/arm/boot/dts/nxp/imx/${DEVICE_TREE}.dtb"
339+
if [ -f "${dtb_path}" ]; then
340+
SIZE=$(stat -c%s "${dtb_path}" 2>/dev/null || stat -f%z "${dtb_path}" 2>/dev/null)
341+
log_info "${DEVICE_TREE}.dtb: ${SIZE} bytes"
342+
else
343+
log_error "${DEVICE_TREE}.dtb: not found"
344+
has_error=1
345+
fi
346+
347+
# 4. Verify .config file
337348
if [ -f "${OUTPUT_DIR}/.config" ]; then
338349
log_info " ✓ .config: present"
339350
else
340351
log_error " ✗ .config: not found"
341352
has_error=1
342353
fi
343354

344-
# 4. Check for System.map
355+
# 5. Check for System.map
345356
if [ -f "${OUTPUT_DIR}/System.map" ]; then
346357
log_info " ✓ System.map: present"
347358
else
348359
log_warn " ! System.map: not found (optional)"
349360
fi
350361

351-
# 5. Check for modules directory
362+
# 6. Check for modules directory
352363
if [ -d "${OUTPUT_DIR}/modules" ]; then
353364
log_info " ✓ modules: directory present"
354365
fi
355366

356-
# 6. Summary
367+
# 7. Summary
357368
if [ ${has_error} -eq 0 ]; then
358369
log_info "All build artifacts verified successfully"
359370
return 0
@@ -374,7 +385,7 @@ main() {
374385
# Pre-build checks
375386
check_host_dependencies
376387
check_toolchain
377-
check_defconfig
388+
# Note: check_defconfig is called after prepare_defconfig since the file is generated from template
378389

379390
log_info "========================================"
380391
log_info "All checks passed, starting build..."
@@ -394,6 +405,7 @@ main() {
394405
log_info " Architecture: ${ARCH}"
395406
log_info " Cross Compile: ${CROSS_COMPILE}"
396407
log_info " Defconfig: ${DEFCONFIG}"
408+
log_info " Device Tree: ${DEVICE_TREE}"
397409
log_info " Parallel Jobs: ${NPROC}"
398410
log_info "========================================"
399411

@@ -413,6 +425,7 @@ main() {
413425
log_info "Kernel artifacts in ${OUTPUT_DIR}:"
414426
[ -f "${OUTPUT_DIR}/vmlinux" ] && log_info " ✓ vmlinux (ELF kernel)"
415427
[ -f "${OUTPUT_DIR}/arch/arm/boot/zImage" ] && log_info " ✓ arch/arm/boot/zImage (compressed kernel)"
428+
[ -f "${OUTPUT_DIR}/arch/arm/boot/dts/nxp/imx/${DEVICE_TREE}.dtb" ] && log_info " ✓ arch/arm/boot/dts/nxp/imx/${DEVICE_TREE}.dtb (device tree)"
416429
[ -f "${OUTPUT_DIR}/System.map" ] && log_info " ✓ System.map (symbol table)"
417430
[ -f "${OUTPUT_DIR}/.config" ] && log_info " ✓ .config (kernel configuration)"
418431

0 commit comments

Comments
 (0)