From 972dcfcdbfe75dcfeb777150c136576cf1a71e99 Mon Sep 17 00:00:00 2001 From: Tudor Florea Date: Fri, 9 Oct 2015 22:59:03 +0200 Subject: initial commit for Enea Linux 5.0 arm Signed-off-by: Tudor Florea --- scripts/lib/wic/plugins/source/bootimg-efi.py | 236 +++++++++++++++++++++ .../lib/wic/plugins/source/bootimg-partition.py | 115 ++++++++++ scripts/lib/wic/plugins/source/bootimg-pcbios.py | 200 +++++++++++++++++ scripts/lib/wic/plugins/source/rootfs.py | 92 ++++++++ scripts/lib/wic/plugins/source/uboot.py | 173 +++++++++++++++ 5 files changed, 816 insertions(+) create mode 100644 scripts/lib/wic/plugins/source/bootimg-efi.py create mode 100644 scripts/lib/wic/plugins/source/bootimg-partition.py create mode 100644 scripts/lib/wic/plugins/source/bootimg-pcbios.py create mode 100644 scripts/lib/wic/plugins/source/rootfs.py create mode 100644 scripts/lib/wic/plugins/source/uboot.py (limited to 'scripts/lib/wic/plugins/source') diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py new file mode 100644 index 0000000000..e4067b6dbf --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-efi.py @@ -0,0 +1,236 @@ +# 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 +# + +import os +import shutil +import re +import tempfile + +from wic import kickstart, msger +from wic.utils import misc, fs_related, errors, runner, cmdln +from wic.conf import configmgr +from wic.plugin import pluginmgr +import wic.imager.direct as direct +from wic.pluginbase import SourcePlugin +from wic.utils.oe.misc import * +from wic.imager.direct import DirectImageCreator + +class BootimgEFIPlugin(SourcePlugin): + name = 'bootimg-efi' + + @classmethod + def do_configure_grubefi(self, hdddir, cr, cr_workdir): + """ + Create loader-specific (grub-efi) config + """ + 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 = "/bzImage" + + if cr._ptable_format == 'msdos': + rootstr = rootdev + else: + raise ImageError("Unsupported partition table format found") + + 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_configure_gummiboot(self, hdddir, cr, cr_workdir): + """ + Create loader-specific (gummiboot) config + """ + install_cmd = "install -d %s/loader" % hdddir + exec_cmd(install_cmd) + + install_cmd = "install -d %s/loader/entries" % hdddir + exec_cmd(install_cmd) + + (rootdev, root_part_uuid) = cr._get_boot_config() + options = cr.ks.handler.bootloader.appendLine + + timeout = kickstart.get_timeout(cr.ks) + if not timeout: + timeout = 0 + + loader_conf = "" + loader_conf += "default boot\n" + loader_conf += "timeout %d\n" % timeout + + msger.debug("Writing gummiboot config %s/hdd/boot/loader/loader.conf" \ + % cr_workdir) + cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w") + cfg.write(loader_conf) + cfg.close() + + kernel = "/bzImage" + + if cr._ptable_format == 'msdos': + rootstr = rootdev + else: + raise ImageError("Unsupported partition table format found") + + boot_conf = "" + boot_conf += "title boot\n" + boot_conf += "linux %s\n" % kernel + boot_conf += "options LABEL=Boot root=%s %s\n" \ + % (rootstr, options) + + msger.debug("Writing gummiboot config %s/hdd/boot/loader/entries/boot.conf" \ + % cr_workdir) + cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") + cfg.write(boot_conf) + cfg.close() + + + @classmethod + def do_configure_partition(self, part, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + native_sysroot): + """ + Called before do_prepare_partition(), creates loader-specific 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 + exec_cmd(install_cmd) + + try: + if source_params['loader'] == 'grub-efi': + self.do_configure_grubefi(hdddir, cr, cr_workdir) + elif source_params['loader'] == 'gummiboot': + self.do_configure_gummiboot(hdddir, cr, cr_workdir) + else: + msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader']) + except KeyError: + msger.error("bootimg-efi requires a loader, none specified") + + + @classmethod + def do_prepare_partition(self, part, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + rootfs_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.set_bootimg_dir(bootimg_dir) + + staging_kernel_dir = kernel_dir + + hdddir = "%s/hdd/boot" % cr_workdir + + install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \ + (staging_kernel_dir, hdddir) + exec_cmd(install_cmd) + + try: + if source_params['loader'] == 'grub-efi': + 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" % (bootimg_dir, hdddir) + exec_cmd(cp_cmd, True) + shutil.move("%s/grub.cfg" % cr_workdir, + "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) + elif source_params['loader'] == 'gummiboot': + cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir) + exec_cmd(cp_cmd, True) + else: + msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader']) + except KeyError: + msger.error("bootimg-efi requires a loader, none specified") + + du_cmd = "du -bks %s" % hdddir + out = exec_cmd(du_cmd) + blocks = int(out.split()[0]) + + extra_blocks = part.get_extra_block_count(blocks) + + if extra_blocks < BOOTDD_EXTRA_SPACE: + extra_blocks = BOOTDD_EXTRA_SPACE + + blocks += extra_blocks + + msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ + (extra_blocks, part.mountpoint, blocks)) + + # 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 + out = exec_cmd(du_cmd) + bootimg_size = out.split()[0] + + part.set_size(bootimg_size) + part.set_source_file(bootimg) diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py new file mode 100644 index 0000000000..564118ad8b --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-partition.py @@ -0,0 +1,115 @@ +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +# +# 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-partition' source plugin class for +# 'wic'. The plugin creates an image of boot partition, copying over +# files listed in IMAGE_BOOT_FILES bitbake variable. +# +# AUTHORS +# Maciej Borzecki +# + +import os +import re + +from wic import msger +from wic.pluginbase import SourcePlugin +from wic.utils.oe.misc import * + +class BootimgPartitionPlugin(SourcePlugin): + name = 'bootimg-partition' + + @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. Do nothing. + """ + pass + + @classmethod + def do_configure_partition(self, part, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + native_sysroot): + """ + Called before do_prepare_partition(). Possibly prepare + configuration files of some sort. + + """ + pass + + @classmethod + def do_prepare_partition(self, part, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + rootfs_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, does the following: + - sets up a vfat partition + - copies all files listed in IMAGE_BOOT_FILES variable + """ + hdddir = "%s/boot" % cr_workdir + rm_cmd = "rm -rf %s" % cr_workdir + exec_cmd(rm_cmd) + + install_cmd = "install -d %s" % hdddir + exec_cmd(install_cmd) + + if not bootimg_dir: + bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") + if not bootimg_dir: + msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n") + + msger.debug('Bootimg dir: %s' % bootimg_dir) + + boot_files = get_bitbake_var("IMAGE_BOOT_FILES") + + if not boot_files: + msger.error('No boot files defined, IMAGE_BOOT_FILES unset') + + msger.debug('Boot files: %s' % boot_files) + + # list of tuples (src_name, dst_name) + deploy_files = [] + for src_entry in re.findall(r'[\w;\-\./]+', boot_files): + if ';' in src_entry: + dst_entry = tuple(src_entry.split(';')) + if not dst_entry[0] or not dst_entry[1]: + msger.error('Malformed boot file entry: %s' % (src_entry)) + else: + dst_entry = (src_entry, src_entry) + + msger.debug('Destination entry: %r' % (dst_entry,)) + deploy_files.append(dst_entry) + + for deploy_entry in deploy_files: + src, dst = deploy_entry + src_path = os.path.join(bootimg_dir, src) + dst_path = os.path.join(hdddir, dst) + + msger.debug('Install %s as %s' % (os.path.basename(src_path), + dst_path)) + install_cmd = "install -m 0644 -D %s %s" \ + % (src_path, dst_path) + exec_cmd(install_cmd) + + msger.debug('Prepare boot partition using rootfs in %s' % (hdddir)) + part.prepare_rootfs(cr_workdir, oe_builddir, hdddir, + native_sysroot) + diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py new file mode 100644 index 0000000000..8a1aca1ad1 --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py @@ -0,0 +1,200 @@ +# 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 +# + +import os +import shutil +import re +import tempfile + +from wic import kickstart, msger +from wic.utils import misc, fs_related, errors, runner, cmdln +from wic.conf import configmgr +from wic.plugin import pluginmgr +import wic.imager.direct as direct +from wic.pluginbase import SourcePlugin +from wic.utils.oe.misc import * +from wic.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 == 'msdos': + 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 ImageError("Unable to set MBR to %s" % full_path) + + @classmethod + def do_configure_partition(self, part, source_params, 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 + 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: + raise ImageError("Unsupported partition table format found") + + 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, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + rootfs_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. + """ + def _has_syslinux(dir): + if dir: + syslinux = "%s/syslinux" % dir + if os.path.exists(syslinux): + return True + return False + + if not _has_syslinux(bootimg_dir): + bootimg_dir = get_bitbake_var("STAGING_DATADIR") + if not bootimg_dir: + msger.error("Couldn't find STAGING_DATADIR, exiting\n") + if not _has_syslinux(bootimg_dir): + msger.error("Please build syslinux first\n") + # just so the result notes display it + cr.set_bootimg_dir(bootimg_dir) + + staging_kernel_dir = kernel_dir + + hdddir = "%s/hdd/boot" % cr_workdir + + install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \ + % (staging_kernel_dir, hdddir) + exec_cmd(install_cmd) + + install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \ + % (bootimg_dir, hdddir) + exec_cmd(install_cmd) + + du_cmd = "du -bks %s" % hdddir + out = exec_cmd(du_cmd) + blocks = int(out.split()[0]) + + extra_blocks = part.get_extra_block_count(blocks) + + if extra_blocks < BOOTDD_EXTRA_SPACE: + extra_blocks = BOOTDD_EXTRA_SPACE + + blocks += extra_blocks + + msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ + (extra_blocks, part.mountpoint, blocks)) + + # 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 + out = exec_cmd(du_cmd) + bootimg_size = out.split()[0] + + part.set_size(bootimg_size) + part.set_source_file(bootimg) + + diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py new file mode 100644 index 0000000000..a432a18705 --- /dev/null +++ b/scripts/lib/wic/plugins/source/rootfs.py @@ -0,0 +1,92 @@ +# 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 'rootfs' source plugin class for 'wic' +# +# AUTHORS +# Tom Zanussi +# Joao Henrique Ferreira de Freitas +# + +import os +import shutil +import re +import tempfile + +from wic import kickstart, msger +from wic.utils import misc, fs_related, errors, runner, cmdln +from wic.conf import configmgr +from wic.plugin import pluginmgr +import wic.imager.direct as direct +from wic.pluginbase import SourcePlugin +from wic.utils.oe.misc import * +from wic.imager.direct import DirectImageCreator + +class RootfsPlugin(SourcePlugin): + name = 'rootfs' + + @staticmethod + def __get_rootfs_dir(rootfs_dir): + if os.path.isdir(rootfs_dir): + return rootfs_dir + + bitbake_env_lines = find_bitbake_env_lines(rootfs_dir) + if not bitbake_env_lines: + msg = "Couldn't get bitbake environment, exiting." + msger.error(msg) + + image_rootfs_dir = find_artifact(bitbake_env_lines, "IMAGE_ROOTFS") + if not os.path.isdir(image_rootfs_dir): + msg = "No valid artifact IMAGE_ROOTFS from image named" + msg += " %s has been found at %s, exiting.\n" % \ + (rootfs_dir, image_rootfs_dir) + msger.error(msg) + + return image_rootfs_dir + + @classmethod + def do_prepare_partition(self, part, source_params, cr, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + krootfs_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 part.rootfs is None: + if not 'ROOTFS_DIR' in krootfs_dir: + msg = "Couldn't find --rootfs-dir, exiting" + msger.error(msg) + 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 + else: + msg = "Couldn't find --rootfs-dir=%s connection" + msg += " or it is not a valid path, exiting" + msger.error(msg % part.rootfs) + + real_rootfs_dir = self.__get_rootfs_dir(rootfs_dir) + + part.set_rootfs(real_rootfs_dir) + part.prepare_rootfs(cr_workdir, oe_builddir, real_rootfs_dir, native_sysroot) + diff --git a/scripts/lib/wic/plugins/source/uboot.py b/scripts/lib/wic/plugins/source/uboot.py new file mode 100644 index 0000000000..57cb3cf8fe --- /dev/null +++ b/scripts/lib/wic/plugins/source/uboot.py @@ -0,0 +1,173 @@ +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +# +# Copyright (c) 2014, Enea AB. +# 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 'uboot' source plugin class for 'wic' +# +# AUTHORS +# Adrian Calianu +# + +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 + +def create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot): + # In order to have a full control over rootfs we will make a local copy under workdir + # and change rootfs_dir to new location. + # In this way we can install more than one ROOTFS_DIRs and/or use + # an empty rootfs to install packages, so a rootfs could be generated only from pkgs + # TBD: create workdir/rootfs ; copy rootfs-> workdir/rootfs; set rootfs=workdir/rootfs + + cr_workdir = os.path.abspath(cr_workdir) + new_rootfs_dir = "%s/rootfs_%s" % (cr_workdir, creator.name) + + rootfs_exists = 1 + if part.rootfs is None: + if not 'ROOTFS_DIR' in krootfs_dir: + msg = "Couldn't find --rootfs-dir, exiting, " + msger.info(msg) + rootfs_exists = 0 + rootfs_dir = krootfs_dir['ROOTFS_DIR'] + creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir + else: + if part.rootfs in krootfs_dir: + rootfs_dir = krootfs_dir[part.rootfs] + creator.rootfs_dir[part.rootfs] = new_rootfs_dir + elif os.path.isdir(part.rootfs): + rootfs_dir = part.rootfs + part.rootfs = new_rootfs_dir + else: + msg = "Couldn't find --rootfs-dir=%s connection" + msg += " or it is not a valid path, exiting" + msger.info(msg % part.rootfs) + rootfs_exists = 0 + creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir + + pseudox = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot + pseudox += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % new_rootfs_dir + pseudox += "export PSEUDO_PASSWD=%s;" % new_rootfs_dir + pseudox += "export PSEUDO_NOSYMLINKEXP=1;" + pseudox += "%s/usr/bin/pseudo " % native_sysroot + + mkdir_cmd = "mkdir %s" % (new_rootfs_dir) + # rc, out = exec_native_cmd(pseudox + mkdir_cmd, native_sysroot) + rc, out = exec_cmd(mkdir_cmd, True) + + if rootfs_exists == 1 and os.path.isdir(rootfs_dir): + defpath = os.environ['PATH'] + os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" + + rootfs_dir = os.path.abspath(rootfs_dir) + + pseudoc = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot + pseudoc += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % rootfs_dir + pseudoc += "export PSEUDO_PASSWD=%s;" % rootfs_dir + pseudoc += "export PSEUDO_NOSYMLINKEXP=1;" + pseudoc += "%s/usr/bin/pseudo " % native_sysroot + + tarc_cmd = "tar cvpf %s/rootfs.tar -C %s ." % (cr_workdir, rootfs_dir) + rc, out = exec_native_cmd(pseudoc + tarc_cmd, native_sysroot) + + tarx_cmd = "tar xpvf %s/rootfs.tar -C %s" % (cr_workdir, new_rootfs_dir) + rc, out = exec_native_cmd(pseudox + tarx_cmd, native_sysroot) + + rm_cmd = "rm %s/rootfs.tar" % cr_workdir + rc, out = exec_cmd(rm_cmd, True) + + os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" + + return new_rootfs_dir + +class UBootPlugin(SourcePlugin): + name = 'uboot' + + @classmethod + def do_install_pkgs(self, part, creator, cr_workdir, oe_builddir, krootfs_dir, + bootimg_dir, kernel_dir, native_sysroot): + """ + Called before all partitions have been prepared and assembled into a + disk image. Intall packages based on wic configuration. + """ + + # set new rootfs_dir + rootfs_dir = create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot) + + # wks file parsing + packages = kickstart.get_packages(creator.ks) + + # wic.conf file parsing = found under 'creator' + local_pkgs_path = creator._local_pkgs_path + repourl = creator.repourl + pkgmgr = creator.pkgmgr_name + + # install packages + if packages and pkgmgr in ["opkg"]: + if len(repourl) > 0 : + part.install_pkgs_ipk(cr_workdir, oe_builddir, rootfs_dir, native_sysroot, + packages, repourl) + else: + msger.error("No packages repository provided in wic.conf") + + @classmethod + def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, + kernel_dir, krootfs_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 part.rootfs is None: + if not 'ROOTFS_DIR' in krootfs_dir: + msg = "Couldn't find --rootfs-dir, exiting" + msger.error(msg) + rootfs_dir = krootfs_dir['ROOTFS_DIR'] + else: + if part.rootfs in krootfs_dir: + rootfs_dir = krootfs_dir[part.rootfs] + elif os.path.isdir(part.rootfs): + rootfs_dir = part.rootfs + else: + msg = "Couldn't find --rootfs-dir=%s connection" + msg += " or it is not a valid path, exiting" + msger.error(msg % part.rootfs) + + part.set_rootfs(rootfs_dir) + + # change partition label wich will reflect into the final rootfs image name + part.label = "%s_%s" % (part.label, cr.name) + + defpath = os.environ['PATH'] + os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" + + part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) + part.prepare_for_uboot(cr.target_arch,cr_workdir, oe_builddir, rootfs_dir, native_sysroot) + + os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" -- cgit v1.2.3-54-g00ecf