All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] wic: support 512 byte size granularity
@ 2022-01-13 22:25 Igor Opaniuk
  2022-01-14  9:30 ` [OE-core] " Richard Purdie
  0 siblings, 1 reply; 2+ messages in thread
From: Igor Opaniuk @ 2022-01-13 22:25 UTC (permalink / raw)
  To: openembedded-core; +Cc: mike, ricardo, tim.anderson, JPEWhacker

Since 938595d1dc("wic: Add 512 Byte alignment to --offset") wic
parser supports "s"/"S" suffixes, that can be used to align partition
on 512 byte boundary. Nevertheless, the minimum value of size is still
1Kb.

Introduce support for "s"/"S" suffixes for --size/--fixes-size.
This is required for some SoCs (like i.MX8M/MM, where SIT image is
stored on 0x8200, and actual boot image is at 0x8400).

Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
---
 meta/lib/oeqa/selftest/cases/wic.py      | 11 +++++++++++
 scripts/lib/wic/ksparser.py              | 19 +++++++------------
 scripts/lib/wic/plugins/imager/direct.py |  6 +++---
 3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index 5fc8e65142..bd2b941f65 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -1011,6 +1011,17 @@ class Wic2(WicTestCase):
                 "1:0.50kiB:102400kiB:102400kiB:ext4::;",
                 ])
 
+        with NamedTemporaryFile("w", suffix=".wks") as tempf:
+            # Test that a partition size can be provided in segments (512 bytes) using "s" prefix
+            tempf.write("bootloader --ptable msdos\n" \
+                        "part /    --source rootfs --ondisk hda --offset 1s --fixed-size 10000s --fstype=fat16\n")
+            tempf.flush()
+
+            _, partlns = self._get_wic_partitions(tempf.name, native_sysroot)
+            self.assertEqual(partlns, [
+                "1:0.50kiB:5000kiB:5000kiB:fat16::;",
+                ])
+
         with NamedTemporaryFile("w", suffix=".wks") as tempf:
             # Test that image creation fails if the partitions would overlap
             tempf.write("bootloader --ptable gpt\n" \
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index 0df9eb0d05..97e3e40825 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -51,7 +51,7 @@ class KickStartParser(ArgumentParser):
     def error(self, message):
         raise ArgumentError(None, message)
 
-def sizetype(default, size_in_bytes=False):
+def sizetype(default):
     def f(arg):
         """
         Custom type for ArgumentParser
@@ -68,19 +68,14 @@ def sizetype(default, size_in_bytes=False):
                 raise ArgumentTypeError("Invalid size: %r" % arg)
 
 
-        if size_in_bytes:
-            if suffix == 's' or suffix == 'S':
-                return size * 512
-            mult = 1024
-        else:
-            mult = 1
-
+        if suffix == 's' or suffix == 'S':
+            return size * 512
         if suffix == "k" or suffix == "K":
-            return size * mult
+            return size * 1024
         if suffix == "M":
-            return size * mult * 1024
+            return size * (1024 ** 2)
         if suffix == "G":
-            return size * mult * 1024 * 1024
+            return size * (1024 ** 3)
 
         raise ArgumentTypeError("Invalid size: %r" % arg)
     return f
@@ -149,7 +144,7 @@ class KickStart():
         part.add_argument('mountpoint', nargs='?')
         part.add_argument('--active', action='store_true')
         part.add_argument('--align', type=int)
-        part.add_argument('--offset', type=sizetype("K", True))
+        part.add_argument('--offset', type=sizetype("K"))
         part.add_argument('--exclude-path', nargs='+')
         part.add_argument('--include-path', nargs='+', action='append')
         part.add_argument('--change-directory')
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 35fff7c102..66f7e1d2aa 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -363,7 +363,7 @@ class PartitionedImage():
                          imager.updated_fstab_path)
 
             # Converting kB to sectors for parted
-            part.size_sec = part.disk_size * 1024 // self.sector_size
+            part.size_sec = part.disk_size // self.sector_size
 
     def layout_partitions(self):
         """ Layout the partitions, meaning calculate the position of every
@@ -422,12 +422,12 @@ class PartitionedImage():
                 # gaps we could enlargea the previous partition?
 
                 # Calc how much the alignment is off.
-                align_sectors = self.offset % (part.align * 1024 // self.sector_size)
+                align_sectors = self.offset % (part.align // self.sector_size)
 
                 if align_sectors:
                     # If partition is not aligned as required, we need
                     # to move forward to the next alignment point
-                    align_sectors = (part.align * 1024 // self.sector_size) - align_sectors
+                    align_sectors = (part.align // self.sector_size) - align_sectors
 
                     logger.debug("Realignment for %s%s with %s sectors, original"
                                  " offset %s, target alignment is %sK.",
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [OE-core] [PATCH 1/1] wic: support 512 byte size granularity
  2022-01-13 22:25 [PATCH 1/1] wic: support 512 byte size granularity Igor Opaniuk
@ 2022-01-14  9:30 ` Richard Purdie
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Purdie @ 2022-01-14  9:30 UTC (permalink / raw)
  To: Igor Opaniuk, openembedded-core; +Cc: mike, ricardo, tim.anderson, JPEWhacker

On Fri, 2022-01-14 at 00:25 +0200, Igor Opaniuk wrote:
> Since 938595d1dc("wic: Add 512 Byte alignment to --offset") wic
> parser supports "s"/"S" suffixes, that can be used to align partition
> on 512 byte boundary. Nevertheless, the minimum value of size is still
> 1Kb.
> 
> Introduce support for "s"/"S" suffixes for --size/--fixes-size.
> This is required for some SoCs (like i.MX8M/MM, where SIT image is
> stored on 0x8200, and actual boot image is at 0x8400).
> 
> Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
> ---
>  meta/lib/oeqa/selftest/cases/wic.py      | 11 +++++++++++
>  scripts/lib/wic/ksparser.py              | 19 +++++++------------
>  scripts/lib/wic/plugins/imager/direct.py |  6 +++---
>  3 files changed, 21 insertions(+), 15 deletions(-)

Should there be some tests added to "oe-selftest -r wic" for this?

Cheers,

Richard



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-14  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13 22:25 [PATCH 1/1] wic: support 512 byte size granularity Igor Opaniuk
2022-01-14  9:30 ` [OE-core] " Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.