2025-06-24 06:49:51 +02:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2024-03-25 14:15:03 -05:00
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include "qdl.h"
|
|
|
|
|
|
2025-05-02 09:16:25 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
const char *__progname = "ramdump";
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-03-25 14:15:03 -05:00
|
|
|
bool qdl_debug;
|
|
|
|
|
|
2025-09-13 22:05:33 -07:00
|
|
|
static void print_usage(FILE *out)
|
2024-03-25 14:15:03 -05:00
|
|
|
{
|
|
|
|
|
extern const char *__progname;
|
2025-06-18 09:39:54 +02:00
|
|
|
|
2025-09-13 22:05:33 -07:00
|
|
|
fprintf(out,
|
2024-03-25 14:15:03 -05:00
|
|
|
"%s [--debug] [-o <ramdump-path>] [segment-filter,...]\n",
|
2024-03-25 14:15:03 -05:00
|
|
|
__progname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2025-04-22 16:34:18 +02:00
|
|
|
struct qdl_device *qdl;
|
|
|
|
|
|
|
|
|
|
qdl = qdl_init(QDL_DEVICE_USB);
|
|
|
|
|
if (!qdl)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2024-03-25 14:15:03 -05:00
|
|
|
char *ramdump_path = ".";
|
2024-03-25 14:15:03 -05:00
|
|
|
char *filter = NULL;
|
2024-05-07 15:08:57 -05:00
|
|
|
char *serial = NULL;
|
2025-04-22 16:34:18 +02:00
|
|
|
int ret = 0;
|
2024-03-25 14:15:03 -05:00
|
|
|
int opt;
|
|
|
|
|
|
|
|
|
|
static struct option options[] = {
|
|
|
|
|
{"debug", no_argument, 0, 'd'},
|
2025-01-17 10:31:37 +01:00
|
|
|
{"version", no_argument, 0, 'v'},
|
2024-03-25 14:15:03 -05:00
|
|
|
{"output", required_argument, 0, 'o'},
|
2024-05-07 15:08:57 -05:00
|
|
|
{"serial", required_argument, 0, 'S'},
|
2025-09-13 22:05:33 -07:00
|
|
|
{"help", no_argument, 0, 'h'},
|
2024-03-25 14:15:03 -05:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-13 22:05:33 -07:00
|
|
|
while ((opt = getopt_long(argc, argv, "dvo:S:h", options, NULL)) != -1) {
|
2024-03-25 14:15:03 -05:00
|
|
|
switch (opt) {
|
|
|
|
|
case 'd':
|
|
|
|
|
qdl_debug = true;
|
|
|
|
|
break;
|
2025-01-17 10:31:37 +01:00
|
|
|
case 'v':
|
|
|
|
|
print_version();
|
2025-04-22 16:34:18 +02:00
|
|
|
ret = 0;
|
|
|
|
|
goto out_cleanup;
|
2024-03-25 14:15:03 -05:00
|
|
|
case 'o':
|
|
|
|
|
ramdump_path = optarg;
|
|
|
|
|
break;
|
2024-05-07 15:08:57 -05:00
|
|
|
case 'S':
|
|
|
|
|
serial = optarg;
|
|
|
|
|
break;
|
2025-09-13 22:05:33 -07:00
|
|
|
case 'h':
|
|
|
|
|
print_usage(stdout);
|
|
|
|
|
return 0;
|
2024-03-25 14:15:03 -05:00
|
|
|
default:
|
2025-09-13 22:05:33 -07:00
|
|
|
print_usage(stderr);
|
|
|
|
|
return 1;
|
2024-03-25 14:15:03 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-25 14:15:03 -05:00
|
|
|
if (optind < argc)
|
|
|
|
|
filter = argv[optind++];
|
|
|
|
|
|
2025-09-13 22:05:33 -07:00
|
|
|
if (optind != argc) {
|
|
|
|
|
print_usage(stderr);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2024-03-25 14:15:03 -05:00
|
|
|
|
2026-02-02 10:17:16 -06:00
|
|
|
ux_init();
|
|
|
|
|
|
2025-01-17 10:31:37 +01:00
|
|
|
if (qdl_debug)
|
|
|
|
|
print_version();
|
|
|
|
|
|
2025-04-22 16:34:18 +02:00
|
|
|
ret = qdl_open(qdl, serial);
|
|
|
|
|
if (ret) {
|
|
|
|
|
ret = 1;
|
|
|
|
|
goto out_cleanup;
|
|
|
|
|
}
|
2024-03-25 14:15:03 -05:00
|
|
|
|
2026-01-26 22:26:07 -06:00
|
|
|
ret = sahara_run(qdl, NULL, ramdump_path, filter);
|
2025-04-22 16:34:18 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
|
ret = 1;
|
|
|
|
|
goto out_cleanup;
|
|
|
|
|
}
|
2024-03-25 14:15:03 -05:00
|
|
|
|
2025-04-22 16:34:18 +02:00
|
|
|
out_cleanup:
|
|
|
|
|
qdl_close(qdl);
|
|
|
|
|
qdl_deinit(qdl);
|
|
|
|
|
|
|
|
|
|
return ret;
|
2024-03-25 14:15:03 -05:00
|
|
|
}
|