99
1010#include "string.h"
1111
12+ #ifdef CONFIG_FATFS
1213#include "ff.h"
14+ #else
15+ #include "media.h"
16+ #include "fdt.h"
17+ #endif
1318
1419#include "debug.h"
1520
1621#define CHUNK_SIZE 0x40000
1722
23+ #ifdef CONFIG_FATFS
1824static int sdcard_loadimage (char * filename , BYTE * dest )
1925{
2026 FIL file ;
@@ -81,7 +87,7 @@ static int sdcard_read_cmd(char *cmdline_file, char *cmdline_args)
8187 ret = -1 ;
8288 goto read_fail ;
8389 }
84-
90+
8591 ret = 0 ;
8692
8793read_fail :
@@ -92,11 +98,43 @@ static int sdcard_read_cmd(char *cmdline_file, char *cmdline_args)
9298
9399}
94100#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+
95128
96129int load_sdcard (struct image_info * image )
97130{
131+ #ifdef CONFIG_FATFS
98132 FATFS fs ;
99133 FRESULT fret ;
134+ #else
135+ unsigned int start_block ;
136+ unsigned int block_count ;
137+ #endif
100138 int ret ;
101139
102140#ifdef CONFIG_AT91_MCI
@@ -113,6 +151,7 @@ int load_sdcard(struct image_info *image)
113151 at91_sdhc_hw_init ();
114152#endif
115153
154+ #ifdef CONFIG_FATFS
116155 /* mount fs */
117156 fret = f_mount (0 , & fs );
118157 if (fret != FR_OK ) {
@@ -171,4 +210,50 @@ int load_sdcard(struct image_info *image)
171210 }
172211
173212 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+ if (ret ) {
235+ return ret ;
236+ }
237+
238+ #ifdef CONFIG_OF_LIBFDT
239+ length = update_image_length (image -> of_offset ,
240+ image -> of_dest , DT_BLOB );
241+ if (length == -1 )
242+ return -1 ;
243+
244+ image -> of_length = length ;
245+
246+ dbg_info ("SD/MMC: dt blob: Copy %x bytes from %x to %x\n" ,
247+ image -> of_length , image -> of_offset , image -> of_dest );
248+
249+ start_block = image -> of_offset / 512 ;
250+ block_count = (image -> of_length + 511 ) / 512 ;
251+
252+ ret = sdcard_block_read (start_block , block_count , image -> of_dest );
253+ if (ret ) {
254+ return ret ;
255+ }
256+ #endif
257+ return 0 ;
258+ #endif
174259}
0 commit comments