[OE-core] [meta-oe][PATCH rebased] wic: Fix and update rootfs-pcbios-ext plugin
Adrian Freihofer
adrian.freihofer at gmail.com
Thu Mar 9 22:08:44 UTC 2017
Resolves #11003
Adds oe-selftest for rootfs-pcbios-ext plugin
---
.../recipes-test/images/wic-image-single-ext.bb | 13 ++
.../recipes-test/images/wic-image-single-ext.wks | 6 +
meta/lib/oeqa/selftest/wic.py | 21 ++++
.../lib/wic/plugins/source/rootfs_pcbios_ext.py | 137 +++++++++------------
4 files changed, 99 insertions(+), 78 deletions(-)
create mode 100644 meta-selftest/recipes-test/images/wic-image-single-ext.bb
create mode 100644 meta-selftest/recipes-test/images/wic-image-single-ext.wks
diff --git a/meta-selftest/recipes-test/images/wic-image-single-ext.bb b/meta-selftest/recipes-test/images/wic-image-single-ext.bb
new file mode 100644
index 0000000..5bd4b62
--- /dev/null
+++ b/meta-selftest/recipes-test/images/wic-image-single-ext.bb
@@ -0,0 +1,13 @@
+SUMMARY = "An example of partitioned image."
+
+SRC_URI = "file://${FILE_DIRNAME}/${BPN}.wks"
+
+IMAGE_INSTALL = "packagegroup-core-boot ${ROOTFS_PKGMANAGE_BOOTSTRAP}"
+
+IMAGE_FSTYPES = "wic"
+
+DEPENDS = "syslinux syslinux-native e2fsprogs-native"
+
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+inherit image
diff --git a/meta-selftest/recipes-test/images/wic-image-single-ext.wks b/meta-selftest/recipes-test/images/wic-image-single-ext.wks
new file mode 100644
index 0000000..af8d2f5
--- /dev/null
+++ b/meta-selftest/recipes-test/images/wic-image-single-ext.wks
@@ -0,0 +1,6 @@
+# short-description: Example of single ext4 partition
+# long-description: This image contains one singel ext4 partition.
+# created from core-image-minimal and wic-image-single-ext image recipes.
+
+part / --source rootfs-pcbios-ext --ondisk vda --fstype=ext4 --active --label rootfs --align 4096 --size 20
+bootloader --source rootfs-pcbios-ext --timeout=0 --append="rootwait console=tty0 rootfstype=ext4"
diff --git a/meta/lib/oeqa/selftest/wic.py b/meta/lib/oeqa/selftest/wic.py
index dcb88ba..8797dd5 100644
--- a/meta/lib/oeqa/selftest/wic.py
+++ b/meta/lib/oeqa/selftest/wic.py
@@ -561,3 +561,24 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
status, output = qemu.run_serial(cmd)
self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '3')
+
+ def test_single_ext_qemu(self):
+ """Test wic-image-single-ext under qemu"""
+ config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-single-ext"\n'
+ self.append_config(config)
+ self.assertEqual(0, bitbake('wic-image-single-ext').status)
+ self.remove_config(config)
+
+ with runqemu('wic-image-single-ext', ssh=False) as qemu:
+ cmd = "grep '/dev/root / ext4' /proc/mounts"
+ status, output = qemu.run_serial(cmd)
+ self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ self.assertRegex(output, '^/dev/root +/ +ext4.*')
+
+ cmd = "ls /boot"
+ status, output = qemu.run_serial(cmd)
+ self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ self.assertRegex(output, '.*ldlinux.c32.*')
+ self.assertRegex(output, '.*ldlinux.sys.*')
+ self.assertRegex(output, '.*syslinux.cfg.*')
+ self.assertRegex(output, '.*vmlinuz.*')
diff --git a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
index 94f80d0..6008cb3 100644
--- a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
+++ b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
@@ -14,13 +14,22 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
+# DESCRIPTION
+# This plugin creates an ext4 rootfs partition. If the image feature
+# package-management is enabled and even the kernel package needs to be
+# updated on the target device this source plugin might be a good choice.
+# In general a fat boot partition and a second root partition is
+# recommended.
+# Example wks file:
+# part / --source rootfs-pcbios-ext --ondisk sda --fstype=ext4 --active --label rootfs --align 4096 --size 20
+# bootloader --source rootfs-pcbios-ext --timeout=0 --append="rootwait console=ttyS0,115200 rootfstype=ext4"
+#
# AUTHOR
-# Adrian Freihofer <adrian.freihofer (at] neratec.com>
+# Adrian Freihofer <adrian.freihofer (at] gmail.com>
#
import logging
import os
-import re
from wic import WicError
from wic.utils import runner
@@ -29,44 +38,9 @@ from wic.pluginbase import SourcePlugin
logger = logging.getLogger('wic')
-def serial_console_form_kargs(kernel_args):
- """
- Create SERIAL... line from kernel parameters
-
- syslinux needs a line SERIAL port [baudrate [flowcontrol]]
- in the syslinux.cfg file. The config line is generated based
- on kernel boot parameters. The the parameters of the first
- ttyS console are considered for syslinux config.
- @param kernel_args kernel command line
- @return line for syslinux config file e.g. "SERIAL 0 115200"
- """
- syslinux_conf = ""
- for param in kernel_args.split():
- param_match = re.match("console=ttyS([0-9]+),?([0-9]*)([noe]?)([0-9]?)(r?)", param)
- if param_match:
- syslinux_conf += "SERIAL " + param_match.group(1)
- # baudrate
- if param_match.group(2):
- syslinux_conf += " " + param_match.group(2)
- # parity
- if param_match.group(3) and param_match.group(3) != 'n':
- logger.warning("syslinux does not support parity for console. "
- "%s is ignored.", param_match.group(3))
- # number of bits
- if param_match.group(4) and param_match.group(4) != '8':
- logger.warning("syslinux supports 8 bit console configuration "
- "only. %s is ignored.", param_match.group(4))
- # flow control
- if param_match.group(5) and param_match.group(5) != '':
- logger.warning("syslinux console flowcontrol configuration. "
- "%s is ignored.", param_match.group(5))
- break
-
- return syslinux_conf
-
# pylint: disable=no-init
-class RootfsPlugin(SourcePlugin):
+class RootfsPcBoisExtPlugin(SourcePlugin):
"""
Create root partition and install syslinux bootloader
@@ -106,83 +80,90 @@ class RootfsPlugin(SourcePlugin):
# pylint: disable=unused-argument
@classmethod
- def do_configure_partition(cls, part, source_params, image_creator,
- image_creator_workdir, oe_builddir, bootimg_dir,
- kernel_dir, native_sysroot):
+ def do_prepare_partition(cls, part, source_params, image_creator,
+ image_creator_workdir, oe_builddir, bootimg_dir,
+ kernel_dir, krootfs_dir, native_sysroot):
"""
- Creates syslinux config in rootfs directory
+ Creates partition out of rootfs directory
- Called before do_prepare_partition()
+ Prepare content for a rootfs partition i.e. create a partition
+ and fill it from a /rootfs dir.
+ Install syslinux bootloader into root partition image file
"""
bootloader = image_creator.ks.bootloader
+ syslinux_serial = get_bitbake_var('SYSLINUX_SERIAL')
syslinux_conf = ""
syslinux_conf += "PROMPT 0\n"
-
- syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n"
+ if bootloader.timeout is not None:
+ syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n"
syslinux_conf += "ALLOWOPTIONS 1\n"
-
- # Derive SERIAL... line from from kernel boot parameters
- syslinux_conf += serial_console_form_kargs(options) + "\n"
-
+ if syslinux_serial:
+ syslinux_conf += "SERIAL " + syslinux_serial
syslinux_conf += "DEFAULT linux\n"
syslinux_conf += "LABEL linux\n"
- syslinux_conf += " KERNEL /boot/bzImage\n"
+ syslinux_conf += " KERNEL /boot/vmlinuz\n"
syslinux_conf += " APPEND label=boot root=%s %s\n" % \
- (image_creator.rootdev, bootloader.append)
+ (image_creator.rootdev, bootloader.append)
- syslinux_cfg = os.path.join(image_creator.rootfs_dir['ROOTFS_DIR'], "boot", "syslinux.cfg")
- logger.debug("Writing syslinux config %s", syslinux_cfg)
- with open(syslinux_cfg, "w") as cfg:
+ # Write syslinux config file into target sysroot dir
+ tmp_syslinux_cfg_file = os.path.join(image_creator_workdir, "syslinux.cfg")
+ with open(tmp_syslinux_cfg_file, "w") as cfg:
cfg.write(syslinux_conf)
- @classmethod
- def do_prepare_partition(cls, part, source_params, image_creator,
- image_creator_workdir, oe_builddir, bootimg_dir,
- kernel_dir, krootfs_dir, native_sysroot):
- """
- Creates partition out of rootfs directory
+ hdd_boot_dir = os.path.join(image_creator.rootfs_dir['ROOTFS_DIR'], "boot")
+ p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
+ p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
+ "%s/../pseudo" % hdd_boot_dir)
+ p_passwd = os.environ.get("PSEUDO_PASSWD", hdd_boot_dir)
+ p_nosymlinkexp = os.environ.get("PSEUDO_NOSYMLINKEXP", "1")
+ pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
+ pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % p_localstatedir
+ pseudo += "export PSEUDO_PASSWD=%s;" % p_passwd
+ pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp
+ pseudo += "%s/usr/bin/pseudo " % native_sysroot
+
+ install_cmd = "%s install -m 0744 -d %s" % (pseudo, hdd_boot_dir)
+ exec_cmd(install_cmd, as_shell=True)
+ install_cmd = "%s install -m 0644 %s %s" % (pseudo, tmp_syslinux_cfg_file, hdd_boot_dir)
+ exec_cmd(install_cmd, as_shell=True)
+ install_cmd = "%s install -m 0644 %s/bzImage %s/vmlinuz" % (pseudo, kernel_dir, hdd_boot_dir)
+ exec_cmd(install_cmd, as_shell=True)
+
+ os.remove(tmp_syslinux_cfg_file)
- Prepare content for a rootfs partition i.e. create a partition
- and fill it from a /rootfs dir.
- Install syslinux bootloader into root partition image file
- """
def is_exe(exepath):
"""Verify exepath is an executable file"""
return os.path.isfile(exepath) and os.access(exepath, os.X_OK)
- # Make sure syslinux-nomtools is available in native sysroot or fail
+ # Verify syslinux-nomtools is available in native sysroot or fail
native_syslinux_nomtools = os.path.join(native_sysroot, "usr/bin/syslinux-nomtools")
if not is_exe(native_syslinux_nomtools):
- logger.info("building syslinux-native...")
- exec_cmd("bitbake syslinux-native")
- if not is_exe(native_syslinux_nomtools):
- raise WicError("Couldn't find syslinux-nomtools (%s), exiting" %
- native_syslinux_nomtools)
+ raise WicError("Cannot find syslinux-nomtools (%s), exiting" % native_syslinux_nomtools)
- if part.rootfs is None:
- if 'ROOTFS_DIR' not in krootfs_dir:
+ if part.rootfs_dir is None:
+ if not 'ROOTFS_DIR' in krootfs_dir:
raise WicError("Couldn't find --rootfs-dir, exiting")
rootfs_dir = krootfs_dir['ROOTFS_DIR']
else:
- if part.rootfs in krootfs_dir:
- rootfs_dir = krootfs_dir[part.rootfs]
- elif part.rootfs:
- rootfs_dir = part.rootfs
+ if part.rootfs_dir in krootfs_dir:
+ rootfs_dir = krootfs_dir[part.rootfs_dir]
+ elif part.rootfs_dir:
+ rootfs_dir = part.rootfs_dir
else:
raise WicError("Couldn't find --rootfs-dir=%s connection or "
"it is not a valid path, exiting" % part.rootfs)
real_rootfs_dir = cls._get_rootfs_dir(rootfs_dir)
-
part.rootfs_dir = real_rootfs_dir
part.prepare_rootfs(image_creator_workdir, oe_builddir, real_rootfs_dir, native_sysroot)
- # install syslinux into rootfs partition
+ # install syslinux into rootfs partition (add ldlinux.c32 ldlinux.sys)
syslinux_cmd = "syslinux-nomtools -d /boot -i %s" % part.source_file
exec_native_cmd(syslinux_cmd, native_sysroot)
+ # pylint: disable=unused-argument
@classmethod
def do_install_disk(cls, disk, disk_name, image_creator, workdir, oe_builddir,
bootimg_dir, kernel_dir, native_sysroot):
--
2.9.3
More information about the Openembedded-core
mailing list