tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / nand_fdl / fdl-2 / inc / fdl_emmc_operate.h
1 #ifndef _FDL_EMMC_OPERATE_H
2 #define _FDL_EMMC_OPERATE_H
3
4 #include <asm/arch/fdl_stdio.h>
5 #include <asm/arch/cmd_def.h>
6 #include <asm/arch/packet.h>
7 #ifdef CONFIG_EMMC_BOOT
8 #include "../../../disk/part_uefi.h"
9 #include "../../../include/part.h"
10
11 #define EMMC_SUCCESS                0
12 #define EMMC_SYSTEM_ERROR           1
13 #define EMMC_DEVICE_INIT_ERROR      2
14 #define EMMC_INVALID_DEVICE_SIZE    3
15 #define EMMC_INCOMPATIBLE_PART      4
16 #define EMMC_INVALID_ADDR           5
17 #define EMMC_INVALID_SIZE           6
18
19 #define DEBUG 1
20
21 //TODO, not well here
22 #ifdef DEBUG
23 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
24 #else
25 #define debugf(fmt, args...)
26 #endif
27
28 static __inline DLSTATUS convert_err (int err)
29 {
30     switch (err)
31     {
32         case EMMC_SUCCESS:
33             return BSL_REP_ACK;
34         case EMMC_INVALID_ADDR:
35             return BSL_REP_DOWN_DEST_ERROR;
36         case EMMC_INVALID_SIZE:
37             return BSL_REP_DOWN_SIZE_ERROR;
38         case EMMC_DEVICE_INIT_ERROR:
39             return BSL_UNKNOWN_DEVICE;
40         case EMMC_INVALID_DEVICE_SIZE:
41             return BSL_INVALID_DEVICE_SIZE;
42         case EMMC_INCOMPATIBLE_PART:
43             return BSL_INCOMPATIBLE_PARTITION;
44         default:
45             return BSL_REP_OPERATION_FAILED;
46     }
47 }
48
49 typedef enum _PARTITION_IMG_TYPE
50 {
51         IMG_RAW = 0,
52         IMG_WITH_SPARSE = 1,
53         IMG_TYPE_MAX
54 }PARTITION_IMG_TYPE;
55
56 typedef enum _PARTITION_PURPOSE
57 {
58         PARTITION_PURPOSE_NORMAL,
59         PARTITION_PURPOSE_NV,
60         PARTITION_PURPOSE_MAX
61 }PARTITION_PURPOSE;
62
63 typedef struct DL_EMMC_STATUS_TAG
64 {
65         uint32 part_total_size ;
66         uint32 base_sector;
67         wchar_t *curUserPartitionName;
68         PARTITION_PURPOSE partitionpurpose;
69         uint8 curEMMCArea;
70         PARTITION_IMG_TYPE curImgType; 
71 } DL_EMMC_STATUS;
72
73 typedef struct DL_FILE_STATUS_TAG
74 {
75         unsigned long   total_size;
76         unsigned long   total_recv_size;
77         unsigned long   unsave_recv_size;
78 } DL_EMMC_FILE_STATUS;
79
80 typedef struct _SPECIAL_PARTITION_CFG
81 {
82         wchar_t* partition;
83         wchar_t* bak_partition;
84         PARTITION_IMG_TYPE imgattr;
85         PARTITION_PURPOSE purpose;
86 }SPECIAL_PARTITION_CFG;
87
88 #if defined(CONFIG_TIGER) || defined(CONFIG_SC7710G2) || defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
89 #define BOOTLOADER_HEADER_OFFSET 0x20
90 typedef struct{
91         uint32 version;
92         uint32 magicData;
93         uint32 checkSum;
94         uint32 hashLen;
95 }EMMC_BootHeader;
96 #endif
97
98 PUBLIC int fdl2_download_start(wchar_t * partition_name, unsigned long size, unsigned long nv_checksum);
99 PUBLIC int fdl2_download_midst(unsigned short size, char *buf);
100 PUBLIC int fdl2_download_end(void);
101 PUBLIC int fdl2_read_start(wchar_t* partition_name, unsigned long size);
102 PUBLIC int fdl2_read_midst(unsigned long size, unsigned long off, unsigned char * buf);
103 PUBLIC int fdl2_read_end(void);
104 PUBLIC int fdl2_erase(wchar_t * partition_name, unsigned long size);
105 PUBLIC int fdl2_repartition(unsigned short * partition_cfg, unsigned short total_partition_num);
106
107 #endif  //CONFIG_EMMC_BOOT
108 #endif  //_FDL_EMMC_OPERATE_H