environment.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * (C) Copyright 2001
  3. * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <config.h>
  24. #include <environment.h>
  25. /*
  26. * Handle HOSTS that have prepended
  27. * crap on symbol names, not TARGETS.
  28. */
  29. #if defined(__APPLE__)
  30. /* Leading underscore on symbols */
  31. # define SYM_CHAR "_"
  32. #else /* No leading character on symbols */
  33. # define SYM_CHAR
  34. #endif
  35. /*
  36. * Generate embedded environment table
  37. * inside U-Boot image, if needed.
  38. */
  39. #if defined(ENV_IS_EMBEDDED)
  40. /*
  41. * Only put the environment in it's own section when we are building
  42. * U-Boot proper. The host based program "tools/envcrc" does not need
  43. * a seperate section. Note that ENV_CRC is only defined when building
  44. * U-Boot itself.
  45. */
  46. #if (defined(CONFIG_FADS) || \
  47. defined(CONFIG_HYMOD) || \
  48. defined(CONFIG_ICU862) || \
  49. defined(CONFIG_R360MPI) || \
  50. defined(CONFIG_TQM8xxL) || \
  51. defined(CONFIG_RRVISION) || \
  52. defined(CONFIG_TRAB) ) && \
  53. defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */
  54. /* XXX - This only works with GNU C */
  55. # define __PPCENV__ __attribute__ ((section(".ppcenv")))
  56. # define __PPCTEXT__ __attribute__ ((section(".text")))
  57. #elif defined(USE_HOSTCC) /* Native for 'tools/envcrc' */
  58. # define __PPCENV__ /*XXX DO_NOT_DEL_THIS_COMMENT*/
  59. # define __PPCTEXT__ /*XXX DO_NOT_DEL_THIS_COMMENT*/
  60. #else /* Environment is embedded in U-Boot's .text section */
  61. /* XXX - This only works with GNU C */
  62. # define __PPCENV__ __attribute__ ((section(".text")))
  63. # define __PPCTEXT__ __attribute__ ((section(".text")))
  64. #endif
  65. /*
  66. * Macros to generate global absolutes.
  67. */
  68. #define GEN_SYMNAME(str) SYM_CHAR #str
  69. #define GEN_VALUE(str) #str
  70. #define GEN_ABS(name, value) \
  71. asm (".globl " GEN_SYMNAME(name)); \
  72. asm (GEN_SYMNAME(name) " = " GEN_VALUE(value))
  73. /*
  74. * Macros to transform values
  75. * into environment strings.
  76. */
  77. #define XMK_STR(x) #x
  78. #define MK_STR(x) XMK_STR(x)
  79. /*
  80. * Check to see if we are building with a
  81. * computed CRC. Otherwise define it as ~0.
  82. */
  83. #if !defined(ENV_CRC)
  84. # define ENV_CRC ~0
  85. #endif
  86. env_t environment __PPCENV__ = {
  87. ENV_CRC, /* CRC Sum */
  88. #ifdef CFG_REDUNDAND_ENVIRONMENT
  89. 1, /* Flags: valid */
  90. #endif
  91. {
  92. #if defined(CONFIG_BOOTARGS)
  93. "bootargs=" CONFIG_BOOTARGS "\0"
  94. #endif
  95. #if defined(CONFIG_BOOTCOMMAND)
  96. "bootcmd=" CONFIG_BOOTCOMMAND "\0"
  97. #endif
  98. #if defined(CONFIG_RAMBOOTCOMMAND)
  99. "ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
  100. #endif
  101. #if defined(CONFIG_NFSBOOTCOMMAND)
  102. "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
  103. #endif
  104. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  105. "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
  106. #endif
  107. #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
  108. "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
  109. #endif
  110. #ifdef CONFIG_LOADS_ECHO
  111. "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
  112. #endif
  113. #ifdef CONFIG_ETHADDR
  114. "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
  115. #endif
  116. #ifdef CONFIG_ETH1ADDR
  117. "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
  118. #endif
  119. #ifdef CONFIG_ETH2ADDR
  120. "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
  121. #endif
  122. #ifdef CONFIG_ETHPRIME
  123. "ethprime=" CONFIG_ETHPRIME "\0"
  124. #endif
  125. #ifdef CONFIG_IPADDR
  126. "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
  127. #endif
  128. #ifdef CONFIG_SERVERIP
  129. "serverip=" MK_STR(CONFIG_SERVERIP) "\0"
  130. #endif
  131. #ifdef CFG_AUTOLOAD
  132. "autoload=" CFG_AUTOLOAD "\0"
  133. #endif
  134. #ifdef CONFIG_ROOTPATH
  135. "rootpath=" MK_STR(CONFIG_ROOTPATH) "\0"
  136. #endif
  137. #ifdef CONFIG_GATEWAYIP
  138. "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
  139. #endif
  140. #ifdef CONFIG_NETMASK
  141. "netmask=" MK_STR(CONFIG_NETMASK) "\0"
  142. #endif
  143. #ifdef CONFIG_HOSTNAME
  144. "hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
  145. #endif
  146. #ifdef CONFIG_BOOTFILE
  147. "bootfile=" MK_STR(CONFIG_BOOTFILE) "\0"
  148. #endif
  149. #ifdef CONFIG_LOADADDR
  150. "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
  151. #endif
  152. #ifdef CONFIG_PREBOOT
  153. "preboot=" CONFIG_PREBOOT "\0"
  154. #endif
  155. #ifdef CONFIG_CLOCKS_IN_MHZ
  156. "clocks_in_mhz=" "1" "\0"
  157. #endif
  158. #ifdef CONFIG_EXTRA_ENV_SETTINGS
  159. CONFIG_EXTRA_ENV_SETTINGS
  160. #endif
  161. "\0" /* Term. env_t.data with 2 NULs */
  162. }
  163. };
  164. #ifdef CFG_ENV_ADDR_REDUND
  165. env_t redundand_environment __PPCENV__ = {
  166. 0, /* CRC Sum: invalid */
  167. 0, /* Flags: invalid */
  168. {
  169. "\0"
  170. }
  171. };
  172. #endif /* CFG_ENV_ADDR_REDUND */
  173. /*
  174. * These will end up in the .text section
  175. * if the environment strings are embedded
  176. * in the image. When this is used for
  177. * tools/envcrc, they are placed in the
  178. * .data/.sdata section.
  179. *
  180. */
  181. unsigned long env_size __PPCTEXT__ = sizeof(env_t);
  182. /*
  183. * Add in absolutes.
  184. */
  185. GEN_ABS(env_offset, CFG_ENV_OFFSET);
  186. #endif /* ENV_IS_EMBEDDED */