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 | |
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')
-rw-r--r-- | scripts/lib/wic/plugins/imager/direct_plugin.py | 98 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-efi.py | 236 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-partition.py | 115 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-pcbios.py | 200 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/source/rootfs.py | 92 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/source/uboot.py | 173 |
6 files changed, 914 insertions, 0 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct_plugin.py b/scripts/lib/wic/plugins/imager/direct_plugin.py new file mode 100644 index 0000000000..5601c3f1c9 --- /dev/null +++ b/scripts/lib/wic/plugins/imager/direct_plugin.py | |||
@@ -0,0 +1,98 @@ | |||
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) 2013, 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 'direct' imager 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 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 | |||
37 | import wic.imager.direct as direct | ||
38 | from wic.pluginbase import ImagerPlugin | ||
39 | |||
40 | class DirectPlugin(ImagerPlugin): | ||
41 | name = 'direct' | ||
42 | |||
43 | @classmethod | ||
44 | def __rootfs_dir_to_dict(self, rootfs_dirs): | ||
45 | """ | ||
46 | Gets a string that contain 'connection=dir' splitted by | ||
47 | space and return a dict | ||
48 | """ | ||
49 | krootfs_dir = {} | ||
50 | for rootfs_dir in rootfs_dirs.split(' '): | ||
51 | k, v = rootfs_dir.split('=') | ||
52 | krootfs_dir[k] = v | ||
53 | |||
54 | return krootfs_dir | ||
55 | |||
56 | @classmethod | ||
57 | def do_create(self, subcmd, opts, *args): | ||
58 | """ | ||
59 | Create direct image, called from creator as 'direct' cmd | ||
60 | """ | ||
61 | if len(args) != 7: | ||
62 | raise errors.Usage("Extra arguments given") | ||
63 | |||
64 | native_sysroot = args[0] | ||
65 | kernel_dir = args[1] | ||
66 | bootimg_dir = args[2] | ||
67 | rootfs_dir = args[3] | ||
68 | |||
69 | creatoropts = configmgr.create | ||
70 | ksconf = args[4] | ||
71 | |||
72 | image_output_dir = args[5] | ||
73 | oe_builddir = args[6] | ||
74 | |||
75 | krootfs_dir = self.__rootfs_dir_to_dict(rootfs_dir) | ||
76 | |||
77 | configmgr._ksconf = ksconf | ||
78 | |||
79 | creator = direct.DirectImageCreator(oe_builddir, | ||
80 | image_output_dir, | ||
81 | krootfs_dir, | ||
82 | bootimg_dir, | ||
83 | kernel_dir, | ||
84 | native_sysroot, | ||
85 | creatoropts) | ||
86 | |||
87 | try: | ||
88 | creator.create() | ||
89 | creator.assemble() | ||
90 | creator.finalize() | ||
91 | creator.print_outimage_info() | ||
92 | |||
93 | except errors.CreatorError: | ||
94 | raise | ||
95 | finally: | ||
96 | creator.cleanup() | ||
97 | |||
98 | return 0 | ||
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..e4067b6dbf --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-efi.py | |||
@@ -0,0 +1,236 @@ | |||
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 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 BootimgEFIPlugin(SourcePlugin): | ||
42 | name = 'bootimg-efi' | ||
43 | |||
44 | @classmethod | ||
45 | def do_configure_grubefi(self, hdddir, cr, cr_workdir): | ||
46 | """ | ||
47 | Create loader-specific (grub-efi) config | ||
48 | """ | ||
49 | splash = os.path.join(cr_workdir, "/EFI/boot/splash.jpg") | ||
50 | if os.path.exists(splash): | ||
51 | splashline = "menu background splash.jpg" | ||
52 | else: | ||
53 | splashline = "" | ||
54 | |||
55 | (rootdev, root_part_uuid) = cr._get_boot_config() | ||
56 | options = cr.ks.handler.bootloader.appendLine | ||
57 | |||
58 | grubefi_conf = "" | ||
59 | grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n" | ||
60 | grubefi_conf += "default=boot\n" | ||
61 | timeout = kickstart.get_timeout(cr.ks) | ||
62 | if not timeout: | ||
63 | timeout = 0 | ||
64 | grubefi_conf += "timeout=%s\n" % timeout | ||
65 | grubefi_conf += "menuentry 'boot'{\n" | ||
66 | |||
67 | kernel = "/bzImage" | ||
68 | |||
69 | if cr._ptable_format == 'msdos': | ||
70 | rootstr = rootdev | ||
71 | else: | ||
72 | raise ImageError("Unsupported partition table format found") | ||
73 | |||
74 | grubefi_conf += "linux %s root=%s rootwait %s\n" \ | ||
75 | % (kernel, rootstr, options) | ||
76 | grubefi_conf += "}\n" | ||
77 | if splashline: | ||
78 | syslinux_conf += "%s\n" % splashline | ||
79 | |||
80 | msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \ | ||
81 | % cr_workdir) | ||
82 | cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w") | ||
83 | cfg.write(grubefi_conf) | ||
84 | cfg.close() | ||
85 | |||
86 | @classmethod | ||
87 | def do_configure_gummiboot(self, hdddir, cr, cr_workdir): | ||
88 | """ | ||
89 | Create loader-specific (gummiboot) config | ||
90 | """ | ||
91 | install_cmd = "install -d %s/loader" % hdddir | ||
92 | exec_cmd(install_cmd) | ||
93 | |||
94 | install_cmd = "install -d %s/loader/entries" % hdddir | ||
95 | exec_cmd(install_cmd) | ||
96 | |||
97 | (rootdev, root_part_uuid) = cr._get_boot_config() | ||
98 | options = cr.ks.handler.bootloader.appendLine | ||
99 | |||
100 | timeout = kickstart.get_timeout(cr.ks) | ||
101 | if not timeout: | ||
102 | timeout = 0 | ||
103 | |||
104 | loader_conf = "" | ||
105 | loader_conf += "default boot\n" | ||
106 | loader_conf += "timeout %d\n" % timeout | ||
107 | |||
108 | msger.debug("Writing gummiboot config %s/hdd/boot/loader/loader.conf" \ | ||
109 | % cr_workdir) | ||
110 | cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w") | ||
111 | cfg.write(loader_conf) | ||
112 | cfg.close() | ||
113 | |||
114 | kernel = "/bzImage" | ||
115 | |||
116 | if cr._ptable_format == 'msdos': | ||
117 | rootstr = rootdev | ||
118 | else: | ||
119 | raise ImageError("Unsupported partition table format found") | ||
120 | |||
121 | boot_conf = "" | ||
122 | boot_conf += "title boot\n" | ||
123 | boot_conf += "linux %s\n" % kernel | ||
124 | boot_conf += "options LABEL=Boot root=%s %s\n" \ | ||
125 | % (rootstr, options) | ||
126 | |||
127 | msger.debug("Writing gummiboot config %s/hdd/boot/loader/entries/boot.conf" \ | ||
128 | % cr_workdir) | ||
129 | cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") | ||
130 | cfg.write(boot_conf) | ||
131 | cfg.close() | ||
132 | |||
133 | |||
134 | @classmethod | ||
135 | def do_configure_partition(self, part, source_params, cr, cr_workdir, | ||
136 | oe_builddir, bootimg_dir, kernel_dir, | ||
137 | native_sysroot): | ||
138 | """ | ||
139 | Called before do_prepare_partition(), creates loader-specific config | ||
140 | """ | ||
141 | hdddir = "%s/hdd/boot" % cr_workdir | ||
142 | rm_cmd = "rm -rf %s" % cr_workdir | ||
143 | exec_cmd(rm_cmd) | ||
144 | |||
145 | install_cmd = "install -d %s/EFI/BOOT" % hdddir | ||
146 | exec_cmd(install_cmd) | ||
147 | |||
148 | try: | ||
149 | if source_params['loader'] == 'grub-efi': | ||
150 | self.do_configure_grubefi(hdddir, cr, cr_workdir) | ||
151 | elif source_params['loader'] == 'gummiboot': | ||
152 | self.do_configure_gummiboot(hdddir, cr, cr_workdir) | ||
153 | else: | ||
154 | msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader']) | ||
155 | except KeyError: | ||
156 | msger.error("bootimg-efi requires a loader, none specified") | ||
157 | |||
158 | |||
159 | @classmethod | ||
160 | def do_prepare_partition(self, part, source_params, cr, cr_workdir, | ||
161 | oe_builddir, bootimg_dir, kernel_dir, | ||
162 | rootfs_dir, native_sysroot): | ||
163 | """ | ||
164 | Called to do the actual content population for a partition i.e. it | ||
165 | 'prepares' the partition to be incorporated into the image. | ||
166 | In this case, prepare content for an EFI (grub) boot partition. | ||
167 | """ | ||
168 | if not bootimg_dir: | ||
169 | bootimg_dir = get_bitbake_var("HDDDIR") | ||
170 | if not bootimg_dir: | ||
171 | msger.error("Couldn't find HDDDIR, exiting\n") | ||
172 | # just so the result notes display it | ||
173 | cr.set_bootimg_dir(bootimg_dir) | ||
174 | |||
175 | staging_kernel_dir = kernel_dir | ||
176 | |||
177 | hdddir = "%s/hdd/boot" % cr_workdir | ||
178 | |||
179 | install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \ | ||
180 | (staging_kernel_dir, hdddir) | ||
181 | exec_cmd(install_cmd) | ||
182 | |||
183 | try: | ||
184 | if source_params['loader'] == 'grub-efi': | ||
185 | shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, | ||
186 | "%s/grub.cfg" % cr_workdir) | ||
187 | cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir) | ||
188 | exec_cmd(cp_cmd, True) | ||
189 | shutil.move("%s/grub.cfg" % cr_workdir, | ||
190 | "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) | ||
191 | elif source_params['loader'] == 'gummiboot': | ||
192 | cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir) | ||
193 | exec_cmd(cp_cmd, True) | ||
194 | else: | ||
195 | msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader']) | ||
196 | except KeyError: | ||
197 | msger.error("bootimg-efi requires a loader, none specified") | ||
198 | |||
199 | du_cmd = "du -bks %s" % hdddir | ||
200 | out = exec_cmd(du_cmd) | ||
201 | blocks = int(out.split()[0]) | ||
202 | |||
203 | extra_blocks = part.get_extra_block_count(blocks) | ||
204 | |||
205 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
206 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
207 | |||
208 | blocks += extra_blocks | ||
209 | |||
210 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | ||
211 | (extra_blocks, part.mountpoint, blocks)) | ||
212 | |||
213 | # Ensure total sectors is an integral number of sectors per | ||
214 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
215 | # generate images with 32 sectors per track. This calculation is | ||
216 | # done in blocks, thus the mod by 16 instead of 32. | ||
217 | blocks += (16 - (blocks % 16)) | ||
218 | |||
219 | # dosfs image, created by mkdosfs | ||
220 | bootimg = "%s/boot.img" % cr_workdir | ||
221 | |||
222 | dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks) | ||
223 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
224 | |||
225 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
226 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
227 | |||
228 | chmod_cmd = "chmod 644 %s" % bootimg | ||
229 | exec_cmd(chmod_cmd) | ||
230 | |||
231 | du_cmd = "du -Lbms %s" % bootimg | ||
232 | out = exec_cmd(du_cmd) | ||
233 | bootimg_size = out.split()[0] | ||
234 | |||
235 | part.set_size(bootimg_size) | ||
236 | part.set_source_file(bootimg) | ||
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py new file mode 100644 index 0000000000..564118ad8b --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-partition.py | |||
@@ -0,0 +1,115 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | # | ||
4 | # This program is free software; you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License version 2 as | ||
6 | # published by the Free Software Foundation. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along | ||
14 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
16 | # | ||
17 | # DESCRIPTION | ||
18 | # This implements the 'bootimg-partition' source plugin class for | ||
19 | # 'wic'. The plugin creates an image of boot partition, copying over | ||
20 | # files listed in IMAGE_BOOT_FILES bitbake variable. | ||
21 | # | ||
22 | # AUTHORS | ||
23 | # Maciej Borzecki <maciej.borzecki (at] open-rnd.pl> | ||
24 | # | ||
25 | |||
26 | import os | ||
27 | import re | ||
28 | |||
29 | from wic import msger | ||
30 | from wic.pluginbase import SourcePlugin | ||
31 | from wic.utils.oe.misc import * | ||
32 | |||
33 | class BootimgPartitionPlugin(SourcePlugin): | ||
34 | name = 'bootimg-partition' | ||
35 | |||
36 | @classmethod | ||
37 | def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir, | ||
38 | bootimg_dir, kernel_dir, native_sysroot): | ||
39 | """ | ||
40 | Called after all partitions have been prepared and assembled into a | ||
41 | disk image. Do nothing. | ||
42 | """ | ||
43 | pass | ||
44 | |||
45 | @classmethod | ||
46 | def do_configure_partition(self, part, source_params, cr, cr_workdir, | ||
47 | oe_builddir, bootimg_dir, kernel_dir, | ||
48 | native_sysroot): | ||
49 | """ | ||
50 | Called before do_prepare_partition(). Possibly prepare | ||
51 | configuration files of some sort. | ||
52 | |||
53 | """ | ||
54 | pass | ||
55 | |||
56 | @classmethod | ||
57 | def do_prepare_partition(self, part, source_params, cr, cr_workdir, | ||
58 | oe_builddir, bootimg_dir, kernel_dir, | ||
59 | rootfs_dir, native_sysroot): | ||
60 | """ | ||
61 | Called to do the actual content population for a partition i.e. it | ||
62 | 'prepares' the partition to be incorporated into the image. | ||
63 | In this case, does the following: | ||
64 | - sets up a vfat partition | ||
65 | - copies all files listed in IMAGE_BOOT_FILES variable | ||
66 | """ | ||
67 | hdddir = "%s/boot" % cr_workdir | ||
68 | rm_cmd = "rm -rf %s" % cr_workdir | ||
69 | exec_cmd(rm_cmd) | ||
70 | |||
71 | install_cmd = "install -d %s" % hdddir | ||
72 | exec_cmd(install_cmd) | ||
73 | |||
74 | if not bootimg_dir: | ||
75 | bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
76 | if not bootimg_dir: | ||
77 | msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n") | ||
78 | |||
79 | msger.debug('Bootimg dir: %s' % bootimg_dir) | ||
80 | |||
81 | boot_files = get_bitbake_var("IMAGE_BOOT_FILES") | ||
82 | |||
83 | if not boot_files: | ||
84 | msger.error('No boot files defined, IMAGE_BOOT_FILES unset') | ||
85 | |||
86 | msger.debug('Boot files: %s' % boot_files) | ||
87 | |||
88 | # list of tuples (src_name, dst_name) | ||
89 | deploy_files = [] | ||
90 | for src_entry in re.findall(r'[\w;\-\./]+', boot_files): | ||
91 | if ';' in src_entry: | ||
92 | dst_entry = tuple(src_entry.split(';')) | ||
93 | if not dst_entry[0] or not dst_entry[1]: | ||
94 | msger.error('Malformed boot file entry: %s' % (src_entry)) | ||
95 | else: | ||
96 | dst_entry = (src_entry, src_entry) | ||
97 | |||
98 | msger.debug('Destination entry: %r' % (dst_entry,)) | ||
99 | deploy_files.append(dst_entry) | ||
100 | |||
101 | for deploy_entry in deploy_files: | ||
102 | src, dst = deploy_entry | ||
103 | src_path = os.path.join(bootimg_dir, src) | ||
104 | dst_path = os.path.join(hdddir, dst) | ||
105 | |||
106 | msger.debug('Install %s as %s' % (os.path.basename(src_path), | ||
107 | dst_path)) | ||
108 | install_cmd = "install -m 0644 -D %s %s" \ | ||
109 | % (src_path, dst_path) | ||
110 | exec_cmd(install_cmd) | ||
111 | |||
112 | msger.debug('Prepare boot partition using rootfs in %s' % (hdddir)) | ||
113 | part.prepare_rootfs(cr_workdir, oe_builddir, hdddir, | ||
114 | native_sysroot) | ||
115 | |||
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 | |||
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py new file mode 100644 index 0000000000..a432a18705 --- /dev/null +++ b/scripts/lib/wic/plugins/source/rootfs.py | |||
@@ -0,0 +1,92 @@ | |||
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 | |||
28 | import os | ||
29 | import shutil | ||
30 | import re | ||
31 | import tempfile | ||
32 | |||
33 | from wic import kickstart, msger | ||
34 | from wic.utils import misc, fs_related, errors, runner, cmdln | ||
35 | from wic.conf import configmgr | ||
36 | from wic.plugin import pluginmgr | ||
37 | import wic.imager.direct as direct | ||
38 | from wic.pluginbase import SourcePlugin | ||
39 | from wic.utils.oe.misc import * | ||
40 | from wic.imager.direct import DirectImageCreator | ||
41 | |||
42 | class 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, source_params, cr, cr_workdir, | ||
66 | oe_builddir, bootimg_dir, kernel_dir, | ||
67 | krootfs_dir, native_sysroot): | ||
68 | """ | ||
69 | Called to do the actual content population for a partition i.e. it | ||
70 | 'prepares' the partition to be incorporated into the image. | ||
71 | In this case, prepare content for legacy bios boot partition. | ||
72 | """ | ||
73 | if part.rootfs is None: | ||
74 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
75 | msg = "Couldn't find --rootfs-dir, exiting" | ||
76 | msger.error(msg) | ||
77 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
78 | else: | ||
79 | if part.rootfs in krootfs_dir: | ||
80 | rootfs_dir = krootfs_dir[part.rootfs] | ||
81 | elif part.rootfs: | ||
82 | rootfs_dir = part.rootfs | ||
83 | else: | ||
84 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
85 | msg += " or it is not a valid path, exiting" | ||
86 | msger.error(msg % part.rootfs) | ||
87 | |||
88 | real_rootfs_dir = self.__get_rootfs_dir(rootfs_dir) | ||
89 | |||
90 | part.set_rootfs(real_rootfs_dir) | ||
91 | part.prepare_rootfs(cr_workdir, oe_builddir, real_rootfs_dir, native_sysroot) | ||
92 | |||
diff --git a/scripts/lib/wic/plugins/source/uboot.py b/scripts/lib/wic/plugins/source/uboot.py new file mode 100644 index 0000000000..57cb3cf8fe --- /dev/null +++ b/scripts/lib/wic/plugins/source/uboot.py | |||
@@ -0,0 +1,173 @@ | |||
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, Enea AB. | ||
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 'uboot' source plugin class for 'wic' | ||
22 | # | ||
23 | # AUTHORS | ||
24 | # Adrian Calianu <adrian.calianu (at] enea.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 | def create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot): | ||
43 | # In order to have a full control over rootfs we will make a local copy under workdir | ||
44 | # and change rootfs_dir to new location. | ||
45 | # In this way we can install more than one ROOTFS_DIRs and/or use | ||
46 | # an empty rootfs to install packages, so a rootfs could be generated only from pkgs | ||
47 | # TBD: create workdir/rootfs ; copy rootfs-> workdir/rootfs; set rootfs=workdir/rootfs | ||
48 | |||
49 | cr_workdir = os.path.abspath(cr_workdir) | ||
50 | new_rootfs_dir = "%s/rootfs_%s" % (cr_workdir, creator.name) | ||
51 | |||
52 | rootfs_exists = 1 | ||
53 | if part.rootfs is None: | ||
54 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
55 | msg = "Couldn't find --rootfs-dir, exiting, " | ||
56 | msger.info(msg) | ||
57 | rootfs_exists = 0 | ||
58 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
59 | creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir | ||
60 | else: | ||
61 | if part.rootfs in krootfs_dir: | ||
62 | rootfs_dir = krootfs_dir[part.rootfs] | ||
63 | creator.rootfs_dir[part.rootfs] = new_rootfs_dir | ||
64 | elif os.path.isdir(part.rootfs): | ||
65 | rootfs_dir = part.rootfs | ||
66 | part.rootfs = new_rootfs_dir | ||
67 | else: | ||
68 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
69 | msg += " or it is not a valid path, exiting" | ||
70 | msger.info(msg % part.rootfs) | ||
71 | rootfs_exists = 0 | ||
72 | creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir | ||
73 | |||
74 | pseudox = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot | ||
75 | pseudox += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % new_rootfs_dir | ||
76 | pseudox += "export PSEUDO_PASSWD=%s;" % new_rootfs_dir | ||
77 | pseudox += "export PSEUDO_NOSYMLINKEXP=1;" | ||
78 | pseudox += "%s/usr/bin/pseudo " % native_sysroot | ||
79 | |||
80 | mkdir_cmd = "mkdir %s" % (new_rootfs_dir) | ||
81 | # rc, out = exec_native_cmd(pseudox + mkdir_cmd, native_sysroot) | ||
82 | rc, out = exec_cmd(mkdir_cmd, True) | ||
83 | |||
84 | if rootfs_exists == 1 and os.path.isdir(rootfs_dir): | ||
85 | defpath = os.environ['PATH'] | ||
86 | os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" | ||
87 | |||
88 | rootfs_dir = os.path.abspath(rootfs_dir) | ||
89 | |||
90 | pseudoc = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot | ||
91 | pseudoc += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % rootfs_dir | ||
92 | pseudoc += "export PSEUDO_PASSWD=%s;" % rootfs_dir | ||
93 | pseudoc += "export PSEUDO_NOSYMLINKEXP=1;" | ||
94 | pseudoc += "%s/usr/bin/pseudo " % native_sysroot | ||
95 | |||
96 | tarc_cmd = "tar cvpf %s/rootfs.tar -C %s ." % (cr_workdir, rootfs_dir) | ||
97 | rc, out = exec_native_cmd(pseudoc + tarc_cmd, native_sysroot) | ||
98 | |||
99 | tarx_cmd = "tar xpvf %s/rootfs.tar -C %s" % (cr_workdir, new_rootfs_dir) | ||
100 | rc, out = exec_native_cmd(pseudox + tarx_cmd, native_sysroot) | ||
101 | |||
102 | rm_cmd = "rm %s/rootfs.tar" % cr_workdir | ||
103 | rc, out = exec_cmd(rm_cmd, True) | ||
104 | |||
105 | os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" | ||
106 | |||
107 | return new_rootfs_dir | ||
108 | |||
109 | class UBootPlugin(SourcePlugin): | ||
110 | name = 'uboot' | ||
111 | |||
112 | @classmethod | ||
113 | def do_install_pkgs(self, part, creator, cr_workdir, oe_builddir, krootfs_dir, | ||
114 | bootimg_dir, kernel_dir, native_sysroot): | ||
115 | """ | ||
116 | Called before all partitions have been prepared and assembled into a | ||
117 | disk image. Intall packages based on wic configuration. | ||
118 | """ | ||
119 | |||
120 | # set new rootfs_dir | ||
121 | rootfs_dir = create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot) | ||
122 | |||
123 | # wks file parsing | ||
124 | packages = kickstart.get_packages(creator.ks) | ||
125 | |||
126 | # wic.conf file parsing = found under 'creator' | ||
127 | local_pkgs_path = creator._local_pkgs_path | ||
128 | repourl = creator.repourl | ||
129 | pkgmgr = creator.pkgmgr_name | ||
130 | |||
131 | # install packages | ||
132 | if packages and pkgmgr in ["opkg"]: | ||
133 | if len(repourl) > 0 : | ||
134 | part.install_pkgs_ipk(cr_workdir, oe_builddir, rootfs_dir, native_sysroot, | ||
135 | packages, repourl) | ||
136 | else: | ||
137 | msger.error("No packages repository provided in wic.conf") | ||
138 | |||
139 | @classmethod | ||
140 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
141 | kernel_dir, krootfs_dir, native_sysroot): | ||
142 | """ | ||
143 | Called to do the actual content population for a partition i.e. it | ||
144 | 'prepares' the partition to be incorporated into the image. | ||
145 | In this case, prepare content for legacy bios boot partition. | ||
146 | """ | ||
147 | if part.rootfs is None: | ||
148 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
149 | msg = "Couldn't find --rootfs-dir, exiting" | ||
150 | msger.error(msg) | ||
151 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
152 | else: | ||
153 | if part.rootfs in krootfs_dir: | ||
154 | rootfs_dir = krootfs_dir[part.rootfs] | ||
155 | elif os.path.isdir(part.rootfs): | ||
156 | rootfs_dir = part.rootfs | ||
157 | else: | ||
158 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
159 | msg += " or it is not a valid path, exiting" | ||
160 | msger.error(msg % part.rootfs) | ||
161 | |||
162 | part.set_rootfs(rootfs_dir) | ||
163 | |||
164 | # change partition label wich will reflect into the final rootfs image name | ||
165 | part.label = "%s_%s" % (part.label, cr.name) | ||
166 | |||
167 | defpath = os.environ['PATH'] | ||
168 | os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" | ||
169 | |||
170 | part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | ||
171 | part.prepare_for_uboot(cr.target_arch,cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | ||
172 | |||
173 | os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" | ||