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 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include <asm/errno.h>
33 static int strtou32(const char *str, unsigned int base, u32 *result)
37 *result = simple_strtoul(str, &ep, base);
38 if (ep == str || *ep != '\0')
44 static int confirm_prog(void)
46 puts("Warning: Programming fuses is an irreversible operation!\n"
47 " This may brick your system.\n"
48 " Use this command only if you are sure of "
49 "what you are doing!\n"
50 "\nReally perform this fuse programming? <y/N>\n");
62 puts("Fuse programming aborted\n");
66 static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
68 const char *op = argc >= 2 ? argv[1] : NULL;
69 int confirmed = argc >= 3 && !strcmp(argv[2], "-y");
70 u32 bank, word, cnt, val;
73 argc -= 2 + confirmed;
74 argv += 2 + confirmed;
76 if (argc < 2 || strtou32(argv[0], 0, &bank) ||
77 strtou32(argv[1], 0, &word))
80 if (!strcmp(op, "read")) {
83 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
86 printf("Reading bank %u:\n", bank);
87 for (i = 0; i < cnt; i++, word++) {
89 printf("\nWord 0x%.8x:", word);
91 ret = fuse_read(bank, word, &val);
98 } else if (!strcmp(op, "sense")) {
101 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
102 return CMD_RET_USAGE;
104 printf("Sensing bank %u:\n", bank);
105 for (i = 0; i < cnt; i++, word++) {
107 printf("\nWord 0x%.8x:", word);
109 ret = fuse_sense(bank, word, &val);
113 printf(" %.8x", val);
116 } else if (!strcmp(op, "prog")) {
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("Programming bank %u word 0x%.8x to 0x%.8x...\n",
126 if (!confirmed && !confirm_prog())
127 return CMD_RET_FAILURE;
128 ret = fuse_prog(bank, word, val);
132 } else if (!strcmp(op, "override")) {
134 return CMD_RET_USAGE;
136 for (i = 2; i < argc; i++, word++) {
137 if (strtou32(argv[i], 16, &val))
138 return CMD_RET_USAGE;
140 printf("Overriding bank %u word 0x%.8x with "
141 "0x%.8x...\n", bank, word, val);
142 ret = fuse_override(bank, word, val);
147 return CMD_RET_USAGE;
158 fuse, CONFIG_SYS_MAXARGS, 0, do_fuse,
160 "read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
161 " starting at 'word'\n"
162 "fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
163 " starting at 'word'\n"
164 "fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
165 " several fuse words, starting at 'word' (PERMANENT)\n"
166 "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n"
167 " several fuse words, starting at 'word'"