配置 genimage 的 eMMC 镜像规则
上一节确定了“放在哪里”,这一节把布局写成可重复执行的规则。genimage 不编译任何组件,它只消费 Buildroot output/images/ 中已经生成的文件。
检查 genimage.cfg
工程文件:
buildroot-2026.05.1/board/avaota/a1-mainline/genimage.cfg
image boot.vfat {
vfat {
label = "boot"
files = {
"Image",
"sun55i-t527-avaota-a1.dtb",
"extlinux"
}
}
size = 240M
}
image avaota-a1-full-mainline.img {
hdimage {}
partition mainline-uboot {
in-partition-table = "no"
image = "u-boot-sunxi-with-spl.bin"
offset = 8K
}
partition boot {
partition-type = 0x0c
bootable = "true"
image = "boot.vfat"
offset = 16M
}
partition rootfs {
partition-type = 0x83
image = "rootfs.ext2"
offset = 256M
}
}
| 配置项 | 变成什么 | 为什么需要 |
|---|---|---|
files | FAT 根目录中的三个对象 | 让 U-Boot 找到内核、DTB 和启动项 |
size = 240M | 固定容量的 boot.vfat | 给当前启动文件及后续更新留空间 |
in-partition-table = "no" | raw 中有数据、MBR 中无分区项 | BootROM 按裸偏移读取 SPL |
offset = 8K | U-Boot 写入 8 KiB | 符合 sunxi BootROM 查找位置 |
offset = 16M | FAT 成为第 1 分区 | 避开前面的启动固件 |
offset = 256M | ext4 成为第 2 分区 | 紧接 240 MiB FAT 之后 |
hdimage {} 采用 genimage 默认的 MBR 布局。当前工程没有 disk-signature 字段,不能从文档中额外推导一个固定 PARTUUID。
将 extlinux 目录写入启动分区
files = { "extlinux" } 会递归复制目录,最终得到:
boot.vfat:/
├── Image
├── sun55i-t527-avaota-a1.dtb
└── extlinux/
└── extlinux.conf
U-Boot 2026.07 的 extlinux boot method 查找 extlinux/extlinux.conf。如果只把配置文件放到 FAT 根目录,内容再正确也不会出现在默认查找路径。
Buildroot 调用 genimage 的阶段
板级 defconfig 中的两行配置把组装动作放在 post-image 阶段:
configs/avaota_a1_mainline_defconfig
BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/avaota/a1-mainline/genimage.cfg"
genimage 必须等 rootfs.ext2 生成后才能运行;而 post-build.sh 必须更早把 U-Boot 与 extlinux 复制到 BINARIES_DIR。这两个阶段写反,常见结果不是编译失败,而是镜像内容与本次构建不一致。
检查 genimage 输出
cd buildroot-2026.05.1
stat -c '%n %s bytes' \
output/images/boot.vfat \
output/images/rootfs.ext2 \
output/images/avaota-a1-full-mainline.img
fdisk -l output/images/avaota-a1-full-mainline.img
应看到两个 MBR 分区从 16 MiB 和 256 MiB 开始,整盘镜像为 768 MiB。接着不要仅凭文件存在就烧录;下一篇会从 raw 中逐层读回 eGON、FIT、FAT 与 ext4。