cmdline.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Command-line Parsing
  3. ====================
  4. The command line is available in U-Boot proper, enabled by CONFIG_CMDLINE which
  5. is on by default. It is not enabled in SPL.
  6. There are two different command-line parsers available with U-Boot:
  7. the old "simple" one, and the much more powerful "hush" shell:
  8. Simple command-line parser
  9. --------------------------
  10. This takes very little code space and offers only basic features:
  11. - supports environment variables (through setenv / saveenv commands)
  12. - several commands on one line, separated by ';'
  13. - variable substitution using "... ${name} ..." syntax
  14. - special characters ('$', ';') can be escaped by prefixing with '\',
  15. for example::
  16. setenv bootcmd bootm \${address}
  17. - You can also escape text by enclosing in single apostrophes, for example::
  18. setenv addip 'setenv bootargs $bootargs ip=$ipaddr:$serverip:$gatewayip:$netmask:$hostname::off'
  19. Hush shell
  20. ----------
  21. This is similar to Bourne shell, with control structures like:
  22. - `if`... `then` ... `else`... `fi`
  23. - `for`... `do` ... `done`
  24. - `while` ... `do` ... `done`
  25. - `until` ... `do` ... `done`
  26. Hush supports environment ("global") variables (through setenv / saveenv
  27. commands) and local shell variables (through standard shell syntax
  28. `name=value`); only environment variables can be used with the "run" command
  29. The Hush shell is enabled with `CONFIG_HUSH_PARSER`.
  30. General rules
  31. -------------
  32. #. If a command line (or an environment variable executed by a "run"
  33. command) contains several commands separated by semicolon, and
  34. one of these commands fails, then the remaining commands will be
  35. executed anyway.
  36. #. If you execute several variables with one call to run (i. e.
  37. calling run with a list of variables as arguments), any failing
  38. command will cause "run" to terminate, i. e. the remaining
  39. variables are not executed.
  40. Representing numbers
  41. --------------------
  42. Most U-Boot commands use hexadecimal (hex) as the default base, for convenient
  43. use of addresses, for example::
  44. => md 1000 6
  45. 00001000: 2c786f62 00697073 03000000 0c000000 box,spi.........
  46. 00001010: 67020000 00000000 ...g....
  47. There is no need to add a `0x` prefix to the arguments and the output is shown
  48. in hex also, without any prefixes. This helps to avoid clutter.
  49. Some commands use decimal where it is more natural::
  50. => i2c dev 0
  51. Setting bus to 0
  52. => i2c speed
  53. Current bus speed=400000
  54. => i2c speed 100000
  55. Setting bus speed to 100000 Hz
  56. In some cases the default is decimal but it is possible to use octal if that is
  57. useful::
  58. pmic dev pmic@41
  59. dev: 1 @ pmic@41
  60. => pmic write 2 0177
  61. => pmic read 2
  62. 0x02: 0x00007f
  63. It is possible to use a `0x` prefix to use a hex value if that is more
  64. convenient::
  65. => i2c speed 0x30000
  66. Setting bus speed to 196608 Hz