summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/lib/mic/plugins/source/bootimg-efi.py161
-rw-r--r--scripts/lib/mic/plugins/source/bootimg-pcbios.py187
2 files changed, 348 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
27import os
28import shutil
29import re
30import tempfile
31
32from mic import kickstart, chroot, msger
33from mic.utils import misc, fs_related, errors, runner, cmdln
34from mic.conf import configmgr
35from mic.plugin import pluginmgr
36from mic.utils.partitionedfs import PartitionedMount
37import mic.imager.direct as direct
38from mic.pluginbase import SourcePlugin
39from mic.utils.oe.misc import *
40from mic.imager.direct import DirectImageCreator
41
42class 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
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..1da2a41fa7
--- /dev/null
+++ b/scripts/lib/mic/plugins/source/bootimg-pcbios.py
@@ -0,0 +1,187 @@
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
27import os
28import shutil
29import re
30import tempfile
31
32from mic import kickstart, chroot, msger
33from mic.utils import misc, fs_related, errors, runner, cmdln
34from mic.conf import configmgr
35from mic.plugin import pluginmgr
36from mic.utils.partitionedfs import PartitionedMount
37import mic.imager.direct as direct
38from mic.pluginbase import SourcePlugin
39from mic.utils.oe.misc import *
40from mic.imager.direct import DirectImageCreator
41
42class 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, 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.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 blocks += BOOTDD_EXTRA_SPACE
158
159 # Ensure total sectors is an integral number of sectors per
160 # track or mcopy will complain. Sectors are 512 bytes, and we
161 # generate images with 32 sectors per track. This calculation is
162 # done in blocks, thus the mod by 16 instead of 32.
163 blocks += (16 - (blocks % 16))
164
165 # dosfs image, created by mkdosfs
166 bootimg = "%s/boot.img" % cr_workdir
167
168 dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks)
169 exec_native_cmd(dosfs_cmd, native_sysroot)
170
171 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
172 exec_native_cmd(mcopy_cmd, native_sysroot)
173
174 syslinux_cmd = "syslinux %s" % bootimg
175 exec_native_cmd(syslinux_cmd, native_sysroot)
176
177 chmod_cmd = "chmod 644 %s" % bootimg
178 exec_cmd(chmod_cmd)
179
180 du_cmd = "du -Lbms %s" % bootimg
181 rc, out = exec_cmd(du_cmd)
182 bootimg_size = out.split()[0]
183
184 part.size = bootimg_size
185 part.source_file = bootimg
186
187