summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/kickstart/custom_commands/partition.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2013-09-19 04:32:19 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-01 22:56:03 +0100
commit75c143a7aef46ecea07cf33edd2b1a0192e10149 (patch)
treefe0eb61a0dfda72e52b01385129f6282814581b6 /scripts/lib/mic/kickstart/custom_commands/partition.py
parent9fc88f96d40b17c90bac53b90045a87b2d2cff84 (diff)
downloadpoky-75c143a7aef46ecea07cf33edd2b1a0192e10149.tar.gz
wic: Add OpenEmbedded-specific implementation
Reuses the mic/livecd infrastructure but heavily subclasses and modifies it to adapt to the special needs of building images from existing OpenEmbedded build artifacts. In addition to the OE-specific mic objects and modifications to the underlying infrastructure, this adds a mechanism to allow OE kickstart files to be 'canned' and made available to users via the 'wic list images' command. Two initial OE kickstart files have been added as canned .wks files: directdisk, which implements the same thing as the images created by directdisk.bbclass, and mkefidisk, which can essentially be used as a replacement for mkefidisk.sh. Of course, since creation of these images are now driven by .wks files rather than being hard-coded into class files or scripts, they can be easily modified to generate different variations on those images. They also don't require root priveleges, since they don't use mount to create the images. They don't however write to media like mkefidisk.sh does, but rather create images that can be written onto media. (From OE-Core rev: f87acc5e59d3c2c39ff171b5557977dab4c8f4a6) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/kickstart/custom_commands/partition.py')
-rw-r--r--scripts/lib/mic/kickstart/custom_commands/partition.py389
1 files changed, 351 insertions, 38 deletions
diff --git a/scripts/lib/mic/kickstart/custom_commands/partition.py b/scripts/lib/mic/kickstart/custom_commands/partition.py
index 59a87fb486..302cace234 100644
--- a/scripts/lib/mic/kickstart/custom_commands/partition.py
+++ b/scripts/lib/mic/kickstart/custom_commands/partition.py
@@ -1,57 +1,370 @@
1#!/usr/bin/python -tt 1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2# 3#
3# Marko Saukko <marko.saukko@cybercom.com> 4# Copyright (c) 2013, Intel Corporation.
5# All rights reserved.
4# 6#
5# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 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.
6# 10#
7# This copyrighted material is made available to anyone wishing to use, modify, 11# This program is distributed in the hope that it will be useful,
8# copy, or redistribute it subject to the terms and conditions of the GNU 12# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# General Public License v.2. This program is distributed in the hope that it 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the 14# GNU General Public License for more details.
11# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15#
12# See the GNU General Public License for more details. 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 module provides the OpenEmbedded partition object definitions.
22#
23# AUTHORS
24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
13# 25#
14# You should have received a copy of the GNU General Public License along with 26
15# this program; if not, write to the Free Software Foundation, Inc., 51 27import shutil
16# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 28
18from pykickstart.commands.partition import * 29from pykickstart.commands.partition import *
30from mic.utils.oe.misc import *
31
32from mic.kickstart.custom_commands import *
19 33
20class Mic_PartData(FC4_PartData): 34BOOTDD_EXTRA_SPACE = 16384
21 removedKeywords = FC4_PartData.removedKeywords 35
22 removedAttrs = FC4_PartData.removedAttrs 36class Wic_PartData(Mic_PartData):
37 removedKeywords = Mic_PartData.removedKeywords
38 removedAttrs = Mic_PartData.removedAttrs
23 39
24 def __init__(self, *args, **kwargs): 40 def __init__(self, *args, **kwargs):
25 FC4_PartData.__init__(self, *args, **kwargs) 41 Mic_PartData.__init__(self, *args, **kwargs)
26 self.deleteRemovedAttrs() 42 self.deleteRemovedAttrs()
27 self.align = kwargs.get("align", None) 43 self.source = kwargs.get("source", None)
28 self.extopts = kwargs.get("extopts", None) 44 self.source_file = ""
29 self.part_type = kwargs.get("part_type", None) 45 self.size = 0
30 46
31 def _getArgsAsStr(self): 47 def _getArgsAsStr(self):
32 retval = FC4_PartData._getArgsAsStr(self) 48 retval = Mic_PartData._getArgsAsStr(self)
33 49
34 if self.align: 50 if self.source:
35 retval += " --align" 51 retval += " --source=%s" % self.source
36 if self.extopts:
37 retval += " --extoptions=%s" % self.extopts
38 if self.part_type:
39 retval += " --part-type=%s" % self.part_type
40 52
41 return retval 53 return retval
42 54
43class Mic_Partition(FC4_Partition): 55 def prepare(self, cr_workdir, oe_builddir, boot_type, rootfs_dir,
44 removedKeywords = FC4_Partition.removedKeywords 56 bootimg_dir, kernel_dir, native_sysroot):
45 removedAttrs = FC4_Partition.removedAttrs 57 """
58 Prepare content for individual partitions, depending on
59 partition command parameters.
60 """
61 if not self.source:
62 if self.fstype and self.fstype == "swap":
63 self.prepare_swap_partition(cr_workdir, oe_builddir,
64 native_sysroot)
65 elif self.fstype:
66 self.prepare_empty_partition(cr_workdir, oe_builddir,
67 native_sysroot)
68 return
69
70 if self.source == "bootimg" and boot_type == "pcbios":
71 self.prepare_bootimg_pcbios(cr_workdir, oe_builddir, bootimg_dir,
72 kernel_dir, native_sysroot)
73 elif self.source == "bootimg" and boot_type == "efi":
74 self.prepare_bootimg_efi(cr_workdir, oe_builddir, bootimg_dir,
75 kernel_dir, native_sysroot)
76 elif self.source.startswith("rootfs"):
77 self.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir,
78 native_sysroot)
79
80 def prepare_bootimg_pcbios(self, cr_workdir, oe_builddir, bootimg_dir,
81 kernel_dir, native_sysroot):
82 """
83 Prepare content for a legacy bios boot partition.
84 """
85 staging_kernel_dir = kernel_dir
86 staging_data_dir = bootimg_dir
87
88 hdddir = "%s/hdd/boot" % cr_workdir
89
90 install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \
91 % (staging_kernel_dir, hdddir)
92 tmp = exec_cmd(install_cmd)
93
94 install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \
95 % (staging_data_dir, hdddir)
96 tmp = exec_cmd(install_cmd)
97
98 du_cmd = "du -bks %s" % hdddir
99 rc, out = exec_cmd(du_cmd)
100 blocks = int(out.split()[0])
101
102 blocks += BOOTDD_EXTRA_SPACE
103
104 # Ensure total sectors is an integral number of sectors per
105 # track or mcopy will complain. Sectors are 512 bytes, and we
106 # generate images with 32 sectors per track. This calculation is
107 # done in blocks, thus the mod by 16 instead of 32.
108 blocks += (16 - (blocks % 16))
109
110 # dosfs image, created by mkdosfs
111 bootimg = "%s/boot.img" % cr_workdir
112
113 dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks)
114 exec_native_cmd(dosfs_cmd, native_sysroot)
115
116 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
117 exec_native_cmd(mcopy_cmd, native_sysroot)
118
119 syslinux_cmd = "syslinux %s" % bootimg
120 exec_native_cmd(syslinux_cmd, native_sysroot)
121
122 chmod_cmd = "chmod 644 %s" % bootimg
123 exec_cmd(chmod_cmd)
124
125 du_cmd = "du -Lbms %s" % bootimg
126 rc, out = exec_cmd(du_cmd)
127 bootimg_size = out.split()[0]
128
129 self.size = bootimg_size
130 self.source_file = bootimg
131
132 def prepare_bootimg_efi(self, cr_workdir, oe_builddir, bootimg_dir,
133 kernel_dir, native_sysroot):
134 """
135 Prepare content for an EFI (grub) boot partition.
136 """
137 staging_kernel_dir = kernel_dir
138 staging_data_dir = bootimg_dir
139
140 hdddir = "%s/hdd/boot" % cr_workdir
141
142 install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" % \
143 (staging_kernel_dir, hdddir)
144 tmp = exec_cmd(install_cmd)
145
146 shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir,
147 "%s/grub.cfg" % cr_workdir)
148
149 cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (staging_data_dir, hdddir)
150 exec_cmd(cp_cmd, True)
151
152 shutil.move("%s/grub.cfg" % cr_workdir,
153 "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir)
154
155 du_cmd = "du -bks %s" % hdddir
156 rc, out = exec_cmd(du_cmd)
157 blocks = int(out.split()[0])
158
159 blocks += BOOTDD_EXTRA_SPACE
160
161 # Ensure total sectors is an integral number of sectors per
162 # track or mcopy will complain. Sectors are 512 bytes, and we
163 # generate images with 32 sectors per track. This calculation is
164 # done in blocks, thus the mod by 16 instead of 32.
165 blocks += (16 - (blocks % 16))
166
167 # dosfs image, created by mkdosfs
168 bootimg = "%s/boot.img" % cr_workdir
169
170 dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks)
171 exec_native_cmd(dosfs_cmd, native_sysroot)
172
173 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
174 exec_native_cmd(mcopy_cmd, native_sysroot)
175
176 chmod_cmd = "chmod 644 %s" % bootimg
177 exec_cmd(chmod_cmd)
178
179 du_cmd = "du -Lbms %s" % bootimg
180 rc, out = exec_cmd(du_cmd)
181 bootimg_size = out.split()[0]
182
183 self.size = bootimg_size
184 self.source_file = bootimg
185
186 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
187 rootfs_dir):
188 """
189 Handle an already-created partition e.g. xxx.ext3
190 """
191 rootfs = oe_builddir
192 du_cmd = "du -Lbms %s" % rootfs
193 rc, out = exec_cmd(du_cmd)
194 rootfs_size = out.split()[0]
195
196 self.size = rootfs_size
197 self.source_file = rootfs
198
199 def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
200 native_sysroot):
201 """
202 Prepare content for a rootfs partition i.e. create a partition
203 and fill it from a /rootfs dir.
204
205 Currently handles ext2/3/4 and btrfs.
206 """
207 if self.fstype.startswith("ext"):
208 return self.prepare_rootfs_ext(cr_workdir, oe_builddir,
209 rootfs_dir, native_sysroot)
210 elif self.fstype.startswith("btrfs"):
211 return self.prepare_rootfs_btrfs(cr_workdir, oe_builddir,
212 rootfs_dir, native_sysroot)
213
214 def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir,
215 native_sysroot):
216 """
217 Prepare content for an ext2/3/4 rootfs partition.
218 """
219 populate_script = "%s/usr/bin/populate-extfs.sh" % native_sysroot
220 image_extra_space = 10240
221
222 image_rootfs = rootfs_dir
223 rootfs = "%s/rootfs.%s" % (cr_workdir, self.fstype)
224
225 du_cmd = "du -ks %s" % image_rootfs
226 rc, out = exec_cmd(du_cmd)
227 actual_rootfs_size = out.split()[0]
228
229 rootfs_size = int(actual_rootfs_size) + image_extra_space
230
231 dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
232 (rootfs, rootfs_size)
233 rc, out = exec_cmd(dd_cmd)
234
235 extra_imagecmd = "-i 8192"
236
237 mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, rootfs)
238 rc, out = exec_native_cmd(mkfs_cmd, native_sysroot)
239
240 populate_cmd = populate_script + " " + image_rootfs + " " + rootfs
241 rc, out = exec_native_cmd(populate_cmd, native_sysroot)
242
243 # get the rootfs size in the right units for kickstart (Mb)
244 du_cmd = "du -Lbms %s" % rootfs
245 rc, out = exec_cmd(du_cmd)
246 rootfs_size = out.split()[0]
247
248 self.size = rootfs_size
249 self.source_file = rootfs
250
251 return 0
252
253 def prepare_rootfs_btrfs(self, cr_workdir, oe_builddir, rootfs_dir,
254 native_sysroot):
255 """
256 Prepare content for a btrfs rootfs partition.
257
258 Currently handles ext2/3/4 and btrfs.
259 """
260 image_extra_space = 10240
261
262 image_rootfs = rootfs_dir
263 rootfs = "%s/rootfs.%s" % (cr_workdir, self.fstype)
264
265 du_cmd = "du -ks %s" % image_rootfs
266 rc, out = exec_cmd(du_cmd)
267 actual_rootfs_size = out.split()[0]
268
269 rootfs_size = int(actual_rootfs_size) + image_extra_space
270
271 dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
272 (rootfs, rootfs_size)
273 rc, out = exec_cmd(dd_cmd)
274
275 mkfs_cmd = "mkfs.%s -b %d -r %s %s" % \
276 (self.fstype, rootfs_size * 1024, image_rootfs, rootfs)
277 rc, out = exec_native_cmd(mkfs_cmd, native_sysroot)
278
279 # get the rootfs size in the right units for kickstart (Mb)
280 du_cmd = "du -Lbms %s" % rootfs
281 rc, out = exec_cmd(du_cmd)
282 rootfs_size = out.split()[0]
283
284 self.size = rootfs_size
285 self.source_file = rootfs
286
287 def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot):
288 """
289 Prepare an empty partition.
290 """
291 if self.fstype.startswith("ext"):
292 return self.prepare_empty_partition_ext(cr_workdir, oe_builddir,
293 native_sysroot)
294 elif self.fstype.startswith("btrfs"):
295 return self.prepare_empty_partition_btrfs(cr_workdir, oe_builddir,
296 native_sysroot)
297
298 def prepare_empty_partition_ext(self, cr_workdir, oe_builddir,
299 native_sysroot):
300 """
301 Prepare an empty ext2/3/4 partition.
302 """
303 fs = "%s/fs.%s" % (cr_workdir, self.fstype)
304
305 dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
306 (fs, self.size)
307 rc, out = exec_cmd(dd_cmd)
308
309 extra_imagecmd = "-i 8192"
310
311 mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs)
312 rc, out = exec_native_cmd(mkfs_cmd, native_sysroot)
313
314 self.source_file = fs
315
316 return 0
317
318 def prepare_empty_partition_btrfs(self, cr_workdir, oe_builddir,
319 native_sysroot):
320 """
321 Prepare an empty btrfs partition.
322 """
323 fs = "%s/fs.%s" % (cr_workdir, self.fstype)
324
325 dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
326 (fs, self.size)
327 rc, out = exec_cmd(dd_cmd)
328
329 mkfs_cmd = "mkfs.%s -b %d %s" % (self.fstype, self.size * 1024, rootfs)
330 rc, out = exec_native_cmd(mkfs_cmd, native_sysroot)
331
332 mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs)
333 rc, out = exec_native_cmd(mkfs_cmd, native_sysroot)
334
335 self.source_file = fs
336
337 return 0
338
339 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
340 """
341 Prepare a swap partition.
342 """
343 fs = "%s/fs.%s" % (cr_workdir, self.fstype)
344
345 dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
346 (fs, self.size)
347 rc, out = exec_cmd(dd_cmd)
348
349 import uuid
350 label_str = ""
351 if self.label:
352 label_str = "-L %s" % self.label
353 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), fs)
354 rc, out = exec_native_cmd(mkswap_cmd, native_sysroot)
355
356 self.source_file = fs
357
358 return 0
359
360class Wic_Partition(Mic_Partition):
361 removedKeywords = Mic_Partition.removedKeywords
362 removedAttrs = Mic_Partition.removedAttrs
46 363
47 def _getParser(self): 364 def _getParser(self):
48 op = FC4_Partition._getParser(self) 365 op = Mic_Partition._getParser(self)
49 # The alignment value is given in kBytes. e.g., value 8 means that 366 # use specified source file to fill the partition
50 # the partition is aligned to start from 8096 byte boundary. 367 # and calculate partition size
51 op.add_option("--align", type="int", action="store", dest="align", 368 op.add_option("--source", type="string", action="store",
52 default=None) 369 dest="source", default=None)
53 op.add_option("--extoptions", type="string", action="store", dest="extopts",
54 default=None)
55 op.add_option("--part-type", type="string", action="store", dest="part_type",
56 default=None)
57 return op 370 return op