blob: e1c4f5e7db8959f4a35911da5d13ea3f62476397 [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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018import logging
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019import os
20
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021from wic import WicError
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022from wic.pluginbase import SourcePlugin
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023from wic.utils.misc import exec_cmd, get_bitbake_var
Patrick Williamsc0f7c042017-02-23 20:41:17 -060024from wic.filemap import sparse_copy
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026logger = logging.getLogger('wic')
27
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028class RawCopyPlugin(SourcePlugin):
29 """
30 Populate partition content from raw image file.
31 """
32
33 name = 'rawcopy'
34
35 @classmethod
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036 def do_prepare_partition(cls, part, source_params, cr, cr_workdir,
37 oe_builddir, bootimg_dir, kernel_dir,
38 rootfs_dir, native_sysroot):
39 """
40 Called to do the actual content population for a partition i.e. it
41 'prepares' the partition to be incorporated into the image.
42 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -050043 if not kernel_dir:
44 kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
45 if not kernel_dir:
46 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 logger.debug('Kernel dir: %s', kernel_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049
50 if 'file' not in source_params:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 raise WicError("No file specified")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053 src = os.path.join(kernel_dir, source_params['file'])
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054 dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
56 if 'skip' in source_params:
Brad Bishop37a0e4d2017-12-04 01:01:44 -050057 sparse_copy(src, dst, skip=int(source_params['skip']))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059 sparse_copy(src, dst)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060
61 # get the size in the right units for kickstart (kB)
62 du_cmd = "du -Lbks %s" % dst
63 out = exec_cmd(du_cmd)
Brad Bishop37a0e4d2017-12-04 01:01:44 -050064 filesize = int(out.split()[0])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065
Brad Bishop37a0e4d2017-12-04 01:01:44 -050066 if filesize > part.size:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 part.size = filesize
68
69 part.source_file = dst