diff options
Diffstat (limited to 'scripts/lib/mic/plugins/source')
| -rw-r--r-- | scripts/lib/mic/plugins/source/bootimg-efi.py | 169 | ||||
| -rw-r--r-- | scripts/lib/mic/plugins/source/bootimg-pcbios.py | 195 | ||||
| -rw-r--r-- | scripts/lib/mic/plugins/source/rootfs.py | 71 | ||||
| -rw-r--r-- | scripts/lib/mic/plugins/source/uboot.py | 173 |
4 files changed, 608 insertions, 0 deletions
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 0000000000..0dd9152b59 --- /dev/null +++ b/scripts/lib/mic/plugins/source/bootimg-efi.py | |||
| @@ -0,0 +1,169 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | # | ||
| 4 | # Copyright (c) 2014, Intel Corporation. | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | # DESCRIPTION | ||
| 21 | # This implements the 'bootimg-efi' source plugin class for 'wic' | ||
| 22 | # | ||
| 23 | # AUTHORS | ||
| 24 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 25 | # | ||
| 26 | |||
| 27 | import os | ||
| 28 | import shutil | ||
| 29 | import re | ||
| 30 | import tempfile | ||
| 31 | |||
| 32 | from mic import kickstart, chroot, msger | ||
| 33 | from mic.utils import misc, fs_related, errors, runner, cmdln | ||
| 34 | from mic.conf import configmgr | ||
| 35 | from mic.plugin import pluginmgr | ||
| 36 | from mic.utils.partitionedfs import PartitionedMount | ||
| 37 | import mic.imager.direct as direct | ||
| 38 | from mic.pluginbase import SourcePlugin | ||
| 39 | from mic.utils.oe.misc import * | ||
| 40 | from mic.imager.direct import DirectImageCreator | ||
| 41 | |||
| 42 | class BootimgEFIPlugin(SourcePlugin): | ||
| 43 | name = 'bootimg-efi' | ||
| 44 | |||
| 45 | @classmethod | ||
| 46 | def do_configure_partition(self, part, cr, cr_workdir, oe_builddir, | ||
| 47 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 48 | """ | ||
| 49 | Called before do_prepare_partition(), creates grubefi config | ||
| 50 | """ | ||
| 51 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 52 | rm_cmd = "rm -rf %s" % cr_workdir | ||
| 53 | exec_cmd(rm_cmd) | ||
| 54 | |||
| 55 | install_cmd = "install -d %s/EFI/BOOT" % hdddir | ||
| 56 | tmp = exec_cmd(install_cmd) | ||
| 57 | |||
| 58 | splash = os.path.join(cr_workdir, "/EFI/boot/splash.jpg") | ||
| 59 | if os.path.exists(splash): | ||
| 60 | splashline = "menu background splash.jpg" | ||
| 61 | else: | ||
| 62 | splashline = "" | ||
| 63 | |||
| 64 | (rootdev, root_part_uuid) = cr._get_boot_config() | ||
| 65 | options = cr.ks.handler.bootloader.appendLine | ||
| 66 | |||
| 67 | grubefi_conf = "" | ||
| 68 | grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n" | ||
| 69 | grubefi_conf += "default=boot\n" | ||
| 70 | timeout = kickstart.get_timeout(cr.ks) | ||
| 71 | if not timeout: | ||
| 72 | timeout = 0 | ||
| 73 | grubefi_conf += "timeout=%s\n" % timeout | ||
| 74 | grubefi_conf += "menuentry 'boot'{\n" | ||
| 75 | |||
| 76 | kernel = "/vmlinuz" | ||
| 77 | |||
| 78 | if cr._ptable_format == 'msdos': | ||
| 79 | rootstr = rootdev | ||
| 80 | else: | ||
| 81 | if not root_part_uuid: | ||
| 82 | raise MountError("Cannot find the root GPT partition UUID") | ||
| 83 | rootstr = "PARTUUID=%s" % root_part_uuid | ||
| 84 | |||
| 85 | grubefi_conf += "linux %s root=%s rootwait %s\n" \ | ||
| 86 | % (kernel, rootstr, options) | ||
| 87 | grubefi_conf += "}\n" | ||
| 88 | if splashline: | ||
| 89 | syslinux_conf += "%s\n" % splashline | ||
| 90 | |||
| 91 | msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \ | ||
| 92 | % cr_workdir) | ||
| 93 | cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w") | ||
| 94 | cfg.write(grubefi_conf) | ||
| 95 | cfg.close() | ||
| 96 | |||
| 97 | @classmethod | ||
| 98 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
| 99 | kernel_dir, rootfs_dir, native_sysroot): | ||
| 100 | """ | ||
| 101 | Called to do the actual content population for a partition i.e. it | ||
| 102 | 'prepares' the partition to be incorporated into the image. | ||
| 103 | In this case, prepare content for an EFI (grub) boot partition. | ||
| 104 | """ | ||
| 105 | if not bootimg_dir: | ||
| 106 | bootimg_dir = get_bitbake_var("HDDDIR") | ||
| 107 | if not bootimg_dir: | ||
| 108 | msger.error("Couldn't find HDDDIR, exiting\n") | ||
| 109 | # just so the result notes display it | ||
| 110 | cr.set_bootimg_dir(bootimg_dir) | ||
| 111 | |||
| 112 | staging_kernel_dir = kernel_dir | ||
| 113 | staging_data_dir = bootimg_dir | ||
| 114 | |||
| 115 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 116 | |||
| 117 | install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \ | ||
| 118 | (staging_kernel_dir, hdddir) | ||
| 119 | tmp = exec_cmd(install_cmd) | ||
| 120 | |||
| 121 | shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, | ||
| 122 | "%s/grub.cfg" % cr_workdir) | ||
| 123 | |||
| 124 | cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (staging_data_dir, hdddir) | ||
| 125 | exec_cmd(cp_cmd, True) | ||
| 126 | |||
| 127 | shutil.move("%s/grub.cfg" % cr_workdir, | ||
| 128 | "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) | ||
| 129 | |||
| 130 | du_cmd = "du -bks %s" % hdddir | ||
| 131 | rc, out = exec_cmd(du_cmd) | ||
| 132 | blocks = int(out.split()[0]) | ||
| 133 | |||
| 134 | extra_blocks = part.get_extra_block_count(blocks) | ||
| 135 | |||
| 136 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
| 137 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
| 138 | |||
| 139 | blocks += extra_blocks | ||
| 140 | |||
| 141 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | ||
| 142 | (extra_blocks, part.mountpoint, blocks)) | ||
| 143 | |||
| 144 | # Ensure total sectors is an integral number of sectors per | ||
| 145 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 146 | # generate images with 32 sectors per track. This calculation is | ||
| 147 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 148 | blocks += (16 - (blocks % 16)) | ||
| 149 | |||
| 150 | # dosfs image, created by mkdosfs | ||
| 151 | bootimg = "%s/boot.img" % cr_workdir | ||
| 152 | |||
| 153 | dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks) | ||
| 154 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 155 | |||
| 156 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 157 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 158 | |||
| 159 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 160 | exec_cmd(chmod_cmd) | ||
| 161 | |||
| 162 | du_cmd = "du -Lbms %s" % bootimg | ||
| 163 | rc, out = exec_cmd(du_cmd) | ||
| 164 | bootimg_size = out.split()[0] | ||
| 165 | |||
| 166 | part.set_size(bootimg_size) | ||
| 167 | part.set_source_file(bootimg) | ||
| 168 | |||
| 169 | |||
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 0000000000..1211e5c93b --- /dev/null +++ b/scripts/lib/mic/plugins/source/bootimg-pcbios.py | |||
| @@ -0,0 +1,195 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | # | ||
| 4 | # Copyright (c) 2014, Intel Corporation. | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | # DESCRIPTION | ||
| 21 | # This implements the 'bootimg-pcbios' source plugin class for 'wic' | ||
| 22 | # | ||
| 23 | # AUTHORS | ||
| 24 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 25 | # | ||
| 26 | |||
| 27 | import os | ||
| 28 | import shutil | ||
| 29 | import re | ||
| 30 | import tempfile | ||
| 31 | |||
| 32 | from mic import kickstart, chroot, msger | ||
| 33 | from mic.utils import misc, fs_related, errors, runner, cmdln | ||
| 34 | from mic.conf import configmgr | ||
| 35 | from mic.plugin import pluginmgr | ||
| 36 | from mic.utils.partitionedfs import PartitionedMount | ||
| 37 | import mic.imager.direct as direct | ||
| 38 | from mic.pluginbase import SourcePlugin | ||
| 39 | from mic.utils.oe.misc import * | ||
| 40 | from mic.imager.direct import DirectImageCreator | ||
| 41 | |||
| 42 | class BootimgPcbiosPlugin(SourcePlugin): | ||
| 43 | name = 'bootimg-pcbios' | ||
| 44 | |||
| 45 | @classmethod | ||
| 46 | def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir, | ||
| 47 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 48 | """ | ||
| 49 | Called after all partitions have been prepared and assembled into a | ||
| 50 | disk image. In this case, we install the MBR. | ||
| 51 | """ | ||
| 52 | mbrfile = "%s/syslinux/" % bootimg_dir | ||
| 53 | if cr._ptable_format == 'gpt': | ||
| 54 | mbrfile += "gptmbr.bin" | ||
| 55 | else: | ||
| 56 | mbrfile += "mbr.bin" | ||
| 57 | |||
| 58 | if not os.path.exists(mbrfile): | ||
| 59 | 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) | ||
| 60 | |||
| 61 | full_path = cr._full_path(workdir, disk_name, "direct") | ||
| 62 | msger.debug("Installing MBR on disk %s as %s with size %s bytes" \ | ||
| 63 | % (disk_name, full_path, disk['min_size'])) | ||
| 64 | |||
| 65 | rc = runner.show(['dd', 'if=%s' % mbrfile, | ||
| 66 | 'of=%s' % full_path, 'conv=notrunc']) | ||
| 67 | if rc != 0: | ||
| 68 | raise MountError("Unable to set MBR to %s" % full_path) | ||
| 69 | |||
| 70 | @classmethod | ||
| 71 | def do_configure_partition(self, part, cr, cr_workdir, oe_builddir, | ||
| 72 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 73 | """ | ||
| 74 | Called before do_prepare_partition(), creates syslinux config | ||
| 75 | """ | ||
| 76 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 77 | rm_cmd = "rm -rf " + cr_workdir | ||
| 78 | exec_cmd(rm_cmd) | ||
| 79 | |||
| 80 | install_cmd = "install -d %s" % hdddir | ||
| 81 | tmp = exec_cmd(install_cmd) | ||
| 82 | |||
| 83 | splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg") | ||
| 84 | if os.path.exists(splash): | ||
| 85 | splashline = "menu background splash.jpg" | ||
| 86 | else: | ||
| 87 | splashline = "" | ||
| 88 | |||
| 89 | (rootdev, root_part_uuid) = cr._get_boot_config() | ||
| 90 | options = cr.ks.handler.bootloader.appendLine | ||
| 91 | |||
| 92 | syslinux_conf = "" | ||
| 93 | syslinux_conf += "PROMPT 0\n" | ||
| 94 | timeout = kickstart.get_timeout(cr.ks) | ||
| 95 | if not timeout: | ||
| 96 | timeout = 0 | ||
| 97 | syslinux_conf += "TIMEOUT " + str(timeout) + "\n" | ||
| 98 | syslinux_conf += "\n" | ||
| 99 | syslinux_conf += "ALLOWOPTIONS 1\n" | ||
| 100 | syslinux_conf += "SERIAL 0 115200\n" | ||
| 101 | syslinux_conf += "\n" | ||
| 102 | if splashline: | ||
| 103 | syslinux_conf += "%s\n" % splashline | ||
| 104 | syslinux_conf += "DEFAULT boot\n" | ||
| 105 | syslinux_conf += "LABEL boot\n" | ||
| 106 | |||
| 107 | kernel = "/vmlinuz" | ||
| 108 | syslinux_conf += "KERNEL " + kernel + "\n" | ||
| 109 | |||
| 110 | if cr._ptable_format == 'msdos': | ||
| 111 | rootstr = rootdev | ||
| 112 | else: | ||
| 113 | if not root_part_uuid: | ||
| 114 | raise MountError("Cannot find the root GPT partition UUID") | ||
| 115 | rootstr = "PARTUUID=%s" % root_part_uuid | ||
| 116 | |||
| 117 | syslinux_conf += "APPEND label=boot root=%s %s\n" % (rootstr, options) | ||
| 118 | |||
| 119 | msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \ | ||
| 120 | % cr_workdir) | ||
| 121 | cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") | ||
| 122 | cfg.write(syslinux_conf) | ||
| 123 | cfg.close() | ||
| 124 | |||
| 125 | @classmethod | ||
| 126 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
| 127 | kernel_dir, rootfs_dir, native_sysroot): | ||
| 128 | """ | ||
| 129 | Called to do the actual content population for a partition i.e. it | ||
| 130 | 'prepares' the partition to be incorporated into the image. | ||
| 131 | In this case, prepare content for legacy bios boot partition. | ||
| 132 | """ | ||
| 133 | if not bootimg_dir: | ||
| 134 | bootimg_dir = get_bitbake_var("STAGING_DATADIR") | ||
| 135 | if not bootimg_dir: | ||
| 136 | msger.error("Couldn't find STAGING_DATADIR, exiting\n") | ||
| 137 | # just so the result notes display it | ||
| 138 | cr.set_bootimg_dir(bootimg_dir) | ||
| 139 | |||
| 140 | staging_kernel_dir = kernel_dir | ||
| 141 | staging_data_dir = bootimg_dir | ||
| 142 | |||
| 143 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 144 | |||
| 145 | install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \ | ||
| 146 | % (staging_kernel_dir, hdddir) | ||
| 147 | tmp = exec_cmd(install_cmd) | ||
| 148 | |||
| 149 | install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \ | ||
| 150 | % (staging_data_dir, hdddir) | ||
| 151 | tmp = exec_cmd(install_cmd) | ||
| 152 | |||
| 153 | du_cmd = "du -bks %s" % hdddir | ||
| 154 | rc, out = exec_cmd(du_cmd) | ||
| 155 | blocks = int(out.split()[0]) | ||
| 156 | |||
| 157 | extra_blocks = part.get_extra_block_count(blocks) | ||
| 158 | |||
| 159 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
| 160 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
| 161 | |||
| 162 | blocks += extra_blocks | ||
| 163 | |||
| 164 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | ||
| 165 | (extra_blocks, part.mountpoint, blocks)) | ||
| 166 | |||
| 167 | # Ensure total sectors is an integral number of sectors per | ||
| 168 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 169 | # generate images with 32 sectors per track. This calculation is | ||
| 170 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 171 | blocks += (16 - (blocks % 16)) | ||
| 172 | |||
| 173 | # dosfs image, created by mkdosfs | ||
| 174 | bootimg = "%s/boot.img" % cr_workdir | ||
| 175 | |||
| 176 | dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks) | ||
| 177 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 178 | |||
| 179 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 180 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 181 | |||
| 182 | syslinux_cmd = "syslinux %s" % bootimg | ||
| 183 | exec_native_cmd(syslinux_cmd, native_sysroot) | ||
| 184 | |||
| 185 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 186 | exec_cmd(chmod_cmd) | ||
| 187 | |||
| 188 | du_cmd = "du -Lbms %s" % bootimg | ||
| 189 | rc, out = exec_cmd(du_cmd) | ||
| 190 | bootimg_size = out.split()[0] | ||
| 191 | |||
| 192 | part.set_size(bootimg_size) | ||
| 193 | part.set_source_file(bootimg) | ||
| 194 | |||
| 195 | |||
diff --git a/scripts/lib/mic/plugins/source/rootfs.py b/scripts/lib/mic/plugins/source/rootfs.py new file mode 100644 index 0000000000..75999e03d2 --- /dev/null +++ b/scripts/lib/mic/plugins/source/rootfs.py | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | # | ||
| 4 | # Copyright (c) 2014, Intel Corporation. | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | # DESCRIPTION | ||
| 21 | # This implements the 'rootfs' source plugin class for 'wic' | ||
| 22 | # | ||
| 23 | # AUTHORS | ||
| 24 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 25 | # Joao Henrique Ferreira de Freitas <joaohf (at] gmail.com> | ||
| 26 | # | ||
| 27 | |||
| 28 | import os | ||
| 29 | import shutil | ||
| 30 | import re | ||
| 31 | import tempfile | ||
| 32 | |||
| 33 | from mic import kickstart, chroot, msger | ||
| 34 | from mic.utils import misc, fs_related, errors, runner, cmdln | ||
| 35 | from mic.conf import configmgr | ||
| 36 | from mic.plugin import pluginmgr | ||
| 37 | from mic.utils.partitionedfs import PartitionedMount | ||
| 38 | import mic.imager.direct as direct | ||
| 39 | from mic.pluginbase import SourcePlugin | ||
| 40 | from mic.utils.oe.misc import * | ||
| 41 | from mic.imager.direct import DirectImageCreator | ||
| 42 | |||
| 43 | class RootfsPlugin(SourcePlugin): | ||
| 44 | name = 'rootfs' | ||
| 45 | |||
| 46 | @classmethod | ||
| 47 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
| 48 | kernel_dir, krootfs_dir, native_sysroot): | ||
| 49 | """ | ||
| 50 | Called to do the actual content population for a partition i.e. it | ||
| 51 | 'prepares' the partition to be incorporated into the image. | ||
| 52 | In this case, prepare content for legacy bios boot partition. | ||
| 53 | """ | ||
| 54 | if part.rootfs is None: | ||
| 55 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
| 56 | msg = "Couldn't find --rootfs-dir, exiting" | ||
| 57 | msger.error(msg) | ||
| 58 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
| 59 | else: | ||
| 60 | if part.rootfs in krootfs_dir: | ||
| 61 | rootfs_dir = krootfs_dir[part.rootfs] | ||
| 62 | elif os.path.isdir(part.rootfs): | ||
| 63 | rootfs_dir = part.rootfs | ||
| 64 | else: | ||
| 65 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
| 66 | msg += " or it is not a valid path, exiting" | ||
| 67 | msger.error(msg % part.rootfs) | ||
| 68 | |||
| 69 | part.set_rootfs(rootfs_dir) | ||
| 70 | part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | ||
| 71 | |||
diff --git a/scripts/lib/mic/plugins/source/uboot.py b/scripts/lib/mic/plugins/source/uboot.py new file mode 100644 index 0000000000..57cb3cf8fe --- /dev/null +++ b/scripts/lib/mic/plugins/source/uboot.py | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | # | ||
| 4 | # Copyright (c) 2014, Enea AB. | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | # DESCRIPTION | ||
| 21 | # This implements the 'uboot' source plugin class for 'wic' | ||
| 22 | # | ||
| 23 | # AUTHORS | ||
| 24 | # Adrian Calianu <adrian.calianu (at] enea.com> | ||
| 25 | # | ||
| 26 | |||
| 27 | import os | ||
| 28 | import shutil | ||
| 29 | import re | ||
| 30 | import tempfile | ||
| 31 | |||
| 32 | from mic import kickstart, chroot, msger | ||
| 33 | from mic.utils import misc, fs_related, errors, runner, cmdln | ||
| 34 | from mic.conf import configmgr | ||
| 35 | from mic.plugin import pluginmgr | ||
| 36 | from mic.utils.partitionedfs import PartitionedMount | ||
| 37 | import mic.imager.direct as direct | ||
| 38 | from mic.pluginbase import SourcePlugin | ||
| 39 | from mic.utils.oe.misc import * | ||
| 40 | from mic.imager.direct import DirectImageCreator | ||
| 41 | |||
| 42 | def create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot): | ||
| 43 | # In order to have a full control over rootfs we will make a local copy under workdir | ||
| 44 | # and change rootfs_dir to new location. | ||
| 45 | # In this way we can install more than one ROOTFS_DIRs and/or use | ||
| 46 | # an empty rootfs to install packages, so a rootfs could be generated only from pkgs | ||
| 47 | # TBD: create workdir/rootfs ; copy rootfs-> workdir/rootfs; set rootfs=workdir/rootfs | ||
| 48 | |||
| 49 | cr_workdir = os.path.abspath(cr_workdir) | ||
| 50 | new_rootfs_dir = "%s/rootfs_%s" % (cr_workdir, creator.name) | ||
| 51 | |||
| 52 | rootfs_exists = 1 | ||
| 53 | if part.rootfs is None: | ||
| 54 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
| 55 | msg = "Couldn't find --rootfs-dir, exiting, " | ||
| 56 | msger.info(msg) | ||
| 57 | rootfs_exists = 0 | ||
| 58 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
| 59 | creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir | ||
| 60 | else: | ||
| 61 | if part.rootfs in krootfs_dir: | ||
| 62 | rootfs_dir = krootfs_dir[part.rootfs] | ||
| 63 | creator.rootfs_dir[part.rootfs] = new_rootfs_dir | ||
| 64 | elif os.path.isdir(part.rootfs): | ||
| 65 | rootfs_dir = part.rootfs | ||
| 66 | part.rootfs = new_rootfs_dir | ||
| 67 | else: | ||
| 68 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
| 69 | msg += " or it is not a valid path, exiting" | ||
| 70 | msger.info(msg % part.rootfs) | ||
| 71 | rootfs_exists = 0 | ||
| 72 | creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir | ||
| 73 | |||
| 74 | pseudox = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot | ||
| 75 | pseudox += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % new_rootfs_dir | ||
| 76 | pseudox += "export PSEUDO_PASSWD=%s;" % new_rootfs_dir | ||
| 77 | pseudox += "export PSEUDO_NOSYMLINKEXP=1;" | ||
| 78 | pseudox += "%s/usr/bin/pseudo " % native_sysroot | ||
| 79 | |||
| 80 | mkdir_cmd = "mkdir %s" % (new_rootfs_dir) | ||
| 81 | # rc, out = exec_native_cmd(pseudox + mkdir_cmd, native_sysroot) | ||
| 82 | rc, out = exec_cmd(mkdir_cmd, True) | ||
| 83 | |||
| 84 | if rootfs_exists == 1 and os.path.isdir(rootfs_dir): | ||
| 85 | defpath = os.environ['PATH'] | ||
| 86 | os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" | ||
| 87 | |||
| 88 | rootfs_dir = os.path.abspath(rootfs_dir) | ||
| 89 | |||
| 90 | pseudoc = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot | ||
| 91 | pseudoc += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % rootfs_dir | ||
| 92 | pseudoc += "export PSEUDO_PASSWD=%s;" % rootfs_dir | ||
| 93 | pseudoc += "export PSEUDO_NOSYMLINKEXP=1;" | ||
| 94 | pseudoc += "%s/usr/bin/pseudo " % native_sysroot | ||
| 95 | |||
| 96 | tarc_cmd = "tar cvpf %s/rootfs.tar -C %s ." % (cr_workdir, rootfs_dir) | ||
| 97 | rc, out = exec_native_cmd(pseudoc + tarc_cmd, native_sysroot) | ||
| 98 | |||
| 99 | tarx_cmd = "tar xpvf %s/rootfs.tar -C %s" % (cr_workdir, new_rootfs_dir) | ||
| 100 | rc, out = exec_native_cmd(pseudox + tarx_cmd, native_sysroot) | ||
| 101 | |||
| 102 | rm_cmd = "rm %s/rootfs.tar" % cr_workdir | ||
| 103 | rc, out = exec_cmd(rm_cmd, True) | ||
| 104 | |||
| 105 | os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" | ||
| 106 | |||
| 107 | return new_rootfs_dir | ||
| 108 | |||
| 109 | class UBootPlugin(SourcePlugin): | ||
| 110 | name = 'uboot' | ||
| 111 | |||
| 112 | @classmethod | ||
| 113 | def do_install_pkgs(self, part, creator, cr_workdir, oe_builddir, krootfs_dir, | ||
| 114 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 115 | """ | ||
| 116 | Called before all partitions have been prepared and assembled into a | ||
| 117 | disk image. Intall packages based on wic configuration. | ||
| 118 | """ | ||
| 119 | |||
| 120 | # set new rootfs_dir | ||
| 121 | rootfs_dir = create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot) | ||
| 122 | |||
| 123 | # wks file parsing | ||
| 124 | packages = kickstart.get_packages(creator.ks) | ||
| 125 | |||
| 126 | # wic.conf file parsing = found under 'creator' | ||
| 127 | local_pkgs_path = creator._local_pkgs_path | ||
| 128 | repourl = creator.repourl | ||
| 129 | pkgmgr = creator.pkgmgr_name | ||
| 130 | |||
| 131 | # install packages | ||
| 132 | if packages and pkgmgr in ["opkg"]: | ||
| 133 | if len(repourl) > 0 : | ||
| 134 | part.install_pkgs_ipk(cr_workdir, oe_builddir, rootfs_dir, native_sysroot, | ||
| 135 | packages, repourl) | ||
| 136 | else: | ||
| 137 | msger.error("No packages repository provided in wic.conf") | ||
| 138 | |||
| 139 | @classmethod | ||
| 140 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
| 141 | kernel_dir, krootfs_dir, native_sysroot): | ||
| 142 | """ | ||
| 143 | Called to do the actual content population for a partition i.e. it | ||
| 144 | 'prepares' the partition to be incorporated into the image. | ||
| 145 | In this case, prepare content for legacy bios boot partition. | ||
| 146 | """ | ||
| 147 | if part.rootfs is None: | ||
| 148 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
| 149 | msg = "Couldn't find --rootfs-dir, exiting" | ||
| 150 | msger.error(msg) | ||
| 151 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
| 152 | else: | ||
| 153 | if part.rootfs in krootfs_dir: | ||
| 154 | rootfs_dir = krootfs_dir[part.rootfs] | ||
| 155 | elif os.path.isdir(part.rootfs): | ||
| 156 | rootfs_dir = part.rootfs | ||
| 157 | else: | ||
| 158 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
| 159 | msg += " or it is not a valid path, exiting" | ||
| 160 | msger.error(msg % part.rootfs) | ||
| 161 | |||
| 162 | part.set_rootfs(rootfs_dir) | ||
| 163 | |||
| 164 | # change partition label wich will reflect into the final rootfs image name | ||
| 165 | part.label = "%s_%s" % (part.label, cr.name) | ||
| 166 | |||
| 167 | defpath = os.environ['PATH'] | ||
| 168 | os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" | ||
| 169 | |||
| 170 | part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | ||
| 171 | part.prepare_for_uboot(cr.target_arch,cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | ||
| 172 | |||
| 173 | os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" | ||
