diff options
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/wic/engine.py | 18 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 56 |
2 files changed, 50 insertions, 24 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index ce7e6c5d75..64b1d52882 100644 --- a/scripts/lib/wic/engine.py +++ b/scripts/lib/wic/engine.py | |||
@@ -232,6 +232,16 @@ class Disk: | |||
232 | self._psector_size = None | 232 | self._psector_size = None |
233 | self._ptable_format = None | 233 | self._ptable_format = None |
234 | 234 | ||
235 | # define sector size | ||
236 | sector_size_str = get_bitbake_var('WIC_SECTOR_SIZE') | ||
237 | if sector_size_str is not None: | ||
238 | try: | ||
239 | self.sector_size = int(sector_size_str) | ||
240 | except ValueError: | ||
241 | self.sector_size = None | ||
242 | else: | ||
243 | self.sector_size = None | ||
244 | |||
235 | # find parted | 245 | # find parted |
236 | # read paths from $PATH environment variable | 246 | # read paths from $PATH environment variable |
237 | # if it fails, use hardcoded paths | 247 | # if it fails, use hardcoded paths |
@@ -258,7 +268,13 @@ class Disk: | |||
258 | def get_partitions(self): | 268 | def get_partitions(self): |
259 | if self._partitions is None: | 269 | if self._partitions is None: |
260 | self._partitions = OrderedDict() | 270 | self._partitions = OrderedDict() |
261 | out = exec_cmd("%s -sm %s unit B print" % (self.parted, self.imagepath)) | 271 | |
272 | if self.sector_size is not None: | ||
273 | out = exec_cmd("export PARTED_SECTOR_SIZE=%d; %s -sm %s unit B print" % \ | ||
274 | (self.sector_size, self.parted, self.imagepath), True) | ||
275 | else: | ||
276 | out = exec_cmd("%s -sm %s unit B print" % (self.parted, self.imagepath)) | ||
277 | |||
262 | parttype = namedtuple("Part", "pnum start end size fstype") | 278 | parttype = namedtuple("Part", "pnum start end size fstype") |
263 | splitted = out.splitlines() | 279 | splitted = out.splitlines() |
264 | # skip over possible errors in exec_cmd output | 280 | # skip over possible errors in exec_cmd output |
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index a1d152659b..2124ceac7f 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
@@ -321,7 +321,15 @@ class PartitionedImage(): | |||
321 | self.partitions = partitions | 321 | self.partitions = partitions |
322 | self.partimages = [] | 322 | self.partimages = [] |
323 | # Size of a sector used in calculations | 323 | # Size of a sector used in calculations |
324 | self.sector_size = SECTOR_SIZE | 324 | sector_size_str = get_bitbake_var('WIC_SECTOR_SIZE') |
325 | if sector_size_str is not None: | ||
326 | try: | ||
327 | self.sector_size = int(sector_size_str) | ||
328 | except ValueError: | ||
329 | self.sector_size = SECTOR_SIZE | ||
330 | else: | ||
331 | self.sector_size = SECTOR_SIZE | ||
332 | |||
325 | self.native_sysroot = native_sysroot | 333 | self.native_sysroot = native_sysroot |
326 | num_real_partitions = len([p for p in self.partitions if not p.no_table]) | 334 | num_real_partitions = len([p for p in self.partitions if not p.no_table]) |
327 | self.extra_space = extra_space | 335 | self.extra_space = extra_space |
@@ -508,7 +516,8 @@ class PartitionedImage(): | |||
508 | logger.debug("Added '%s' partition, sectors %d-%d, size %d sectors", | 516 | logger.debug("Added '%s' partition, sectors %d-%d, size %d sectors", |
509 | parttype, start, end, size) | 517 | parttype, start, end, size) |
510 | 518 | ||
511 | cmd = "parted -s %s unit s mkpart %s" % (device, parttype) | 519 | cmd = "export PARTED_SECTOR_SIZE=%d; parted -s %s unit s mkpart %s" % \ |
520 | (self.sector_size, device, parttype) | ||
512 | if fstype: | 521 | if fstype: |
513 | cmd += " %s" % fstype | 522 | cmd += " %s" % fstype |
514 | cmd += " %d %d" % (start, end) | 523 | cmd += " %d %d" % (start, end) |
@@ -527,8 +536,8 @@ class PartitionedImage(): | |||
527 | os.ftruncate(sparse.fileno(), min_size) | 536 | os.ftruncate(sparse.fileno(), min_size) |
528 | 537 | ||
529 | logger.debug("Initializing partition table for %s", device) | 538 | logger.debug("Initializing partition table for %s", device) |
530 | exec_native_cmd("parted -s %s mklabel %s" % (device, ptable_format), | 539 | exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s mklabel %s" % |
531 | self.native_sysroot) | 540 | (self.sector_size, device, ptable_format), self.native_sysroot) |
532 | 541 | ||
533 | def _write_disk_guid(self): | 542 | def _write_disk_guid(self): |
534 | if self.ptable_format in ('gpt', 'gpt-hybrid'): | 543 | if self.ptable_format in ('gpt', 'gpt-hybrid'): |
@@ -538,7 +547,8 @@ class PartitionedImage(): | |||
538 | self.disk_guid = uuid.uuid4() | 547 | self.disk_guid = uuid.uuid4() |
539 | 548 | ||
540 | logger.debug("Set disk guid %s", self.disk_guid) | 549 | logger.debug("Set disk guid %s", self.disk_guid) |
541 | sfdisk_cmd = "sfdisk --disk-id %s %s" % (self.path, self.disk_guid) | 550 | sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \ |
551 | (self.sector_size, self.path, self.disk_guid) | ||
542 | exec_native_cmd(sfdisk_cmd, self.native_sysroot) | 552 | exec_native_cmd(sfdisk_cmd, self.native_sysroot) |
543 | 553 | ||
544 | def create(self): | 554 | def create(self): |
@@ -613,45 +623,44 @@ class PartitionedImage(): | |||
613 | partition_label = part.part_name if part.part_name else part.label | 623 | partition_label = part.part_name if part.part_name else part.label |
614 | logger.debug("partition %d: set name to %s", | 624 | logger.debug("partition %d: set name to %s", |
615 | part.num, partition_label) | 625 | part.num, partition_label) |
616 | exec_native_cmd("sgdisk --change-name=%d:%s %s" % \ | 626 | exec_native_cmd("sfdisk --sector-size %s --part-label %s %d %s" % \ |
617 | (part.num, partition_label, | 627 | (self.sector_size, self.path, part.num, |
618 | self.path), self.native_sysroot) | 628 | partition_label), self.native_sysroot) |
619 | |||
620 | if part.part_type: | 629 | if part.part_type: |
621 | logger.debug("partition %d: set type UID to %s", | 630 | logger.debug("partition %d: set type UID to %s", |
622 | part.num, part.part_type) | 631 | part.num, part.part_type) |
623 | exec_native_cmd("sgdisk --typecode=%d:%s %s" % \ | 632 | exec_native_cmd("sfdisk --sector-size %s --part-type %s %d %s" % \ |
624 | (part.num, part.part_type, | 633 | (self.sector_size, self.path, part.num, |
625 | self.path), self.native_sysroot) | 634 | part.part_type), self.native_sysroot) |
626 | 635 | ||
627 | if part.uuid and self.ptable_format in ("gpt", "gpt-hybrid"): | 636 | if part.uuid and self.ptable_format in ("gpt", "gpt-hybrid"): |
628 | logger.debug("partition %d: set UUID to %s", | 637 | logger.debug("partition %d: set UUID to %s", |
629 | part.num, part.uuid) | 638 | part.num, part.uuid) |
630 | exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \ | 639 | exec_native_cmd("sfdisk --sector-size %s --part-uuid %s %d %s" % \ |
631 | (part.num, part.uuid, self.path), | 640 | (self.sector_size, self.path, part.num, part.uuid), |
632 | self.native_sysroot) | 641 | self.native_sysroot) |
633 | 642 | ||
634 | if part.active: | 643 | if part.active: |
635 | flag_name = "legacy_boot" if self.ptable_format in ('gpt', 'gpt-hybrid') else "boot" | 644 | flag_name = "legacy_boot" if self.ptable_format in ('gpt', 'gpt-hybrid') else "boot" |
636 | logger.debug("Set '%s' flag for partition '%s' on disk '%s'", | 645 | logger.debug("Set '%s' flag for partition '%s' on disk '%s'", |
637 | flag_name, part.num, self.path) | 646 | flag_name, part.num, self.path) |
638 | exec_native_cmd("parted -s %s set %d %s on" % \ | 647 | exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s set %d %s on" % \ |
639 | (self.path, part.num, flag_name), | 648 | (self.sector_size, self.path, part.num, flag_name), |
640 | self.native_sysroot) | 649 | self.native_sysroot) |
641 | if self.ptable_format == 'gpt-hybrid' and part.mbr: | 650 | if self.ptable_format == 'gpt-hybrid' and part.mbr: |
642 | exec_native_cmd("parted -s %s set %d %s on" % \ | 651 | exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s set %d %s on" % \ |
643 | (mbr_path, hybrid_mbr_part_num, "boot"), | 652 | (self.sector_size, mbr_path, hybrid_mbr_part_num, "boot"), |
644 | self.native_sysroot) | 653 | self.native_sysroot) |
645 | if part.system_id: | 654 | if part.system_id: |
646 | exec_native_cmd("sfdisk --part-type %s %s %s" % \ | 655 | exec_native_cmd("sfdisk --sector-size %s --part-type %s %s %s" % \ |
647 | (self.path, part.num, part.system_id), | 656 | (self.sector_size, self.path, part.num, part.system_id), |
648 | self.native_sysroot) | 657 | self.native_sysroot) |
649 | 658 | ||
650 | if part.hidden and self.ptable_format == "gpt": | 659 | if part.hidden and self.ptable_format == "gpt": |
651 | logger.debug("Set hidden attribute for partition '%s' on disk '%s'", | 660 | logger.debug("Set hidden attribute for partition '%s' on disk '%s'", |
652 | part.num, self.path) | 661 | part.num, self.path) |
653 | exec_native_cmd("sfdisk --part-attrs %s %s RequiredPartition" % \ | 662 | exec_native_cmd("sfdisk --sector-size %s --part-attrs %s %s RequiredPartition" % \ |
654 | (self.path, part.num), | 663 | (self.sector_size, self.path, part.num), |
655 | self.native_sysroot) | 664 | self.native_sysroot) |
656 | 665 | ||
657 | if self.ptable_format == "gpt-hybrid": | 666 | if self.ptable_format == "gpt-hybrid": |
@@ -664,7 +673,8 @@ class PartitionedImage(): | |||
664 | # create with an arbitrary type, then change it to the correct type | 673 | # create with an arbitrary type, then change it to the correct type |
665 | # with sfdisk | 674 | # with sfdisk |
666 | self._create_partition(mbr_path, "primary", "fat32", 1, GPT_OVERHEAD) | 675 | self._create_partition(mbr_path, "primary", "fat32", 1, GPT_OVERHEAD) |
667 | exec_native_cmd("sfdisk --part-type %s %d 0xee" % (mbr_path, hybrid_mbr_part_num), | 676 | exec_native_cmd("sfdisk --sector-size %s --part-type %s %d 0xee" % \ |
677 | (self.sector_size, mbr_path, hybrid_mbr_part_num), | ||
668 | self.native_sysroot) | 678 | self.native_sysroot) |
669 | 679 | ||
670 | # Copy hybrid MBR | 680 | # Copy hybrid MBR |