diff options
Diffstat (limited to 'scripts/lib/mic/kickstart')
4 files changed, 417 insertions, 42 deletions
diff --git a/scripts/lib/mic/kickstart/__init__.py b/scripts/lib/mic/kickstart/__init__.py index f9a53343d1..7e645caa11 100644 --- a/scripts/lib/mic/kickstart/__init__.py +++ b/scripts/lib/mic/kickstart/__init__.py @@ -99,11 +99,11 @@ def read_kickstart(path): commandMap[using_version]["desktop"] = desktop.Mic_Desktop commandMap[using_version]["repo"] = micrepo.Mic_Repo commandMap[using_version]["bootloader"] = micboot.Mic_Bootloader - commandMap[using_version]["part"] = partition.Mic_Partition - commandMap[using_version]["partition"] = partition.Mic_Partition + commandMap[using_version]["part"] = partition.Wic_Partition + commandMap[using_version]["partition"] = partition.Wic_Partition commandMap[using_version]["installerfw"] = installerfw.Mic_installerfw dataMap[using_version]["RepoData"] = micrepo.Mic_RepoData - dataMap[using_version]["PartData"] = partition.Mic_PartData + dataMap[using_version]["PartData"] = partition.Wic_PartData superclass = ksversion.returnClassForVersion(version=using_version) class KSHandlers(superclass): diff --git a/scripts/lib/mic/kickstart/custom_commands/__init__.py b/scripts/lib/mic/kickstart/custom_commands/__init__.py index 5f4c440369..6aed0ff6fa 100644 --- a/scripts/lib/mic/kickstart/custom_commands/__init__.py +++ b/scripts/lib/mic/kickstart/custom_commands/__init__.py @@ -1,12 +1,17 @@ from desktop import Mic_Desktop from micrepo import Mic_Repo, Mic_RepoData -from partition import Mic_Partition +from micpartition import Mic_Partition +from micpartition import Mic_PartData from installerfw import Mic_installerfw +from partition import Wic_Partition __all__ = ( "Mic_Desktop", "Mic_Repo", "Mic_RepoData", "Mic_Partition", + "Mic_PartData", "Mic_installerfw", + "Wic_Partition", + "Wic_PartData", ) diff --git a/scripts/lib/mic/kickstart/custom_commands/micpartition.py b/scripts/lib/mic/kickstart/custom_commands/micpartition.py new file mode 100644 index 0000000000..59a87fb486 --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/micpartition.py @@ -0,0 +1,57 @@ +#!/usr/bin/python -tt +# +# Marko Saukko <marko.saukko@cybercom.com> +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# +# This copyrighted material is made available to anyone wishing to use, modify, +# copy, or redistribute it subject to the terms and conditions of the GNU +# General Public License v.2. This program is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the +# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +from pykickstart.commands.partition import * + +class Mic_PartData(FC4_PartData): + removedKeywords = FC4_PartData.removedKeywords + removedAttrs = FC4_PartData.removedAttrs + + def __init__(self, *args, **kwargs): + FC4_PartData.__init__(self, *args, **kwargs) + self.deleteRemovedAttrs() + self.align = kwargs.get("align", None) + self.extopts = kwargs.get("extopts", None) + self.part_type = kwargs.get("part_type", None) + + def _getArgsAsStr(self): + retval = FC4_PartData._getArgsAsStr(self) + + if self.align: + retval += " --align" + if self.extopts: + retval += " --extoptions=%s" % self.extopts + if self.part_type: + retval += " --part-type=%s" % self.part_type + + return retval + +class Mic_Partition(FC4_Partition): + removedKeywords = FC4_Partition.removedKeywords + removedAttrs = FC4_Partition.removedAttrs + + def _getParser(self): + op = FC4_Partition._getParser(self) + # The alignment value is given in kBytes. e.g., value 8 means that + # the partition is aligned to start from 8096 byte boundary. + op.add_option("--align", type="int", action="store", dest="align", + default=None) + op.add_option("--extoptions", type="string", action="store", dest="extopts", + default=None) + op.add_option("--part-type", type="string", action="store", dest="part_type", + default=None) + return op diff --git a/scripts/lib/mic/kickstart/custom_commands/partition.py b/scripts/lib/mic/kickstart/custom_commands/partition.py index 59a87fb486..302cace234 100644 --- a/scripts/lib/mic/kickstart/custom_commands/partition.py +++ b/scripts/lib/mic/kickstart/custom_commands/partition.py @@ -1,57 +1,370 @@ -#!/usr/bin/python -tt +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- # -# Marko Saukko <marko.saukko@cybercom.com> +# Copyright (c) 2013, Intel Corporation. +# All rights reserved. # -# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. # -# This copyrighted material is made available to anyone wishing to use, modify, -# copy, or redistribute it subject to the terms and conditions of the GNU -# General Public License v.2. This program is distributed in the hope that it -# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the -# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the GNU General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# DESCRIPTION +# This module provides the OpenEmbedded partition object definitions. +# +# AUTHORS +# Tom Zanussi <tom.zanussi (at] linux.intel.com> # -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Software Foundation, Inc., 51 -# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +import shutil from pykickstart.commands.partition import * +from mic.utils.oe.misc import * + +from mic.kickstart.custom_commands import * -class Mic_PartData(FC4_PartData): - removedKeywords = FC4_PartData.removedKeywords - removedAttrs = FC4_PartData.removedAttrs +BOOTDD_EXTRA_SPACE = 16384 + +class Wic_PartData(Mic_PartData): + removedKeywords = Mic_PartData.removedKeywords + removedAttrs = Mic_PartData.removedAttrs def __init__(self, *args, **kwargs): - FC4_PartData.__init__(self, *args, **kwargs) + Mic_PartData.__init__(self, *args, **kwargs) self.deleteRemovedAttrs() - self.align = kwargs.get("align", None) - self.extopts = kwargs.get("extopts", None) - self.part_type = kwargs.get("part_type", None) + self.source = kwargs.get("source", None) + self.source_file = "" + self.size = 0 def _getArgsAsStr(self): - retval = FC4_PartData._getArgsAsStr(self) + retval = Mic_PartData._getArgsAsStr(self) - if self.align: - retval += " --align" - if self.extopts: - retval += " --extoptions=%s" % self.extopts - if self.part_type: - retval += " --part-type=%s" % self.part_type + if self.source: + retval += " --source=%s" % self.source return retval -class Mic_Partition(FC4_Partition): - removedKeywords = FC4_Partition.removedKeywords - removedAttrs = FC4_Partition.removedAttrs + def prepare(self, cr_workdir, oe_builddir, boot_type, rootfs_dir, + bootimg_dir, kernel_dir, native_sysroot): + """ + Prepare content for individual partitions, depending on + partition command parameters. + """ + if not self.source: + if self.fstype and self.fstype == "swap": + self.prepare_swap_partition(cr_workdir, oe_builddir, + native_sysroot) + elif self.fstype: + self.prepare_empty_partition(cr_workdir, oe_builddir, + native_sysroot) + return + + if self.source == "bootimg" and boot_type == "pcbios": + self.prepare_bootimg_pcbios(cr_workdir, oe_builddir, bootimg_dir, + kernel_dir, native_sysroot) + elif self.source == "bootimg" and boot_type == "efi": + self.prepare_bootimg_efi(cr_workdir, oe_builddir, bootimg_dir, + kernel_dir, native_sysroot) + elif self.source.startswith("rootfs"): + self.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, + native_sysroot) + + def prepare_bootimg_pcbios(self, cr_workdir, oe_builddir, bootimg_dir, + kernel_dir, native_sysroot): + """ + Prepare content for a legacy bios boot partition. + """ + staging_kernel_dir = kernel_dir + staging_data_dir = bootimg_dir + + hdddir = "%s/hdd/boot" % cr_workdir + + install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \ + % (staging_kernel_dir, hdddir) + tmp = exec_cmd(install_cmd) + + install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \ + % (staging_data_dir, hdddir) + tmp = exec_cmd(install_cmd) + + du_cmd = "du -bks %s" % hdddir + rc, out = exec_cmd(du_cmd) + blocks = int(out.split()[0]) + + blocks += BOOTDD_EXTRA_SPACE + + # Ensure total sectors is an integral number of sectors per + # track or mcopy will complain. Sectors are 512 bytes, and we + # generate images with 32 sectors per track. This calculation is + # done in blocks, thus the mod by 16 instead of 32. + blocks += (16 - (blocks % 16)) + + # dosfs image, created by mkdosfs + bootimg = "%s/boot.img" % cr_workdir + + dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks) + exec_native_cmd(dosfs_cmd, native_sysroot) + + mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) + exec_native_cmd(mcopy_cmd, native_sysroot) + + syslinux_cmd = "syslinux %s" % bootimg + exec_native_cmd(syslinux_cmd, native_sysroot) + + chmod_cmd = "chmod 644 %s" % bootimg + exec_cmd(chmod_cmd) + + du_cmd = "du -Lbms %s" % bootimg + rc, out = exec_cmd(du_cmd) + bootimg_size = out.split()[0] + + self.size = bootimg_size + self.source_file = bootimg + + def prepare_bootimg_efi(self, cr_workdir, oe_builddir, bootimg_dir, + kernel_dir, native_sysroot): + """ + Prepare content for an EFI (grub) boot partition. + """ + staging_kernel_dir = kernel_dir + staging_data_dir = bootimg_dir + + hdddir = "%s/hdd/boot" % cr_workdir + + install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" % \ + (staging_kernel_dir, hdddir) + tmp = exec_cmd(install_cmd) + + shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, + "%s/grub.cfg" % cr_workdir) + + cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (staging_data_dir, hdddir) + exec_cmd(cp_cmd, True) + + shutil.move("%s/grub.cfg" % cr_workdir, + "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) + + du_cmd = "du -bks %s" % hdddir + rc, out = exec_cmd(du_cmd) + blocks = int(out.split()[0]) + + blocks += BOOTDD_EXTRA_SPACE + + # Ensure total sectors is an integral number of sectors per + # track or mcopy will complain. Sectors are 512 bytes, and we + # generate images with 32 sectors per track. This calculation is + # done in blocks, thus the mod by 16 instead of 32. + blocks += (16 - (blocks % 16)) + + # dosfs image, created by mkdosfs + bootimg = "%s/boot.img" % cr_workdir + + dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks) + exec_native_cmd(dosfs_cmd, native_sysroot) + + mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) + exec_native_cmd(mcopy_cmd, native_sysroot) + + chmod_cmd = "chmod 644 %s" % bootimg + exec_cmd(chmod_cmd) + + du_cmd = "du -Lbms %s" % bootimg + rc, out = exec_cmd(du_cmd) + bootimg_size = out.split()[0] + + self.size = bootimg_size + self.source_file = bootimg + + def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir, + rootfs_dir): + """ + Handle an already-created partition e.g. xxx.ext3 + """ + rootfs = oe_builddir + du_cmd = "du -Lbms %s" % rootfs + rc, out = exec_cmd(du_cmd) + rootfs_size = out.split()[0] + + self.size = rootfs_size + self.source_file = rootfs + + def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir, + native_sysroot): + """ + Prepare content for a rootfs partition i.e. create a partition + and fill it from a /rootfs dir. + + Currently handles ext2/3/4 and btrfs. + """ + if self.fstype.startswith("ext"): + return self.prepare_rootfs_ext(cr_workdir, oe_builddir, + rootfs_dir, native_sysroot) + elif self.fstype.startswith("btrfs"): + return self.prepare_rootfs_btrfs(cr_workdir, oe_builddir, + rootfs_dir, native_sysroot) + + def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir, + native_sysroot): + """ + Prepare content for an ext2/3/4 rootfs partition. + """ + populate_script = "%s/usr/bin/populate-extfs.sh" % native_sysroot + image_extra_space = 10240 + + image_rootfs = rootfs_dir + rootfs = "%s/rootfs.%s" % (cr_workdir, self.fstype) + + du_cmd = "du -ks %s" % image_rootfs + rc, out = exec_cmd(du_cmd) + actual_rootfs_size = out.split()[0] + + rootfs_size = int(actual_rootfs_size) + image_extra_space + + dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ + (rootfs, rootfs_size) + rc, out = exec_cmd(dd_cmd) + + extra_imagecmd = "-i 8192" + + mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, rootfs) + rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) + + populate_cmd = populate_script + " " + image_rootfs + " " + rootfs + rc, out = exec_native_cmd(populate_cmd, native_sysroot) + + # get the rootfs size in the right units for kickstart (Mb) + du_cmd = "du -Lbms %s" % rootfs + rc, out = exec_cmd(du_cmd) + rootfs_size = out.split()[0] + + self.size = rootfs_size + self.source_file = rootfs + + return 0 + + def prepare_rootfs_btrfs(self, cr_workdir, oe_builddir, rootfs_dir, + native_sysroot): + """ + Prepare content for a btrfs rootfs partition. + + Currently handles ext2/3/4 and btrfs. + """ + image_extra_space = 10240 + + image_rootfs = rootfs_dir + rootfs = "%s/rootfs.%s" % (cr_workdir, self.fstype) + + du_cmd = "du -ks %s" % image_rootfs + rc, out = exec_cmd(du_cmd) + actual_rootfs_size = out.split()[0] + + rootfs_size = int(actual_rootfs_size) + image_extra_space + + dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ + (rootfs, rootfs_size) + rc, out = exec_cmd(dd_cmd) + + mkfs_cmd = "mkfs.%s -b %d -r %s %s" % \ + (self.fstype, rootfs_size * 1024, image_rootfs, rootfs) + rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) + + # get the rootfs size in the right units for kickstart (Mb) + du_cmd = "du -Lbms %s" % rootfs + rc, out = exec_cmd(du_cmd) + rootfs_size = out.split()[0] + + self.size = rootfs_size + self.source_file = rootfs + + def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot): + """ + Prepare an empty partition. + """ + if self.fstype.startswith("ext"): + return self.prepare_empty_partition_ext(cr_workdir, oe_builddir, + native_sysroot) + elif self.fstype.startswith("btrfs"): + return self.prepare_empty_partition_btrfs(cr_workdir, oe_builddir, + native_sysroot) + + def prepare_empty_partition_ext(self, cr_workdir, oe_builddir, + native_sysroot): + """ + Prepare an empty ext2/3/4 partition. + """ + fs = "%s/fs.%s" % (cr_workdir, self.fstype) + + dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \ + (fs, self.size) + rc, out = exec_cmd(dd_cmd) + + extra_imagecmd = "-i 8192" + + mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs) + rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) + + self.source_file = fs + + return 0 + + def prepare_empty_partition_btrfs(self, cr_workdir, oe_builddir, + native_sysroot): + """ + Prepare an empty btrfs partition. + """ + fs = "%s/fs.%s" % (cr_workdir, self.fstype) + + dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \ + (fs, self.size) + rc, out = exec_cmd(dd_cmd) + + mkfs_cmd = "mkfs.%s -b %d %s" % (self.fstype, self.size * 1024, rootfs) + rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) + + mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs) + rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) + + self.source_file = fs + + return 0 + + def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot): + """ + Prepare a swap partition. + """ + fs = "%s/fs.%s" % (cr_workdir, self.fstype) + + dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \ + (fs, self.size) + rc, out = exec_cmd(dd_cmd) + + 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()), fs) + rc, out = exec_native_cmd(mkswap_cmd, native_sysroot) + + self.source_file = fs + + return 0 + +class Wic_Partition(Mic_Partition): + removedKeywords = Mic_Partition.removedKeywords + removedAttrs = Mic_Partition.removedAttrs def _getParser(self): - op = FC4_Partition._getParser(self) - # The alignment value is given in kBytes. e.g., value 8 means that - # the partition is aligned to start from 8096 byte boundary. - op.add_option("--align", type="int", action="store", dest="align", - default=None) - op.add_option("--extoptions", type="string", action="store", dest="extopts", - default=None) - op.add_option("--part-type", type="string", action="store", dest="part_type", - default=None) + op = Mic_Partition._getParser(self) + # use specified source file to fill the partition + # and calculate partition size + op.add_option("--source", type="string", action="store", + dest="source", default=None) return op |