diff options
Diffstat (limited to 'scripts/wic')
-rwxr-xr-x | scripts/wic | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/scripts/wic b/scripts/wic new file mode 100755 index 0000000000..06e72bbfda --- /dev/null +++ b/scripts/wic | |||
@@ -0,0 +1,185 @@ | |||
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 | import os | ||
35 | import sys | ||
36 | import optparse | ||
37 | import logging | ||
38 | |||
39 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) | ||
40 | lib_path = scripts_path + '/lib' | ||
41 | sys.path = sys.path + [lib_path] | ||
42 | |||
43 | from image.help import * | ||
44 | from image.engine import * | ||
45 | |||
46 | |||
47 | def wic_create_subcommand(args, usage_str): | ||
48 | """ | ||
49 | Command-line handling for image creation. The real work is done | ||
50 | by image.engine.wic_create() | ||
51 | """ | ||
52 | parser = optparse.OptionParser(usage = usage_str) | ||
53 | |||
54 | parser.add_option("-o", "--outdir", dest = "outdir", | ||
55 | action = "store", help = "name of directory to create image in") | ||
56 | parser.add_option("-i", "--infile", dest = "properties_file", | ||
57 | action = "store", help = "name of file containing the values for image properties as a JSON file") | ||
58 | parser.add_option("-e", "--image-name", dest = "image_name", | ||
59 | action = "store", help = "name of the image to use the artifacts from e.g. core-image-sato") | ||
60 | parser.add_option("-r", "--rootfs-dir", dest = "rootfs_dir", | ||
61 | action = "store", help = "path to the /rootfs dir to use as the .wks rootfs source") | ||
62 | parser.add_option("-b", "--bootimg-dir", dest = "bootimg_dir", | ||
63 | action = "store", help = "path to the dir containing the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the .wks bootimg source") | ||
64 | parser.add_option("-k", "--kernel-dir", dest = "kernel_dir", | ||
65 | action = "store", help = "path to the dir containing the kernel to use in the .wks bootimg") | ||
66 | parser.add_option("-n", "--native-sysroot", dest = "native_sysroot", | ||
67 | action = "store", help = "path to the native sysroot containing the tools to use to build the image") | ||
68 | parser.add_option("-p", "--skip-build-check", dest = "build_check", | ||
69 | action = "store_false", default = True, help = "skip the build check") | ||
70 | |||
71 | (options, args) = parser.parse_args(args) | ||
72 | |||
73 | if len(args) != 1: | ||
74 | logging.error("Wrong number of arguments, exiting\n") | ||
75 | parser.print_help() | ||
76 | sys.exit(1) | ||
77 | |||
78 | if not options.image_name: | ||
79 | options.build_check = False | ||
80 | |||
81 | if options.build_check and not options.properties_file: | ||
82 | print "Checking basic build environment..." | ||
83 | if not verify_build_env(): | ||
84 | print "Couldn't verify build environment, exiting\n" | ||
85 | sys.exit(1) | ||
86 | else: | ||
87 | print "Done.\n" | ||
88 | |||
89 | print "Creating image(s)...\n" | ||
90 | |||
91 | bootimg_dir = staging_data_dir = hdddir = "" | ||
92 | |||
93 | if options.image_name: | ||
94 | (rootfs_dir, kernel_dir, hdddir, staging_data_dir, native_sysroot) = \ | ||
95 | find_artifacts(options.image_name) | ||
96 | |||
97 | wks_file = args[0] | ||
98 | |||
99 | if not wks_file.endswith(".wks"): | ||
100 | wks_file = find_canned_image(scripts_path, wks_file) | ||
101 | if not wks_file: | ||
102 | print "No image named %s found, exiting. (Use 'wic list images' to list available images, or specify a fully-qualified OE kickstart (.wks) filename)\n" % wks_file | ||
103 | sys.exit(1) | ||
104 | |||
105 | image_output_dir = "" | ||
106 | if options.outdir: | ||
107 | image_output_dir = options.outdir | ||
108 | |||
109 | if not options.image_name: | ||
110 | rootfs_dir = options.rootfs_dir | ||
111 | bootimg_dir = options.bootimg_dir | ||
112 | kernel_dir = options.kernel_dir | ||
113 | native_sysroot = options.native_sysroot | ||
114 | |||
115 | wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir, | ||
116 | native_sysroot, hdddir, staging_data_dir, scripts_path, | ||
117 | image_output_dir, options.properties_file) | ||
118 | |||
119 | |||
120 | def wic_list_subcommand(args, usage_str): | ||
121 | """ | ||
122 | Command-line handling for listing available image properties and | ||
123 | values. The real work is done by image.engine.wic_list() | ||
124 | """ | ||
125 | parser = optparse.OptionParser(usage = usage_str) | ||
126 | |||
127 | parser.add_option("-o", "--outfile", action = "store", | ||
128 | dest = "properties_file", | ||
129 | help = "dump the possible values for image properties to a JSON file") | ||
130 | |||
131 | (options, args) = parser.parse_args(args) | ||
132 | |||
133 | if not wic_list(args, scripts_path, options.properties_file): | ||
134 | logging.error("Bad list arguments, exiting\n") | ||
135 | parser.print_help() | ||
136 | sys.exit(1) | ||
137 | |||
138 | |||
139 | subcommands = { | ||
140 | "create": [wic_create_subcommand, | ||
141 | wic_create_usage, | ||
142 | wic_create_help], | ||
143 | "list": [wic_list_subcommand, | ||
144 | wic_list_usage, | ||
145 | wic_list_help], | ||
146 | } | ||
147 | |||
148 | |||
149 | def start_logging(loglevel): | ||
150 | logging.basicConfig(filname = 'wic.log', filemode = 'w', level=loglevel) | ||
151 | |||
152 | |||
153 | def main(): | ||
154 | parser = optparse.OptionParser(version = "wic version %s" % __version__, | ||
155 | usage = wic_usage) | ||
156 | |||
157 | parser.disable_interspersed_args() | ||
158 | parser.add_option("-D", "--debug", dest = "debug", action = "store_true", | ||
159 | default = False, help = "output debug information") | ||
160 | |||
161 | (options, args) = parser.parse_args() | ||
162 | |||
163 | loglevel = logging.INFO | ||
164 | if options.debug: | ||
165 | loglevel = logging.DEBUG | ||
166 | start_logging(loglevel) | ||
167 | |||
168 | if len(args): | ||
169 | if args[0] == "help": | ||
170 | if len(args) == 1: | ||
171 | parser.print_help() | ||
172 | sys.exit(1) | ||
173 | |||
174 | invoke_subcommand(args, parser, wic_help_usage, subcommands) | ||
175 | |||
176 | |||
177 | if __name__ == "__main__": | ||
178 | try: | ||
179 | ret = main() | ||
180 | except Exception: | ||
181 | ret = 1 | ||
182 | import traceback | ||
183 | traceback.print_exc(5) | ||
184 | sys.exit(ret) | ||
185 | |||