yocto-kernel 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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) 2012, 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
  22. # 'yocto-kernel' is the Yocto BSP Tool that helps users manage kernel
  23. # config options and patches for a Yocto BSP. Invoking it without any
  24. # arguments will display help screens for the 'yocto-kernel' command
  25. # and list the available 'yocto-kernel' subcommands. Invoking a
  26. # subcommand without any arguments will likewise display help screens
  27. # for the specified subcommand. Please use that interface for
  28. # detailed help.
  29. #
  30. # AUTHORS
  31. # Tom Zanussi <tom.zanussi (at] intel.com>
  32. #
  33. __version__ = "0.1.0"
  34. import os
  35. import sys
  36. import optparse
  37. import logging
  38. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  39. lib_path = scripts_path + '/lib'
  40. sys.path = sys.path + [lib_path]
  41. from bsp.help import *
  42. from bsp.kernel import *
  43. def yocto_kernel_config_list_subcommand(args, usage_str):
  44. """
  45. Command-line handling for listing BSP config options. The
  46. real work is done by bsp.kernel.yocto_kernel_config_list().
  47. """
  48. logging.debug("yocto_kernel_config_list_subcommand")
  49. parser = optparse.OptionParser(usage = usage_str)
  50. (options, args) = parser.parse_args(args)
  51. if len(args) != 1:
  52. logging.error("Wrong number of arguments, exiting\n")
  53. parser.print_help()
  54. sys.exit(1)
  55. yocto_kernel_config_list(scripts_path, args[0])
  56. def yocto_kernel_config_add_subcommand(args, usage_str):
  57. """
  58. Command-line handling for adding BSP config items. The real work
  59. is done by bsp.kernel.yocto_kernel_config_add().
  60. """
  61. logging.debug("yocto_kernel_config_add_subcommand")
  62. parser = optparse.OptionParser(usage = usage_str)
  63. (options, args) = parser.parse_args(args)
  64. if len(args) < 2:
  65. logging.error("Wrong number of arguments, exiting\n")
  66. parser.print_help()
  67. sys.exit(1)
  68. machine = args.pop(0)
  69. yocto_kernel_config_add(scripts_path, machine, args)
  70. def yocto_kernel_config_rm_subcommand(args, usage_str):
  71. """
  72. Command-line handling for removing BSP config items. The real
  73. work is done by bsp.kernel.yocto_kernel_config_rm().
  74. """
  75. logging.debug("yocto_kernel_config_rm_subcommand")
  76. parser = optparse.OptionParser(usage = usage_str)
  77. (options, args) = parser.parse_args(args)
  78. if len(args) != 1:
  79. logging.error("Wrong number of arguments, exiting\n")
  80. parser.print_help()
  81. sys.exit(1)
  82. yocto_kernel_config_rm(scripts_path, args[0])
  83. def yocto_kernel_patch_list_subcommand(args, usage_str):
  84. """
  85. Command-line handling for listing BSP (SRC_URI patches. The real
  86. work is done by bsp.kernel.yocto_kernel_patch_list().
  87. """
  88. logging.debug("yocto_kernel_patch_list_subcommand")
  89. parser = optparse.OptionParser(usage = usage_str)
  90. (options, args) = parser.parse_args(args)
  91. if len(args) != 1:
  92. logging.error("Wrong number of arguments, exiting\n")
  93. parser.print_help()
  94. sys.exit(1)
  95. yocto_kernel_patch_list(scripts_path, args[0])
  96. def yocto_kernel_patch_add_subcommand(args, usage_str):
  97. """
  98. Command-line handling for adding BSP patches. The real work is
  99. done by bsp.kernel.yocto_kernel_patch_add().
  100. """
  101. logging.debug("yocto_kernel_patch_add_subcommand")
  102. parser = optparse.OptionParser(usage = usage_str)
  103. (options, args) = parser.parse_args(args)
  104. if len(args) < 2:
  105. logging.error("Wrong number of arguments, exiting\n")
  106. parser.print_help()
  107. sys.exit(1)
  108. machine = args.pop(0)
  109. yocto_kernel_patch_add(scripts_path, machine, args)
  110. def yocto_kernel_patch_rm_subcommand(args, usage_str):
  111. """
  112. Command-line handling for removing BSP patches. The real work is
  113. done by bsp.kernel.yocto_kernel_patch_rm().
  114. """
  115. logging.debug("yocto_kernel_patch_rm_subcommand")
  116. parser = optparse.OptionParser(usage = usage_str)
  117. (options, args) = parser.parse_args(args)
  118. if len(args) != 1:
  119. logging.error("Wrong number of arguments, exiting\n")
  120. parser.print_help()
  121. sys.exit(1)
  122. yocto_kernel_patch_rm(scripts_path, args[0])
  123. def yocto_kernel_feature_list_subcommand(args, usage_str):
  124. """
  125. Command-line handling for listing the BSP features that are being
  126. used by the BSP. The real work is done by
  127. bsp.kernel.yocto_kernel_feature_list().
  128. """
  129. logging.debug("yocto_kernel_feature_list_subcommand")
  130. parser = optparse.OptionParser(usage = usage_str)
  131. (options, args) = parser.parse_args(args)
  132. if len(args) != 1:
  133. logging.error("Wrong number of arguments, exiting\n")
  134. parser.print_help()
  135. sys.exit(1)
  136. yocto_kernel_feature_list(scripts_path, args[0])
  137. def yocto_kernel_feature_add_subcommand(args, usage_str):
  138. """
  139. Command-line handling for adding the use of kernel features to a
  140. BSP. The real work is done by bsp.kernel.yocto_kernel_feature_add().
  141. """
  142. logging.debug("yocto_kernel_feature_add_subcommand")
  143. parser = optparse.OptionParser(usage = usage_str)
  144. (options, args) = parser.parse_args(args)
  145. if len(args) < 2:
  146. logging.error("Wrong number of arguments, exiting\n")
  147. parser.print_help()
  148. sys.exit(1)
  149. machine = args.pop(0)
  150. yocto_kernel_feature_add(scripts_path, machine, args)
  151. def yocto_kernel_feature_rm_subcommand(args, usage_str):
  152. """
  153. Command-line handling for removing the use of kernel features from
  154. a BSP. The real work is done by bsp.kernel.yocto_kernel_feature_rm().
  155. """
  156. logging.debug("yocto_kernel_feature_rm_subcommand")
  157. parser = optparse.OptionParser(usage = usage_str)
  158. (options, args) = parser.parse_args(args)
  159. if len(args) != 1:
  160. logging.error("Wrong number of arguments, exiting\n")
  161. parser.print_help()
  162. sys.exit(1)
  163. yocto_kernel_feature_rm(scripts_path, args[0])
  164. def yocto_kernel_available_features_list_subcommand(args, usage_str):
  165. """
  166. Command-line handling for listing all the kernel features
  167. available for use in a BSP. This includes the features present in
  168. the meta branch(es) of the pointed-to repo(s) as well as the local
  169. features added in recipe-space to the current BSP as well. The
  170. real work is done by bsp.kernel.yocto_kernel_available_features_list().
  171. """
  172. logging.debug("yocto_kernel_feature_available_features_list_subcommand")
  173. parser = optparse.OptionParser(usage = usage_str)
  174. (options, args) = parser.parse_args(args)
  175. if len(args) != 1:
  176. logging.error("Wrong number of arguments, exiting\n")
  177. parser.print_help()
  178. sys.exit(1)
  179. yocto_kernel_available_features_list(scripts_path, args[0])
  180. def yocto_kernel_feature_describe_subcommand(args, usage_str):
  181. """
  182. Command-line handling for listing the description of a specific
  183. kernel feature available for use in a BSP. This includes the
  184. features present in the meta branch(es) of the pointed-to repo(s)
  185. as well as the local features added in recipe-space to the current
  186. BSP as well. The real work is done by
  187. bsp.kernel.yocto_kernel_feature_describe().
  188. """
  189. logging.debug("yocto_kernel_feature_describe_subcommand")
  190. parser = optparse.OptionParser(usage = usage_str)
  191. (options, args) = parser.parse_args(args)
  192. if len(args) != 2:
  193. logging.error("Wrong number of arguments, exiting\n")
  194. parser.print_help()
  195. sys.exit(1)
  196. yocto_kernel_feature_describe(scripts_path, args[0], args[1])
  197. def yocto_kernel_feature_create_subcommand(args, usage_str):
  198. """
  199. Command-line handling for creating a recipe-space kernel feature
  200. in a BSP. The real work is done by
  201. bsp.kernel.yocto_kernel_feature_create().
  202. """
  203. logging.debug("yocto_kernel_feature_create_subcommand")
  204. parser = optparse.OptionParser(usage = usage_str)
  205. (options, args) = parser.parse_args(args)
  206. if len(args) < 4:
  207. logging.error("Wrong number of arguments, exiting\n")
  208. parser.print_help()
  209. sys.exit(1)
  210. machine = args.pop(0)
  211. yocto_kernel_feature_create(scripts_path, machine, args)
  212. def yocto_kernel_feature_destroy_subcommand(args, usage_str):
  213. """
  214. Command-line handling for removing a recipe-space kernel feature
  215. from a BSP. The real work is done by
  216. bsp.kernel.yocto_kernel_feature_destroy().
  217. """
  218. logging.debug("yocto_kernel_feature_destroy_subcommand")
  219. parser = optparse.OptionParser(usage = usage_str)
  220. (options, args) = parser.parse_args(args)
  221. if len(args) != 2:
  222. logging.error("Wrong number of arguments, exiting\n")
  223. parser.print_help()
  224. sys.exit(1)
  225. yocto_kernel_feature_destroy(scripts_path, args[0], args[1])
  226. subcommands = {
  227. "config-list": [yocto_kernel_config_list_subcommand,
  228. yocto_kernel_config_list_usage,
  229. yocto_kernel_config_list_help],
  230. "config-add": [yocto_kernel_config_add_subcommand,
  231. yocto_kernel_config_add_usage,
  232. yocto_kernel_config_add_help],
  233. "config-rm": [yocto_kernel_config_rm_subcommand,
  234. yocto_kernel_config_rm_usage,
  235. yocto_kernel_config_rm_help],
  236. "patch-list": [yocto_kernel_patch_list_subcommand,
  237. yocto_kernel_patch_list_usage,
  238. yocto_kernel_patch_list_help],
  239. "patch-add": [yocto_kernel_patch_add_subcommand,
  240. yocto_kernel_patch_add_usage,
  241. yocto_kernel_patch_add_help],
  242. "patch-rm": [yocto_kernel_patch_rm_subcommand,
  243. yocto_kernel_patch_rm_usage,
  244. yocto_kernel_patch_rm_help],
  245. "feature-list": [yocto_kernel_feature_list_subcommand,
  246. yocto_kernel_feature_list_usage,
  247. yocto_kernel_feature_list_help],
  248. "feature-add": [yocto_kernel_feature_add_subcommand,
  249. yocto_kernel_feature_add_usage,
  250. yocto_kernel_feature_add_help],
  251. "feature-rm": [yocto_kernel_feature_rm_subcommand,
  252. yocto_kernel_feature_rm_usage,
  253. yocto_kernel_feature_rm_help],
  254. "features-list": [yocto_kernel_available_features_list_subcommand,
  255. yocto_kernel_available_features_list_usage,
  256. yocto_kernel_available_features_list_help],
  257. "feature-describe": [yocto_kernel_feature_describe_subcommand,
  258. yocto_kernel_feature_describe_usage,
  259. yocto_kernel_feature_describe_help],
  260. "feature-create": [yocto_kernel_feature_create_subcommand,
  261. yocto_kernel_feature_create_usage,
  262. yocto_kernel_feature_create_help],
  263. "feature-destroy": [yocto_kernel_feature_destroy_subcommand,
  264. yocto_kernel_feature_destroy_usage,
  265. yocto_kernel_feature_destroy_help],
  266. }
  267. def start_logging(loglevel):
  268. logging.basicConfig(filname = 'yocto-kernel.log', filemode = 'w', level=loglevel)
  269. def main():
  270. parser = optparse.OptionParser(version = "yocto-kernel version %s" % __version__,
  271. usage = yocto_kernel_usage)
  272. parser.disable_interspersed_args()
  273. parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
  274. default = False, help = "output debug information")
  275. (options, args) = parser.parse_args()
  276. loglevel = logging.INFO
  277. if options.debug:
  278. loglevel = logging.DEBUG
  279. start_logging(loglevel)
  280. if len(args):
  281. if args[0] == "help":
  282. if len(args) == 1:
  283. parser.print_help()
  284. sys.exit(1)
  285. sc = 1
  286. else:
  287. sc = 0
  288. if args[sc] == "config" or args[sc] == "patch" or \
  289. args[sc] == "feature" or args[sc] == "features":
  290. if len(args) < 2 + sc:
  291. parser.print_help()
  292. sys.exit(1)
  293. args[sc] += "-" + args[sc + 1]
  294. args.pop(sc + 1)
  295. invoke_subcommand(args, parser, yocto_kernel_help_usage, subcommands)
  296. if __name__ == "__main__":
  297. try:
  298. ret = main()
  299. except Exception:
  300. ret = 1
  301. import traceback
  302. traceback.print_exc(5)
  303. sys.exit(ret)