1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2009-2013 ADVANSEE
4 * Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
6 * Based on the mpc512x iim code:
7 * Copyright 2008 Silicon Turnkey Express, Inc.
8 * Martha Marx <mmarx@silicontkx.com>
16 #include <linux/errno.h>
18 static int strtou32(const char *str, unsigned int base, u32 *result)
22 *result = simple_strtoul(str, &ep, base);
23 if (ep == str || *ep != '\0')
29 static int confirm_prog(void)
31 puts("Warning: Programming fuses is an irreversible operation!\n"
32 " This may brick your system.\n"
33 " Use this command only if you are sure of "
34 "what you are doing!\n"
35 "\nReally perform this fuse programming? <y/N>\n");
40 puts("Fuse programming aborted\n");
44 static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc,
47 const char *op = argc >= 2 ? argv[1] : NULL;
48 int confirmed = argc >= 3 && !strcmp(argv[2], "-y");
49 u32 bank, word, cnt, val, cmp;
54 argc -= 2 + confirmed;
55 argv += 2 + confirmed;
57 if (argc < 2 || strtou32(argv[0], 0, &bank) ||
58 strtou32(argv[1], 0, &word))
61 if (!strcmp(op, "read")) {
64 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
67 printf("Reading bank %u:\n", bank);
68 for (i = 0; i < cnt; i++, word++) {
70 printf("\nWord 0x%.8x:", word);
72 ret = fuse_read(bank, word, &val);
79 } else if (!strcmp(op, "readm")) {
82 else if (argc != 4 || strtou32(argv[3], 0, &cnt))
85 addr = simple_strtoul(argv[2], NULL, 16);
87 start = map_sysmem(addr, 4);
90 printf("Reading bank %u len %u to 0x%lx\n", bank, cnt, addr);
91 for (i = 0; i < cnt; i++, word++) {
92 ret = fuse_read(bank, word, &val);
101 } else if (!strcmp(op, "cmp")) {
102 if (argc != 3 || strtou32(argv[2], 0, &cmp))
103 return CMD_RET_USAGE;
105 printf("Comparing bank %u:\n", bank);
106 printf("\nWord 0x%.8x:", word);
107 printf("\nValue 0x%.8x:", cmp);
109 ret = fuse_read(bank, word, &val);
113 printf("0x%.8x\n", val);
116 return CMD_RET_FAILURE;
119 } else if (!strcmp(op, "sense")) {
122 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
123 return CMD_RET_USAGE;
125 printf("Sensing bank %u:\n", bank);
126 for (i = 0; i < cnt; i++, word++) {
128 printf("\nWord 0x%.8x:", word);
130 ret = fuse_sense(bank, word, &val);
134 printf(" %.8x", val);
137 } else if (!strcmp(op, "prog")) {
139 return CMD_RET_USAGE;
141 for (i = 2; i < argc; i++, word++) {
142 if (strtou32(argv[i], 16, &val))
143 return CMD_RET_USAGE;
145 printf("Programming bank %u word 0x%.8x to 0x%.8x...\n",
147 if (!confirmed && !confirm_prog())
148 return CMD_RET_FAILURE;
149 ret = fuse_prog(bank, word, val);
153 } else if (!strcmp(op, "override")) {
155 return CMD_RET_USAGE;
157 for (i = 2; i < argc; i++, word++) {
158 if (strtou32(argv[i], 16, &val))
159 return CMD_RET_USAGE;
161 printf("Overriding bank %u word 0x%.8x with "
162 "0x%.8x...\n", bank, word, val);
163 ret = fuse_override(bank, word, val);
168 return CMD_RET_USAGE;
175 return CMD_RET_FAILURE;
179 fuse, CONFIG_SYS_MAXARGS, 0, do_fuse,
181 "read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
182 " starting at 'word'\n"
183 "fuse cmp <bank> <word> <hexval> - compare 'hexval' to fuse\n"
185 "fuse readm <bank> <word> <addr> [<cnt>] - read 1 or 'cnt' fuse words,\n"
186 " starting at 'word' into memory at 'addr'\n"
187 "fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
188 " starting at 'word'\n"
189 "fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
190 " several fuse words, starting at 'word' (PERMANENT)\n"
191 "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n"
192 " several fuse words, starting at 'word'"