1 #ifndef DEFINE_HEADER 2 #define DEFINE_HEADER 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <stdarg.h> 6 #include <string.h> 7 #include <sys/stat.h> 8 #include <dirent.h> 9 #include <time.h> 10 #include <unistd.h> 11 #include <wchar.h> 12 #include <errno.h> 13 #include <pthread.h> 14 #include <libusb.h> 15 16 #include "Property.hpp" 17 #include <list> 18 #include <vector> 19 #include <set> 20 #include <string> 21 #include <sstream> 22 #include <algorithm> 23 using namespace std; 24 typedef unsigned char BYTE, *PBYTE; 25 typedef unsigned char UCHAR; 26 typedef unsigned short WCHAR; 27 typedef unsigned short USHORT; 28 typedef unsigned int UINT; 29 typedef unsigned int DWORD; 30 #define ALIGN(x, a) __ALIGN_MASK((x), (a) - 1) 31 #define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) 32 #define RK28_SEC2_RESERVED_LEN 473 33 #define CHIPINFO_LEN 16 34 #define RK28_SEC3_RESERVED_LEN 382 35 #define RKDEVICE_SN_LEN 60 36 #define RKDEVICE_UID_LEN 30 37 #define RKDEVICE_MAC_LEN 6 38 #define RKDEVICE_WIFI_LEN 6 39 #define RKDEVICE_BT_LEN 6 40 #define RKDEVICE_IMEI_LEN 15 41 typedef enum{ 42 RKNONE_DEVICE = 0, 43 RK27_DEVICE = 0x10, 44 RKCAYMAN_DEVICE, 45 RK28_DEVICE = 0x20, 46 RK281X_DEVICE, 47 RKPANDA_DEVICE, 48 RKNANO_DEVICE = 0x30, 49 RKSMART_DEVICE, 50 RKCROWN_DEVICE = 0x40, 51 RK29_DEVICE = 0x50, 52 RK292X_DEVICE, 53 RK30_DEVICE = 0x60, 54 RK30B_DEVICE, 55 RK31_DEVICE = 0x70, 56 RK32_DEVICE = 0x80 57 } ENUM_RKDEVICE_TYPE; 58 typedef enum{ 59 RK_OS = 0, 60 ANDROID_OS = 0x1 61 } ENUM_OS_TYPE; 62 63 typedef enum{ 64 RKUSB_NONE = 0x0, 65 RKUSB_MASKROM = 0x01, 66 RKUSB_LOADER = 0x02, 67 RKUSB_MSC = 0x04 68 } ENUM_RKUSB_TYPE; 69 typedef enum{ 70 ENTRY471 = 1, 71 ENTRY472 = 2, 72 ENTRYLOADER = 4 73 } ENUM_RKBOOTENTRY; 74 75 #pragma pack(1) 76 typedef struct sparse_header_t { 77 UINT magic; /* 0xed26ff3a */ 78 USHORT major_version; /* (0x1) - reject images with higher major versions */ 79 USHORT minor_version; /* (0x0) - allow images with higer minor versions */ 80 USHORT file_hdr_sz; /* 28 bytes for first revision of the file format */ 81 USHORT chunk_hdr_sz; /* 12 bytes for first revision of the file format */ 82 UINT blk_sz; /* block size in bytes, must be a multiple of 4 (4096) */ 83 UINT total_blks; /* total blocks in the non-sparse output image */ 84 UINT total_chunks; /* total chunks in the sparse input image */ 85 UINT image_checksum; /* CRC32 checksum of the original data, counting "don't care" */ 86 /* as 0. Standard 802.3 polynomial, use a Public Domain */ 87 /* table implementation */ 88 } sparse_header; 89 #define SPARSE_HEADER_MAGIC 0xed26ff3a 90 #define UBI_HEADER_MAGIC 0x23494255 91 #define CHUNK_TYPE_RAW 0xCAC1 92 #define CHUNK_TYPE_FILL 0xCAC2 93 #define CHUNK_TYPE_DONT_CARE 0xCAC3 94 #define CHUNK_TYPE_CRC32 0xCAC4 95 typedef struct chunk_header_t { 96 USHORT chunk_type; /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */ 97 USHORT reserved1; 98 UINT chunk_sz; /* in blocks in output image */ 99 UINT total_sz; /* in bytes of chunk input file including chunk header and data */ 100 } chunk_header; 101 102 typedef struct{ 103 USHORT usYear; 104 BYTE ucMonth; 105 BYTE ucDay; 106 BYTE ucHour; 107 BYTE ucMinute; 108 BYTE ucSecond; 109 } STRUCT_RKTIME, *PSTRUCT_RKTIME; 110 111 typedef struct{ 112 char szItemName[20]; 113 char szItemValue[256]; 114 } STRUCT_CONFIG_ITEM, *PSTRUCT_CONFIG_ITEM; 115 typedef struct 116 { 117 char szItemName[64]; 118 UINT uiItemOffset; 119 UINT uiItemSize; 120 }STRUCT_PARAM_ITEM,*PSTRUCT_PARAM_ITEM; 121 typedef struct _STRUCT_RKDEVICE_DESC{ 122 USHORT usVid; 123 USHORT usPid; 124 USHORT usbcdUsb; 125 UINT uiLocationID; 126 ENUM_RKUSB_TYPE emUsbType; 127 ENUM_RKDEVICE_TYPE emDeviceType; 128 void *pUsbHandle; 129 } STRUCT_RKDEVICE_DESC, *PSTRUCT_RKDEVICE_DESC; 130 typedef struct { 131 DWORD dwTag; 132 BYTE reserved[4]; 133 UINT uiRc4Flag; 134 USHORT usBootCode1Offset; 135 USHORT usBootCode2Offset; 136 BYTE reserved1[490]; 137 USHORT usBootDataSize; 138 USHORT usBootCodeSize; 139 USHORT usCrc; 140 } RK28_IDB_SEC0, *PRK28_IDB_SEC0; 141 142 typedef struct { 143 USHORT usSysReservedBlock; 144 USHORT usDisk0Size; 145 USHORT usDisk1Size; 146 USHORT usDisk2Size; 147 USHORT usDisk3Size; 148 UINT uiChipTag; 149 UINT uiMachineId; 150 USHORT usLoaderYear; 151 USHORT usLoaderDate; 152 USHORT usLoaderVer; 153 USHORT usLastLoaderVer; 154 USHORT usReadWriteTimes; 155 DWORD dwFwVer; 156 USHORT usMachineInfoLen; 157 UCHAR ucMachineInfo[30]; 158 USHORT usManufactoryInfoLen; 159 UCHAR ucManufactoryInfo[30]; 160 USHORT usFlashInfoOffset; 161 USHORT usFlashInfoLen; 162 UCHAR reserved[384]; 163 UINT uiFlashSize; 164 BYTE reserved1; 165 BYTE bAccessTime; 166 USHORT usBlockSize; 167 BYTE bPageSize; 168 BYTE bECCBits; 169 BYTE reserved2[8]; 170 USHORT usIdBlock0; 171 USHORT usIdBlock1; 172 USHORT usIdBlock2; 173 USHORT usIdBlock3; 174 USHORT usIdBlock4; 175 } RK28_IDB_SEC1, *PRK28_IDB_SEC1; 176 177 typedef struct { 178 USHORT usInfoSize; 179 BYTE bChipInfo[CHIPINFO_LEN]; 180 BYTE reserved[RK28_SEC2_RESERVED_LEN]; 181 char szVcTag[3]; 182 USHORT usSec0Crc; 183 USHORT usSec1Crc; 184 UINT uiBootCodeCrc; 185 USHORT usSec3CustomDataOffset; 186 USHORT usSec3CustomDataSize; 187 char szCrcTag[4]; 188 USHORT usSec3Crc; 189 } RK28_IDB_SEC2, *PRK28_IDB_SEC2; 190 191 typedef struct { 192 USHORT usSNSize; 193 BYTE sn[RKDEVICE_SN_LEN]; 194 BYTE reserved[RK28_SEC3_RESERVED_LEN]; 195 BYTE wifiSize; 196 BYTE wifiAddr[RKDEVICE_WIFI_LEN]; 197 BYTE imeiSize; 198 BYTE imei[RKDEVICE_IMEI_LEN]; 199 BYTE uidSize; 200 BYTE uid[RKDEVICE_UID_LEN]; 201 BYTE blueToothSize; 202 BYTE blueToothAddr[RKDEVICE_BT_LEN]; 203 BYTE macSize; 204 BYTE macAddr[RKDEVICE_MAC_LEN]; 205 } RK28_IDB_SEC3, *PRK28_IDB_SEC3; 206 #pragma pack() 207 typedef list<STRUCT_RKDEVICE_DESC> RKDEVICE_DESC_SET; 208 typedef RKDEVICE_DESC_SET::iterator device_list_iter; 209 typedef vector<string> STRING_VECTOR; 210 typedef vector<UINT> UINT_VECTOR; 211 typedef vector<STRUCT_CONFIG_ITEM> CONFIG_ITEM_VECTOR; 212 typedef vector<STRUCT_PARAM_ITEM> PARAM_ITEM_VECTOR; 213 typedef enum{ 214 TESTDEVICE_PROGRESS, 215 DOWNLOADIMAGE_PROGRESS, 216 CHECKIMAGE_PROGRESS, 217 TAGBADBLOCK_PROGRESS, 218 TESTBLOCK_PROGRESS, 219 ERASEFLASH_PROGRESS, 220 ERASESYSTEM_PROGRESS, 221 LOWERFORMAT_PROGRESS, 222 ERASEUSERDATA_PROGRESS 223 } ENUM_PROGRESS_PROMPT; 224 225 typedef enum{ 226 CALL_FIRST, 227 CALL_MIDDLE, 228 CALL_LAST 229 } ENUM_CALL_STEP; 230 231 typedef void (*ProgressPromptCB)(DWORD deviceLayer, ENUM_PROGRESS_PROMPT promptID, long long totalValue, long long currentValue, ENUM_CALL_STEP emCall); 232 233 // bool WideStringToString(wchar_t *pszSrc, char *&pszDest); 234 // bool StringToWideString(char *pszSrc, wchar_t *&pszDest); 235 #endif 236