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>
21 char *env_name_spec = "FAT";
25 DECLARE_GLOBAL_DATA_PTR;
30 gd->env_addr = (ulong)&default_environment[0];
36 #ifdef CONFIG_CMD_SAVEENV
42 block_dev_desc_t *dev_desc = NULL;
43 int dev = FAT_ENV_DEVICE;
44 int part = FAT_ENV_PART;
47 res = (char *)&env_new.data;
48 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
50 error("Cannot export environment: errno = %d\n", errno);
55 if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) {
56 struct mmc *mmc = find_mmc_device(dev);
59 printf("no mmc device at slot %x\n", dev);
66 #endif /* CONFIG_MMC */
68 dev_desc = get_dev(FAT_ENV_INTERFACE, dev);
69 if (dev_desc == NULL) {
70 printf("Failed to find %s%d\n",
71 FAT_ENV_INTERFACE, dev);
75 err = fat_register_device(dev_desc, part);
77 printf("Failed to register %s%d:%d\n",
78 FAT_ENV_INTERFACE, dev, part);
82 env_new.crc = crc32(0, env_new.data, ENV_SIZE);
83 err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, sizeof(env_t));
85 printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
86 FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part);
93 #endif /* CONFIG_CMD_SAVEENV */
95 void env_relocate_spec(void)
97 char buf[CONFIG_ENV_SIZE];
98 block_dev_desc_t *dev_desc = NULL;
99 int dev = FAT_ENV_DEVICE;
100 int part = FAT_ENV_PART;
104 if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) {
105 struct mmc *mmc = find_mmc_device(dev);
108 printf("no mmc device at slot %x\n", dev);
109 set_default_env(NULL);
116 #endif /* CONFIG_MMC */
118 dev_desc = get_dev(FAT_ENV_INTERFACE, dev);
119 if (dev_desc == NULL) {
120 printf("Failed to find %s%d\n",
121 FAT_ENV_INTERFACE, dev);
122 set_default_env(NULL);
126 err = fat_register_device(dev_desc, part);
128 printf("Failed to register %s%d:%d\n",
129 FAT_ENV_INTERFACE, dev, part);
130 set_default_env(NULL);
134 err = file_fat_read(FAT_ENV_FILE, (uchar *)&buf, CONFIG_ENV_SIZE);
136 printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
137 FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part);
138 set_default_env(NULL);