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;
41 static int env_fat_save(void)
44 struct blk_desc *dev_desc = NULL;
45 disk_partition_t info;
50 err = env_export(&env_new);
54 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
55 CONFIG_ENV_FAT_DEVICE_AND_PART,
60 dev = dev_desc->devnum;
61 if (fat_set_blk_dev(dev_desc, &info) != 0) {
62 printf("\n** Unable to use %s %d:%d for saveenv **\n",
63 CONFIG_ENV_FAT_INTERFACE, dev, part);
67 err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
70 printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
71 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
78 #endif /* CMD_SAVEENV */
81 static void env_fat_load(void)
83 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
84 struct blk_desc *dev_desc = NULL;
85 disk_partition_t info;
89 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
90 CONFIG_ENV_FAT_DEVICE_AND_PART,
93 goto err_env_relocate;
95 dev = dev_desc->devnum;
96 if (fat_set_blk_dev(dev_desc, &info) != 0) {
97 printf("\n** Unable to use %s %d:%d for loading the env **\n",
98 CONFIG_ENV_FAT_INTERFACE, dev, part);
99 goto err_env_relocate;
102 err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
104 printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
105 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
106 goto err_env_relocate;
113 set_default_env(NULL);
117 U_BOOT_ENV_LOCATION(fat) = {
118 .location = ENVL_FAT,
120 .load = env_fat_load,
123 .save = env_save_ptr(env_fat_save),