]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_otp.c
2 * cmd_otp.c - interface to Blackfin on-chip One-Time-Programmable memory
4 * Copyright (c) 2007-2008 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
9 /* There are 512 128-bit "pages" (0x000 to 0x1FF).
10 * The pages are accessable as 64-bit "halfpages" (an upper and lower half).
11 * The pages are not part of the memory map. There is an OTP controller which
12 * handles scanning in/out of bits. While access is done through OTP MMRs,
13 * the bootrom provides C-callable helper functions to handle the interaction.
22 #include <asm/blackfin.h>
23 #include <asm/mach-common/bits/otp.h>
25 static const char *otp_strerror(uint32_t err
)
28 case 0: return "no error";
29 case OTP_WRITE_ERROR
: return "OTP fuse write error";
30 case OTP_READ_ERROR
: return "OTP fuse read error";
31 case OTP_ACC_VIO_ERROR
: return "invalid OTP address";
32 case OTP_DATA_MULT_ERROR
: return "multiple bad bits detected";
33 case OTP_ECC_MULT_ERROR
: return "error in ECC bits";
34 case OTP_PREV_WR_ERROR
: return "space already written";
35 case OTP_DATA_SB_WARN
: return "single bad bit in half page";
36 case OTP_ECC_SB_WARN
: return "single bad bit in ECC";
37 default: return "unknown error";
41 #define lowup(x) ((x) % 2 ? "upper" : "lower")
43 int do_otp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
46 if (!strcmp(argv
[1], "--force")) {
53 uint32_t (*otp_func
)(uint32_t page
, uint32_t flags
, uint64_t *page_content
);
54 if (!strcmp(argv
[1], "read"))
56 else if (!strcmp(argv
[1], "write"))
60 printf("Usage:\n%s\n", cmdtp
->usage
);
64 uint64_t *addr
= (uint64_t *)simple_strtoul(argv
[2], NULL
, 16);
65 uint32_t page
= simple_strtoul(argv
[3], NULL
, 16);
71 count
= simple_strtoul(argv
[4], NULL
, 16);
76 half
= simple_strtoul(argv
[5], NULL
, 16);
77 if (half
!= 0 && half
!= 1) {
78 puts("Error: 'half' can only be '0' or '1'\n");
84 /* do to the nature of OTP, make sure users are sure */
85 if (!force
&& otp_func
== otp_write
) {
87 "Writing one time programmable memory\n"
88 "Make sure your operating voltages and temperature are within spec\n"
89 " source address: 0x%p\n"
90 " OTP destination: %s page 0x%03X - %s page 0x%03X\n"
91 " number to write: %ld halfpages\n"
92 " type \"YES\" (no quotes) to confirm: ",
95 lowup(half
+ count
- 1), page
+ (half
+ count
- 1) / 2,
102 const char exp_ans
[] = "YES\r";
105 if (exp_ans
[i
++] != c
) {
106 printf(" Aborting\n");
108 } else if (!exp_ans
[i
]) {
115 /* Only supported in newer silicon ... enable writing */
117 otp_command(OTP_INIT
, ...);
119 *pOTP_TIMING
= 0x32149485;
123 printf("OTP memory %s: addr 0x%08lx page 0x%03X count %ld ... ",
124 argv
[1], addr
, page
, count
);
127 for (i
= half
; i
< count
+ half
; ++i
) {
128 flags
= (i
% 2) ? OTP_UPPER_HALF
: OTP_LOWER_HALF
;
129 ret
= otp_func(page
, flags
, addr
);
141 printf("\nERROR at page 0x%03X (%s-halfpage): 0x%03X: %s\n",
142 page
, lowup(i
), ret
, otp_strerror(ret
));
146 if (otp_func
== otp_write
)
147 /* Only supported in newer silicon ... disable writing */
149 otp_command(OTP_INIT
, ...);
151 *pOTP_TIMING
= 0x1485;
157 U_BOOT_CMD(otp
, 6, 0, do_otp
,
158 "otp - One-Time-Programmable sub-system\n",
159 "read <addr> <page> [count] [half]\n"
160 "otp write [--force] <addr> <page> [count] [half]\n"
161 " - read/write 'count' half-pages starting at page 'page' (offset 'half')\n");