blob: 9b6be58f451ddd939392f47218c53eb7ed8fbb54 [file] [log] [blame]
Meng yufceeb992024-08-06 11:34:39 +08001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#include <common.h>
7#include <command.h>
8#include <amlogic/aml_profile.h>
9#include <asm/amlogic/arch/cpu_config.h>
10
11#define BL2_CORE "BL2"
12#define BL2_REE "BL2E"
13#define BL2_TEE "BL2X"
14#define BL31 "BL31"
15#define BL33 "BL33"
16
17int dump_boot_time_flag;
18
19struct measurement_item bl2_core_measurement_item[] = {
20 {.start_index = BL2_CORE_ROM, .end_index = BL2_CORE_ENTRY,
21 .name = "ROM time:"},
22 {.start_index = BL2_CORE_DDR_s, .end_index = BL2_CORE_DDR_e,
23 .name = "ddr time:"},
24 {.start_index = BL2_CORE_LOAD_BL2E_s, .end_index = BL2_CORE_LOAD_BL2E_e,
25 .name = "load bl2e time:"},
26 {.start_index = BL2_CORE_LOAD_BL2X_s, .end_index = BL2_CORE_LOAD_BL2X_e,
27 .name = "load bl2x time:"},
28 {.start_index = BL2_CORE_VERIFY_BL2EX_s, .end_index = BL2_CORE_VERIFY_BL2EX_e,
29 .name = "verify bl2e,bl2x time:"},
30 {.start_index = BL2_CORE_ENTRY, .end_index = BL2_CORE_BOOT_BL2E,
31 .name = "total bl2 time:"},
32};
33
34#define BL2_CORE_MEASUREMENT_ITEM_COUNT (ARRAY_SIZE(bl2_core_measurement_item))
35
36struct measurement_item bl2e_measurement_item[] = {
37 {.start_index = BL2_REE_LOAD_HEADER_s, .end_index = BL2_REE_LOAD_HEADER_e,
38 .name = "load fip head time:"},
39 {.start_index = BL2_REE_PROCESS_HEADER_s, .end_index = BL2_REE_PROCESS_HEADER_e,
40 .name = "process fip head time:"},
41 {.start_index = BL2_REE_LOAD_DEVFIP_s, .end_index = BL2_REE_LOAD_DEVFIP_e,
42 .name = "load dev-fip time:"},
43 {.start_index = BL2_REE_PROCESS_DEVFIP_s, .end_index = BL2_REE_PROCESS_DEVFIP_e,
44 .name = "process dev-fip time:"},
45 {.start_index = BL2_REE_ENTRY, .end_index = BL2_REE_PROCESS_DEVFIP_e,
46 .name = "total bl2e time:"},
47};
48
49#define BL2E_MEASUREMENT_ITEM_COUNT (ARRAY_SIZE(bl2e_measurement_item))
50
51struct measurement_item bl2x_measurement_item[] = {
52 {.start_index = BL2_TEE_PARSE_BL3X, .end_index = BL2_TEE_DECRYPT_BL3X,
53 .name = "parse bl3x time:"},
54 {.start_index = BL2_TEE_DECRYPT_BL3X, .end_index = BL2_TEE_BOOT_BL31,
55 .name = "decrypt,auth bl3x time:"},
56 {.start_index = BL2_TEE_ENTRY, .end_index = BL2_TEE_BOOT_BL31,
57 .name = "total bl2x time:"},
58};
59
60#define BL2X_MEASUREMENT_ITEM_COUNT (ARRAY_SIZE(bl2x_measurement_item))
61
62struct measurement_item bl31_measurement_item[] = {
63 {.start_index = BL31_SOC_INIT_s, .end_index = BL31_SOC_INIT_e,
64 .name = "soc init time:"},
65 {.start_index = BL31_BL32_INIT_s, .end_index = BL31_BL32_INIT_e,
66 .name = "bl32 init time:"},
67 {.start_index = BL31_ENTRY, .end_index = BL31_EXIT_MAIN,
68 .name = "total bl31,bl32 time:"},
69};
70
71#define BL31_MEASUREMENT_ITEM_COUNT (ARRAY_SIZE(bl31_measurement_item))
72
73struct measurement_item bl33_measurement_item[] = {
74 {.start_index = BL33_ENTRY, .end_index = BL33_RELOCATE_finish,
75 .name = "finish relocation time:"},
76 {.start_index = BL33_STORAGE_s, .end_index = BL33_STORAGE_e,
77 .name = "storage init time:"},
78 {.start_index = BL33_ENV_s, .end_index = BL33_ENV_e,
79 .name = "env init time:"},
80 {.start_index = BL33_LOAD_DTB_s, .end_index = BL33_LOAD_DTB_e,
81 .name = "load dtb time:"},
82 {.start_index = BL33_VPUVPP_INIT_s, .end_index = BL33_VPUVPP_INIT_e,
83 .name = "vpu vpp init:"},
84 {.start_index = BL33_PREBOOT_s, .end_index = BL33_PREBOOT_e,
85 .name = "preboot time:"},
86 {.start_index = BL33_LOAD_UIMAGE_s, .end_index = BL33_LOAD_UIMAGE_e,
87 .name = "load uimage time:"},
88 {.start_index = BL33_LOAD_UIMAGE_e, .end_index = BL33_BOOT_KERNEL_s,
89 .name = "boot uimage time:"},
90 {.start_index = BL33_ENTRY, .end_index = BL33_BOOT_KERNEL_s,
91 .name = "total bl33 time:"},
92};
93
94#define BL33_MEASUREMENT_ITEM_COUNT (ARRAY_SIZE(bl33_measurement_item))
95
96struct time_point_t time_point_bl33[BL33_MAX_NUM] = {{BL33, 1}, {"_start", 0},};
97
98void push_time_te(const char *func, unsigned int stage)
99{
100 if (stage >= BL33_MAX_NUM) {
101 printf("%s, func full\n", __func__);
102 return;
103 }
104
105 if (stage > BL33_ENTRY) {
106 unsigned int len = (strlen(func) > 11) ? 11 : strlen(func);
107
108 memcpy(time_point_bl33[stage].func, func, len);
109 }
110 time_point_bl33[stage].time = get_time();
111}
112
113void push_time_te_bl33(void)
114{
115 time_point_bl33[BL33_ENTRY].time = get_time();
116}
117
118static void print_item(unsigned long addr, void *item, unsigned int num)
119{
120 struct time_point_t *point = (struct time_point_t *)addr;
121 struct measurement_item *pitem = (struct measurement_item *)item;
122 int i, time_num = 0;
123 char *profile = NULL;
124
125 if (point[0].time == 1) {
126 printf("%s stage time(us):-------------\n", point[0].func);
127 for (i = 0; i < num; i++) {
128 printf("%-24s %8d\n", pitem[i].name, point[pitem[i].end_index].time
129 - point[pitem[i].start_index].time);
130 }
131
132 if (env_get("profile")) {
133 profile = env_get("profile");
134 if (!(strcmp(profile, "0") && strcmp(profile, "off")))
135 return;
136
137 if (strcmp(point[0].func, BL2_CORE) == 0)
138 time_num = BL2_CORE_MAX_NUM;
139 else if (strcmp(point[0].func, BL2_REE) == 0)
140 time_num = BL2_REE_MAX_NUM;
141 else if (strcmp(point[0].func, BL2_TEE) == 0)
142 time_num = BL2_TEE_MAX_NUM;
143 else if (strcmp(point[0].func, BL31) == 0)
144 time_num = BL31_MAX_NUM;
145 else if (strcmp(point[0].func, BL33) == 0)
146 time_num = BL33_MAX_NUM;
147
148 for (i = 1; i < time_num; i++)
149 printf("%3d, %16s %7d\n", i, point[i].func, point[i].time);
150 }
151 }
152}
153
154void dump_te(void)
155{
156 if (dump_boot_time_flag == 0)
157 return;
158
159 print_item(BL2E_PARAM_CORE, &bl2_core_measurement_item[0],
160 BL2_CORE_MEASUREMENT_ITEM_COUNT);
161 print_item(BL2E_PARAM_BL2E, &bl2e_measurement_item[0],
162 BL2E_MEASUREMENT_ITEM_COUNT);
163 print_item(BL2E_PARAM_BL2X, &bl2x_measurement_item[0],
164 BL2X_MEASUREMENT_ITEM_COUNT);
165 print_item(BL2E_PARAM_BL31, &bl31_measurement_item[0],
166 BL31_MEASUREMENT_ITEM_COUNT);
167 print_item((unsigned long)&time_point_bl33[0],
168 &bl33_measurement_item[0], BL33_MEASUREMENT_ITEM_COUNT);
169}
170
171static int do_pushte(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
172{
173 if (argc != 1)
174 return CMD_RET_USAGE;
175
176 dump_boot_time_flag = 1;
177 dump_te();
178 dump_boot_time_flag = 0;
179
180 return CMD_RET_SUCCESS;
181}
182
183U_BOOT_CMD(pushte, //command name
184 1, //maxargs
185 0, //repeatable
186 do_pushte, //command function
187 "print profile time", //description
188 "(no argv)\n" //usage
189 "Set env \"profile\" to print detailed time nodes"
190);