1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (c) 2014 Google, Inc 4 */ 5 6 #include <common.h> 7 #include <command.h> 8 #include <iotrace.h> 9 10 static void do_print_stats(void) 11 { 12 ulong start, size, offset, count; 13 14 printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis"); 15 iotrace_get_buffer(&start, &size, &offset, &count); 16 printf("Start: %08lx\n", start); 17 printf("Size: %08lx\n", size); 18 iotrace_get_region(&start, &size); 19 printf("Region: %08lx\n", start); 20 printf("Size: %08lx\n", size); 21 printf("Offset: %08lx\n", offset); 22 printf("Output: %08lx\n", start + offset); 23 printf("Count: %08lx\n", count); 24 printf("CRC32: %08lx\n", (ulong)iotrace_get_checksum()); 25 } 26 27 static int do_set_buffer(int argc, char * const argv[]) 28 { 29 ulong addr = 0, size = 0; 30 31 if (argc == 2) { 32 addr = simple_strtoul(*argv++, NULL, 16); 33 size = simple_strtoul(*argv++, NULL, 16); 34 } else if (argc != 0) { 35 return CMD_RET_USAGE; 36 } 37 38 iotrace_set_buffer(addr, size); 39 40 return 0; 41 } 42 43 static int do_set_region(int argc, char * const argv[]) 44 { 45 ulong addr = 0, size = 0; 46 47 if (argc == 2) { 48 addr = simple_strtoul(*argv++, NULL, 16); 49 size = simple_strtoul(*argv++, NULL, 16); 50 } else if (argc != 0) { 51 return CMD_RET_USAGE; 52 } 53 54 iotrace_set_region(addr, size); 55 56 return 0; 57 } 58 59 int do_iotrace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 60 { 61 const char *cmd = argc < 2 ? NULL : argv[1]; 62 63 if (!cmd) 64 return cmd_usage(cmdtp); 65 switch (*cmd) { 66 case 'b': 67 return do_set_buffer(argc - 2, argv + 2); 68 case 'l': 69 return do_set_region(argc - 2, argv + 2); 70 case 'p': 71 iotrace_set_enabled(0); 72 break; 73 case 'r': 74 iotrace_set_enabled(1); 75 break; 76 case 's': 77 do_print_stats(); 78 break; 79 default: 80 return CMD_RET_USAGE; 81 } 82 83 return 0; 84 } 85 86 U_BOOT_CMD( 87 iotrace, 4, 1, do_iotrace, 88 "iotrace utility commands", 89 "stats - display iotrace stats\n" 90 "iotrace buffer <address> <size> - set iotrace buffer\n" 91 "iotrace limit <address> <size> - set iotrace region limit\n" 92 "iotrace pause - pause tracing\n" 93 "iotrace resume - resume tracing" 94 ); 95