summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/source
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/plugins/source')
-rw-r--r--scripts/lib/wic/plugins/source/bootimg-efi.py166
-rw-r--r--scripts/lib/wic/plugins/source/bootimg-pcbios.py190
-rw-r--r--scripts/lib/wic/plugins/source/rootfs.py91
3 files changed, 447 insertions, 0 deletions
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
new file mode 100644
index 0000000000..53f1782381
--- /dev/null
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -0,0 +1,166 @@
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 wic import kickstart, msger
33from wic.utils import misc, fs_related, errors, runner, cmdln
34from wic.conf import configmgr
35from wic.plugin import pluginmgr
36import wic.imager.direct as direct
37from wic.pluginbase import SourcePlugin
38from wic.utils.oe.misc import *
39from wic.imager.direct import DirectImageCreator
40
41class BootimgEFIPlugin(SourcePlugin):
42 name = 'bootimg-efi'
43
44 @classmethod
45 def do_configure_partition(self, part, cr, cr_workdir, oe_builddir,
46 bootimg_dir, kernel_dir, native_sysroot):
47 """
48 Called before do_prepare_partition(), creates grubefi config
49 """
50 hdddir = "%s/hdd/boot" % cr_workdir
51 rm_cmd = "rm -rf %s" % cr_workdir
52 exec_cmd(rm_cmd)
53
54 install_cmd = "install -d %s/EFI/BOOT" % hdddir
55 exec_cmd(install_cmd)
56
57 splash = os.path.join(cr_workdir, "/EFI/boot/splash.jpg")
58 if os.path.exists(splash):
59 splashline = "menu background splash.jpg"
60 else:
61 splashline = ""
62
63 (rootdev, root_part_uuid) = cr._get_boot_config()
64 options = cr.ks.handler.bootloader.appendLine
65
66 grubefi_conf = ""
67 grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n"
68 grubefi_conf += "default=boot\n"
69 timeout = kickstart.get_timeout(cr.ks)
70 if not timeout:
71 timeout = 0
72 grubefi_conf += "timeout=%s\n" % timeout
73 grubefi_conf += "menuentry 'boot'{\n"
74
75 kernel = "/vmlinuz"
76
77 if cr._ptable_format == 'msdos':
78 rootstr = rootdev
79 else:
80 raise ImageError("Unsupported partition table format found")
81
82 grubefi_conf += "linux %s root=%s rootwait %s\n" \
83 % (kernel, rootstr, options)
84 grubefi_conf += "}\n"
85 if splashline:
86 syslinux_conf += "%s\n" % splashline
87
88 msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \
89 % cr_workdir)
90 cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w")
91 cfg.write(grubefi_conf)
92 cfg.close()
93
94 @classmethod
95 def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
96 kernel_dir, rootfs_dir, native_sysroot):
97 """
98 Called to do the actual content population for a partition i.e. it
99 'prepares' the partition to be incorporated into the image.
100 In this case, prepare content for an EFI (grub) boot partition.
101 """
102 if not bootimg_dir:
103 bootimg_dir = get_bitbake_var("HDDDIR")
104 if not bootimg_dir:
105 msger.error("Couldn't find HDDDIR, exiting\n")
106 # just so the result notes display it
107 cr.set_bootimg_dir(bootimg_dir)
108
109 staging_kernel_dir = kernel_dir
110 staging_data_dir = bootimg_dir
111
112 hdddir = "%s/hdd/boot" % cr_workdir
113
114 install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
115 (staging_kernel_dir, hdddir)
116 exec_cmd(install_cmd)
117
118 shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir,
119 "%s/grub.cfg" % cr_workdir)
120
121 cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (staging_data_dir, hdddir)
122 exec_cmd(cp_cmd, True)
123
124 shutil.move("%s/grub.cfg" % cr_workdir,
125 "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir)
126
127 du_cmd = "du -bks %s" % hdddir
128 out = exec_cmd(du_cmd)
129 blocks = int(out.split()[0])
130
131 extra_blocks = part.get_extra_block_count(blocks)
132
133 if extra_blocks < BOOTDD_EXTRA_SPACE:
134 extra_blocks = BOOTDD_EXTRA_SPACE
135
136 blocks += extra_blocks
137
138 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
139 (extra_blocks, part.mountpoint, blocks))
140
141 # Ensure total sectors is an integral number of sectors per
142 # track or mcopy will complain. Sectors are 512 bytes, and we
143 # generate images with 32 sectors per track. This calculation is
144 # done in blocks, thus the mod by 16 instead of 32.
145 blocks += (16 - (blocks % 16))
146
147 # dosfs image, created by mkdosfs
148 bootimg = "%s/boot.img" % cr_workdir
149
150 dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks)
151 exec_native_cmd(dosfs_cmd, native_sysroot)
152
153 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
154 exec_native_cmd(mcopy_cmd, native_sysroot)
155
156 chmod_cmd = "chmod 644 %s" % bootimg
157 exec_cmd(chmod_cmd)
158
159 du_cmd = "du -Lbms %s" % bootimg
160 out = exec_cmd(du_cmd)
161 bootimg_size = out.split()[0]
162
163 part.set_size(bootimg_size)
164 part.set_source_file(bootimg)
165
166
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
27import os
28import shutil
29import re
30import tempfile
31
32from wic import kickstart, msger
33from wic.utils import misc, fs_related, errors, runner, cmdln
34from wic.conf import configmgr
35from wic.plugin import pluginmgr
36import wic.imager.direct as direct
37from wic.pluginbase import SourcePlugin
38from wic.utils.oe.misc import *
39from wic.imager.direct import DirectImageCreator
40
41class 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
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
new file mode 100644
index 0000000000..919e97e6b6
--- /dev/null
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -0,0 +1,91 @@
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 'rootfs' source plugin class for 'wic'
22#
23# AUTHORS
24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
25# Joao Henrique Ferreira de Freitas <joaohf (at] gmail.com>
26#
27
28import os
29import shutil
30import re
31import tempfile
32
33from wic import kickstart, msger
34from wic.utils import misc, fs_related, errors, runner, cmdln
35from wic.conf import configmgr
36from wic.plugin import pluginmgr
37import wic.imager.direct as direct
38from wic.pluginbase import SourcePlugin
39from wic.utils.oe.misc import *
40from wic.imager.direct import DirectImageCreator
41
42class RootfsPlugin(SourcePlugin):
43 name = 'rootfs'
44
45 @staticmethod
46 def __get_rootfs_dir(rootfs_dir):
47 if os.path.isdir(rootfs_dir):
48 return rootfs_dir
49
50 bitbake_env_lines = find_bitbake_env_lines(rootfs_dir)
51 if not bitbake_env_lines:
52 msg = "Couldn't get bitbake environment, exiting."
53 msger.error(msg)
54
55 image_rootfs_dir = find_artifact(bitbake_env_lines, "IMAGE_ROOTFS")
56 if not os.path.isdir(image_rootfs_dir):
57 msg = "No valid artifact IMAGE_ROOTFS from image named"
58 msg += " %s has been found at %s, exiting.\n" % \
59 (rootfs_dir, image_rootfs_dir)
60 msger.error(msg)
61
62 return image_rootfs_dir
63
64 @classmethod
65 def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
66 kernel_dir, krootfs_dir, native_sysroot):
67 """
68 Called to do the actual content population for a partition i.e. it
69 'prepares' the partition to be incorporated into the image.
70 In this case, prepare content for legacy bios boot partition.
71 """
72 if part.rootfs is None:
73 if not 'ROOTFS_DIR' in krootfs_dir:
74 msg = "Couldn't find --rootfs-dir, exiting"
75 msger.error(msg)
76 rootfs_dir = krootfs_dir['ROOTFS_DIR']
77 else:
78 if part.rootfs in krootfs_dir:
79 rootfs_dir = krootfs_dir[part.rootfs]
80 elif part.rootfs:
81 rootfs_dir = part.rootfs
82 else:
83 msg = "Couldn't find --rootfs-dir=%s connection"
84 msg += " or it is not a valid path, exiting"
85 msger.error(msg % part.rootfs)
86
87 real_rootfs_dir = self.__get_rootfs_dir(rootfs_dir)
88
89 part.set_rootfs(real_rootfs_dir)
90 part.prepare_rootfs(cr_workdir, oe_builddir, real_rootfs_dir, native_sysroot)
91