blob: 32ab57943c31da3bcbc7ed9723d364dea3adb85e [file] [log] [blame]
developere5e687d2023-08-08 16:05:33 +08001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2023 MediaTek Inc. All Rights Reserved.
4 *
5 * Author: Alvin Kuo <Alvin.Kuo@mediatek.com>
6 */
7
8#include <string.h>
9#include <stdio.h>
10#include <errno.h>
11
12#include "dump.h"
13
14static void print_usage(void)
15{
16 printf("Usage:\n");
17 printf(" tops-tool [CMD] [DUMP_DIR]\n");
18 printf(" [CMD] are:\n");
19 printf(" save_dump save dump data as file in directory [DUMP_DIR]\n");
20 printf(" [DUMP_DIR] is directory of dump file\n");
21}
22
23static int verify_parameters(int argc,
24 char *argv[])
25{
26 char *cmd;
27
28 if (argc < 2) {
29 fprintf(stderr, DUMP_LOG_FMT("missing cmd\n"));
30 return -EINVAL;
31 }
32
33 cmd = argv[1];
34 if (!strncmp(cmd, "save_dump", 9)) {
35 if (argc < 3) {
36 fprintf(stderr, DUMP_LOG_FMT("too few parameters\n"));
37 return -EINVAL;
38 }
39 }
40
41 return 0;
42}
43
44int main(int argc, char *argv[])
45{
46 int ret = 0;
47 char *cmd;
48
49 ret = verify_parameters(argc, argv);
50 if (ret) {
51 print_usage();
52 goto error;
53 }
54
55 cmd = argv[1];
56 if (!strncmp(cmd, "save_dump", 9)) {
57 ret = tops_save_dump_data(argv[2]);
58 if (ret) {
59 fprintf(stderr,
60 DUMP_LOG_FMT("cmd %s: save dump data fail(%d)\n"),
61 cmd, ret);
62 goto error;
63 }
64 } else {
65 fprintf(stderr, DUMP_LOG_FMT("unsupported cmd %s\n"), cmd);
66 goto error;
67 }
68
69error:
70 return ret;
71}