1 // SPDX-License-Identifier: GPL-2.0+
3 * (c) Copyright 2011 by Tigris Elektronik GmbH
6 * Maximilian Schwerin <mvs@tigris.de>
13 #include <env_internal.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)
35 static int env_fat_save(void)
37 env_t __aligned(ARCH_DMA_MINALIGN) env_new;
38 struct blk_desc *dev_desc = NULL;
39 disk_partition_t info;
44 err = env_export(&env_new);
48 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
49 CONFIG_ENV_FAT_DEVICE_AND_PART,
54 dev = dev_desc->devnum;
55 if (fat_set_blk_dev(dev_desc, &info) != 0) {
57 * This printf is embedded in the messages from env_save that
58 * will calling it. The missing \n is intentional.
60 printf("Unable to use %s %d:%d... ",
61 CONFIG_ENV_FAT_INTERFACE, dev, part);
65 err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
69 * This printf is embedded in the messages from env_save that
70 * will calling it. The missing \n is intentional.
72 printf("Unable to write \"%s\" from %s%d:%d... ",
73 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
79 #endif /* CMD_SAVEENV */
82 static int env_fat_load(void)
84 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
85 struct blk_desc *dev_desc = NULL;
86 disk_partition_t info;
91 if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
95 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
96 CONFIG_ENV_FAT_DEVICE_AND_PART,
99 goto err_env_relocate;
101 dev = dev_desc->devnum;
102 if (fat_set_blk_dev(dev_desc, &info) != 0) {
104 * This printf is embedded in the messages from env_save that
105 * will calling it. The missing \n is intentional.
107 printf("Unable to use %s %d:%d... ",
108 CONFIG_ENV_FAT_INTERFACE, dev, part);
109 goto err_env_relocate;
112 err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
115 * This printf is embedded in the messages from env_save that
116 * will calling it. The missing \n is intentional.
118 printf("Unable to read \"%s\" from %s%d:%d... ",
119 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
120 goto err_env_relocate;
123 return env_import(buf, 1);
126 env_set_default(NULL, 0);
132 U_BOOT_ENV_LOCATION(fat) = {
133 .location = ENVL_FAT,
136 .load = env_fat_load,
139 .save = env_save_ptr(env_fat_save),