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