[Buildroot] [PATCH] v2 Add UBI image generation support.

Thomas Petazzoni thomas.petazzoni at free-electrons.com
Thu Dec 23 12:54:27 UTC 2010


Hello,

Thanks Julien for this UBI support, it's definitely good to have in
Buildroot. This version looks good to me, but there is an alternate
solution (patch below, merged into Julien's patch).

Peter, we need you to make a decision here, between those two
solutions, because I have no strong opinion on which one is the best. To
summarize:

 * Julien's solution is to create a new root filesystem type, called
   "ubi", which depends on the "ubifs" filesystem to be generated. So
   at build time, the rootfs.ubifs image is first generated, and then
   the rootfs.ubi image is generated from rootfs.ubifs using ubinize.
   You end up with rootfs.ubifs and rootfs.ubi in $(O)/images.

 * The other solution proposed below is to not add a new root
   filesystem type, but rather add a post-processing step to the
   rootfs.ubifs image when "Embed in UBI image" is selected. You end up
   with rootfs.ubifs in $(O)/images, regardless of whether it is a
   UBIFS filesystem image, or a complete UBI image.

I just implemented the second solution because it's how I would have
implemented it if I had to do it, but I don't know if it's better or
not than Julien's proposal.

Regards,

Thomas

From a541890e129d59bba53a34a5d724b33ad23a116a Mon Sep 17 00:00:00 2001
From: Julien Boibessot <julien.boibessot at armadeus.com>
Date: Tue, 21 Dec 2010 18:38:07 +0100
Subject: [PATCH] v2 Add UBI image generation support.

UBI images are generated from UBIFS one (with ubinize tool) and are used by
bootloaders (eg U-Boot) to write UBIFS images directly on bare NAND FLASH
(see http://www.linux-mtd.infradead.org/faq/ubi.html).

Changes since v1:
* change some comments/helps
* as requested by Thomas, merged fs/ubi/ in fs/ubifs/, but kept ubifs.mk and
  ubi.mk separated. (I don't know if it's really worth to merge them...)

[ Thomas: merged into a single ubifs.mk, used the post gen hook
  mechanism, and keep a single final rootfs.ubifs image, regardless of
  whether it was embedded in an UBI image or not. ]

Signed-off-by: Julien Boibessot <julien.boibessot at armadeus.com>
Signed-off-by: Nicolas Colombain <nicolas.colombain at armadeus.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
---
 fs/ubifs/Config.in   |   22 ++++++++++++++++++++++
 fs/ubifs/ubifs.mk    |   17 +++++++++++++++++
 fs/ubifs/ubinize.cfg |    7 +++++++
 3 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100644 fs/ubifs/ubinize.cfg

diff --git a/fs/ubifs/Config.in b/fs/ubifs/Config.in
index bcf409c..ca1c5a6 100644
--- a/fs/ubifs/Config.in
+++ b/fs/ubifs/Config.in
@@ -77,3 +77,25 @@ config BR2_TARGET_ROOTFS_UBIFS_LZMA
 
 endchoice
 
+config BR2_TARGET_ROOTFS_UBIFS_EMBED_UBI
+	depends on BR2_TARGET_ROOTFS_UBIFS
+	bool "Embed into an UBI image"
+	help
+	  Build an ubi image from the ubifs one (with ubinize).
+
+config BR2_TARGET_ROOTFS_UBIFS_UBI_PEBSIZE
+	hex "UBI physical erase block size"
+	depends on BR2_TARGET_ROOTFS_UBIFS_EMBED_UBI
+	default 0x20000
+	help
+	  Tells ubinize that physical eraseblock size of the flash chip the ubi
+	  image is created for is 0x20000 (by default).
+
+config BR2_TARGET_ROOTFS_UBIFS_UBI_SUBSIZE
+	int "UBI sub-page size"
+	depends on BR2_TARGET_ROOTFS_UBIFS_EMBED_UBI
+	default 512
+	help
+	  Tells ubinize that the flash supports sub-pages and that sub-page
+	  size is 512 bytes (by default).
+
diff --git a/fs/ubifs/ubifs.mk b/fs/ubifs/ubifs.mk
index 337180e..c5e9022 100644
--- a/fs/ubifs/ubifs.mk
+++ b/fs/ubifs/ubifs.mk
@@ -22,4 +22,21 @@ define ROOTFS_UBIFS_CMD
 	$(HOST_DIR)/usr/sbin/mkfs.ubifs -d $(TARGET_DIR) $(UBIFS_OPTS) -o $$@
 endef
 
+UBI_UBINIZE_OPTS := -m $(BR2_TARGET_ROOTFS_UBIFS_MINIOSIZE)
+UBI_UBINIZE_OPTS += -p $(BR2_TARGET_ROOTFS_UBIFS_UBI_PEBSIZE)
+ifneq ($(BR2_TARGET_ROOTFS_UBIFS_UBI_SUBSIZE),0)
+UBI_UBINIZE_OPTS += -s $(BR2_TARGET_ROOTFS_UBIFS_UBI_SUBSIZE)
+endif
+
+ifeq ($(BR2_TARGET_ROOTFS_UBIFS_EMBED_UBI),y)
+define ROOTFS_UBIFS_EMBED_UBI_HOOK
+	cp fs/ubifs/ubinize.cfg . ;\
+	mv $$@ $$@.tmp ;\
+	echo "image=$$@.tmp" >> ./ubinize.cfg ;\
+	$(HOST_DIR)/usr/sbin/ubinize -o $$@ $(UBI_UBINIZE_OPTS) ubinize.cfg ;\
+	rm ubinize.cfg $$@.tmp
+endef
+ROOTFS_UBIFS_POST_GEN_HOOKS += ROOTFS_UBIFS_EMBED_UBI_HOOK
+endif
+
 $(eval $(call ROOTFS_TARGET,ubifs))
\ No newline at end of file
diff --git a/fs/ubifs/ubinize.cfg b/fs/ubifs/ubinize.cfg
new file mode 100644
index 0000000..6515271
--- /dev/null
+++ b/fs/ubifs/ubinize.cfg
@@ -0,0 +1,7 @@
+[ubifs]
+mode=ubi
+vol_id=0
+vol_type=dynamic
+vol_name=rootfs
+vol_alignment=1
+vol_flags=autoresize
-- 
1.7.0.4



-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com



More information about the buildroot mailing list