Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ jobs:
- name: 构建 Docker 镜像
run: cd docker && docker build -t ${{ env.DOCKER_IMAGE }} .

- name: 应用 Linux Mainline 补丁
run: cd third_party/linux_mainline && ../../scripts/apply_patches.sh linux_mainline

- name: Cache ccache for Linux Mainline
uses: actions/cache@v4
with:
Expand All @@ -219,26 +216,31 @@ jobs:
-e CCACHE_COMPILERCHECK=content \
${{ env.DOCKER_IMAGE }} \
bash -c '
git config --global --add safe.directory "*"
ccache -M 2G && ccache -z
mkdir -p /workspace/ccache-bin
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-gcc
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-g++
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-ar
export PATH="/workspace/ccache-bin:${PATH}"
./scripts/build_helper/build-mainline-linux.sh
./scripts/release-all.sh --mainline --stage 2
ccache -s
'

- name: 验证产物
run: |
[ -f out/mainline/linux/arch/arm/boot/zImage ] || exit 1
file out/mainline/linux/arch/arm/boot/zImage | grep -q ARM
[ -f out/release-latest/linux/arch/arm/boot/zImage ] || exit 1
[ -f out/release-latest/linux/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb ] || exit 1
file out/release-latest/linux/arch/arm/boot/zImage | grep -q ARM
grep -q "Kernel Track: mainline" out/release-latest/linux/build_info.txt

- name: 上传产物
uses: actions/upload-artifact@v4
with:
name: linux-mainline
path: out/mainline/linux/arch/arm/boot/zImage
path: |
out/release-latest/linux/arch/arm/boot/zImage
out/release-latest/linux/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb
retention-days: 7

# BusyBox 构建
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/ci-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,6 @@ jobs:
- name: 构建 Docker 镜像
run: cd docker && docker build -t ${{ env.DOCKER_IMAGE }} .

- name: 应用 Linux Mainline 补丁
run: |
if [ -f "patches/linux_mainline/linux_mainline-feat-imx6ull_patches-20260322.patch" ]; then
cd third_party/linux_mainline
git apply --3way ../../patches/linux_mainline/linux_mainline-feat-imx6ull_patches-20260322.patch || true
cd ../..
fi

- name: Cache ccache for Linux Mainline
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -219,13 +211,15 @@ jobs:
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-g++
ln -sf /usr/bin/ccache /workspace/ccache-bin/arm-none-linux-gnueabihf-ar
export PATH="/workspace/ccache-bin:${PATH}"
./scripts/build_helper/build-mainline-linux.sh
./scripts/release-all.sh --mainline --stage 2
ccache -s
'

- name: 验证产物
run: |
[ -f out/mainline/linux/arch/arm/boot/zImage ] || exit 1
[ -f out/release-latest/linux/arch/arm/boot/zImage ] || exit 1
[ -f out/release-latest/linux/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb ] || exit 1
grep -q "Kernel Track: mainline" out/release-latest/linux/build_info.txt

# Stage 3+4: BusyBox + RootFS (合并)
stage3-4:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# build_release_mainline_linux.sh - Linux Mainline 发布构建脚本

## 概述

`build_release_mainline_linux.sh` 用于构建发布布局中的 Linux Mainline 内核。它服务于 `scripts/release-all.sh --mainline --stage 2`,输出目录由 `OUTPUT_DIR` 控制,release-all 默认写入 `out/release-latest/linux`。

这个脚本不会追踪上游 `origin/HEAD`。Mainline 内核源码固定使用 superproject 记录的 `third_party/linux_mainline` gitlink commit;该提交由维护者周期性更新,避免普通 PR 因上游 mainline 变化而破坏构建。

## 使用方法

```bash
./scripts/release_builder/build_release_mainline_linux.sh [--fast-build] [release_version]
```

通常不直接调用,而是通过:

```bash
./scripts/release-all.sh --mainline --stage 2
./scripts/release-all.sh --mainline --stage 2 --fast-build
```

## 参数说明

| 参数 | 说明 | 必需/可选 |
|------|------|-----------|
| `--fast-build` | 传递给 `build-mainline-linux.sh`,跳过输出目录 distclean | 可选 |
| `release_version` | 写入 `build_info.txt` 的发布版本 | 可选 |
| `--help`, `-h` | 显示帮助信息 | 可选 |

## 执行流程

1. 读取 superproject 锁定的 `third_party/linux_mainline` commit。
2. 如果子模块未初始化或本地缺少锁定提交,则执行 `git submodule update --init --depth=1 third_party/linux_mainline`。
3. 清理 `third_party/linux_mainline` 并 checkout 到锁定提交。
4. 创建临时 release 分支。
5. 从 `patches/linux_mainline/*.patch` 中按文件名排序选择最新补丁并应用;补丁冲突会使构建失败。
6. 调用 `scripts/build_helper/build-mainline-linux.sh` 构建 `zImage` 和 DTB。
7. 生成 `build_info.txt`,记录 `Kernel Track: mainline`、锁定提交和补丁信息。

## 依赖关系

### 依赖的脚本

- `scripts/build_helper/build-mainline-linux.sh`

### 依赖的目录

- `third_party/linux_mainline`
- `patches/linux_mainline`

## 环境变量

| 变量 | 说明 | 默认值 |
|------|------|--------|
| `OUTPUT_DIR` | 内核构建输出目录 | `out/mainline/linux` |
| `SOURCE_DATE_EPOCH` | 可重现构建时间戳 | `1609459200` |

## 输出产物

- `${OUTPUT_DIR}/arch/arm/boot/zImage`
- `${OUTPUT_DIR}/arch/arm/boot/dts/nxp/imx/imx6ull-aes.dtb`
- `${OUTPUT_DIR}/vmlinux`
- `${OUTPUT_DIR}/System.map`
- `${OUTPUT_DIR}/build_info.txt`

## 注意事项

- 该脚本会对 `third_party/linux_mainline` 执行 `git reset --hard` 和 `git clean -ffdx`。
- 更新 Mainline 内核版本应通过更新 submodule gitlink commit 完成,而不是修改本脚本去追远程 HEAD。
27 changes: 20 additions & 7 deletions scripts/build_helper/build-mainline-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ARCH=arm
CROSS_COMPILE=arm-none-linux-gnueabihf-
DEFCONFIG=imx_aes_mainline_defconfig
FAST_BUILD=0
DEVICE_TREE="${DEFAULT_DEVICE_TREE:-imx6ull-aes}"

# Parse arguments
for arg in "$@"; do
Expand Down Expand Up @@ -283,7 +284,7 @@ do_configure() {
# Build Linux kernel
do_build() {
log_info "Building Linux kernel..."
local cmd="make -C ${LINUX_SRC_DIR} ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} O=${OUTPUT_DIR} -j${NPROC}"
local cmd="make -C ${LINUX_SRC_DIR} ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} O=${OUTPUT_DIR} -j${NPROC} zImage dtbs"
echo -e "${YELLOW}[CMD]${NC} ${cmd}"
${cmd}
}
Expand Down Expand Up @@ -326,34 +327,44 @@ verify_build_artifacts() {

# 2. Verify zImage (compressed kernel image)
if [ -f "${OUTPUT_DIR}/arch/arm/boot/zImage" ]; then
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)
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)
log_info " ✓ zImage: ${SIZE} bytes"
else
log_error " ✗ zImage: not found"
has_error=1
fi

# 3. Verify .config file
# 3. Verify board DTB
local dtb_path="${OUTPUT_DIR}/arch/arm/boot/dts/nxp/imx/${DEVICE_TREE}.dtb"
if [ -f "${dtb_path}" ]; then
SIZE=$(stat -c%s "${dtb_path}" 2>/dev/null || stat -f%z "${dtb_path}" 2>/dev/null)
log_info " ✓ ${DEVICE_TREE}.dtb: ${SIZE} bytes"
else
log_error " ✗ ${DEVICE_TREE}.dtb: not found"
has_error=1
fi

# 4. Verify .config file
if [ -f "${OUTPUT_DIR}/.config" ]; then
log_info " ✓ .config: present"
else
log_error " ✗ .config: not found"
has_error=1
fi

# 4. Check for System.map
# 5. Check for System.map
if [ -f "${OUTPUT_DIR}/System.map" ]; then
log_info " ✓ System.map: present"
else
log_warn " ! System.map: not found (optional)"
fi

# 5. Check for modules directory
# 6. Check for modules directory
if [ -d "${OUTPUT_DIR}/modules" ]; then
log_info " ✓ modules: directory present"
fi

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

log_info "========================================"
log_info "All checks passed, starting build..."
Expand All @@ -394,6 +405,7 @@ main() {
log_info " Architecture: ${ARCH}"
log_info " Cross Compile: ${CROSS_COMPILE}"
log_info " Defconfig: ${DEFCONFIG}"
log_info " Device Tree: ${DEVICE_TREE}"
log_info " Parallel Jobs: ${NPROC}"
log_info "========================================"

Expand All @@ -413,6 +425,7 @@ main() {
log_info "Kernel artifacts in ${OUTPUT_DIR}:"
[ -f "${OUTPUT_DIR}/vmlinux" ] && log_info " ✓ vmlinux (ELF kernel)"
[ -f "${OUTPUT_DIR}/arch/arm/boot/zImage" ] && log_info " ✓ arch/arm/boot/zImage (compressed kernel)"
[ -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)"
[ -f "${OUTPUT_DIR}/System.map" ] && log_info " ✓ System.map (symbol table)"
[ -f "${OUTPUT_DIR}/.config" ] && log_info " ✓ .config (kernel configuration)"

Expand Down
Loading
Loading