summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/plugins')
-rw-r--r--scripts/lib/wic/plugins/source/rawcopy2.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/scripts/lib/wic/plugins/source/rawcopy2.py b/scripts/lib/wic/plugins/source/rawcopy2.py
new file mode 100644
index 0000000..e2166d6
--- /dev/null
+++ b/scripts/lib/wic/plugins/source/rawcopy2.py
@@ -0,0 +1,93 @@
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
18import logging
19import os
20
21from wic import WicError
22from wic.pluginbase import SourcePlugin
23from wic.misc import exec_cmd, get_bitbake_var
24from wic.filemap import sparse_copy
25
26logger = logging.getLogger('wic')
27
28class RawCopy2Plugin(SourcePlugin):
29 """
30 Populate partition content from raw image file.
31 """
32
33 name = 'rawcopy2'
34
35 @staticmethod
36 def do_image_label(fstype, dst, label):
37 if fstype.startswith('ext'):
38 cmd = 'tune2fs -L %s %s' % (label, dst)
39 elif fstype in ('msdos', 'vfat'):
40 cmd = 'dosfslabel %s %s' % (dst, label)
41 elif fstype == 'btrfs':
42 cmd = 'btrfs filesystem label %s %s' % (dst, label)
43 elif fstype == 'swap':
44 cmd = 'mkswap -L %s %s' % (label, dst)
45 elif fstype == 'squashfs':
46 raise WicError("It's not possible to update a squashfs "
47 "filesystem label '%s'" % (label))
48 else:
49 raise WicError("Cannot update filesystem label: "
50 "Unknown fstype: '%s'" % (fstype))
51
52 exec_cmd(cmd)
53
54 @classmethod
55 def do_prepare_partition(cls, part, source_params, cr, cr_workdir,
56 oe_builddir, bootimg_dir, kernel_dir,
57 rootfs_dir, native_sysroot):
58 """
59 Called to do the actual content population for a partition i.e. it
60 'prepares' the partition to be incorporated into the image.
61 """
62 if not kernel_dir:
63 kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
64 if not kernel_dir:
65 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
66
67 logger.debug('Kernel dir: %s', kernel_dir)
68
69 if 'file' not in source_params:
70 raise WicError("No file specified")
71
72 src = os.path.join(kernel_dir, source_params['file'])
73 dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
74 if not os.path.exists(os.path.dirname(dst)):
75 os.makedirs(os.path.dirname(dst))
76
77 if 'skip' in source_params:
78 sparse_copy(src, dst, skip=int(source_params['skip']))
79 else:
80 sparse_copy(src, dst)
81
82 # get the size in the right units for kickstart (kB)
83 du_cmd = "du -Lbks %s" % dst
84 out = exec_cmd(du_cmd)
85 filesize = int(out.split()[0])
86
87 if filesize > part.size:
88 part.size = filesize
89
90 if part.label:
91 RawCopy2Plugin.do_image_label(part.fstype, dst, part.label)
92
93 part.source_file = dst