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