1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 00:39:46 +00:00

wic: use the same partition object in direct and partitionedfs

Partition attributes were copied to the dictionary in partitionedfs
code, which makes the code hard to follow.

Used partition object passed from direct.py module as is in
partitionedfs.

(From OE-Core rev: 97db24d34847a641868f9ee83aae56f9dd5e0a8a)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh
2017-02-08 20:51:29 +02:00
committed by Richard Purdie
parent 4edcd63ba1
commit fd1f6fb201
3 changed files with 73 additions and 96 deletions
+2
View File
@@ -38,12 +38,14 @@ class Partition():
self.active = args.active self.active = args.active
self.align = args.align self.align = args.align
self.disk = args.disk self.disk = args.disk
self.device = None
self.extra_space = args.extra_space self.extra_space = args.extra_space
self.fsopts = args.fsopts self.fsopts = args.fsopts
self.fstype = args.fstype self.fstype = args.fstype
self.label = args.label self.label = args.label
self.mountpoint = args.mountpoint self.mountpoint = args.mountpoint
self.no_table = args.no_table self.no_table = args.no_table
self.num = None
self.overhead_factor = args.overhead_factor self.overhead_factor = args.overhead_factor
self.part_type = args.part_type self.part_type = args.part_type
self.rootfs_dir = args.rootfs_dir self.rootfs_dir = args.rootfs_dir
+1 -8
View File
@@ -237,14 +237,7 @@ class DirectPlugin(ImagerPlugin):
part.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir, part.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir,
self.bootimg_dir, self.kernel_dir, self.native_sysroot) self.bootimg_dir, self.kernel_dir, self.native_sysroot)
self._image.add_partition(part)
self._image.add_partition(part.disk_size, part.disk,
part.mountpoint, part.source_file,
part.fstype, part.label,
fsopts=part.fsopts, boot=part.active,
align=part.align, no_table=part.no_table,
part_type=part.part_type, uuid=part.uuid,
system_id=part.system_id)
if fstab_path: if fstab_path:
shutil.move(fstab_path + ".orig", fstab_path) shutil.move(fstab_path + ".orig", fstab_path)
+70 -88
View File
@@ -71,47 +71,29 @@ class Image():
'ptable_format': "msdos", # Partition table format 'ptable_format': "msdos", # Partition table format
'identifier': None} # Disk system identifier 'identifier': None} # Disk system identifier
def add_disk(self, disk_name, disk_obj, identifier): def add_disk(self, name, disk_obj, identifier):
""" Add a disk object which have to be partitioned. More than one disk """ Add a disk object which have to be partitioned. More than one disk
can be added. In case of multiple disks, disk partitions have to be can be added. In case of multiple disks, disk partitions have to be
added for each disk separately with 'add_partition()". """ added for each disk separately with 'add_partition()". """
self._add_disk(disk_name) self._add_disk(name)
self.disks[disk_name]['disk'] = disk_obj self.disks[name]['disk'] = disk_obj
self.disks[disk_name]['identifier'] = identifier self.disks[name]['identifier'] = identifier
def add_partition(self, size, disk_name, mountpoint, source_file=None, fstype=None, def add_partition(self, part):
label=None, fsopts=None, boot=False, align=None, no_table=False, """
part_type=None, uuid=None, system_id=None): Add the next partition. Partitions have to be added in the
""" Add the next partition. Partitions have to be added in the first-to-last order.
first-to-last order. """ """
part.ks_pnum = len(self.partitions)
ks_pnum = len(self.partitions)
# Converting kB to sectors for parted # Converting kB to sectors for parted
size = size * 1024 // self.sector_size part.size_sec = part.disk_size * 1024 // self.sector_size
part = {'ks_pnum': ks_pnum, # Partition number in the KS file
'size': size, # In sectors
'mountpoint': mountpoint, # Mount relative to chroot
'source_file': source_file, # partition contents
'fstype': fstype, # Filesystem type
'fsopts': fsopts, # Filesystem mount options
'label': label, # Partition label
'disk_name': disk_name, # physical disk name holding partition
'device': None, # kpartx device node for partition
'num': None, # Partition number
'boot': boot, # Bootable flag
'align': align, # Partition alignment
'no_table' : no_table, # Partition does not appear in partition table
'part_type' : part_type, # Partition type
'uuid': uuid, # Partition UUID
'system_id': system_id} # Partition system id
assert not self._partitions_layed_out assert not self._partitions_layed_out
self.partitions.append(part) self.partitions.append(part)
self._add_disk(part['disk_name']) self._add_disk(part.disk)
def layout_partitions(self, ptable_format="msdos"): def layout_partitions(self, ptable_format="msdos"):
""" Layout the partitions, meaning calculate the position of every """ Layout the partitions, meaning calculate the position of every
@@ -129,11 +111,11 @@ class Image():
for num in range(len(self.partitions)): for num in range(len(self.partitions)):
part = self.partitions[num] part = self.partitions[num]
if part['disk_name'] not in self.disks: if part.disk not in self.disks:
raise ImageError("No disk %s for partition %s" \ raise ImageError("No disk %s for partition %s" \
% (part['disk_name'], part['mountpoint'])) % (part.disk, part.mountpoint))
if ptable_format == 'msdos' and part['part_type']: if ptable_format == 'msdos' and part.part_type:
# The --part-type can also be implemented for MBR partitions, # The --part-type can also be implemented for MBR partitions,
# in which case it would map to the 1-byte "partition type" # in which case it would map to the 1-byte "partition type"
# filed at offset 3 of the partition entry. # filed at offset 3 of the partition entry.
@@ -141,9 +123,9 @@ class Image():
"implemented for msdos partitions") "implemented for msdos partitions")
# Get the disk where the partition is located # Get the disk where the partition is located
disk = self.disks[part['disk_name']] disk = self.disks[part.disk]
disk['numpart'] += 1 disk['numpart'] += 1
if not part['no_table']: if not part.no_table:
disk['realpart'] += 1 disk['realpart'] += 1
disk['ptable_format'] = ptable_format disk['ptable_format'] = ptable_format
@@ -163,50 +145,50 @@ class Image():
disk['offset'] += 1 disk['offset'] += 1
if part['align']: if part.align:
# If not first partition and we do have alignment set we need # If not first partition and we do have alignment set we need
# to align the partition. # to align the partition.
# FIXME: This leaves a empty spaces to the disk. To fill the # FIXME: This leaves a empty spaces to the disk. To fill the
# gaps we could enlargea the previous partition? # gaps we could enlargea the previous partition?
# Calc how much the alignment is off. # Calc how much the alignment is off.
align_sectors = disk['offset'] % (part['align'] * 1024 // self.sector_size) align_sectors = disk['offset'] % (part.align * 1024 // self.sector_size)
if align_sectors: if align_sectors:
# If partition is not aligned as required, we need # If partition is not aligned as required, we need
# to move forward to the next alignment point # to move forward to the next alignment point
align_sectors = (part['align'] * 1024 // self.sector_size) - align_sectors align_sectors = (part.align * 1024 // self.sector_size) - align_sectors
msger.debug("Realignment for %s%s with %s sectors, original" msger.debug("Realignment for %s%s with %s sectors, original"
" offset %s, target alignment is %sK." % " offset %s, target alignment is %sK." %
(part['disk_name'], disk['numpart'], align_sectors, (part.disk, disk['numpart'], align_sectors,
disk['offset'], part['align'])) disk['offset'], part.align))
# increase the offset so we actually start the partition on right alignment # increase the offset so we actually start the partition on right alignment
disk['offset'] += align_sectors disk['offset'] += align_sectors
part['start'] = disk['offset'] part.start = disk['offset']
disk['offset'] += part['size'] disk['offset'] += part.size_sec
part['type'] = 'primary' part.type = 'primary'
if not part['no_table']: if not part.no_table:
part['num'] = disk['realpart'] part.num = disk['realpart']
else: else:
part['num'] = 0 part.num = 0
if disk['ptable_format'] == "msdos": if disk['ptable_format'] == "msdos":
# only count the partitions that are in partition table # only count the partitions that are in partition table
if len([p for p in self.partitions if not p['no_table']]) > 4: if len([p for p in self.partitions if not p.no_table]) > 4:
if disk['realpart'] > 3: if disk['realpart'] > 3:
part['type'] = 'logical' part.type = 'logical'
part['num'] = disk['realpart'] + 1 part.num = disk['realpart'] + 1
disk['partitions'].append(num) disk['partitions'].append(num)
msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d " msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d "
"sectors (%d bytes)." \ "sectors (%d bytes)." \
% (part['mountpoint'], part['disk_name'], part['num'], % (part.mountpoint, part.disk, part.num,
part['start'], disk['offset'] - 1, part.start, disk['offset'] - 1,
part['size'], part['size'] * self.sector_size)) part.size_sec, part.size_sec * self.sector_size))
# Once all the partitions have been layed out, we can calculate the # Once all the partitions have been layed out, we can calculate the
# minumim disk sizes. # minumim disk sizes.
@@ -256,11 +238,11 @@ class Image():
msger.debug("Creating partitions") msger.debug("Creating partitions")
for part in self.partitions: for part in self.partitions:
if part['num'] == 0: if part.num == 0:
continue continue
disk = self.disks[part['disk_name']] disk = self.disks[part.disk]
if disk['ptable_format'] == "msdos" and part['num'] == 5: if disk['ptable_format'] == "msdos" and part.num == 5:
# Create an extended partition (note: extended # Create an extended partition (note: extended
# partition is described in MBR and contains all # partition is described in MBR and contains all
# logical partitions). The logical partitions save a # logical partitions). The logical partitions save a
@@ -273,16 +255,16 @@ class Image():
# add a sector at the back, so that there is enough # add a sector at the back, so that there is enough
# room for all logical partitions. # room for all logical partitions.
self._create_partition(disk['disk'].device, "extended", self._create_partition(disk['disk'].device, "extended",
None, part['start'] - 1, None, part.start - 1,
disk['offset'] - part['start'] + 1) disk['offset'] - part.start + 1)
if part['fstype'] == "swap": if part.fstype == "swap":
parted_fs_type = "linux-swap" parted_fs_type = "linux-swap"
elif part['fstype'] == "vfat": elif part.fstype == "vfat":
parted_fs_type = "fat32" parted_fs_type = "fat32"
elif part['fstype'] == "msdos": elif part.fstype == "msdos":
parted_fs_type = "fat16" parted_fs_type = "fat16"
elif part['fstype'] == "ontrackdm6aux3": elif part.fstype == "ontrackdm6aux3":
parted_fs_type = "ontrackdm6aux3" parted_fs_type = "ontrackdm6aux3"
else: else:
# Type for ext2/ext3/ext4/btrfs # Type for ext2/ext3/ext4/btrfs
@@ -290,47 +272,47 @@ class Image():
# Boot ROM of OMAP boards require vfat boot partition to have an # Boot ROM of OMAP boards require vfat boot partition to have an
# even number of sectors. # even number of sectors.
if part['mountpoint'] == "/boot" and part['fstype'] in ["vfat", "msdos"] \ if part.mountpoint == "/boot" and part.fstype in ["vfat", "msdos"] \
and part['size'] % 2: and part.size_sec % 2:
msger.debug("Subtracting one sector from '%s' partition to " \ msger.debug("Subtracting one sector from '%s' partition to " \
"get even number of sectors for the partition" % \ "get even number of sectors for the partition" % \
part['mountpoint']) part.mountpoint)
part['size'] -= 1 part.size_sec -= 1
self._create_partition(disk['disk'].device, part['type'], self._create_partition(disk['disk'].device, part.type,
parted_fs_type, part['start'], part['size']) parted_fs_type, part.start, part.size_sec)
if part['part_type']: if part.part_type:
msger.debug("partition %d: set type UID to %s" % \ msger.debug("partition %d: set type UID to %s" % \
(part['num'], part['part_type'])) (part.num, part.part_type))
exec_native_cmd("sgdisk --typecode=%d:%s %s" % \ exec_native_cmd("sgdisk --typecode=%d:%s %s" % \
(part['num'], part['part_type'], (part.num, part.part_type,
disk['disk'].device), self.native_sysroot) disk['disk'].device), self.native_sysroot)
if part['uuid'] and disk['ptable_format'] == "gpt": if part.uuid and disk['ptable_format'] == "gpt":
msger.debug("partition %d: set UUID to %s" % \ msger.debug("partition %d: set UUID to %s" % \
(part['num'], part['uuid'])) (part.num, part.uuid))
exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \ exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \
(part['num'], part['uuid'], disk['disk'].device), (part.num, part.uuid, disk['disk'].device),
self.native_sysroot) self.native_sysroot)
if part['label'] and disk['ptable_format'] == "gpt": if part.label and disk['ptable_format'] == "gpt":
msger.debug("partition %d: set name to %s" % \ msger.debug("partition %d: set name to %s" % \
(part['num'], part['label'])) (part.num, part.label))
exec_native_cmd("parted -s %s name %d %s" % \ exec_native_cmd("parted -s %s name %d %s" % \
(disk['disk'].device, part['num'], part['label']), (disk['disk'].device, part.num, part.label),
self.native_sysroot) self.native_sysroot)
if part['boot']: if part.active:
flag_name = "legacy_boot" if disk['ptable_format'] == 'gpt' else "boot" flag_name = "legacy_boot" if disk['ptable_format'] == 'gpt' else "boot"
msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \ msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \
(flag_name, part['num'], disk['disk'].device)) (flag_name, part.num, disk['disk'].device))
exec_native_cmd("parted -s %s set %d %s on" % \ exec_native_cmd("parted -s %s set %d %s on" % \
(disk['disk'].device, part['num'], flag_name), (disk['disk'].device, part.num, flag_name),
self.native_sysroot) self.native_sysroot)
if part['system_id']: if part.system_id:
exec_native_cmd("sfdisk --part-type %s %s %s" % \ exec_native_cmd("sfdisk --part-type %s %s %s" % \
(disk['disk'].device, part['num'], part['system_id']), (disk['disk'].device, part.num, part.system_id),
self.native_sysroot) self.native_sysroot)
# Parted defaults to enabling the lba flag for fat16 partitions, # Parted defaults to enabling the lba flag for fat16 partitions,
@@ -339,9 +321,9 @@ class Image():
if parted_fs_type == "fat16": if parted_fs_type == "fat16":
if disk['ptable_format'] == 'msdos': if disk['ptable_format'] == 'msdos':
msger.debug("Disable 'lba' flag for partition '%s' on disk '%s'" % \ msger.debug("Disable 'lba' flag for partition '%s' on disk '%s'" % \
(part['num'], disk['disk'].device)) (part.num, disk['disk'].device))
exec_native_cmd("parted -s %s set %d lba off" % \ exec_native_cmd("parted -s %s set %d lba off" % \
(disk['disk'].device, part['num']), (disk['disk'].device, part.num),
self.native_sysroot) self.native_sysroot)
def cleanup(self): def cleanup(self):
@@ -360,16 +342,16 @@ class Image():
msger.debug("Installing partitions") msger.debug("Installing partitions")
for part in self.partitions: for part in self.partitions:
source = part['source_file'] source = part.source_file
if source: if source:
# install source_file contents into a partition # install source_file contents into a partition
sparse_copy(source, image_file, part['start'] * self.sector_size) sparse_copy(source, image_file, part.start * self.sector_size)
msger.debug("Installed %s in partition %d, sectors %d-%d, " msger.debug("Installed %s in partition %d, sectors %d-%d, "
"size %d sectors" % \ "size %d sectors" % \
(source, part['num'], part['start'], (source, part.num, part.start,
part['start'] + part['size'] - 1, part['size'])) part.start + part.size_sec - 1, part.size_sec))
partimage = image_file + '.p%d' % part['num'] partimage = image_file + '.p%d' % part.num
os.rename(source, partimage) os.rename(source, partimage)
self.partimages.append(partimage) self.partimages.append(partimage)