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)
31 static int env_fat_save(void)
33 env_t __aligned(ARCH_DMA_MINALIGN) env_new;
34 struct blk_desc *dev_desc = NULL;
35 disk_partition_t info;
40 err = env_export(&env_new);
44 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
45 CONFIG_ENV_FAT_DEVICE_AND_PART,
50 dev = dev_desc->devnum;
51 if (fat_set_blk_dev(dev_desc, &info) != 0) {
53 * This printf is embedded in the messages from env_save that
54 * will calling it. The missing \n is intentional.
56 printf("Unable to use %s %d:%d... ",
57 CONFIG_ENV_FAT_INTERFACE, dev, part);
61 err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t),
65 * This printf is embedded in the messages from env_save that
66 * will calling it. The missing \n is intentional.
68 printf("Unable to write \"%s\" from %s%d:%d... ",
69 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
77 static int env_fat_load(void)
79 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
80 struct blk_desc *dev_desc = NULL;
81 disk_partition_t info;
86 if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
90 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
91 CONFIG_ENV_FAT_DEVICE_AND_PART,
94 goto err_env_relocate;
96 dev = dev_desc->devnum;
97 if (fat_set_blk_dev(dev_desc, &info) != 0) {
99 * This printf is embedded in the messages from env_save that
100 * will calling it. The missing \n is intentional.
102 printf("Unable to use %s %d:%d... ",
103 CONFIG_ENV_FAT_INTERFACE, dev, part);
104 goto err_env_relocate;
107 err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE);
110 * This printf is embedded in the messages from env_save that
111 * will calling it. The missing \n is intentional.
113 printf("Unable to read \"%s\" from %s%d:%d... ",
114 CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part);
115 goto err_env_relocate;
118 return env_import(buf, 1);
121 env_set_default(NULL, 0);
127 U_BOOT_ENV_LOCATION(fat) = {
128 .location = ENVL_FAT,
131 .load = env_fat_load,
133 .save = ENV_SAVE_PTR(env_fat_save),