xref: /rkdeveloptool/boot_merger.h (revision 78884ef4bafbcdb297daf3d3da7adf84677908d7)
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 
16 
17 #define SCANF_EAT(in)   fscanf(in, "%*[ \r\n\t/]")//, gEat)
18 #define MAX_LINE_LEN        256
19 
20 typedef char line_t[MAX_LINE_LEN];
21 
22 
23 
24 #define DEF_CONFIG_FILE     "config.ini"
25 
26 #define DEF_MAJOR           0
27 #define DEF_MINOR           3
28 #define DEF_CHIP            "RK30"
29 #define DEF_CODE471_NUM     1
30 #define DEF_CODE472_NUM     1
31 #define DEF_CODE471_SLEEP   0
32 #define DEF_CODE472_SLEEP   0
33 #define DEF_CODE471_PATH    "rk3288_ddr_400MHZ_v1.01.bin"
34 #define DEF_CODE472_PATH    "rk3288_usbplug_v2.32.bin"
35 #define DEF_LOADER_NUM      2
36 #define DEF_LOADER0         "FlashData"
37 #define DEF_LOADER0_PATH    "rk3288_ddr_400MHZ_v1.01.bin"
38 #define DEF_LOADER1         "FlashBoot"
39 #define DEF_LOADER1_PATH    "u-boot.bin"
40 #define DEF_OUT_PATH        "rk3288_bootloader_test.bin"
41 
42 #define OUT_SUBFIX          ".bin"
43 
44 #define SEC_CHIP            "[CHIP_NAME]"
45 #define SEC_VERSION         "[VERSION]"
46 #define SEC_471             "[CODE471_OPTION]"
47 #define SEC_472             "[CODE472_OPTION]"
48 #define SEC_LOADER          "[LOADER_OPTION]"
49 #define SEC_OUT             "[OUTPUT]"
50 
51 #define OPT_NAME            "NAME"
52 #define OPT_MAJOR           "MAJOR"
53 #define OPT_MINOR           "MINOR"
54 #define OPT_NUM             "NUM"
55 #define OPT_LOADER_NUM      "LOADERCOUNT"
56 #define OPT_PATH            "Path"
57 #define OPT_SLEEP           "Sleep"
58 #define OPT_LOADER_NAME     "LOADER"
59 #define OPT_OUT_PATH        "PATH"
60 
61 typedef struct {
62 	char       name[MAX_LINE_LEN];
63 	char       path[MAX_LINE_LEN];
64 } name_entry;
65 
66 typedef struct {
67 	int         major;
68 	int         minor;
69 	char        chip[MAX_LINE_LEN];
70 	int         code471Sleep;
71 	int         code472Sleep;
72 	int         code471Num;
73 	int         code472Num;
74 	line_t*     code471Path;
75 	line_t*     code472Path;
76 	int         loaderNum;
77 	name_entry* loader;
78 	char        outPath[MAX_LINE_LEN];
79 } options;
80 
81 
82 #define TAG						0x544F4F42
83 #define MERGER_VERSION          0x01030000
84 #define SMALL_PACKET			512
85 
86 #define MAX_NAME_LEN            20
87 #define MAX_MERGE_SIZE          (1024 << 10)
88 
89 #define SEC_CHIP_TYPES          "[CHIP_TYPES]"
90 
91 #define CHIP_RK28               "RK28"
92 #define CHIP_RK281X             "RK281X"
93 #define CHIP_RKPANDA            "RKPANDA"
94 #define CHIP_RK27               "RK27"
95 #define CHIP_RKNANO             "RKNANO"
96 #define CHIP_RKSMART            "RKSMART"
97 #define CHIP_RKCROWN            "RKCROWN"
98 #define CHIP_RKCAYMAN           "RKCAYMAN"
99 #define CHIP_RK29               "RK29"
100 #define CHIP_RK292X             "RK292X"
101 #define CHIP_RK30               "RK30"
102 #define CHIP_RK30B              "RK30B"
103 #define CHIP_RK31               "RK31"
104 #define CHIP_RK32               "RK32"
105 
106 typedef enum {
107 	ENTRY_471       =1,
108 	ENTRY_472       =2,
109 	ENTRY_LOADER    =4,
110 } rk_entry_type;
111 
112 #pragma pack(1)
113 typedef struct {
114 	uint16_t  year;
115 	uint8_t   month;
116 	uint8_t   day;
117 	uint8_t   hour;
118 	uint8_t   minute;
119 	uint8_t   second;
120 } rk_time;
121 
122 #define  BOOT_RESERVED_SIZE 57
123 typedef struct {
124 	uint32_t        tag;
125 	uint16_t        size;
126 	uint32_t        version;
127 	uint32_t        mergerVersion;
128 	rk_time         releaseTime;
129 	uint32_t        chipType;
130 	uint8_t         code471Num;
131 	uint32_t        code471Offset;
132 	uint8_t         code471Size;
133 	uint8_t         code472Num;
134 	uint32_t        code472Offset;
135 	uint8_t         code472Size;
136 	uint8_t         loaderNum;
137 	uint32_t        loaderOffset;
138 	uint8_t         loaderSize;
139 	uint8_t         signFlag;
140 	uint8_t         rc4Flag;
141 	uint8_t         reserved[BOOT_RESERVED_SIZE];
142 } rk_boot_header;
143 
144 typedef struct {
145 	uint8_t         size;
146 	rk_entry_type   type;
147 	uint16_t        name[MAX_NAME_LEN];
148 	uint32_t        dataOffset;
149 	uint32_t        dataSize;
150 	uint32_t        dataDelay;
151 } rk_boot_entry;
152 #pragma pack()
153 
154 #endif// BOOT_MERGER_H
155