Skip to content

Commit be354c1

Browse files
JoshWutrini
authored andcommitted
env_fat: use get_device_and_partition() during env save and load
Use get_device_and_partition() is better since: 1. It will call the device initialize function internally. So we can remove the mmc intialization code to save many lines. 2. It is used by fatls/fatload/fatwrite. So saveenv & load env should use it too. 3. It can parse the "D:P", "D", "D:", "D:auto" string to get correct device and partition information by run-time. Also we remove the FAT_ENV_DEVICE and FAT_ENV_PART. We use a string: FAT_ENV_DEVICE_AND_PART. For at91sam9m10g45ek, it is "0". That means use device 0 and if: a)device 0 has no partition table, use the whole device as a FAT file system. b)device 0 has partittion table, use the partition KFire-Android#1. Refer to the commit: 10a37fd for details of device & partition string. Signed-off-by: Josh Wu <josh.wu@atmel.com> Reviewed-by: Stephen Warren <swarren@nvidia.com>
1 parent 8038b49 commit be354c1

File tree

2 files changed

+34
-60
lines changed

2 files changed

+34
-60
lines changed

common/env_fat.c

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,24 @@ int saveenv(void)
3838
{
3939
env_t env_new;
4040
block_dev_desc_t *dev_desc = NULL;
41-
int dev = FAT_ENV_DEVICE;
42-
int part = FAT_ENV_PART;
41+
disk_partition_t info;
42+
int dev, part;
4343
int err;
4444

4545
err = env_export(&env_new);
4646
if (err)
4747
return err;
4848

49-
#ifdef CONFIG_MMC
50-
if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) {
51-
struct mmc *mmc = find_mmc_device(dev);
52-
53-
if (!mmc) {
54-
printf("no mmc device at slot %x\n", dev);
55-
return 1;
56-
}
57-
58-
mmc->has_init = 0;
59-
mmc_init(mmc);
60-
}
61-
#endif /* CONFIG_MMC */
62-
63-
dev_desc = get_dev(FAT_ENV_INTERFACE, dev);
64-
if (dev_desc == NULL) {
65-
printf("Failed to find %s%d\n",
66-
FAT_ENV_INTERFACE, dev);
49+
part = get_device_and_partition(FAT_ENV_INTERFACE,
50+
FAT_ENV_DEVICE_AND_PART,
51+
&dev_desc, &info, 1);
52+
if (part < 0)
6753
return 1;
68-
}
6954

70-
err = fat_register_device(dev_desc, part);
71-
if (err) {
72-
printf("Failed to register %s%d:%d\n",
73-
FAT_ENV_INTERFACE, dev, part);
55+
dev = dev_desc->dev;
56+
if (fat_set_blk_dev(dev_desc, &info) != 0) {
57+
printf("\n** Unable to use %s %d:%d for saveenv **\n",
58+
FAT_ENV_INTERFACE, dev, part);
7459
return 1;
7560
}
7661

@@ -90,48 +75,33 @@ void env_relocate_spec(void)
9075
{
9176
char buf[CONFIG_ENV_SIZE];
9277
block_dev_desc_t *dev_desc = NULL;
93-
int dev = FAT_ENV_DEVICE;
94-
int part = FAT_ENV_PART;
78+
disk_partition_t info;
79+
int dev, part;
9580
int err;
9681

97-
#ifdef CONFIG_MMC
98-
if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) {
99-
struct mmc *mmc = find_mmc_device(dev);
100-
101-
if (!mmc) {
102-
printf("no mmc device at slot %x\n", dev);
103-
set_default_env(NULL);
104-
return;
105-
}
106-
107-
mmc->has_init = 0;
108-
mmc_init(mmc);
109-
}
110-
#endif /* CONFIG_MMC */
111-
112-
dev_desc = get_dev(FAT_ENV_INTERFACE, dev);
113-
if (dev_desc == NULL) {
114-
printf("Failed to find %s%d\n",
115-
FAT_ENV_INTERFACE, dev);
116-
set_default_env(NULL);
117-
return;
118-
}
119-
120-
err = fat_register_device(dev_desc, part);
121-
if (err) {
122-
printf("Failed to register %s%d:%d\n",
123-
FAT_ENV_INTERFACE, dev, part);
124-
set_default_env(NULL);
125-
return;
82+
part = get_device_and_partition(FAT_ENV_INTERFACE,
83+
FAT_ENV_DEVICE_AND_PART,
84+
&dev_desc, &info, 1);
85+
if (part < 0)
86+
goto err_env_relocate;
87+
88+
dev = dev_desc->dev;
89+
if (fat_set_blk_dev(dev_desc, &info) != 0) {
90+
printf("\n** Unable to use %s %d:%d for loading the env **\n",
91+
FAT_ENV_INTERFACE, dev, part);
92+
goto err_env_relocate;
12693
}
12794

12895
err = file_fat_read(FAT_ENV_FILE, (uchar *)&buf, CONFIG_ENV_SIZE);
12996
if (err == -1) {
13097
printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
13198
FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part);
132-
set_default_env(NULL);
133-
return;
99+
goto err_env_relocate;
134100
}
135101

136102
env_import(buf, 1);
103+
return;
104+
105+
err_env_relocate:
106+
set_default_env(NULL);
137107
}

include/configs/at91sam9m10g45ek.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@
167167
#elif CONFIG_SYS_USE_MMC
168168
/* bootstrap + u-boot + env + linux in mmc */
169169
#define FAT_ENV_INTERFACE "mmc"
170-
#define FAT_ENV_DEVICE 0
171-
#define FAT_ENV_PART 1
170+
/*
171+
* We don't specify the part number, if device 0 has partition table, it means
172+
* the first partition; it no partition table, then take whole device as a
173+
* FAT file system.
174+
*/
175+
#define FAT_ENV_DEVICE_AND_PART "0"
172176
#define FAT_ENV_FILE "uboot.env"
173177
#define CONFIG_ENV_IS_IN_FAT
174178
#define CONFIG_FAT_WRITE

0 commit comments

Comments
 (0)