else
env_set_default(NULL, 0);
+ env_import_fdt();
+
if (IS_ENABLED(CONFIG_OF_CONTROL))
env_set_hex("fdtcontroladdr",
(unsigned long)map_to_sysmem(gd->fdt_blob));
later by U-Boot code. With CONFIG_OF_CONTROL this is instead
controlled by the value of /config/load-environment.
+config ENV_IMPORT_FDT
+ bool "Amend environment by FDT properties"
+ depends on OF_CONTROL
+ help
+ If selected, after the environment has been loaded from its
+ persistent location, the "env_fdt_path" variable is looked
+ up and used as a path to a node in the control DTB. The
+ property/value pairs in that node is then used to update the
+ run-time environment. This can be useful to use the same
+ U-Boot binary with different board variants.
+
+config ENV_FDT_PATH
+ string "Default value for env_fdt_path variable"
+ depends on ENV_IMPORT_FDT
+ default "/config/environment"
+ help
+ The initial value of the env_fdt_path variable.
+
config ENV_APPEND
bool "Always append the environment with new data"
default n
#include <errno.h>
#include <malloc.h>
#include <u-boot/crc.h>
+#include <dm/ofnode.h>
DECLARE_GLOBAL_DATA_PTR;
return found;
}
#endif
+
+#ifdef CONFIG_ENV_IMPORT_FDT
+void env_import_fdt(void)
+{
+ const char *path;
+ struct ofprop prop;
+ ofnode node;
+ int res;
+
+ path = env_get("env_fdt_path");
+ if (!path || !path[0])
+ return;
+
+ node = ofnode_path(path);
+ if (!ofnode_valid(node)) {
+ printf("Warning: device tree node '%s' not found\n", path);
+ return;
+ }
+
+ for (res = ofnode_get_first_property(node, &prop);
+ !res;
+ res = ofnode_get_next_property(&prop)) {
+ const char *name, *val;
+
+ val = ofnode_get_property_by_prop(&prop, &name, NULL);
+ env_set(name, val);
+ }
+}
+#endif
* This is used for those unfortunate archs with crappy toolchains
*/
void env_reloc(void);
+
+
+/**
+ * env_import_fdt() - Import environment values from device tree blob
+ *
+ * This uses the value of the environment variable "env_fdt_path" as a
+ * path to an fdt node, whose property/value pairs are added to the
+ * environment.
+ */
+#ifdef CONFIG_ENV_IMPORT_FDT
+void env_import_fdt(void);
+#else
+static inline void env_import_fdt(void) {}
+#endif
+
#endif
#ifdef CONFIG_SYS_SOC
"soc=" CONFIG_SYS_SOC "\0"
#endif
+#ifdef CONFIG_ENV_IMPORT_FDT
+ "env_fdt_path=" CONFIG_ENV_FDT_PATH "\0"
+#endif
#endif
#if defined(CONFIG_BOOTCOUNT_BOOTLIMIT) && (CONFIG_BOOTCOUNT_BOOTLIMIT > 0)
"bootlimit=" __stringify(CONFIG_BOOTCOUNT_BOOTLIMIT)"\0"