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