xref: /rkdeveloptool/DefineHeader.h (revision b06b487d7032fb122d83edf5dd70060822a7ce78)
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 <wchar.h>
1276af099aSliuyi #include <errno.h>
1376af099aSliuyi #include <pthread.h>
1476af099aSliuyi #include <libusb.h>
1576af099aSliuyi 
1676af099aSliuyi #include "Property.hpp"
1776af099aSliuyi #include <list>
1876af099aSliuyi #include <vector>
1976af099aSliuyi #include <set>
2076af099aSliuyi #include <string>
2176af099aSliuyi #include <sstream>
2276af099aSliuyi #include <algorithm>
2376af099aSliuyi using namespace std;
24*21b25fd4SDave Murphy #ifndef __MINGW32__
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*21b25fd4SDave Murphy #endif
32c30d921cSKever Yang #define ALIGN(x, a)		__ALIGN_MASK((x), (a) - 1)
33c30d921cSKever Yang #define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
34c30d921cSKever Yang #define RK28_SEC2_RESERVED_LEN 473
35c30d921cSKever Yang #define CHIPINFO_LEN 16
36c30d921cSKever Yang #define RK28_SEC3_RESERVED_LEN 382
37c30d921cSKever Yang #define RKDEVICE_SN_LEN 60
38c30d921cSKever Yang #define RKDEVICE_UID_LEN 30
39c30d921cSKever Yang #define RKDEVICE_MAC_LEN 6
40c30d921cSKever Yang #define RKDEVICE_WIFI_LEN 6
41c30d921cSKever Yang #define RKDEVICE_BT_LEN 6
42c30d921cSKever Yang #define RKDEVICE_IMEI_LEN 15
4376af099aSliuyi typedef enum{
4476af099aSliuyi 	RKNONE_DEVICE = 0,
4576af099aSliuyi 	RK27_DEVICE = 0x10,
4676af099aSliuyi 	RKCAYMAN_DEVICE,
4776af099aSliuyi 	RK28_DEVICE = 0x20,
4876af099aSliuyi 	RK281X_DEVICE,
4976af099aSliuyi 	RKPANDA_DEVICE,
5076af099aSliuyi 	RKNANO_DEVICE = 0x30,
5176af099aSliuyi 	RKSMART_DEVICE,
5276af099aSliuyi 	RKCROWN_DEVICE = 0x40,
5376af099aSliuyi 	RK29_DEVICE = 0x50,
5476af099aSliuyi 	RK292X_DEVICE,
5576af099aSliuyi 	RK30_DEVICE = 0x60,
5676af099aSliuyi 	RK30B_DEVICE,
5776af099aSliuyi 	RK31_DEVICE = 0x70,
5876af099aSliuyi 	RK32_DEVICE = 0x80
5976af099aSliuyi } ENUM_RKDEVICE_TYPE;
6076af099aSliuyi typedef enum{
6176af099aSliuyi 	RK_OS = 0,
6276af099aSliuyi 	ANDROID_OS = 0x1
6376af099aSliuyi } ENUM_OS_TYPE;
6476af099aSliuyi 
6576af099aSliuyi typedef enum{
6676af099aSliuyi 	RKUSB_NONE = 0x0,
6776af099aSliuyi 	RKUSB_MASKROM = 0x01,
6876af099aSliuyi 	RKUSB_LOADER = 0x02,
6976af099aSliuyi 	RKUSB_MSC = 0x04
7076af099aSliuyi } ENUM_RKUSB_TYPE;
7176af099aSliuyi typedef enum{
7276af099aSliuyi 	ENTRY471 = 1,
7376af099aSliuyi 	ENTRY472 = 2,
7476af099aSliuyi 	ENTRYLOADER = 4
7576af099aSliuyi } ENUM_RKBOOTENTRY;
7676af099aSliuyi 
7776af099aSliuyi #pragma pack(1)
786ae612beSliuyi typedef struct sparse_header_t {
796ae612beSliuyi 	UINT	magic;		/* 0xed26ff3a */
806ae612beSliuyi 	USHORT	major_version;	/* (0x1) - reject images with higher major versions */
816ae612beSliuyi 	USHORT	minor_version;	/* (0x0) - allow images with higer minor versions */
826ae612beSliuyi 	USHORT	file_hdr_sz;	/* 28 bytes for first revision of the file format */
836ae612beSliuyi 	USHORT	chunk_hdr_sz;	/* 12 bytes for first revision of the file format */
846ae612beSliuyi 	UINT	blk_sz;		/* block size in bytes, must be a multiple of 4 (4096) */
856ae612beSliuyi 	UINT	total_blks;	/* total blocks in the non-sparse output image */
866ae612beSliuyi 	UINT	total_chunks;	/* total chunks in the sparse input image */
876ae612beSliuyi 	UINT	image_checksum; /* CRC32 checksum of the original data, counting "don't care" */
886ae612beSliuyi 							/* as 0. Standard 802.3 polynomial, use a Public Domain */
896ae612beSliuyi 							/* table implementation */
906ae612beSliuyi } sparse_header;
916ae612beSliuyi #define SPARSE_HEADER_MAGIC	0xed26ff3a
920dcb0a4cSliuyi #define UBI_HEADER_MAGIC	0x23494255
936ae612beSliuyi #define CHUNK_TYPE_RAW		0xCAC1
946ae612beSliuyi #define CHUNK_TYPE_FILL		0xCAC2
956ae612beSliuyi #define CHUNK_TYPE_DONT_CARE	0xCAC3
966ae612beSliuyi #define CHUNK_TYPE_CRC32    0xCAC4
976ae612beSliuyi typedef struct chunk_header_t {
986ae612beSliuyi 	USHORT	chunk_type;	/* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */
996ae612beSliuyi 	USHORT	reserved1;
1006ae612beSliuyi 	UINT	chunk_sz;	/* in blocks in output image */
1016ae612beSliuyi 	UINT	total_sz;	/* in bytes of chunk input file including chunk header and data */
1026ae612beSliuyi } chunk_header;
1036ae612beSliuyi 
10476af099aSliuyi typedef struct{
10576af099aSliuyi 	USHORT	usYear;
10676af099aSliuyi 	BYTE	ucMonth;
10776af099aSliuyi 	BYTE  	ucDay;
10876af099aSliuyi 	BYTE  	ucHour;
10976af099aSliuyi 	BYTE  	ucMinute;
11076af099aSliuyi 	BYTE  	ucSecond;
11176af099aSliuyi } STRUCT_RKTIME, *PSTRUCT_RKTIME;
11276af099aSliuyi 
11376af099aSliuyi typedef struct{
11476af099aSliuyi 	char szItemName[20];
11576af099aSliuyi 	char szItemValue[256];
11676af099aSliuyi } STRUCT_CONFIG_ITEM, *PSTRUCT_CONFIG_ITEM;
117c30d921cSKever Yang typedef struct
118c30d921cSKever Yang {
119c30d921cSKever Yang 	char szItemName[64];
120c30d921cSKever Yang 	UINT uiItemOffset;
121c30d921cSKever Yang 	UINT uiItemSize;
122c30d921cSKever Yang }STRUCT_PARAM_ITEM,*PSTRUCT_PARAM_ITEM;
12376af099aSliuyi typedef struct _STRUCT_RKDEVICE_DESC{
12476af099aSliuyi 	USHORT usVid;
12576af099aSliuyi 	USHORT usPid;
12676af099aSliuyi 	USHORT usbcdUsb;
12776af099aSliuyi 	UINT     uiLocationID;
12876af099aSliuyi 	ENUM_RKUSB_TYPE emUsbType;
12976af099aSliuyi 	ENUM_RKDEVICE_TYPE emDeviceType;
13076af099aSliuyi 	void   *pUsbHandle;
13176af099aSliuyi } STRUCT_RKDEVICE_DESC, *PSTRUCT_RKDEVICE_DESC;
132c30d921cSKever Yang typedef	struct {
133c30d921cSKever Yang 	DWORD	dwTag;
134c30d921cSKever Yang 	BYTE	reserved[4];
135c30d921cSKever Yang 	UINT	uiRc4Flag;
136c30d921cSKever Yang 	USHORT	usBootCode1Offset;
137c30d921cSKever Yang 	USHORT	usBootCode2Offset;
138c30d921cSKever Yang 	BYTE	reserved1[490];
139c30d921cSKever Yang 	USHORT  usBootDataSize;
140c30d921cSKever Yang 	USHORT	usBootCodeSize;
141c30d921cSKever Yang 	USHORT	usCrc;
142c30d921cSKever Yang } RK28_IDB_SEC0, *PRK28_IDB_SEC0;
143c30d921cSKever Yang 
144c30d921cSKever Yang typedef struct {
145c30d921cSKever Yang 	USHORT  usSysReservedBlock;
146c30d921cSKever Yang 	USHORT  usDisk0Size;
147c30d921cSKever Yang 	USHORT  usDisk1Size;
148c30d921cSKever Yang 	USHORT  usDisk2Size;
149c30d921cSKever Yang 	USHORT  usDisk3Size;
150c30d921cSKever Yang 	UINT	uiChipTag;
151c30d921cSKever Yang 	UINT	uiMachineId;
152c30d921cSKever Yang 	USHORT	usLoaderYear;
153c30d921cSKever Yang 	USHORT	usLoaderDate;
154c30d921cSKever Yang 	USHORT	usLoaderVer;
155c30d921cSKever Yang 	USHORT  usLastLoaderVer;
156c30d921cSKever Yang 	USHORT  usReadWriteTimes;
157c30d921cSKever Yang 	DWORD	dwFwVer;
158c30d921cSKever Yang 	USHORT  usMachineInfoLen;
159c30d921cSKever Yang 	UCHAR	ucMachineInfo[30];
160c30d921cSKever Yang 	USHORT	usManufactoryInfoLen;
161c30d921cSKever Yang 	UCHAR	ucManufactoryInfo[30];
162c30d921cSKever Yang 	USHORT	usFlashInfoOffset;
163c30d921cSKever Yang 	USHORT	usFlashInfoLen;
164c30d921cSKever Yang 	UCHAR	reserved[384];
165c30d921cSKever Yang 	UINT	uiFlashSize;
166c30d921cSKever Yang 	BYTE    reserved1;
167c30d921cSKever Yang 	BYTE    bAccessTime;
168c30d921cSKever Yang 	USHORT  usBlockSize;
169c30d921cSKever Yang 	BYTE    bPageSize;
170c30d921cSKever Yang 	BYTE    bECCBits;
171c30d921cSKever Yang 	BYTE    reserved2[8];
172c30d921cSKever Yang 	USHORT  usIdBlock0;
173c30d921cSKever Yang 	USHORT  usIdBlock1;
174c30d921cSKever Yang 	USHORT  usIdBlock2;
175c30d921cSKever Yang 	USHORT  usIdBlock3;
176c30d921cSKever Yang 	USHORT  usIdBlock4;
177c30d921cSKever Yang } RK28_IDB_SEC1, *PRK28_IDB_SEC1;
178c30d921cSKever Yang 
179c30d921cSKever Yang typedef struct {
180c30d921cSKever Yang 	USHORT  usInfoSize;
181c30d921cSKever Yang 	BYTE    bChipInfo[CHIPINFO_LEN];
182c30d921cSKever Yang 	BYTE    reserved[RK28_SEC2_RESERVED_LEN];
183c30d921cSKever Yang 	char    szVcTag[3];
184c30d921cSKever Yang 	USHORT  usSec0Crc;
185c30d921cSKever Yang 	USHORT  usSec1Crc;
186c30d921cSKever Yang 	UINT	uiBootCodeCrc;
187c30d921cSKever Yang 	USHORT  usSec3CustomDataOffset;
188c30d921cSKever Yang 	USHORT  usSec3CustomDataSize;
189c30d921cSKever Yang 	char    szCrcTag[4];
190c30d921cSKever Yang 	USHORT  usSec3Crc;
191c30d921cSKever Yang } RK28_IDB_SEC2, *PRK28_IDB_SEC2;
192c30d921cSKever Yang 
193c30d921cSKever Yang typedef struct {
194c30d921cSKever Yang 	USHORT  usSNSize;
195c30d921cSKever Yang 	BYTE    sn[RKDEVICE_SN_LEN];
196c30d921cSKever Yang 	BYTE    reserved[RK28_SEC3_RESERVED_LEN];
197c30d921cSKever Yang 	BYTE	wifiSize;
198c30d921cSKever Yang 	BYTE	wifiAddr[RKDEVICE_WIFI_LEN];
199c30d921cSKever Yang 	BYTE	imeiSize;
200c30d921cSKever Yang 	BYTE	imei[RKDEVICE_IMEI_LEN];
201c30d921cSKever Yang 	BYTE	uidSize;
202c30d921cSKever Yang 	BYTE	uid[RKDEVICE_UID_LEN];
203c30d921cSKever Yang 	BYTE    blueToothSize;
204c30d921cSKever Yang 	BYTE	blueToothAddr[RKDEVICE_BT_LEN];
205c30d921cSKever Yang 	BYTE	macSize;
206c30d921cSKever Yang 	BYTE	macAddr[RKDEVICE_MAC_LEN];
207c30d921cSKever Yang } RK28_IDB_SEC3, *PRK28_IDB_SEC3;
20876af099aSliuyi #pragma pack()
20976af099aSliuyi typedef list<STRUCT_RKDEVICE_DESC> RKDEVICE_DESC_SET;
21076af099aSliuyi typedef RKDEVICE_DESC_SET::iterator device_list_iter;
21176af099aSliuyi typedef vector<string> STRING_VECTOR;
21276af099aSliuyi typedef vector<UINT> UINT_VECTOR;
21376af099aSliuyi typedef vector<STRUCT_CONFIG_ITEM> CONFIG_ITEM_VECTOR;
214c30d921cSKever Yang typedef vector<STRUCT_PARAM_ITEM> PARAM_ITEM_VECTOR;
21576af099aSliuyi typedef enum{
21676af099aSliuyi 	TESTDEVICE_PROGRESS,
21776af099aSliuyi 	DOWNLOADIMAGE_PROGRESS,
21876af099aSliuyi 	CHECKIMAGE_PROGRESS,
21976af099aSliuyi 	TAGBADBLOCK_PROGRESS,
22076af099aSliuyi 	TESTBLOCK_PROGRESS,
22176af099aSliuyi 	ERASEFLASH_PROGRESS,
22276af099aSliuyi 	ERASESYSTEM_PROGRESS,
22376af099aSliuyi 	LOWERFORMAT_PROGRESS,
22476af099aSliuyi 	ERASEUSERDATA_PROGRESS
22576af099aSliuyi } ENUM_PROGRESS_PROMPT;
22676af099aSliuyi 
22776af099aSliuyi typedef enum{
22876af099aSliuyi 	CALL_FIRST,
22976af099aSliuyi 	CALL_MIDDLE,
23076af099aSliuyi 	CALL_LAST
23176af099aSliuyi } ENUM_CALL_STEP;
23276af099aSliuyi 
233*21b25fd4SDave Murphy typedef void (*ProgressPromptCB)(UINT deviceLayer, ENUM_PROGRESS_PROMPT promptID, long long totalValue, long long currentValue, ENUM_CALL_STEP emCall);
23476af099aSliuyi 
2350dcb0a4cSliuyi //	bool WideStringToString(wchar_t *pszSrc, char *&pszDest);
2360dcb0a4cSliuyi //	bool StringToWideString(char *pszSrc, wchar_t *&pszDest);
23776af099aSliuyi #endif
238