diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /scripts/wic | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'scripts/wic')
-rwxr-xr-x | scripts/wic | 328 |
1 files changed, 328 insertions, 0 deletions
diff --git a/scripts/wic b/scripts/wic new file mode 100755 index 0000000000..c708a58e90 --- /dev/null +++ b/scripts/wic | |||
@@ -0,0 +1,328 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | # | ||
5 | # Copyright (c) 2013, Intel Corporation. | ||
6 | # All rights reserved. | ||
7 | # | ||
8 | # This program is free software; you can redistribute it and/or modify | ||
9 | # it under the terms of the GNU General Public License version 2 as | ||
10 | # published by the Free Software Foundation. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License along | ||
18 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
20 | # | ||
21 | # DESCRIPTION 'wic' is the OpenEmbedded Image Creator that users can | ||
22 | # use to generate bootable images. Invoking it without any arguments | ||
23 | # will display help screens for the 'wic' command and list the | ||
24 | # available 'wic' subcommands. Invoking a subcommand without any | ||
25 | # arguments will likewise display help screens for the specified | ||
26 | # subcommand. Please use that interface for detailed help. | ||
27 | # | ||
28 | # AUTHORS | ||
29 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
30 | # | ||
31 | |||
32 | __version__ = "0.1.0" | ||
33 | |||
34 | # Python Standard Library modules | ||
35 | import os | ||
36 | import sys | ||
37 | import optparse | ||
38 | import logging | ||
39 | |||
40 | # External modules | ||
41 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) | ||
42 | lib_path = scripts_path + '/lib' | ||
43 | sys.path = sys.path + [lib_path] | ||
44 | |||
45 | from image.help import * | ||
46 | from image.engine import * | ||
47 | |||
48 | def rootfs_dir_to_args(krootfs_dir): | ||
49 | """ | ||
50 | Get a rootfs_dir dict and serialize to string | ||
51 | """ | ||
52 | rootfs_dir = '' | ||
53 | for k, v in krootfs_dir.items(): | ||
54 | rootfs_dir += ' ' | ||
55 | rootfs_dir += '='.join([k, v]) | ||
56 | return rootfs_dir.strip() | ||
57 | |||
58 | def callback_rootfs_dir(option, opt, value, parser): | ||
59 | """ | ||
60 | Build a dict using --rootfs_dir connection=dir | ||
61 | """ | ||
62 | if not type(parser.values.rootfs_dir) is dict: | ||
63 | parser.values.rootfs_dir = dict() | ||
64 | |||
65 | if '=' in value: | ||
66 | (key, rootfs_dir) = value.split('=') | ||
67 | else: | ||
68 | key = 'ROOTFS_DIR' | ||
69 | rootfs_dir = value | ||
70 | |||
71 | parser.values.rootfs_dir[key] = rootfs_dir | ||
72 | |||
73 | def wic_create_subcommand(args, usage_str): | ||
74 | """ | ||
75 | Command-line handling for image creation. The real work is done | ||
76 | by image.engine.wic_create() | ||
77 | """ | ||
78 | parser = optparse.OptionParser(usage = usage_str) | ||
79 | |||
80 | parser.add_option("-o", "--outdir", dest = "outdir", | ||
81 | action = "store", help = "name of directory to create image in") | ||
82 | parser.add_option("-i", "--infile", dest = "properties_file", | ||
83 | action = "store", help = "name of file containing the values for image properties as a JSON file") | ||
84 | parser.add_option("-e", "--image-name", dest = "image_name", | ||
85 | action = "store", help = "name of the image to use the artifacts from e.g. core-image-sato") | ||
86 | parser.add_option("-r", "--rootfs-dir", dest = "rootfs_dir", | ||
87 | action = "callback", callback = callback_rootfs_dir, type = "string", | ||
88 | help = "path to the /rootfs dir to use as the .wks rootfs source") | ||
89 | parser.add_option("-b", "--bootimg-dir", dest = "bootimg_dir", | ||
90 | action = "store", help = "path to the dir containing the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the .wks bootimg source") | ||
91 | parser.add_option("-k", "--kernel-dir", dest = "kernel_dir", | ||
92 | action = "store", help = "path to the dir containing the kernel to use in the .wks bootimg") | ||
93 | parser.add_option("-n", "--native-sysroot", dest = "native_sysroot", | ||
94 | action = "store", help = "path to the native sysroot containing the tools to use to build the image") | ||
95 | parser.add_option("-p", "--skip-build-check", dest = "build_check", | ||
96 | action = "store_false", default = True, help = "skip the build check") | ||
97 | parser.add_option("-D", "--debug", dest = "debug", action = "store_true", | ||
98 | default = False, help = "output debug information") | ||
99 | |||
100 | (options, args) = parser.parse_args(args) | ||
101 | |||
102 | if options.debug: | ||
103 | loglevel = logging.DEBUG | ||
104 | start_logging(loglevel) | ||
105 | |||
106 | if len(args) != 1: | ||
107 | logging.error("Wrong number of arguments, exiting\n") | ||
108 | parser.print_help() | ||
109 | sys.exit(1) | ||
110 | |||
111 | if not options.image_name and not (options.rootfs_dir and | ||
112 | options.bootimg_dir and | ||
113 | options.kernel_dir and | ||
114 | options.native_sysroot or | ||
115 | options.native_sysroot): | ||
116 | print "Build artifacts not completely specified, exiting." | ||
117 | print " (Use 'wic -e' or 'wic -r -b -k -n' or 'wic -r -n' to specify artifacts)" | ||
118 | print options | ||
119 | sys.exit(1) | ||
120 | |||
121 | if not options.image_name: | ||
122 | options.build_check = False | ||
123 | |||
124 | if options.build_check and not options.properties_file: | ||
125 | print "Checking basic build environment..." | ||
126 | if not verify_build_env(): | ||
127 | print "Couldn't verify build environment, exiting\n" | ||
128 | sys.exit(1) | ||
129 | else: | ||
130 | print "Done.\n" | ||
131 | |||
132 | print "Creating image(s)...\n" | ||
133 | |||
134 | # If '-e' option is used the values are extracted from bitbake env. | ||
135 | if options.image_name: | ||
136 | bitbake_env_lines = find_bitbake_env_lines(options.image_name) | ||
137 | if not bitbake_env_lines: | ||
138 | print "Couldn't get bitbake environment, exiting." | ||
139 | sys.exit(1) | ||
140 | set_bitbake_env_lines(bitbake_env_lines) | ||
141 | |||
142 | bootimg_dir = "" | ||
143 | rootfs_dir = native_sysroot = kernel_dir = image_output_dir = "" | ||
144 | |||
145 | if options.image_name: | ||
146 | (rootfs_dir, kernel_dir, bootimg_dir, native_sysroot) \ | ||
147 | = find_artifacts(options.image_name) | ||
148 | |||
149 | wks_file = args[0] | ||
150 | |||
151 | if not wks_file.endswith(".wks"): | ||
152 | # Return full path of the .wks file | ||
153 | wks_file = find_canned_image(scripts_path, wks_file) | ||
154 | if not wks_file: | ||
155 | print "No image named %s found, exiting.\n" % wks_file | ||
156 | print "(Use 'wic list images' to list available images, or specify a fully-qualified OE kickstart (.wks) filename)\n" | ||
157 | sys.exit(1) | ||
158 | |||
159 | if options.outdir: | ||
160 | image_output_dir = options.outdir | ||
161 | |||
162 | if options.native_sysroot: | ||
163 | native_sysroot = options.native_sysroot | ||
164 | print "Using native_sysroot from user command: %s" % native_sysroot | ||
165 | |||
166 | if not os.path.isdir(native_sysroot): | ||
167 | print "--native-sysroot (-n) not found, exiting" | ||
168 | sys.exit(1) | ||
169 | |||
170 | native_sysroot = os.path.abspath(native_sysroot) | ||
171 | |||
172 | if not options.image_name: | ||
173 | if (options.bootimg_dir and options.kernel_dir and | ||
174 | options.rootfs_dir and options.native_sysroot): | ||
175 | rootfs_dir = '' | ||
176 | if 'ROOTFS_DIR' in options.rootfs_dir: | ||
177 | rootfs_dir = options.rootfs_dir['ROOTFS_DIR'] | ||
178 | bootimg_dir = options.bootimg_dir | ||
179 | kernel_dir = options.kernel_dir | ||
180 | native_sysroot = options.native_sysroot | ||
181 | |||
182 | if rootfs_dir and not os.path.isdir(rootfs_dir): | ||
183 | print "--roofs-dir (-r) not found, exiting\n" | ||
184 | sys.exit(1) | ||
185 | if not os.path.isdir(bootimg_dir): | ||
186 | print "--bootimg-dir (-b) not found, exiting\n" | ||
187 | sys.exit(1) | ||
188 | if not os.path.isdir(kernel_dir): | ||
189 | print "--kernel-dir (-k) not found, exiting\n" | ||
190 | sys.exit(1) | ||
191 | if not os.path.isdir(native_sysroot): | ||
192 | print "--native-sysroot (-n) not found, exiting\n" | ||
193 | sys.exit(1) | ||
194 | else: | ||
195 | print 'Build image from rootfs and a package list using native rootfs\n' | ||
196 | if options.rootfs_dir and 'ROOTFS_DIR' in options.rootfs_dir: | ||
197 | rootfs_dir = options.rootfs_dir['ROOTFS_DIR'] | ||
198 | elif options.rootfs_dir: | ||
199 | rootfs_dir = options.rootfs_dir | ||
200 | else: | ||
201 | rootfs_dir = "" | ||
202 | |||
203 | native_sysroot = options.native_sysroot | ||
204 | |||
205 | if rootfs_dir and not os.path.isdir(rootfs_dir): | ||
206 | print "--roofs-dir (-r) not found, exiting\n" | ||
207 | sys.exit(1) | ||
208 | if not os.path.isdir(native_sysroot): | ||
209 | print "--native-sysroot (-n) not found, exiting\n" | ||
210 | sys.exit(1) | ||
211 | else: | ||
212 | not_found = not_found_dir = "" | ||
213 | if not os.path.isdir(rootfs_dir): | ||
214 | (not_found, not_found_dir) = ("rootfs-dir", rootfs_dir) | ||
215 | elif not os.path.isdir(kernel_dir): | ||
216 | (not_found, not_found_dir) = ("kernel-dir", kernel_dir) | ||
217 | elif not os.path.isdir(native_sysroot): | ||
218 | (not_found, not_found_dir) = ("native-sysroot", native_sysroot) | ||
219 | if not_found: | ||
220 | if not not_found_dir: | ||
221 | not_found_dir = "Completely missing artifact - wrong image (.wks) used?" | ||
222 | print "Build artifacts not found, exiting." | ||
223 | print " (Please check that the build artifacts for the machine" | ||
224 | print " selected in local.conf actually exist and that they" | ||
225 | print " are the correct artifacts for the image (.wks file)).\n" | ||
226 | print "The artifact that couldn't be found was %s:\n %s" % \ | ||
227 | (not_found, not_found_dir) | ||
228 | sys.exit(1) | ||
229 | |||
230 | krootfs_dir = options.rootfs_dir | ||
231 | if krootfs_dir is None: | ||
232 | krootfs_dir = {} | ||
233 | krootfs_dir['ROOTFS_DIR'] = rootfs_dir | ||
234 | |||
235 | rootfs_dir = rootfs_dir_to_args(krootfs_dir) | ||
236 | |||
237 | wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir, | ||
238 | native_sysroot, scripts_path, image_output_dir, | ||
239 | options.debug, options.properties_file) | ||
240 | |||
241 | |||
242 | def wic_list_subcommand(args, usage_str): | ||
243 | """ | ||
244 | Command-line handling for listing available image properties and | ||
245 | values. The real work is done by image.engine.wic_list() | ||
246 | """ | ||
247 | parser = optparse.OptionParser(usage = usage_str) | ||
248 | |||
249 | parser.add_option("-o", "--outfile", action = "store", | ||
250 | dest = "properties_file", | ||
251 | help = "dump the possible values for image properties to a JSON file") | ||
252 | |||
253 | (options, args) = parser.parse_args(args) | ||
254 | |||
255 | bitbake_env_lines = find_bitbake_env_lines(None) | ||
256 | if not bitbake_env_lines: | ||
257 | print "Couldn't get bitbake environment, exiting." | ||
258 | sys.exit(1) | ||
259 | set_bitbake_env_lines(bitbake_env_lines) | ||
260 | |||
261 | if not wic_list(args, scripts_path, options.properties_file): | ||
262 | logging.error("Bad list arguments, exiting\n") | ||
263 | parser.print_help() | ||
264 | sys.exit(1) | ||
265 | |||
266 | |||
267 | def wic_help_topic_subcommand(args, usage_str): | ||
268 | """ | ||
269 | Command-line handling for help-only 'subcommands'. This is | ||
270 | essentially a dummy command that doesn nothing but allow users to | ||
271 | use the existing subcommand infrastructure to display help on a | ||
272 | particular topic not attached to any particular subcommand. | ||
273 | """ | ||
274 | pass | ||
275 | |||
276 | |||
277 | wic_help_topic_usage = """ | ||
278 | """ | ||
279 | |||
280 | subcommands = { | ||
281 | "create": [wic_create_subcommand, | ||
282 | wic_create_usage, | ||
283 | wic_create_help], | ||
284 | "list": [wic_list_subcommand, | ||
285 | wic_list_usage, | ||
286 | wic_list_help], | ||
287 | "plugins": [wic_help_topic_subcommand, | ||
288 | wic_help_topic_usage, | ||
289 | wic_plugins_help], | ||
290 | "overview": [wic_help_topic_subcommand, | ||
291 | wic_help_topic_usage, | ||
292 | wic_overview_help], | ||
293 | "kickstart": [wic_help_topic_subcommand, | ||
294 | wic_help_topic_usage, | ||
295 | wic_kickstart_help], | ||
296 | } | ||
297 | |||
298 | |||
299 | def start_logging(loglevel): | ||
300 | logging.basicConfig(filname = 'wic.log', filemode = 'w', level=loglevel) | ||
301 | |||
302 | |||
303 | def main(): | ||
304 | parser = optparse.OptionParser(version = "wic version %s" % __version__, | ||
305 | usage = wic_usage) | ||
306 | |||
307 | parser.disable_interspersed_args() | ||
308 | |||
309 | (options, args) = parser.parse_args() | ||
310 | |||
311 | if len(args): | ||
312 | if args[0] == "help": | ||
313 | if len(args) == 1: | ||
314 | parser.print_help() | ||
315 | sys.exit(1) | ||
316 | |||
317 | invoke_subcommand(args, parser, wic_help_usage, subcommands) | ||
318 | |||
319 | |||
320 | if __name__ == "__main__": | ||
321 | try: | ||
322 | ret = main() | ||
323 | except Exception: | ||
324 | ret = 1 | ||
325 | import traceback | ||
326 | traceback.print_exc(5) | ||
327 | sys.exit(ret) | ||
328 | |||