blob: 618dd4475c11ef944a5edd8a7d2d3fcebee6fd7d [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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 os
19
20from wic import msger
21from wic.pluginbase import SourcePlugin
22from wic.utils.oe.misc import exec_cmd, get_bitbake_var
Patrick Williamsc0f7c042017-02-23 20:41:17 -060023from wic.filemap import sparse_copy
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024
25class RawCopyPlugin(SourcePlugin):
26 """
27 Populate partition content from raw image file.
28 """
29
30 name = 'rawcopy'
31
32 @classmethod
33 def do_install_disk(cls, disk, disk_name, cr, workdir, oe_builddir,
34 bootimg_dir, kernel_dir, native_sysroot):
35 """
36 Called after all partitions have been prepared and assembled into a
37 disk image. Do nothing.
38 """
39 pass
40
41 @classmethod
42 def do_configure_partition(cls, part, source_params, cr, cr_workdir,
43 oe_builddir, bootimg_dir, kernel_dir,
44 native_sysroot):
45 """
46 Called before do_prepare_partition(). Possibly prepare
47 configuration files of some sort.
48 """
49 pass
50
51 @classmethod
52 def do_prepare_partition(cls, part, source_params, cr, cr_workdir,
53 oe_builddir, bootimg_dir, kernel_dir,
54 rootfs_dir, native_sysroot):
55 """
56 Called to do the actual content population for a partition i.e. it
57 'prepares' the partition to be incorporated into the image.
58 """
59 if not bootimg_dir:
60 bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
61 if not bootimg_dir:
62 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
63
64 msger.debug('Bootimg dir: %s' % bootimg_dir)
65
66 if 'file' not in source_params:
67 msger.error("No file specified\n")
68 return
69
70 src = os.path.join(bootimg_dir, source_params['file'])
Patrick Williamsc0f7c042017-02-23 20:41:17 -060071 dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072
73 if 'skip' in source_params:
Brad Bishop37a0e4d2017-12-04 01:01:44 -050074 sparse_copy(src, dst, skip=int(source_params['skip']))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050075 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060076 sparse_copy(src, dst)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077
78 # get the size in the right units for kickstart (kB)
79 du_cmd = "du -Lbks %s" % dst
80 out = exec_cmd(du_cmd)
Brad Bishop37a0e4d2017-12-04 01:01:44 -050081 filesize = int(out.split()[0])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082
Brad Bishop37a0e4d2017-12-04 01:01:44 -050083 if filesize > part.size:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 part.size = filesize
85
86 part.source_file = dst
87