9
9
10
10
#include "string.h"
11
11
12
+ #ifdef CONFIG_FATFS
12
13
#include "ff.h"
14
+ #else
15
+ #include "media.h"
16
+ #include "fdt.h"
17
+ #endif
13
18
14
19
#include "debug.h"
15
20
16
21
#define CHUNK_SIZE 0x40000
17
22
23
+ #ifdef CONFIG_FATFS
18
24
static int sdcard_loadimage (char * filename , BYTE * dest )
19
25
{
20
26
FIL file ;
@@ -81,7 +87,7 @@ static int sdcard_read_cmd(char *cmdline_file, char *cmdline_args)
81
87
ret = -1 ;
82
88
goto read_fail ;
83
89
}
84
-
90
+
85
91
ret = 0 ;
86
92
87
93
read_fail :
@@ -92,11 +98,43 @@ static int sdcard_read_cmd(char *cmdline_file, char *cmdline_args)
92
98
93
99
}
94
100
#endif
101
+ #else
102
+ #if defined(CONFIG_LOAD_LINUX ) || defined(CONFIG_LOAD_ANDROID )
103
+ static int update_image_length (unsigned int offset ,
104
+ unsigned char * dest ,
105
+ unsigned char flag )
106
+ {
107
+ unsigned int length = 512 ;
108
+ int ret ;
109
+
110
+ dbg_info ("SD/MMC: update image length from image\n" );
111
+
112
+ memcpy (dest , (const char * )offset , length );
113
+
114
+ if (flag == KERNEL_IMAGE )
115
+ return kernel_size (dest );
116
+ #ifdef CONFIG_OF_LIBFDT
117
+ else {
118
+ ret = check_dt_blob_valid ((void * )dest );
119
+ if (!ret )
120
+ return of_get_dt_total_size ((void * )dest );
121
+ }
122
+ #endif
123
+ return -1 ;
124
+ }
125
+ #endif
126
+ #endif
127
+
95
128
96
129
int load_sdcard (struct image_info * image )
97
130
{
131
+ #ifdef CONFIG_FATFS
98
132
FATFS fs ;
99
133
FRESULT fret ;
134
+ #else
135
+ unsigned int start_block ;
136
+ unsigned int block_count ;
137
+ #endif
100
138
int ret ;
101
139
102
140
#ifdef CONFIG_AT91_MCI
@@ -113,6 +151,7 @@ int load_sdcard(struct image_info *image)
113
151
at91_sdhc_hw_init ();
114
152
#endif
115
153
154
+ #ifdef CONFIG_FATFS
116
155
/* mount fs */
117
156
fret = f_mount (0 , & fs );
118
157
if (fret != FR_OK ) {
@@ -171,4 +210,54 @@ int load_sdcard(struct image_info *image)
171
210
}
172
211
173
212
return 0 ;
213
+ #else
214
+ ret = sdcard_initialize ();
215
+ if (ret ) {
216
+ return ret ;
217
+ }
218
+
219
+ #if defined(CONFIG_LOAD_LINUX ) || defined(CONFIG_LOAD_ANDROID )
220
+ int length = update_image_length (image -> offset , image -> dest , KERNEL_IMAGE );
221
+ if (length == -1 )
222
+ return -1 ;
223
+
224
+ image -> length = length ;
225
+ #endif
226
+
227
+ dbg_info ("SD/MMC: Copy %x bytes from %x to %x\n" ,
228
+ image -> length , image -> offset , image -> dest );
229
+
230
+ start_block = image -> offset / 512 ;
231
+ block_count = (image -> length + 511 ) / 512 ;
232
+
233
+ ret = sdcard_block_read (start_block , block_count , image -> dest );
234
+ ret = ret == block_count ? 0 : -1 ;
235
+ if (ret ) {
236
+ return ret ;
237
+ }
238
+
239
+ #ifdef CONFIG_OF_LIBFDT
240
+ if (image -> of_dest ) {
241
+ length = update_image_length (image -> of_offset ,
242
+ image -> of_dest , DT_BLOB );
243
+ if (length == -1 )
244
+ return -1 ;
245
+
246
+ image -> of_length = length ;
247
+
248
+ dbg_info ("SD/MMC: dt blob: Copy %x bytes from %x to %x\n" ,
249
+ image -> of_length , image -> of_offset , image -> of_dest );
250
+
251
+ start_block = image -> of_offset / 512 ;
252
+ block_count = (image -> of_length + 511 ) / 512 ;
253
+
254
+ ret = sdcard_block_read (start_block , block_count , image -> of_dest );
255
+ ret = ret == block_count ? 0 : -1 ;
256
+ if (ret ) {
257
+ return ret ;
258
+ }
259
+ }
260
+ #endif
261
+ return 0 ;
262
+ #endif
174
263
}
0 commit comments