Yocto 2.5
Move OpenBMC to Yocto 2.5(sumo)
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Change-Id: I5c5ad6904a16e14c1c397f0baf10c9d465594a78
diff --git a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in
new file mode 100644
index 0000000..7300e65
--- /dev/null
+++ b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in
@@ -0,0 +1,3 @@
+bootloader --ptable gpt
+part /boot --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/boot --fstype=vfat --label boot --active --align 1024 --use-uuid --overhead-factor 1.0
+part / --source rootfs --fstype=ext4 --label root --align 1024 --exclude-path boot/
diff --git a/import-layers/yocto-poky/scripts/lib/wic/filemap.py b/import-layers/yocto-poky/scripts/lib/wic/filemap.py
index 77e32b9..a72fa09 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/filemap.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/filemap.py
@@ -37,7 +37,15 @@
# Get the block size of the host file-system for the image file by calling
# the FIGETBSZ ioctl (number 2).
binary_data = fcntl.ioctl(file_obj, 2, struct.pack('I', 0))
- return struct.unpack('I', binary_data)[0]
+ bsize = struct.unpack('I', binary_data)[0]
+ if not bsize:
+ import os
+ stat = os.fstat(file_obj.fileno())
+ if hasattr(stat, 'st_blksize'):
+ bsize = stat.st_blksize
+ else:
+ raise IOError("Unable to determine block size")
+ return bsize
class ErrorNotSupp(Exception):
"""
diff --git a/import-layers/yocto-poky/scripts/lib/wic/help.py b/import-layers/yocto-poky/scripts/lib/wic/help.py
index 2ac45e0..842b868 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/help.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/help.py
@@ -576,6 +576,10 @@
partition. In other words, it 'prepares' the final partition
image which will be incorporated into the disk image.
+ do_post_partition()
+ Called after the partition is created. It is useful to add post
+ operations e.g. signing the partition.
+
do_configure_partition()
Called before do_prepare_partition(), typically used to
create custom configuration files for a partition, for
@@ -863,7 +867,10 @@
This is achieved by wic adding entries to the fstab during image
generation. In order for a valid fstab to be generated one of the
--ondrive, --ondisk or --use-uuid partition options must be used for
- each partition that specifies a mountpoint.
+ each partition that specifies a mountpoint. Note that with --use-uuid
+ and non-root <mountpoint>, including swap, the mount program must
+ understand the PARTUUID syntax. This currently excludes the busybox
+ versions of these applications.
The following are supported 'part' options:
@@ -986,6 +993,11 @@
in bootloader configuration before running wic. In this case .wks file can
be generated or modified to set preconfigured parition UUID using this option.
+ --fsuuid: This option is specific to wic. It specifies filesystem UUID.
+ It's useful if preconfigured filesystem UUID is added to kernel command line
+ in bootloader configuration before running wic. In this case .wks file can
+ be generated or modified to set preconfigured filesystem UUID using this option.
+
--system-id: This option is specific to wic. It specifies partition system id. It's useful
for the harware that requires non-default partition system ids. The parameter
in one byte long hex number either with 0x prefix or without it.
diff --git a/import-layers/yocto-poky/scripts/lib/wic/ksparser.py b/import-layers/yocto-poky/scripts/lib/wic/ksparser.py
index 7850e81..e590b2f 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/ksparser.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/ksparser.py
@@ -161,6 +161,7 @@
part.add_argument('--system-id', type=systemidtype)
part.add_argument('--use-uuid', action='store_true')
part.add_argument('--uuid')
+ part.add_argument('--fsuuid')
bootloader = subparsers.add_parser('bootloader')
bootloader.add_argument('--append')
@@ -195,6 +196,11 @@
raise KickStartError('%s:%d: %s' % \
(confpath, lineno, err))
if line.startswith('part'):
+ # SquashFS does not support UUID
+ if parsed.fstype == 'squashfs' and parsed.use_uuid:
+ err = "%s:%d: SquashFS does not support UUID" \
+ % (confpath, lineno)
+ raise KickStartError(err)
# using ArgumentParser one cannot easily tell if option
# was passed as argument, if said option has a default
# value; --overhead-factor/--extra-space cannot be used
diff --git a/import-layers/yocto-poky/scripts/lib/wic/partition.py b/import-layers/yocto-poky/scripts/lib/wic/partition.py
index 84fe85d..3fe5c4e 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/partition.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/partition.py
@@ -26,6 +26,7 @@
import logging
import os
+import uuid
from wic import WicError
from wic.misc import exec_cmd, exec_native_cmd, get_bitbake_var
@@ -61,6 +62,7 @@
self.system_id = args.system_id
self.use_uuid = args.use_uuid
self.uuid = args.uuid
+ self.fsuuid = args.fsuuid
self.lineno = lineno
self.source_file = ""
@@ -183,6 +185,9 @@
plugin.do_prepare_partition(self, srcparams_dict, creator,
cr_workdir, oe_builddir, bootimg_dir,
kernel_dir, rootfs_dir, native_sysroot)
+ plugin.do_post_partition(self, srcparams_dict, creator,
+ cr_workdir, oe_builddir, bootimg_dir,
+ kernel_dir, rootfs_dir, native_sysroot)
# further processing required Partition.size to be an integer, make
# sure that it is one
@@ -197,12 +202,12 @@
(self.mountpoint, self.size, self.fixed_size))
def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
- native_sysroot):
+ native_sysroot, real_rootfs = True):
"""
Prepare content for a rootfs partition i.e. create a partition
and fill it from a /rootfs dir.
- Currently handles ext2/3/4, btrfs and vfat.
+ Currently handles ext2/3/4, btrfs, vfat and squashfs.
"""
p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
@@ -221,7 +226,7 @@
os.remove(rootfs)
# Get rootfs size from bitbake variable if it's not set in .ks file
- if not self.size:
+ if not self.size and real_rootfs:
# Bitbake variable ROOTFS_SIZE is calculated in
# Image._get_rootfs_size method from meta/lib/oe/image.py
# using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT,
@@ -264,8 +269,8 @@
if self.label:
label_str = "-L %s" % self.label
- mkfs_cmd = "mkfs.%s %s %s %s -d %s" % \
- (self.fstype, extraopts, rootfs, label_str, rootfs_dir)
+ mkfs_cmd = "mkfs.%s %s %s %s -U %s -d %s" % \
+ (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
@@ -275,8 +280,6 @@
native_sysroot, pseudo):
"""
Prepare content for a btrfs rootfs partition.
-
- Currently handles ext2/3/4 and btrfs.
"""
du_cmd = "du -ks %s" % rootfs_dir
out = exec_cmd(du_cmd)
@@ -291,9 +294,9 @@
if self.label:
label_str = "-L %s" % self.label
- mkfs_cmd = "mkfs.%s -b %d -r %s %s %s %s" % \
+ mkfs_cmd = "mkfs.%s -b %d -r %s %s %s -U %s %s" % \
(self.fstype, rootfs_size * 1024, rootfs_dir, label_str,
- self.mkfs_extraopts, rootfs)
+ self.mkfs_extraopts, self.fsuuid, rootfs)
exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
def prepare_rootfs_msdos(self, rootfs, oe_builddir, rootfs_dir,
@@ -317,8 +320,9 @@
extraopts = self.mkfs_extraopts or '-S 512'
- dosfs_cmd = "mkdosfs %s %s %s -C %s %d" % \
- (label_str, size_str, extraopts, rootfs, rootfs_size)
+ dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
+ (label_str, self.fsuuid, size_str, extraopts, rootfs,
+ max(8250, rootfs_size))
exec_native_cmd(dosfs_cmd, native_sysroot)
mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
@@ -354,8 +358,8 @@
if self.label:
label_str = "-L %s" % self.label
- mkfs_cmd = "mkfs.%s -F %s %s %s" % \
- (self.fstype, extraopts, label_str, rootfs)
+ mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
+ (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
exec_native_cmd(mkfs_cmd, native_sysroot)
def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
@@ -371,8 +375,8 @@
if self.label:
label_str = "-L %s" % self.label
- mkfs_cmd = "mkfs.%s -b %d %s %s %s" % \
- (self.fstype, self.size * 1024, label_str,
+ mkfs_cmd = "mkfs.%s -b %d %s -U %s %s %s" % \
+ (self.fstype, self.size * 1024, label_str, self.fsuuid,
self.mkfs_extraopts, rootfs)
exec_native_cmd(mkfs_cmd, native_sysroot)
@@ -393,8 +397,9 @@
extraopts = self.mkfs_extraopts or '-S 512'
- dosfs_cmd = "mkdosfs %s %s %s -C %s %d" % \
- (label_str, extraopts, size_str, rootfs, blocks)
+ dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
+ (label_str, self.fsuuid, extraopts, size_str, rootfs,
+ blocks)
exec_native_cmd(dosfs_cmd, native_sysroot)
@@ -412,9 +417,9 @@
with open(path, 'w') as sparse:
os.ftruncate(sparse.fileno(), self.size * 1024)
- import uuid
label_str = ""
if self.label:
label_str = "-L %s" % self.label
- mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
+
+ mkswap_cmd = "mkswap %s -U %s %s" % (label_str, self.fsuuid, path)
exec_native_cmd(mkswap_cmd, native_sysroot)
diff --git a/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py b/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py
index c009820..686d2fe 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py
@@ -137,3 +137,13 @@
'prepares' the partition to be incorporated into the image.
"""
logger.debug("SourcePlugin: do_prepare_partition: part: %s", part)
+
+ @classmethod
+ def do_post_partition(cls, part, source_params, creator, cr_workdir,
+ oe_builddir, bootimg_dir, kernel_dir, rootfs_dir,
+ native_sysroot):
+ """
+ Called after the partition is created. It is useful to add post
+ operations e.g. security signing the partition.
+ """
+ logger.debug("SourcePlugin: do_post_partition: part: %s", part)
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct.py
index da1c061..1fa6b91 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct.py
@@ -63,6 +63,7 @@
# parse possible 'rootfs=name' items
self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' '))
+ self.replaced_rootfs_paths = {}
self.bootimg_dir = bootimg_dir
self.kernel_dir = kernel_dir
self.native_sysroot = native_sysroot
@@ -141,7 +142,15 @@
continue
if part.use_uuid:
- device_name = "PARTUUID=%s" % part.uuid
+ if part.fsuuid:
+ # FAT UUID is different from others
+ if len(part.fsuuid) == 10:
+ device_name = "UUID=%s-%s" % \
+ (part.fsuuid[2:6], part.fsuuid[6:])
+ else:
+ device_name = "UUID=%s" % part.fsuuid
+ else:
+ device_name = "PARTUUID=%s" % part.uuid
else:
# mmc device partitions are named mmcblk0p1, mmcblk0p2..
prefix = 'p' if part.disk.startswith('mmcblk') else ''
@@ -175,6 +184,7 @@
new_rootfs = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
if new_rootfs:
# rootfs was copied to update fstab
+ self.replaced_rootfs_paths[new_rootfs] = self.rootfs_dir['ROOTFS_DIR']
self.rootfs_dir['ROOTFS_DIR'] = new_rootfs
for part in self.parts:
@@ -250,7 +260,10 @@
suffix = ':'
else:
suffix = '["%s"]:' % (part.mountpoint or part.label)
- msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), part.rootfs_dir)
+ rootdir = part.rootfs_dir
+ if rootdir in self.replaced_rootfs_paths:
+ rootdir = self.replaced_rootfs_paths[rootdir]
+ msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), rootdir)
msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir
msg += ' KERNEL_DIR: %s\n' % self.kernel_dir
@@ -334,13 +347,18 @@
continue
part.realnum = realnum
- # generate parition UUIDs
+ # generate parition and filesystem UUIDs
for part in self.partitions:
if not part.uuid and part.use_uuid:
if self.ptable_format == 'gpt':
part.uuid = str(uuid.uuid4())
else: # msdos partition table
part.uuid = '%08x-%02d' % (self.identifier, part.realnum)
+ if not part.fsuuid:
+ if part.fstype == 'vfat' or part.fstype == 'msdos':
+ part.fsuuid = '0x' + str(uuid.uuid4())[:8].upper()
+ else:
+ part.fsuuid = str(uuid.uuid4())
def prepare(self, imager):
"""Prepare an image. Call prepare method of all image partitions."""
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py
index 4c4f36a..beb74d7 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -240,7 +240,8 @@
# dosfs image, created by mkdosfs
bootimg = "%s/boot.img" % cr_workdir
- dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks)
+ dosfs_cmd = "mkdosfs -n efi -i %s -C %s %d" % \
+ (part.fsuuid, bootimg, blocks)
exec_native_cmd(dosfs_cmd, native_sysroot)
mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-partition.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-partition.py
index 67e5498..b239fc0 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -129,4 +129,4 @@
logger.debug('Prepare boot partition using rootfs in %s', hdddir)
part.prepare_rootfs(cr_workdir, oe_builddir, hdddir,
- native_sysroot)
+ native_sysroot, False)
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py
index 56da468..d599112 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py
@@ -186,7 +186,8 @@
# dosfs image, created by mkdosfs
bootimg = "%s/boot%s.img" % (cr_workdir, part.lineno)
- dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks)
+ dosfs_cmd = "mkdosfs -n boot -i %s -S 512 -C %s %d" % \
+ (part.fsuuid, bootimg, blocks)
exec_native_cmd(dosfs_cmd, native_sysroot)
mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)