diff options
-rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 24 | ||||
-rw-r--r-- | scripts/lib/wic/ksparser.py | 20 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 8 |
3 files changed, 42 insertions, 10 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index 8b58285c32..e6b23c6888 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py | |||
@@ -890,6 +890,30 @@ class Wic2(WicTestCase): | |||
890 | ]) | 890 | ]) |
891 | 891 | ||
892 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 892 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
893 | # Test that partitions can be placed on a 512 byte sector boundary | ||
894 | tempf.write("bootloader --ptable gpt\n" \ | ||
895 | "part / --source rootfs --ondisk hda --offset 65s --fixed-size 99M --fstype=ext4\n" \ | ||
896 | "part /bar --ondisk hda --offset 102432 --fixed-size 100M --fstype=ext4\n") | ||
897 | tempf.flush() | ||
898 | |||
899 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
900 | self.assertEqual(partlns, [ | ||
901 | "1:32.5kiB:101408kiB:101376kiB:ext4:primary:;", | ||
902 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | ||
903 | ]) | ||
904 | |||
905 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
906 | # Test that a partition can be placed immediately after a MSDOS partition table | ||
907 | tempf.write("bootloader --ptable msdos\n" \ | ||
908 | "part / --source rootfs --ondisk hda --offset 1s --fixed-size 100M --fstype=ext4\n") | ||
909 | tempf.flush() | ||
910 | |||
911 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
912 | self.assertEqual(partlns, [ | ||
913 | "1:0.50kiB:102400kiB:102400kiB:ext4::;", | ||
914 | ]) | ||
915 | |||
916 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
893 | # Test that image creation fails if the partitions would overlap | 917 | # Test that image creation fails if the partitions would overlap |
894 | tempf.write("bootloader --ptable gpt\n" \ | 918 | tempf.write("bootloader --ptable gpt\n" \ |
895 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ | 919 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ |
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py index 3453d9cb9d..913e3283dc 100644 --- a/scripts/lib/wic/ksparser.py +++ b/scripts/lib/wic/ksparser.py | |||
@@ -51,11 +51,11 @@ class KickStartParser(ArgumentParser): | |||
51 | def error(self, message): | 51 | def error(self, message): |
52 | raise ArgumentError(None, message) | 52 | raise ArgumentError(None, message) |
53 | 53 | ||
54 | def sizetype(default): | 54 | def sizetype(default, size_in_bytes=False): |
55 | def f(arg): | 55 | def f(arg): |
56 | """ | 56 | """ |
57 | Custom type for ArgumentParser | 57 | Custom type for ArgumentParser |
58 | Converts size string in <num>[K|k|M|G] format into the integer value | 58 | Converts size string in <num>[S|s|K|k|M|G] format into the integer value |
59 | """ | 59 | """ |
60 | try: | 60 | try: |
61 | suffix = default | 61 | suffix = default |
@@ -67,12 +67,20 @@ def sizetype(default): | |||
67 | except ValueError: | 67 | except ValueError: |
68 | raise ArgumentTypeError("Invalid size: %r" % arg) | 68 | raise ArgumentTypeError("Invalid size: %r" % arg) |
69 | 69 | ||
70 | |||
71 | if size_in_bytes: | ||
72 | if suffix == 's' or suffix == 'S': | ||
73 | return size * 512 | ||
74 | mult = 1024 | ||
75 | else: | ||
76 | mult = 1 | ||
77 | |||
70 | if suffix == "k" or suffix == "K": | 78 | if suffix == "k" or suffix == "K": |
71 | return size | 79 | return size * mult |
72 | if suffix == "M": | 80 | if suffix == "M": |
73 | return size * 1024 | 81 | return size * mult * 1024 |
74 | if suffix == "G": | 82 | if suffix == "G": |
75 | return size * 1024 * 1024 | 83 | return size * mult * 1024 * 1024 |
76 | 84 | ||
77 | raise ArgumentTypeError("Invalid size: %r" % arg) | 85 | raise ArgumentTypeError("Invalid size: %r" % arg) |
78 | return f | 86 | return f |
@@ -141,7 +149,7 @@ class KickStart(): | |||
141 | part.add_argument('mountpoint', nargs='?') | 149 | part.add_argument('mountpoint', nargs='?') |
142 | part.add_argument('--active', action='store_true') | 150 | part.add_argument('--active', action='store_true') |
143 | part.add_argument('--align', type=int) | 151 | part.add_argument('--align', type=int) |
144 | part.add_argument('--offset', type=sizetype("K")) | 152 | part.add_argument('--offset', type=sizetype("K", True)) |
145 | part.add_argument('--exclude-path', nargs='+') | 153 | part.add_argument('--exclude-path', nargs='+') |
146 | part.add_argument('--include-path', nargs='+', action='append') | 154 | part.add_argument('--include-path', nargs='+', action='append') |
147 | part.add_argument('--change-directory') | 155 | part.add_argument('--change-directory') |
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index 2f01999405..55db826e93 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
@@ -429,14 +429,14 @@ class PartitionedImage(): | |||
429 | self.offset += align_sectors | 429 | self.offset += align_sectors |
430 | 430 | ||
431 | if part.offset is not None: | 431 | if part.offset is not None: |
432 | offset = (part.offset * 1024) // self.sector_size | 432 | offset = part.offset // self.sector_size |
433 | 433 | ||
434 | if offset * self.sector_size != part.offset * 1024: | 434 | if offset * self.sector_size != part.offset: |
435 | raise WicError("Could not place %s%s at offset %dK with sector size %d" % (part.disk, self.numpart, part.offset, self.sector_size)) | 435 | raise WicError("Could not place %s%s at offset %d with sector size %d" % (part.disk, self.numpart, part.offset, self.sector_size)) |
436 | 436 | ||
437 | delta = offset - self.offset | 437 | delta = offset - self.offset |
438 | if delta < 0: | 438 | if delta < 0: |
439 | raise WicError("Could not place %s%s at offset %dK: next free sector is %d (delta: %d)" % (part.disk, self.numpart, part.offset, self.offset, delta)) | 439 | raise WicError("Could not place %s%s at offset %d: next free sector is %d (delta: %d)" % (part.disk, self.numpart, part.offset, self.offset, delta)) |
440 | 440 | ||
441 | logger.debug("Skipping %d sectors to place %s%s at offset %dK", | 441 | logger.debug("Skipping %d sectors to place %s%s at offset %dK", |
442 | delta, part.disk, self.numpart, part.offset) | 442 | delta, part.disk, self.numpart, part.offset) |