summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/kickstart
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2014-08-08 15:53:52 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-08-11 10:53:12 +0100
commitd8f9d05baee3abd4feb0a5b2f2afe467e919c6b9 (patch)
treeedc6ba90a220ad5bbba41998c3c5c82e1e97760d /scripts/lib/wic/kickstart
parenta43c1f94205d95c6eb77af2f0a494b4143f9eaf8 (diff)
downloadpoky-d8f9d05baee3abd4feb0a5b2f2afe467e919c6b9.tar.gz
wic: Rename /mic to /wic
As well as any other stray instances of mic in the codebase that can be removed. We don't really need to carry around legacy naming, and the history is in git. (From OE-Core rev: 598b120406dc1d2b7e377bd1ab6f0acbef034b22) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/kickstart')
-rw-r--r--scripts/lib/wic/kickstart/__init__.py125
-rw-r--r--scripts/lib/wic/kickstart/custom_commands/__init__.py10
-rw-r--r--scripts/lib/wic/kickstart/custom_commands/micboot.py49
-rw-r--r--scripts/lib/wic/kickstart/custom_commands/micpartition.py57
-rw-r--r--scripts/lib/wic/kickstart/custom_commands/partition.py496
-rw-r--r--scripts/lib/wic/kickstart/custom_commands/wicboot.py57
6 files changed, 794 insertions, 0 deletions
diff --git a/scripts/lib/wic/kickstart/__init__.py b/scripts/lib/wic/kickstart/__init__.py
new file mode 100644
index 0000000000..4f5b778b5d
--- /dev/null
+++ b/scripts/lib/wic/kickstart/__init__.py
@@ -0,0 +1,125 @@
1#!/usr/bin/python -tt
2#
3# Copyright (c) 2007 Red Hat, Inc.
4# Copyright (c) 2009, 2010, 2011 Intel, Inc.
5#
6# This program is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by the Free
8# Software Foundation; version 2 of the License
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13# for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc., 59
17# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19import os, sys, re
20import shutil
21import subprocess
22import string
23
24import pykickstart.sections as kssections
25import pykickstart.commands as kscommands
26import pykickstart.constants as ksconstants
27import pykickstart.errors as kserrors
28import pykickstart.parser as ksparser
29import pykickstart.version as ksversion
30from pykickstart.handlers.control import commandMap
31from pykickstart.handlers.control import dataMap
32
33from wic import msger
34from wic.utils import errors, misc, runner, fs_related as fs
35from custom_commands import wicboot, partition
36
37def read_kickstart(path):
38 """Parse a kickstart file and return a KickstartParser instance.
39
40 This is a simple utility function which takes a path to a kickstart file,
41 parses it and returns a pykickstart KickstartParser instance which can
42 be then passed to an ImageCreator constructor.
43
44 If an error occurs, a CreatorError exception is thrown.
45 """
46
47 #version = ksversion.makeVersion()
48 #ks = ksparser.KickstartParser(version)
49
50 using_version = ksversion.DEVEL
51 commandMap[using_version]["bootloader"] = wicboot.Wic_Bootloader
52 commandMap[using_version]["part"] = partition.Wic_Partition
53 commandMap[using_version]["partition"] = partition.Wic_Partition
54 dataMap[using_version]["PartData"] = partition.Wic_PartData
55 superclass = ksversion.returnClassForVersion(version=using_version)
56
57 class KSHandlers(superclass):
58 def __init__(self):
59 superclass.__init__(self, mapping=commandMap[using_version])
60
61 ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=False)
62
63 try:
64 ks.readKickstart(path)
65 except (kserrors.KickstartParseError, kserrors.KickstartError), err:
66 if msger.ask("Errors occured on kickstart file, skip and continue?"):
67 msger.warning("%s" % err)
68 pass
69 else:
70 raise errors.KsError("%s" % err)
71
72 return ks
73
74def get_image_size(ks, default = None):
75 __size = 0
76 for p in ks.handler.partition.partitions:
77 if p.mountpoint == "/" and p.size:
78 __size = p.size
79 if __size > 0:
80 return int(__size) * 1024L * 1024L
81 else:
82 return default
83
84def get_image_fstype(ks, default = None):
85 for p in ks.handler.partition.partitions:
86 if p.mountpoint == "/" and p.fstype:
87 return p.fstype
88 return default
89
90def get_image_fsopts(ks, default = None):
91 for p in ks.handler.partition.partitions:
92 if p.mountpoint == "/" and p.fsopts:
93 return p.fsopts
94 return default
95
96def get_timeout(ks, default = None):
97 if not hasattr(ks.handler.bootloader, "timeout"):
98 return default
99 if ks.handler.bootloader.timeout is None:
100 return default
101 return int(ks.handler.bootloader.timeout)
102
103def get_kernel_args(ks, default = "ro rd.live.image"):
104 if not hasattr(ks.handler.bootloader, "appendLine"):
105 return default
106 if ks.handler.bootloader.appendLine is None:
107 return default
108 return "%s %s" %(default, ks.handler.bootloader.appendLine)
109
110def get_menu_args(ks, default = ""):
111 if not hasattr(ks.handler.bootloader, "menus"):
112 return default
113 if ks.handler.bootloader.menus in (None, ""):
114 return default
115 return "%s" % ks.handler.bootloader.menus
116
117def get_default_kernel(ks, default = None):
118 if not hasattr(ks.handler.bootloader, "default"):
119 return default
120 if not ks.handler.bootloader.default:
121 return default
122 return ks.handler.bootloader.default
123
124def get_partitions(ks):
125 return ks.handler.partition.partitions
diff --git a/scripts/lib/wic/kickstart/custom_commands/__init__.py b/scripts/lib/wic/kickstart/custom_commands/__init__.py
new file mode 100644
index 0000000000..f84c6d9e00
--- /dev/null
+++ b/scripts/lib/wic/kickstart/custom_commands/__init__.py
@@ -0,0 +1,10 @@
1from micpartition import Mic_Partition
2from micpartition import Mic_PartData
3from partition import Wic_Partition
4
5__all__ = (
6 "Mic_Partition",
7 "Mic_PartData",
8 "Wic_Partition",
9 "Wic_PartData",
10)
diff --git a/scripts/lib/wic/kickstart/custom_commands/micboot.py b/scripts/lib/wic/kickstart/custom_commands/micboot.py
new file mode 100644
index 0000000000..66d1678aa7
--- /dev/null
+++ b/scripts/lib/wic/kickstart/custom_commands/micboot.py
@@ -0,0 +1,49 @@
1#!/usr/bin/python -tt
2#
3# Copyright (c) 2008, 2009, 2010 Intel, Inc.
4#
5# Anas Nashif
6#
7# This program is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the Free
9# Software Foundation; version 2 of the License
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14# 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., 59
18# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20from pykickstart.base import *
21from pykickstart.errors import *
22from pykickstart.options import *
23from pykickstart.commands.bootloader import *
24
25class Mic_Bootloader(F8_Bootloader):
26 def __init__(self, writePriority=10, appendLine="", driveorder=None,
27 forceLBA=False, location="", md5pass="", password="",
28 upgrade=False, menus=""):
29 F8_Bootloader.__init__(self, writePriority, appendLine, driveorder,
30 forceLBA, location, md5pass, password, upgrade)
31
32 self.menus = ""
33 self.ptable = "msdos"
34
35 def _getArgsAsStr(self):
36 ret = F8_Bootloader._getArgsAsStr(self)
37
38 if self.menus == "":
39 ret += " --menus=%s" %(self.menus,)
40 if self.ptable:
41 ret += " --ptable=\"%s\"" %(self.ptable,)
42 return ret
43
44 def _getParser(self):
45 op = F8_Bootloader._getParser(self)
46 op.add_option("--menus", dest="menus")
47 op.add_option("--ptable", dest="ptable", type="string")
48 return op
49
diff --git a/scripts/lib/wic/kickstart/custom_commands/micpartition.py b/scripts/lib/wic/kickstart/custom_commands/micpartition.py
new file mode 100644
index 0000000000..59a87fb486
--- /dev/null
+++ b/scripts/lib/wic/kickstart/custom_commands/micpartition.py
@@ -0,0 +1,57 @@
1#!/usr/bin/python -tt
2#
3# Marko Saukko <marko.saukko@cybercom.com>
4#
5# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
6#
7# This copyrighted material is made available to anyone wishing to use, modify,
8# copy, or redistribute it subject to the terms and conditions of the GNU
9# General Public License v.2. This program is distributed in the hope that it
10# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
11# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12# See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# this program; if not, write to the Free Software Foundation, Inc., 51
16# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18from pykickstart.commands.partition import *
19
20class Mic_PartData(FC4_PartData):
21 removedKeywords = FC4_PartData.removedKeywords
22 removedAttrs = FC4_PartData.removedAttrs
23
24 def __init__(self, *args, **kwargs):
25 FC4_PartData.__init__(self, *args, **kwargs)
26 self.deleteRemovedAttrs()
27 self.align = kwargs.get("align", None)
28 self.extopts = kwargs.get("extopts", None)
29 self.part_type = kwargs.get("part_type", None)
30
31 def _getArgsAsStr(self):
32 retval = FC4_PartData._getArgsAsStr(self)
33
34 if self.align:
35 retval += " --align"
36 if self.extopts:
37 retval += " --extoptions=%s" % self.extopts
38 if self.part_type:
39 retval += " --part-type=%s" % self.part_type
40
41 return retval
42
43class Mic_Partition(FC4_Partition):
44 removedKeywords = FC4_Partition.removedKeywords
45 removedAttrs = FC4_Partition.removedAttrs
46
47 def _getParser(self):
48 op = FC4_Partition._getParser(self)
49 # The alignment value is given in kBytes. e.g., value 8 means that
50 # the partition is aligned to start from 8096 byte boundary.
51 op.add_option("--align", type="int", action="store", dest="align",
52 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
diff --git a/scripts/lib/wic/kickstart/custom_commands/partition.py b/scripts/lib/wic/kickstart/custom_commands/partition.py
new file mode 100644
index 0000000000..24f523ae41
--- /dev/null
+++ b/scripts/lib/wic/kickstart/custom_commands/partition.py
@@ -0,0 +1,496 @@
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 module provides the OpenEmbedded partition object definitions.
22#
23# AUTHORS
24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
25#
26
27import shutil
28import os
29import tempfile
30
31from pykickstart.commands.partition import *
32from wic.utils.oe.misc import *
33from wic.kickstart.custom_commands import *
34from wic.plugin import pluginmgr
35
36partition_methods = {
37 "do_stage_partition":None,
38 "do_prepare_partition":None,
39 "do_configure_partition":None,
40}
41
42class Wic_PartData(Mic_PartData):
43 removedKeywords = Mic_PartData.removedKeywords
44 removedAttrs = Mic_PartData.removedAttrs
45
46 def __init__(self, *args, **kwargs):
47 Mic_PartData.__init__(self, *args, **kwargs)
48 self.deleteRemovedAttrs()
49 self.source = kwargs.get("source", None)
50 self.rootfs = kwargs.get("rootfs-dir", None)
51 self.source_file = ""
52 self.size = 0
53
54 def _getArgsAsStr(self):
55 retval = Mic_PartData._getArgsAsStr(self)
56
57 if self.source:
58 retval += " --source=%s" % self.source
59 if self.rootfs:
60 retval += " --rootfs-dir=%s" % self.rootfs
61
62 return retval
63
64 def get_rootfs(self):
65 """
66 Acessor for rootfs dir
67 """
68 return self.rootfs
69
70 def set_rootfs(self, rootfs):
71 """
72 Acessor for actual rootfs dir, which must be set by source
73 plugins.
74 """
75 self.rootfs = rootfs
76
77 def get_size(self):
78 """
79 Accessor for partition size, 0 or --size before set_size().
80 """
81 return self.size
82
83 def set_size(self, size):
84 """
85 Accessor for actual partition size, which must be set by source
86 plugins.
87 """
88 self.size = size
89
90 def set_source_file(self, source_file):
91 """
92 Accessor for source_file, the location of the generated partition
93 image, which must be set by source plugins.
94 """
95 self.source_file = source_file
96
97 def get_extra_block_count(self, current_blocks):
98 """
99 The --size param is reflected in self.size (in MB), and we already
100 have current_blocks (1k) blocks, calculate and return the
101 number of (1k) blocks we need to add to get to --size, 0 if
102 we're already there or beyond.
103 """
104 msger.debug("Requested partition size for %s: %d" % \
105 (self.mountpoint, self.size))
106
107 if not self.size:
108 return 0
109
110 requested_blocks = self.size * 1024
111
112 msger.debug("Requested blocks %d, current_blocks %d" % \
113 (requested_blocks, current_blocks))
114
115 if requested_blocks > current_blocks:
116 return requested_blocks - current_blocks
117 else:
118 return 0
119
120 def prepare(self, cr, cr_workdir, oe_builddir, rootfs_dir, bootimg_dir,
121 kernel_dir, native_sysroot):
122 """
123 Prepare content for individual partitions, depending on
124 partition command parameters.
125 """
126 if not self.source:
127 if not self.size:
128 msger.error("The %s partition has a size of zero. Please specify a non-zero --size for that partition." % self.mountpoint)
129 if self.fstype and self.fstype == "swap":
130 self.prepare_swap_partition(cr_workdir, oe_builddir,
131 native_sysroot)
132 elif self.fstype:
133 self.prepare_empty_partition(cr_workdir, oe_builddir,
134 native_sysroot)
135 return
136
137 plugins = pluginmgr.get_source_plugins()
138
139 if self.source not in plugins:
140 msger.error("The '%s' --source specified for %s doesn't exist.\n\tSee 'wic list source-plugins' for a list of available --sources.\n\tSee 'wic help source-plugins' for details on adding a new source plugin." % (self.source, self.mountpoint))
141
142 self._source_methods = pluginmgr.get_source_plugin_methods(self.source, partition_methods)
143 self._source_methods["do_configure_partition"](self, cr, cr_workdir,
144 oe_builddir,
145 bootimg_dir,
146 kernel_dir,
147 native_sysroot)
148 self._source_methods["do_stage_partition"](self, cr, cr_workdir,
149 oe_builddir,
150 bootimg_dir, kernel_dir,
151 native_sysroot)
152 self._source_methods["do_prepare_partition"](self, cr, cr_workdir,
153 oe_builddir,
154 bootimg_dir, kernel_dir, rootfs_dir,
155 native_sysroot)
156
157 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
158 rootfs_dir):
159 """
160 Handle an already-created partition e.g. xxx.ext3
161 """
162 rootfs = oe_builddir
163 du_cmd = "du -Lbms %s" % rootfs
164 out = exec_cmd(du_cmd)
165 rootfs_size = out.split()[0]
166
167 self.size = rootfs_size
168 self.source_file = rootfs
169
170 def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
171 native_sysroot):
172 """
173 Prepare content for a rootfs partition i.e. create a partition
174 and fill it from a /rootfs dir.
175
176 Currently handles ext2/3/4 and btrfs.
177 """
178 pseudo = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot
179 pseudo += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % rootfs_dir
180 pseudo += "export PSEUDO_PASSWD=%s;" % rootfs_dir
181 pseudo += "export PSEUDO_NOSYMLINKEXP=1;"
182 pseudo += "%s/usr/bin/pseudo " % native_sysroot
183
184 if self.fstype.startswith("ext"):
185 return self.prepare_rootfs_ext(cr_workdir, oe_builddir,
186 rootfs_dir, native_sysroot,
187 pseudo)
188 elif self.fstype.startswith("btrfs"):
189 return self.prepare_rootfs_btrfs(cr_workdir, oe_builddir,
190 rootfs_dir, native_sysroot,
191 pseudo)
192
193 elif self.fstype.startswith("vfat"):
194 return self.prepare_rootfs_vfat(cr_workdir, oe_builddir,
195 rootfs_dir, native_sysroot,
196 pseudo)
197 elif self.fstype.startswith("squashfs"):
198 return self.prepare_rootfs_squashfs(cr_workdir, oe_builddir,
199 rootfs_dir, native_sysroot,
200 pseudo)
201
202 def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir,
203 native_sysroot, pseudo):
204 """
205 Prepare content for an ext2/3/4 rootfs partition.
206 """
207
208 image_rootfs = rootfs_dir
209 rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label ,self.fstype)
210
211 du_cmd = "du -ks %s" % image_rootfs
212 out = exec_cmd(du_cmd)
213 actual_rootfs_size = int(out.split()[0])
214
215 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
216
217 if extra_blocks < IMAGE_EXTRA_SPACE:
218 extra_blocks = IMAGE_EXTRA_SPACE
219
220 rootfs_size = actual_rootfs_size + extra_blocks
221
222 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
223 (extra_blocks, self.mountpoint, rootfs_size))
224
225 dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
226 (rootfs, rootfs_size)
227 exec_cmd(dd_cmd)
228
229 extra_imagecmd = "-i 8192"
230
231 mkfs_cmd = "mkfs.%s -F %s %s -d %s" % \
232 (self.fstype, extra_imagecmd, rootfs, image_rootfs)
233 exec_native_cmd(pseudo + mkfs_cmd, native_sysroot)
234
235
236 # get the rootfs size in the right units for kickstart (Mb)
237 du_cmd = "du -Lbms %s" % rootfs
238 out = exec_cmd(du_cmd)
239 rootfs_size = out.split()[0]
240
241 self.size = rootfs_size
242 self.source_file = rootfs
243
244 return 0
245
246 def prepare_rootfs_btrfs(self, cr_workdir, oe_builddir, rootfs_dir,
247 native_sysroot, pseudo):
248 """
249 Prepare content for a btrfs rootfs partition.
250
251 Currently handles ext2/3/4 and btrfs.
252 """
253 image_rootfs = rootfs_dir
254 rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label, self.fstype)
255
256 du_cmd = "du -ks %s" % image_rootfs
257 out = exec_cmd(du_cmd)
258 actual_rootfs_size = int(out.split()[0])
259
260 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
261
262 if extra_blocks < IMAGE_EXTRA_SPACE:
263 extra_blocks = IMAGE_EXTRA_SPACE
264
265 rootfs_size = actual_rootfs_size + extra_blocks
266
267 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
268 (extra_blocks, self.mountpoint, rootfs_size))
269
270 dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
271 (rootfs, rootfs_size)
272 exec_cmd(dd_cmd)
273
274 mkfs_cmd = "mkfs.%s -b %d -r %s %s" % \
275 (self.fstype, rootfs_size * 1024, image_rootfs, rootfs)
276 exec_native_cmd(pseudo + mkfs_cmd, native_sysroot)
277
278 # get the rootfs size in the right units for kickstart (Mb)
279 du_cmd = "du -Lbms %s" % rootfs
280 out = exec_cmd(du_cmd)
281 rootfs_size = out.split()[0]
282
283 self.size = rootfs_size
284 self.source_file = rootfs
285
286 def prepare_rootfs_vfat(self, cr_workdir, oe_builddir, rootfs_dir,
287 native_sysroot, pseudo):
288 """
289 Prepare content for a vfat rootfs partition.
290 """
291 image_rootfs = rootfs_dir
292 rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label, self.fstype)
293
294 du_cmd = "du -bks %s" % image_rootfs
295 out = exec_cmd(du_cmd)
296 blocks = int(out.split()[0])
297
298 extra_blocks = self.get_extra_block_count(blocks)
299
300 if extra_blocks < BOOTDD_EXTRA_SPACE:
301 extra_blocks = BOOTDD_EXTRA_SPACE
302
303 blocks += extra_blocks
304
305 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
306 (extra_blocks, self.mountpoint, blocks))
307
308 # Ensure total sectors is an integral number of sectors per
309 # track or mcopy will complain. Sectors are 512 bytes, and we
310 # generate images with 32 sectors per track. This calculation is
311 # done in blocks, thus the mod by 16 instead of 32.
312 blocks += (16 - (blocks % 16))
313
314 dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (rootfs, blocks)
315 exec_native_cmd(dosfs_cmd, native_sysroot)
316
317 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, image_rootfs)
318 rc, out = exec_native_cmd(mcopy_cmd, native_sysroot)
319 if rc:
320 msger.error("ERROR: mcopy returned '%s' instead of 0 (which you probably don't want to ignore, use --debug for details)" % rc)
321
322 chmod_cmd = "chmod 644 %s" % rootfs
323 exec_cmd(chmod_cmd)
324
325 # get the rootfs size in the right units for kickstart (Mb)
326 du_cmd = "du -Lbms %s" % rootfs
327 out = exec_cmd(du_cmd)
328 rootfs_size = out.split()[0]
329
330 self.set_size(rootfs_size)
331 self.set_source_file(rootfs)
332
333 def prepare_rootfs_squashfs(self, cr_workdir, oe_builddir, rootfs_dir,
334 native_sysroot, pseudo):
335 """
336 Prepare content for a squashfs rootfs partition.
337 """
338 image_rootfs = rootfs_dir
339 rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label ,self.fstype)
340
341 squashfs_cmd = "mksquashfs %s %s -noappend" % \
342 (image_rootfs, rootfs)
343 exec_native_cmd(pseudo + squashfs_cmd, native_sysroot)
344
345 # get the rootfs size in the right units for kickstart (Mb)
346 du_cmd = "du -Lbms %s" % rootfs
347 out = exec_cmd(du_cmd)
348 rootfs_size = out.split()[0]
349
350 self.size = rootfs_size
351 self.source_file = rootfs
352
353 return 0
354
355 def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot):
356 """
357 Prepare an empty partition.
358 """
359 if self.fstype.startswith("ext"):
360 return self.prepare_empty_partition_ext(cr_workdir, oe_builddir,
361 native_sysroot)
362 elif self.fstype.startswith("btrfs"):
363 return self.prepare_empty_partition_btrfs(cr_workdir, oe_builddir,
364 native_sysroot)
365 elif self.fstype.startswith("vfat"):
366 return self.prepare_empty_partition_vfat(cr_workdir, oe_builddir,
367 native_sysroot)
368 elif self.fstype.startswith("squashfs"):
369 return self.prepare_empty_partition_squashfs(cr_workdir, oe_builddir,
370 native_sysroot)
371
372 def prepare_empty_partition_ext(self, cr_workdir, oe_builddir,
373 native_sysroot):
374 """
375 Prepare an empty ext2/3/4 partition.
376 """
377 fs = "%s/fs.%s" % (cr_workdir, self.fstype)
378
379 dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
380 (fs, self.size)
381 exec_cmd(dd_cmd)
382
383 extra_imagecmd = "-i 8192"
384
385 mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs)
386 exec_native_cmd(mkfs_cmd, native_sysroot)
387
388 self.source_file = fs
389
390 return 0
391
392 def prepare_empty_partition_btrfs(self, cr_workdir, oe_builddir,
393 native_sysroot):
394 """
395 Prepare an empty btrfs partition.
396 """
397 fs = "%s/fs.%s" % (cr_workdir, self.fstype)
398
399 dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
400 (fs, self.size)
401 exec_cmd(dd_cmd)
402
403 mkfs_cmd = "mkfs.%s -b %d %s" % (self.fstype, self.size * 1024, rootfs)
404 exec_native_cmd(mkfs_cmd, native_sysroot)
405
406 mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs)
407 exec_native_cmd(mkfs_cmd, native_sysroot)
408
409 self.source_file = fs
410
411 return 0
412
413 def prepare_empty_partition_vfat(self, cr_workdir, oe_builddir,
414 native_sysroot):
415 """
416 Prepare an empty vfat partition.
417 """
418 fs = "%s/fs.%s" % (cr_workdir, self.fstype)
419
420 blocks = self.size * 1024
421
422 dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (fs, blocks)
423 exec_native_cmd(dosfs_cmd, native_sysroot)
424
425 chmod_cmd = "chmod 644 %s" % fs
426 exec_cmd(chmod_cmd)
427
428 self.source_file = fs
429
430 return 0
431
432 def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
433 native_sysroot):
434 """
435 Prepare an empty squashfs partition.
436 """
437 msger.warning("Creating of an empty squashfs %s partition was attempted. " \
438 "Proceeding as requested." % self.mountpoint)
439
440 fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
441
442 # it is not possible to create a squashfs without source data,
443 # thus prepare an empty temp dir that is used as source
444 tmpdir = tempfile.mkdtemp()
445
446 squashfs_cmd = "mksquashfs %s %s -noappend" % \
447 (tmpdir, fs)
448 exec_native_cmd(squashfs_cmd, native_sysroot)
449
450 os.rmdir(tmpdir)
451
452 # get the rootfs size in the right units for kickstart (Mb)
453 du_cmd = "du -Lbms %s" % fs
454 out = exec_cmd(du_cmd)
455 fs_size = out.split()[0]
456
457 self.size = fs_size
458 self.source_file = fs
459
460 return 0
461
462 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
463 """
464 Prepare a swap partition.
465 """
466 fs = "%s/fs.%s" % (cr_workdir, self.fstype)
467
468 dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \
469 (fs, self.size)
470 exec_cmd(dd_cmd)
471
472 import uuid
473 label_str = ""
474 if self.label:
475 label_str = "-L %s" % self.label
476 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), fs)
477 exec_native_cmd(mkswap_cmd, native_sysroot)
478
479 self.source_file = fs
480
481 return 0
482
483class Wic_Partition(Mic_Partition):
484 removedKeywords = Mic_Partition.removedKeywords
485 removedAttrs = Mic_Partition.removedAttrs
486
487 def _getParser(self):
488 op = Mic_Partition._getParser(self)
489 # use specified source file to fill the partition
490 # and calculate partition size
491 op.add_option("--source", type="string", action="store",
492 dest="source", default=None)
493 # use specified rootfs path to fill the partition
494 op.add_option("--rootfs-dir", type="string", action="store",
495 dest="rootfs", default=None)
496 return op
diff --git a/scripts/lib/wic/kickstart/custom_commands/wicboot.py b/scripts/lib/wic/kickstart/custom_commands/wicboot.py
new file mode 100644
index 0000000000..f1914169d8
--- /dev/null
+++ b/scripts/lib/wic/kickstart/custom_commands/wicboot.py
@@ -0,0 +1,57 @@
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 module provides the OpenEmbedded bootloader object definitions.
22#
23# AUTHORS
24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
25#
26
27from pykickstart.base import *
28from pykickstart.errors import *
29from pykickstart.options import *
30from pykickstart.commands.bootloader import *
31
32from wic.kickstart.custom_commands.micboot import *
33
34class Wic_Bootloader(Mic_Bootloader):
35 def __init__(self, writePriority=10, appendLine="", driveorder=None,
36 forceLBA=False, location="", md5pass="", password="",
37 upgrade=False, menus=""):
38 Mic_Bootloader.__init__(self, writePriority, appendLine, driveorder,
39 forceLBA, location, md5pass, password, upgrade)
40
41 self.source = ""
42
43 def _getArgsAsStr(self):
44 retval = Mic_Bootloader._getArgsAsStr(self)
45
46 if self.source:
47 retval += " --source=%s" % self.source
48
49 return retval
50
51 def _getParser(self):
52 op = Mic_Bootloader._getParser(self)
53 # use specified source plugin to implement bootloader-specific methods
54 op.add_option("--source", type="string", action="store",
55 dest="source", default=None)
56 return op
57