501bd2855c2652df96e1c25c978fec402e32f47d
[profile/mobile/platform/kernel/u-boot-tm1.git] / sd_ramdisk.c
1
2 #include <linux/types.h>
3 #include <common.h>
4 #include <part.h>
5 #include <mmc.h>
6 #include <fat.h>
7
8 //rootfs.cpio.gz
9 #define SD_RAMDISK   "ramdisk.img"
10
11 #define TEST_VERIFY_FILE ".sprdtest"
12
13 int load_sd_ramdisk(void* buf,int size)
14 {
15         struct mmc *mmc;
16         block_dev_desc_t *dev_desc=NULL;
17         int ret = 0;
18         char bufread[10];
19
20         printf("%s: tick=%ld\n",__func__,get_ticks());
21
22         mmc = find_mmc_device(0);
23         if(mmc){
24                 ret = mmc_init(mmc);
25                 if(ret < 0){
26                         printf("mmc init failed %d,tick=%d\n", ret,get_ticks());
27                         return -1;
28                 }
29         }else{
30                 printf("no mmc card found\n");
31                 return -1;
32         }
33
34         dev_desc = &mmc->block_dev;
35         if(dev_desc==NULL){
36                 printf("no mmc block device found\n");
37                 return -1;
38         }
39         ret = fat_register_device(dev_desc, 1);
40         if(ret < 0){
41                 printf("fat regist fail %d\n", ret);
42                 return -1;
43         }
44         ret = file_fat_detectfs();
45         if(ret){
46                 printf("detect fs failed\n");
47                 return -1;
48         }
49
50         ret = file_fat_read(TEST_VERIFY_FILE, bufread, 10);
51         if (ret<=0){
52                 printf("sd verity file read error %d\n", ret);
53                 return ret;
54         }
55
56         ret = file_fat_read(SD_RAMDISK, buf, size);
57         if(ret <= 0){
58                 printf("sd file read error %d\n", ret);
59         }
60         printf("fat_read %d,tick=%ld\n", ret,get_ticks());
61         return ret;
62 }
63