By: fu linux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎点赞和订阅!
你的喜欢就是我写作的动力!
任务和问题
问题由来
我们知道执行下面的命令,poky会直接给我创建一个文件系统,如下:
bitbake core-image-sato
#或者
bitbake core-image-minimal
- 1
- 2
- 3
生成的文件系统在:
tmp/deploy/images/msm8909/core-image-sato.ext4
#或者
tmp/deploy/images/msm8909/core-image-minimal.ext4
- 1
- 2
- 3
也可以看下实际大小:
build]$ ls -lh tmp/deploy/images/msm8909/core-image-sato-20211112080027.rootfs.ext4
-rw-r--r-- 2 peeta peeta 105M 11月 12 16:00 tmp-msm8909/deploy/images/xxxx/core-image-sato-20211112080027.rootfs.ext4
- 1
- 2
实际大小也是105M, 我目前使用的机器给emmc设备中的system根文件系统分配的空间是1.5G, 使用
fastboot
刷机后
在机器中使用
df
命令查看发现
~ # df -h
/dev/root 200M 105M 95M 38% /
- 1
- 2
很显然这个有问题,还有很大的空间都没有使用到。
IMAGE_ROOTFS_SIZE变量
在yocto中给的分区大小设置方法是IMAGE_ROOTFS_SIZE变量,于是:
IMAGE_ROOTFS_SIZE = "1572865" #单位是kbytes
- 1
全编译后,镜像文件整体大小就是1.5G。
可是,在刷机的过程中发现,太大了用fastboot刷的时候会报警告:
C:\Users\peeta.chen> fastboot flash system X:\XXX\core-image-sato.ext4
Invalid sparse file format at header magic
Sending sparse 'system' 1/1 (85236 KB) OKAY [ 2.826s]
Writing sparse 'system' 1/1 OKAY [158.485s]
Finished. Total time: 180.001s #可见太费时间了
C:\Users\peeta.chen> fastboot reboot
- 1
- 2
- 3
- 4
- 5
- 6
系统也能正常起来,而且:
~ # df -h
/dev/root 1.5G 555M 918M 38% /
~ # cat /proc/partitions
179 21 1572865 mmcblk0p21
- 1
- 2
- 3
- 4
但是文件系统太大了,需要深入研究下。其中还研究了这两个变量:
IMAGE_ROOTFS_EXTRA_SPACE = "0"
IMAGE_ROOTFS_MAXSIZE = "1572865"
- 1
- 2
但是依旧发现不行,需要换思路。
make_ext4fs命令
使用make_ext4fs命令,可以手动制作文件系统,类似:
make_ext4fs -b 4096 -s -l 1610613760 msm8909-sysfs.ext4 ~/poky/build/tmp/work/msm8909-oe-linux-gnueabi/machine-image/1.0-r0/rootf
- 1
这样就可以生成一个msm8909-sysfs.ext4镜像文件,其中make_ext4fs工具和参数如下
$ apt-cache search make_ext4fs
android-sdk-ext4-utils - Android ext4-utils tools
$ sudo apt-get install android-sdk-ext4-utils
参数:
make_ext4fs [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]
[ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]
[ -L <label> ] [ -f ] [ -a <android mountpoint> ]
[ -u <ubuntu mountpoint> ] [ -U <ubuntu fs content> ]
[ -S file_contexts ] [ -C fs_config ] [ -T timestamp ]
[ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] [ -B <block_list_file> ]
<filename> [<directory>]
#特别的-s没有说明什么意义,应该是small的意思,就是其他没有实质内容的就省略了
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
验证和刷机验证结果如下:
$ ls -lh msm8909-sysfs.ext4
-rw-r--r-- 1 peeta peeta 109M 11月 12 16:10 msm8909-sysfs.ext4 #大小只有109大小
#模块中:
root@msm8909:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 1.5G 84.5M 1.4G 6% /
- 1
- 2
- 3
- 4
- 5
- 6
yocto中没有make_ext4fs工具怎么办
在msm8909.conf配置文件中,添加这样一句内容:
HOSTTOOLS_append = " make_ext4fs"
- 1
最后完整的补丁内容:
meta-mybsp]$ git diff
diff --git a/conf/machine/msm8909.conf b/conf/machine/msm8909.conf
index ba5b9d8..dc7cf49 100644
--- a/conf/machine/msm8909.conf
+++ b/conf/machine/msm8909.conf
@@ -37,3 +37,12 @@ TCLIBC := "glibc"
#HOSTTOOLS_NONFATAL_append = " python"
HOSTTOOLS_append = " python"
+HOSTTOOLS_append = " make_ext4fs"
+
+#IMAGE_ROOTFS_SIZE = "1572800"
+#IMAGE_ROOTFS_EXTRA_SPACE = "0"
+#IMAGE_ROOTFS_MAXSIZE = "1572865"
+SYSTEM_SIZE_EXT4 ?= "1610613760"
+SYSTEMIMAGE_TARGET ?= "${MACHINE_ARCH}-sysfs.ext4"
+
+VARIANT="debug"
diff --git a/conf/set-mybsp-build-env b/conf/set-mybsp-build-env
index 9483e7c..917d134 100644
--- a/conf/set-mybsp-build-env
+++ b/conf/set-mybsp-build-env
@@ -5,7 +5,7 @@ export TEMPLATECONF="meta-mybsp/conf"
scriptdir="$(dirname "${BASH_SOURCE}")"
# Find where the workspace is...
-CURDIR=$(readlink -f $scriptdir/../..)
+CURDIR=$(readlink -f $scriptdir/)
function build-msm8909-sato-image() {
unset_bb_env
diff --git a/recipes-sato/images/core-image-sato.bbappend b/recipes-sato/images/core-image-sato.bbappend
index 627ffc8..8c7ec5e 100644
--- a/recipes-sato/images/core-image-sato.bbappend
+++ b/recipes-sato/images/core-image-sato.bbappend
@@ -1,5 +1,19 @@
+# Target image
+
IMAGE_INSTALL += "adreno"
IMAGE_INSTALL += "partitions"
IMAGE_INSTALL += "rmtstorage"
IMAGE_INSTALL += "diag-reboot-app"
IMAGE_INSTALL += "libmincrypt"
+
+SRC_URI += "file://rootfs-fsconfig.conf"
+
+do_makesystem () {
+ make_ext4fs -b 4096 -s -l ${SYSTEM_SIZE_EXT4} \
+ ${DEPLOY_DIR_IMAGE}/${SYSTEMIMAGE_TARGET} ${IMAGE_ROOTFS}
+}
+
+python __anonymous () { #这个是匿名函数
+ bb.build.addtask('makesystem', 'do_build', 'do_rootfs', d)
+}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
什么时候调用do_makesystem函数
参见:
yocto-第44篇-bb文件中函数实操演示(2)
匿名函数在bb文件解析结束后执行。