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");
39 puts("Fuse programming aborted\n");
43 static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
45 const char *op = argc >= 2 ? argv[1] : NULL;
46 int confirmed = argc >= 3 && !strcmp(argv[2], "-y");
47 u32 bank, word, cnt, val;
50 argc -= 2 + confirmed;
51 argv += 2 + confirmed;
53 if (argc < 2 || strtou32(argv[0], 0, &bank) ||
54 strtou32(argv[1], 0, &word))
57 if (!strcmp(op, "read")) {
60 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
63 printf("Reading bank %u:\n", bank);
64 for (i = 0; i < cnt; i++, word++) {
66 printf("\nWord 0x%.8x:", word);
68 ret = fuse_read(bank, word, &val);
75 } else if (!strcmp(op, "sense")) {
78 else if (argc != 3 || strtou32(argv[2], 0, &cnt))
81 printf("Sensing bank %u:\n", bank);
82 for (i = 0; i < cnt; i++, word++) {
84 printf("\nWord 0x%.8x:", word);
86 ret = fuse_sense(bank, word, &val);
93 } else if (!strcmp(op, "prog")) {
97 for (i = 2; i < argc; i++, word++) {
98 if (strtou32(argv[i], 16, &val))
101 printf("Programming bank %u word 0x%.8x to 0x%.8x...\n",
103 if (!confirmed && !confirm_prog())
104 return CMD_RET_FAILURE;
105 ret = fuse_prog(bank, word, val);
109 } else if (!strcmp(op, "override")) {
111 return CMD_RET_USAGE;
113 for (i = 2; i < argc; i++, word++) {
114 if (strtou32(argv[i], 16, &val))
115 return CMD_RET_USAGE;
117 printf("Overriding bank %u word 0x%.8x with "
118 "0x%.8x...\n", bank, word, val);
119 ret = fuse_override(bank, word, val);
124 return CMD_RET_USAGE;
135 fuse, CONFIG_SYS_MAXARGS, 0, do_fuse,
137 "read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
138 " starting at 'word'\n"
139 "fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
140 " starting at 'word'\n"
141 "fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
142 " several fuse words, starting at 'word' (PERMANENT)\n"
143 "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n"
144 " several fuse words, starting at 'word'"