cmd_bootstage.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2012, Google Inc. All rights reserved.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #ifndef CONFIG_BOOTSTAGE_STASH
  24. #define CONFIG_BOOTSTAGE_STASH -1UL
  25. #define CONFIG_BOOTSTAGE_STASH_SIZE -1
  26. #endif
  27. static int do_bootstage_report(cmd_tbl_t *cmdtp, int flag, int argc,
  28. char * const argv[])
  29. {
  30. bootstage_report();
  31. return 0;
  32. }
  33. static int get_base_size(int argc, char * const argv[], ulong *basep,
  34. ulong *sizep)
  35. {
  36. char *endp;
  37. *basep = CONFIG_BOOTSTAGE_STASH;
  38. *sizep = CONFIG_BOOTSTAGE_STASH_SIZE;
  39. if (argc < 2)
  40. return 0;
  41. *basep = simple_strtoul(argv[1], &endp, 16);
  42. if (*argv[1] == 0 || *endp != 0)
  43. return -1;
  44. if (argc == 2)
  45. return 0;
  46. *sizep = simple_strtoul(argv[2], &endp, 16);
  47. if (*argv[2] == 0 || *endp != 0)
  48. return -1;
  49. return 0;
  50. }
  51. static int do_bootstage_stash(cmd_tbl_t *cmdtp, int flag, int argc,
  52. char * const argv[])
  53. {
  54. ulong base, size;
  55. int ret;
  56. if (get_base_size(argc, argv, &base, &size))
  57. return CMD_RET_USAGE;
  58. if (base == -1UL) {
  59. printf("No bootstage stash area defined\n");
  60. return 1;
  61. }
  62. if (0 == strcmp(argv[0], "stash"))
  63. ret = bootstage_stash((void *)base, size);
  64. else
  65. ret = bootstage_unstash((void *)base, size);
  66. if (ret)
  67. return 1;
  68. return 0;
  69. }
  70. static cmd_tbl_t cmd_bootstage_sub[] = {
  71. U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""),
  72. U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""),
  73. U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""),
  74. };
  75. /*
  76. * Process a bootstage sub-command
  77. */
  78. static int do_boostage(cmd_tbl_t *cmdtp, int flag, int argc,
  79. char * const argv[])
  80. {
  81. cmd_tbl_t *c;
  82. /* Strip off leading 'bootstage' command argument */
  83. argc--;
  84. argv++;
  85. c = find_cmd_tbl(argv[0], cmd_bootstage_sub,
  86. ARRAY_SIZE(cmd_bootstage_sub));
  87. if (c)
  88. return c->cmd(cmdtp, flag, argc, argv);
  89. else
  90. return CMD_RET_USAGE;
  91. }
  92. U_BOOT_CMD(bootstage, 4, 1, do_boostage,
  93. "Boot stage command",
  94. " - check boot progress and timing\n"
  95. "report - Print a report\n"
  96. "stash [<start> [<size>]] - Stash data into memory\n"
  97. "unstash [<start> [<size>]] - Unstash data from memory"
  98. );