2 * (c) Copyright 2011 by Tigris Elektronik GmbH
5 * Maximilian Schwerin <mvs@tigris.de>
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <environment.h>
14 #include <linux/stddef.h>
22 #ifdef CONFIG_SPL_BUILD
23 /* TODO(sjg@chromium.org): Figure out why this is needed */
24 # if !defined(CONFIG_TARGET_AM335X_EVM) || defined(CONFIG_SPL_OS_BOOT)
29 # if defined(CONFIG_CMD_SAVEENV)
34 char *env_name_spec = "FAT";
38 DECLARE_GLOBAL_DATA_PTR;
40 static int env_fat_init(void)
43 gd->env_addr = (ulong)&default_environment[0];
44 gd->env_valid = ENV_VALID;
50 static int env_fat_save(void)
53 struct blk_desc *dev_desc = NULL;
54 disk_partition_t info;
59 err = env_export(&env_new);
63 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
64 CONFIG_ENV_FAT_DEVICE_AND_PART,
69 dev = dev_desc->devnum;
70 if (fat_set_blk_dev(dev_desc, &info) != 0) {
71 printf("\n** Unable to use %s %d:%d for saveenv **\n",
72 CONFIG_ENV_FAT_INTERFACE, dev, part);
76 err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
79 printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
80 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
87 #endif /* CMD_SAVEENV */
90 static void env_fat_load(void)
92 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
93 struct blk_desc *dev_desc = NULL;
94 disk_partition_t info;
98 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
99 CONFIG_ENV_FAT_DEVICE_AND_PART,
100 &dev_desc, &info, 1);
102 goto err_env_relocate;
104 dev = dev_desc->devnum;
105 if (fat_set_blk_dev(dev_desc, &info) != 0) {
106 printf("\n** Unable to use %s %d:%d for loading the env **\n",
107 CONFIG_ENV_FAT_INTERFACE, dev, part);
108 goto err_env_relocate;
111 err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
113 printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
114 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
115 goto err_env_relocate;
122 set_default_env(NULL);
126 U_BOOT_ENV_LOCATION(fat) = {
127 .location = ENVL_FAT,
129 .load = env_fat_load,
132 .save = env_save_ptr(env_fat_save),
134 .init = env_fat_init,