Add genimage logic in fs/genimage
cover Add genimage logic in fs/genimage
Hello,
This has been discussed in the past, so here is a first attempt at adding some logic to generate genimage images from Buildroot. It's sent as an RFC to really point out that it's an initial attempt, meant to start the discussion.
The aspects I'm not entirely sure:
- fs/genimage/ is not ideal, because it's not a filesystem format per-se. But I'm not sure where to put it.
- the "Filesystem images" menu in menuconfig is also not the ideal location, for the same reason, but I'm also not sure where this would fit.
- the direct call from target-post-image to GENIMAGE_GENERATE_CMDS is also probably not ideal.
Suggestions welcome.
Thanks!
Thomas
Thomas Petazzoni (2):
fs/genimage: add logic to generate an image using genimage support/testing: add tests for the genimage generation logic
Makefile | 1 + fs/Config.in | 1 + fs/genimage/Config.in | 26 ++++++++++ fs/genimage/genimage.mk | 31 ++++++++++++ support/testing/tests/fs/genimage-simple.cfg | 9 ++++ support/testing/tests/fs/genimage-vfat.cfg | 25 ++++++++++ support/testing/tests/fs/test_genimage.py | 74 ++++++++++++++++++++++++++++ 7 files changed, 167 insertions(+) create mode 100644 fs/genimage/Config.in create mode 100644 fs/genimage/genimage.mk create mode 100644 support/testing/tests/fs/genimage-simple.cfg create mode 100644 support/testing/tests/fs/genimage-vfat.cfg create mode 100644 support/testing/tests/fs/test_genimage.py
Signature · 1 line
2.9.4
PATCH 1/2 fs/genimage: add logic to generate an image using genimage
We have more and more boards that need to repeat in their post-image script the logic to use genimage. Even though the logic has been factorized in support/scripts/genimage.sh, users still have to remember that they need to enable BR2_PACKAGE_HOST_MTOOLS and BR2_PACKAGE_HOST_DOSFSTOOLS when they have a VFAT partition in their genimage configuration.
Therefore, this commit adds some minimal logic in Buildroot to use genimage directly.
This logic is added into fs/genimage/, even if stricly speaking genimage isn't a filesystem format. It does not use the filesystem infrastructure (fs/common.mk), and is referenced explicitly from the target-post-image target in the main Makefile.
--- Makefile | 1 + fs/Config.in | 1 + fs/genimage/Config.in | 26 ++++++++++++++++++++++++++ fs/genimage/genimage.mk | 31 +++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 fs/genimage/Config.in create mode 100644 fs/genimage/genimage.mk
Makefile +1 -0
@@ -733,6 +733,7 @@ endif .PHONY: target-post-image target-post-image: $(TARGETS_ROOTFS) target-finalize + $(GENIMAGE_GENERATE_CMDS) @$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT)), \ $(call MESSAGE,"Executing post-image script $(s)"); \ $(EXTRA_ENV) $(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
fs/Config.in +1 -0
@@ -13,5 +13,6 @@ source "fs/squashfs/Config.in" source "fs/tar/Config.in" source "fs/ubifs/Config.in" source "fs/yaffs2/Config.in" +source "fs/genimage/Config.in" endmenu
fs/genimage/Config.in new file +26 -0
@@ -0,0 +1,26 @@ +config BR2_TARGET_ROOTFS_GENIMAGE + bool "generate a final image with genimage" + select BR2_PACKAGE_HOST_GENIMAGE + help + This option allows to generate a final image to flash on + your device using a tool called genimage. + +if BR2_TARGET_ROOTFS_GENIMAGE + +config BR2_TARGET_ROOTFS_GENIMAGE_CFG_FILE + string "genimage config file" + help + This option allows to specify the path to the genimage + configuration file. See + https://git.pengutronix.de/cgit/genimage/plain/README for + the specification of the genimage configuration file format. + +config BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT + bool "genimage config uses vfat" + select BR2_PACKAGE_HOST_DOSFSTOOLS + select BR2_PACKAGE_HOST_MTOOLS + help + Enable this option if your genimage configuration file uses + a "vfat" section to generate a VFAT filesystem. + +endif
fs/genimage/genimage.mk new file +31 -0
@@ -0,0 +1,31 @@ +################################################################################ +# +# genimage support +# +################################################################################ + +ifeq ($(BR2_TARGET_ROOTFS_GENIMAGE),y) +PACKAGES += host-genimage + +ifeq ($(BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT),y) +PACKAGES += host-dosfstools host-mtools +endif + +GENIMAGE_CFG_FILE = $(call qstrip,$(BR2_TARGET_ROOTFS_GENIMAGE_CFG_FILE)) +GENIMAGE_TMP = $(BUILD_DIR)/genimage.tmp + +define GENIMAGE_GENERATE_CMDS + if grep -q "vfat.*{" $(GENIMAGE_CFG_FILE) && \ + test "$(BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT)" != "y" ; then \ + echo "ERROR: genimage configuration generates a VFAT filesystem" ; \ + echo " please enable BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT" ; \ + fi + $(RM) -rf $(GENIMAGE_TMP) + $(HOST_DIR)/usr/bin/genimage --rootpath $(TARGET_DIR) \ + --tmppath $(GENIMAGE_TMP) \ + --inputpath $(BINARIES_DIR) \ + --outputpath $(BINARIES_DIR) \ + --config $(GENIMAGE_CFG_FILE) +endef + +endif # BR2_TARGET_ROOTFS_GENIMAGE
Signature · 1 line
2.9.4
PATCH 1/2 fs/genimage: add logic to generate an image using genimage
Quoted 2 lines · Thomas Petazzoni
We have more and more boards that need to repeat in their post-image script the logic to use genimage.
Perhaps you should add least one patch to your series that updates a defconfig
with this feature.
Quoted 15 lines
Even though the logic has been
factorized insupport/scripts/genimage.sh, users still have to remember that they need to enableBR2_PACKAGE_HOST_MTOOLSandBR2_PACKAGE_HOST_DOSFSTOOLSwhen they have a VFAT partition in their genimage configuration.Therefore, this commit adds some minimal logic in Buildroot to use genimage directly.
This logic is added into
fs/genimage/, even if stricly speaking genimage isn't a filesystem format. It does not use the filesystem infrastructure (fs/common.mk), and is referenced explicitly from the target-post-image target in the mainMakefile.Signed-off-by Thomas Petazzoni <[email protected]>
[snip]
Quoted 6 lines
fs/genimage/genimage.mk new file +0
-0
fs/genimage/genimage.mk line 8
Quoted 8 lines
fs/genimage/genimage.mk new file +8
-0@@ -0,0 +1,31 @@ +################################################################################ +# +# genimage support +# +################################################################################ + +ifeq ($(BR2_TARGET_ROOTFS_GENIMAGE),y) +PACKAGES += host-genimage
This shouldn't be needed, since Config.in already adds them to the packages
list, no?
fs/genimage/genimage.mk line 11
Quoted 3 lines
fs/genimage/genimage.mk new file +3
-0+ +ifeq ($(BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT),y) +PACKAGES += host-dosfstools host-mtools
Same here.
fs/genimage/genimage.mk line 14
Quoted 3 lines
fs/genimage/genimage.mk new file +3
-0+endif + +GENIMAGE_CFG_FILE = $(call qstrip,$(BR2_TARGET_ROOTFS_GENIMAGE_CFG_FILE))
Perhaps we should $(error) if the file doesn't exist? Hm, hangon, the
genimage.cfg file could be generated by a post-{build,image} script, so no, don't error here...
fs/genimage/genimage.mk line 18
Quoted 4 lines
fs/genimage/genimage.mk new file +4
-0+GENIMAGE_TMP = $(BUILD_DIR)/genimage.tmp + +define GENIMAGE_GENERATE_CMDS + if grep -q "vfat.*{" $(GENIMAGE_CFG_FILE) && \
Unfortunately whitespace is not significant in genimage files, so it is
possible that this regex matches in a genimage.cfg that doesn't have a vfat partition at all but just has the string "vfat" somewhere... OK, that's a bit a weird situation.
fs/genimage/genimage.mk line 28
Quoted 10 lines
fs/genimage/genimage.mk new file +10
-0+ test "$(BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT)" != "y" ; then \ + echo "ERROR: genimage configuration generates a VFAT filesystem" ; \ + echo " please enable BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT" ; \ + fi + $(RM) -rf $(GENIMAGE_TMP) + $(HOST_DIR)/usr/bin/genimage --rootpath $(TARGET_DIR) \ + --tmppath $(GENIMAGE_TMP) \ + --inputpath $(BINARIES_DIR) \ + --outputpath $(BINARIES_DIR) \ + --config $(GENIMAGE_CFG_FILE)
So the idea is to drop the genimage.sh script entirely? Hm, in the light of the
longer-term vision, I think things will become more and more complicated so delegating it to a script sounds like the right thing to do...
Regards,
Arnout
Quoted 4 lines
fs/genimage/genimage.mk new file +3
-0+endef + +endif # BR2_TARGET_ROOTFS_GENIMAGE
Signature · 6 lines
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
PATCH 1/2 fs/genimage: add logic to generate an image using genimage
Hello,
Quoted 1 line · Arnout Vandecappelle
On 23-08-17 22:45, Thomas Petazzoni wrote:
[snip]
Quoted 6 lines
fs/genimage/genimage.mk line 24
Quoted 6 lines
fs/genimage/genimage.mk new file +6
-0+ test "$(BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT)" != "y" ; then \ + echo "ERROR: genimage configuration generates a VFAT filesystem" ; \ + echo " please enable BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT" ; \ + fi + $(RM) -rf $(GENIMAGE_TMP) + $(HOST_DIR)/usr/bin/genimage --rootpath $(TARGET_DIR) \
I think you need to pass $(EXTRA_ENV) or a subset of it here, otherwise it will not use mkdosfs from the host/ directory and will fail if it not pre-installed, see:
https://gitlab.com/RicardoMartincoski/buildroot/-/jobs/30257871
sh: 1: mkdosfs: not found
Quoted 8 lines
fs/genimage/genimage.mk line 28
Quoted 4 lines
fs/genimage/genimage.mk new file +4
-0+ --tmppath $(GENIMAGE_TMP) \ + --inputpath $(BINARIES_DIR) \ + --outputpath $(BINARIES_DIR) \ + --config $(GENIMAGE_CFG_FILE)So the idea is to drop the
genimage.shscript entirely? Hm, in the light of the
longer-term vision, I think things will become more and more complicated so delegating it to a script sounds like the right thing to do...
Even if the script is called I guess $(EXTRA_ENV) will be needed, just like target-post-image already does for custom scripts.
Regards,
Ricardo
PATCH 2/2 support/testing: add tests for the genimage generation logic
In reply to Thomas PetazzoniThis commit adds two new test cases, to validate that the genimage related functionality in Buildroot is working as expected:
- One test case with just one ext4 partition. We do the build, check in the image that one partition is available with the right type, and then boot the system under Qemu to validate that the root filesystem can be mounted from /dev/mmcblk0p1.
- One test case with one VFAT partition and one ext4 partition. We do the build, check in the image that two partitions are available with the right types, and then boot the system under Qemu. This allows to validate that the root filesystem can be mounted from /dev/mmcblk0p2, and that /dev/mmcblk0p1 can be mounted as a VFAT filesystem and contains the expected file.
--- support/testing/tests/fs/genimage-simple.cfg | 9 ++++ support/testing/tests/fs/genimage-vfat.cfg | 25 ++++++++++ support/testing/tests/fs/test_genimage.py | 74 ++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 support/testing/tests/fs/genimage-simple.cfg create mode 100644 support/testing/tests/fs/genimage-vfat.cfg create mode 100644 support/testing/tests/fs/test_genimage.py
support/testing/tests/fs/genimage-simple.cfg new file +9 -0
@@ -0,0 +1,9 @@ +image sdcard.img { + hdimage { + } + + partition rootfs { + partition-type = 0x83 + image = "rootfs.ext4" + } +}
support/testing/tests/fs/genimage-vfat.cfg new file +25 -0
@@ -0,0 +1,25 @@ +image boot.vfat { + vfat { + files = { + "rootfs.tar", + } + } + size = 16M +} + +image sdcard.img { + hdimage { + } + + partition boot { + partition-type = 0xC + bootable = "true" + image = "boot.vfat" + offset = 8M + } + + partition rootfs { + partition-type = 0x83 + image = "rootfs.ext4" + } +}
support/testing/tests/fs/test_genimage.py new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.9.4
PATCH 2/2 support/testing: add tests for the genimage generation logic
Hello,
Looks good. Only nits below.
Quoted 7 lines · Thomas Petazzoni
This commit adds two new test cases, to validate that the genimage related functionality in Buildroot is working as expected:
- One test case with just one ext4 partition. We do the build, check in the image that one partition is available with the right type, and then boot the system under Qemu to validate that the root filesystem can be mounted from
/dev/mmcblk0p1.
The root filesystem ends up mounted as read-only due to limitations in the builtin kernel image. From the -run.log:
Filesystem with huge files cannot be mounted RDWR without CONFIG_LBDAF
But I think it is OK since whether it is writable or not is not the subject of the test.
[snip]
Quoted 5 lines
--- support/testing/tests/fs/genimage-simple.cfg | 9 ++++ support/testing/tests/fs/genimage-vfat.cfg | 25 ++++++++++ support/testing/tests/fs/test_genimage.py | 74 ++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+)
I don't know if it was intended (due to RFC status) or not, but the update to .gitlab-ci.yml is missing.
[snip]
Quoted 1 line
+++
b/support/testing/tests/fs/test_genimage.py
Since it's a new file, could fix the 9 code style warnings from flake8?
[snip]
support/testing/tests/fs/test_genimage.py line 13
Quoted 7 lines
support/testing/tests/fs/test_genimage.py new file +7
-0+ config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_TARGET_ROOTFS_EXT2=y + BR2_TARGET_ROOTFS_EXT2_4=y + BR2_TARGET_ROOTFS_GENIMAGE=y + BR2_TARGET_ROOTFS_GENIMAGE_CFG_FILE="{}" + """.format(infra.filepath("tests/fs/genimage-simple.cfg"))
This is a triple-quoted string and the test infra removes the white space at beginning of lines, so any indentation would be valid.
But perhaps we could adopt a default and use everywhere for consistency. See support/testing/tests/init/test_none.py that indents one level in this case.
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
"""Regards,
Ricardo
cover Add genimage logic in fs/genimage
In reply to Thomas PetazzoniQuoted 4 lines · Thomas Petazzoni
This has been discussed in the past, so here is a first attempt at adding some logic to generate genimage images from Buildroot. It's sent as an RFC to really point out that it's an initial attempt, meant to start the discussion.
I'm still not very convinced this is an improvement. The only thing it brings,
really, is that the option to select the packages required for VFAT right next to the genimage option. But we can get a similar result by reorganizing the Config.in.host menu with some sections so all the filesystem generation bits are next to each other, and in the host-genimage help text explain that VFAT needs both mtools and dosfstools.
That said, I would agree if the longer-term vision is to:
* do genimage under fakeroot, so it can generate the ext4fs directly instead of requiring support from Buildroot;
* add support to generate simple genimage.cfg files from Buildroot config options;
* make sure that genimage supports all the filesystem types that we do (just talking about actual filesystems here, so not cpio, tar, initramfs);
* eventually deprecate our filesystem support and delegate all of it to genimage.
That's a five-year vision, of course, not something that needs to be fully
implemented right away.
Quoted 4 lines
The aspects I'm not entirely sure:
-
fs/genimage/is not ideal, because it's not a filesystem format per-se. But I'm not sure where to put it.
I think it is. As mentioned above, cpio, initramfs and tar are not filesystem
formats either.
Quoted 3 lines
- the "Filesystem images" menu in menuconfig is also not the ideal location, for the same reason, but I'm also not sure where this would fit.
It would make more sense close to the post-build options. However, that would
put it in a not very logical place as well. Except if we move the filesystems menu as a submenu of system configuration. Oh well, not so important.
Quoted 2 lines
- the direct call from target-post-image to
GENIMAGE_GENERATE_CMDSis also probably not ideal.
We could introduce something like TARGET_FINALIZE_HOOKS, but with just one such
thing I don't think it's worth it.
However, IMO, the genimage step should be done *after* the post-image scripts.
If you look at our existing defconfigs, almost all of them do some preparatory work before calling genimage. There's only one script that does something
afterwards: board/hardkernel/odroidc2/post-image.sh writes u-boot into the image using dd, because it needs a gap in the middle. But even that one could be done before genimage, splitting u-boot.bin into two files and using the genimage.cfg files to add them to the image.
Regards,
Arnout
Signature · 6 lines
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF