如何在buildroot打包bootfs.ext4
贫穷贵公子
在开发STM32MP157的时候,内核的uImage和stm32mp157d-atk.dtb设备树,会被打包成ext4格式的文件系统,然后通过uboot进行加载。本文介绍一种方法,通过buildroot的构建环境,生成uImage的同时,完成bootfs.ext4的打包。
配置buildroot时,以stm32mp157a_dk1_defconfig为基础,进行构建。
make stm32mp157a_dk1_defconfig
该配置会指定 post-image.sh 的后处理脚本,用于生成sdcard.img。
buildroot-2022.02/board/stmicroelectronics/common/stm32mp157/post-image.sh
通过在该脚本当中,增加逻辑,生成bootfs.img
diff --git a/buildroot-2022.02/board/stmicroelectronics/common/stm32mp157/post-image.sh b/buildroot-2022.02/board/stmicroelectronics/common/stm32mp157/post-image.sh
index 363c3127c..ee02f43b9 100755
--- a/buildroot-2022.02/board/stmicroelectronics/common/stm32mp157/post-image.sh
+++ b/buildroot-2022.02/board/stmicroelectronics/common/stm32mp157/post-image.sh
@@ -13,9 +13,11 @@ atf_image()
if grep -Eq "DTB_FILE_NAME=stm32mp157c-dk2.dtb" <<< ${ATF_VARIABLES}; then
echo "tf-a-stm32mp157c-dk2.stm32"
elif grep -Eq "DTB_FILE_NAME=stm32mp157a-dk1.dtb" <<< ${ATF_VARIABLES}; then
- echo "tf-a-stm32mp157a-dk1.stm32"
+ echo "tf-a-stm32mp157a-dk1.stm32"
elif grep -Eq "DTB_FILE_NAME=stm32mp157a-avenger96.dtb" <<< ${ATF_VARIABLES}; then
- echo "tf-a-stm32mp157a-avenger96.stm32"
+ echo "tf-a-stm32mp157a-avenger96.stm32"
+ elif grep -Eq "DTB_FILE_NAME=stm32mp157a-dk1.dtb" <<< ${ATF_VARIABLES}; then
+ echo "stm32mp157a-dk1.dtb"
@@ -32,7 +34,21 @@ main()
rm -f ${GENIMAGE_CFG}
+ bootfs_img
exit $?
+bootfs_img()
+ rm -rf ${BUILD_DIR}/genbootimage.tmp
+ mkdir -p ${BUILD_DIR}/genbootimage.tmp
+ local GENBOOTIMAGE_TMP="${BUILD_DIR}/genbootimage.tmp"
+ cp ${BUILD_DIR}/../images/uImage ${GENBOOTIMAGE_TMP}