2 #include <linux/types.h>
3 #include <linux/string.h>
5 #include <jffs2/jffs2.h>
9 #ifdef CONFIG_EMMC_BOOT
10 #include "../disk/part_uefi.h"
11 #include "../drivers/mmc/card_sdio.h"
14 int do_fs_file_read(char *mpart, char *filenm, void *buf, int len)
21 part = malloc(sizeof(wchar_t)*(strlen(mpart)+1));
25 while ((*tmp++ = *mpart++) != '\0')
27 ret = ext4_read_content(mmc_dev,
31 0,/*not support non-zero offset*/
34 #elif defined(CONFIG_FS_UBIFS)
35 static int is_ubifs_init = 0;
36 if(is_ubifs_init == 0){
41 ret = ubifs_mount(mpart);
43 printf("do_fs_file_read:mount %s failed!\n",mpart);
46 ret = ubifs_load(filenm, buf, len);
48 printf("do_fs_file_read:file %s not found!\n", filenm);
53 int do_fs_file_write(char *mpart, char *filenm, void *buf, int len)
55 /*do not write in uboot now*/
59 int do_raw_data_read(char *part, u32 size, u32 off, char *buf)
62 #ifdef CONFIG_EMMC_BOOT
63 u16 offp=0, len=0, left=0;
67 wchar_t *partition=NULL;
69 disk_partition_t info;
70 block_dev_desc_t *dev = NULL;
75 dev = get_dev("mmc", 1);
77 printf("get mmc dev failed!\n");
81 partition = malloc(sizeof(wchar_t)*(strlen(part)+1));
85 while ((*tmp++ = *part++) != '\0');
87 offp = off%EMMC_SECTOR_SIZE;
90 len = EMMC_SECTOR_SIZE - offp;
93 nsct = size/EMMC_SECTOR_SIZE;
94 left = size%EMMC_SECTOR_SIZE;
97 sctbuf = malloc(EMMC_SECTOR_SIZE);
104 if(get_partition_info_by_name(dev, partition, &info))
107 cursct = info.start + off/EMMC_SECTOR_SIZE;
108 //read first unaligned data
110 if(!Emmc_Read(PARTITION_USER, cursct, 1, sctbuf))
113 memcpy(bufwp,sctbuf+offp,len);
116 //read sector aligned data
118 if(!Emmc_Read(PARTITION_USER, cursct, nsct, bufwp))
123 //read last unaligned data
125 if(!Emmc_Read(PARTITION_USER, cursct, 1, sctbuf))
127 memcpy(bufwp,sctbuf,left);
132 printf("do_raw_data_read: wanted size :0x%x, real 0x%x\n",size+len,bufwp-buf);
138 struct ubi_volume_desc *vol;
140 ubi_dev = nand_ubi_dev_init();
142 printf("do_raw_data_read: ubi init failed.\n");
145 vol = ubi_open_volume_nm(ubi_dev, part, UBI_READONLY);
147 printf("cannot open \"%s\", error %d",
148 part, (int)PTR_ERR(vol));
152 if(size != uboot_ubi_read(vol, buf, off, size))
153 printf("%s: read vol %s failed!\n",__func__,part);
157 ubi_close_volume(vol);
160 printf("do_raw_data_read error.\n");
164 int do_raw_data_write(char *part, u32 updsz, u32 size, u32 off, char *buf)
167 #ifdef CONFIG_EMMC_BOOT
174 size_t length,wlen=0;
175 struct mtd_device *dev;
176 struct mtd_info *nand;
177 struct part_info *mtdpart;
178 struct ubi_volume_desc *vol;
179 nand_erase_options_t opts;
182 ret = find_dev_and_part(part, &dev, &pnum, &mtdpart);
185 else if (dev->id->type != MTD_DEV_TYPE_NAND)
188 offset = mtdpart->offset+off;
190 nand = &nand_info[dev->id->num];
191 memset(&opts, 0x0, sizeof(opts));
192 opts.offset = offset;
193 opts.length = length;
197 ret = nand_erase_opts(nand, &opts);
199 printf("erase %s failed.\n",part);
202 //write spl part with header
203 if(strcmp(part, "spl")==0){
204 ret = sprd_nand_write_spl(buf, nand);
208 while((size != wlen) && (i++<0xff)) {
209 ret = nand_write_skip_bad(nand, offset, &length, buf);
215 //mark a block as badblock
216 printf("nand write error %d, mark bad block 0x%llx\n",ret,offset&~(nand->erasesize-1));
217 nand->block_markbad(nand,offset &~(nand->erasesize-1));
223 ubi_dev = nand_ubi_dev_init();
225 printf("do_raw_data_write: ubi init failed.\n");
228 vol = ubi_open_volume_nm(ubi_dev, part, UBI_READWRITE);
230 printf("cannot open \"%s\", error %d",
231 part, (int)PTR_ERR(vol));
235 //set total size to be updated in this volume
237 ret = ubi_start_update(vol->vol->ubi, vol->vol, updsz);
239 printf("Cannot start volume %s update\n",part);
244 ret = ubi_more_update_data(vol->vol->ubi, vol->vol, buf, size);
246 printf("Couldnt write data in volume %s\n",part);
250 ubi_close_volume(vol);
255 printf("do_raw_data_write error.\n");