diff options
Diffstat (limited to 'scripts/lib/mic/plugins/source/bootimg-efi.py')
-rw-r--r-- | scripts/lib/mic/plugins/source/bootimg-efi.py | 161 |
1 files changed, 161 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..f2bd071aff --- /dev/null +++ b/scripts/lib/mic/plugins/source/bootimg-efi.py | |||
@@ -0,0 +1,161 @@ | |||
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, 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.bootimg_dir = bootimg_dir | ||
111 | |||
112 | staging_kernel_dir = kernel_dir | ||
113 | staging_data_dir = bootimg_dir | ||
114 | |||
115 | hdddir = "%s/hdd" % 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 | blocks += BOOTDD_EXTRA_SPACE | ||
135 | |||
136 | # Ensure total sectors is an integral number of sectors per | ||
137 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
138 | # generate images with 32 sectors per track. This calculation is | ||
139 | # done in blocks, thus the mod by 16 instead of 32. | ||
140 | blocks += (16 - (blocks % 16)) | ||
141 | |||
142 | # dosfs image, created by mkdosfs | ||
143 | bootimg = "%s/boot.img" % cr_workdir | ||
144 | |||
145 | dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks) | ||
146 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
147 | |||
148 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
149 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
150 | |||
151 | chmod_cmd = "chmod 644 %s" % bootimg | ||
152 | exec_cmd(chmod_cmd) | ||
153 | |||
154 | du_cmd = "du -Lbms %s" % bootimg | ||
155 | rc, out = exec_cmd(du_cmd) | ||
156 | bootimg_size = out.split()[0] | ||
157 | |||
158 | part.size = bootimg_size | ||
159 | part.source_file = bootimg | ||
160 | |||
161 | |||