2 * (C) Copyright 2009-2013 ADVANSEE
3 * Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
5 * Based on the mpc512x iim code:
6 * Copyright 2008 Silicon Turnkey Express, Inc.
7 * Martha Marx <mmarx@silicontkx.com>
9 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm/errno.h>
17 static int strtou32(const char *str, unsigned int base, u32 *result)
21 *result = simple_strtoul(str, &ep, base);
22 if (ep == str || *ep != '\0')
28 static int confirm_prog(void)
30 puts("Warning: Programming fuses is an irreversible operation!\n"
31 " This may brick your system.\n"
32 " Use this command only if you are sure of "
33 "what you are doing!\n"
34 "\nReally perform this fuse programming? <y/N>\n");
46 puts("Fuse programming aborted\n");
50 static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
52 const char *op = argc >= 2 ? argv[1] : NULL;
53 int confirmed = argc >= 3 && !strcmp(argv[2], "-y");
54 u32 bank, word, cnt, val;
57 argc -= 2 + confirmed;
58 argv += 2 + confirmed;
60 if (argc < 2 || strtou32(argv[0], 0, &bank) ||
61 strtou32(argv[1], 0, &word))
64 if (!strcmp(op, "read")) {
67 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
70 printf("Reading bank %u:\n", bank);
71 for (i = 0; i < cnt; i++, word++) {
73 printf("\nWord 0x%.8x:", word);
75 ret = fuse_read(bank, word, &val);
82 } else if (!strcmp(op, "sense")) {
85 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
88 printf("Sensing bank %u:\n", bank);
89 for (i = 0; i < cnt; i++, word++) {
91 printf("\nWord 0x%.8x:", word);
93 ret = fuse_sense(bank, word, &val);
100 } else if (!strcmp(op, "prog")) {
102 return CMD_RET_USAGE;
104 for (i = 2; i < argc; i++, word++) {
105 if (strtou32(argv[i], 16, &val))
106 return CMD_RET_USAGE;
108 printf("Programming bank %u word 0x%.8x to 0x%.8x...\n",
110 if (!confirmed && !confirm_prog())
111 return CMD_RET_FAILURE;
112 ret = fuse_prog(bank, word, val);
116 } else if (!strcmp(op, "override")) {
118 return CMD_RET_USAGE;
120 for (i = 2; i < argc; i++, word++) {
121 if (strtou32(argv[i], 16, &val))
122 return CMD_RET_USAGE;
124 printf("Overriding bank %u word 0x%.8x with "
125 "0x%.8x...\n", bank, word, val);
126 ret = fuse_override(bank, word, val);
131 return CMD_RET_USAGE;
142 fuse, CONFIG_SYS_MAXARGS, 0, do_fuse,
144 "read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
145 " starting at 'word'\n"
146 "fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
147 " starting at 'word'\n"
148 "fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
149 " several fuse words, starting at 'word' (PERMANENT)\n"
150 "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n"
151 " several fuse words, starting at 'word'"