]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cmd/fuse.c
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+
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(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
46 const char *op
= argc
>= 2 ? argv
[1] : NULL
;
47 int confirmed
= argc
>= 3 && !strcmp(argv
[2], "-y");
48 u32 bank
, word
, cnt
, val
;
51 argc
-= 2 + confirmed
;
52 argv
+= 2 + confirmed
;
54 if (argc
< 2 || strtou32(argv
[0], 0, &bank
) ||
55 strtou32(argv
[1], 0, &word
))
58 if (!strcmp(op
, "read")) {
61 else if (argc
!= 3 || strtou32(argv
[2], 0, &cnt
))
64 printf("Reading bank %u:\n", bank
);
65 for (i
= 0; i
< cnt
; i
++, word
++) {
67 printf("\nWord 0x%.8x:", word
);
69 ret
= fuse_read(bank
, word
, &val
);
76 } else if (!strcmp(op
, "sense")) {
79 else if (argc
!= 3 || strtou32(argv
[2], 0, &cnt
))
82 printf("Sensing bank %u:\n", bank
);
83 for (i
= 0; i
< cnt
; i
++, word
++) {
85 printf("\nWord 0x%.8x:", word
);
87 ret
= fuse_sense(bank
, word
, &val
);
94 } else if (!strcmp(op
, "prog")) {
98 for (i
= 2; i
< argc
; i
++, word
++) {
99 if (strtou32(argv
[i
], 16, &val
))
100 return CMD_RET_USAGE
;
102 printf("Programming bank %u word 0x%.8x to 0x%.8x...\n",
104 if (!confirmed
&& !confirm_prog())
105 return CMD_RET_FAILURE
;
106 ret
= fuse_prog(bank
, word
, val
);
110 } else if (!strcmp(op
, "override")) {
112 return CMD_RET_USAGE
;
114 for (i
= 2; i
< argc
; i
++, word
++) {
115 if (strtou32(argv
[i
], 16, &val
))
116 return CMD_RET_USAGE
;
118 printf("Overriding bank %u word 0x%.8x with "
119 "0x%.8x...\n", bank
, word
, val
);
120 ret
= fuse_override(bank
, word
, val
);
125 return CMD_RET_USAGE
;
132 return CMD_RET_FAILURE
;
136 fuse
, CONFIG_SYS_MAXARGS
, 0, do_fuse
,
138 "read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
139 " starting at 'word'\n"
140 "fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
141 " starting at 'word'\n"
142 "fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
143 " several fuse words, starting at 'word' (PERMANENT)\n"
144 "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n"
145 " several fuse words, starting at 'word'"