Yocto创建自己的分区(基于STM32MP1)
前几章节我们分析了machine class里面几篇关键的class,还有machine conf里面的inc文件,大致的创建分区的流程都比较清晰了,本章节动手实际操作一把,创建一个自己的分区。
一、添加分区配置
layers/meta-farsight/meta-fs-mp1/conf/machine/include/st-machine-common-stm32mp.inc下修改
下面是完整的diff文件,关键修改就是+的地方:
//配置分区的名称、镜像名、默认挂载点、分区大小等信息
STM32MP_TTFS_IMAGE ?= “st-image-ttfs”
STM32MP_TTFS_LABEL ?= “ttfs”
STM32MP_TTFS_MOUNTPOINT ?= “/mnt/tt”
TTFS_PARTITION_SIZE ?= “10240”
//使能打开该分区配置
ST_TTFS ?= “1”
//将上面的配置信息添加到全局的PARTITIONS_CONFIG变量里面
PARTITIONS_CONFIG[ttfs] ?= “${STM32MP_TTFS_IMAGE},${STM32MP_TTFS_LABEL},${STM32MP_TTFS_MOUNTPOINT},${TTFS_PARTITION_SIZE},FileSystem”
--- a/conf/machine/include/st-machine-common-stm32mp.inc
+++ b/conf/machine/include/st-machine-common-stm32mp.inc
@@ -90,6 +90,9 @@ STM32MP_USERFS_MOUNTPOINT ?= "/usr/local"
diff --git a/conf/machine/include/st-machine-common-stm32mp.inc b/conf/machine/include/st-machine-common-stm32mp.inc
index a9eec8d..f688175 100644
--- a/conf/machine/include/st-machine-common-stm32mp.inc
+++ b/conf/machine/include/st-machine-common-stm32mp.inc
@@ -90,6 +90,9 @@ STM32MP_USERFS_MOUNTPOINT ?= "/usr/local"
STM32MP_VENDORFS_IMAGE ?= "st-image-vendorfs"
STM32MP_VENDORFS_LABEL ?= "vendorfs"
STM32MP_VENDORFS_MOUNTPOINT ?= "/vendor"
+STM32MP_TTFS_IMAGE ?= "st-image-ttfs"
+STM32MP_TTFS_LABEL ?= "ttfs"
+STM32MP_TTFS_MOUNTPOINT ?= "/mnt/tt"
# Define image partition size (supposed to be set as max size in image recipe)
# Proposed value for bootfs is 64MB
@@ -120,22 +123,27 @@ ROOTFS_PARTITION_SIZE ?= "${IMAGE_ROOTFS_MAXSIZE}"
USERFS_PARTITION_SIZE ?= "131072"
# Proposed value for vendorfs is 16MB
VENDORFS_PARTITION_SIZE ?= "16384"
+# Proposed value for ttfs is 10MB
+TTFS_PARTITION_SIZE ?= "10240"
# Enable use of extra partition(s)
ST_BOOTFS ?= "1"
ST_VENDORFS ?= "1"
ST_USERFS ?= "1"
+ST_TTFS ?= "1"
PARTITIONS_CONFIG[ttfs] ?= "${STM32MP_TTFS_IMAGE},${STM32MP_TTFS_LABEL},${STM32MP_TTFS_MOUNTPOINT},${TTFS_PARTITION_SIZE},FileSystem"
# Partitions configuration
PARTITIONS_CONFIG += "${@bb.utils.contains('ST_BOOTFS', '1', 'bootfs', '', d)}"
PARTITIONS_CONFIG += "${@bb.utils.contains('ST_VENDORFS', '1', 'vendorfs', '', d)}"
PARTITIONS_CONFIG += "rootfs"
PARTITIONS_CONFIG += "${@bb.utils.contains('ST_USERFS', '1', 'userfs', '', d)}"
+PARTITIONS_CONFIG += "${@bb.utils.contains('ST_TTFS', '1', 'ttfs', '', d)}"
PARTITIONS_CONFIG[bootfs] ?= "${STM32MP_BOOTFS_IMAGE},${STM32MP_BOOTFS_LABEL},${STM32MP_BOOTFS_MOUNTPOINT},${BOOTFS_PARTITION_SIZE},System"
PARTITIONS_CONFIG[vendorfs] ?= "${STM32MP_VENDORFS_IMAGE},${STM32MP_VENDORFS_LABEL},${STM32MP_VENDORFS_MOUNTPOINT},${VENDORFS_PARTITION_SIZE},FileSystem"
PARTITIONS_CONFIG[rootfs] ?= "${IMAGE_BASENAME},rootfs,,${ROOTFS_PARTITION_SIZE},FileSystem"
PARTITIONS_CONFIG[userfs] ?= "${STM32MP_USERFS_IMAGE},${STM32MP_USERFS_LABEL},${STM32MP_USERFS_MOUNTPOINT},${USERFS_PARTITION_SIZE},FileSystem"
+PARTITIONS_CONFIG[ttfs] ?= "${STM32MP_TTFS_IMAGE},${STM32MP_TTFS_LABEL},${STM32MP_TTFS_MOUNTPOINT},${TTFS_PARTITION_SIZE},FileSystem"
二、编写image bb文件
添加一个image 镜像文件:
layers/meta-farsight/meta-fs-mp1/recipes-st/images/st-image-ttfs.bb
实际内容如下:
SUMMARY = "STM32MP ttfs Image"
LICENSE = "MIT"
include recipes-st/images/st-image-partitions.inc
# Define to null ROOTFS_MAXSIZE
IMAGE_ROOTFS_MAXSIZE = ""
# Add demo application described on specific packagegroup
PACKAGE_INSTALL += " \
servo-ttfs \
"
st-image-ttfs.b内容比较简单,其实主要的工作都在st-image-partitions.inc里面,我们在st-image-ttfs 镜像里面只安装了一个 servo-ttfs包
三、应用包recipe bb编写
servo-ttfs 实际上就是一个简单的QT demo程序,比较简单,这里就不贴源码了,只放一下bb文件的内容:
# My application of Qt5 for example
SUMMARY = "My application of Qt5 for example"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
FILESEXTRAPATHS_prepend := "${THISDIR}/:"
SRC_DIR = "servo"
SRC_URI = "file://servo/"
DEPENDS += "qtbase"
PACKAGES += "${PN}-ttfs"
S = "${WORKDIR}/servo"
inherit qmake5
do_install() {
install -d ${D}/mnt/tt
install -m 0755 ${B}/Servo ${D}/mnt/tt
}
FILES_${PN}-ttfs = "/mnt/tt/"
这里面有几个需要注意的点:
- QT依赖
因为是一个QT demo程序,编译需要依赖QT库,所以需要指定如下内容:
inherit qmake5
DEPENDS += “qtbase” - 提供包
我们的应用程序是作为一个package的,所以需要指定
PACKAGES += “${PN}-ttfs” - 安装
do_install 里面会把我们编译出来的Servo应用程序安装到 KaTeX parse error: Expected group after '_' at position 19: …/mnt/tt下面 FILES_̲{PN}-ttfs = “/mnt/tt/” 则会在打包的时候把我们安装的包打进去,缺一不可
/mnt/tt因为是我们image的默认挂载点,所以在这里安装路径也写成了这个,这样在rootfs里面会自动创建这个路径。
至此,添加分区的工作的就完成了,是不是相当简单。
编译验证
上面的工作完成以后执行我们的yocto编译:
DISTRO=openstlinux-eglfs MACHINE=fsmp1a source layers/meta-farsight/scripts/envsetup.sh
bitbake fs-mp1a-qt
少等片刻,编译完成以后我们到image产物下面看看我们的分区镜像是否生成:
可以看到生成了st-image-ttfs-openstlinux-eglfs-fsmp1a-20221203130814.ttfs.ext4 镜像
自动生成的flashlayout 刷机文件中也已经添加了我们的ttfs分区信息,在最后一行
开机验证
将上面的分区镜像和刷机脚本烧录到开发板上查看:
开机信息:
可以看到开机自动mount了我们的分区到/mnt/tt路径下面
进入系统查看,使用df -Th查看分区可以看到自动添加了一个分区/dev/mmcblk2p6,大小在8.7M,比我们设置的10M稍微小一点,可能是文件系统占用了一部分开销,挂载点也是/mnt/tt。
进入/mnt/tt可以看到里面确实有我们的QT Demo应用程序Servo。
至此,分区相关分析到此结束!