env.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Common environment functions
  4. *
  5. * (C) Copyright 2000-2009
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. */
  8. #ifndef __ENV_H
  9. #define __ENV_H
  10. #include <stdbool.h>
  11. #include <linux/types.h>
  12. /**
  13. * env_get_id() - Gets a sequence number for the environment
  14. *
  15. * This value increments every time the environment changes, so can be used an
  16. * an indication of this
  17. *
  18. * @return environment ID
  19. */
  20. int env_get_id(void);
  21. /**
  22. * env_init() - Set up the pre-relocation environment
  23. *
  24. * This locates the environment or uses the default if nothing is available.
  25. * This must be called before env_get() will work.
  26. *
  27. * @return 0 if OK, -ENODEV if no environment drivers are enabled
  28. */
  29. int env_init(void);
  30. /**
  31. * env_relocate() - Set up the post-relocation environment
  32. *
  33. * This loads the environment into RAM so that it can be modified. This is
  34. * called after relocation, before the environment is used
  35. */
  36. void env_relocate(void);
  37. /**
  38. * env_match() - Match a name / name=value pair
  39. *
  40. * This is used prior to relocation for finding envrionment variables
  41. *
  42. * @name: A simple 'name', or a 'name=value' pair.
  43. * @index: The environment index for a 'name2=value2' pair.
  44. * @return index for the value if the names match, else -1.
  45. */
  46. int env_match(unsigned char *name, int index);
  47. /**
  48. * env_get_f() - Look up the value of an environment variable (early)
  49. *
  50. * This function is called from env_get() if the environment has not been
  51. * loaded yet (GD_FLG_ENV_READY flag is 0). Some environment locations will
  52. * support reading the value (slowly) and some will not.
  53. *
  54. * @varname: Variable to look up
  55. * @return value of variable, or NULL if not found
  56. */
  57. int env_get_f(const char *name, char *buf, unsigned int len);
  58. /**
  59. * env_get_ulong() - Return an environment variable as an integer value
  60. *
  61. * Most U-Boot environment variables store hex values. For those which store
  62. * (e.g.) base-10 integers, this function can be used to read the value.
  63. *
  64. * @name: Variable to look up
  65. * @base: Base to use (e.g. 10 for base 10, 2 for binary)
  66. * @default_val: Default value to return if no value is found
  67. * @return the value found, or @default_val if none
  68. */
  69. ulong env_get_ulong(const char *name, int base, ulong default_val);
  70. /**
  71. * env_set_ulong() - set an environment variable to an integer
  72. *
  73. * @varname: Variable to adjust
  74. * @value: Value to set for the variable (will be converted to a string)
  75. * @return 0 if OK, 1 on error
  76. */
  77. int env_set_ulong(const char *varname, ulong value);
  78. /**
  79. * env_set_hex() - set an environment variable to a hex value
  80. *
  81. * @varname: Variable to adjust
  82. * @value: Value to set for the variable (will be converted to a hex string)
  83. * @return 0 if OK, 1 on error
  84. */
  85. int env_set_hex(const char *varname, ulong value);
  86. /**
  87. * env_set_addr - Set an environment variable to an address in hex
  88. *
  89. * @varname: Environment variable to set
  90. * @addr: Value to set it to
  91. * @return 0 if ok, 1 on error
  92. */
  93. static inline int env_set_addr(const char *varname, const void *addr)
  94. {
  95. return env_set_hex(varname, (ulong)addr);
  96. }
  97. /**
  98. * env_complete() - return an auto-complete for environment variables
  99. *
  100. * @var: partial name to auto-complete
  101. * @maxv: Maximum number of matches to return
  102. * @cmdv: Returns a list of possible matches
  103. * @maxsz: Size of buffer to use for matches
  104. * @buf: Buffer to use for matches
  105. * @dollar_comp: non-zero to wrap each match in ${...}
  106. * @return number of matches found (in @cmdv)
  107. */
  108. int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf,
  109. bool dollar_comp);
  110. #endif