environment.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Environment Variables
  3. =====================
  4. U-Boot supports user configuration using environment variables which
  5. can be made persistent by saving to persistent storage, for example flash
  6. memory.
  7. Environment variables are set using "env set" (alias "setenv"), printed using
  8. "env print" (alias "printenv"), and saved to persistent storage using
  9. "env save" (alias "saveenv"). Using "env set"
  10. without a value can be used to delete a variable from the
  11. environment. As long as you don't save the environment, you are
  12. working with an in-memory copy. In case the Flash area containing the
  13. environment is erased by accident, a default environment is provided.
  14. See :doc:`cmd/env` for details.
  15. Some configuration is controlled by Environment Variables, so that setting the
  16. variable can adjust the behaviour of U-Boot (e.g. autoboot delay, autoloading
  17. from tftp).
  18. Text-based Environment
  19. ----------------------
  20. The default environment for a board is created using a `.env` environment file
  21. using a simple text format. The base filename for this is defined by
  22. `CONFIG_ENV_SOURCE_FILE`, or `CONFIG_SYS_BOARD` if that is empty.
  23. The file must be in the board directory and have a .env extension, so
  24. assuming that there is a board vendor, the resulting filename is therefore::
  25. board/<vendor>/<board>/<CONFIG_ENV_SOURCE_FILE>.env
  26. or::
  27. board/<vendor>/<board>/<CONFIG_SYS_BOARD>.env
  28. This is a plain text file where you can type your environment variables in
  29. the form `var=value`. Blank lines and multi-line variables are supported.
  30. The conversion script looks for a line that starts in column 1 with a string
  31. and has an equals sign immediately afterwards. Spaces before the = are not
  32. permitted. It is a good idea to indent your scripts so that only the 'var='
  33. appears at the start of a line.
  34. To add additional text to a variable you can use `var+=value`. This text is
  35. merged into the variable during the make process and made available as a
  36. single value to U-Boot. Variables can contain `+` characters but in the unlikely
  37. event that you want to have a variable name ending in plus, put a backslash
  38. before the `+` so that the script knows you are not adding to an existing
  39. variable but assigning to a new one::
  40. maximum\+=value
  41. This file can include C-style comments. Blank lines and multi-line
  42. variables are supported, and you can use normal C preprocessor directives
  43. and CONFIG defines from your board config also.
  44. For example, for snapper9260 you would create a text file called
  45. `board/bluewater/snapper9260.env` containing the environment text.
  46. Example::
  47. stdout=serial
  48. #ifdef CONFIG_VIDEO
  49. stdout+=,vidconsole
  50. #endif
  51. bootcmd=
  52. /* U-Boot script for booting */
  53. if [ -z ${tftpserverip} ]; then
  54. echo "Use 'setenv tftpserverip a.b.c.d' to set IP address."
  55. fi
  56. usb start; setenv autoload n; bootp;
  57. tftpboot ${tftpserverip}:
  58. bootm
  59. failed=
  60. /* Print a message when boot fails */
  61. echo CONFIG_SYS_BOARD boot failed - please check your image
  62. echo Load address is CONFIG_SYS_LOAD_ADDR
  63. Settings which are common to a group of boards can use #include to bring in
  64. a common file in the `include/env` directory, containing environment
  65. settings. For example::
  66. #include <env/ti/mmc.env>
  67. If CONFIG_ENV_SOURCE_FILE is empty and the default filename is not present, then
  68. the old-style C environment is used instead. See below.
  69. Old-style C environment
  70. -----------------------
  71. Traditionally, the default environment is created in `include/env_default.h`,
  72. and can be augmented by various `CONFIG` defines. See that file for details. In
  73. particular you can define `CFG_EXTRA_ENV_SETTINGS` in your board file
  74. to add environment variables.
  75. Board maintainers are encouraged to migrate to the text-based environment as it
  76. is easier to maintain. The distro-board script still requires the old-style
  77. environments, so use :doc:`../develop/bootstd` instead.
  78. List of environment variables
  79. -----------------------------
  80. Some device configuration options can be set using environment variables. In
  81. many cases the value in the default environment comes from a CONFIG option - see
  82. `include/env_default.h`) for this.
  83. This is most-likely not complete:
  84. autostart
  85. If set to "yes" (actually any string starting with 1, y, Y, t, or T) an
  86. image loaded with one of the commands listed below will be automatically
  87. started by internally invoking the bootm command.
  88. * bootelf - Boot from an ELF image in memory
  89. * bootp - boot image via network using BOOTP/TFTP protocol
  90. * dhcp - boot image via network using DHCP/TFTP protocol
  91. * diskboot - boot from ide device
  92. * nboot - boot from NAND device
  93. * nfs - boot image via network using NFS protocol
  94. * rarpboot - boot image via network using RARP/TFTP protocol
  95. * scsiboot - boot from SCSI device
  96. * tftpboot - boot image via network using TFTP protocol
  97. * usbboot - boot from USB device
  98. If the environment variable autostart is not set to a value starting with
  99. 1, y, Y, t, or T, an image passed to the "bootm" command will be copied to
  100. the load address (and eventually uncompressed), but NOT be started.
  101. This can be used to load and uncompress arbitrary data.
  102. baudrate
  103. Used to set the baudrate of the UART - it defaults to CONFIG_BAUDRATE (which
  104. defaults to 115200).
  105. bootdelay
  106. Delay before automatically running bootcmd. During this time the user
  107. can choose to enter the shell (or the boot menu if
  108. CONFIG_AUTOBOOT_MENU_SHOW=y):
  109. - 0 to autoboot with no delay, but you can stop it by key input.
  110. - -1 to disable autoboot.
  111. - -2 to autoboot with no delay and not check for abort
  112. The default value is defined by CONFIG_BOOTDELAY.
  113. The value of 'bootdelay' is overridden by the /config/bootdelay value in
  114. the device-tree if CONFIG_OF_CONTROL=y.
  115. bootcmd
  116. The command that is run if the user does not enter the shell during the
  117. boot delay.
  118. bootargs
  119. Command line arguments passed when booting an operating system or binary
  120. image
  121. bootfile
  122. Name of the image to load with TFTP
  123. bootm_low
  124. Memory range available for image processing in the bootm
  125. command can be restricted. This variable is given as
  126. a hexadecimal number and defines lowest address allowed
  127. for use by the bootm command. See also "bootm_size"
  128. environment variable. Address defined by "bootm_low" is
  129. also the base of the initial memory mapping for the Linux
  130. kernel -- see the description of CFG_SYS_BOOTMAPSZ and
  131. bootm_mapsize.
  132. bootm_mapsize
  133. Size of the initial memory mapping for the Linux kernel.
  134. This variable is given as a hexadecimal number and it
  135. defines the size of the memory region starting at base
  136. address bootm_low that is accessible by the Linux kernel
  137. during early boot. If unset, CFG_SYS_BOOTMAPSZ is used
  138. as the default value if it is defined, and bootm_size is
  139. used otherwise.
  140. bootm_size
  141. Memory range available for image processing in the bootm
  142. command can be restricted. This variable is given as
  143. a hexadecimal number and defines the size of the region
  144. allowed for use by the bootm command. See also "bootm_low"
  145. environment variable.
  146. bootstopkeysha256, bootdelaykey, bootstopkey
  147. See README.autoboot
  148. updatefile
  149. Location of the software update file on a TFTP server, used
  150. by the automatic software update feature. Please refer to
  151. documentation in doc/README.update for more details.
  152. autoload
  153. if set to "no" (any string beginning with 'n'),
  154. "bootp" and "dhcp" will just load perform a lookup of the
  155. configuration from the BOOTP server, but not try to
  156. load any image.
  157. fdt_high
  158. if set this restricts the maximum address that the
  159. flattened device tree will be copied into upon boot.
  160. For example, if you have a system with 1 GB memory
  161. at physical address 0x10000000, while Linux kernel
  162. only recognizes the first 704 MB as low memory, you
  163. may need to set fdt_high as 0x3C000000 to have the
  164. device tree blob be copied to the maximum address
  165. of the 704 MB low memory, so that Linux kernel can
  166. access it during the boot procedure.
  167. If this is set to the special value 0xffffffff (32-bit machines) or
  168. 0xffffffffffffffff (64-bit machines) then
  169. the fdt will not be copied at all on boot. For this
  170. to work it must reside in writable memory, have
  171. sufficient padding on the end of it for u-boot to
  172. add the information it needs into it, and the memory
  173. must be accessible by the kernel. This usage is strongly discouraged
  174. however as it also stops U-Boot from ensuring the device tree starting
  175. address is properly aligned and a misaligned tree will cause OS failures.
  176. fdtcontroladdr
  177. if set this is the address of the control flattened
  178. device tree used by U-Boot when CONFIG_OF_CONTROL is
  179. defined.
  180. initrd_high
  181. restrict positioning of initrd images:
  182. If this variable is not set, initrd images will be
  183. copied to the highest possible address in RAM; this
  184. is usually what you want since it allows for
  185. maximum initrd size. If for some reason you want to
  186. make sure that the initrd image is loaded below the
  187. CFG_SYS_BOOTMAPSZ limit, you can set this environment
  188. variable to a value of "no" or "off" or "0".
  189. Alternatively, you can set it to a maximum upper
  190. address to use (U-Boot will still check that it
  191. does not overwrite the U-Boot stack and data).
  192. For instance, when you have a system with 16 MB
  193. RAM, and want to reserve 4 MB from use by Linux,
  194. you can do this by adding "mem=12M" to the value of
  195. the "bootargs" variable. However, now you must make
  196. sure that the initrd image is placed in the first
  197. 12 MB as well - this can be done with::
  198. setenv initrd_high 00c00000
  199. If you set initrd_high to 0xffffffff (32-bit machines) or
  200. 0xffffffffffffffff (64-bit machines), this is an
  201. indication to U-Boot that all addresses are legal
  202. for the Linux kernel, including addresses in flash
  203. memory. In this case U-Boot will NOT COPY the
  204. ramdisk at all. This may be useful to reduce the
  205. boot time on your system, but requires that this
  206. feature is supported by your Linux kernel. This usage however requires
  207. that the user ensure that there will be no overlap with other parts of the
  208. image such as the Linux kernel BSS. It should not be enabled by default
  209. and only done as part of optimizing a deployment.
  210. ipaddr
  211. IP address; needed for tftpboot command
  212. loadaddr
  213. Default load address for commands like "bootp",
  214. "rarpboot", "tftpboot", "loadb" or "diskboot". Note that the optimal
  215. default values here will vary between architectures. On 32bit ARM for
  216. example, some offset from start of memory is used as the Linux kernel
  217. zImage has a self decompressor and it's best if we stay out of where that
  218. will be working.
  219. loads_echo
  220. see CONFIG_LOADS_ECHO
  221. serverip
  222. TFTP server IP address; needed for tftpboot command
  223. bootretry
  224. see CONFIG_BOOT_RETRY_TIME
  225. bootdelaykey
  226. see CONFIG_AUTOBOOT_DELAY_STR
  227. bootstopkey
  228. see CONFIG_AUTOBOOT_STOP_STR
  229. ethprime
  230. controls which network interface is used first.
  231. ethact
  232. controls which interface is currently active.
  233. For example you can do the following::
  234. => setenv ethact FEC
  235. => ping 192.168.0.1 # traffic sent on FEC
  236. => setenv ethact SCC
  237. => ping 10.0.0.1 # traffic sent on SCC
  238. ethrotate
  239. When set to "no" U-Boot does not go through all
  240. available network interfaces.
  241. It just stays at the currently selected interface. When unset or set to
  242. anything other than "no", U-Boot does go through all
  243. available network interfaces.
  244. netretry
  245. When set to "no" each network operation will
  246. either succeed or fail without retrying.
  247. When set to "once" the network operation will
  248. fail when all the available network interfaces
  249. are tried once without success.
  250. Useful on scripts which control the retry operation
  251. themselves.
  252. silent_linux
  253. If set then Linux will be told to boot silently, by
  254. adding 'console=' to its command line. If "yes" it will be
  255. made silent. If "no" it will not be made silent. If
  256. unset, then it will be made silent if the U-Boot console
  257. is silent.
  258. tftpsrcp
  259. If this is set, the value is used for TFTP's
  260. UDP source port.
  261. tftpdstp
  262. If this is set, the value is used for TFTP's UDP
  263. destination port instead of the default port 69.
  264. tftpblocksize
  265. Block size to use for TFTP transfers; if not set,
  266. we use the TFTP server's default block size
  267. tftptimeout
  268. Retransmission timeout for TFTP packets (in milli-
  269. seconds, minimum value is 1000 = 1 second). Defines
  270. when a packet is considered to be lost so it has to
  271. be retransmitted. The default is 5000 = 5 seconds.
  272. Lowering this value may make downloads succeed
  273. faster in networks with high packet loss rates or
  274. with unreliable TFTP servers.
  275. tftptimeoutcountmax
  276. maximum count of TFTP timeouts (no
  277. unit, minimum value = 0). Defines how many timeouts
  278. can happen during a single file transfer before that
  279. transfer is aborted. The default is 10, and 0 means
  280. 'no timeouts allowed'. Increasing this value may help
  281. downloads succeed with high packet loss rates, or with
  282. unreliable TFTP servers or client hardware.
  283. tftpwindowsize
  284. if this is set, the value is used for TFTP's
  285. window size as described by RFC 7440.
  286. This means the count of blocks we can receive before
  287. sending ack to server.
  288. vlan
  289. When set to a value < 4095 the traffic over
  290. Ethernet is encapsulated/received over 802.1q
  291. VLAN tagged frames.
  292. Note: This appears not to be used in U-Boot. See `README.VLAN`.
  293. bootpretryperiod
  294. Period during which BOOTP/DHCP sends retries.
  295. Unsigned value, in milliseconds. If not set, the period will
  296. be either the default (28000), or a value based on
  297. CONFIG_NET_RETRY_COUNT, if defined. This value has
  298. precedence over the value based on CONFIG_NET_RETRY_COUNT.
  299. memmatches
  300. Number of matches found by the last 'ms' command, in hex
  301. memaddr
  302. Address of the last match found by the 'ms' command, in hex,
  303. or 0 if none
  304. mempos
  305. Index position of the last match found by the 'ms' command,
  306. in units of the size (.b, .w, .l) of the search
  307. zbootbase
  308. (x86 only) Base address of the bzImage 'setup' block
  309. zbootaddr
  310. (x86 only) Address of the loaded bzImage, typically
  311. BZIMAGE_LOAD_ADDR which is 0x100000
  312. Image locations
  313. ---------------
  314. The following image location variables contain the location of images
  315. used in booting. The "Image" column gives the role of the image and is
  316. not an environment variable name. The other columns are environment
  317. variable names. "File Name" gives the name of the file on a TFTP
  318. server, "RAM Address" gives the location in RAM the image will be
  319. loaded to, and "Flash Location" gives the image's address in NOR
  320. flash or offset in NAND flash.
  321. *Note* - these variables don't have to be defined for all boards, some
  322. boards currently use other variables for these purposes, and some
  323. boards use these variables for other purposes.
  324. Also note that most of these variables are just a commonly used set of variable
  325. names, used in some other variable definitions, but are not hard-coded anywhere
  326. in U-Boot code.
  327. ================= ============== ================ ==============
  328. Image File Name RAM Address Flash Location
  329. ================= ============== ================ ==============
  330. Linux kernel bootfile kernel_addr_r kernel_addr
  331. device tree blob fdtfile fdt_addr_r fdt_addr
  332. ramdisk ramdiskfile ramdisk_addr_r ramdisk_addr
  333. ================= ============== ================ ==============
  334. When setting the RAM addresses for `kernel_addr_r`, `fdt_addr_r` and
  335. `ramdisk_addr_r` there are several types of constraints to keep in mind. The
  336. one type of constraint is payload requirement. For example, a device tree MUST
  337. be loaded at an 8-byte aligned address as that is what the specification
  338. requires. In a similar manner, the operating system may define restrictions on
  339. where in memory space payloads can be. This is documented for example in Linux,
  340. with both the `Booting ARM Linux`_ and `Booting AArch64 Linux`_ documents.
  341. Finally, there are practical constraints. We do not know the size of a given
  342. payload a user will use but each payload must not overlap or it will corrupt
  343. the other payload. A similar problem can happen when a payload ends up being in
  344. the OS BSS area. For these reasons we need to ensure our default values here
  345. are both unlikely to lead to failure to boot and sufficiently explained so that
  346. they can be optimized for boot time or adjusted for smaller memory
  347. configurations.
  348. On different architectures we will have different constraints. It is important
  349. that we follow whatever documented requirements are available to best ensure
  350. forward compatibility. What follows are examples to highlight how to provide
  351. reasonable default values in different cases.
  352. Texas Instruments OMAP2PLUS (ARMv7) example
  353. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  354. On these families of processors we are on a 32bit ARMv7 core. As booting some
  355. form of Linux is our most common payload we will also keep in mind the
  356. documented requirements for booting that Linux provides. These values are also
  357. known to be fine for booting a number of other operating systems (or their
  358. loaders). In this example we define the following variables and values::
  359. loadaddr=0x82000000
  360. kernel_addr_r=${loadaddr}
  361. fdt_addr_r=0x88000000
  362. ramdisk_addr_r=0x88080000
  363. bootm_size=0x10000000
  364. The first thing to keep in mind is that DRAM starts at 0x80000000. We set a
  365. 32MiB buffer from the start of memory as our default load address and set
  366. ``kernel_addr_r`` to that. This is because the Linux ``zImage`` decompressor
  367. will typically then be able to avoid doing a relocation itself. It also MUST be
  368. within the first 128MiB of memory. The next value is we set ``fdt_addr_r`` to
  369. be at 128MiB offset from the start of memory. This location is suggested by the
  370. kernel documentation and is exceedingly unlikely to be overwritten by the
  371. kernel itself given other architectural constraints. We then allow for the
  372. device tree to be up to 512KiB in size before placing the ramdisk in memory. We
  373. then say that everything should be within the first 256MiB of memory so that
  374. U-Boot can relocate things as needed to ensure proper alignment. We pick 256MiB
  375. as our value here because we know there are very few platforms on in this
  376. family with less memory. It could be as high as 768MiB and still ensure that
  377. everything would be visible to the kernel, but again we go with what we assume
  378. is the safest assumption.
  379. Automatically updated variables
  380. -------------------------------
  381. The following environment variables may be used and automatically
  382. updated by the network boot commands ("bootp" and "rarpboot"),
  383. depending the information provided by your boot server:
  384. ========= ===================================================
  385. Variable Notes
  386. ========= ===================================================
  387. bootfile see above
  388. dnsip IP address of your Domain Name Server
  389. dnsip2 IP address of your secondary Domain Name Server
  390. gatewayip IP address of the Gateway (Router) to use
  391. hostname Target hostname
  392. ipaddr See above
  393. netmask Subnet Mask
  394. rootpath Pathname of the root filesystem on the NFS server
  395. serverip see above
  396. ========= ===================================================
  397. Special environment variables
  398. -----------------------------
  399. There are two special Environment Variables:
  400. serial#
  401. contains hardware identification information such as type string and/or
  402. serial number
  403. ethaddr
  404. Ethernet address. If CONFIG_REGEX=y, also eth*addr (where * is an integer).
  405. These variables can be set only once (usually during manufacturing of
  406. the board). U-Boot refuses to delete or overwrite these variables
  407. once they have been set, unless CONFIG_ENV_OVERWRITE is enabled in the board
  408. configuration.
  409. Also:
  410. ver
  411. Contains the U-Boot version string as printed
  412. with the "version" command. This variable is
  413. readonly (see CONFIG_VERSION_VARIABLE).
  414. Please note that changes to some configuration parameters may take
  415. only effect after the next boot (yes, that's just like Windows).
  416. External environment file
  417. -------------------------
  418. The `CONFIG_USE_DEFAULT_ENV_FILE` option provides a way to bypass the
  419. environment generation in U-Boot. If enabled, then `CONFIG_DEFAULT_ENV_FILE`
  420. provides the name of a file which is converted into the environment,
  421. completely bypassing the standard environment variables in `env_default.h`.
  422. The format is the same as accepted by the mkenvimage tool, with lines containing
  423. key=value pairs. Blank lines and lines beginning with # are ignored.
  424. Future work may unify this feature with the text-based environment, perhaps
  425. moving the contents of `env_default.h` to a text file.
  426. Implementation
  427. --------------
  428. See :doc:`../develop/environment` for internal development details.
  429. .. _`Booting ARM Linux`: https://www.kernel.org/doc/html/latest/arm/booting.html
  430. .. _`Booting AArch64 Linux`: https://www.kernel.org/doc/html/latest/arm64/booting.html