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 os 19 20from wic import msger 21from wic.pluginbase import SourcePlugin 22from wic.utils.oe.misc import exec_cmd, get_bitbake_var 23 24class RawCopyPlugin(SourcePlugin): 25 """ 26 Populate partition content from raw image file. 27 """ 28 29 name = 'rawcopy' 30 31 @classmethod 32 def do_install_disk(cls, disk, disk_name, cr, workdir, oe_builddir, 33 bootimg_dir, kernel_dir, native_sysroot): 34 """ 35 Called after all partitions have been prepared and assembled into a 36 disk image. Do nothing. 37 """ 38 pass 39 40 @classmethod 41 def do_configure_partition(cls, part, source_params, cr, cr_workdir, 42 oe_builddir, bootimg_dir, kernel_dir, 43 native_sysroot): 44 """ 45 Called before do_prepare_partition(). Possibly prepare 46 configuration files of some sort. 47 """ 48 pass 49 50 @classmethod 51 def do_prepare_partition(cls, part, source_params, cr, cr_workdir, 52 oe_builddir, bootimg_dir, kernel_dir, 53 rootfs_dir, native_sysroot): 54 """ 55 Called to do the actual content population for a partition i.e. it 56 'prepares' the partition to be incorporated into the image. 57 """ 58 if not bootimg_dir: 59 bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") 60 if not bootimg_dir: 61 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n") 62 63 msger.debug('Bootimg dir: %s' % bootimg_dir) 64 65 if 'file' not in source_params: 66 msger.error("No file specified\n") 67 return 68 69 src = os.path.join(bootimg_dir, source_params['file']) 70 dst = src 71 72 if 'skip' in source_params: 73 dst = os.path.join(cr_workdir, source_params['file']) 74 dd_cmd = "dd if=%s of=%s ibs=%s skip=1 conv=notrunc" % \ 75 (src, dst, source_params['skip']) 76 exec_cmd(dd_cmd) 77 78 # get the size in the right units for kickstart (kB) 79 du_cmd = "du -Lbks %s" % dst 80 out = exec_cmd(du_cmd) 81 filesize = out.split()[0] 82 83 if int(filesize) > int(part.size): 84 part.size = filesize 85 86 part.source_file = dst 87 88