根据DTB和内核制作immortalwrt镜像
侧边栏壁纸
  • 累计撰写 19 篇文章
  • 累计收到 2 条评论

根据DTB和内核制作immortalwrt镜像

admin
2025-08-29 / 0 评论 / 2 阅读 / 正在检测是否收录...

根据您提供的开发板已有DTB和内核的情况,以下是针对ImmortalWrt镜像制作的定制化步骤指南:


一、环境准备(跳过已安装部分)

# 1. 安装基础依赖(Debian/Ubuntu示例)
sudo apt update && sudo apt install -y \
  build-essential ccache git curl wget rsync \
  libncurses5-dev gawk gettext unzip \
  python3 python3-pip python3-ply \
  device-tree-compiler  # 确保包含dtc工具

# 2. 创建专用工作目录
mkdir -p ~/immortalwrt-build && cd ~/immortalwrt-build

二、源码获取与配置

# 1. 克隆指定分支源码(以openwrt-23.05为例)
git clone -b openwrt-23.05 --single-branch https://github.com/immortalwrt/immortalwrt
cd immortalwrt

# 2. 更新软件包源
./scripts/feeds update -a
./scripts/feeds install -a

三、关键配置调整

1. 复制现有DTB和内核

将您的开发板文件放置到指定目录:

# 假设您的文件结构如下:
# ├── immortalwrt/
# │   └── target/
# │       └── linux/
# │           └── <target>/
# │               └── <subtarget>/
# │                   └── config-<version>  # 现有内核配置
# ├── dtb/                                   # 自定义DTB目录
# └── zImage                                 # 现有内核镜像

# 示例操作(根据实际路径调整):
cp /path/to/your/dtb/*.dtb target/linux/<target>/<subtarget>/
cp /path/to/your/zImage target/linux/<target>/<subtarget>/

2. 配置编译参数

make menuconfig
  • 目标系统配置

    Target System  →  选择对应SoC(如MediaTek、Qualcomm等)
    Subtarget      →  选择子型号(如MT7621)
    Target Profile →  选择具体开发板型号(或自定义)
  • 内核配置

    Kernel → 
      [*] Use custom DTB files from target/linux/<target>/<subtarget>/
      [*] Use custom kernel image (zImage)
  • 文件系统配置

    Base system → 
      <*> busybox
      <*> mtd
  • 保存配置

    Exit → Save → 输入.config文件名(如custom_config)

四、编译优化(可选)

# 1. 启用并行编译(根据CPU核心数调整)
make -j$(nproc) V=s

# 2. 使用ccache加速(首次编译后生效)
export USE_CCACHE=1

五、镜像生成与验证

# 编译完成后镜像位于bin/targets/<target>/<subtarget>/
ls bin/targets/

# 验证关键文件
file bin/targets/<target>/<subtarget>/openwrt-<target>-<subtarget>-squashfs-sysupgrade.bin
# 应显示包含您的DTB和内核版本信息

# 使用qemu测试(需安装qemu-utils)
qemu-system-aarch64 -M virt -bios bin/targets/<target>/<subtarget>/openwrt-<target>-<subtarget>-vmlinuz \
  -dtb bin/targets/<target>/<subtarget>/openwrt-<target>-<subtarget>-dtb.img \
  -drive file=bin/targets/<target>/<subtarget>/openwrt-<target>-<subtarget>-rootfs.img,format=raw

六、常见问题处理

  1. DTB加载失败

    • 检查target/linux/<target>/<subtarget>/路径是否正确
    • 确认make menuconfig中启用了自定义DTB选项
  2. 内核不匹配

    • 确保zImage与DTB的SoC版本完全一致
    • 尝试在Kernel菜单中禁用Automatically select kernel version
  3. 空间不足

    • 添加tmpfs临时编译目录:

      mkdir ~/immortalwrt-build/tmp
      mount -t tmpfs -o size=16G tmpfs ~/immortalwrt-build/tmp
      make O=$HOME/immortalwrt-build/tmp

七、高级定制建议

  • 自定义软件包

    # 在package/目录下创建自定义包
    mkdir package/my-custom-package
    # 参考现有包结构添加Makefile和补丁
  • 系统精简

    make menuconfig
    # 在Base system中禁用不需要的服务(如dropbear、uhttpd)
  • 固件签名

    # 生成带签名的镜像(需openssl)
    openssl dgst -sha256 -binary bin/targets/<target>/<subtarget>/openwrt-*.bin > firmware.sha256

通过以上步骤,您可以在保留现有DTB和内核的基础上,构建包含自定义组件的ImmortalWrt镜像。建议首次编译后保留.config文件以便复现环境。

0

评论 (0)

取消