3 #ifdef CONFIG_EMMC_BOOT
8 #include "asm/arch/sci_types.h"
9 #include <linux/crc32b.h>
11 #include <asm/arch/secure_boot.h>
12 #include "fdl_common.h"
13 #include "fdl_emmc_operate.h"
14 #include <ext_common.h>
16 #ifdef CONFIG_SECURE_BOOT
17 #include "secure_verify.h"
19 #define EFI_SECTOR_SIZE (512)
20 #define EMMC_MAX_MUTIL_WRITE (0x8000)
21 #define ERASE_SECTOR_SIZE ((64 * 1024) / EFI_SECTOR_SIZE)
22 #define EMMC_BUF_SIZE (((216 * 1024 * 1024) / EFI_SECTOR_SIZE) * EFI_SECTOR_SIZE)
24 #if defined(CONFIG_SPX30G) || defined(CONFIG_SC9630)
25 #define SPL_CHECKSUM_LEN 0x8000
27 #define SPL_CHECKSUM_LEN 0x6000
29 #define MAX_GPT_PARTITION_SUPPORT (50)
30 #define EMMC_ERASE_ALIGN_LENGTH (0x800)
32 static DL_EMMC_FILE_STATUS g_status;
33 static DL_EMMC_STATUS g_dl_eMMCStatus = {0, 0, 0xffffffff,0, 0, 0,0};
35 static unsigned long g_checksum;
36 static unsigned long g_sram_addr;
38 #if defined (CONFIG_SC8825) || defined (CONFIG_TIGER) || defined (CONFIG_SC8830) ||defined(CONFIG_SC9630)
39 unsigned char *g_eMMCBuf = (unsigned char*)0x82000000;
41 unsigned char *g_eMMCBuf = (unsigned char*)0x2000000;
44 unsigned int g_total_partition_number = 0;
46 static wchar_t s_uboot_partition[MAX_UTF_PARTITION_NAME_LEN] = L"uboot";
47 static wchar_t s_spl_loader_partition[MAX_UTF_PARTITION_NAME_LEN] = L"splloader";
49 static int uefi_part_info_ok_flag = 0;
50 static PARTITION_CFG uefi_part_info[MAX_GPT_PARTITION_SUPPORT] = {0};
51 static PARTITION_CFG s_sprd_emmc_partition_cfg[MAX_GPT_PARTITION_SUPPORT] = {0};
53 #ifdef CONFIG_SECURE_BOOT
54 static int check_secure_flag = 0;
55 static int secure_image_flag = 0;
57 static wchar_t* const s_force_secure_check[]={
58 L"boot",L"recovery",L"uboot",L"tdmodem",L"tddsp",L"wmodem",L"wdsp",L"wcnmodem",L"wl_modem", L"wl_ldsp", L"wl_gdsp", L"wl_warm", L"pm_sys", L"sml",L"tl_gdsp",L"tl_ldsp",L"tl_modem",NULL
63 partitions not for raw data or normal usage(e.g. nv and prodinfo) should config here.
64 partitions not list here mean raw data/normal usage.
66 static SPECIAL_PARTITION_CFG const s_special_partition_cfg[]={
67 {{L"fixnv1"},{L"fixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
68 {{L"runtimenv1"},{L"runtimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
69 {{L"tdfixnv1"},{L"tdfixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
70 {{L"tdruntimenv1"},{L"tdruntimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
71 {{L"g_fixnv1"},{L"g_fixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
72 {{L"g_runtimenv1"},{L"g_runtimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
73 {{L"l_fixnv1"},{L"l_fixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
74 {{L"l_runtimenv1"},{L"l_runtimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
75 {{L"tl_fixnv1"},{L"tl_fixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
76 {{L"tl_runtimenv1"},{L"tl_runtimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
77 {{L"lf_fixnv1"},{L"lf_fixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
78 {{L"lf_runtimenv1"},{L"lf_runtimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
79 {{L"wfixnv1"},{L"wfixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
80 {{L"wruntimenv1"},{L"wruntimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
81 {{L"wl_fixnv1"},{L"wl_fixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
82 {{L"wl_runtimenv1"},{L"wl_runtimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
83 {{L"wcnfixnv1"},{L"wcnfixnv2"},IMG_RAW,PARTITION_PURPOSE_NV},
84 {{L"wcnruntimenv1"},{L"wcnruntimenv2"},IMG_RAW,PARTITION_PURPOSE_NV},
85 {{L"system"},NULL,IMG_RAW,PARTITION_PURPOSE_NORMAL},
86 {{L"userdata"},NULL,IMG_WITH_SPARSE,PARTITION_PURPOSE_NORMAL},
87 {{L"cache"},NULL,IMG_WITH_SPARSE,PARTITION_PURPOSE_NORMAL},
88 {{L"prodnv"},NULL,IMG_RAW,PARTITION_PURPOSE_NORMAL},
89 {NULL,NULL,IMG_TYPE_MAX,PARTITION_PURPOSE_MAX}
92 static __inline void FDL2_eMMC_SendRep (unsigned long err)
94 FDL_SendAckPacket (convert_err (err));
98 just convert partition name wchar to char with violent.
100 LOCAL __inline char* _w2c(wchar_t *wchar)
102 static char buf[73]={0};
104 while((NULL != wchar[i]) && (i<72))
106 buf[i] = wchar[i]&0xFF;
114 LOCAL unsigned short eMMCCheckSum(const unsigned int *src, int len)
116 unsigned int sum = 0;
117 unsigned short *src_short_ptr = PNULL;
125 src_short_ptr = (unsigned short *) src;
129 sum += * (src_short_ptr);
135 sum += * ( (unsigned char *) (src_short_ptr));
138 sum = (sum >> 16) + (sum & 0x0FFFF);
141 return (unsigned short) (~sum);
143 LOCAL unsigned int get_pad_data(const unsigned int *src, int len, int offset, unsigned short sum)
145 unsigned int sum_tmp;
146 unsigned int sum1 = 0;
147 unsigned int pad_data;
150 sum_tmp = sum & 0xffff;
152 for(i = 0; i < offset; i++) {
155 for(i = (offset + 1); i < len; i++) {
158 pad_data = sum_tmp - sum1;
162 LOCAL void splFillCheckData(unsigned int * splBuf, int len)
164 #define MAGIC_DATA 0xAA55A5A5
165 #define CHECKSUM_START_OFFSET 0x28
166 #define MAGIC_DATA_SAVE_OFFSET (0x20/4)
167 #define CHECKSUM_SAVE_OFFSET (0x24/4)
169 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2) || defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
170 EMMC_BootHeader *header;
171 #if defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
172 unsigned int pad_data;
174 unsigned int w_offset;
175 w_len = (SPL_CHECKSUM_LEN-(BOOTLOADER_HEADER_OFFSET+sizeof(*header))) / 4;
176 w_offset = w_len - 1;
177 //pad the data inorder to make check sum to 0
178 pad_data = (unsigned int)get_pad_data((unsigned char*)splBuf+BOOTLOADER_HEADER_OFFSET+sizeof(*header), w_len, w_offset, 0);
179 *(volatile unsigned int *)((unsigned char*)splBuf+SPL_CHECKSUM_LEN - 4) = pad_data;
181 header = (EMMC_BootHeader *)((unsigned char*)splBuf+BOOTLOADER_HEADER_OFFSET);
183 header->magicData= MAGIC_DATA;
184 header->checkSum = (unsigned int)eMMCCheckSum((unsigned char*)splBuf+BOOTLOADER_HEADER_OFFSET+sizeof(*header), SPL_CHECKSUM_LEN-(BOOTLOADER_HEADER_OFFSET+sizeof(*header)));
185 #ifdef CONFIG_SECURE_BOOT
186 header->hashLen = CONFIG_SPL_HASH_LEN>>2;
192 *(splBuf + MAGIC_DATA_SAVE_OFFSET) = MAGIC_DATA;
193 *(splBuf + CHECKSUM_SAVE_OFFSET) = (unsigned int)eMMCCheckSum((unsigned int *)&splBuf[CHECKSUM_START_OFFSET/4], SPL_CHECKSUM_LEN - CHECKSUM_START_OFFSET);
194 // *(splBuf + CHECKSUM_SAVE_OFFSET) = splCheckSum(splBuf);
198 LOCAL int _uefi_get_part_info(void)
200 block_dev_desc_t *dev_desc = NULL;
201 disk_partition_t info;
205 if(uefi_part_info_ok_flag)
208 dev_desc = get_dev("mmc", 1);
209 if (dev_desc==NULL) {
213 debugf("%s:GPT PARTITION \n",__FUNCTION__);
215 if (get_all_partition_info(dev_desc, uefi_part_info, &g_total_partition_number) != 0)
218 uefi_part_info_ok_flag = 1;
222 LOCAL unsigned long efi_GetPartBaseSec(wchar_t *partition_name)
226 _uefi_get_part_info();
228 for(i=0;i<g_total_partition_number;i++)
230 if(wcscmp(partition_name, uefi_part_info[i].partition_name) == 0)
232 return uefi_part_info[i].partition_offset;
236 //Can't find the specified partition
237 debugf("%s: Can't find partition:%s!\n", __FUNCTION__,_w2c(partition_name));
238 FDL_SendAckPacket (BSL_INCOMPATIBLE_PARTITION);
242 LOCAL unsigned long efi_GetPartSize(wchar_t *partition_name)
246 _uefi_get_part_info();
248 for(i=0;i<g_total_partition_number;i++)
250 if(wcscmp(partition_name, uefi_part_info[i].partition_name) == 0)
251 return (EFI_SECTOR_SIZE * uefi_part_info[i].partition_size);
254 //Can't find the specified partition
255 debugf("%s: Can't find partition:%s!\n", __FUNCTION__,_w2c(partition_name));
256 FDL_SendAckPacket (BSL_INCOMPATIBLE_PARTITION);
260 LOCAL void _parser_repartition_cfg(unsigned short* partition_cfg, unsigned short total_partition_num)
263 unsigned long partition_size;
265 /*Decode String: Partition Name(72Byte)+SIZE(4Byte)+...*/
266 for(i=0;i<total_partition_num;i++)
268 partition_size = *(unsigned long *)(partition_cfg+38*(i+1)-2);
269 s_sprd_emmc_partition_cfg[i].partition_index = i+1;
270 //the partition size received from tool is MByte.
271 if(MAX_SIZE_FLAG == partition_size)
272 s_sprd_emmc_partition_cfg[i].partition_size = partition_size;
274 s_sprd_emmc_partition_cfg[i].partition_size = 1024*partition_size;
275 s_sprd_emmc_partition_cfg[i].partition_attr = PARTITION_RAW;//TODO
276 s_sprd_emmc_partition_cfg[i].partition_offset = 0;
277 for(j=0;j<MAX_UTF_PARTITION_NAME_LEN;j++)
279 s_sprd_emmc_partition_cfg[i].partition_name[j] = *(partition_cfg+38*i+j);
282 debugf("%s:partition name:%s,partition_size:0x%x\n",__FUNCTION__,_w2c(s_sprd_emmc_partition_cfg[i].partition_name),s_sprd_emmc_partition_cfg[i].partition_size);
288 Get the partition's target image type(raw data or others) and purpose(nv/prodinfo/normal).
290 LOCAL void _get_partition_attribute(wchar_t* partition_name)
294 for(i=0;s_special_partition_cfg[i].partition != NULL;i++)
296 if(wcscmp(s_special_partition_cfg[i].partition, partition_name) == 0)
298 g_dl_eMMCStatus.curImgType = s_special_partition_cfg[i].imgattr;
299 g_dl_eMMCStatus.partitionpurpose = s_special_partition_cfg[i].purpose;
300 debugf("%s:partition %s image type is %d,partitionpurpose:%d\n", __FUNCTION__,_w2c(partition_name),g_dl_eMMCStatus.curImgType,g_dl_eMMCStatus.partitionpurpose);
304 //default type is IMG_RAW
305 g_dl_eMMCStatus.curImgType = IMG_RAW;
306 g_dl_eMMCStatus.partitionpurpose = PARTITION_PURPOSE_NORMAL;
307 debugf("%s:partition %s image type is RAW, normal partition!\n", __FUNCTION__,_w2c(partition_name));
312 Check whether the partition to be operated is compatible.
314 LOCAL BOOLEAN _get_compatible_partition(wchar_t* partition_name)
318 //get special partition attr
319 _get_partition_attribute(partition_name);
320 //Get user partition info from eMMC
321 _uefi_get_part_info();
323 //Try to find the partition specified
324 if(wcscmp(partition_name, L"uboot") == 0)
326 g_dl_eMMCStatus.curUserPartitionName = s_uboot_partition;
329 if(wcscmp(partition_name, L"splloader") == 0)
331 g_dl_eMMCStatus.curUserPartitionName = s_spl_loader_partition;
335 for(i=0;i<g_total_partition_number;i++)
337 if(wcscmp(partition_name, uefi_part_info[i].partition_name) == 0)
339 g_dl_eMMCStatus.curUserPartitionName = uefi_part_info[i].partition_name;
343 //Can't find the specified partition
344 g_dl_eMMCStatus.curUserPartitionName = NULL;
345 debugf("%s:Can't find partition:%s \n", __FUNCTION__,_w2c(partition_name));
350 Get the backup partition name
352 LOCAL wchar_t * _get_backup_partition_name(wchar_t *partition_name)
356 for(i=0;s_special_partition_cfg[i].partition != NULL;i++)
358 if(wcscmp(partition_name, s_special_partition_cfg[i].partition) == 0)
360 return s_special_partition_cfg[i].bak_partition;
368 Partition Check Function
370 0:No partition table or not same with New
371 1:Same with new partition
373 LOCAL int _fdl2_check_partition_table(PARTITION_CFG* new_cfg, PARTITION_CFG* old_cfg, unsigned short total_partition_num)
376 debugf("_fdl2_check_partition_table -----\n");
378 uefi_part_info_ok_flag = 0;
380 if (!_uefi_get_part_info())
385 //we may modify starting LBA of first partition,so we should check it.
386 if(STARTING_LBA_OF_FIRST_PARTITION != old_cfg[0].partition_offset)
389 if(total_partition_num == g_total_partition_number)
391 for(i=0;i<total_partition_num;i++)
393 if(0 !=wcscmp(new_cfg[i].partition_name,old_cfg[i].partition_name))
400 the new_cfg partition size get from tool is xx kbyte,
401 the old_cfg partition size read from disk is yy*sector_size byte.
403 if(2*new_cfg[i].partition_size != old_cfg[i].partition_size && new_cfg[i].partition_size !=0xffffffff)
415 LOCAL int _format_sd_partition(void)
417 unsigned long part_size = 0;
418 unsigned long sd_data_size = 0;
419 unsigned long base_sector = 0;
421 part_size = efi_GetPartSize(g_dl_eMMCStatus.curUserPartitionName);
425 sd_data_size = newfs_msdos_main(g_eMMCBuf,part_size);
426 g_dl_eMMCStatus.curEMMCArea = PARTITION_USER;
427 base_sector = efi_GetPartBaseSec(g_dl_eMMCStatus.curUserPartitionName);
429 if (!Emmc_Erase(g_dl_eMMCStatus.curEMMCArea,base_sector,part_size / EFI_SECTOR_SIZE)) {
433 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, base_sector,sd_data_size / EFI_SECTOR_SIZE, g_eMMCBuf)) {
440 Erase the whole partition.
442 LOCAL int _emmc_real_erase_partition(wchar_t *partition_name)
444 unsigned long count=0, base_sector=0;
447 if(NULL == partition_name)
450 if (wcscmp(L"splloader", partition_name) == 0){
451 if(secureboot_enabled()){
454 count = Emmc_GetCapacity(PARTITION_BOOT1);
455 curArea = PARTITION_BOOT1;
457 }else if (wcscmp(L"uboot", partition_name) == 0){
458 count = Emmc_GetCapacity(PARTITION_BOOT2);
459 curArea = PARTITION_BOOT2;
463 curArea = PARTITION_USER;
464 count = efi_GetPartSize(partition_name); /* partition size : in bytes */
465 count = count / EFI_SECTOR_SIZE; /* partition size : in blocks */
466 base_sector = efi_GetPartBaseSec(partition_name);
469 if(count < EMMC_ERASE_ALIGN_LENGTH)
471 unsigned char buf[EMMC_ERASE_ALIGN_LENGTH*EFI_SECTOR_SIZE] = {0xFF};
472 if (!Emmc_Write(curArea, base_sector,count,buf))
477 if(base_sector%EMMC_ERASE_ALIGN_LENGTH)
479 unsigned char buf[EMMC_ERASE_ALIGN_LENGTH*EFI_SECTOR_SIZE] = {0xFF};
480 unsigned long base_sector_offset = 0;
482 base_sector_offset = EMMC_ERASE_ALIGN_LENGTH - base_sector%EMMC_ERASE_ALIGN_LENGTH;
483 if (!Emmc_Write(curArea, base_sector,base_sector_offset,buf))
485 count = ((count-base_sector_offset)/EMMC_ERASE_ALIGN_LENGTH)*EMMC_ERASE_ALIGN_LENGTH;
486 base_sector = base_sector + base_sector_offset;
489 count = (count/EMMC_ERASE_ALIGN_LENGTH)*EMMC_ERASE_ALIGN_LENGTH;
494 if (!Emmc_Erase(curArea, base_sector,count))
502 Fast erase userpartition use emmc_write .
504 LOCAL int _emmc_fast_erase_userpartition(wchar_t *partition_name)
506 unsigned long i, count, len, base_sector;
509 curArea = PARTITION_USER;
510 len = efi_GetPartSize(partition_name);
511 count = len / EFI_SECTOR_SIZE;
512 base_sector = efi_GetPartBaseSec(partition_name);
513 count = (count > ERASE_SECTOR_SIZE)?ERASE_SECTOR_SIZE:count;
514 memset(g_eMMCBuf, 0xff, count * EFI_SECTOR_SIZE);
515 if (!Emmc_Write(curArea, base_sector, count, (unsigned char *)g_eMMCBuf))
521 LOCAL int _emmc_erase_allflash(void)
526 _uefi_get_part_info();
527 memset(g_eMMCBuf, 0xff, ERASE_SECTOR_SIZE*EFI_SECTOR_SIZE);
528 //erase user partitions
529 for (i = 0; i < g_total_partition_number; i++) {
530 if (!_emmc_fast_erase_userpartition(uefi_part_info[i].partition_name))
533 //erase gpt header and partition entry table
534 if (!Emmc_Write(PARTITION_USER, 0, ERASE_SECTOR_SIZE, (unsigned char *)g_eMMCBuf))
536 //erase backup gpt header
537 count = Emmc_GetCapacity(PARTITION_USER);
538 if (!Emmc_Write(PARTITION_USER, count - 1, 1, (unsigned char *)g_eMMCBuf))
540 //erase boot1 partition
541 if(!_emmc_real_erase_partition(L"splloader"))
543 //erase boot2 partition
544 if(!_emmc_real_erase_partition(L"uboot"))
550 #ifdef CONFIG_SECURE_BOOT
551 int _check_secure_part(wchar_t *partition_name)
556 if(0 == wcscmp(s_force_secure_check[i], partition_name))
559 }while(s_force_secure_check[i]!=0);
564 LOCAL int _emmc_secure_download(wchar_t* partition_name)
566 unsigned long count = 0;
567 unsigned int saved = 0;
569 unsigned int base_sector = g_dl_eMMCStatus.base_sector;
572 if(secure_image_flag == 0)
574 else if(secure_image_flag == 1) {
575 if (wcscmp(L"uboot", partition_name) == 0){
576 secure_verify(L"splloader",g_eMMCBuf,0);
579 secure_verify(L"fdl2",g_eMMCBuf,0);
582 else if(secure_image_flag == 2)
583 secure_verify(L"splloader0",g_eMMCBuf,0);
586 if (0 == (g_status.unsave_recv_size % EFI_SECTOR_SIZE))
587 count = g_status.unsave_recv_size / EFI_SECTOR_SIZE;
589 count = g_status.unsave_recv_size / EFI_SECTOR_SIZE + 1;
593 each = MIN(count,EMMC_MAX_MUTIL_WRITE);
594 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, base_sector,
595 each, (unsigned char *) (g_eMMCBuf+(saved*EFI_SECTOR_SIZE))))
597 g_status.unsave_recv_size = 0;
598 SEND_ERROR_RSP (BSL_WRITE_ERROR);
608 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, efi_GetPartSize(g_dl_eMMCStatus.curUserPartitionName)/EFI_SECTOR_SIZE-8,
611 g_status.unsave_recv_size = 0;
612 SEND_ERROR_RSP (BSL_WRITE_ERROR);
617 g_status.unsave_recv_size = 0;
618 secure_image_flag = 0;
623 LOCAL int _emmc_download_image(unsigned long nSectorCount, unsigned long each_write_block, int is_total_recv)
625 unsigned long cnt, base_sector, trans_times, remain_block;
626 unsigned char *point;
629 #ifdef CONFIG_SECURE_BOOT
630 if(secure_image_flag >= 1)
634 if (IMG_WITH_SPARSE == g_dl_eMMCStatus.curImgType){
635 retval = write_simg2emmc("mmc", 1, g_dl_eMMCStatus.curUserPartitionName,
636 g_eMMCBuf, g_status.unsave_recv_size);
638 g_status.unsave_recv_size = 0;
639 SEND_ERROR_RSP (BSL_WRITE_ERROR);
643 unsigned long count = nSectorCount;
644 unsigned int saved = 0;
646 unsigned int base_sector = g_dl_eMMCStatus.base_sector;
648 each = MIN(count,each_write_block);
649 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, base_sector,
650 each, (unsigned char *) (g_eMMCBuf+(saved*EFI_SECTOR_SIZE)))) {
651 g_status.unsave_recv_size = 0;
652 SEND_ERROR_RSP (BSL_WRITE_ERROR);
661 if (IMG_WITH_SPARSE == g_dl_eMMCStatus.curImgType){
663 memmove(g_eMMCBuf, g_eMMCBuf + retval, g_status.unsave_recv_size - retval);
664 g_status.unsave_recv_size -= retval;
665 g_sram_addr = (unsigned long)(g_eMMCBuf+g_status.unsave_recv_size);
667 g_status.unsave_recv_size = 0;
668 g_sram_addr = (unsigned long)g_eMMCBuf;
671 g_status.unsave_recv_size = 0;
673 g_dl_eMMCStatus.base_sector += nSectorCount;
674 g_sram_addr = (unsigned long)g_eMMCBuf;
681 Function used for reading nv partition which has crc protection.
683 LOCAL BOOLEAN _read_nv_with_backup(wchar_t *partition_name, uint8* buf, uint32 size)
685 wchar_t *backup_partition_name = NULL;
686 uint8 header_buf[EFI_SECTOR_SIZE];
689 uint32 magic = 0,len = 0;
690 nv_header_t * header_p = NULL;
692 header_p = header_buf;
693 base_sector = efi_GetPartBaseSec(partition_name);
694 //read origin image header
695 memset(header_buf, 0, EFI_SECTOR_SIZE);
696 if(!Emmc_Read(PARTITION_USER, base_sector, 1, header_buf)){
697 debugf("_read_nv_with_backup read origin image header failed\n");
700 memcpy(&magic,header_buf,4);
701 if(NV_HEAD_MAGIC == magic){
704 debugf("_read_nv_with_backup origin image magic = 0x%x\n",magic);
707 memset(buf, 0xFF, size);
708 if(Emmc_Read(PARTITION_USER, base_sector, (size>>9)+1, (uint8*)buf)){
709 // get length and checksum
710 if(NV_HEAD_MAGIC == magic){
712 checkSum = header_p->checksum;
716 checkSum = (uint16)((((uint16)buf[size-3])<<8) | ((uint16)buf[size-4]));
719 if(fdl_check_crc(buf, len,checkSum)){
725 //get the backup partition name
726 backup_partition_name = _get_backup_partition_name(partition_name);
727 if(NULL== backup_partition_name){
730 base_sector = efi_GetPartBaseSec(backup_partition_name);
733 memset(header_buf, 0, EFI_SECTOR_SIZE);
734 if(!Emmc_Read(PARTITION_USER, base_sector, 1, header_buf)){
735 debugf("_read_nv_with_backup read backup image header failed\n");
738 memcpy(&magic,header_buf,4);
739 if(NV_HEAD_MAGIC == magic){
742 debugf("_read_nv_with_backup backup image magic = 0x%x\n",magic);
745 memset(buf, 0xFF, size);
746 if(Emmc_Read(PARTITION_USER, base_sector, (size>>9)+1, (uint8*)buf)){
747 //get length and checksum
748 if(NV_HEAD_MAGIC == magic){
750 checkSum = header_p->checksum;
754 checkSum = (uint16)((((uint16)buf[size-3])<<8) | ((uint16)buf[size-4]));
757 if(!fdl_check_crc(buf, len,checkSum)){
758 debugf("read backup image checksum error \n");;
765 LOCAL int _nv_img_check_and_write(wchar_t* partition, unsigned long size)
767 unsigned long nSectorCount, nSectorBase;
768 unsigned short sum = 0, *dataaddr;
769 wchar_t *backup_partition_name = NULL;
770 uint8 header_buf[EFI_SECTOR_SIZE];
771 nv_header_t * nv_header_p = NULL;
772 //uint32 checksum = 0;
774 if (0 == ((size + 4) % EFI_SECTOR_SIZE))
775 nSectorCount = (size + 4) / EFI_SECTOR_SIZE;
777 nSectorCount = (size + 4) / EFI_SECTOR_SIZE + 1;
779 memset(header_buf,0x00,EFI_SECTOR_SIZE);
780 nv_header_p = header_buf;
781 nv_header_p->magic = NV_HEAD_MAGIC;
782 nv_header_p->len = size;
783 nv_header_p->checksum = (unsigned long)fdl_calc_checksum(g_eMMCBuf,size);
784 nv_header_p->version = NV_VERSION;
785 //write the original partition
786 _emmc_real_erase_partition(partition);
787 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, g_dl_eMMCStatus.base_sector,
788 1, (unsigned char *)header_buf)) {
789 debugf("%s:original header %s write error! \n", __FUNCTION__,_w2c(partition));
790 SEND_ERROR_RSP (BSL_WRITE_ERROR);
793 g_dl_eMMCStatus.base_sector++;
794 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, g_dl_eMMCStatus.base_sector,
795 nSectorCount, (unsigned char *)g_eMMCBuf)) {
796 debugf("%s:original %s write error! \n", __FUNCTION__,_w2c(partition));
797 SEND_ERROR_RSP (BSL_WRITE_ERROR);
801 //write the backup partition
802 backup_partition_name = _get_backup_partition_name(partition);
803 nSectorBase = efi_GetPartBaseSec(backup_partition_name);
804 _emmc_real_erase_partition(backup_partition_name);
805 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, nSectorBase, 1,
806 (unsigned char *)header_buf)) {
807 debugf("%s:backup header %s write error! \n", __FUNCTION__,_w2c(partition));
808 SEND_ERROR_RSP (BSL_WRITE_ERROR);
812 if (!Emmc_Write(g_dl_eMMCStatus.curEMMCArea, nSectorBase, nSectorCount,
813 (unsigned char *)g_eMMCBuf)) {
814 debugf("%s:backup %s write error! \n", __FUNCTION__,_w2c(partition));
815 SEND_ERROR_RSP (BSL_WRITE_ERROR);
818 g_status.unsave_recv_size = 0;
822 PUBLIC int fdl2_download_start(wchar_t* partition_name, unsigned long size, unsigned long nv_checksum)
826 debugf("Enter %s,partition:%s,size:0x%x \n", __FUNCTION__,_w2c(partition_name),size);
828 g_status.total_size = size;
830 #ifdef CONFIG_SECURE_BOOT
831 if(_check_secure_part(partition_name))
833 check_secure_flag = 1;
834 secure_image_flag = 0;
837 check_secure_flag = 0;
838 secure_image_flag = 0;
842 if(!_get_compatible_partition(partition_name))
844 FDL_SendAckPacket (convert_err (EMMC_INCOMPATIBLE_PART));
848 if (PARTITION_PURPOSE_NV == g_dl_eMMCStatus.partitionpurpose)
850 g_dl_eMMCStatus.curEMMCArea = PARTITION_USER;
851 g_dl_eMMCStatus.part_total_size = efi_GetPartSize(g_dl_eMMCStatus.curUserPartitionName);
853 if ((size > g_dl_eMMCStatus.part_total_size) || (size > FIXNV_SIZE)) {
854 debugf("%s:size(0x%x) beyond max,size:0x%x,FIXNV_SIZE:0x%x !\n", __FUNCTION__,size,g_dl_eMMCStatus.part_total_size,FIXNV_SIZE);
855 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
858 g_dl_eMMCStatus.base_sector = efi_GetPartBaseSec(g_dl_eMMCStatus.curUserPartitionName);
859 memset(g_eMMCBuf, 0xff, FIXNV_SIZE + EFI_SECTOR_SIZE);
860 g_checksum = nv_checksum;
862 else if (wcscmp(L"splloader", g_dl_eMMCStatus.curUserPartitionName) == 0)
864 #ifdef CONFIG_SECURE_BOOT
865 secure_image_flag = 2;
867 //need to check secure
868 g_dl_eMMCStatus.curEMMCArea = PARTITION_BOOT1;
869 g_dl_eMMCStatus.part_total_size = EFI_SECTOR_SIZE * Emmc_GetCapacity(PARTITION_BOOT1);
870 g_dl_eMMCStatus.base_sector = 0;
871 memset(g_eMMCBuf, 0xff, g_dl_eMMCStatus.part_total_size);
872 if (size > g_dl_eMMCStatus.part_total_size) {
873 debugf("%s:size(0x%x) beyond max size:0x%x!\n", __FUNCTION__,size,g_dl_eMMCStatus.part_total_size);
874 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
878 else if (wcscmp(L"uboot", g_dl_eMMCStatus.curUserPartitionName) == 0)
880 g_dl_eMMCStatus.curEMMCArea = PARTITION_BOOT2;
881 g_dl_eMMCStatus.part_total_size = EFI_SECTOR_SIZE * Emmc_GetCapacity(PARTITION_BOOT2);
882 g_dl_eMMCStatus.base_sector = 0;
883 memset(g_eMMCBuf, 0xff, g_dl_eMMCStatus.part_total_size);
884 if (size > g_dl_eMMCStatus.part_total_size) {
885 debugf("%s:size(0x%x) beyond max size:0x%x!\n", __FUNCTION__,size,g_dl_eMMCStatus.part_total_size);
886 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
892 g_dl_eMMCStatus.curEMMCArea = PARTITION_USER;
894 if (IMG_WITH_SPARSE != g_dl_eMMCStatus.curImgType)
895 _emmc_real_erase_partition(g_dl_eMMCStatus.curUserPartitionName);
897 memset(g_eMMCBuf, 0, EMMC_BUF_SIZE);
899 g_dl_eMMCStatus.part_total_size = efi_GetPartSize(g_dl_eMMCStatus.curUserPartitionName);
900 if (size > g_dl_eMMCStatus.part_total_size) {
901 debugf("%s:size(0x%x) beyond max size:0x%x!\n", __FUNCTION__,size,g_dl_eMMCStatus.part_total_size);
902 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
905 g_dl_eMMCStatus.base_sector = efi_GetPartBaseSec(g_dl_eMMCStatus.curUserPartitionName);
908 g_status.total_recv_size = 0;
909 g_status.unsave_recv_size = 0;
910 g_sram_addr = (unsigned long)g_eMMCBuf;
911 FDL_SendAckPacket (BSL_REP_ACK);
915 PUBLIC int fdl2_download_midst(unsigned short size, char *buf)
917 unsigned long lastSize, nSectorCount;
918 unsigned long each_write_block = EMMC_MAX_MUTIL_WRITE;
920 if ((g_status.total_recv_size + size) > g_status.total_size) {
921 debugf("%s,size+recvd>total_size!\n", __FUNCTION__);
922 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
926 g_status.total_recv_size += size;
928 #ifdef CONFIG_SECURE_BOOT
929 if(check_secure_flag == 1)
931 check_secure_flag = 0;
932 if(secure_header_parser(buf) != 1)
934 secure_image_flag = 0;
935 SEND_ERROR_RSP(BSL_WRITE_ERROR);
939 secure_image_flag = 1;
943 if (EMMC_BUF_SIZE >= (g_status.unsave_recv_size + size))
945 memcpy((unsigned char *)g_sram_addr, buf, size);
947 g_status.unsave_recv_size += size;
949 if (EMMC_BUF_SIZE == g_status.unsave_recv_size)
951 if (0 == (EMMC_BUF_SIZE % EFI_SECTOR_SIZE))
952 nSectorCount = EMMC_BUF_SIZE / EFI_SECTOR_SIZE;
954 nSectorCount = EMMC_BUF_SIZE / EFI_SECTOR_SIZE + 1;
956 if(!_emmc_download_image(nSectorCount, each_write_block, FALSE))
959 else if (g_status.total_recv_size == g_status.total_size)
961 if (PARTITION_PURPOSE_NV == g_dl_eMMCStatus.partitionpurpose)
963 unsigned long fix_nv_checksum;
964 fix_nv_checksum = Get_CheckSum((unsigned char *) g_eMMCBuf, g_status.total_recv_size);
965 if (fix_nv_checksum != g_checksum) {
966 //may data transfer error
967 debugf("%s:nv data transfer error,checksum error!\n", __FUNCTION__);
968 SEND_ERROR_RSP(BSL_CHECKSUM_DIFF);
971 if(!_nv_img_check_and_write(g_dl_eMMCStatus.curUserPartitionName,FIXNV_SIZE))
976 if (g_status.unsave_recv_size != 0) {
977 if (0 == (g_status.unsave_recv_size % EFI_SECTOR_SIZE))
978 nSectorCount = g_status.unsave_recv_size / EFI_SECTOR_SIZE;
980 nSectorCount = g_status.unsave_recv_size / EFI_SECTOR_SIZE + 1;
982 if (wcscmp(L"splloader", g_dl_eMMCStatus.curUserPartitionName) == 0){
983 if (g_status.total_recv_size < SPL_CHECKSUM_LEN)
984 nSectorCount = SPL_CHECKSUM_LEN / EFI_SECTOR_SIZE;
985 splFillCheckData((unsigned int *) g_eMMCBuf, (int)g_status.total_recv_size);
988 if(!_emmc_download_image(nSectorCount, each_write_block, TRUE))
996 lastSize = EMMC_BUF_SIZE - g_status.unsave_recv_size;
997 memcpy((unsigned char *)g_sram_addr, buf, lastSize);
998 g_status.unsave_recv_size = EMMC_BUF_SIZE;
999 if (0 == (EMMC_BUF_SIZE % EFI_SECTOR_SIZE))
1000 nSectorCount = EMMC_BUF_SIZE / EFI_SECTOR_SIZE;
1002 nSectorCount = EMMC_BUF_SIZE / EFI_SECTOR_SIZE + 1;
1004 if(!_emmc_download_image(nSectorCount, each_write_block, FALSE))
1007 g_sram_addr = (unsigned long)(g_eMMCBuf + g_status.unsave_recv_size);
1008 memcpy((unsigned char *)g_sram_addr, (char *)(&buf[lastSize]), size - lastSize);
1009 g_status.unsave_recv_size += size - lastSize;
1010 g_sram_addr = (unsigned long)(g_eMMCBuf + g_status.unsave_recv_size);
1013 FDL2_eMMC_SendRep (EMMC_SUCCESS);
1017 PUBLIC int fdl2_download_end(void)
1019 #ifdef CONFIG_SECURE_BOOT
1020 if(_emmc_secure_download(g_dl_eMMCStatus.curUserPartitionName) != 1)
1022 debugf("%s:_emmc_secure_download error!\n", __FUNCTION__);
1023 FDL2_eMMC_SendRep (EMMC_SYSTEM_ERROR);
1027 if(g_status.unsave_recv_size != 0)
1029 debugf("%s:unsaved size is not zero!\n", __FUNCTION__);
1030 FDL2_eMMC_SendRep (EMMC_SYSTEM_ERROR);
1034 FDL2_eMMC_SendRep (EMMC_SUCCESS);
1035 g_status.total_size = 0;
1039 PUBLIC int fdl2_read_start(wchar_t* partition_name, unsigned long size)
1041 debugf("Enter %s,partition:%s,size:0x%x \n", __FUNCTION__,_w2c(partition_name),size);
1043 if(!_get_compatible_partition(partition_name))
1045 FDL_SendAckPacket (convert_err (EMMC_INCOMPATIBLE_PART));
1049 g_dl_eMMCStatus.curEMMCArea = PARTITION_USER;
1051 if(PARTITION_PURPOSE_NV == g_dl_eMMCStatus.partitionpurpose)
1053 g_dl_eMMCStatus.part_total_size = efi_GetPartSize(g_dl_eMMCStatus.curUserPartitionName);
1054 if ((size > g_dl_eMMCStatus.part_total_size) /*|| (size > FIXNV_SIZE)*/){
1055 debugf("%s:size(0x%x) beyond max size:0x%x!\n", __FUNCTION__,size,g_dl_eMMCStatus.part_total_size);
1056 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
1059 g_dl_eMMCStatus.base_sector = efi_GetPartBaseSec(g_dl_eMMCStatus.curUserPartitionName);
1061 else if (wcscmp(L"splloader", g_dl_eMMCStatus.curUserPartitionName) == 0)
1063 g_dl_eMMCStatus.curEMMCArea = PARTITION_BOOT1;
1064 g_dl_eMMCStatus.part_total_size = EFI_SECTOR_SIZE * Emmc_GetCapacity(PARTITION_BOOT1);
1065 g_dl_eMMCStatus.base_sector = 0;
1067 else if (wcscmp(L"uboot", g_dl_eMMCStatus.curUserPartitionName) == 0)
1069 g_dl_eMMCStatus.curEMMCArea = PARTITION_BOOT2;
1070 g_dl_eMMCStatus.part_total_size = EFI_SECTOR_SIZE * Emmc_GetCapacity(PARTITION_BOOT2);
1071 g_dl_eMMCStatus.base_sector = 0;
1075 g_dl_eMMCStatus.part_total_size = efi_GetPartSize(g_dl_eMMCStatus.curUserPartitionName);
1076 g_dl_eMMCStatus.base_sector = efi_GetPartBaseSec(g_dl_eMMCStatus.curUserPartitionName);
1079 if (size > g_dl_eMMCStatus.part_total_size)
1081 debugf("%s:size(0x%x) beyond max size:0x%x!\n", __FUNCTION__,size,g_dl_eMMCStatus.part_total_size);
1082 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
1086 if (wcscmp(L"prodnv", g_dl_eMMCStatus.curUserPartitionName) == 0)
1088 struct ext2_sblock *sblock=NULL;
1089 sblock = malloc(MAX(EFI_SECTOR_SIZE,sizeof(struct ext2_sblock)));
1091 debugf("malloc sblock failed\n");
1095 if (!Emmc_Read(g_dl_eMMCStatus.curEMMCArea,
1096 g_dl_eMMCStatus.base_sector + 2,/*superblock offset 2 sect*/
1097 1,/*superblock take one sect*/
1103 if(sblock->magic != EXT2_MAGIC){
1104 debugf("bad prodnv image magic\n");
1111 FDL_SendAckPacket (BSL_REP_ACK);
1114 FDL2_eMMC_SendRep (EMMC_SYSTEM_ERROR);
1118 PUBLIC int fdl2_read_midst(unsigned long size, unsigned long off, unsigned char *buf)
1120 unsigned long nSectorCount, nSectorOffset;
1122 if ((size +off) > g_dl_eMMCStatus.part_total_size)
1124 debugf("%s:size(0x%x)+off(0x%x) beyond max size(0x%x)!\n", __FUNCTION__,size,off,g_dl_eMMCStatus.part_total_size);
1125 FDL2_eMMC_SendRep (EMMC_INVALID_SIZE);
1129 if(PARTITION_PURPOSE_NV == g_dl_eMMCStatus.partitionpurpose)
1131 if(_read_nv_with_backup(g_dl_eMMCStatus.curUserPartitionName, g_eMMCBuf, FIXNV_SIZE))
1133 memcpy(buf, (unsigned char *)(g_eMMCBuf + off), size);
1138 FDL2_eMMC_SendRep (EMMC_SYSTEM_ERROR);
1144 if (0 == (size % EFI_SECTOR_SIZE))
1145 nSectorCount = size / EFI_SECTOR_SIZE;
1147 nSectorCount = size / EFI_SECTOR_SIZE + 1;
1148 nSectorOffset = off / EFI_SECTOR_SIZE;
1149 if (!Emmc_Read(g_dl_eMMCStatus.curEMMCArea, g_dl_eMMCStatus.base_sector + nSectorOffset, nSectorCount, buf ))
1151 debugf("%s: read error!\n", __FUNCTION__);
1152 FDL2_eMMC_SendRep (EMMC_SYSTEM_ERROR);
1159 LOCAL void _checkNVPartition(void){
1162 wchar_t *backup_partition_name = NULL;
1163 uint8 ori_header_buf[EFI_SECTOR_SIZE];
1164 uint8 backup_header_buf[EFI_SECTOR_SIZE];
1166 uint16 checkSum = 0;
1168 nv_header_t * header_p = NULL;
1170 uint32 size = FIXNV_SIZE;
1172 debugf("check nv partition enter\n");
1173 ori_buf = malloc(size+EFI_SECTOR_SIZE);
1175 debugf("check nv partition malloc oribuf failed\n");
1178 debugf("check nv partition ori_buf 0x%x\n",ori_buf);
1179 backup_buf = malloc(size+EFI_SECTOR_SIZE);
1181 debugf("check nv partition malloc backup_buf failed\n");
1185 debugf("check nv partition backup_buf 0x%x\n",backup_buf);
1186 header_p = ori_header_buf;
1187 base_sector = efi_GetPartBaseSec(g_dl_eMMCStatus.curUserPartitionName);
1188 //read origin image header
1189 memset(ori_header_buf, 0, EFI_SECTOR_SIZE);
1190 if(!Emmc_Read(PARTITION_USER, base_sector, 1, ori_header_buf)){
1191 debugf("_checkNVPartition read origin image header failed\n");
1196 if(NV_HEAD_MAGIC == header_p->magic){
1199 debugf("_checkNVPartition origin image magic = 0x%x\n",header_p->magic);
1202 memset(ori_buf, 0xFF, size+EFI_SECTOR_SIZE);
1203 if(Emmc_Read(PARTITION_USER, base_sector, ((size+EFI_SECTOR_SIZE-1)&~(EFI_SECTOR_SIZE-1))>>9, (uint8*)ori_buf)){
1204 // get length and checksum
1205 if(NV_HEAD_MAGIC == header_p->magic){
1206 len = header_p->len;
1207 checkSum = header_p->checksum;
1211 checkSum = (uint16)((((uint16)ori_buf[size-3])<<8) | ((uint16)ori_buf[size-4]));
1214 if(fdl_check_crc(ori_buf, len,checkSum)){
1220 //get the backup partition name
1221 backup_partition_name = _get_backup_partition_name(g_dl_eMMCStatus.curUserPartitionName);
1222 if(NULL== backup_partition_name){
1227 base_sector = efi_GetPartBaseSec(backup_partition_name);
1228 //read backup header
1229 header_p = backup_header_buf;
1230 memset(backup_header_buf, 0, EFI_SECTOR_SIZE);
1231 if(!Emmc_Read(PARTITION_USER, base_sector, 1, backup_header_buf)){
1232 debugf("_read_nv_with_backup read backup image header failed\n");
1238 if(NV_HEAD_MAGIC == header_p->magic){
1241 debugf("_read_nv_with_backup backup image magic = 0x%x\n",header_p->magic);
1244 memset(backup_buf, 0xFF, size+EFI_SECTOR_SIZE);
1245 if(Emmc_Read(PARTITION_USER, base_sector, ((size+EFI_SECTOR_SIZE-1)&~(EFI_SECTOR_SIZE-1))>>9, (uint8*)backup_buf)){
1246 //get length and checksum
1247 if(NV_HEAD_MAGIC == header_p->magic){
1248 len = header_p->len;
1249 checkSum = header_p->checksum;
1253 checkSum = (uint16)((((uint16)backup_buf[size-3])<<8) | ((uint16)backup_buf[size-4]));
1256 if(fdl_check_crc(backup_buf, len,checkSum)){
1257 status |= 2;//four status:00,01,10,11
1262 debugf("%s:both org and bak partition are damaged!\n",__FUNCTION__);
1265 debugf("%s:bak partition is damaged!\n",__FUNCTION__);
1266 base_sector = efi_GetPartBaseSec(backup_partition_name);
1267 header_p = ori_header_buf;
1268 if(NV_HEAD_MAGIC == header_p->magic){
1269 if(Emmc_Write(PARTITION_USER, base_sector, 1, ori_header_buf)){
1270 debugf("write backup nv header success\n");
1274 //write one more sector
1275 if(Emmc_Write(PARTITION_USER, base_sector, ((size+EFI_SECTOR_SIZE-1)&~(EFI_SECTOR_SIZE-1))>>9, (uint8*)ori_buf)){
1276 debugf("write backup nv body success\n");
1280 debugf("%s:org partition is damaged!\n!",__FUNCTION__);
1281 base_sector = efi_GetPartBaseSec(g_dl_eMMCStatus.curUserPartitionName);
1282 header_p = backup_header_buf;
1283 if(NV_HEAD_MAGIC == header_p->magic){
1284 if(Emmc_Write(PARTITION_USER, base_sector, 1, backup_header_buf)){
1285 debugf("write original partition header success\n");
1289 if(Emmc_Write(PARTITION_USER, base_sector, ((size+EFI_SECTOR_SIZE-1)&~(EFI_SECTOR_SIZE-1))>>9, (uint8*)backup_buf)){
1290 debugf("write original partition body success\n");
1294 debugf("%s:both org and bak partition are ok!\n",__FUNCTION__);
1297 debugf("%s: status error!\n",__FUNCTION__);
1306 PUBLIC int fdl2_read_end(void)
1308 //Just send ack to tool in emmc
1309 printf("g_dl_eMMCStatus.partitionpurpose = %d\n",g_dl_eMMCStatus.partitionpurpose);
1310 if(PARTITION_PURPOSE_NV == g_dl_eMMCStatus.partitionpurpose){
1311 _checkNVPartition();
1313 FDL_SendAckPacket (BSL_REP_ACK);
1317 PUBLIC int fdl2_erase(wchar_t* partition_name, unsigned long size)
1320 unsigned long part_size;
1321 wchar_t *backup_partition_name = NULL;
1323 if ((wcscmp(partition_name, L"erase_all") == 0) && (size = 0xffffffff)) {
1324 debugf("%s:Erase all!\n", __FUNCTION__);
1325 if (!_emmc_erase_allflash()) {
1326 SEND_ERROR_RSP (BSL_WRITE_ERROR);
1330 debugf("%s:erase partition %s!\n", __FUNCTION__,_w2c(partition_name));
1331 if(!_get_compatible_partition(partition_name))
1333 FDL_SendAckPacket (BSL_INCOMPATIBLE_PARTITION);
1337 if (!_emmc_real_erase_partition(g_dl_eMMCStatus.curUserPartitionName)) {
1338 SEND_ERROR_RSP (BSL_WRITE_ERROR);
1342 backup_partition_name = _get_backup_partition_name(g_dl_eMMCStatus.curUserPartitionName);
1344 if(NULL != backup_partition_name)
1346 if (!_emmc_real_erase_partition(backup_partition_name)) {
1347 SEND_ERROR_RSP (BSL_WRITE_ERROR);
1352 if (wcscmp(L"sd", g_dl_eMMCStatus.curUserPartitionName) == 0) {
1353 debugf("formating sd partition, waiting for a while!\n");
1354 if (_format_sd_partition() == -1){
1355 debugf("format sd partition failed\n");
1356 SEND_ERROR_RSP (BSL_WRITE_ERROR);
1362 FDL2_eMMC_SendRep (EMMC_SUCCESS);
1366 PUBLIC int fdl2_repartition(unsigned short* partition_cfg, unsigned short total_partition_num)
1370 _parser_repartition_cfg(partition_cfg, total_partition_num);
1372 if(_fdl2_check_partition_table(s_sprd_emmc_partition_cfg, uefi_part_info, total_partition_num))
1374 debugf("%s:Partition Config same with before!\n",__FUNCTION__);
1375 FDL2_eMMC_SendRep (EMMC_SUCCESS);
1379 for (i = 0; i < 3; i++) {
1380 write_uefi_partition_table(s_sprd_emmc_partition_cfg);
1381 if (_fdl2_check_partition_table(s_sprd_emmc_partition_cfg, uefi_part_info, total_partition_num))
1386 FDL2_eMMC_SendRep (EMMC_SUCCESS);
1389 FDL2_eMMC_SendRep (EMMC_SYSTEM_ERROR);