1 // SPDX-License-Identifier: GPL-2.0+
3 * (c) Copyright 2011 by Tigris Elektronik GmbH
6 * Maximilian Schwerin <mvs@tigris.de>
12 #include <env_internal.h>
20 #include <asm/cache.h>
21 #include <linux/stddef.h>
23 #ifdef CONFIG_SPL_BUILD
24 /* TODO(sjg@chromium.org): Figure out why this is needed */
25 # if !defined(CONFIG_TARGET_AM335X_EVM) || defined(CONFIG_SPL_OS_BOOT)
32 static int env_fat_save(void)
34 env_t __aligned(ARCH_DMA_MINALIGN) env_new;
35 struct blk_desc *dev_desc = NULL;
36 struct disk_partition info;
41 err = env_export(&env_new);
45 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
46 CONFIG_ENV_FAT_DEVICE_AND_PART,
51 dev = dev_desc->devnum;
52 if (fat_set_blk_dev(dev_desc, &info) != 0) {
54 * This printf is embedded in the messages from env_save that
55 * will calling it. The missing \n is intentional.
57 printf("Unable to use %s %d:%d... ",
58 CONFIG_ENV_FAT_INTERFACE, dev, part);
62 err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
66 * This printf is embedded in the messages from env_save that
67 * will calling it. The missing \n is intentional.
69 printf("Unable to write \"%s\" from %s%d:%d... ",
70 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
78 static int env_fat_load(void)
80 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
81 struct blk_desc *dev_desc = NULL;
82 struct disk_partition info;
87 if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
91 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
92 CONFIG_ENV_FAT_DEVICE_AND_PART,
95 goto err_env_relocate;
97 dev = dev_desc->devnum;
98 if (fat_set_blk_dev(dev_desc, &info) != 0) {
100 * This printf is embedded in the messages from env_save that
101 * will calling it. The missing \n is intentional.
103 printf("Unable to use %s %d:%d... ",
104 CONFIG_ENV_FAT_INTERFACE, dev, part);
105 goto err_env_relocate;
108 err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
111 * This printf is embedded in the messages from env_save that
112 * will calling it. The missing \n is intentional.
114 printf("Unable to read \"%s\" from %s%d:%d... ",
115 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
116 goto err_env_relocate;
119 return env_import(buf, 1);
122 env_set_default(NULL, 0);
128 U_BOOT_ENV_LOCATION(fat) = {
129 .location = ENVL_FAT,
132 .load = env_fat_load,
134 .save = ENV_SAVE_PTR(env_fat_save),