* [PATCH 1/7] wic: Move some common items to oe.misc
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
@ 2014-02-04 1:16 ` Tom Zanussi
2014-02-04 1:16 ` [PATCH 2/7] wic: Create and use new functions for getting bitbake variables Tom Zanussi
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:16 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
Move a couple items into a more common location since they're going to
need to be accessible from source plugins.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
scripts/lib/image/engine.py | 11 -----------
scripts/lib/mic/kickstart/custom_commands/partition.py | 2 --
scripts/lib/mic/utils/oe/misc.py | 12 ++++++++++++
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/scripts/lib/image/engine.py b/scripts/lib/image/engine.py
index b3a9c74..0e8b89e 100644
--- a/scripts/lib/image/engine.py
+++ b/scripts/lib/image/engine.py
@@ -60,17 +60,6 @@ def verify_build_env():
return True
-def get_line_val(line, key):
- """
- Extract the value from the VAR="val" string
- """
- if line.startswith(key + "="):
- stripped_line = line.split('=')[1]
- stripped_line = stripped_line.replace('\"', '')
- return stripped_line
- return None
-
-
def find_artifacts(image_name):
"""
Gather the build artifacts for the current image (the image_name
diff --git a/scripts/lib/mic/kickstart/custom_commands/partition.py b/scripts/lib/mic/kickstart/custom_commands/partition.py
index 4b11195..fe8e55a 100644
--- a/scripts/lib/mic/kickstart/custom_commands/partition.py
+++ b/scripts/lib/mic/kickstart/custom_commands/partition.py
@@ -31,8 +31,6 @@ from mic.utils.oe.misc import *
from mic.kickstart.custom_commands import *
-BOOTDD_EXTRA_SPACE = 16384
-
class Wic_PartData(Mic_PartData):
removedKeywords = Mic_PartData.removedKeywords
removedAttrs = Mic_PartData.removedAttrs
diff --git a/scripts/lib/mic/utils/oe/misc.py b/scripts/lib/mic/utils/oe/misc.py
index 9edaa23..097d44c 100644
--- a/scripts/lib/mic/utils/oe/misc.py
+++ b/scripts/lib/mic/utils/oe/misc.py
@@ -106,3 +106,15 @@ def get_wks_var(key):
def add_wks_var(key, val):
wks_vars[key] = val
+
+BOOTDD_EXTRA_SPACE = 16384
+
+def get_line_val(line, key):
+ """
+ Extract the value from the VAR="val" string
+ """
+ if line.startswith(key + "="):
+ stripped_line = line.split('=')[1]
+ stripped_line = stripped_line.replace('\"', '')
+ return stripped_line
+ return None
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/7] wic: Create and use new functions for getting bitbake variables
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
2014-02-04 1:16 ` [PATCH 1/7] wic: Move some common items to oe.misc Tom Zanussi
@ 2014-02-04 1:16 ` Tom Zanussi
2014-02-04 1:16 ` [PATCH 3/7] wic: Add wic-specific bootloader subclass Tom Zanussi
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:16 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
Add get_bitbake_var() and bitbake_env_lines() functions for use by
plugins, which will need access to them for customization.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
scripts/lib/image/engine.py | 20 +++++++++++++++-----
scripts/lib/mic/utils/oe/misc.py | 16 ++++++++++++++++
scripts/wic | 6 ++++++
3 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/scripts/lib/image/engine.py b/scripts/lib/image/engine.py
index 0e8b89e..2dd98b9 100644
--- a/scripts/lib/image/engine.py
+++ b/scripts/lib/image/engine.py
@@ -60,16 +60,26 @@ def verify_build_env():
return True
-def find_artifacts(image_name):
+def find_bitbake_env_lines(image_name):
"""
- Gather the build artifacts for the current image (the image_name
- e.g. core-image-minimal) for the current MACHINE set in local.conf
+ If image_name is empty, plugins might still be able to use the
+ environment, so set it regardless.
"""
bitbake_env_cmd = "bitbake -e %s" % image_name
rc, bitbake_env_lines = exec_cmd(bitbake_env_cmd)
if rc != 0:
- print "Couldn't get '%s' output, exiting." % bitbake_env_cmd
- sys.exit(1)
+ print "Couldn't get '%s' output." % bitbake_env_cmd
+ return None
+
+ return bitbake_env_lines
+
+
+def find_artifacts(image_name):
+ """
+ Gather the build artifacts for the current image (the image_name
+ e.g. core-image-minimal) for the current MACHINE set in local.conf
+ """
+ bitbake_env_lines = get_bitbake_env_lines()
rootfs_dir = kernel_dir = hdddir = staging_data_dir = native_sysroot = ""
diff --git a/scripts/lib/mic/utils/oe/misc.py b/scripts/lib/mic/utils/oe/misc.py
index 097d44c..77dfe03 100644
--- a/scripts/lib/mic/utils/oe/misc.py
+++ b/scripts/lib/mic/utils/oe/misc.py
@@ -109,6 +109,15 @@ def add_wks_var(key, val):
BOOTDD_EXTRA_SPACE = 16384
+__bitbake_env_lines = ""
+
+def set_bitbake_env_lines(bitbake_env_lines):
+ global __bitbake_env_lines
+ __bitbake_env_lines = bitbake_env_lines
+
+def get_bitbake_env_lines():
+ return __bitbake_env_lines
+
def get_line_val(line, key):
"""
Extract the value from the VAR="val" string
@@ -118,3 +127,10 @@ def get_line_val(line, key):
stripped_line = stripped_line.replace('\"', '')
return stripped_line
return None
+
+def get_bitbake_var(key):
+ for line in __bitbake_env_lines.split('\n'):
+ if (get_line_val(line, key)):
+ val = get_line_val(line, key)
+ return val
+ return None
diff --git a/scripts/wic b/scripts/wic
index b6fd16c..4ea5569 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -98,6 +98,12 @@ def wic_create_subcommand(args, usage_str):
print "Creating image(s)...\n"
+ bitbake_env_lines = find_bitbake_env_lines(options.image_name)
+ if not bitbake_env_lines:
+ print "Couldn't get bitbake environment, exiting."
+ sys.exit(1)
+ set_bitbake_env_lines(bitbake_env_lines)
+
bootimg_dir = staging_data_dir = hdddir = ""
if options.image_name:
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/7] wic: Add wic-specific bootloader subclass
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
2014-02-04 1:16 ` [PATCH 1/7] wic: Move some common items to oe.misc Tom Zanussi
2014-02-04 1:16 ` [PATCH 2/7] wic: Create and use new functions for getting bitbake variables Tom Zanussi
@ 2014-02-04 1:16 ` Tom Zanussi
2014-02-04 1:16 ` [PATCH 4/7] wic: Add SourcePlugin class Tom Zanussi
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:16 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
Add a new wic-specific bootloader subclass so we can add a --source
param to hang non-partition plugin off of.
By default, the bootloader gets the /boot partition source plugin, but
this can be overridden by the --source bootloader param if needed.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
scripts/lib/mic/imager/direct.py | 6 +++
scripts/lib/mic/kickstart/__init__.py | 4 +-
.../lib/mic/kickstart/custom_commands/wicboot.py | 57 ++++++++++++++++++++++
3 files changed, 65 insertions(+), 2 deletions(-)
create mode 100644 scripts/lib/mic/kickstart/custom_commands/wicboot.py
diff --git a/scripts/lib/mic/imager/direct.py b/scripts/lib/mic/imager/direct.py
index d24bc68..3827eb8 100644
--- a/scripts/lib/mic/imager/direct.py
+++ b/scripts/lib/mic/imager/direct.py
@@ -225,6 +225,12 @@ class DirectImageCreator(BaseImageCreator):
fstab = self.__write_fstab()
+ for p in parts:
+ # as a convenience, set source to the boot partition source
+ # instead of forcing it to be set via bootloader --source
+ if not self.ks.handler.bootloader.source and p.mountpoint == "/boot":
+ self.ks.handler.bootloader.source = p.source
+
self.boot_type = self.get_boot_type()
if not self.bootimg_dir:
diff --git a/scripts/lib/mic/kickstart/__init__.py b/scripts/lib/mic/kickstart/__init__.py
index 7e645ca..72f3ca6 100644
--- a/scripts/lib/mic/kickstart/__init__.py
+++ b/scripts/lib/mic/kickstart/__init__.py
@@ -32,7 +32,7 @@ from pykickstart.handlers.control import dataMap
from mic import msger
from mic.utils import errors, misc, runner, fs_related as fs
-from custom_commands import desktop, micrepo, micboot, partition, installerfw
+from custom_commands import desktop, micrepo, wicboot, partition, installerfw
AUTH_URL_PTN = r"(?P<scheme>.*)://(?P<username>.*)(:?P<password>.*)?@(?P<url>.*)"
@@ -98,7 +98,7 @@ def read_kickstart(path):
using_version = ksversion.DEVEL
commandMap[using_version]["desktop"] = desktop.Mic_Desktop
commandMap[using_version]["repo"] = micrepo.Mic_Repo
- commandMap[using_version]["bootloader"] = micboot.Mic_Bootloader
+ commandMap[using_version]["bootloader"] = wicboot.Wic_Bootloader
commandMap[using_version]["part"] = partition.Wic_Partition
commandMap[using_version]["partition"] = partition.Wic_Partition
commandMap[using_version]["installerfw"] = installerfw.Mic_installerfw
diff --git a/scripts/lib/mic/kickstart/custom_commands/wicboot.py b/scripts/lib/mic/kickstart/custom_commands/wicboot.py
new file mode 100644
index 0000000..ab8871d
--- /dev/null
+++ b/scripts/lib/mic/kickstart/custom_commands/wicboot.py
@@ -0,0 +1,57 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2014, Intel Corporation.
+# All rights reserved.
+#
+# 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 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 bootloader object definitions.
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+#
+
+from pykickstart.base import *
+from pykickstart.errors import *
+from pykickstart.options import *
+from pykickstart.commands.bootloader import *
+
+from mic.kickstart.custom_commands.micboot import *
+
+class Wic_Bootloader(Mic_Bootloader):
+ def __init__(self, writePriority=10, appendLine="", driveorder=None,
+ forceLBA=False, location="", md5pass="", password="",
+ upgrade=False, menus=""):
+ Mic_Bootloader.__init__(self, writePriority, appendLine, driveorder,
+ forceLBA, location, md5pass, password, upgrade)
+
+ self.source = ""
+
+ def _getArgsAsStr(self):
+ retval = Mic_Bootloader._getArgsAsStr(self)
+
+ if self.source:
+ retval += " --source=%s" % self.source
+
+ return retval
+
+ def _getParser(self):
+ op = Mic_Bootloader._getParser(self)
+ # use specified source plugin to implement bootloader-specific methods
+ op.add_option("--source", type="string", action="store",
+ dest="source", default=None)
+ return op
+
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 0/7] wic updates: Initial source plugin implementation
@ 2014-02-04 1:16 Tom Zanussi
2014-02-04 1:16 ` [PATCH 1/7] wic: Move some common items to oe.misc Tom Zanussi
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:16 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
This patchset implements wic 'source plugins', basically a generalization
of the existing --source params to wic .wks commands.
The following changes since commit 358dd840c53e2e69e668a6d5da04eb3da3769ba3:
sstate-cache-management.sh: don't remove all packagedata sstate archives (2014-02-02 11:30:34 +0000)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib.git tzanussi/wic-plugins-v0
http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=tzanussi/wic-plugins-v0
Tom Zanussi (7):
wic: Move some common items to oe.misc
wic: Create and use new functions for getting bitbake variables
wic: Add wic-specific bootloader subclass
wic: Add SourcePlugin class
wic: Add BootimgEFIPlugin and BootimgPcbiosPlugin
wic: Hook up BootimgEFIPlugin and BootimgPcbiosPlugin plugins
wic: Hook up --debug option
scripts/lib/image/canned-wks/directdisk.wks | 2 +-
scripts/lib/image/canned-wks/mkefidisk.wks | 2 +-
scripts/lib/image/engine.py | 28 +--
scripts/lib/mic/imager/direct.py | 198 +++++----------------
scripts/lib/mic/kickstart/__init__.py | 4 +-
.../lib/mic/kickstart/custom_commands/partition.py | 155 ++++------------
.../lib/mic/kickstart/custom_commands/wicboot.py | 57 ++++++
scripts/lib/mic/plugin.py | 23 ++-
scripts/lib/mic/pluginbase.py | 55 +++++-
scripts/lib/mic/plugins/source/bootimg-efi.py | 161 +++++++++++++++++
scripts/lib/mic/plugins/source/bootimg-pcbios.py | 187 +++++++++++++++++++
scripts/lib/mic/utils/oe/misc.py | 28 +++
scripts/wic | 17 +-
13 files changed, 618 insertions(+), 299 deletions(-)
create mode 100644 scripts/lib/mic/kickstart/custom_commands/wicboot.py
create mode 100644 scripts/lib/mic/plugins/source/bootimg-efi.py
create mode 100644 scripts/lib/mic/plugins/source/bootimg-pcbios.py
--
1.8.3.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/7] wic: Add SourcePlugin class
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
` (2 preceding siblings ...)
2014-02-04 1:16 ` [PATCH 3/7] wic: Add wic-specific bootloader subclass Tom Zanussi
@ 2014-02-04 1:16 ` Tom Zanussi
2014-02-04 1:16 ` [PATCH 5/7] wic: Add BootimgEFIPlugin and BootimgPcbiosPlugin Tom Zanussi
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:16 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
Define the SourcePlugin class, which is the class that should be
subclassed to create a 'source' plugin.
'Source' plugins provide a mechanism to customize various aspects of
the image generation process in wic, mainly the contents of
partitions.
The initial version of wic defined a --source param for partitions,
which was in the first revision hard-coded to two possible values:
rootfs and bootimg.
This patch essentially removes the hard-coded --bootimg param and
replaces it with a plugin system that maps the value specified as
--source to a particular 'source' plugin instead.
A 'source' plugin is created as a subclass of SourcePlugin and the
plugin file containing it is added to scriptsl/lib/mic/plugins/source/
to make the plugin implementation available to the wic implementation.
When the wic implementation needs to invoke a partition-specific
implementation, it looks for the plugin that has the same name as the
--source param given to that partition. For example, if the partition
is set up like this:
part /boot --source bootimg-pcbios ...
then the methods defined as class members of the plugin having the
matching .name class member would be used.
To be more concrete, here's the plugin definition that would match a
'--source bootimg-pcbios' usage, along with an example method that
would be called by the wic implementation when it needed to invoke an
implementation-specific partition-preparation function:
class BootimgPcbiosPlugin(SourcePlugin):
name = 'bootimg-pcbios'
@classmethod
def do_prepare_partition(self, part, ...)
If the subclass itself doesn't implement a function, a 'default'
version in a superclass will be located and used, which is why all
plugins must be derived from SourcePlugin.
This scheme is extensible - adding more hooks is a simple matter of
adding more plugin methods to SourcePlugin and derived classes. The
code that then needs to call the plugin methods the uses
plugin.get_source_plugin_methods() to find the method(s) needed by the
call; this is done by filling up a dict with keys containing the
methon names of interest - on success, these will be filled in with
the actual methods. fPlease see the implementation for examples and
details.
Note that a source plugin need not restrict itself to methods that
apply directly to partitions - methods can also be defined for higher
level processing such as at the 'disk' level. The
get_default_source_plugin() of DirectImageCreator allows the default
source plugin to be retrieved; by default this is set to be the same
plugin used for the /boot partition, but that can be overridden by
specifying a different --source and therefore different plugin on the
'bootloader' line. This isn't ideal, but it avoids forcing a new
high-level object to be defined for that purpose.
Note that the '--source rootfs' param remains as its current
hard-coded value, which is just the rootfs to be used to populate the
partition - by default, that's just the value of the bitbake
ROOTFS_DIR variable (or whatever was passed in using the -r param).
Note that this also could also be overridden by creating a source
plugin using a different name; at this point, unlike with bootimg,
there's been no need to do so.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
scripts/lib/mic/plugin.py | 23 ++++++++++++++++--
scripts/lib/mic/pluginbase.py | 55 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/scripts/lib/mic/plugin.py b/scripts/lib/mic/plugin.py
index 7c296e9..df03c15 100644
--- a/scripts/lib/mic/plugin.py
+++ b/scripts/lib/mic/plugin.py
@@ -19,13 +19,12 @@ import os, sys
from mic import msger
from mic import pluginbase
-from mic.conf import configmgr
from mic.utils import errors
__ALL__ = ['PluginMgr', 'pluginmgr']
-PLUGIN_TYPES = ["imager", "backend"] # TODO "hook"
+PLUGIN_TYPES = ["imager", "source"] # TODO "hook"
class PluginMgr(object):
@@ -99,4 +98,24 @@ class PluginMgr(object):
return pluginbase.get_plugins(ptype)
+ def get_source_plugin_methods(self, source_name, methods):
+ """
+ The methods param is a dict with the method names to find. On
+ return, the dict values will be filled in with pointers to the
+ corresponding methods. If one or more methods are not found,
+ None is returned.
+ """
+ return_methods = None
+ for _source_name, klass in self.get_plugins('source').iteritems():
+ if _source_name == source_name:
+ for _method_name in methods.keys():
+ if not hasattr(klass, _method_name):
+ msger.warning("Unimplemented %s source interface for: %s"\
+ % (_method_name, _source_name))
+ return None
+ func = getattr(klass, _method_name)
+ methods[_method_name] = func
+ return_methods = methods
+ return return_methods
+
pluginmgr = PluginMgr()
diff --git a/scripts/lib/mic/pluginbase.py b/scripts/lib/mic/pluginbase.py
index 2f9d720..e26b525 100644
--- a/scripts/lib/mic/pluginbase.py
+++ b/scripts/lib/mic/pluginbase.py
@@ -80,6 +80,59 @@ class ImagerPlugin(_Plugin):
def do_chroot(self):
pass
+class SourcePlugin(_Plugin):
+ mic_plugin_type = "source"
+ """
+ The methods that can be implemented by --source plugins.
+
+ Any methods not implemented in a subclass inherit these.
+ """
+
+ @classmethod
+ def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir,
+ bootimg_dir, kernel_dir, native_sysroot):
+ """
+ Called after all partitions have been prepared and assembled into a
+ disk image. This provides a hook to allow finalization of a
+ disk image e.g. to write an MBR to it.
+ """
+ msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name)
+
+ @classmethod
+ def do_stage_partition(self, part, cr, workdir, oe_builddir, bootimg_dir,
+ kernel_dir, native_sysroot):
+ """
+ Special content staging hook called before do_prepare_partition(),
+ normally empty.
+
+ Typically, a partition will just use the passed-in parame e.g
+ straight bootimg_dir, etc, but in some cases, things need to
+ be more tailored e.g. to use a deploy dir + /boot, etc. This
+ hook allows those files to be staged in a customized fashion.
+ Not that get_bitbake_var() allows you to acces non-standard
+ variables that you might want to use for this.
+ """
+ msger.debug("SourcePlugin: do_stage_partition: part: %s" % part)
+
+ @classmethod
+ def do_configure_partition(self, part, cr, cr_workdir, oe_builddir,
+ bootimg_dir, kernel_dir, native_sysroot):
+ """
+ Called before do_prepare_partition(), typically used to create
+ custom configuration files for a partition, for example
+ syslinux or grub config files.
+ """
+ msger.debug("SourcePlugin: do_configure_partition: part: %s" % part)
+
+ @classmethod
+ def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
+ kernel_dir, native_sysroot):
+ """
+ Called to do the actual content population for a partition i.e. it
+ 'prepares' the partition to be incorporated into the image.
+ """
+ msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part)
+
class BackendPlugin(_Plugin):
mic_plugin_type="backend"
@@ -93,4 +146,4 @@ def get_plugins(typen):
else:
return None
-__all__ = ['ImagerPlugin', 'BackendPlugin', 'get_plugins']
+__all__ = ['ImagerPlugin', 'BackendPlugin', 'SourcePlugin', 'get_plugins']
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/7] wic: Add BootimgEFIPlugin and BootimgPcbiosPlugin
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
` (3 preceding siblings ...)
2014-02-04 1:16 ` [PATCH 4/7] wic: Add SourcePlugin class Tom Zanussi
@ 2014-02-04 1:16 ` Tom Zanussi
2014-02-04 1:16 ` [PATCH 6/7] wic: Hook up BootimgEFIPlugin and BootimgPcbiosPlugin plugins Tom Zanussi
2014-02-04 1:17 ` [PATCH 7/7] wic: Hook up --debug option Tom Zanussi
6 siblings, 0 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:16 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
Implement the BootimgPcbiosPlugin and BootimgEFIPlugin SourcePlugin
classes. The configure/prepare_partition() methods are implemented
using code derived from similar code in the Wic_PartData class.
These classes have the corresponding names 'bootimg-pcbios' and
'bootimg-efi', which are the names that should be used in the --source
parameters of the .wks partition commands.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
scripts/lib/mic/plugins/source/bootimg-efi.py | 161 +++++++++++++++++++
scripts/lib/mic/plugins/source/bootimg-pcbios.py | 187 +++++++++++++++++++++++
2 files changed, 348 insertions(+)
create mode 100644 scripts/lib/mic/plugins/source/bootimg-efi.py
create mode 100644 scripts/lib/mic/plugins/source/bootimg-pcbios.py
diff --git a/scripts/lib/mic/plugins/source/bootimg-efi.py b/scripts/lib/mic/plugins/source/bootimg-efi.py
new file mode 100644
index 0000000..f2bd071
--- /dev/null
+++ b/scripts/lib/mic/plugins/source/bootimg-efi.py
@@ -0,0 +1,161 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2014, Intel Corporation.
+# All rights reserved.
+#
+# 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 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 implements the 'bootimg-efi' source plugin class for 'wic'
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+#
+
+import os
+import shutil
+import re
+import tempfile
+
+from mic import kickstart, chroot, msger
+from mic.utils import misc, fs_related, errors, runner, cmdln
+from mic.conf import configmgr
+from mic.plugin import pluginmgr
+from mic.utils.partitionedfs import PartitionedMount
+import mic.imager.direct as direct
+from mic.pluginbase import SourcePlugin
+from mic.utils.oe.misc import *
+from mic.imager.direct import DirectImageCreator
+
+class BootimgEFIPlugin(SourcePlugin):
+ name = 'bootimg-efi'
+
+ @classmethod
+ def do_configure_partition(self, part, cr, cr_workdir, oe_builddir,
+ bootimg_dir, kernel_dir, native_sysroot):
+ """
+ Called before do_prepare_partition(), creates grubefi config
+ """
+ hdddir = "%s/hdd/boot" % cr_workdir
+ rm_cmd = "rm -rf %s" % cr_workdir
+ exec_cmd(rm_cmd)
+
+ install_cmd = "install -d %s/EFI/BOOT" % hdddir
+ tmp = exec_cmd(install_cmd)
+
+ splash = os.path.join(cr_workdir, "/EFI/boot/splash.jpg")
+ if os.path.exists(splash):
+ splashline = "menu background splash.jpg"
+ else:
+ splashline = ""
+
+ (rootdev, root_part_uuid) = cr._get_boot_config()
+ options = cr.ks.handler.bootloader.appendLine
+
+ grubefi_conf = ""
+ grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n"
+ grubefi_conf += "default=boot\n"
+ timeout = kickstart.get_timeout(cr.ks)
+ if not timeout:
+ timeout = 0
+ grubefi_conf += "timeout=%s\n" % timeout
+ grubefi_conf += "menuentry 'boot'{\n"
+
+ kernel = "/vmlinuz"
+
+ if cr._ptable_format == 'msdos':
+ rootstr = rootdev
+ else:
+ if not root_part_uuid:
+ raise MountError("Cannot find the root GPT partition UUID")
+ rootstr = "PARTUUID=%s" % root_part_uuid
+
+ grubefi_conf += "linux %s root=%s rootwait %s\n" \
+ % (kernel, rootstr, options)
+ grubefi_conf += "}\n"
+ if splashline:
+ syslinux_conf += "%s\n" % splashline
+
+ msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \
+ % cr_workdir)
+ cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w")
+ cfg.write(grubefi_conf)
+ cfg.close()
+
+ @classmethod
+ def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
+ kernel_dir, native_sysroot):
+ """
+ Called to do the actual content population for a partition i.e. it
+ 'prepares' the partition to be incorporated into the image.
+ In this case, prepare content for an EFI (grub) boot partition.
+ """
+ if not bootimg_dir:
+ bootimg_dir = get_bitbake_var("HDDDIR")
+ if not bootimg_dir:
+ msger.error("Couldn't find HDDDIR, exiting\n")
+ # just so the result notes display it
+ cr.bootimg_dir = bootimg_dir
+
+ staging_kernel_dir = kernel_dir
+ staging_data_dir = bootimg_dir
+
+ hdddir = "%s/hdd" % cr_workdir
+
+ install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
+ (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]
+
+ part.size = bootimg_size
+ part.source_file = bootimg
+
+
diff --git a/scripts/lib/mic/plugins/source/bootimg-pcbios.py b/scripts/lib/mic/plugins/source/bootimg-pcbios.py
new file mode 100644
index 0000000..1da2a41
--- /dev/null
+++ b/scripts/lib/mic/plugins/source/bootimg-pcbios.py
@@ -0,0 +1,187 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2014, Intel Corporation.
+# All rights reserved.
+#
+# 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 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 implements the 'bootimg-pcbios' source plugin class for 'wic'
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+#
+
+import os
+import shutil
+import re
+import tempfile
+
+from mic import kickstart, chroot, msger
+from mic.utils import misc, fs_related, errors, runner, cmdln
+from mic.conf import configmgr
+from mic.plugin import pluginmgr
+from mic.utils.partitionedfs import PartitionedMount
+import mic.imager.direct as direct
+from mic.pluginbase import SourcePlugin
+from mic.utils.oe.misc import *
+from mic.imager.direct import DirectImageCreator
+
+class BootimgPcbiosPlugin(SourcePlugin):
+ name = 'bootimg-pcbios'
+
+ @classmethod
+ def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir,
+ bootimg_dir, kernel_dir, native_sysroot):
+ """
+ Called after all partitions have been prepared and assembled into a
+ disk image. In this case, we install the MBR.
+ """
+ mbrfile = "%s/syslinux/" % bootimg_dir
+ if cr._ptable_format == 'gpt':
+ mbrfile += "gptmbr.bin"
+ else:
+ mbrfile += "mbr.bin"
+
+ if not os.path.exists(mbrfile):
+ msger.error("Couldn't find %s. If using the -e option, do you have the right MACHINE set in local.conf? If not, is the bootimg_dir path correct?" % mbrfile)
+
+ full_path = cr._full_path(workdir, disk_name, "direct")
+ msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
+ % (disk_name, full_path, disk['min_size']))
+
+ rc = runner.show(['dd', 'if=%s' % mbrfile,
+ 'of=%s' % full_path, 'conv=notrunc'])
+ if rc != 0:
+ raise MountError("Unable to set MBR to %s" % full_path)
+
+ @classmethod
+ def do_configure_partition(self, part, cr, cr_workdir, oe_builddir,
+ bootimg_dir, kernel_dir, native_sysroot):
+ """
+ Called before do_prepare_partition(), creates syslinux config
+ """
+ hdddir = "%s/hdd/boot" % cr_workdir
+ rm_cmd = "rm -rf " + cr_workdir
+ exec_cmd(rm_cmd)
+
+ install_cmd = "install -d %s" % hdddir
+ tmp = exec_cmd(install_cmd)
+
+ splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg")
+ if os.path.exists(splash):
+ splashline = "menu background splash.jpg"
+ else:
+ splashline = ""
+
+ (rootdev, root_part_uuid) = cr._get_boot_config()
+ options = cr.ks.handler.bootloader.appendLine
+
+ syslinux_conf = ""
+ syslinux_conf += "PROMPT 0\n"
+ timeout = kickstart.get_timeout(cr.ks)
+ if not timeout:
+ timeout = 0
+ syslinux_conf += "TIMEOUT " + str(timeout) + "\n"
+ syslinux_conf += "\n"
+ syslinux_conf += "ALLOWOPTIONS 1\n"
+ syslinux_conf += "SERIAL 0 115200\n"
+ syslinux_conf += "\n"
+ if splashline:
+ syslinux_conf += "%s\n" % splashline
+ syslinux_conf += "DEFAULT boot\n"
+ syslinux_conf += "LABEL boot\n"
+
+ kernel = "/vmlinuz"
+ syslinux_conf += "KERNEL " + kernel + "\n"
+
+ if cr._ptable_format == 'msdos':
+ rootstr = rootdev
+ else:
+ if not root_part_uuid:
+ raise MountError("Cannot find the root GPT partition UUID")
+ rootstr = "PARTUUID=%s" % root_part_uuid
+
+ syslinux_conf += "APPEND label=boot root=%s %s\n" % (rootstr, options)
+
+ msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \
+ % cr_workdir)
+ cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w")
+ cfg.write(syslinux_conf)
+ cfg.close()
+
+ @classmethod
+ def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
+ kernel_dir, native_sysroot):
+ """
+ Called to do the actual content population for a partition i.e. it
+ 'prepares' the partition to be incorporated into the image.
+ In this case, prepare content for legacy bios boot partition.
+ """
+ if not bootimg_dir:
+ bootimg_dir = get_bitbake_var("STAGING_DATADIR")
+ if not bootimg_dir:
+ msger.error("Couldn't find STAGING_DATADIR, exiting\n")
+ # just so the result notes display it
+ cr.bootimg_dir = bootimg_dir
+
+ 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]
+
+ part.size = bootimg_size
+ part.source_file = bootimg
+
+
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/7] wic: Hook up BootimgEFIPlugin and BootimgPcbiosPlugin plugins
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
` (4 preceding siblings ...)
2014-02-04 1:16 ` [PATCH 5/7] wic: Add BootimgEFIPlugin and BootimgPcbiosPlugin Tom Zanussi
@ 2014-02-04 1:16 ` Tom Zanussi
2014-02-04 1:17 ` [PATCH 7/7] wic: Hook up --debug option Tom Zanussi
6 siblings, 0 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:16 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
Remove all the Wic_PartData and DirectImageCreator code now
implemented by the BootimgEFIPlugin and BootimgPcbiosPlugin plugins,
as well as all the special-cased boot_type code, significantly
cleaning up the code.
Replace the calling code with general-purpose plugin invocations, in
essence calling the appropriate implementations at run-time based on
the --source value in effect.
Change the directdisk.wks and mkefidisk.wks scripts to make use of the
new plugins.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
scripts/lib/image/canned-wks/directdisk.wks | 2 +-
scripts/lib/image/canned-wks/mkefidisk.wks | 2 +-
scripts/lib/mic/imager/direct.py | 194 +++++----------------
.../lib/mic/kickstart/custom_commands/partition.py | 155 +++++-----------
scripts/lib/mic/plugins/source/bootimg-efi.py | 6 +-
scripts/lib/mic/plugins/source/bootimg-pcbios.py | 6 +-
6 files changed, 86 insertions(+), 279 deletions(-)
diff --git a/scripts/lib/image/canned-wks/directdisk.wks b/scripts/lib/image/canned-wks/directdisk.wks
index d54b382..397a929 100644
--- a/scripts/lib/image/canned-wks/directdisk.wks
+++ b/scripts/lib/image/canned-wks/directdisk.wks
@@ -3,7 +3,7 @@
# can directly dd to boot media.
-part /boot --source bootimg --ondisk sda --fstype=msdos --label boot --active --align 1024
+part /boot --source bootimg-pcbios --ondisk sda --fstype=msdos --label boot --active --align 1024
part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024
bootloader --timeout=0 --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0"
diff --git a/scripts/lib/image/canned-wks/mkefidisk.wks b/scripts/lib/image/canned-wks/mkefidisk.wks
index 8a3e1f6..e976bc8 100644
--- a/scripts/lib/image/canned-wks/mkefidisk.wks
+++ b/scripts/lib/image/canned-wks/mkefidisk.wks
@@ -2,7 +2,7 @@
# long-description: Creates a partitioned EFI disk image that the user
# can directly dd to boot media.
-part /boot --source bootimg --ondisk sda --fstype=efi --label msdos --active --align 1024
+part /boot --source bootimg-efi --ondisk sda --fstype=msdos --label msdos --active --align 1024
part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024
diff --git a/scripts/lib/mic/imager/direct.py b/scripts/lib/mic/imager/direct.py
index 3827eb8..f8c300c 100644
--- a/scripts/lib/mic/imager/direct.py
+++ b/scripts/lib/mic/imager/direct.py
@@ -35,6 +35,11 @@ from mic.utils.partitionedfs import PartitionedMount
from mic.utils.errors import CreatorError, MountError
from mic.imager.baseimager import BaseImageCreator
from mic.utils.oe.misc import *
+from mic.plugin import pluginmgr
+
+disk_methods = {
+ "do_install_disk":None,
+}
class DirectImageCreator(BaseImageCreator):
"""
@@ -78,7 +83,6 @@ class DirectImageCreator(BaseImageCreator):
self.native_sysroot = native_sysroot
self.hdddir = hdddir
self.staging_data_dir = staging_data_dir
- self.boot_type = ""
def __write_fstab(self):
"""overriden to generate fstab (temporarily) in rootfs. This
@@ -101,7 +105,7 @@ class DirectImageCreator(BaseImageCreator):
def _update_fstab(self, fstab_lines, parts):
"""Assume partition order same as in wks"""
for num, p in enumerate(parts, 1):
- if p.mountpoint == "/" or p.mountpoint == "/boot":
+ if not p.mountpoint or p.mountpoint == "/" or p.mountpoint == "/boot":
continue
if self._ptable_format == 'msdos' and num > 3:
device_name = "/dev/" + p.disk + str(num + 1)
@@ -132,6 +136,15 @@ class DirectImageCreator(BaseImageCreator):
return fstab_contents
+ def set_bootimg_dir(self, bootimg_dir):
+ """
+ Accessor for bootimg_dir, the actual location used for the source
+ of the bootimg. Should be set by source plugins (only if they
+ change the default bootimg source) so the correct info gets
+ displayed for print_outimage_info().
+ """
+ self.bootimg_dir = bootimg_dir
+
def _get_parts(self):
if not self.ks:
raise CreatorError("Failed to get partition info, "
@@ -182,19 +195,18 @@ class DirectImageCreator(BaseImageCreator):
""" Construct full file path to a file we generate. """
return os.path.join(path, self._full_name(name, extention))
- def get_boot_type(self):
- """ Determine the boot type from fstype and mountpoint. """
- parts = self._get_parts()
-
- boot_type = ""
-
- for p in parts:
- if p.mountpoint == "/boot":
- if p.fstype == "msdos":
- boot_type = "pcbios"
- else:
- boot_type = p.fstype
- return boot_type
+ def get_default_source_plugin(self):
+ """
+ The default source plugin i.e. the plugin that's consulted for
+ overall image generation tasks outside of any particular
+ partition. For convenience, we just hang it off the
+ bootloader handler since it's the one non-partition object in
+ any setup. By default the default plugin is set to the same
+ plugin as the /boot partition; since we hang it off the
+ bootloader object, the default can be explicitly set using the
+ --source bootloader param.
+ """
+ return self.ks.handler.bootloader.source
#
# Actual implemention
@@ -231,25 +243,7 @@ class DirectImageCreator(BaseImageCreator):
if not self.ks.handler.bootloader.source and p.mountpoint == "/boot":
self.ks.handler.bootloader.source = p.source
- self.boot_type = self.get_boot_type()
-
- if not self.bootimg_dir:
- if self.boot_type == "pcbios":
- self.bootimg_dir = self.staging_data_dir
- elif self.boot_type == "efi":
- self.bootimg_dir = self.hdddir
-
- if self.boot_type == "pcbios":
- self._create_syslinux_config()
- elif self.boot_type == "efi":
- self._create_grubefi_config()
- else:
- raise CreatorError("Failed to detect boot type (no /boot partition?), "
- "please check your kickstart setting.")
-
for p in parts:
- if p.fstype == "efi":
- p.fstype = "msdos"
# need to create the filesystems in order to get their
# sizes before we can add them and do the layout.
# PartitionedMount.mount() actually calls __format_disks()
@@ -266,9 +260,8 @@ class DirectImageCreator(BaseImageCreator):
# when/if we need to actually do package selection we
# should modify things to use those objects, but for now
# we can avoid that.
- p.prepare(self.workdir, self.oe_builddir, self.boot_type,
- self.rootfs_dir, self.bootimg_dir, self.kernel_dir,
- self.native_sysroot)
+ p.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir,
+ self.bootimg_dir, self.kernel_dir, self.native_sysroot)
self.__instimage.add_partition(int(p.size),
p.disk,
@@ -311,8 +304,16 @@ class DirectImageCreator(BaseImageCreator):
For now, it just prepares the image to be bootable by e.g.
creating and installing a bootloader configuration.
"""
- if self.boot_type == "pcbios":
- self._install_syslinux()
+ source_plugin = self.get_default_source_plugin()
+ if source_plugin:
+ self._source_methods = pluginmgr.get_source_plugin_methods(source_plugin, disk_methods)
+ for disk_name, disk in self.__instimage.disks.items():
+ self._source_methods["do_install_disk"](disk, disk_name, self,
+ self.workdir,
+ self.oe_builddir,
+ self.bootimg_dir,
+ self.kernel_dir,
+ self.native_sysroot)
def print_outimage_info(self):
"""
@@ -352,123 +353,6 @@ class DirectImageCreator(BaseImageCreator):
return (rootdev, root_part_uuid)
- def _create_syslinux_config(self):
- hdddir = "%s/hdd/boot" % self.workdir
- rm_cmd = "rm -rf " + self.workdir
- exec_cmd(rm_cmd)
-
- install_cmd = "install -d %s" % hdddir
- tmp = exec_cmd(install_cmd)
-
- splash = os.path.join(self.workdir, "/hdd/boot/splash.jpg")
- if os.path.exists(splash):
- splashline = "menu background splash.jpg"
- else:
- splashline = ""
-
- (rootdev, root_part_uuid) = self._get_boot_config()
- options = self.ks.handler.bootloader.appendLine
-
- syslinux_conf = ""
- syslinux_conf += "PROMPT 0\n"
- timeout = kickstart.get_timeout(self.ks)
- if not timeout:
- timeout = 0
- syslinux_conf += "TIMEOUT " + str(timeout) + "\n"
- syslinux_conf += "\n"
- syslinux_conf += "ALLOWOPTIONS 1\n"
- syslinux_conf += "SERIAL 0 115200\n"
- syslinux_conf += "\n"
- if splashline:
- syslinux_conf += "%s\n" % splashline
- syslinux_conf += "DEFAULT boot\n"
- syslinux_conf += "LABEL boot\n"
-
- kernel = "/vmlinuz"
- syslinux_conf += "KERNEL " + kernel + "\n"
-
- if self._ptable_format == 'msdos':
- rootstr = rootdev
- else:
- if not root_part_uuid:
- raise MountError("Cannot find the root GPT partition UUID")
- rootstr = "PARTUUID=%s" % root_part_uuid
-
- syslinux_conf += "APPEND label=boot root=%s %s\n" % (rootstr, options)
-
- msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \
- % self.workdir)
- cfg = open("%s/hdd/boot/syslinux.cfg" % self.workdir, "w")
- cfg.write(syslinux_conf)
- cfg.close()
-
- def _create_grubefi_config(self):
- hdddir = "%s/hdd/boot" % self.workdir
- rm_cmd = "rm -rf %s" % self.workdir
- exec_cmd(rm_cmd)
-
- install_cmd = "install -d %s/EFI/BOOT" % hdddir
- tmp = exec_cmd(install_cmd)
-
- splash = os.path.join(self.workdir, "/EFI/boot/splash.jpg")
- if os.path.exists(splash):
- splashline = "menu background splash.jpg"
- else:
- splashline = ""
-
- (rootdev, root_part_uuid) = self._get_boot_config()
- options = self.ks.handler.bootloader.appendLine
-
- grubefi_conf = ""
- grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n"
- grubefi_conf += "default=boot\n"
- timeout = kickstart.get_timeout(self.ks)
- if not timeout:
- timeout = 0
- grubefi_conf += "timeout=%s\n" % timeout
- grubefi_conf += "menuentry 'boot'{\n"
-
- kernel = "/vmlinuz"
-
- if self._ptable_format == 'msdos':
- rootstr = rootdev
- else:
- if not root_part_uuid:
- raise MountError("Cannot find the root GPT partition UUID")
- rootstr = "PARTUUID=%s" % root_part_uuid
-
- grubefi_conf += "linux %s root=%s rootwait %s\n" \
- % (kernel, rootstr, options)
- grubefi_conf += "}\n"
- if splashline:
- syslinux_conf += "%s\n" % splashline
-
- msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \
- % self.workdir)
- cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % self.workdir, "w")
- cfg.write(grubefi_conf)
- cfg.close()
-
- def _install_syslinux(self):
- mbrfile = "%s/syslinux/" % self.bootimg_dir
- if self._ptable_format == 'gpt':
- mbrfile += "gptmbr.bin"
- else:
- mbrfile += "mbr.bin"
-
- if not os.path.exists(mbrfile):
- msger.error("Couldn't find %s. If using the -e option, do you have the right MACHINE set in local.conf? If not, is the bootimg_dir path correct?" % mbrfile)
-
- for disk_name, disk in self.__instimage.disks.items():
- full_path = self._full_path(self.__imgdir, disk_name, "direct")
- msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
- % (disk_name, full_path, disk['min_size']))
-
- rc = runner.show(['dd', 'if=%s' % mbrfile,
- 'of=%s' % full_path, 'conv=notrunc'])
- if rc != 0:
- raise MountError("Unable to set MBR to %s" % full_path)
-
def _unmount_instroot(self):
if not self.__instimage is None:
try:
diff --git a/scripts/lib/mic/kickstart/custom_commands/partition.py b/scripts/lib/mic/kickstart/custom_commands/partition.py
index fe8e55a..4974a87 100644
--- a/scripts/lib/mic/kickstart/custom_commands/partition.py
+++ b/scripts/lib/mic/kickstart/custom_commands/partition.py
@@ -28,8 +28,14 @@ import shutil
from pykickstart.commands.partition import *
from mic.utils.oe.misc import *
-
from mic.kickstart.custom_commands import *
+from mic.plugin import pluginmgr
+
+partition_methods = {
+ "do_stage_partition":None,
+ "do_prepare_partition":None,
+ "do_configure_partition":None,
+}
class Wic_PartData(Mic_PartData):
removedKeywords = Mic_PartData.removedKeywords
@@ -50,8 +56,22 @@ class Wic_PartData(Mic_PartData):
return retval
- def prepare(self, cr_workdir, oe_builddir, boot_type, rootfs_dir,
- bootimg_dir, kernel_dir, native_sysroot):
+ def set_size(self, size):
+ """
+ Accessor for actual partition size, which must be set by source
+ plugins.
+ """
+ self.size = size
+
+ def set_source_file(self, source_file):
+ """
+ Accessor for source_file, the location of the generated partition
+ image, which must be set by source plugins.
+ """
+ self.source_file = source_file
+
+ def prepare(self, cr, cr_workdir, oe_builddir, rootfs_dir, bootimg_dir,
+ kernel_dir, native_sysroot):
"""
Prepare content for individual partitions, depending on
partition command parameters.
@@ -65,121 +85,24 @@ class Wic_PartData(Mic_PartData):
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"):
+ if 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
+ else:
+ self._source_methods = pluginmgr.get_source_plugin_methods(self.source, partition_methods)
+ self._source_methods["do_configure_partition"](self, cr, cr_workdir,
+ oe_builddir,
+ bootimg_dir,
+ kernel_dir,
+ native_sysroot)
+ self._source_methods["do_stage_partition"](self, cr, cr_workdir,
+ oe_builddir,
+ bootimg_dir, kernel_dir,
+ native_sysroot)
+ self._source_methods["do_prepare_partition"](self, cr, cr_workdir,
+ oe_builddir,
+ bootimg_dir, kernel_dir,
+ native_sysroot)
def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
rootfs_dir):
diff --git a/scripts/lib/mic/plugins/source/bootimg-efi.py b/scripts/lib/mic/plugins/source/bootimg-efi.py
index f2bd071..3e0997b 100644
--- a/scripts/lib/mic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/mic/plugins/source/bootimg-efi.py
@@ -107,7 +107,7 @@ class BootimgEFIPlugin(SourcePlugin):
if not bootimg_dir:
msger.error("Couldn't find HDDDIR, exiting\n")
# just so the result notes display it
- cr.bootimg_dir = bootimg_dir
+ cr.set_bootimg_dir(bootimg_dir)
staging_kernel_dir = kernel_dir
staging_data_dir = bootimg_dir
@@ -155,7 +155,7 @@ class BootimgEFIPlugin(SourcePlugin):
rc, out = exec_cmd(du_cmd)
bootimg_size = out.split()[0]
- part.size = bootimg_size
- part.source_file = bootimg
+ part.set_size(bootimg_size)
+ part.set_source_file(bootimg)
diff --git a/scripts/lib/mic/plugins/source/bootimg-pcbios.py b/scripts/lib/mic/plugins/source/bootimg-pcbios.py
index 1da2a41..3cd446f 100644
--- a/scripts/lib/mic/plugins/source/bootimg-pcbios.py
+++ b/scripts/lib/mic/plugins/source/bootimg-pcbios.py
@@ -135,7 +135,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
if not bootimg_dir:
msger.error("Couldn't find STAGING_DATADIR, exiting\n")
# just so the result notes display it
- cr.bootimg_dir = bootimg_dir
+ cr.set_bootimg_dir(bootimg_dir)
staging_kernel_dir = kernel_dir
staging_data_dir = bootimg_dir
@@ -181,7 +181,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
rc, out = exec_cmd(du_cmd)
bootimg_size = out.split()[0]
- part.size = bootimg_size
- part.source_file = bootimg
+ part.set_size(bootimg_size)
+ part.set_source_file(bootimg)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 7/7] wic: Hook up --debug option
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
` (5 preceding siblings ...)
2014-02-04 1:16 ` [PATCH 6/7] wic: Hook up BootimgEFIPlugin and BootimgPcbiosPlugin plugins Tom Zanussi
@ 2014-02-04 1:17 ` Tom Zanussi
6 siblings, 0 replies; 8+ messages in thread
From: Tom Zanussi @ 2014-02-04 1:17 UTC (permalink / raw)
To: openembedded-core; +Cc: Tom Zanussi
Hook up the existing --debug option to toggle the wic debug loglevel,
which is indispensible when things go wrong, and make it easy to use
from the command-line.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
scripts/lib/image/engine.py | 5 ++++-
scripts/wic | 11 +++--------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/scripts/lib/image/engine.py b/scripts/lib/image/engine.py
index 2dd98b9..6cf6169 100644
--- a/scripts/lib/image/engine.py
+++ b/scripts/lib/image/engine.py
@@ -175,7 +175,7 @@ def list_canned_image_help(scripts_path, fullpath):
def wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, hdddir, staging_data_dir, scripts_path,
- image_output_dir, properties_file, properties=None):
+ image_output_dir, debug, properties_file, properties=None):
"""
Create image
@@ -235,6 +235,9 @@ def wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
direct_args.insert(0, staging_data_dir)
direct_args.insert(0, "direct")
+ if debug:
+ msger.set_loglevel('debug')
+
cr = creator.Creator()
cr.main(direct_args)
diff --git a/scripts/wic b/scripts/wic
index 4ea5569..824acae 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -69,6 +69,8 @@ def wic_create_subcommand(args, usage_str):
action = "store", help = "path to the native sysroot containing the tools to use to build the image")
parser.add_option("-p", "--skip-build-check", dest = "build_check",
action = "store_false", default = True, help = "skip the build check")
+ parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
+ default = False, help = "output debug information")
(options, args) = parser.parse_args(args)
@@ -162,7 +164,7 @@ def wic_create_subcommand(args, usage_str):
wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, hdddir, staging_data_dir, scripts_path,
- image_output_dir, options.properties_file)
+ image_output_dir, options.debug, options.properties_file)
def wic_list_subcommand(args, usage_str):
@@ -203,16 +205,9 @@ def main():
usage = wic_usage)
parser.disable_interspersed_args()
- parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
- default = False, help = "output debug information")
(options, args) = parser.parse_args()
- loglevel = logging.INFO
- if options.debug:
- loglevel = logging.DEBUG
- start_logging(loglevel)
-
if len(args):
if args[0] == "help":
if len(args) == 1:
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-02-04 1:17 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-04 1:16 [PATCH 0/7] wic updates: Initial source plugin implementation Tom Zanussi
2014-02-04 1:16 ` [PATCH 1/7] wic: Move some common items to oe.misc Tom Zanussi
2014-02-04 1:16 ` [PATCH 2/7] wic: Create and use new functions for getting bitbake variables Tom Zanussi
2014-02-04 1:16 ` [PATCH 3/7] wic: Add wic-specific bootloader subclass Tom Zanussi
2014-02-04 1:16 ` [PATCH 4/7] wic: Add SourcePlugin class Tom Zanussi
2014-02-04 1:16 ` [PATCH 5/7] wic: Add BootimgEFIPlugin and BootimgPcbiosPlugin Tom Zanussi
2014-02-04 1:16 ` [PATCH 6/7] wic: Hook up BootimgEFIPlugin and BootimgPcbiosPlugin plugins Tom Zanussi
2014-02-04 1:17 ` [PATCH 7/7] wic: Hook up --debug option Tom Zanussi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox