rootfs.py: Added support for creating UBI images.
authorTuomas Kulve <tuomas@kulve.fi>
Sun, 11 May 2008 09:38:35 +0000 (12:38 +0300)
committerTuomas Kulve <tuomas@kulve.fi>
Tue, 20 May 2008 08:32:07 +0000 (11:32 +0300)
matrix/config.py
matrix/rootfs.py

index e642e1ebcd944c6b9913b893f4ed9ee0663df055..3f8ab6c42ee794c2c8d7a6f544064ccb9d8ea726 100644 (file)
@@ -18,7 +18,12 @@ class Board(object):
                     gcc_options=None,
                     gnu_host=None,
                     flash_erase_size=65536,
-                    flash_pad_size=0):
+                    flash_pad_size=0,
+                    flash_compression=None,
+                    ubifs_leb_size=0,
+                    ubifs_max_leb_count=0,
+                    ubifs_min_io_size=0,
+                    ubinize_config_vol_size=0):
                self.name = name
                self.arch = arch
                self.gcc_march = gcc_march
@@ -28,6 +33,11 @@ class Board(object):
                self.gnu_host = gnu_host or ''
                self.flash_erase_size = flash_erase_size
                self.flash_pad_size = flash_pad_size
+               self.flash_compression = flash_compression or ''
+               self.ubifs_leb_size = ubifs_leb_size
+               self.ubifs_max_leb_count = ubifs_max_leb_count
+               self.ubifs_min_io_size = ubifs_min_io_size
+               self.ubinize_config_vol_size = ubinize_config_vol_size
 
                config.boards[name] = self
 
index f18ae9d576695d342a35bc520a6bf20fd3ba7886..223ae3243fc40580d34355caf041a597388e9b04 100644 (file)
@@ -1,6 +1,7 @@
 # Copyright (C) 2007-2008 Movial Oy
 # Authors: Kalle Vahlman <kalle.vahlman@movial.fi>
 #          Timo Savola <tsavola@movial.fi>
+#          Tuomas Kulve <tuomas.kulve@movial.fi>
 
 import errno
 import optparse
@@ -14,6 +15,7 @@ from config import parse as config_parse
 
 image_type_list = (
        'jffs2',
+       'ubi',
 )
 image_type_default = 'jffs2'
 
@@ -70,8 +72,14 @@ def main():
        build.add_paths(config.created_paths)
        build.set_devices(config.devices)
        build.set_change_owner(config.change_owner)
-       build.set_erase_size(config.boards[config.board].flash_erase_size)
-       build.set_pad_size(config.boards[config.board].flash_pad_size)
+       build.set_flash_erase_size(config.boards[config.board].flash_erase_size)
+       build.set_flash_pad_size(config.boards[config.board].flash_pad_size)
+
+       build.set_flash_compression(config.boards[config.board].flash_compression)
+       build.set_ubifs_leb_size(config.boards[config.board].ubifs_leb_size)
+       build.set_ubifs_max_leb_count(config.boards[config.board].ubifs_max_leb_count)
+       build.set_ubifs_min_io_size(config.boards[config.board].ubifs_min_io_size)
+       build.set_ubinize_config_vol_size(config.boards[config.board].ubinize_config_vol_size)
 
        if opts.rootfs_only:
                build.generate(opts.clean, build_target="rootfs")
@@ -91,10 +99,33 @@ class Builder(object):
        mknod = "fakeroot -i /tmp/env.faked -s /tmp/env.faked mknod"
        chmod = "fakeroot -i /tmp/env.faked -s /tmp/env.faked chmod"
        chown = "fakeroot -i /tmp/env.faked -s /tmp/env.faked chown"
-       mkfs = "fakeroot -i /tmp/env.faked -s /tmp/env.faked mkfs.jffs2"
+       mkfs_jffs2 = "fakeroot -i /tmp/env.faked -s /tmp/env.faked mkfs.jffs2"
+       mkfs_ubifs = "fakeroot -i /tmp/env.faked -s /tmp/env.faked mkfs.ubifs"
+       ubinize = "fakeroot -i /tmp/env.faked -s /tmp/env.faked ubinize"
        tar = "fakeroot -i /tmp/env.faked -s /tmp/env.faked tar"
        flash_erase_size = 0x4000
        flash_pad_size = 0x3e00000
+       # Compression to use
+       flash_compression = "lzo"
+       # Logical erase block size
+       ubifs_leb_size = 130944
+       # Maximum logical erase block count
+       ubifs_max_leb_count = 120
+       # Minimum I/O unit size
+       ubifs_min_io_size = 1
+       # Size of the physical eraseblock of the flash
+       ubinize_peb_size = flash_erase_size
+
+       # Configation values for ubinize
+       ubinize_config_mode = "ubi"
+       ubinize_config_image = None
+       ubinize_config_vol_id = 0
+       ubinize_config_vol_size = 13631488
+       ubinize_config_vol_type = "dynamic"
+       ubinize_config_vol_name = "rootfs"
+       ubinize_config_vol_aligment = 1
+       ubinize_config_vol_flags = "autoresize"
+       
 
        file_list = []
        remove_list = []
@@ -165,14 +196,35 @@ class Builder(object):
                if change_owner is not None:
                        self.change_owner= change_owner
 
-       def set_erase_size(self, size):
+       def set_flash_erase_size(self, size):
                if size is not None:
                        self.flash_erase_size = size
+                       self.ubinize_peb_size = size
 
-       def set_pad_size(self, size):
+       def set_flash_pad_size(self, size):
                if size is not None:
                        self.flash_pad_size = size
 
+       def set_flash_compression(self, compr):
+               if compr is not None:
+                       self.flash_compression = compr
+
+       def set_ubifs_leb_size(self, size):
+               if size is not None:
+                       self.ubifs_leb_size = size
+
+       def set_ubifs_max_leb_count(self, count):
+               if count is not None:
+                       self.ubifs_max_leb_count = count
+
+       def set_ubifs_min_io_size(self, size):
+               if size is not None:
+                       self.ubifs_min_io_size = size
+
+       def set_ubinize_config_vol_size(self, size):
+               if size is not None:
+                       self.ubinize_config_vol_size = size
+
        def generate(self, clean, build_target="all"):
                copy_list = self.file_list
 
@@ -277,26 +329,54 @@ class Builder(object):
                                user,group = self.change_owner[d]
                                os.system("%s %s.%s -R %s/%s/%s " % (self.chown, user, group, self.builddir, self.target, dir))
 
-               if build_target is "all" or build_target is "rootfs":
+               # Build rootfs
+               if build_target == "all" or build_target == "rootfs":
                        print "Creating a rootfs..."
                        os.system("%s -c --one-file-system -C %s/%s -z -f %s/%s.tgz ." % (self.tar, self.builddir, self.target, self.builddir, self.target))
-               if build_target is "all" or build_target is "jffs2":
-                       print "Creating a root image..."
-                       os.system("%s -p%d -n -e%d -r %s/%s -o %s/%s.jffs2" % (self.mkfs, self.flash_pad_size, self.flash_erase_size, self.builddir, self.target, self.builddir, self.target))
-               if build_target is "all" or build_target is "devrootfs":
+
+               # Build jffs2
+               if build_target == "all" or build_target == "jffs2":
+                       print "Creating a root image as JFFS2..."
+                       os.system("%s -p%d -n -e%d -r %s/%s -o %s/%s.jffs2" % (self.mkfs_jffs2, self.flash_pad_size, self.flash_erase_size, self.builddir, self.target, self.builddir, self.target))
+
+               # Build ubifs
+               if build_target == "ubi":
+                       print "Creating a root image as UBI..."
+                       ubinize_config = ""
+                       ubinize_config += "[ubifs]\n"
+                       ubinize_config += "mode=%s\n" % self.ubinize_config_mode
+                       ubinize_config += "image=%s/%s.ubifs\n" % (self.builddir, self.target)
+                       ubinize_config += "vol_id=%d\n" % self.ubinize_config_vol_id
+                       ubinize_config += "vol_size=%d\n" % self.ubinize_config_vol_size
+                       ubinize_config += "vol_type=%s\n" % self.ubinize_config_vol_type
+                       ubinize_config += "vol_name=%s\n" % self.ubinize_config_vol_name
+                       ubinize_config += "vol_alignment=%d\n" % self.ubinize_config_vol_aligment
+                       ubinize_config += "vol_flags=%s\n" % self.ubinize_config_vol_flags
+                       f=open('/tmp/ubinize.cfg', 'w')
+                       f.write(ubinize_config)
+                       f.close()
+
+                       os.system("%s --compr=%s -r %s/%s -o %s/%s.ubifs -m %d -e %d -c %d" % (self.mkfs_ubifs, self.flash_compression, self.builddir, self.target, self.builddir, self.target, self.ubifs_min_io_size, self.ubifs_leb_size, self.ubifs_max_leb_count))
+                       os.system("%s -m %d -p %d -o %s/%s.ubi %s/ubinize.cfg" % (self.ubinize, self.ubifs_min_io_size, self.ubinize_peb_size, self.builddir, self.target, self.builddir))
+
+               # Build development rootfs
+               if build_target == "all" or build_target == "devrootfs":
                        print "Creating a rootstrap..."
                        os.system("%s -c --one-file-system -C /targets/%s -z -f %s/%s-rootstrap.tgz ." % ("tar", self.target, self.builddir, self.target))
 
                os.chdir(old_dir)
 
                print "Build finished:"
-               if build_target is "all" or build_target is "rootfs":
+               if build_target == "all" or build_target == "rootfs":
                        s = os.stat(self.builddir + "/" + self.target + ".tgz");
                        print "\t%s/%s.tgz\t%0.2f MiB" % (self.builddir, self.target, s.st_size/1024.0/1024.0)
-               if build_target is "all" or build_target is "jffs2":
+               if build_target == "all" or build_target == "jffs2":
                        s = os.stat(self.builddir + "/" + self.target + ".jffs2");
                        print "\t%s/%s.jffs2\t%0.2f MiB" % (self.builddir, self.target, s.st_size/1024.0/1024.0)
-               if build_target is "all" or build_target is "devrootfs":
+               if build_target == "ubi":
+                       s = os.stat(self.builddir + "/" + self.target + ".ubi");
+                       print "\t%s/%s.ubi\t%0.2f MiB" % (self.builddir, self.target, s.st_size/1024.0/1024.0)
+               if build_target == "all" or build_target == "devrootfs":
                        s = os.stat(self.builddir + "/" + self.target + "-rootstrap.tgz");
                        print "\t%s/%s-rootstrap.tgz\t%0.2f MiB" % (self.builddir, self.target, s.st_size/1024.0/1024.0)