diff options
Diffstat (limited to 'scripts/lib/mic/plugins/source/bootimg-pcbios.py')
-rw-r--r-- | scripts/lib/mic/plugins/source/bootimg-pcbios.py | 195 |
1 files changed, 195 insertions, 0 deletions
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 | |||