]>
Commit | Line | Data |
---|---|---|
cabcbb56 SG |
1 | /* |
2 | * Copyright (c) 2011 The Chromium OS Authors. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License as | |
6 | * published by the Free Software Foundation; either version 2 of | |
7 | * the License, or (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
17 | * MA 02111-1307 USA | |
18 | */ | |
19 | ||
20 | #include <common.h> | |
21 | #include <command.h> | |
22 | #include <trace.h> | |
23 | #include <asm/io.h> | |
24 | ||
25 | static int get_args(int argc, char * const argv[], char **buff, | |
26 | size_t *buff_ptr, size_t *buff_size) | |
27 | { | |
28 | if (argc < 2) | |
29 | return -1; | |
30 | if (argc < 4) { | |
31 | *buff_size = getenv_ulong("profsize", 16, 0); | |
32 | *buff = map_sysmem(getenv_ulong("profbase", 16, 0), | |
33 | *buff_size); | |
34 | *buff_ptr = getenv_ulong("profoffset", 16, 0); | |
35 | } else { | |
36 | *buff_size = simple_strtoul(argv[3], NULL, 16); | |
37 | *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16), | |
38 | *buff_size); | |
39 | *buff_ptr = 0; | |
40 | }; | |
41 | return 0; | |
42 | } | |
43 | ||
44 | static int create_func_list(int argc, char * const argv[]) | |
45 | { | |
46 | size_t buff_size, avail, buff_ptr, used; | |
47 | unsigned int needed; | |
48 | char *buff; | |
49 | int err; | |
50 | ||
51 | if (get_args(argc, argv, &buff, &buff_ptr, &buff_size)) | |
52 | return -1; | |
53 | ||
54 | avail = buff_size - buff_ptr; | |
55 | err = trace_list_functions(buff + buff_ptr, avail, &needed); | |
56 | if (err) | |
57 | printf("Error: truncated (%#x bytes needed)\n", needed); | |
58 | used = min(avail, needed); | |
59 | printf("Function trace dumped to %08lx, size %#zx\n", | |
60 | (ulong)map_to_sysmem(buff + buff_ptr), used); | |
61 | setenv_hex("profbase", map_to_sysmem(buff)); | |
62 | setenv_hex("profsize", buff_size); | |
63 | setenv_hex("profoffset", buff_ptr + used); | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
68 | static int create_call_list(int argc, char * const argv[]) | |
69 | { | |
70 | size_t buff_size, avail, buff_ptr, used; | |
71 | unsigned int needed; | |
72 | char *buff; | |
73 | int err; | |
74 | ||
75 | if (get_args(argc, argv, &buff, &buff_ptr, &buff_size)) | |
76 | return -1; | |
77 | ||
78 | avail = buff_size - buff_ptr; | |
79 | err = trace_list_calls(buff + buff_ptr, avail, &needed); | |
80 | if (err) | |
81 | printf("Error: truncated (%#x bytes needed)\n", needed); | |
82 | used = min(avail, needed); | |
83 | printf("Call list dumped to %08lx, size %#zx\n", | |
84 | (ulong)map_to_sysmem(buff + buff_ptr), used); | |
85 | ||
86 | setenv_hex("profbase", map_to_sysmem(buff)); | |
87 | setenv_hex("profsize", buff_size); | |
88 | setenv_hex("profoffset", buff_ptr + used); | |
89 | ||
90 | return 0; | |
91 | } | |
92 | ||
93 | int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
94 | { | |
95 | const char *cmd = argc < 2 ? NULL : argv[1]; | |
96 | ||
97 | if (!cmd) | |
98 | return cmd_usage(cmdtp); | |
99 | switch (*cmd) { | |
100 | case 'p': | |
101 | trace_set_enabled(0); | |
102 | break; | |
103 | case 'c': | |
104 | if (create_call_list(argc, argv)) | |
105 | return cmd_usage(cmdtp); | |
106 | break; | |
107 | case 'r': | |
108 | trace_set_enabled(1); | |
109 | break; | |
110 | case 'f': | |
111 | if (create_func_list(argc, argv)) | |
112 | return cmd_usage(cmdtp); | |
113 | break; | |
114 | case 's': | |
115 | trace_print_stats(); | |
116 | break; | |
117 | default: | |
118 | return CMD_RET_USAGE; | |
119 | } | |
120 | ||
121 | return 0; | |
122 | } | |
123 | ||
124 | U_BOOT_CMD( | |
125 | trace, 4, 1, do_trace, | |
126 | "trace utility commands", | |
127 | "stats - display tracing statistics\n" | |
128 | "trace pause - pause tracing\n" | |
129 | "trace resume - resume tracing\n" | |
130 | "trace funclist [<addr> <size>] - dump function list into buffer\n" | |
131 | "trace calls [<addr> <size>] " | |
132 | "- dump function call trace into buffer" | |
133 | ); |