mcp251xfd-dump: add tool to decode chip and driver state of mcp251xfd

It works on dev coredump data generated by the mcp251xfd driver in
case of failures, as well as on regmap based register dumps.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
Marc Kleine-Budde
2021-02-13 23:36:43 +01:00
parent e8c90ddff9
commit 66de96d337
13 changed files with 1913 additions and 1 deletions
+81
View File
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: GPL-2.0
//
// Microchip MCP251xFD Family CAN controller debug tool
//
// Copyright (c) 2020 Pengutronix,
// Marc Kleine-Budde <kernel@pengutronix.de>
//
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <linux/kernel.h>
#include "mcp251xfd.h"
#include "mcp251xfd-dump-userspace.h"
static int
do_mcp251xfd_regmap_read(struct mcp251xfd_priv *priv,
struct mcp251xfd_mem *mem,
const char *file_path)
{
FILE *reg_file;
uint16_t reg;
uint32_t val;
reg_file = fopen(file_path, "r");
if (!reg_file)
return -errno;
while (fscanf(reg_file, "%hx: %x\n", &reg, &val) == 2) {
if (reg >= ARRAY_SIZE(mem->buf))
return -EINVAL;
*(uint32_t *)(mem->buf + reg) = val;
}
fclose(reg_file);
return 0;
}
int mcp251xfd_regmap_read(struct mcp251xfd_priv *priv,
struct mcp251xfd_mem *mem,
const char *file_path)
{
char *tmp;
int err;
err = do_mcp251xfd_regmap_read(priv, mem, file_path);
if (!err)
return 0;
/* maybe it's something like "spi0.0" */
tmp = strchr(file_path, '/');
if (tmp)
return -ENOENT;
/* first try literally */
err = asprintf(&tmp, "/sys/kernel/debug/regmap/%s/registers", file_path);
if (err == -1)
return -errno;
err = do_mcp251xfd_regmap_read(priv, mem, tmp);
free (tmp);
if (!err)
return 0;
/* then add "-crc" */
err = asprintf(&tmp, "/sys/kernel/debug/regmap/%s-crc/registers", file_path);
if (err == -1)
return -errno;
err = do_mcp251xfd_regmap_read(priv, mem, tmp);
free (tmp);
return err;
}