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