Commit be354c1a214daeedb24d7716308432f188d0004c
Committed by
Tom Rini
1 parent
8038b497e7
Exists in
v2017.01-smarct4x
and in
40 other branches
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 #1. Refer to the commit: 10a37fd7a4 for details of device & partition string. Signed-off-by: Josh Wu <josh.wu@atmel.com> Reviewed-by: Stephen Warren <swarren@nvidia.com>
Showing 2 changed files with 34 additions and 60 deletions Side-by-side Diff
common/env_fat.c
... | ... | @@ -38,39 +38,24 @@ |
38 | 38 | { |
39 | 39 | env_t env_new; |
40 | 40 | 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; | |
43 | 43 | int err; |
44 | 44 | |
45 | 45 | err = env_export(&env_new); |
46 | 46 | if (err) |
47 | 47 | return err; |
48 | 48 | |
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) | |
67 | 53 | return 1; |
68 | - } | |
69 | 54 | |
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); | |
74 | 59 | return 1; |
75 | 60 | } |
76 | 61 | |
77 | 62 | |
78 | 63 | |
79 | 64 | |
80 | 65 | |
81 | 66 | |
82 | 67 | |
... | ... | @@ -90,49 +75,34 @@ |
90 | 75 | { |
91 | 76 | char buf[CONFIG_ENV_SIZE]; |
92 | 77 | 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; | |
95 | 80 | int err; |
96 | 81 | |
97 | -#ifdef CONFIG_MMC | |
98 | - if (strcmp(FAT_ENV_INTERFACE, "mmc") == 0) { | |
99 | - struct mmc *mmc = find_mmc_device(dev); | |
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; | |
100 | 87 | |
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); | |
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; | |
109 | 93 | } |
110 | -#endif /* CONFIG_MMC */ | |
111 | 94 | |
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; | |
126 | - } | |
127 | - | |
128 | 95 | err = file_fat_read(FAT_ENV_FILE, (uchar *)&buf, CONFIG_ENV_SIZE); |
129 | 96 | if (err == -1) { |
130 | 97 | printf("\n** Unable to read \"%s\" from %s%d:%d **\n", |
131 | 98 | FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part); |
132 | - set_default_env(NULL); | |
133 | - return; | |
99 | + goto err_env_relocate; | |
134 | 100 | } |
135 | 101 | |
136 | 102 | env_import(buf, 1); |
103 | + return; | |
104 | + | |
105 | +err_env_relocate: | |
106 | + set_default_env(NULL); | |
137 | 107 | } |
include/configs/at91sam9m10g45ek.h
... | ... | @@ -167,8 +167,12 @@ |
167 | 167 | #elif CONFIG_SYS_USE_MMC |
168 | 168 | /* bootstrap + u-boot + env + linux in mmc */ |
169 | 169 | #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" | |
172 | 176 | #define FAT_ENV_FILE "uboot.env" |
173 | 177 | #define CONFIG_ENV_IS_IN_FAT |
174 | 178 | #define CONFIG_FAT_WRITE |