-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathkeil-build-viewer.h
350 lines (316 loc) · 15.8 KB
/
keil-build-viewer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#ifndef __KEIL_BUILD_VIEWER_H__
#define __KEIL_BUILD_VIEWER_H__
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <windows.h>
#define APP_NAME "keil-build-viewer"
#define APP_VERSION "v1.6"
#define MAX_DIR_HIERARCHY 32 /* 最大目录层级 */
#define MAX_PATH_QTY 32 /* 最大目录数量 */
#define MAX_FILE_QTY 512 /* 最大文件数量 */
#define MAX_PRJ_NAME_SIZE 128 /* 最大工程名称长度 */
#define OBJECT_INFO_STR_QTY 7 /* Code + (inc. data) + RO Data + RW Data + ZI Data + Debug + Object Name */
#define ENABLE_REFER_TO_KEIL_DIALOG 0 /* 当 chip 没有对应的 keil pack 且使用自定义的 scatter file 时,是否参考 keil 的 memory dialog */
#define UNKNOWN_MEMORY_ID 1
#define ZI_SYMBOL_0 0x4F /* O */
#define USED_SYMBOL_0 0x23 /* # */
#define ZI_SYMBOL_1 0x4F /* O */
#define USED_SYMBOL_1 0x58 /* X */
#define ZI_SYMBOL_GBK_H 0xA1 /* □ */
#define ZI_SYMBOL_GBK_L 0xF5
#define USED_SYMBOL_GBK_H 0xA1 /* ■ */
#define USED_SYMBOL_GBK_L 0xF6
#define ZI_SYMBOL_BIG5_H 0xA1 /* □ */
#define ZI_SYMBOL_BIG5_L 0xBC
#define USED_SYMBOL_BIG5_H 0xA1 /* ■ */
#define USED_SYMBOL_BIG5_L 0xBD
#define UNUSE_SYMBOL "_"
#define UNUSED_LOAD_REGION_NAME "Unused Load Region"
#define STR_ZERO_INIT " Zero "
#define STR_PADDING " PAD"
#define STR_RENAME_MARK " - object file renamed from "
#define STR_COMPILING "compiling "
#define STR_MAX_STACK_USAGE "Maximum Stack Usage "
#define STR_FILE "FILE(s)"
#define STR_LTO_LLVW "lto-llvm-"
#define STR_MEMORY_MAP_OF_THE_IMAGE "Memory Map of the image"
#define STR_LOAD_REGION "Load Region"
#define STR_EXECUTION_REGION "Execution Region"
#define STR_LOAD_BASE "Load base: "
#define STR_REGION_USED_SIZE "Size: "
#define STR_REGION_MAX_SIZE "Max: "
#define STR_EXECUTE_BASE "Base: "
#define STR_EXECUTE_BASE_ADDR "Exec base: "
#define STR_IMAGE_COMPONENT_SIZE "Image component sizes"
#define STR_OBJECT_NAME "Object Name"
#define STR_LIBRARY_MEMBER_NAME "Library Member Name"
#define STR_LIBRARY_NAME "Library Name"
#define STR_OBJECT_TOTALS "Object Totals"
#define STR_LIBRARY_TOTALS "Library Totals"
#define LABEL_TARGET_NAME "<TargetName>"
#define LABEL_IS_CURRENT_TARGET "<IsCurrentTarget>"
#define LABEL_DEVICE "<Device>"
#define LABEL_VENDOR "<Vendor>"
#define LABEL_CPU "<Cpu>"
#define LABEL_OUTPUT_DIRECTORY "<OutputDirectory>"
#define LABEL_OUTPUT_NAME "<OutputName>"
#define LABEL_LISTING_PATH "<ListingPath>"
#define LABEL_IS_CREATE_MAP "<AdsLLst>"
#define LABEL_AC6_LTO "<v6Lto>"
#define LABEL_IS_KEIL_SCATTER "<umfTarg>"
#define LABEL_END_GROUPS "</Groups>"
#define LABEL_END_FILE "</File>"
#define LABEL_END_FILES "</Files>"
#define LABEL_END_CADS "</Cads>"
#define LABEL_END_LDADS "</LDads>"
#define LABEL_GROUP_NAME "<GroupName>"
#define LABEL_FILE_NAME "<FileName>"
#define LABEL_FILE_TYPE "<FileType>"
#define LABEL_FILE_PATH "<FilePath>"
#define LABEL_INCLUDE_IN_BUILD "<IncludeInBuild>"
#define LABEL_ONCHIP_MEMORY "<OnChipMemories>"
#define LABEL_END_ONCHIP_MEMORY "</OnChipMemories>"
#define LABEL_MEMORY_AREA "<OCR_RVCT"
#define LABLE_END_MEMORY_AREA "</OCR_RVCT"
#define LABEL_MEMORY_TYPE "<Type>"
#define LABEL_MEMORY_ADDRESS "<StartAddress>"
#define LABEL_MEMORY_SIZE "<Size>"
#define log_save(log, fmt, ...) log_write(log, false, fmt, ##__VA_ARGS__)
#define log_print(log, fmt, ...) log_write(log, true, fmt, ##__VA_ARGS__)
typedef enum
{
ENCODING_TYPE_GBK = 0x00,
ENCODING_TYPE_BIG5,
ENCODING_TYPE_OTHER,
} ENCODING_TYPE;
typedef enum
{
PROGRESS_STYLE_0 = 0x00,
PROGRESS_STYLE_1,
PROGRESS_STYLE_2,
} PROGRESS_STYLE;
typedef enum
{
MEMORY_PRINT_MODE_0 = 0x00, /* keil pack 有 RAM 和 ROM 信息(多数情况) */
MEMORY_PRINT_MODE_1, /* keil pack 没有 RAM 和 ROM 信息,但 memory 使用了 keil dialog 配置 */
MEMORY_PRINT_MODE_2, /* keil pack 没有 RAM 和 ROM 信息,并且使用自定义的 scatter file */
} MEMORY_PRINT_MODE;
typedef enum
{
MEMORY_TYPE_NONE = 0x00,
MEMORY_TYPE_RAM,
MEMORY_TYPE_FLASH,
MEMORY_TYPE_UNKNOWN,
} MEMORY_TYPE;
typedef enum
{
OBJECT_FILE_TYPE_UNKNOWN = 0x00,
OBJECT_FILE_TYPE_USER,
OBJECT_FILE_TYPE_OBJECT,
OBJECT_FILE_TYPE_LIBRARY,
} OBJECT_FILE_TYPE;
/* keil 工程路径存储链表 */
struct prj_path_list
{
char **items;
size_t capacity;
size_t size;
};
struct object_info
{
char *name;
char *path;
uint32_t code;
uint32_t ro_data;
uint32_t rw_data;
uint32_t zi_data;
struct object_info *old_object;
struct object_info *next;
};
struct region_block
{
uint32_t start_addr;
uint32_t size;
struct region_block *next;
};
struct exec_region
{
char *name;
char *load_region_name;
size_t memory_id; /* 从 1 开始, 1 固定为 unknown */
uint32_t base_addr;
uint32_t size;
uint32_t used_size;
MEMORY_TYPE memory_type;
bool is_offchip;
bool is_printed;
struct region_block *zi_block;
struct exec_region *old_exec_region;
struct exec_region *next;
};
struct load_region
{
char *name;
struct exec_region *exec_region;
struct load_region *next;
};
struct memory_info
{
char *name;
size_t id;
size_t mem_id;
uint32_t base_addr;
uint32_t size;
MEMORY_TYPE type;
bool is_from_pack;
bool is_offchip;
bool is_used;
struct memory_info *next;
};
struct file_path_list
{
char *old_name; /* 原名 */
char *object_name; /* 更改为 .o 后缀名的名称 */
char *new_object_name; /* 因重名而改名后的名称,为 .o 后缀 */
char *path;
bool is_rename;
OBJECT_FILE_TYPE file_type;
struct file_path_list *next;
};
struct command_list
{
const char *cmd;
const char *desc;
};
struct uvprojx_info
{
bool is_has_pack;
bool is_enable_lto;
bool is_has_user_lib;
bool is_custom_scatter;
char chip[MAX_PRJ_NAME_SIZE];
char target_name[MAX_PRJ_NAME_SIZE];
char output_name[MAX_PRJ_NAME_SIZE];
char output_path[MAX_PATH];
char listing_path[MAX_PATH];
};
bool is_keil_project (const char *path);
bool is_same_string (const char *str1,
const char *str2[],
size_t str2_qty);
int combine_path (char *out_path,
size_t out_path_size,
const char *absolute_path,
const char *relative_path);
bool file_path_add (struct file_path_list **path_head,
const char *name,
const char *path,
OBJECT_FILE_TYPE file_type);
void file_path_free (struct file_path_list **path_head);
bool memory_info_add (struct memory_info **memory_head,
const char *name,
size_t id,
uint32_t base_addr,
uint32_t size,
MEMORY_TYPE mem_type,
bool is_offchip,
bool is_from_pack);
void memory_info_free (struct memory_info **memory_head);
bool object_info_add (struct object_info **object_head,
const char *name,
uint32_t code,
uint32_t ro_data,
uint32_t rw_data,
uint32_t zi_data);
void object_info_free (struct object_info **object_head);
struct load_region * load_region_create (struct load_region **region_head, const char *name);
struct exec_region * load_region_add_exec_region (struct load_region **region_head,
const char *name,
const char *load_region_name,
size_t memory_id,
uint32_t base_addr,
uint32_t size,
uint32_t used_size,
MEMORY_TYPE mem_type,
bool is_offchip);
void load_region_free (struct load_region **region_head);
void search_files_by_extension (const char *dir,
size_t dir_len,
const char *extension[],
size_t extension_qty,
struct prj_path_list *list);
struct prj_path_list * prj_path_list_init (size_t capacity);
void prj_path_list_add (struct prj_path_list *list, char *path);
void prj_path_list_free (struct prj_path_list *list);
int parameter_process (int param_qty,
char *param[],
char *prj_name,
size_t name_size,
char *prj_path,
size_t path_size,
int *err_param);
bool uvoptx_file_process (const char *file_path,
char *target_name,
size_t max_size);
int uvprojx_file_process (const char *file_path,
const char *target_name,
struct uvprojx_info *out_info,
bool is_get_target_name);
bool memory_area_process (const char *str, bool is_new);
bool file_path_process (const char *str, bool *is_has_user_lib);
void build_log_file_process (const char *file_path);
void file_rename_process (void);
int map_file_process (const char *file_path,
struct load_region **region_head,
struct object_info **object_head,
bool is_get_user_lib,
bool is_match_memory);
int region_info_process (FILE *p_file,
long read_start_pos,
struct load_region **region_head,
bool is_match_memory);
void region_zi_process (struct exec_region **e_region,
char *text,
size_t size_pos);
int object_info_process (struct object_info **object_head,
FILE *p_file,
long *end_pos,
bool is_get_user_lib,
uint8_t parse_mode);
int record_file_process (const char *file_path,
struct load_region **region_head,
struct object_info **object_head,
bool *is_has_object,
bool *is_has_region,
bool is_match_memory);
void object_print_process (struct object_info *object_head,
size_t max_path_len,
bool is_has_record);
void memory_numbering (MEMORY_TYPE mem_type);
void memory_print_unused (MEMORY_TYPE mem_type, size_t max_region_name);
void memory_mode0_print (struct exec_region *e_region,
const char *load_region_name,
MEMORY_TYPE mem_type,
size_t max_region_name,
bool is_has_record,
bool is_print_null);
void memory_mode1_print (struct exec_region *e_region,
MEMORY_TYPE mem_type,
bool is_offchip,
size_t max_region_name,
bool is_has_record);
void memory_mode2_print (struct exec_region *e_region,
size_t max_region_name,
bool is_has_record);
void progress_print (struct exec_region *region,
size_t max_region_name,
bool is_has_record);
void stack_print_process (const char *file_path);
void log_write (FILE *p_log,
bool is_print,
const char *fmt,
...);
#endif