blob: 6d3f46cc61ac78eba07e7bf4c9d9577b6eacabba [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# 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 implements the 'direct' imager plugin class for 'wic'
22#
23# AUTHORS
24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
25#
26
27from wic.utils import errors
28from wic.conf import configmgr
29
30import wic.imager.direct as direct
31from wic.pluginbase import ImagerPlugin
32
33class DirectPlugin(ImagerPlugin):
34 """
35 Install a system into a file containing a partitioned disk image.
36
37 An image file is formatted with a partition table, each partition
38 created from a rootfs or other OpenEmbedded build artifact and dd'ed
39 into the virtual disk. The disk image can subsequently be dd'ed onto
40 media and used on actual hardware.
41 """
42
43 name = 'direct'
44
45 @classmethod
46 def __rootfs_dir_to_dict(cls, rootfs_dirs):
47 """
48 Gets a string that contain 'connection=dir' splitted by
49 space and return a dict
50 """
51 krootfs_dir = {}
52 for rootfs_dir in rootfs_dirs.split(' '):
53 key, val = rootfs_dir.split('=')
54 krootfs_dir[key] = val
55
56 return krootfs_dir
57
58 @classmethod
59 def do_create(cls, opts, *args):
60 """
61 Create direct image, called from creator as 'direct' cmd
62 """
63 if len(args) != 8:
64 raise errors.Usage("Extra arguments given")
65
66 native_sysroot = args[0]
67 kernel_dir = args[1]
68 bootimg_dir = args[2]
69 rootfs_dir = args[3]
70
71 creatoropts = configmgr.create
72 ksconf = args[4]
73
74 image_output_dir = args[5]
75 oe_builddir = args[6]
76 compressor = args[7]
77
78 krootfs_dir = cls.__rootfs_dir_to_dict(rootfs_dir)
79
80 configmgr._ksconf = ksconf
81
82 creator = direct.DirectImageCreator(oe_builddir,
83 image_output_dir,
84 krootfs_dir,
85 bootimg_dir,
86 kernel_dir,
87 native_sysroot,
88 compressor,
89 creatoropts)
90
91 try:
92 creator.create()
93 creator.assemble()
94 creator.finalize()
95 creator.print_outimage_info()
96
97 except errors.CreatorError:
98 raise
99 finally:
100 creator.cleanup()
101
102 return 0