From 96e825da7985d65eba5084dab898736df79f9c4b Mon Sep 17 00:00:00 2001 From: Josua Mayer Date: Tue, 11 Jun 2024 13:35:44 +0200 Subject: [PATCH] cmd: fuse: add report command for mvebu This is an armada-388-specific efuse dumping command used during production at SolidRun to ensure all efuses are clear. Likely it breaks the build for other platforms and should be rewritten when upstream is desired. Signed-off-by: Josua Mayer --- cmd/fuse.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/cmd/fuse.c b/cmd/fuse.c index f884c894fb00..691c99e28289 100644 --- a/cmd/fuse.c +++ b/cmd/fuse.c @@ -14,6 +14,7 @@ #include #include #include +#include static int strtou32(const char *str, unsigned int base, u32 *result) { @@ -41,6 +42,54 @@ static int confirm_prog(void) return 0; } +static int report(const char *interface, const char *device, const char *filename) +{ + int i, j; + int ret; + uint32_t val[3]; + char buffer[66*64] = {0}; + size_t len = 0; + + // open report device + if (interface && device && filename) { + ret = fs_set_blk_dev(interface, device, FS_TYPE_ANY); + if (ret) { + printf("Failed to open %s %s: %d\n", interface, device, ret); + return 1; + } + } + + // read all fuse banks + for (i = 0; i <= 65; i++) { + for (j = 0; j < 3; j++) { + ret = fuse_read(i, j, &val[j]); + if (ret) + return ret; + // TODO: report + } + if (!ret) { + printf("EFUSE bank %.2d: 0x%.8x 0x%.8x 0x%.8x\n", i, val[0], val[1], val[2]); + len += sprintf(&buffer[len], "EFUSE bank %.2d: 0x%.8x 0x%.8x 0x%.8x\n", i, val[0], val[1], val[2]); + } else { + printf("EFUSE bank %.2d: Error %d\n", i, ret); + len += sprintf(&buffer[len], "EFUSE bank %.2d: Error %d\n", i, ret); + } + } + + // write report + if (interface && device && filename) { + ret = fs_write(filename, map_to_sysmem(buffer), 0, len, NULL); + if (ret < 0) { + printf("Failed to write report file \"%s\": %d\n", filename, ret); + return 1; + } + + printf("Report written to scsi 0:1 \"%s\"\n", filename); + } + + return 0; +} + static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -51,6 +100,15 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc, void *buf, *start; int ret, i; + if (!strcmp(op, "report")) { + if (argc == 2) + return report(NULL, NULL, NULL); + else if (argc == 5) + return report(argv[2], argv[3], argv[4]); + else + return CMD_RET_USAGE; + } + argc -= 2 + confirmed; argv += 2 + confirmed; @@ -189,5 +247,6 @@ U_BOOT_CMD( "fuse prog [-y] [...] - program 1 or\n" " several fuse words, starting at 'word' (PERMANENT)\n" "fuse override [...] - override 1 or\n" - " several fuse words, starting at 'word'" + " several fuse words, starting at 'word'\n" + "fuse report [ ] - read all fuses and generate report" );