Skip to content

Commit

Permalink
ramdump: Add support for filtering which segments to extract
Browse files Browse the repository at this point in the history
The typical ramdump covers the entire DDR, which on modern devices can
be huge. But sometimes one is only interested in one or more specific
segments.

Parse the optional, comma-separated, argument to qdl-ramdump, and use
this to skip not requested segments.

Signed-off-by: Bjorn Andersson <[email protected]>
  • Loading branch information
quic-bjorande authored and Konrad Dybcio committed May 8, 2024
1 parent 2fd923e commit 5f2f82a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ks.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int main(int argc, char **argv)
return 1;
}

ret = sahara_run(&qdl, qdl.mappings, false, NULL);
ret = sahara_run(&qdl, qdl.mappings, false, NULL, NULL);
if (ret < 0)
return 1;

Expand Down
2 changes: 1 addition & 1 deletion qdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int main(int argc, char **argv)
return 1;

qdl.mappings[0] = prog_mbn;
ret = sahara_run(&qdl, qdl.mappings, true, NULL);
ret = sahara_run(&qdl, qdl.mappings, true, NULL, NULL);
if (ret < 0)
return 1;

Expand Down
2 changes: 1 addition & 1 deletion qdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int qdl_write(struct qdl_device *qdl, const void *buf, size_t len);

int firehose_run(struct qdl_device *qdl, const char *incdir, const char *storage);
int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
const char *ramdump_path);
const char *ramdump_path, const char *ramdump_filter);
void print_hex_dump(const char *prefix, const void *buf, size_t len);
unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors);
const char *attr_as_string(xmlNode *node, const char *attr, int *errors);
Expand Down
8 changes: 6 additions & 2 deletions ramdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static void print_usage(void)
{
extern const char *__progname;
fprintf(stderr,
"%s [--debug] [-o <ramdump-path>]\n",
"%s [--debug] [-o <ramdump-path>] [segment-filter,...]\n",
__progname);
exit(1);
}
Expand All @@ -20,6 +20,7 @@ int main(int argc, char **argv)
{
struct qdl_device qdl;
char *ramdump_path = ".";
char *filter = NULL;
int ret;
int opt;

Expand All @@ -42,14 +43,17 @@ int main(int argc, char **argv)
}
}

if (optind < argc)
filter = argv[optind++];

if (optind != argc)
print_usage();

ret = qdl_open(&qdl);
if (ret)
return 1;

ret = sahara_run(&qdl, NULL, true, ramdump_path);
ret = sahara_run(&qdl, NULL, true, ramdump_path, filter);
if (ret < 0)
return 1;

Expand Down
32 changes: 29 additions & 3 deletions sahara.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <inttypes.h>
#include <poll.h>
#include <stdbool.h>
Expand Down Expand Up @@ -358,8 +359,30 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
return 0;
}

static bool sahara_debug64_filter(const char *filename, const char *filter)
{
bool anymatch = false;
char *ptr;
char *tmp;
char *s;

if (!filter)
return false;

tmp = strdup(filter);
for (s = strtok_r(tmp, ",", &ptr); s; s = strtok_r(NULL, ",", &ptr)) {
if (fnmatch(s, filename, 0) == 0) {
anymatch = true;
break;
}
}
free(tmp);

return !anymatch;
}

static void sahara_debug64(struct qdl_device *qdl, struct sahara_pkt *pkt,
int ramdump_dir)
int ramdump_dir, const char *filter)
{
struct sahara_debug_region64 *table;
struct sahara_pkt read_req;
Expand Down Expand Up @@ -387,6 +410,9 @@ static void sahara_debug64(struct qdl_device *qdl, struct sahara_pkt *pkt,
return;

for (i = 0; i < pkt->debug64_req.length / sizeof(table[0]); i++) {
if (sahara_debug64_filter(table[i].filename, filter))
continue;

printf("%-2d: type 0x%" PRIx64 " address: 0x%" PRIx64 " length: 0x%" PRIx64 " region: %s filename: %s\n",
i, table[i].type, table[i].addr, table[i].length, table[i].region, table[i].filename);

Expand All @@ -403,7 +429,7 @@ static void sahara_debug64(struct qdl_device *qdl, struct sahara_pkt *pkt,
}

int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
const char *ramdump_path)
const char *ramdump_path, const char *ramdump_filter)
{
struct sahara_pkt *pkt;
int ramdump_dir = -1;
Expand Down Expand Up @@ -447,7 +473,7 @@ int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
done = true;
break;
case SAHARA_MEM_DEBUG64_CMD:
sahara_debug64(qdl, pkt, ramdump_dir);
sahara_debug64(qdl, pkt, ramdump_dir, ramdump_filter);
break;
case SAHARA_READ_DATA64_CMD:
sahara_read64(qdl, pkt, img_arr, single_image);
Expand Down

0 comments on commit 5f2f82a

Please sign in to comment.