diff options
Diffstat (limited to 'scripts/lib/wic/plugins/imager/direct.py')
-rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 108 |
1 files changed, 39 insertions, 69 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index b38e876758..ae420a687e 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
@@ -39,50 +39,6 @@ from wic.utils.errors import CreatorError, ImageError | |||
39 | from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd | 39 | from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd |
40 | from wic.utils.partitionedfs import Image | 40 | from wic.utils.partitionedfs import Image |
41 | 41 | ||
42 | class DirectPlugin(ImagerPlugin): | ||
43 | """ | ||
44 | Install a system into a file containing a partitioned disk image. | ||
45 | |||
46 | An image file is formatted with a partition table, each partition | ||
47 | created from a rootfs or other OpenEmbedded build artifact and dd'ed | ||
48 | into the virtual disk. The disk image can subsequently be dd'ed onto | ||
49 | media and used on actual hardware. | ||
50 | """ | ||
51 | |||
52 | name = 'direct' | ||
53 | |||
54 | @staticmethod | ||
55 | def do_create(opts, *args): | ||
56 | """ | ||
57 | Create direct image, called from creator as 'direct' cmd | ||
58 | """ | ||
59 | native_sysroot, kernel_dir, bootimg_dir, rootfs_dir, ksconf, \ | ||
60 | outdir, oe_builddir, compressor = args | ||
61 | |||
62 | try: | ||
63 | ksobj = KickStart(ksconf) | ||
64 | except KickStartError as err: | ||
65 | msger.error(str(err)) | ||
66 | |||
67 | name = "%s-%s" % (os.path.splitext(os.path.basename(ksconf))[0], | ||
68 | strftime("%Y%m%d%H%M")) | ||
69 | |||
70 | # parse possible 'rootfs=name' items | ||
71 | krootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' ')) | ||
72 | |||
73 | creator = DirectImageCreator(name, ksobj, oe_builddir, outdir, | ||
74 | krootfs_dir, bootimg_dir, kernel_dir, | ||
75 | native_sysroot, compressor, opts.bmap) | ||
76 | try: | ||
77 | creator.create() | ||
78 | creator.assemble() | ||
79 | creator.finalize() | ||
80 | creator.print_info() | ||
81 | except errors.CreatorError: | ||
82 | raise | ||
83 | finally: | ||
84 | creator.cleanup() | ||
85 | |||
86 | class DiskImage(): | 42 | class DiskImage(): |
87 | """ | 43 | """ |
88 | A Disk backed by a file. | 44 | A Disk backed by a file. |
@@ -101,43 +57,57 @@ class DiskImage(): | |||
101 | 57 | ||
102 | self.created = True | 58 | self.created = True |
103 | 59 | ||
104 | class DirectImageCreator: | 60 | class DirectPlugin(ImagerPlugin): |
105 | """ | 61 | """ |
106 | Installs a system into a file containing a partitioned disk image. | 62 | Install a system into a file containing a partitioned disk image. |
107 | 63 | ||
108 | DirectImageCreator is an advanced ImageCreator subclass; an image | 64 | An image file is formatted with a partition table, each partition |
109 | file is formatted with a partition table, each partition created | 65 | created from a rootfs or other OpenEmbedded build artifact and dd'ed |
110 | from a rootfs or other OpenEmbedded build artifact and dd'ed into | 66 | into the virtual disk. The disk image can subsequently be dd'ed onto |
111 | the virtual disk. The disk image can subsequently be dd'ed onto | ||
112 | media and used on actual hardware. | 67 | media and used on actual hardware. |
113 | """ | 68 | """ |
69 | name = 'direct' | ||
114 | 70 | ||
115 | def __init__(self, name, ksobj, oe_builddir, outdir, | 71 | def __init__(self, wks_file, rootfs_dir, bootimg_dir, kernel_dir, |
116 | rootfs_dir, bootimg_dir, kernel_dir, | 72 | native_sysroot, scripts_path, oe_builddir, options): |
117 | native_sysroot, compressor, bmap=False): | 73 | try: |
118 | """ | 74 | self.ks = KickStart(wks_file) |
119 | Initialize a DirectImageCreator instance. | 75 | except KickStartError as err: |
76 | msger.error(str(err)) | ||
120 | 77 | ||
121 | This method takes the same arguments as ImageCreator.__init__() | 78 | # parse possible 'rootfs=name' items |
122 | """ | 79 | self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' ')) |
123 | self.name = name | 80 | self.bootimg_dir = bootimg_dir |
124 | self.outdir = outdir | 81 | self.kernel_dir = kernel_dir |
125 | self.workdir = tempfile.mkdtemp(dir=outdir, prefix='tmp.wic.') | 82 | self.native_sysroot = native_sysroot |
126 | self.ks = ksobj | 83 | self.oe_builddir = oe_builddir |
127 | 84 | ||
85 | self.outdir = options.outdir | ||
86 | self.compressor = options.compressor | ||
87 | self.bmap = options.bmap | ||
88 | |||
89 | self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0], | ||
90 | strftime("%Y%m%d%H%M")) | ||
91 | self.workdir = tempfile.mkdtemp(dir=self.outdir, prefix='tmp.wic.') | ||
128 | self._image = None | 92 | self._image = None |
129 | self._disks = {} | 93 | self._disks = {} |
130 | self._disk_format = "direct" | 94 | self._disk_format = "direct" |
131 | self._disk_names = [] | 95 | self._disk_names = [] |
132 | self.ptable_format = self.ks.bootloader.ptable | 96 | self.ptable_format = self.ks.bootloader.ptable |
133 | 97 | ||
134 | self.oe_builddir = oe_builddir | 98 | def do_create(self): |
135 | self.rootfs_dir = rootfs_dir | 99 | """ |
136 | self.bootimg_dir = bootimg_dir | 100 | Plugin entry point. |
137 | self.kernel_dir = kernel_dir | 101 | """ |
138 | self.native_sysroot = native_sysroot | 102 | try: |
139 | self.compressor = compressor | 103 | self.create() |
140 | self.bmap = bmap | 104 | self.assemble() |
105 | self.finalize() | ||
106 | self.print_info() | ||
107 | except errors.CreatorError: | ||
108 | raise | ||
109 | finally: | ||
110 | self.cleanup() | ||
141 | 111 | ||
142 | def _get_part_num(self, num, parts): | 112 | def _get_part_num(self, num, parts): |
143 | """calculate the real partition number, accounting for partitions not | 113 | """calculate the real partition number, accounting for partitions not |
@@ -359,7 +329,7 @@ class DirectImageCreator: | |||
359 | extension = "direct" + {"gzip": ".gz", | 329 | extension = "direct" + {"gzip": ".gz", |
360 | "bzip2": ".bz2", | 330 | "bzip2": ".bz2", |
361 | "xz": ".xz", | 331 | "xz": ".xz", |
362 | "": ""}.get(self.compressor) | 332 | None: ""}.get(self.compressor) |
363 | full_path = self._full_path(self.outdir, disk_name, extension) | 333 | full_path = self._full_path(self.outdir, disk_name, extension) |
364 | msg += ' %s\n\n' % full_path | 334 | msg += ' %s\n\n' % full_path |
365 | 335 | ||