diff options
Diffstat (limited to 'scripts/lib/mic/plugins/source/bootimg-efi.py')
| -rw-r--r-- | scripts/lib/mic/plugins/source/bootimg-efi.py | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/scripts/lib/mic/plugins/source/bootimg-efi.py b/scripts/lib/mic/plugins/source/bootimg-efi.py deleted file mode 100644 index 5b1a5332c4..0000000000 --- a/scripts/lib/mic/plugins/source/bootimg-efi.py +++ /dev/null | |||
| @@ -1,166 +0,0 @@ | |||
| 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, 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 | import mic.imager.direct as direct | ||
| 37 | from mic.pluginbase import SourcePlugin | ||
| 38 | from mic.utils.oe.misc import * | ||
| 39 | from mic.imager.direct import DirectImageCreator | ||
| 40 | |||
| 41 | class BootimgEFIPlugin(SourcePlugin): | ||
| 42 | name = 'bootimg-efi' | ||
| 43 | |||
| 44 | @classmethod | ||
| 45 | def do_configure_partition(self, part, cr, cr_workdir, oe_builddir, | ||
| 46 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 47 | """ | ||
| 48 | Called before do_prepare_partition(), creates grubefi config | ||
| 49 | """ | ||
| 50 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 51 | rm_cmd = "rm -rf %s" % cr_workdir | ||
| 52 | exec_cmd(rm_cmd) | ||
| 53 | |||
| 54 | install_cmd = "install -d %s/EFI/BOOT" % hdddir | ||
| 55 | exec_cmd(install_cmd) | ||
| 56 | |||
| 57 | splash = os.path.join(cr_workdir, "/EFI/boot/splash.jpg") | ||
| 58 | if os.path.exists(splash): | ||
| 59 | splashline = "menu background splash.jpg" | ||
| 60 | else: | ||
| 61 | splashline = "" | ||
| 62 | |||
| 63 | (rootdev, root_part_uuid) = cr._get_boot_config() | ||
| 64 | options = cr.ks.handler.bootloader.appendLine | ||
| 65 | |||
| 66 | grubefi_conf = "" | ||
| 67 | grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n" | ||
| 68 | grubefi_conf += "default=boot\n" | ||
| 69 | timeout = kickstart.get_timeout(cr.ks) | ||
| 70 | if not timeout: | ||
| 71 | timeout = 0 | ||
| 72 | grubefi_conf += "timeout=%s\n" % timeout | ||
| 73 | grubefi_conf += "menuentry 'boot'{\n" | ||
| 74 | |||
| 75 | kernel = "/vmlinuz" | ||
| 76 | |||
| 77 | if cr._ptable_format == 'msdos': | ||
| 78 | rootstr = rootdev | ||
| 79 | else: | ||
| 80 | raise ImageError("Unsupported partition table format found") | ||
| 81 | |||
| 82 | grubefi_conf += "linux %s root=%s rootwait %s\n" \ | ||
| 83 | % (kernel, rootstr, options) | ||
| 84 | grubefi_conf += "}\n" | ||
| 85 | if splashline: | ||
| 86 | syslinux_conf += "%s\n" % splashline | ||
| 87 | |||
| 88 | msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \ | ||
| 89 | % cr_workdir) | ||
| 90 | cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w") | ||
| 91 | cfg.write(grubefi_conf) | ||
| 92 | cfg.close() | ||
| 93 | |||
| 94 | @classmethod | ||
| 95 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
| 96 | kernel_dir, rootfs_dir, native_sysroot): | ||
| 97 | """ | ||
| 98 | Called to do the actual content population for a partition i.e. it | ||
| 99 | 'prepares' the partition to be incorporated into the image. | ||
| 100 | In this case, prepare content for an EFI (grub) boot partition. | ||
| 101 | """ | ||
| 102 | if not bootimg_dir: | ||
| 103 | bootimg_dir = get_bitbake_var("HDDDIR") | ||
| 104 | if not bootimg_dir: | ||
| 105 | msger.error("Couldn't find HDDDIR, exiting\n") | ||
| 106 | # just so the result notes display it | ||
| 107 | cr.set_bootimg_dir(bootimg_dir) | ||
| 108 | |||
| 109 | staging_kernel_dir = kernel_dir | ||
| 110 | staging_data_dir = bootimg_dir | ||
| 111 | |||
| 112 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 113 | |||
| 114 | install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \ | ||
| 115 | (staging_kernel_dir, hdddir) | ||
| 116 | exec_cmd(install_cmd) | ||
| 117 | |||
| 118 | shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, | ||
| 119 | "%s/grub.cfg" % cr_workdir) | ||
| 120 | |||
| 121 | cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (staging_data_dir, hdddir) | ||
| 122 | exec_cmd(cp_cmd, True) | ||
| 123 | |||
| 124 | shutil.move("%s/grub.cfg" % cr_workdir, | ||
| 125 | "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) | ||
| 126 | |||
| 127 | du_cmd = "du -bks %s" % hdddir | ||
| 128 | out = exec_cmd(du_cmd) | ||
| 129 | blocks = int(out.split()[0]) | ||
| 130 | |||
| 131 | extra_blocks = part.get_extra_block_count(blocks) | ||
| 132 | |||
| 133 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
| 134 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
| 135 | |||
| 136 | blocks += extra_blocks | ||
| 137 | |||
| 138 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | ||
| 139 | (extra_blocks, part.mountpoint, blocks)) | ||
| 140 | |||
| 141 | # Ensure total sectors is an integral number of sectors per | ||
| 142 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 143 | # generate images with 32 sectors per track. This calculation is | ||
| 144 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 145 | blocks += (16 - (blocks % 16)) | ||
| 146 | |||
| 147 | # dosfs image, created by mkdosfs | ||
| 148 | bootimg = "%s/boot.img" % cr_workdir | ||
| 149 | |||
| 150 | dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks) | ||
| 151 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 152 | |||
| 153 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 154 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 155 | |||
| 156 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 157 | exec_cmd(chmod_cmd) | ||
| 158 | |||
| 159 | du_cmd = "du -Lbms %s" % bootimg | ||
| 160 | out = exec_cmd(du_cmd) | ||
| 161 | bootimg_size = out.split()[0] | ||
| 162 | |||
| 163 | part.set_size(bootimg_size) | ||
| 164 | part.set_source_file(bootimg) | ||
| 165 | |||
| 166 | |||
