xref: /OK3568_Linux_fs/u-boot/tools/rockchip/boot_merger.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * (C) Copyright 2008-2015 Fuzhou Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 #ifndef BOOT_MERGER_H
7 #define BOOT_MERGER_H
8 
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <memory.h>
13 #include <stdbool.h>
14 
15 /* #define DEBUG */
16 
17 extern bool gDebug;
18 
19 #define LOGE(fmt, args...) fprintf(stderr, "E: [%s] "fmt, __func__, ##args)
20 #define LOGD(fmt, args...) do {\
21 	if (gDebug) \
22 	fprintf(stderr, "W: [%s] "fmt, __func__, ##args); \
23 } while (0)
24 
25 
26 #define SCANF_EAT(in)   fscanf(in, "%*[ \r\n\t/]")//, gEat)
27 #define MAX_LINE_LEN        256
28 extern char gEat[MAX_LINE_LEN];
29 
30 typedef char line_t[MAX_LINE_LEN];
31 
32 
33 
34 #define DEF_CONFIG_FILE     "CONFIG.ini"
35 
36 #define DEF_MAJOR           0
37 #define DEF_MINOR           3
38 #define DEF_CHIP            "RK30"
39 #define DEF_CODE471_NUM     1
40 #define DEF_CODE472_NUM     1
41 #define DEF_CODE471_SLEEP   0
42 #define DEF_CODE472_SLEEP   0
43 #define DEF_CODE471_PATH    "30_LPDDR2_300MHz_DDR3_300MHz.bin"
44 #define DEF_CODE472_PATH    "rk30usbplug.bin"
45 #define DEF_LOADER_NUM      2
46 #define DEF_LOADER0         "FlashData"
47 #define DEF_LOADER0_PATH    "30_LPDDR2_300MHz_DDR3_300MHz.bin"
48 #define DEF_LOADER1         "FlashBoot"
49 #define DEF_LOADER1_PATH    "../../u-boot.bin"
50 #define DEF_OUT_PATH        "../../RK30xxLoader_uboot.bin"
51 
52 #define OUT_SUBFIX          ".bin"
53 
54 #define SEC_CHIP            "[CHIP_NAME]"
55 #define SEC_VERSION         "[VERSION]"
56 #define SEC_471             "[CODE471_OPTION]"
57 #define SEC_472             "[CODE472_OPTION]"
58 #define SEC_LOADER          "[LOADER_OPTION]"
59 #define SEC_OUT             "[OUTPUT]"
60 
61 #define OPT_NAME            "NAME"
62 #define OPT_MAJOR           "MAJOR"
63 #define OPT_MINOR           "MINOR"
64 #define OPT_NUM             "NUM"
65 #define OPT_LOADER_NUM      "LOADERCOUNT"
66 #define OPT_PATH            "Path"
67 #define OPT_SLEEP           "Sleep"
68 #define OPT_LOADER_NAME     "LOADER"
69 #define OPT_OUT_PATH        "PATH"
70 
71 typedef struct {
72 	char       name[MAX_LINE_LEN];
73 	char       path[MAX_LINE_LEN];
74 } name_entry;
75 
76 typedef struct {
77 	int         major;
78 	int         minor;
79 	char        chip[MAX_LINE_LEN];
80 	int         code471Sleep;
81 	int         code472Sleep;
82 	int         code471Num;
83 	int         code472Num;
84 	line_t*     code471Path;
85 	line_t*     code472Path;
86 	int         loaderNum;
87 	name_entry* loader;
88 	char        outPath[MAX_LINE_LEN * 2];
89 } options;
90 
91 
92 #define TAG						0x544F4F42
93 #define MERGER_VERSION          0x01030000
94 #define SMALL_PACKET			512
95 
96 #define MAX_NAME_LEN            20
97 #define MAX_MERGE_SIZE          (512 << 10)
98 
99 #define SEC_CHIP_TYPES          "[CHIP_TYPES]"
100 
101 #define CHIP_RK28               "RK28"
102 #define CHIP_RK281X             "RK281X"
103 #define CHIP_RKPANDA            "RKPANDA"
104 #define CHIP_RK27               "RK27"
105 #define CHIP_RKNANO             "RKNANO"
106 #define CHIP_RKSMART            "RKSMART"
107 #define CHIP_RKCROWN            "RKCROWN"
108 #define CHIP_RKCAYMAN           "RKCAYMAN"
109 #define CHIP_RK29               "RK29"
110 #define CHIP_RK292X             "RK292X"
111 #define CHIP_RK30               "RK30"
112 #define CHIP_RK30B              "RK30B"
113 #define CHIP_RK31               "RK31"
114 #define CHIP_RK32               "RK32"
115 
116 typedef enum {
117 	RKNONE_DEVICE   =0,
118 	RK27_DEVICE     =0x10,
119 	RKCAYMAN_DEVICE =0x11,
120 	RK28_DEVICE     =0x20,
121 	RK281X_DEVICE   =0x21,
122 	RKPANDA_DEVICE  =0x22,
123 	RKNANO_DEVICE   =0x30,
124 	RKSMART_DEVICE  =0x31,
125 	RKCROWN_DEVICE  =0x40,
126 	RK29_DEVICE     =0x50,
127 	RK292X_DEVICE   =0x51,
128 	RK30_DEVICE     =0x60,
129 	RK30B_DEVICE    =0x61,
130 	RK31_DEVICE     =0x70,
131 	RK32_DEVICE     =0x80
132 } rk_chip_type;
133 
134 typedef enum {
135 	ENTRY_471       =1,
136 	ENTRY_472       =2,
137 	ENTRY_LOADER    =4,
138 } rk_entry_type;
139 
140 #pragma pack(1)
141 typedef struct {
142 	uint16_t  year;
143 	uint8_t   month;
144 	uint8_t   day;
145 	uint8_t   hour;
146 	uint8_t   minute;
147 	uint8_t   second;
148 } rk_time;
149 
150 #define  BOOT_RESERVED_SIZE 57
151 typedef struct {
152 	uint32_t        tag;
153 	uint16_t        size;
154 	uint32_t        version;
155 	uint32_t        mergerVersion;
156 	rk_time         releaseTime;
157 	uint32_t        chipType;
158 	uint8_t         code471Num;
159 	uint32_t        code471Offset;
160 	uint8_t         code471Size;
161 	uint8_t         code472Num;
162 	uint32_t        code472Offset;
163 	uint8_t         code472Size;
164 	uint8_t         loaderNum;
165 	uint32_t        loaderOffset;
166 	uint8_t         loaderSize;
167 	uint8_t         signFlag;
168 	uint8_t         rc4Flag;
169 	uint8_t         reserved[BOOT_RESERVED_SIZE];
170 } rk_boot_header;
171 
172 typedef struct {
173 	uint8_t         size;
174 	rk_entry_type   type;
175 	uint16_t        name[MAX_NAME_LEN];
176 	uint32_t        dataOffset;
177 	uint32_t        dataSize;
178 	uint32_t        dataDelay;
179 } rk_boot_entry;
180 #pragma pack()
181 
182 #define OPT_VERBOSE         "--verbose"
183 #define OPT_HELP            "--help"
184 #define OPT_VERSION         "--version"
185 #define OPT_MERGE           "--pack"
186 #define OPT_UNPACK          "--unpack"
187 #define OPT_SUBFIX          "--subfix"
188 #define OPT_REPLACE         "--replace"
189 #define OPT_PREPATH         "--prepath"
190 #define OPT_SIZE	    "--size"
191 #define OPT_RC4		    "--rc4"
192 
193 #define OPT_CHIP	"-c"
194 #define OPT_471		"-1"
195 #define OPT_472		"-2"
196 #define	OPT_DATA	"-d"
197 #define	OPT_BOOT	"-b"
198 #define	OPT_OUT		"-o"
199 
200 
201 #define VERSION             "2013-8-12 14:27:23"
202 
203 #endif/* BOOT_MERGER_H */
204