diff options
| author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
|---|---|---|
| committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
| commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
| tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /scripts/lib/wic/plugins/source/bootimg-pcbios.py | |
| download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz | |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'scripts/lib/wic/plugins/source/bootimg-pcbios.py')
| -rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-pcbios.py | 200 |
1 files changed, 200 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..8a1aca1ad1 --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py | |||
| @@ -0,0 +1,200 @@ | |||
| 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, source_params, cr, cr_workdir, | ||
| 69 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 70 | native_sysroot): | ||
| 71 | """ | ||
| 72 | Called before do_prepare_partition(), creates syslinux config | ||
| 73 | """ | ||
| 74 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 75 | rm_cmd = "rm -rf " + cr_workdir | ||
| 76 | exec_cmd(rm_cmd) | ||
| 77 | |||
| 78 | install_cmd = "install -d %s" % hdddir | ||
| 79 | exec_cmd(install_cmd) | ||
| 80 | |||
| 81 | splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg") | ||
| 82 | if os.path.exists(splash): | ||
| 83 | splashline = "menu background splash.jpg" | ||
| 84 | else: | ||
| 85 | splashline = "" | ||
| 86 | |||
| 87 | (rootdev, root_part_uuid) = cr._get_boot_config() | ||
| 88 | options = cr.ks.handler.bootloader.appendLine | ||
| 89 | |||
| 90 | syslinux_conf = "" | ||
| 91 | syslinux_conf += "PROMPT 0\n" | ||
| 92 | timeout = kickstart.get_timeout(cr.ks) | ||
| 93 | if not timeout: | ||
| 94 | timeout = 0 | ||
| 95 | syslinux_conf += "TIMEOUT " + str(timeout) + "\n" | ||
| 96 | syslinux_conf += "\n" | ||
| 97 | syslinux_conf += "ALLOWOPTIONS 1\n" | ||
| 98 | syslinux_conf += "SERIAL 0 115200\n" | ||
| 99 | syslinux_conf += "\n" | ||
| 100 | if splashline: | ||
| 101 | syslinux_conf += "%s\n" % splashline | ||
| 102 | syslinux_conf += "DEFAULT boot\n" | ||
| 103 | syslinux_conf += "LABEL boot\n" | ||
| 104 | |||
| 105 | kernel = "/vmlinuz" | ||
| 106 | syslinux_conf += "KERNEL " + kernel + "\n" | ||
| 107 | |||
| 108 | if cr._ptable_format == 'msdos': | ||
| 109 | rootstr = rootdev | ||
| 110 | else: | ||
| 111 | raise ImageError("Unsupported partition table format found") | ||
| 112 | |||
| 113 | syslinux_conf += "APPEND label=boot root=%s %s\n" % (rootstr, options) | ||
| 114 | |||
| 115 | msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \ | ||
| 116 | % cr_workdir) | ||
| 117 | cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") | ||
| 118 | cfg.write(syslinux_conf) | ||
| 119 | cfg.close() | ||
| 120 | |||
| 121 | @classmethod | ||
| 122 | def do_prepare_partition(self, part, source_params, cr, cr_workdir, | ||
| 123 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 124 | rootfs_dir, native_sysroot): | ||
| 125 | """ | ||
| 126 | Called to do the actual content population for a partition i.e. it | ||
| 127 | 'prepares' the partition to be incorporated into the image. | ||
| 128 | In this case, prepare content for legacy bios boot partition. | ||
| 129 | """ | ||
| 130 | def _has_syslinux(dir): | ||
| 131 | if dir: | ||
| 132 | syslinux = "%s/syslinux" % dir | ||
| 133 | if os.path.exists(syslinux): | ||
| 134 | return True | ||
| 135 | return False | ||
| 136 | |||
| 137 | if not _has_syslinux(bootimg_dir): | ||
| 138 | bootimg_dir = get_bitbake_var("STAGING_DATADIR") | ||
| 139 | if not bootimg_dir: | ||
| 140 | msger.error("Couldn't find STAGING_DATADIR, exiting\n") | ||
| 141 | if not _has_syslinux(bootimg_dir): | ||
| 142 | msger.error("Please build syslinux first\n") | ||
| 143 | # just so the result notes display it | ||
| 144 | cr.set_bootimg_dir(bootimg_dir) | ||
| 145 | |||
| 146 | staging_kernel_dir = kernel_dir | ||
| 147 | |||
| 148 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 149 | |||
| 150 | install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \ | ||
| 151 | % (staging_kernel_dir, hdddir) | ||
| 152 | exec_cmd(install_cmd) | ||
| 153 | |||
| 154 | install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \ | ||
| 155 | % (bootimg_dir, hdddir) | ||
| 156 | exec_cmd(install_cmd) | ||
| 157 | |||
| 158 | du_cmd = "du -bks %s" % hdddir | ||
| 159 | out = exec_cmd(du_cmd) | ||
| 160 | blocks = int(out.split()[0]) | ||
| 161 | |||
| 162 | extra_blocks = part.get_extra_block_count(blocks) | ||
| 163 | |||
| 164 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
| 165 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
| 166 | |||
| 167 | blocks += extra_blocks | ||
| 168 | |||
| 169 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | ||
| 170 | (extra_blocks, part.mountpoint, blocks)) | ||
| 171 | |||
| 172 | # Ensure total sectors is an integral number of sectors per | ||
| 173 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 174 | # generate images with 32 sectors per track. This calculation is | ||
| 175 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 176 | blocks += (16 - (blocks % 16)) | ||
| 177 | |||
| 178 | # dosfs image, created by mkdosfs | ||
| 179 | bootimg = "%s/boot.img" % cr_workdir | ||
| 180 | |||
| 181 | dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks) | ||
| 182 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 183 | |||
| 184 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 185 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 186 | |||
| 187 | syslinux_cmd = "syslinux %s" % bootimg | ||
| 188 | exec_native_cmd(syslinux_cmd, native_sysroot) | ||
| 189 | |||
| 190 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 191 | exec_cmd(chmod_cmd) | ||
| 192 | |||
| 193 | du_cmd = "du -Lbms %s" % bootimg | ||
| 194 | out = exec_cmd(du_cmd) | ||
| 195 | bootimg_size = out.split()[0] | ||
| 196 | |||
| 197 | part.set_size(bootimg_size) | ||
| 198 | part.set_source_file(bootimg) | ||
| 199 | |||
| 200 | |||
