1 /* 2 * Copyright (c) 2012, Google Inc. All rights reserved. 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 9 static int do_bootstage_report(cmd_tbl_t *cmdtp, int flag, int argc, 10 char * const argv[]) 11 { 12 bootstage_report(); 13 14 return 0; 15 } 16 17 static int get_base_size(int argc, char * const argv[], ulong *basep, 18 ulong *sizep) 19 { 20 char *endp; 21 22 *basep = CONFIG_BOOTSTAGE_STASH_ADDR; 23 *sizep = CONFIG_BOOTSTAGE_STASH_SIZE; 24 if (argc < 2) 25 return 0; 26 *basep = simple_strtoul(argv[1], &endp, 16); 27 if (*argv[1] == 0 || *endp != 0) 28 return -1; 29 if (argc == 2) 30 return 0; 31 *sizep = simple_strtoul(argv[2], &endp, 16); 32 if (*argv[2] == 0 || *endp != 0) 33 return -1; 34 35 return 0; 36 } 37 38 static int do_bootstage_stash(cmd_tbl_t *cmdtp, int flag, int argc, 39 char * const argv[]) 40 { 41 ulong base, size; 42 int ret; 43 44 if (get_base_size(argc, argv, &base, &size)) 45 return CMD_RET_USAGE; 46 if (base == -1UL) { 47 printf("No bootstage stash area defined\n"); 48 return 1; 49 } 50 51 if (0 == strcmp(argv[0], "stash")) 52 ret = bootstage_stash((void *)base, size); 53 else 54 ret = bootstage_unstash((void *)base, size); 55 if (ret) 56 return 1; 57 58 return 0; 59 } 60 61 static cmd_tbl_t cmd_bootstage_sub[] = { 62 U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""), 63 U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""), 64 U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""), 65 }; 66 67 /* 68 * Process a bootstage sub-command 69 */ 70 static int do_boostage(cmd_tbl_t *cmdtp, int flag, int argc, 71 char * const argv[]) 72 { 73 cmd_tbl_t *c; 74 75 /* Strip off leading 'bootstage' command argument */ 76 argc--; 77 argv++; 78 79 c = find_cmd_tbl(argv[0], cmd_bootstage_sub, 80 ARRAY_SIZE(cmd_bootstage_sub)); 81 82 if (c) 83 return c->cmd(cmdtp, flag, argc, argv); 84 else 85 return CMD_RET_USAGE; 86 } 87 88 89 U_BOOT_CMD(bootstage, 4, 1, do_boostage, 90 "Boot stage command", 91 " - check boot progress and timing\n" 92 "report - Print a report\n" 93 "stash [<start> [<size>]] - Stash data into memory\n" 94 "unstash [<start> [<size>]] - Unstash data from memory" 95 ); 96