xref: /OK3568_Linux_fs/external/recovery/update_engine/rkimage.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2023 Rockchip Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _RKIMAGE_H
18 #define _RKIMAGE_H
19 #include <stdbool.h>
20 #include "defineHeader.h"
21 #pragma pack(1)
22 typedef struct {
23     USHORT  usYear;
24     BYTE    ucMonth;
25     BYTE    ucDay;
26     BYTE    ucHour;
27     BYTE    ucMinute;
28     BYTE    ucSecond;
29 } STRUCT_RKTIME, *PSTRUCT_RKTIME;
30 
31 typedef struct {
32     UINT uiTag;     //标志,固定为0x57 0x46 0x4B 0x52
33     USHORT usSize;  //结构体大小
34     DWORD  dwVersion;   //Image 文件版本
35     DWORD  dwMergeVersion;  //打包工具版本
36     STRUCT_RKTIME stReleaseTime;    //生成时间
37     ENUM_RKDEVICE_TYPE emSupportChip;   //使用芯片
38     DWORD  dwBootOffset;    //Boot偏移
39     DWORD  dwBootSize;  //Boot大小
40     DWORD  dwFWOffset;  //固件偏移
41     DWORD  dwFWSize;    //固件大小
42     BYTE   reserved[61];    //预留空间,用于存放不同固件特征
43 } STRUCT_RKIMAGE_HEAD, *PSTRUCT_RKIMAGE_HEAD;
44 
45 typedef struct tagRKIMAGE_ITEM {
46     char name[PART_NAME];
47     char file[RELATIVE_PATH];
48     unsigned int offset;
49     unsigned int flash_offset;
50     unsigned int usespace;
51     unsigned int size;
52 } RKIMAGE_ITEM, *PRKIMAGE_ITEM;
53 
54 typedef struct tagRKIMAGE_HDR {
55     unsigned int tag;
56     unsigned int size;
57     char machine_model[MAX_MACHINE_MODEL];
58     char manufacturer[MAX_MANUFACTURER];
59     unsigned int version;
60     int item_count;
61     RKIMAGE_ITEM item[MAX_PACKAGE_FILES];
62 } RKIMAGE_HDR, *PRKIMAGE_HDR;
63 
64 typedef struct {
65     UINT uiTag;
66     USHORT usSize;
67     DWORD  dwVersion;
68     DWORD  dwMergeVersion;
69     STRUCT_RKTIME stReleaseTime;
70     ENUM_RKDEVICE_TYPE emSupportChip;
71     UCHAR uc471EntryCount;
72     DWORD dw471EntryOffset;
73     UCHAR uc471EntrySize;
74     UCHAR uc472EntryCount;
75     DWORD dw472EntryOffset;
76     UCHAR uc472EntrySize;
77     UCHAR ucLoaderEntryCount;
78     DWORD dwLoaderEntryOffset;
79     UCHAR ucLoaderEntrySize;
80     UCHAR ucSignFlag;
81     UCHAR ucRc4Flag;
82     UCHAR reserved[BOOT_RESERVED_SIZE];
83 } STRUCT_RKBOOT_HEAD, *PSTRUCT_RKBOOT_HEAD;
84 
85 typedef struct {
86     UCHAR ucSize;
87     ENUM_RKBOOTENTRY emType;
88     WCHAR szName[20];
89     DWORD dwDataOffset;
90     DWORD dwDataSize;
91     DWORD dwDataDelay;//以秒为单位
92 } STRUCT_RKBOOT_ENTRY, *PSTRUCT_RKBOOT_ENTRY;
93 typedef    struct {
94     DWORD    dwTag;
95     BYTE    reserved[4];
96     UINT    uiRc4Flag;
97     USHORT    usBootCode1Offset;
98     USHORT    usBootCode2Offset;
99     BYTE    reserved1[490];
100     USHORT  usBootDataSize;
101     USHORT    usBootCodeSize;
102     USHORT    usCrc;
103 } RKANDROID_IDB_SEC0, *PRKANDROID_IDB_SEC0;
104 
105 typedef struct {
106     USHORT  usSysReservedBlock;
107     USHORT  usDisk0Size;
108     USHORT  usDisk1Size;
109     USHORT  usDisk2Size;
110     USHORT  usDisk3Size;
111     UINT    uiChipTag;
112     UINT    uiMachineId;
113     USHORT    usLoaderYear;
114     USHORT    usLoaderDate;
115     USHORT    usLoaderVer;
116     USHORT  usLastLoaderVer;
117     USHORT  usReadWriteTimes;
118     DWORD    dwFwVer;
119     USHORT  usMachineInfoLen;
120     UCHAR    ucMachineInfo[30];
121     USHORT    usManufactoryInfoLen;
122     UCHAR    ucManufactoryInfo[30];
123     USHORT    usFlashInfoOffset;
124     USHORT    usFlashInfoLen;
125     UCHAR    reserved[384];
126     UINT    uiFlashSize;
127     BYTE    reserved1;
128     BYTE    bAccessTime;
129     USHORT  usBlockSize;
130     BYTE    bPageSize;
131     BYTE    bECCBits;
132     BYTE    reserved2[8];
133     USHORT  usIdBlock0;
134     USHORT  usIdBlock1;
135     USHORT  usIdBlock2;
136     USHORT  usIdBlock3;
137     USHORT  usIdBlock4;
138 } RKANDROID_IDB_SEC1, *PRKANDROID_IDB_SEC1;
139 
140 typedef struct {
141     USHORT  usInfoSize;
142     BYTE    bChipInfo[CHIPINFO_LEN];
143     BYTE    reserved[RKANDROID_SEC2_RESERVED_LEN];
144     char    szVcTag[3];
145     USHORT  usSec0Crc;
146     USHORT  usSec1Crc;
147     UINT    uiBootCodeCrc;
148     USHORT  usSec3CustomDataOffset;
149     USHORT  usSec3CustomDataSize;
150     char    szCrcTag[4];
151     USHORT  usSec3Crc;
152 } RKANDROID_IDB_SEC2, *PRKANDROID_IDB_SEC2;
153 
154 typedef struct {
155     USHORT  usSNSize;
156     BYTE    sn[RKDEVICE_SN_LEN];
157     BYTE    reserved[RKANDROID_SEC3_RESERVED_LEN];
158     BYTE    imeiSize;
159     BYTE    imei[RKDEVICE_IMEI_LEN];
160     BYTE    uidSize;
161     BYTE    uid[RKDEVICE_UID_LEN];
162     BYTE    blueToothSize;
163     BYTE    blueToothAddr[RKDEVICE_BT_LEN];
164     BYTE    macSize;
165     BYTE    macAddr[RKDEVICE_MAC_LEN];
166 } RKANDROID_IDB_SEC3, *PRKANDROID_IDB_SEC3;
167 
168 #pragma pack()
169 
170 bool getImageVersion(const char *filepath, char *version, int maxLength) ;
171 int analyticImage(const char *filepath, PRKIMAGE_HDR phdr);
172 #endif
173