mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-07-10 21:26:19 +09:00
Blackfin: implement real write support for OTP
Now that real documentation has been released for the OTP interface and the on-chip ROM wrt writing/timings, implement support for reading/writing as well as dumping/locking. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
This commit is contained in:
parent
9372c32148
commit
8b35e3aeff
151
common/cmd_otp.c
151
common/cmd_otp.c
|
@ -6,7 +6,7 @@
|
||||||
* Licensed under the GPL-2 or later.
|
* Licensed under the GPL-2 or later.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* There are 512 128-bit "pages" (0x000 to 0x1FF).
|
/* There are 512 128-bit "pages" (0x000 through 0x1FF).
|
||||||
* The pages are accessable as 64-bit "halfpages" (an upper and lower half).
|
* The pages are accessable as 64-bit "halfpages" (an upper and lower half).
|
||||||
* The pages are not part of the memory map. There is an OTP controller which
|
* The pages are not part of the memory map. There is an OTP controller which
|
||||||
* handles scanning in/out of bits. While access is done through OTP MMRs,
|
* handles scanning in/out of bits. While access is done through OTP MMRs,
|
||||||
|
@ -17,8 +17,6 @@
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
|
|
||||||
#ifdef CONFIG_CMD_OTP
|
|
||||||
|
|
||||||
#include <asm/blackfin.h>
|
#include <asm/blackfin.h>
|
||||||
#include <asm/mach-common/bits/otp.h>
|
#include <asm/mach-common/bits/otp.h>
|
||||||
|
|
||||||
|
@ -40,30 +38,87 @@ static const char *otp_strerror(uint32_t err)
|
||||||
|
|
||||||
#define lowup(x) ((x) % 2 ? "upper" : "lower")
|
#define lowup(x) ((x) % 2 ? "upper" : "lower")
|
||||||
|
|
||||||
int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
static int check_voltage(void)
|
||||||
{
|
{
|
||||||
bool force = false;
|
/* Make sure voltage limits are within datasheet spec */
|
||||||
if (!strcmp(argv[1], "--force")) {
|
uint16_t vr_ctl = bfin_read_VR_CTL();
|
||||||
force = true;
|
|
||||||
argv[1] = argv[0];
|
#ifdef __ADSPBF54x__
|
||||||
argv++;
|
/* 0.9V <= VDDINT <= 1.1V */
|
||||||
--argc;
|
if ((vr_ctl & 0xc) && (vr_ctl & 0xc0) == 0xc0)
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
|
/* for the parts w/out qualification yet */
|
||||||
|
(void)vr_ctl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_otp_timing(bool write)
|
||||||
|
{
|
||||||
|
static uint32_t timing;
|
||||||
|
if (!timing) {
|
||||||
|
uint32_t tp1, tp2, tp3;
|
||||||
|
/* OTP_TP1 = 1000 / sclk_period (in nanoseconds)
|
||||||
|
* OTP_TP1 = 1000 / (1 / get_sclk() * 10^9)
|
||||||
|
* OTP_TP1 = (1000 * get_sclk()) / 10^9
|
||||||
|
* OTP_TP1 = get_sclk() / 10^6
|
||||||
|
*/
|
||||||
|
tp1 = get_sclk() / 1000000;
|
||||||
|
/* OTP_TP2 = 400 / (2 * sclk_period)
|
||||||
|
* OTP_TP2 = 400 / (2 * 1 / get_sclk() * 10^9)
|
||||||
|
* OTP_TP2 = (400 * get_sclk()) / (2 * 10^9)
|
||||||
|
* OTP_TP2 = (2 * get_sclk()) / 10^7
|
||||||
|
*/
|
||||||
|
tp2 = (2 * get_sclk() / 10000000) << 8;
|
||||||
|
/* OTP_TP3 = magic constant */
|
||||||
|
tp3 = (0x1401) << 15;
|
||||||
|
timing = tp1 | tp2 | tp3;
|
||||||
|
}
|
||||||
|
|
||||||
|
bfrom_OtpCommand(OTP_INIT, write ? timing : timing & ~(-1 << 15));
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
uint32_t ret, base_flags;
|
||||||
|
bool prompt_user, force_read;
|
||||||
uint32_t (*otp_func)(uint32_t page, uint32_t flags, uint64_t *page_content);
|
uint32_t (*otp_func)(uint32_t page, uint32_t flags, uint64_t *page_content);
|
||||||
if (!strcmp(argv[1], "read"))
|
|
||||||
otp_func = otp_read;
|
if (argc < 4) {
|
||||||
else if (!strcmp(argv[1], "write"))
|
|
||||||
otp_func = otp_write;
|
|
||||||
else {
|
|
||||||
usage:
|
usage:
|
||||||
cmd_usage(cmdtp);
|
cmd_usage(cmdtp);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prompt_user = false;
|
||||||
|
base_flags = 0;
|
||||||
|
if (!strcmp(argv[1], "read"))
|
||||||
|
otp_func = bfrom_OtpRead;
|
||||||
|
else if (!strcmp(argv[1], "dump")) {
|
||||||
|
otp_func = bfrom_OtpRead;
|
||||||
|
force_read = true;
|
||||||
|
} else if (!strcmp(argv[1], "write")) {
|
||||||
|
otp_func = bfrom_OtpWrite;
|
||||||
|
base_flags = OTP_CHECK_FOR_PREV_WRITE;
|
||||||
|
if (!strcmp(argv[2], "--force")) {
|
||||||
|
argv[2] = argv[1];
|
||||||
|
argv++;
|
||||||
|
--argc;
|
||||||
|
} else
|
||||||
|
prompt_user = false;
|
||||||
|
} else if (!strcmp(argv[1], "lock")) {
|
||||||
|
if (argc != 4)
|
||||||
|
goto usage;
|
||||||
|
otp_func = bfrom_OtpWrite;
|
||||||
|
base_flags = OTP_LOCK;
|
||||||
|
} else
|
||||||
|
goto usage;
|
||||||
|
|
||||||
uint64_t *addr = (uint64_t *)simple_strtoul(argv[2], NULL, 16);
|
uint64_t *addr = (uint64_t *)simple_strtoul(argv[2], NULL, 16);
|
||||||
uint32_t page = simple_strtoul(argv[3], NULL, 16);
|
uint32_t page = simple_strtoul(argv[3], NULL, 16);
|
||||||
uint32_t flags, ret;
|
uint32_t flags;
|
||||||
size_t i, count;
|
size_t i, count;
|
||||||
ulong half;
|
ulong half;
|
||||||
|
|
||||||
|
@ -81,8 +136,15 @@ int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||||
} else
|
} else
|
||||||
half = 0;
|
half = 0;
|
||||||
|
|
||||||
|
/* "otp lock" has slightly different semantics */
|
||||||
|
if (base_flags & OTP_LOCK) {
|
||||||
|
count = page;
|
||||||
|
page = (uint32_t)addr;
|
||||||
|
addr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* do to the nature of OTP, make sure users are sure */
|
/* do to the nature of OTP, make sure users are sure */
|
||||||
if (!force && otp_func == otp_write) {
|
if (prompt_user) {
|
||||||
printf(
|
printf(
|
||||||
"Writing one time programmable memory\n"
|
"Writing one time programmable memory\n"
|
||||||
"Make sure your operating voltages and temperature are within spec\n"
|
"Make sure your operating voltages and temperature are within spec\n"
|
||||||
|
@ -111,31 +173,43 @@ int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only supported in newer silicon ... enable writing */
|
|
||||||
#if (0)
|
|
||||||
otp_command(OTP_INIT, ...);
|
|
||||||
#else
|
|
||||||
*pOTP_TIMING = 0x32149485;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("OTP memory %s: addr 0x%08lx page 0x%03X count %ld ... ",
|
printf("OTP memory %s: addr 0x%08lx page 0x%03X count %ld ... ",
|
||||||
argv[1], addr, page, count);
|
argv[1], addr, page, count);
|
||||||
|
|
||||||
|
set_otp_timing(otp_func == bfrom_OtpWrite);
|
||||||
|
if (otp_func == bfrom_OtpWrite && check_voltage()) {
|
||||||
|
puts("ERROR: VDDINT voltage is out of spec for writing\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do the actual reading/writing stuff */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (i = half; i < count + half; ++i) {
|
for (i = half; i < count + half; ++i) {
|
||||||
flags = (i % 2) ? OTP_UPPER_HALF : OTP_LOWER_HALF;
|
flags = base_flags | (i % 2 ? OTP_UPPER_HALF : OTP_LOWER_HALF);
|
||||||
|
try_again:
|
||||||
ret = otp_func(page, flags, addr);
|
ret = otp_func(page, flags, addr);
|
||||||
if (ret & 0x1)
|
if (ret & OTP_MASTER_ERROR) {
|
||||||
|
if (force_read) {
|
||||||
|
if (flags & OTP_NO_ECC)
|
||||||
break;
|
break;
|
||||||
else if (ret)
|
else
|
||||||
|
flags |= OTP_NO_ECC;
|
||||||
|
puts("E");
|
||||||
|
goto try_again;
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
} else if (ret)
|
||||||
puts("W");
|
puts("W");
|
||||||
else
|
else
|
||||||
puts(".");
|
puts(".");
|
||||||
|
if (!(base_flags & OTP_LOCK)) {
|
||||||
++addr;
|
++addr;
|
||||||
if (i % 2)
|
if (i % 2)
|
||||||
++page;
|
++page;
|
||||||
|
} else
|
||||||
|
++page;
|
||||||
}
|
}
|
||||||
if (ret & 0x1)
|
if (ret & 0x1)
|
||||||
printf("\nERROR at page 0x%03X (%s-halfpage): 0x%03X: %s\n",
|
printf("\nERROR at page 0x%03X (%s-halfpage): 0x%03X: %s\n",
|
||||||
|
@ -143,21 +217,20 @@ int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||||
else
|
else
|
||||||
puts(" done\n");
|
puts(" done\n");
|
||||||
|
|
||||||
if (otp_func == otp_write)
|
/* Make sure we disable writing */
|
||||||
/* Only supported in newer silicon ... disable writing */
|
set_otp_timing(false);
|
||||||
#if (0)
|
bfrom_OtpCommand(OTP_CLOSE, 0);
|
||||||
otp_command(OTP_INIT, ...);
|
|
||||||
#else
|
|
||||||
*pOTP_TIMING = 0x1485;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
U_BOOT_CMD(otp, 6, 0, do_otp,
|
U_BOOT_CMD(otp, 7, 0, do_otp,
|
||||||
"One-Time-Programmable sub-system",
|
"One-Time-Programmable sub-system\n",
|
||||||
"read <addr> <page> [count] [half]\n"
|
"read <addr> <page> [count] [half]\n"
|
||||||
|
" - read 'count' half-pages starting at 'page' (offset 'half') to 'addr'\n"
|
||||||
|
"otp dump <addr> <page> [count] [half]\n"
|
||||||
|
" - like 'otp read', but skip read errors\n"
|
||||||
"otp write [--force] <addr> <page> [count] [half]\n"
|
"otp write [--force] <addr> <page> [count] [half]\n"
|
||||||
" - read/write 'count' half-pages starting at page 'page' (offset 'half')\n");
|
" - write 'count' half-pages starting at 'page' (offset 'half') from 'addr'\n"
|
||||||
|
"otp lock <page> <count>\n"
|
||||||
#endif
|
" - lock 'count' pages starting at 'page'\n");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user