1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# Copyright (c) 2012, Intel Corporation.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# DESCRIPTION
# 'yocto-kernel' is the Yocto BSP Tool that helps users manage kernel
# config options and patches for a Yocto BSP. Invoking it without any
# arguments will display help screens for the 'yocto-kernel' command
# and list the available 'yocto-kernel' subcommands. Invoking a
# subcommand without any arguments will likewise display help screens
# for the specified subcommand. Please use that interface for
# detailed help.
#
# AUTHORS
# Tom Zanussi <tom.zanussi (at] intel.com>
#
__version__ = "0.1.0"
import os
import sys
import optparse
import logging
scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
lib_path = scripts_path + '/lib'
sys.path = sys.path + [lib_path]
from bsp.help import *
from bsp.kernel import *
def yocto_kernel_config_list_subcommand(args, usage_str):
"""
Command-line handling for listing BSP config options. The
real work is done by bsp.kernel.yocto_kernel_config_list().
"""
logging.debug("yocto_kernel_config_list_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 1:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_config_list(scripts_path, args[0])
def yocto_kernel_config_add_subcommand(args, usage_str):
"""
Command-line handling for adding BSP config items. The real work
is done by bsp.kernel.yocto_kernel_config_add().
"""
logging.debug("yocto_kernel_config_add_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) < 2:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
machine = args.pop(0)
yocto_kernel_config_add(scripts_path, machine, args)
def yocto_kernel_config_rm_subcommand(args, usage_str):
"""
Command-line handling for removing BSP config items. The real
work is done by bsp.kernel.yocto_kernel_config_rm().
"""
logging.debug("yocto_kernel_config_rm_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 1:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_config_rm(scripts_path, args[0])
def yocto_kernel_patch_list_subcommand(args, usage_str):
"""
Command-line handling for listing BSP (SRC_URI patches. The real
work is done by bsp.kernel.yocto_kernel_patch_list().
"""
logging.debug("yocto_kernel_patch_list_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 1:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_patch_list(scripts_path, args[0])
def yocto_kernel_patch_add_subcommand(args, usage_str):
"""
Command-line handling for adding BSP patches. The real work is
done by bsp.kernel.yocto_kernel_patch_add().
"""
logging.debug("yocto_kernel_patch_add_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) < 2:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
machine = args.pop(0)
yocto_kernel_patch_add(scripts_path, machine, args)
def yocto_kernel_patch_rm_subcommand(args, usage_str):
"""
Command-line handling for removing BSP patches. The real work is
done by bsp.kernel.yocto_kernel_patch_rm().
"""
logging.debug("yocto_kernel_patch_rm_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 1:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_patch_rm(scripts_path, args[0])
def yocto_kernel_feature_list_subcommand(args, usage_str):
"""
Command-line handling for listing the BSP features that are being
used by the BSP. The real work is done by
bsp.kernel.yocto_kernel_feature_list().
"""
logging.debug("yocto_kernel_feature_list_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 1:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_feature_list(scripts_path, args[0])
def yocto_kernel_feature_add_subcommand(args, usage_str):
"""
Command-line handling for adding the use of kernel features to a
BSP. The real work is done by bsp.kernel.yocto_kernel_feature_add().
"""
logging.debug("yocto_kernel_feature_add_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) < 2:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
machine = args.pop(0)
yocto_kernel_feature_add(scripts_path, machine, args)
def yocto_kernel_feature_rm_subcommand(args, usage_str):
"""
Command-line handling for removing the use of kernel features from
a BSP. The real work is done by bsp.kernel.yocto_kernel_feature_rm().
"""
logging.debug("yocto_kernel_feature_rm_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 1:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_feature_rm(scripts_path, args[0])
def yocto_kernel_available_features_list_subcommand(args, usage_str):
"""
Command-line handling for listing all the kernel features
available for use in a BSP. This includes the features present in
the meta branch(es) of the pointed-to repo(s) as well as the local
features added in recipe-space to the current BSP as well. The
real work is done by bsp.kernel.yocto_kernel_available_features_list().
"""
logging.debug("yocto_kernel_feature_available_features_list_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 1:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_available_features_list(scripts_path, args[0])
def yocto_kernel_feature_describe_subcommand(args, usage_str):
"""
Command-line handling for listing the description of a specific
kernel feature available for use in a BSP. This includes the
features present in the meta branch(es) of the pointed-to repo(s)
as well as the local features added in recipe-space to the current
BSP as well. The real work is done by
bsp.kernel.yocto_kernel_feature_describe().
"""
logging.debug("yocto_kernel_feature_describe_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) != 2:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
yocto_kernel_feature_describe(scripts_path, args[0], args[1])
def yocto_kernel_feature_create_subcommand(args, usage_str):
"""
Command-line handling for creating a recipe-space kernel feature
in a BSP. The real work is done by
bsp.kernel.yocto_kernel_feature_create().
"""
logging.debug("yocto_kernel_feature_create_subcommand")
parser = optparse.OptionParser(usage = usage_str)
(options, args) = parser.parse_args(args)
if len(args) < 4:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
machine = args.pop(0)
yocto_kernel_feature_create(scripts_path, machine, args)
subcommands = {
"config-list": [yocto_kernel_config_list_subcommand,
yocto_kernel_config_list_usage,
yocto_kernel_config_list_help],
"config-add": [yocto_kernel_config_add_subcommand,
yocto_kernel_config_add_usage,
yocto_kernel_config_add_help],
"config-rm": [yocto_kernel_config_rm_subcommand,
yocto_kernel_config_rm_usage,
yocto_kernel_config_rm_help],
"patch-list": [yocto_kernel_patch_list_subcommand,
yocto_kernel_patch_list_usage,
yocto_kernel_patch_list_help],
"patch-add": [yocto_kernel_patch_add_subcommand,
yocto_kernel_patch_add_usage,
yocto_kernel_patch_add_help],
"patch-rm": [yocto_kernel_patch_rm_subcommand,
yocto_kernel_patch_rm_usage,
yocto_kernel_patch_rm_help],
"feature-list": [yocto_kernel_feature_list_subcommand,
yocto_kernel_feature_list_usage,
yocto_kernel_feature_list_help],
"feature-add": [yocto_kernel_feature_add_subcommand,
yocto_kernel_feature_add_usage,
yocto_kernel_feature_add_help],
"feature-rm": [yocto_kernel_feature_rm_subcommand,
yocto_kernel_feature_rm_usage,
yocto_kernel_feature_rm_help],
"features-list": [yocto_kernel_available_features_list_subcommand,
yocto_kernel_available_features_list_usage,
yocto_kernel_available_features_list_help],
"feature-describe": [yocto_kernel_feature_describe_subcommand,
yocto_kernel_feature_describe_usage,
yocto_kernel_feature_describe_help],
"feature-create": [yocto_kernel_feature_create_subcommand,
yocto_kernel_feature_create_usage,
yocto_kernel_feature_create_help],
}
def start_logging(loglevel):
logging.basicConfig(filname = 'yocto-kernel.log', filemode = 'w', level=loglevel)
def main():
parser = optparse.OptionParser(version = "yocto-kernel version %s" % __version__,
usage = yocto_kernel_usage)
parser.disable_interspersed_args()
parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
default = False, help = "output debug information")
(options, args) = parser.parse_args()
loglevel = logging.INFO
if options.debug:
loglevel = logging.DEBUG
start_logging(loglevel)
if len(args):
if args[0] == "help":
if len(args) == 1:
parser.print_help()
sys.exit(1)
sc = 1
else:
sc = 0
if args[sc] == "config" or args[sc] == "patch" or \
args[sc] == "feature" or args[sc] == "features":
if len(args) < 2 + sc:
parser.print_help()
sys.exit(1)
args[sc] += "-" + args[sc + 1]
args.pop(sc + 1)
invoke_subcommand(args, parser, yocto_kernel_help_usage, subcommands)
if __name__ == "__main__":
try:
ret = main()
except Exception:
ret = 1
import traceback
traceback.print_exc(5)
sys.exit(ret)
|