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,54 @@ 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+ 	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 
174263}
0 commit comments