1 // SPDX-License-Identifier: GPL-2.0+
3 * (c) Copyright 2011 by Tigris Elektronik GmbH
6 * Maximilian Schwerin <mvs@tigris.de>
12 #include <environment.h>
13 #include <linux/stddef.h>
21 #ifdef CONFIG_SPL_BUILD
22 /* TODO(sjg@chromium.org): Figure out why this is needed */
23 # if !defined(CONFIG_TARGET_AM335X_EVM) || defined(CONFIG_SPL_OS_BOOT)
28 # if defined(CONFIG_CMD_SAVEENV)
34 static int env_fat_save(void)
36 env_t
__aligned(ARCH_DMA_MINALIGN
) env_new
;
37 struct blk_desc
*dev_desc
= NULL
;
38 disk_partition_t info
;
43 err
= env_export(&env_new
);
47 part
= blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE
,
48 CONFIG_ENV_FAT_DEVICE_AND_PART
,
53 dev
= dev_desc
->devnum
;
54 if (fat_set_blk_dev(dev_desc
, &info
) != 0) {
56 * This printf is embedded in the messages from env_save that
57 * will calling it. The missing \n is intentional.
59 printf("Unable to use %s %d:%d... ",
60 CONFIG_ENV_FAT_INTERFACE
, dev
, part
);
64 err
= file_fat_write(CONFIG_ENV_FAT_FILE
, (void *)&env_new
, 0, sizeof(env_t
),
68 * This printf is embedded in the messages from env_save that
69 * will calling it. The missing \n is intentional.
71 printf("Unable to write \"%s\" from %s%d:%d... ",
72 CONFIG_ENV_FAT_FILE
, CONFIG_ENV_FAT_INTERFACE
, dev
, part
);
78 #endif /* CMD_SAVEENV */
81 static int 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
;
90 if (!strcmp(CONFIG_ENV_FAT_INTERFACE
, "mmc"))
94 part
= blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE
,
95 CONFIG_ENV_FAT_DEVICE_AND_PART
,
98 goto err_env_relocate
;
100 dev
= dev_desc
->devnum
;
101 if (fat_set_blk_dev(dev_desc
, &info
) != 0) {
103 * This printf is embedded in the messages from env_save that
104 * will calling it. The missing \n is intentional.
106 printf("Unable to use %s %d:%d... ",
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
);
114 * This printf is embedded in the messages from env_save that
115 * will calling it. The missing \n is intentional.
117 printf("Unable to read \"%s\" from %s%d:%d... ",
118 CONFIG_ENV_FAT_FILE
, CONFIG_ENV_FAT_INTERFACE
, dev
, part
);
119 goto err_env_relocate
;
122 return env_import(buf
, 1);
125 set_default_env(NULL
, 0);
131 U_BOOT_ENV_LOCATION(fat
) = {
132 .location
= ENVL_FAT
,
135 .load
= env_fat_load
,
138 .save
= env_save_ptr(env_fat_save
),