help.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. # Copyright (c) 2012, Intel Corporation.
  5. # All rights reserved.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. # DESCRIPTION
  21. # This module implements some basic help invocation functions along
  22. # with the bulk of the help topic text for the Yocto BSP Tools.
  23. #
  24. # AUTHORS
  25. # Tom Zanussi <tom.zanussi (at] intel.com>
  26. #
  27. import subprocess
  28. import logging
  29. def subcommand_error(args):
  30. logging.info("invalid subcommand %s" % args[0])
  31. def display_help(subcommand, subcommands):
  32. """
  33. Display help for subcommand.
  34. """
  35. if subcommand not in subcommands:
  36. return False
  37. help = subcommands.get(subcommand, subcommand_error)[2]
  38. pager = subprocess.Popen('less', stdin=subprocess.PIPE)
  39. pager.communicate(help)
  40. return True
  41. def yocto_help(args, usage_str, subcommands):
  42. """
  43. Subcommand help dispatcher.
  44. """
  45. if len(args) == 1 or not display_help(args[1], subcommands):
  46. print(usage_str)
  47. def invoke_subcommand(args, parser, main_command_usage, subcommands):
  48. """
  49. Dispatch to subcommand handler borrowed from combo-layer.
  50. Should use argparse, but has to work in 2.6.
  51. """
  52. if not args:
  53. logging.error("No subcommand specified, exiting")
  54. parser.print_help()
  55. elif args[0] == "help":
  56. yocto_help(args, main_command_usage, subcommands)
  57. elif args[0] not in subcommands:
  58. logging.error("Unsupported subcommand %s, exiting\n" % (args[0]))
  59. parser.print_help()
  60. else:
  61. usage = subcommands.get(args[0], subcommand_error)[1]
  62. subcommands.get(args[0], subcommand_error)[0](args[1:], usage)
  63. ##
  64. # yocto-bsp help and usage strings
  65. ##
  66. yocto_bsp_usage = """
  67. Create a customized Yocto BSP layer.
  68. usage: yocto-bsp [--version] [--help] COMMAND [ARGS]
  69. Current 'yocto-bsp' commands are:
  70. create Create a new Yocto BSP
  71. list List available values for options and BSP properties
  72. See 'yocto-bsp help COMMAND' for more information on a specific command.
  73. """
  74. yocto_bsp_help_usage = """
  75. usage: yocto-bsp help <subcommand>
  76. This command displays detailed help for the specified subcommand.
  77. """
  78. yocto_bsp_create_usage = """
  79. Create a new Yocto BSP
  80. usage: yocto-bsp create <bsp-name> <karch> [-o <DIRNAME> | --outdir <DIRNAME>]
  81. [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
  82. This command creates a Yocto BSP based on the specified parameters.
  83. The new BSP will be a new Yocto BSP layer contained by default within
  84. the top-level directory specified as 'meta-bsp-name'. The -o option
  85. can be used to place the BSP layer in a directory with a different
  86. name and location.
  87. The value of the 'karch' parameter determines the set of files that
  88. will be generated for the BSP, along with the specific set of
  89. 'properties' that will be used to fill out the BSP-specific portions
  90. of the BSP. The possible values for the 'karch' paramter can be
  91. listed via 'yocto-bsp list karch'.
  92. """
  93. yocto_bsp_create_help = """
  94. NAME
  95. yocto-bsp create - Create a new Yocto BSP
  96. SYNOPSIS
  97. yocto-bsp create <bsp-name> <karch> [-o <DIRNAME> | --outdir <DIRNAME>]
  98. [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
  99. DESCRIPTION
  100. This command creates a Yocto BSP based on the specified
  101. parameters. The new BSP will be a new Yocto BSP layer contained
  102. by default within the top-level directory specified as
  103. 'meta-bsp-name'. The -o option can be used to place the BSP layer
  104. in a directory with a different name and location.
  105. The value of the 'karch' parameter determines the set of files
  106. that will be generated for the BSP, along with the specific set of
  107. 'properties' that will be used to fill out the BSP-specific
  108. portions of the BSP. The possible values for the 'karch' paramter
  109. can be listed via 'yocto-bsp list karch'.
  110. The BSP-specific properties that define the values that will be
  111. used to generate a particular BSP can be specified on the
  112. command-line using the -i option and supplying a JSON object
  113. consisting of the set of name:value pairs needed by the BSP.
  114. If the -i option is not used, the user will be interactively
  115. prompted for each of the required property values, which will then
  116. be used as values for BSP generation.
  117. The set of properties available for a given architecture can be
  118. listed using the 'yocto-bsp list' command.
  119. Specifying -c causes the Python code generated and executed to
  120. create the BSP to be dumped to the 'bspgen.out' file in the
  121. current directory, and is useful for debugging.
  122. NOTE: Once created, you should add your new layer to your
  123. bblayers.conf file in order for it to be subsquently seen and
  124. modified by the yocto-kernel tool.
  125. NOTE for x86- and x86_64-based BSPs: The generated BSP assumes the
  126. presence of the of the meta-intel layer, so you should also have a
  127. meta-intel layer present and added to your bblayers.conf as well.
  128. """
  129. yocto_bsp_list_usage = """
  130. usage: yocto-bsp list karch
  131. yocto-bsp list <karch> properties
  132. [-o <JSON PROPERTY FILE> | --outfile <JSON PROPERTY_FILE>]
  133. yocto-bsp list <karch> property <xxx>
  134. [-o <JSON PROPERTY FILE> | --outfile <JSON PROPERTY_FILE>]
  135. This command enumerates the complete set of possible values for a
  136. specified option or property needed by the BSP creation process.
  137. The first form enumerates all the possible values that exist and can
  138. be specified for the 'karch' parameter to the 'yocto bsp create'
  139. command.
  140. The second form enumerates all the possible properties that exist and
  141. must have values specified for them in the 'yocto bsp create' command
  142. for the given 'karch'.
  143. The third form enumerates all the possible values that exist and can
  144. be specified for any of the enumerable properties of the given
  145. 'karch' in the 'yocto bsp create' command.
  146. See 'yocto-bsp help list' for more details.
  147. """
  148. yocto_bsp_list_help = """
  149. NAME
  150. yocto-bsp list - List available values for options and BSP properties
  151. SYNOPSIS
  152. yocto-bsp list karch
  153. yocto-bsp list <karch> properties
  154. [--o <JSON PROPERTY FILE> | -outfile <JSON PROPERTY_FILE>]
  155. yocto-bsp list <karch> property <xxx>
  156. [--o <JSON PROPERTY FILE> | -outfile <JSON PROPERTY_FILE>]
  157. DESCRIPTION
  158. This command enumerates the complete set of possible values for a
  159. specified option or property needed by the BSP creation process.
  160. The first form enumerates all the possible values that exist and
  161. can be specified for the 'karch' parameter to the 'yocto bsp
  162. create' command. Example output for the 'list karch' command:
  163. $ yocto-bsp list karch
  164. Architectures available:
  165. arm
  166. powerpc
  167. i386
  168. mips
  169. x86_64
  170. qemu
  171. The second form enumerates all the possible properties that exist
  172. and must have values specified for them in the 'yocto bsp create'
  173. command for the given 'karch'. This command is mainly meant to
  174. allow the development user interface alternatives to the default
  175. text-based prompting interface. If the -o option is specified,
  176. the list of properties, in addition to being displayed, will be
  177. written to the specified file as a JSON object. In this case, the
  178. object will consist of the set of name:value pairs corresponding
  179. to the (possibly nested) dictionary of properties defined by the
  180. input statements used by the BSP. Some example output for the
  181. 'list properties' command:
  182. $ yocto-bsp list arm properties
  183. "touchscreen" : {
  184. "msg" : Does your BSP have a touchscreen? (y/N)
  185. "default" : n
  186. "type" : boolean
  187. }
  188. "uboot_loadaddress" : {
  189. "msg" : Please specify a value for UBOOT_LOADADDRESS.
  190. "default" : 0x80008000
  191. "type" : edit
  192. "prio" : 40
  193. }
  194. "kernel_choice" : {
  195. "prio" : 10
  196. "default" : linux-yocto_3.2
  197. "depends-on" : use_default_kernel
  198. "depends-on-val" : n
  199. "msg" : Please choose the kernel to use in this BSP =>
  200. "type" : choicelist
  201. "gen" : bsp.kernel.kernels
  202. }
  203. "if kernel_choice == "linux-yocto_3.0":" : {
  204. "base_kbranch_linux_yocto_3_0" : {
  205. "prio" : 20
  206. "default" : yocto/standard
  207. "depends-on" : new_kbranch_linux_yocto_3_0
  208. "depends-on-val" : y
  209. "msg" : Please choose a machine branch to base this BSP on =>
  210. "type" : choicelist
  211. "gen" : bsp.kernel.all_branches
  212. }
  213. .
  214. .
  215. .
  216. Each entry in the output consists of the name of the input element
  217. e.g. "touchscreen", followed by the properties defined for that
  218. element enclosed in braces. This information should provide
  219. sufficient information to create a complete user interface with.
  220. Two features of the scheme provide for conditional input. First,
  221. if a Python "if" statement appears in place of an input element
  222. name, the set of enclosed input elements apply and should be
  223. presented to the user only if the 'if' statement evaluates to
  224. true. The test in the if statement will always reference another
  225. input element in the list, which means that the element being
  226. tested should be presented to the user before the elements
  227. enclosed by the if block. Secondly, in a similar way, some
  228. elements contain "depends-on" and depends-on-val" tags, which mean
  229. that the affected input element should only be presented to the
  230. user if the element it depends on has already been presented to
  231. the user and the user has selected the specified value for that
  232. element.
  233. The third form enumerates all the possible values that exist and
  234. can be specified for any of the enumerable properties of the given
  235. 'karch' in the 'yocto bsp create' command. If the -o option is
  236. specified, the list of values for the given property, in addition
  237. to being displayed, will be written to the specified file as a
  238. JSON object. In this case, the object will consist of the set of
  239. name:value pairs corresponding to the array of property values
  240. associated with the property.
  241. $ yocto-bsp list i386 property xserver_choice
  242. ["xserver_vesa", "VESA xserver support"]
  243. ["xserver_emgd", "EMGD xserver support (proprietary)"]
  244. ["xserver_i915", "i915 xserver support"]
  245. $ yocto-bsp list arm property base_kbranch_linux_yocto_3_0
  246. Getting branches from remote repo git://git.yoctoproject.org/linux-yocto-3.0...
  247. ["yocto/base", "yocto/base"]
  248. ["yocto/eg20t", "yocto/eg20t"]
  249. ["yocto/emgd", "yocto/emgd"]
  250. ["yocto/emgd-1.10", "yocto/emgd-1.10"]
  251. ["yocto/gma500", "yocto/gma500"]
  252. ["yocto/pvr", "yocto/pvr"]
  253. ["yocto/standard/arm-versatile-926ejs", "yocto/standard/arm-versatile-926ejs"]
  254. ["yocto/standard/base", "yocto/standard/base"]
  255. ["yocto/standard/beagleboard", "yocto/standard/beagleboard"]
  256. ["yocto/standard/cedartrail", "yocto/standard/cedartrail"]
  257. .
  258. .
  259. .
  260. ["yocto/standard/qemu-ppc32", "yocto/standard/qemu-ppc32"]
  261. ["yocto/standard/routerstationpro", "yocto/standard/routerstationpro"]
  262. The third form as well is meant mainly for developers of
  263. alternative interfaces - it allows the developer to fetch the
  264. possible values for a given input element on-demand. This
  265. on-demand capability is especially valuable for elements that
  266. require relatively expensive remote operations to fulfill, such as
  267. the example that returns the set of branches available in a remote
  268. git tree above.
  269. """
  270. ##
  271. # yocto-kernel help and usage strings
  272. ##
  273. yocto_kernel_usage = """
  274. Modify and list Yocto BSP kernel config items and patches.
  275. usage: yocto-kernel [--version] [--help] COMMAND [ARGS]
  276. Current 'yocto-kernel' commands are:
  277. config list List the modifiable set of bare kernel config options for a BSP
  278. config add Add or modify bare kernel config options for a BSP
  279. config rm Remove bare kernel config options from a BSP
  280. patch list List the patches associated with a BSP
  281. patch add Patch the Yocto kernel for a BSP
  282. patch rm Remove patches from a BSP
  283. See 'yocto-kernel help COMMAND' for more information on a specific command.
  284. """
  285. yocto_kernel_help_usage = """
  286. usage: yocto-kernel help <subcommand>
  287. This command displays detailed help for the specified subcommand.
  288. """
  289. yocto_kernel_config_list_usage = """
  290. List the modifiable set of bare kernel config options for a BSP
  291. usage: yocto-kernel config list <bsp-name>
  292. This command lists the 'modifiable' config items for a BSP i.e. the
  293. items which are eligible for modification or removal by other
  294. yocto-kernel commands.
  295. 'modifiable' config items are the config items contained a BSP's
  296. user-config.cfg base config.
  297. """
  298. yocto_kernel_config_list_help = """
  299. NAME
  300. yocto-kernel config list - List the modifiable set of bare kernel
  301. config options for a BSP
  302. SYNOPSIS
  303. yocto-kernel config list <bsp-name>
  304. DESCRIPTION
  305. This command lists the 'modifiable' config items for a BSP
  306. i.e. the items which are eligible for modification or removal by
  307. other yocto-kernel commands.
  308. """
  309. yocto_kernel_config_add_usage = """
  310. Add or modify bare kernel config options for a BSP
  311. usage: yocto-kernel config add <bsp-name> [<CONFIG_XXX=x> ...]
  312. This command adds one or more CONFIG_XXX=x items to a BSP's user-config.cfg
  313. base config.
  314. """
  315. yocto_kernel_config_add_help = """
  316. NAME
  317. yocto-kernel config add - Add or modify bare kernel config options
  318. for a BSP
  319. SYNOPSIS
  320. yocto-kernel config add <bsp-name> [<CONFIG_XXX=x> ...]
  321. DESCRIPTION
  322. This command adds one or more CONFIG_XXX=x items to a BSP's
  323. foo.cfg base config.
  324. NOTE: It's up to the user to determine whether or not the config
  325. options being added make sense or not - this command does no
  326. sanity checking or verification of any kind to ensure that a
  327. config option really makes sense and will actually be set in in
  328. the final config. For example, if a config option depends on
  329. other config options, it will be turned off by kconfig if the
  330. other options aren't set correctly.
  331. """
  332. yocto_kernel_config_rm_usage = """
  333. Remove bare kernel config options from a BSP
  334. usage: yocto-kernel config rm <bsp-name>
  335. This command removes (turns off) one or more CONFIG_XXX items from a
  336. BSP's user-config.cfg base config.
  337. The set of config items available to be removed by this command for a
  338. BSP is listed and the user prompted for the specific items to remove.
  339. """
  340. yocto_kernel_config_rm_help = """
  341. NAME
  342. yocto-kernel config rm - Remove bare kernel config options from a
  343. BSP
  344. SYNOPSIS
  345. yocto-kernel config rm <bsp-name>
  346. DESCRIPTION
  347. This command removes (turns off) one or more CONFIG_XXX items from a
  348. BSP's user-config.cfg base config.
  349. The set of config items available to be removed by this command
  350. for a BSP is listed and the user prompted for the specific items
  351. to remove.
  352. """
  353. yocto_kernel_patch_list_usage = """
  354. List the patches associated with the kernel for a BSP
  355. usage: yocto-kernel patch list <bsp-name>
  356. This command lists the patches associated with a BSP.
  357. NOTE: this only applies to patches listed in the kernel recipe's
  358. user-patches.scc file (and currently repeated in its SRC_URI).
  359. """
  360. yocto_kernel_patch_list_help = """
  361. NAME
  362. yocto-kernel patch list - List the patches associated with the kernel
  363. for a BSP
  364. SYNOPSIS
  365. yocto-kernel patch list <bsp-name>
  366. DESCRIPTION
  367. This command lists the patches associated with a BSP.
  368. NOTE: this only applies to patches listed in the kernel recipe's
  369. user-patches.scc file (and currently repeated in its SRC_URI).
  370. """
  371. yocto_kernel_patch_add_usage = """
  372. Patch the Yocto kernel for a specific BSP
  373. usage: yocto-kernel patch add <bsp-name> [<PATCH> ...]
  374. This command adds one or more patches to a BSP's machine branch. The
  375. patch will be added to the BSP's linux-yocto kernel user-patches.scc
  376. file (and currently repeated in its SRC_URI) and will be guaranteed
  377. to be applied in the order specified.
  378. """
  379. yocto_kernel_patch_add_help = """
  380. NAME
  381. yocto-kernel patch add - Patch the Yocto kernel for a specific BSP
  382. SYNOPSIS
  383. yocto-kernel patch add <bsp-name> [<PATCH> ...]
  384. DESCRIPTION
  385. This command adds one or more patches to a BSP's machine branch.
  386. The patch will be added to the BSP's linux-yocto kernel
  387. user-patches.scc file (and currently repeated in its SRC_URI) and
  388. will be guaranteed to be applied in the order specified.
  389. NOTE: It's up to the user to determine whether or not the patches
  390. being added makes sense or not - this command does no sanity
  391. checking or verification of any kind to ensure that a patch can
  392. actually be applied to the BSP's kernel branch; it's assumed that
  393. the user has already done that.
  394. """
  395. yocto_kernel_patch_rm_usage = """
  396. Remove a patch from the Yocto kernel for a specific BSP
  397. usage: yocto-kernel patch rm <bsp-name>
  398. This command removes one or more patches from a BSP's machine branch.
  399. The patch will be removed from the BSP's linux-yocto kernel
  400. user-patches.scc file (and currently repeated in its SRC_URI) and
  401. kernel SRC_URI dir.
  402. The set of patches available to be removed by this command for a BSP
  403. is listed and the user prompted for the specific patches to remove.
  404. """
  405. yocto_kernel_patch_rm_help = """
  406. NAME
  407. yocto-kernel patch rm - Remove a patch from the Yocto kernel for a specific BSP
  408. SYNOPSIS
  409. yocto-kernel patch rm <bsp-name>
  410. DESCRIPTION
  411. This command removes one or more patches from a BSP's machine
  412. branch. The patch will be removed from the BSP's linux-yocto
  413. kernel user-patches.scc file (and currently repeated in its
  414. SRC_URI).
  415. The set of patches available to be removed by this command for a
  416. BSP is listed and the user prompted for the specific patches to
  417. remove.
  418. """
  419. ##
  420. # test code
  421. ##
  422. test_bsp_properties = {
  423. 'smp': 'yes',
  424. 'touchscreen': 'yes',
  425. 'keyboard': 'no',
  426. 'xserver': 'yes',
  427. 'xserver_choice': 'xserver-i915',
  428. 'features': ['goodfeature', 'greatfeature'],
  429. 'tunefile': 'tune-quark',
  430. }