aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/utils/partitionedfs.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2013-09-19 04:32:19 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-01 22:53:52 +0100
commitf87acc5e59d3c2c39ff171b5557977dab4c8f4a6 (patch)
treeef0017d066a319e38aba507ef0ff85d1d863a17a /scripts/lib/mic/utils/partitionedfs.py
parent31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e (diff)
downloadopenembedded-core-contrib-f87acc5e59d3c2c39ff171b5557977dab4c8f4a6.tar.gz
wic: Add OpenEmbedded-specific implementation
Reuses the mic/livecd infrastructure but heavily subclasses and modifies it to adapt to the special needs of building images from existing OpenEmbedded build artifacts. In addition to the OE-specific mic objects and modifications to the underlying infrastructure, this adds a mechanism to allow OE kickstart files to be 'canned' and made available to users via the 'wic list images' command. Two initial OE kickstart files have been added as canned .wks files: directdisk, which implements the same thing as the images created by directdisk.bbclass, and mkefidisk, which can essentially be used as a replacement for mkefidisk.sh. Of course, since creation of these images are now driven by .wks files rather than being hard-coded into class files or scripts, they can be easily modified to generate different variations on those images. They also don't require root priveleges, since they don't use mount to create the images. They don't however write to media like mkefidisk.sh does, but rather create images that can be written onto media. Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/utils/partitionedfs.py')
-rw-r--r--scripts/lib/mic/utils/partitionedfs.py94
1 files changed, 40 insertions, 54 deletions
diff --git a/scripts/lib/mic/utils/partitionedfs.py b/scripts/lib/mic/utils/partitionedfs.py
index 04758440e1..e8cded26e0 100644
--- a/scripts/lib/mic/utils/partitionedfs.py
+++ b/scripts/lib/mic/utils/partitionedfs.py
@@ -25,6 +25,7 @@ from mic.utils import runner
from mic.utils.errors import MountError
from mic.utils.fs_related import *
from mic.utils.gpt_parser import GptParser
+from mic.utils.oe.misc import *
# Overhead of the MBR partitioning scheme (just one sector)
MBR_OVERHEAD = 1
@@ -93,7 +94,7 @@ class PartitionedMount(Mount):
self.partitions.append(part)
self.__add_disk(part['disk_name'])
- def add_partition(self, size, disk_name, mountpoint, fstype = None,
+ def add_partition(self, size, disk_name, mountpoint, source_file = None, fstype = None,
label=None, fsopts = None, boot = False, align = None,
part_type = None):
""" Add the next partition. Prtitions have to be added in the
@@ -141,6 +142,7 @@ class PartitionedMount(Mount):
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
@@ -723,67 +725,51 @@ class PartitionedMount(Mount):
self.snapshot_created = True
+ def __install_partition(self, num, source_file, start, size):
+ """
+ Install source_file contents into a partition.
+ """
+ if not source_file: # nothing to install
+ return
+
+ # Start is included in the size so need to substract one from the end.
+ end = start + size - 1
+ msger.debug("Installed %s in partition %d, sectors %d-%d, size %d sectors" % (source_file, num, start, end, size))
+
+ dd_cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \
+ (source_file, self.image_file, self.sector_size, start, size)
+ rc, out = exec_cmd(dd_cmd)
+
+
+ def install(self, image_file):
+ msger.debug("Installing partitions")
+
+ self.image_file = image_file
+
+ for p in self.partitions:
+ d = self.disks[p['disk_name']]
+ if d['ptable_format'] == "msdos" and p['num'] == 5:
+ # The last sector of the 3rd partition was reserved for the EBR
+ # of the first _logical_ partition. This is why the extended
+ # partition should start one sector before the first logical
+ # partition.
+ self.__install_partition(p['num'], p['source_file'],
+ p['start'] - 1,
+ d['offset'] - p['start'])
+
+ self.__install_partition(p['num'], p['source_file'],
+ p['start'], p['size'])
+
def mount(self):
for dev in self.disks.keys():
d = self.disks[dev]
d['disk'].create()
self.__format_disks()
- self.__map_partitions()
- self.__calculate_mountorder()
- for mp in self.mountOrder:
- p = None
- for p1 in self.partitions:
- if p1['mountpoint'] == mp:
- p = p1
- break
-
- if not p['label']:
- if p['mountpoint'] == "/":
- p['label'] = 'platform'
- else:
- p['label'] = mp.split('/')[-1]
-
- if mp == 'swap':
- import uuid
- p['uuid'] = str(uuid.uuid1())
- runner.show([self.mkswap,
- '-L', p['label'],
- '-U', p['uuid'],
- p['device']])
- continue
+ self.__calculate_mountorder()
- rmmountdir = False
- if p['mountpoint'] == "/":
- rmmountdir = True
- if p['fstype'] == "vfat" or p['fstype'] == "msdos":
- myDiskMount = VfatDiskMount
- elif p['fstype'] in ("ext2", "ext3", "ext4"):
- myDiskMount = ExtDiskMount
- elif p['fstype'] == "btrfs":
- myDiskMount = BtrfsDiskMount
- else:
- raise MountError("Fail to support file system " + p['fstype'])
-
- if p['fstype'] == "btrfs" and not p['fsopts']:
- p['fsopts'] = "subvolid=0"
-
- pdisk = myDiskMount(RawDisk(p['size'] * self.sector_size, p['device']),
- self.mountdir + p['mountpoint'],
- p['fstype'],
- 4096,
- p['label'],
- rmmountdir,
- self.skipformat,
- fsopts = p['fsopts'])
- pdisk.mount(pdisk.fsopts)
- if p['fstype'] == "btrfs" and p['mountpoint'] == "/":
- if not self.skipformat:
- self.__create_subvolumes(p, pdisk)
- self.__mount_subvolumes(p, pdisk)
- p['mount'] = pdisk
- p['uuid'] = pdisk.uuid
+ return
def resparse(self, size = None):
# Can't re-sparse a disk image - too hard