176af099aSliuyi #ifndef DEFINE_HEADER 276af099aSliuyi #define DEFINE_HEADER 376af099aSliuyi #include <stdio.h> 476af099aSliuyi #include <stdlib.h> 576af099aSliuyi #include <stdarg.h> 676af099aSliuyi #include <string.h> 776af099aSliuyi #include <sys/stat.h> 876af099aSliuyi #include <dirent.h> 976af099aSliuyi #include <time.h> 1076af099aSliuyi #include <unistd.h> 1176af099aSliuyi #include <iconv.h> 1276af099aSliuyi #include <wchar.h> 1376af099aSliuyi #include <errno.h> 1476af099aSliuyi #include <pthread.h> 1576af099aSliuyi #include <libusb.h> 1676af099aSliuyi 1776af099aSliuyi #include "Property.hpp" 1876af099aSliuyi #include <list> 1976af099aSliuyi #include <vector> 2076af099aSliuyi #include <set> 2176af099aSliuyi #include <string> 2276af099aSliuyi #include <sstream> 2376af099aSliuyi #include <algorithm> 2476af099aSliuyi using namespace std; 2576af099aSliuyi typedef unsigned char BYTE, *PBYTE; 2676af099aSliuyi typedef unsigned char UCHAR; 2776af099aSliuyi typedef unsigned short WCHAR; 2876af099aSliuyi typedef unsigned short USHORT; 2976af099aSliuyi typedef unsigned int UINT; 3076af099aSliuyi typedef unsigned int DWORD; 31*c30d921cSKever Yang #define ALIGN(x, a) __ALIGN_MASK((x), (a) - 1) 32*c30d921cSKever Yang #define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) 33*c30d921cSKever Yang #define RK28_SEC2_RESERVED_LEN 473 34*c30d921cSKever Yang #define CHIPINFO_LEN 16 35*c30d921cSKever Yang #define RK28_SEC3_RESERVED_LEN 382 36*c30d921cSKever Yang #define RKDEVICE_SN_LEN 60 37*c30d921cSKever Yang #define RKDEVICE_UID_LEN 30 38*c30d921cSKever Yang #define RKDEVICE_MAC_LEN 6 39*c30d921cSKever Yang #define RKDEVICE_WIFI_LEN 6 40*c30d921cSKever Yang #define RKDEVICE_BT_LEN 6 41*c30d921cSKever Yang #define RKDEVICE_IMEI_LEN 15 4276af099aSliuyi typedef enum{ 4376af099aSliuyi RKNONE_DEVICE = 0, 4476af099aSliuyi RK27_DEVICE = 0x10, 4576af099aSliuyi RKCAYMAN_DEVICE, 4676af099aSliuyi RK28_DEVICE = 0x20, 4776af099aSliuyi RK281X_DEVICE, 4876af099aSliuyi RKPANDA_DEVICE, 4976af099aSliuyi RKNANO_DEVICE = 0x30, 5076af099aSliuyi RKSMART_DEVICE, 5176af099aSliuyi RKCROWN_DEVICE = 0x40, 5276af099aSliuyi RK29_DEVICE = 0x50, 5376af099aSliuyi RK292X_DEVICE, 5476af099aSliuyi RK30_DEVICE = 0x60, 5576af099aSliuyi RK30B_DEVICE, 5676af099aSliuyi RK31_DEVICE = 0x70, 5776af099aSliuyi RK32_DEVICE = 0x80 5876af099aSliuyi } ENUM_RKDEVICE_TYPE; 5976af099aSliuyi typedef enum{ 6076af099aSliuyi RK_OS = 0, 6176af099aSliuyi ANDROID_OS = 0x1 6276af099aSliuyi } ENUM_OS_TYPE; 6376af099aSliuyi 6476af099aSliuyi typedef enum{ 6576af099aSliuyi RKUSB_NONE = 0x0, 6676af099aSliuyi RKUSB_MASKROM = 0x01, 6776af099aSliuyi RKUSB_LOADER = 0x02, 6876af099aSliuyi RKUSB_MSC = 0x04 6976af099aSliuyi } ENUM_RKUSB_TYPE; 7076af099aSliuyi typedef enum{ 7176af099aSliuyi ENTRY471 = 1, 7276af099aSliuyi ENTRY472 = 2, 7376af099aSliuyi ENTRYLOADER = 4 7476af099aSliuyi } ENUM_RKBOOTENTRY; 7576af099aSliuyi 7676af099aSliuyi #pragma pack(1) 7776af099aSliuyi typedef struct{ 7876af099aSliuyi USHORT usYear; 7976af099aSliuyi BYTE ucMonth; 8076af099aSliuyi BYTE ucDay; 8176af099aSliuyi BYTE ucHour; 8276af099aSliuyi BYTE ucMinute; 8376af099aSliuyi BYTE ucSecond; 8476af099aSliuyi } STRUCT_RKTIME, *PSTRUCT_RKTIME; 8576af099aSliuyi 8676af099aSliuyi typedef struct{ 8776af099aSliuyi char szItemName[20]; 8876af099aSliuyi char szItemValue[256]; 8976af099aSliuyi } STRUCT_CONFIG_ITEM, *PSTRUCT_CONFIG_ITEM; 90*c30d921cSKever Yang typedef struct 91*c30d921cSKever Yang { 92*c30d921cSKever Yang char szItemName[64]; 93*c30d921cSKever Yang UINT uiItemOffset; 94*c30d921cSKever Yang UINT uiItemSize; 95*c30d921cSKever Yang }STRUCT_PARAM_ITEM,*PSTRUCT_PARAM_ITEM; 9676af099aSliuyi typedef struct _STRUCT_RKDEVICE_DESC{ 9776af099aSliuyi USHORT usVid; 9876af099aSliuyi USHORT usPid; 9976af099aSliuyi USHORT usbcdUsb; 10076af099aSliuyi UINT uiLocationID; 10176af099aSliuyi ENUM_RKUSB_TYPE emUsbType; 10276af099aSliuyi ENUM_RKDEVICE_TYPE emDeviceType; 10376af099aSliuyi void *pUsbHandle; 10476af099aSliuyi } STRUCT_RKDEVICE_DESC, *PSTRUCT_RKDEVICE_DESC; 105*c30d921cSKever Yang typedef struct { 106*c30d921cSKever Yang DWORD dwTag; 107*c30d921cSKever Yang BYTE reserved[4]; 108*c30d921cSKever Yang UINT uiRc4Flag; 109*c30d921cSKever Yang USHORT usBootCode1Offset; 110*c30d921cSKever Yang USHORT usBootCode2Offset; 111*c30d921cSKever Yang BYTE reserved1[490]; 112*c30d921cSKever Yang USHORT usBootDataSize; 113*c30d921cSKever Yang USHORT usBootCodeSize; 114*c30d921cSKever Yang USHORT usCrc; 115*c30d921cSKever Yang } RK28_IDB_SEC0, *PRK28_IDB_SEC0; 116*c30d921cSKever Yang 117*c30d921cSKever Yang typedef struct { 118*c30d921cSKever Yang USHORT usSysReservedBlock; 119*c30d921cSKever Yang USHORT usDisk0Size; 120*c30d921cSKever Yang USHORT usDisk1Size; 121*c30d921cSKever Yang USHORT usDisk2Size; 122*c30d921cSKever Yang USHORT usDisk3Size; 123*c30d921cSKever Yang UINT uiChipTag; 124*c30d921cSKever Yang UINT uiMachineId; 125*c30d921cSKever Yang USHORT usLoaderYear; 126*c30d921cSKever Yang USHORT usLoaderDate; 127*c30d921cSKever Yang USHORT usLoaderVer; 128*c30d921cSKever Yang USHORT usLastLoaderVer; 129*c30d921cSKever Yang USHORT usReadWriteTimes; 130*c30d921cSKever Yang DWORD dwFwVer; 131*c30d921cSKever Yang USHORT usMachineInfoLen; 132*c30d921cSKever Yang UCHAR ucMachineInfo[30]; 133*c30d921cSKever Yang USHORT usManufactoryInfoLen; 134*c30d921cSKever Yang UCHAR ucManufactoryInfo[30]; 135*c30d921cSKever Yang USHORT usFlashInfoOffset; 136*c30d921cSKever Yang USHORT usFlashInfoLen; 137*c30d921cSKever Yang UCHAR reserved[384]; 138*c30d921cSKever Yang UINT uiFlashSize; 139*c30d921cSKever Yang BYTE reserved1; 140*c30d921cSKever Yang BYTE bAccessTime; 141*c30d921cSKever Yang USHORT usBlockSize; 142*c30d921cSKever Yang BYTE bPageSize; 143*c30d921cSKever Yang BYTE bECCBits; 144*c30d921cSKever Yang BYTE reserved2[8]; 145*c30d921cSKever Yang USHORT usIdBlock0; 146*c30d921cSKever Yang USHORT usIdBlock1; 147*c30d921cSKever Yang USHORT usIdBlock2; 148*c30d921cSKever Yang USHORT usIdBlock3; 149*c30d921cSKever Yang USHORT usIdBlock4; 150*c30d921cSKever Yang } RK28_IDB_SEC1, *PRK28_IDB_SEC1; 151*c30d921cSKever Yang 152*c30d921cSKever Yang typedef struct { 153*c30d921cSKever Yang USHORT usInfoSize; 154*c30d921cSKever Yang BYTE bChipInfo[CHIPINFO_LEN]; 155*c30d921cSKever Yang BYTE reserved[RK28_SEC2_RESERVED_LEN]; 156*c30d921cSKever Yang char szVcTag[3]; 157*c30d921cSKever Yang USHORT usSec0Crc; 158*c30d921cSKever Yang USHORT usSec1Crc; 159*c30d921cSKever Yang UINT uiBootCodeCrc; 160*c30d921cSKever Yang USHORT usSec3CustomDataOffset; 161*c30d921cSKever Yang USHORT usSec3CustomDataSize; 162*c30d921cSKever Yang char szCrcTag[4]; 163*c30d921cSKever Yang USHORT usSec3Crc; 164*c30d921cSKever Yang } RK28_IDB_SEC2, *PRK28_IDB_SEC2; 165*c30d921cSKever Yang 166*c30d921cSKever Yang typedef struct { 167*c30d921cSKever Yang USHORT usSNSize; 168*c30d921cSKever Yang BYTE sn[RKDEVICE_SN_LEN]; 169*c30d921cSKever Yang BYTE reserved[RK28_SEC3_RESERVED_LEN]; 170*c30d921cSKever Yang BYTE wifiSize; 171*c30d921cSKever Yang BYTE wifiAddr[RKDEVICE_WIFI_LEN]; 172*c30d921cSKever Yang BYTE imeiSize; 173*c30d921cSKever Yang BYTE imei[RKDEVICE_IMEI_LEN]; 174*c30d921cSKever Yang BYTE uidSize; 175*c30d921cSKever Yang BYTE uid[RKDEVICE_UID_LEN]; 176*c30d921cSKever Yang BYTE blueToothSize; 177*c30d921cSKever Yang BYTE blueToothAddr[RKDEVICE_BT_LEN]; 178*c30d921cSKever Yang BYTE macSize; 179*c30d921cSKever Yang BYTE macAddr[RKDEVICE_MAC_LEN]; 180*c30d921cSKever Yang } RK28_IDB_SEC3, *PRK28_IDB_SEC3; 18176af099aSliuyi #pragma pack() 18276af099aSliuyi typedef list<STRUCT_RKDEVICE_DESC> RKDEVICE_DESC_SET; 18376af099aSliuyi typedef RKDEVICE_DESC_SET::iterator device_list_iter; 18476af099aSliuyi typedef vector<string> STRING_VECTOR; 18576af099aSliuyi typedef vector<UINT> UINT_VECTOR; 18676af099aSliuyi typedef vector<STRUCT_CONFIG_ITEM> CONFIG_ITEM_VECTOR; 187*c30d921cSKever Yang typedef vector<STRUCT_PARAM_ITEM> PARAM_ITEM_VECTOR; 18876af099aSliuyi typedef enum{ 18976af099aSliuyi TESTDEVICE_PROGRESS, 19076af099aSliuyi DOWNLOADIMAGE_PROGRESS, 19176af099aSliuyi CHECKIMAGE_PROGRESS, 19276af099aSliuyi TAGBADBLOCK_PROGRESS, 19376af099aSliuyi TESTBLOCK_PROGRESS, 19476af099aSliuyi ERASEFLASH_PROGRESS, 19576af099aSliuyi ERASESYSTEM_PROGRESS, 19676af099aSliuyi LOWERFORMAT_PROGRESS, 19776af099aSliuyi ERASEUSERDATA_PROGRESS 19876af099aSliuyi } ENUM_PROGRESS_PROMPT; 19976af099aSliuyi 20076af099aSliuyi typedef enum{ 20176af099aSliuyi CALL_FIRST, 20276af099aSliuyi CALL_MIDDLE, 20376af099aSliuyi CALL_LAST 20476af099aSliuyi } ENUM_CALL_STEP; 20576af099aSliuyi 20676af099aSliuyi typedef void (*ProgressPromptCB)(DWORD deviceLayer, ENUM_PROGRESS_PROMPT promptID, long long totalValue, long long currentValue, ENUM_CALL_STEP emCall); 20776af099aSliuyi 20876af099aSliuyi bool WideStringToString(wchar_t *pszSrc, char *&pszDest); 20976af099aSliuyi bool StringToWideString(char *pszSrc, wchar_t *&pszDest); 21076af099aSliuyi #endif