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; 31c30d921cSKever Yang #define ALIGN(x, a) __ALIGN_MASK((x), (a) - 1) 32c30d921cSKever Yang #define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) 33c30d921cSKever Yang #define RK28_SEC2_RESERVED_LEN 473 34c30d921cSKever Yang #define CHIPINFO_LEN 16 35c30d921cSKever Yang #define RK28_SEC3_RESERVED_LEN 382 36c30d921cSKever Yang #define RKDEVICE_SN_LEN 60 37c30d921cSKever Yang #define RKDEVICE_UID_LEN 30 38c30d921cSKever Yang #define RKDEVICE_MAC_LEN 6 39c30d921cSKever Yang #define RKDEVICE_WIFI_LEN 6 40c30d921cSKever Yang #define RKDEVICE_BT_LEN 6 41c30d921cSKever 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) 77*6ae612beSliuyi typedef struct sparse_header_t { 78*6ae612beSliuyi UINT magic; /* 0xed26ff3a */ 79*6ae612beSliuyi USHORT major_version; /* (0x1) - reject images with higher major versions */ 80*6ae612beSliuyi USHORT minor_version; /* (0x0) - allow images with higer minor versions */ 81*6ae612beSliuyi USHORT file_hdr_sz; /* 28 bytes for first revision of the file format */ 82*6ae612beSliuyi USHORT chunk_hdr_sz; /* 12 bytes for first revision of the file format */ 83*6ae612beSliuyi UINT blk_sz; /* block size in bytes, must be a multiple of 4 (4096) */ 84*6ae612beSliuyi UINT total_blks; /* total blocks in the non-sparse output image */ 85*6ae612beSliuyi UINT total_chunks; /* total chunks in the sparse input image */ 86*6ae612beSliuyi UINT image_checksum; /* CRC32 checksum of the original data, counting "don't care" */ 87*6ae612beSliuyi /* as 0. Standard 802.3 polynomial, use a Public Domain */ 88*6ae612beSliuyi /* table implementation */ 89*6ae612beSliuyi } sparse_header; 90*6ae612beSliuyi #define SPARSE_HEADER_MAGIC 0xed26ff3a 91*6ae612beSliuyi #define CHUNK_TYPE_RAW 0xCAC1 92*6ae612beSliuyi #define CHUNK_TYPE_FILL 0xCAC2 93*6ae612beSliuyi #define CHUNK_TYPE_DONT_CARE 0xCAC3 94*6ae612beSliuyi #define CHUNK_TYPE_CRC32 0xCAC4 95*6ae612beSliuyi typedef struct chunk_header_t { 96*6ae612beSliuyi USHORT chunk_type; /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */ 97*6ae612beSliuyi USHORT reserved1; 98*6ae612beSliuyi UINT chunk_sz; /* in blocks in output image */ 99*6ae612beSliuyi UINT total_sz; /* in bytes of chunk input file including chunk header and data */ 100*6ae612beSliuyi } chunk_header; 101*6ae612beSliuyi 10276af099aSliuyi typedef struct{ 10376af099aSliuyi USHORT usYear; 10476af099aSliuyi BYTE ucMonth; 10576af099aSliuyi BYTE ucDay; 10676af099aSliuyi BYTE ucHour; 10776af099aSliuyi BYTE ucMinute; 10876af099aSliuyi BYTE ucSecond; 10976af099aSliuyi } STRUCT_RKTIME, *PSTRUCT_RKTIME; 11076af099aSliuyi 11176af099aSliuyi typedef struct{ 11276af099aSliuyi char szItemName[20]; 11376af099aSliuyi char szItemValue[256]; 11476af099aSliuyi } STRUCT_CONFIG_ITEM, *PSTRUCT_CONFIG_ITEM; 115c30d921cSKever Yang typedef struct 116c30d921cSKever Yang { 117c30d921cSKever Yang char szItemName[64]; 118c30d921cSKever Yang UINT uiItemOffset; 119c30d921cSKever Yang UINT uiItemSize; 120c30d921cSKever Yang }STRUCT_PARAM_ITEM,*PSTRUCT_PARAM_ITEM; 12176af099aSliuyi typedef struct _STRUCT_RKDEVICE_DESC{ 12276af099aSliuyi USHORT usVid; 12376af099aSliuyi USHORT usPid; 12476af099aSliuyi USHORT usbcdUsb; 12576af099aSliuyi UINT uiLocationID; 12676af099aSliuyi ENUM_RKUSB_TYPE emUsbType; 12776af099aSliuyi ENUM_RKDEVICE_TYPE emDeviceType; 12876af099aSliuyi void *pUsbHandle; 12976af099aSliuyi } STRUCT_RKDEVICE_DESC, *PSTRUCT_RKDEVICE_DESC; 130c30d921cSKever Yang typedef struct { 131c30d921cSKever Yang DWORD dwTag; 132c30d921cSKever Yang BYTE reserved[4]; 133c30d921cSKever Yang UINT uiRc4Flag; 134c30d921cSKever Yang USHORT usBootCode1Offset; 135c30d921cSKever Yang USHORT usBootCode2Offset; 136c30d921cSKever Yang BYTE reserved1[490]; 137c30d921cSKever Yang USHORT usBootDataSize; 138c30d921cSKever Yang USHORT usBootCodeSize; 139c30d921cSKever Yang USHORT usCrc; 140c30d921cSKever Yang } RK28_IDB_SEC0, *PRK28_IDB_SEC0; 141c30d921cSKever Yang 142c30d921cSKever Yang typedef struct { 143c30d921cSKever Yang USHORT usSysReservedBlock; 144c30d921cSKever Yang USHORT usDisk0Size; 145c30d921cSKever Yang USHORT usDisk1Size; 146c30d921cSKever Yang USHORT usDisk2Size; 147c30d921cSKever Yang USHORT usDisk3Size; 148c30d921cSKever Yang UINT uiChipTag; 149c30d921cSKever Yang UINT uiMachineId; 150c30d921cSKever Yang USHORT usLoaderYear; 151c30d921cSKever Yang USHORT usLoaderDate; 152c30d921cSKever Yang USHORT usLoaderVer; 153c30d921cSKever Yang USHORT usLastLoaderVer; 154c30d921cSKever Yang USHORT usReadWriteTimes; 155c30d921cSKever Yang DWORD dwFwVer; 156c30d921cSKever Yang USHORT usMachineInfoLen; 157c30d921cSKever Yang UCHAR ucMachineInfo[30]; 158c30d921cSKever Yang USHORT usManufactoryInfoLen; 159c30d921cSKever Yang UCHAR ucManufactoryInfo[30]; 160c30d921cSKever Yang USHORT usFlashInfoOffset; 161c30d921cSKever Yang USHORT usFlashInfoLen; 162c30d921cSKever Yang UCHAR reserved[384]; 163c30d921cSKever Yang UINT uiFlashSize; 164c30d921cSKever Yang BYTE reserved1; 165c30d921cSKever Yang BYTE bAccessTime; 166c30d921cSKever Yang USHORT usBlockSize; 167c30d921cSKever Yang BYTE bPageSize; 168c30d921cSKever Yang BYTE bECCBits; 169c30d921cSKever Yang BYTE reserved2[8]; 170c30d921cSKever Yang USHORT usIdBlock0; 171c30d921cSKever Yang USHORT usIdBlock1; 172c30d921cSKever Yang USHORT usIdBlock2; 173c30d921cSKever Yang USHORT usIdBlock3; 174c30d921cSKever Yang USHORT usIdBlock4; 175c30d921cSKever Yang } RK28_IDB_SEC1, *PRK28_IDB_SEC1; 176c30d921cSKever Yang 177c30d921cSKever Yang typedef struct { 178c30d921cSKever Yang USHORT usInfoSize; 179c30d921cSKever Yang BYTE bChipInfo[CHIPINFO_LEN]; 180c30d921cSKever Yang BYTE reserved[RK28_SEC2_RESERVED_LEN]; 181c30d921cSKever Yang char szVcTag[3]; 182c30d921cSKever Yang USHORT usSec0Crc; 183c30d921cSKever Yang USHORT usSec1Crc; 184c30d921cSKever Yang UINT uiBootCodeCrc; 185c30d921cSKever Yang USHORT usSec3CustomDataOffset; 186c30d921cSKever Yang USHORT usSec3CustomDataSize; 187c30d921cSKever Yang char szCrcTag[4]; 188c30d921cSKever Yang USHORT usSec3Crc; 189c30d921cSKever Yang } RK28_IDB_SEC2, *PRK28_IDB_SEC2; 190c30d921cSKever Yang 191c30d921cSKever Yang typedef struct { 192c30d921cSKever Yang USHORT usSNSize; 193c30d921cSKever Yang BYTE sn[RKDEVICE_SN_LEN]; 194c30d921cSKever Yang BYTE reserved[RK28_SEC3_RESERVED_LEN]; 195c30d921cSKever Yang BYTE wifiSize; 196c30d921cSKever Yang BYTE wifiAddr[RKDEVICE_WIFI_LEN]; 197c30d921cSKever Yang BYTE imeiSize; 198c30d921cSKever Yang BYTE imei[RKDEVICE_IMEI_LEN]; 199c30d921cSKever Yang BYTE uidSize; 200c30d921cSKever Yang BYTE uid[RKDEVICE_UID_LEN]; 201c30d921cSKever Yang BYTE blueToothSize; 202c30d921cSKever Yang BYTE blueToothAddr[RKDEVICE_BT_LEN]; 203c30d921cSKever Yang BYTE macSize; 204c30d921cSKever Yang BYTE macAddr[RKDEVICE_MAC_LEN]; 205c30d921cSKever Yang } RK28_IDB_SEC3, *PRK28_IDB_SEC3; 20676af099aSliuyi #pragma pack() 20776af099aSliuyi typedef list<STRUCT_RKDEVICE_DESC> RKDEVICE_DESC_SET; 20876af099aSliuyi typedef RKDEVICE_DESC_SET::iterator device_list_iter; 20976af099aSliuyi typedef vector<string> STRING_VECTOR; 21076af099aSliuyi typedef vector<UINT> UINT_VECTOR; 21176af099aSliuyi typedef vector<STRUCT_CONFIG_ITEM> CONFIG_ITEM_VECTOR; 212c30d921cSKever Yang typedef vector<STRUCT_PARAM_ITEM> PARAM_ITEM_VECTOR; 21376af099aSliuyi typedef enum{ 21476af099aSliuyi TESTDEVICE_PROGRESS, 21576af099aSliuyi DOWNLOADIMAGE_PROGRESS, 21676af099aSliuyi CHECKIMAGE_PROGRESS, 21776af099aSliuyi TAGBADBLOCK_PROGRESS, 21876af099aSliuyi TESTBLOCK_PROGRESS, 21976af099aSliuyi ERASEFLASH_PROGRESS, 22076af099aSliuyi ERASESYSTEM_PROGRESS, 22176af099aSliuyi LOWERFORMAT_PROGRESS, 22276af099aSliuyi ERASEUSERDATA_PROGRESS 22376af099aSliuyi } ENUM_PROGRESS_PROMPT; 22476af099aSliuyi 22576af099aSliuyi typedef enum{ 22676af099aSliuyi CALL_FIRST, 22776af099aSliuyi CALL_MIDDLE, 22876af099aSliuyi CALL_LAST 22976af099aSliuyi } ENUM_CALL_STEP; 23076af099aSliuyi 23176af099aSliuyi typedef void (*ProgressPromptCB)(DWORD deviceLayer, ENUM_PROGRESS_PROMPT promptID, long long totalValue, long long currentValue, ENUM_CALL_STEP emCall); 23276af099aSliuyi 23376af099aSliuyi bool WideStringToString(wchar_t *pszSrc, char *&pszDest); 23476af099aSliuyi bool StringToWideString(char *pszSrc, wchar_t *&pszDest); 23576af099aSliuyi #endif 236