diff options
Diffstat (limited to 'scripts/lib/wic/plugins/source/bootimg-pcbios.py')
| -rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-pcbios.py | 190 |
1 files changed, 190 insertions, 0 deletions
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..bd2225eeaf --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py | |||
| @@ -0,0 +1,190 @@ | |||
| 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 wic import kickstart, msger | ||
| 33 | from wic.utils import misc, fs_related, errors, runner, cmdln | ||
| 34 | from wic.conf import configmgr | ||
| 35 | from wic.plugin import pluginmgr | ||
| 36 | import wic.imager.direct as direct | ||
| 37 | from wic.pluginbase import SourcePlugin | ||
| 38 | from wic.utils.oe.misc import * | ||
| 39 | from wic.imager.direct import DirectImageCreator | ||
| 40 | |||
| 41 | class BootimgPcbiosPlugin(SourcePlugin): | ||
| 42 | name = 'bootimg-pcbios' | ||
| 43 | |||
| 44 | @classmethod | ||
| 45 | def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir, | ||
| 46 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 47 | """ | ||
| 48 | Called after all partitions have been prepared and assembled into a | ||
| 49 | disk image. In this case, we install the MBR. | ||
| 50 | """ | ||
| 51 | mbrfile = "%s/syslinux/" % bootimg_dir | ||
| 52 | if cr._ptable_format == 'msdos': | ||
| 53 | mbrfile += "mbr.bin" | ||
| 54 | |||
| 55 | if not os.path.exists(mbrfile): | ||
| 56 | 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) | ||
| 57 | |||
| 58 | full_path = cr._full_path(workdir, disk_name, "direct") | ||
| 59 | msger.debug("Installing MBR on disk %s as %s with size %s bytes" \ | ||
| 60 | % (disk_name, full_path, disk['min_size'])) | ||
| 61 | |||
| 62 | rc = runner.show(['dd', 'if=%s' % mbrfile, | ||
| 63 | 'of=%s' % full_path, 'conv=notrunc']) | ||
| 64 | if rc != 0: | ||
| 65 | raise ImageError("Unable to set MBR to %s" % full_path) | ||
| 66 | |||
| 67 | @classmethod | ||
| 68 | def do_configure_partition(self, part, cr, cr_workdir, oe_builddir, | ||
| 69 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 70 | """ | ||
| 71 | Called before do_prepare_partition(), creates syslinux config | ||
| 72 | """ | ||
| 73 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 74 | rm_cmd = "rm -rf " + cr_workdir | ||
| 75 | exec_cmd(rm_cmd) | ||
| 76 | |||
| 77 | install_cmd = "install -d %s" % hdddir | ||
| 78 | exec_cmd(install_cmd) | ||
| 79 | |||
| 80 | splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg") | ||
| 81 | if os.path.exists(splash): | ||
| 82 | splashline = "menu background splash.jpg" | ||
| 83 | else: | ||
| 84 | splashline = "" | ||
| 85 | |||
| 86 | (rootdev, root_part_uuid) = cr._get_boot_config() | ||
| 87 | options = cr.ks.handler.bootloader.appendLine | ||
| 88 | |||
| 89 | syslinux_conf = "" | ||
| 90 | syslinux_conf += "PROMPT 0\n" | ||
| 91 | timeout = kickstart.get_timeout(cr.ks) | ||
| 92 | if not timeout: | ||
| 93 | timeout = 0 | ||
| 94 | syslinux_conf += "TIMEOUT " + str(timeout) + "\n" | ||
| 95 | syslinux_conf += "\n" | ||
| 96 | syslinux_conf += "ALLOWOPTIONS 1\n" | ||
| 97 | syslinux_conf += "SERIAL 0 115200\n" | ||
| 98 | syslinux_conf += "\n" | ||
| 99 | if splashline: | ||
| 100 | syslinux_conf += "%s\n" % splashline | ||
| 101 | syslinux_conf += "DEFAULT boot\n" | ||
| 102 | syslinux_conf += "LABEL boot\n" | ||
| 103 | |||
| 104 | kernel = "/vmlinuz" | ||
| 105 | syslinux_conf += "KERNEL " + kernel + "\n" | ||
| 106 | |||
| 107 | if cr._ptable_format == 'msdos': | ||
| 108 | rootstr = rootdev | ||
| 109 | else: | ||
| 110 | raise ImageError("Unsupported partition table format found") | ||
| 111 | |||
| 112 | syslinux_conf += "APPEND label=boot root=%s %s\n" % (rootstr, options) | ||
| 113 | |||
| 114 | msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \ | ||
| 115 | % cr_workdir) | ||
| 116 | cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") | ||
| 117 | cfg.write(syslinux_conf) | ||
| 118 | cfg.close() | ||
| 119 | |||
| 120 | @classmethod | ||
| 121 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
| 122 | kernel_dir, rootfs_dir, native_sysroot): | ||
| 123 | """ | ||
| 124 | Called to do the actual content population for a partition i.e. it | ||
| 125 | 'prepares' the partition to be incorporated into the image. | ||
| 126 | In this case, prepare content for legacy bios boot partition. | ||
| 127 | """ | ||
| 128 | if not bootimg_dir: | ||
| 129 | bootimg_dir = get_bitbake_var("STAGING_DATADIR") | ||
| 130 | if not bootimg_dir: | ||
| 131 | msger.error("Couldn't find STAGING_DATADIR, exiting\n") | ||
| 132 | # just so the result notes display it | ||
| 133 | cr.set_bootimg_dir(bootimg_dir) | ||
| 134 | |||
| 135 | staging_kernel_dir = kernel_dir | ||
| 136 | staging_data_dir = bootimg_dir | ||
| 137 | |||
| 138 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 139 | |||
| 140 | install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \ | ||
| 141 | % (staging_kernel_dir, hdddir) | ||
| 142 | exec_cmd(install_cmd) | ||
| 143 | |||
| 144 | install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \ | ||
| 145 | % (staging_data_dir, hdddir) | ||
| 146 | exec_cmd(install_cmd) | ||
| 147 | |||
| 148 | du_cmd = "du -bks %s" % hdddir | ||
| 149 | out = exec_cmd(du_cmd) | ||
| 150 | blocks = int(out.split()[0]) | ||
| 151 | |||
| 152 | extra_blocks = part.get_extra_block_count(blocks) | ||
| 153 | |||
| 154 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
| 155 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
| 156 | |||
| 157 | blocks += extra_blocks | ||
| 158 | |||
| 159 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | ||
| 160 | (extra_blocks, part.mountpoint, blocks)) | ||
| 161 | |||
| 162 | # Ensure total sectors is an integral number of sectors per | ||
| 163 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 164 | # generate images with 32 sectors per track. This calculation is | ||
| 165 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 166 | blocks += (16 - (blocks % 16)) | ||
| 167 | |||
| 168 | # dosfs image, created by mkdosfs | ||
| 169 | bootimg = "%s/boot.img" % cr_workdir | ||
| 170 | |||
| 171 | dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks) | ||
| 172 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 173 | |||
| 174 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 175 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 176 | |||
| 177 | syslinux_cmd = "syslinux %s" % bootimg | ||
| 178 | exec_native_cmd(syslinux_cmd, native_sysroot) | ||
| 179 | |||
| 180 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 181 | exec_cmd(chmod_cmd) | ||
| 182 | |||
| 183 | du_cmd = "du -Lbms %s" % bootimg | ||
| 184 | out = exec_cmd(du_cmd) | ||
| 185 | bootimg_size = out.split()[0] | ||
| 186 | |||
| 187 | part.set_size(bootimg_size) | ||
| 188 | part.set_source_file(bootimg) | ||
| 189 | |||
| 190 | |||
