2 * (c) Copyright 2011 by Tigris Elektronik GmbH
5 * Maximilian Schwerin <mvs@tigris.de>
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <environment.h>
30 #include <linux/stddef.h>
37 char *env_name_spec = "FAT";
41 DECLARE_GLOBAL_DATA_PTR;
46 gd->env_addr = (ulong)&default_environment[0];
52 #ifdef CONFIG_CMD_SAVEENV
58 block_dev_desc_t *dev_desc = NULL;
59 int dev = FAT_ENV_DEVICE;
60 int part = FAT_ENV_PART;
63 res = (char *)&env_new.data;
64 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
66 error("Cannot export environment: errno = %d\n", errno);
71 if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) {
72 struct mmc *mmc = find_mmc_device(dev);
75 printf("no mmc device at slot %x\n", dev);
82 #endif /* CONFIG_MMC */
84 dev_desc = get_dev(FAT_ENV_INTERFACE, dev);
85 if (dev_desc == NULL) {
86 printf("Failed to find %s%d\n",
87 FAT_ENV_INTERFACE, dev);
91 err = fat_register_device(dev_desc, part);
93 printf("Failed to register %s%d:%d\n",
94 FAT_ENV_INTERFACE, dev, part);
98 env_new.crc = crc32(0, env_new.data, ENV_SIZE);
99 err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, sizeof(env_t));
101 printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
102 FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part);
109 #endif /* CONFIG_CMD_SAVEENV */
111 void env_relocate_spec(void)
113 char buf[CONFIG_ENV_SIZE];
114 block_dev_desc_t *dev_desc = NULL;
115 int dev = FAT_ENV_DEVICE;
116 int part = FAT_ENV_PART;
120 if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) {
121 struct mmc *mmc = find_mmc_device(dev);
124 printf("no mmc device at slot %x\n", dev);
125 set_default_env(NULL);
132 #endif /* CONFIG_MMC */
134 dev_desc = get_dev(FAT_ENV_INTERFACE, dev);
135 if (dev_desc == NULL) {
136 printf("Failed to find %s%d\n",
137 FAT_ENV_INTERFACE, dev);
138 set_default_env(NULL);
142 err = fat_register_device(dev_desc, part);
144 printf("Failed to register %s%d:%d\n",
145 FAT_ENV_INTERFACE, dev, part);
146 set_default_env(NULL);
150 err = file_fat_read(FAT_ENV_FILE, (uchar *)&buf, CONFIG_ENV_SIZE);
152 printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
153 FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part);
154 set_default_env(NULL);