]> code.ossystems Code Review - openembedded-core.git/commitdiff
wic: use kB for the partitions size
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>
Wed, 4 Feb 2015 22:45:02 +0000 (23:45 +0100)
committerOtavio Salvador <otavio@ossystems.com.br>
Wed, 18 Mar 2015 04:09:18 +0000 (01:09 -0300)
Use kB instead of MB for the partition size to get a better granularity.

This is needed on some SoC (i.mx, omap) where it is necessary to create
partitions as small as 64kB.

Keep the backward compatibility by assuming MB when no unit is provided.

Change-Id: Ie0d619801d5f6d81fb3159bd6e71d0e574f2471b
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Tested-by: Maciej Borzecki <maciej.borzecki@open-rnd.pl>
Acked-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Tested-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
scripts/lib/image/help.py
scripts/lib/wic/3rdparty/pykickstart/commands/partition.py
scripts/lib/wic/3rdparty/pykickstart/options.py
scripts/lib/wic/kickstart/__init__.py
scripts/lib/wic/kickstart/custom_commands/partition.py
scripts/lib/wic/plugins/source/bootimg-efi.py
scripts/lib/wic/plugins/source/bootimg-pcbios.py
scripts/lib/wic/utils/partitionedfs.py

index 6b74f57662119ee9a22918085234d0f90bb8b164..0d8a6adfaa71d0029ed2bbd77358c8bd1c55a8f8 100644 (file)
@@ -673,10 +673,10 @@ DESCRIPTION
 
        The following are supported 'part' options:
 
-         --size: The minimum partition size in MBytes. Specify an
-                 integer value such as 500. Do not append the number
-                 with "MB". You do not need this option if you use
-                 --source.
+         --size: The minimum partition size. Specify an integer value
+                 such as 500. Multipliers k, M ang G can be used. If
+                 not specified, the size is in MB.
+                 You do not need this option if you use --source.
 
          --source: This option is a wic-specific option that names the
                    source of the data that will populate the
index 56b91aa9d9a49cb9edeb669fa933379b9127591f..b564b1a7abb9495da09f1dd66c45c005adf388f6 100644 (file)
@@ -78,7 +78,7 @@ class FC3_PartData(BaseData):
         if self.recommended:
             retval += " --recommended"
         if self.size and self.size != 0:
-            retval += " --size=%s" % self.size
+            retval += " --size=%sk" % self.size
         if hasattr(self, "start") and self.start != 0:
             retval += " --start=%s" % self.start
 
@@ -216,7 +216,7 @@ class FC3_Partition(KickstartCommand):
                       callback=part_cb, nargs=1, type="string")
         op.add_option("--recommended", dest="recommended", action="store_true",
                       default=False)
-        op.add_option("--size", dest="size", action="store", type="int",
+        op.add_option("--size", dest="size", action="store", type="size",
                       nargs=1)
         op.add_option("--start", dest="start", action="store", type="int",
                       nargs=1)
index 341c5d7298b01a33b7c59fae0a146a042189ba6b..b2d8e3e51615cdbd844a218759154271fd8cfc15 100644 (file)
@@ -143,6 +143,24 @@ def _check_string(option, opt, value):
     else:
         return value
 
+def _check_size(option, opt, value):
+    # Former default was MB
+    if (value.isdigit()):
+        return int(value) * 1024L
+
+    mapping = {"opt": opt, "value": value}
+    if (not value[:-1].isdigit()):
+        raise OptionValueError(_("Option %(opt)s: invalid size value: %(value)r") % mapping)
+
+    size = int(value[:-1])
+    if (value.endswith("k") or value.endswith("K")):
+        return size
+    if (value.endswith("M")):
+        return size * 1024L
+    if (value.endswith("G")):
+        return size * 1024L * 1024L
+    raise OptionValueError(_("Option %(opt)s: invalid size value: %(value)r") % mapping)
+
 # Creates a new Option class that supports several new attributes:
 # - required:  any option with this attribute must be supplied or an exception
 #              is thrown
@@ -169,10 +187,11 @@ class KSOption (Option):
     ACTIONS = Option.ACTIONS + ("map", "map_extend",)
     STORE_ACTIONS = Option.STORE_ACTIONS + ("map", "map_extend",)
 
-    TYPES = Option.TYPES + ("ksboolean", "string")
+    TYPES = Option.TYPES + ("ksboolean", "string", "size")
     TYPE_CHECKER = copy(Option.TYPE_CHECKER)
     TYPE_CHECKER["ksboolean"] = _check_ksboolean
     TYPE_CHECKER["string"] = _check_string
+    TYPE_CHECKER["size"] = _check_size
 
     def _check_required(self):
         if self.required and not self.takes_value():
index b1406a04575906f7d5822139eef5a4a2753040fc..10959213d1080b12d183a447f59171c80fc8521a 100644 (file)
@@ -74,7 +74,7 @@ def get_image_size(ks, default = None):
         if p.mountpoint == "/" and p.size:
             __size = p.size
     if __size > 0:
-        return int(__size) * 1024L * 1024L
+        return int(__size) * 1024L
     else:
         return default
 
index 54a494e033b966f8e022c01d1d8393474652005a..7a307065f289a7212c9930a5a4aff98e65b80d53 100644 (file)
@@ -99,7 +99,7 @@ class Wic_PartData(Mic_PartData):
 
     def get_extra_block_count(self, current_blocks):
         """
-        The --size param is reflected in self.size (in MB), and we already
+        The --size param is reflected in self.size (in kB), and we already
         have current_blocks (1k) blocks, calculate and return the
         number of (1k) blocks we need to add to get to --size, 0 if
         we're already there or beyond.
@@ -110,7 +110,7 @@ class Wic_PartData(Mic_PartData):
         if not self.size:
             return 0
 
-        requested_blocks = self.size * 1024
+        requested_blocks = self.size
 
         msger.debug("Requested blocks %d, current_blocks %d" % \
                     (requested_blocks, current_blocks))
@@ -171,7 +171,7 @@ class Wic_PartData(Mic_PartData):
         Handle an already-created partition e.g. xxx.ext3
         """
         rootfs = oe_builddir
-        du_cmd = "du -Lbms %s" % rootfs
+        du_cmd = "du -Lbks %s" % rootfs
         out = exec_cmd(du_cmd)
         rootfs_size = out.split()[0]
 
@@ -247,8 +247,8 @@ class Wic_PartData(Mic_PartData):
             print "rootfs_dir: %s" % rootfs_dir
             msger.error("ERROR: mkfs.%s returned '%s' instead of 0 (which you probably don't want to ignore, use --debug for details) when creating filesystem from rootfs directory: %s" % (self.fstype, rc, rootfs_dir))
 
-        # get the rootfs size in the right units for kickstart (Mb)
-        du_cmd = "du -Lbms %s" % rootfs
+        # get the rootfs size in the right units for kickstart (kB)
+        du_cmd = "du -Lbks %s" % rootfs
         out = exec_cmd(du_cmd)
         rootfs_size = out.split()[0]
 
@@ -292,8 +292,8 @@ class Wic_PartData(Mic_PartData):
         if rc:
             msger.error("ERROR: mkfs.%s returned '%s' instead of 0 (which you probably don't want to ignore, use --debug for details) when creating filesystem from rootfs directory: %s" % (self.fstype, rc, rootfs_dir))
 
-        # get the rootfs size in the right units for kickstart (Mb)
-        du_cmd = "du -Lbms %s" % rootfs
+        # get the rootfs size in the right units for kickstart (kB)
+        du_cmd = "du -Lbks %s" % rootfs
         out = exec_cmd(du_cmd)
         rootfs_size = out.split()[0]
 
@@ -341,8 +341,8 @@ class Wic_PartData(Mic_PartData):
         chmod_cmd = "chmod 644 %s" % rootfs
         exec_cmd(chmod_cmd)
 
-        # get the rootfs size in the right units for kickstart (Mb)
-        du_cmd = "du -Lbms %s" % rootfs
+        # get the rootfs size in the right units for kickstart (kB)
+        du_cmd = "du -Lbks %s" % rootfs
         out = exec_cmd(du_cmd)
         rootfs_size = out.split()[0]
 
@@ -361,8 +361,8 @@ class Wic_PartData(Mic_PartData):
                        (image_rootfs, rootfs)
         exec_native_cmd(pseudo + squashfs_cmd, native_sysroot)
 
-        # get the rootfs size in the right units for kickstart (Mb)
-        du_cmd = "du -Lbms %s" % rootfs
+        # get the rootfs size in the right units for kickstart (kB)
+        du_cmd = "du -Lbks %s" % rootfs
         out = exec_cmd(du_cmd)
         rootfs_size = out.split()[0]
 
@@ -395,7 +395,7 @@ class Wic_PartData(Mic_PartData):
         """
         fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
 
-        dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
+        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
             (fs, self.size)
         exec_cmd(dd_cmd)
 
@@ -417,11 +417,11 @@ class Wic_PartData(Mic_PartData):
         """
         fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
 
-        dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
+        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
             (fs, self.size)
         exec_cmd(dd_cmd)
 
-        mkfs_cmd = "mkfs.%s -b %d %s" % (self.fstype, self.size * 1024, rootfs)
+        mkfs_cmd = "mkfs.%s -b %d %s" % (self.fstype, self.size, rootfs)
         (rc, out) = exec_native_cmd(mkfs_cmd, native_sysroot)
         if rc:
             msger.error("ERROR: mkfs.%s returned '%s' instead of 0 (which you probably don't want to ignore, use --debug for details)" % (self.fstype, rc))
@@ -442,7 +442,7 @@ class Wic_PartData(Mic_PartData):
         """
         fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
 
-        blocks = self.size * 1024
+        blocks = self.size
 
         dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (fs, blocks)
         exec_native_cmd(dosfs_cmd, native_sysroot)
@@ -474,8 +474,8 @@ class Wic_PartData(Mic_PartData):
 
         os.rmdir(tmpdir)
 
-        # get the rootfs size in the right units for kickstart (Mb)
-        du_cmd = "du -Lbms %s" % fs
+        # get the rootfs size in the right units for kickstart (kB)
+        du_cmd = "du -Lbks %s" % fs
         out = exec_cmd(du_cmd)
         fs_size = out.split()[0]
 
@@ -490,7 +490,7 @@ class Wic_PartData(Mic_PartData):
         """
         fs = "%s/fs.%s" % (cr_workdir, self.fstype)
 
-        dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
+        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
             (fs, self.size)
         exec_cmd(dd_cmd)
 
index e4067b6dbf6bc2eef749216162d84b37a2993269..ee57881e90f8e49b8099e57e0831f207daf676f2 100644 (file)
@@ -228,7 +228,7 @@ class BootimgEFIPlugin(SourcePlugin):
         chmod_cmd = "chmod 644 %s" % bootimg
         exec_cmd(chmod_cmd)
 
-        du_cmd = "du -Lbms %s" % bootimg
+        du_cmd = "du -Lbks %s" % bootimg
         out = exec_cmd(du_cmd)
         bootimg_size = out.split()[0]
 
index 8a1aca1ad16ab8e139aa733556d65aca542f734f..c4786a6e0ea1e2851d1007e2315cba5f86ecf3b5 100644 (file)
@@ -190,7 +190,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
         chmod_cmd = "chmod 644 %s" % bootimg
         exec_cmd(chmod_cmd)
 
-        du_cmd = "du -Lbms %s" % bootimg
+        du_cmd = "du -Lbks %s" % bootimg
         out = exec_cmd(du_cmd)
         bootimg_size = out.split()[0]
 
index 9df93dca2f54aa24fd29507cd94277d72d864371..c72bb29b027c76bad639c8f5cbfc49181d2ac840 100644 (file)
@@ -92,8 +92,8 @@ class Image:
 
         ks_pnum = len(self.partitions)
 
-        # Converting MB to sectors for parted
-        size = size * 1024 * 1024 / self.sector_size
+        # Converting kB to sectors for parted
+        size = size * 1024 / self.sector_size
 
         # We still need partition for "/" or non-subvolume
         if mountpoint == "/" or not fsopts: