From: "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/5] Add fuse API and commands
Date: Tue, 14 Aug 2012 14:52:35 +0200 (CEST) [thread overview]
Message-ID: <1038235395.2398352.1344948755663.JavaMail.root@advansee.com> (raw)
In-Reply-To: <1047085507.2398341.1344948708040.JavaMail.root@advansee.com>
This can be useful for fuse-like hardware, OTP SoC options, etc.
Signed-off-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Stefano Babic <sbabic@denx.de>
---
{u-boot-4d3c95f.orig => u-boot-4d3c95f}/README | 1 +
.../common/Makefile | 1 +
/dev/null => u-boot-4d3c95f/common/cmd_fuse.c | 182 ++++++++++++++++++++
.../include/config_cmd_all.h | 1 +
/dev/null => u-boot-4d3c95f/include/fuse.h | 49 ++++++
5 files changed, 234 insertions(+)
create mode 100644 u-boot-4d3c95f/common/cmd_fuse.c
create mode 100644 u-boot-4d3c95f/include/fuse.h
diff --git u-boot-4d3c95f.orig/README u-boot-4d3c95f/README
index fb9d904..c40fd34 100644
--- u-boot-4d3c95f.orig/README
+++ u-boot-4d3c95f/README
@@ -780,6 +780,7 @@ The following options need to be configured:
CONFIG_CMD_FDOS * Dos diskette Support
CONFIG_CMD_FLASH flinfo, erase, protect
CONFIG_CMD_FPGA FPGA device initialization support
+ CONFIG_CMD_FUSE Device fuse support
CONFIG_CMD_GO * the 'go' command (exec code)
CONFIG_CMD_GREPENV * search environment
CONFIG_CMD_HWFLOW * RTS/CTS hw flow control
diff --git u-boot-4d3c95f.orig/common/Makefile u-boot-4d3c95f/common/Makefile
index 3d62775..44ef757 100644
--- u-boot-4d3c95f.orig/common/Makefile
+++ u-boot-4d3c95f/common/Makefile
@@ -96,6 +96,7 @@ COBJS-$(CONFIG_CMD_FLASH) += cmd_flash.o
ifdef CONFIG_FPGA
COBJS-$(CONFIG_CMD_FPGA) += cmd_fpga.o
endif
+COBJS-$(CONFIG_CMD_FUSE) += cmd_fuse.o
COBJS-$(CONFIG_CMD_GPIO) += cmd_gpio.o
COBJS-$(CONFIG_CMD_I2C) += cmd_i2c.o
COBJS-$(CONFIG_CMD_IDE) += cmd_ide.o
diff --git u-boot-4d3c95f/common/cmd_fuse.c u-boot-4d3c95f/common/cmd_fuse.c
new file mode 100644
index 0000000..fd54d40
--- /dev/null
+++ u-boot-4d3c95f/common/cmd_fuse.c
@@ -0,0 +1,182 @@
+/*
+ * (C) Copyright 2009-2012 ADVANSEE
+ * Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
+ *
+ * Based on the mpc512x iim code:
+ * Copyright 2008 Silicon Turnkey Express, Inc.
+ * Martha Marx <mmarx@silicontkx.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fuse.h>
+#include <asm/errno.h>
+
+static int strtou32(const char *str, unsigned int base, u32 *result)
+{
+ char *ep;
+
+ *result = simple_strtoul(str, &ep, base);
+ if (ep == str || *ep != '\0')
+ return -EINVAL;
+
+ return 0;
+}
+
+static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+ u32 bank, row, bit, cnt, val;
+ int ret, i;
+
+ if (argc < 4 || strtou32(argv[2], 0, &bank) ||
+ strtou32(argv[3], 0, &row))
+ return CMD_RET_USAGE;
+
+ if (!strcmp(argv[1], "read.bit")) {
+ if (argc != 5 || strtou32(argv[4], 0, &bit))
+ return CMD_RET_USAGE;
+
+ printf("Reading bank %u row 0x%.8x bit %u: ", bank, row, bit);
+ ret = fuse_read_bit(bank, row, bit, &val);
+ if (ret)
+ goto err;
+
+ printf("%u\n", val);
+ } else if (!strcmp(argv[1], "read.row")) {
+ if (argc == 4)
+ cnt = 1;
+ else if (argc != 5 || strtou32(argv[4], 0, &cnt))
+ return CMD_RET_USAGE;
+
+ printf("Reading bank %u:\n", bank);
+ for (i = 0; i < cnt; i++, row++) {
+ if (!(i % 4))
+ printf("\nRow 0x%.8x:", row);
+
+ ret = fuse_read_row(bank, row, &val);
+ if (ret)
+ goto err;
+
+ printf(" %.8x", val);
+ }
+ putc('\n');
+ } else if (!strcmp(argv[1], "sense.bit")) {
+ if (argc != 5 || strtou32(argv[4], 0, &bit))
+ return CMD_RET_USAGE;
+
+ printf("Sensing bank %u row 0x%.8x bit %u: ", bank, row, bit);
+ ret = fuse_sense_bit(bank, row, bit, &val);
+ if (ret)
+ goto err;
+
+ printf("%u\n", val);
+ } else if (!strcmp(argv[1], "sense.row")) {
+ if (argc == 4)
+ cnt = 1;
+ else if (argc != 5 || strtou32(argv[4], 0, &cnt))
+ return CMD_RET_USAGE;
+
+ printf("Sensing bank %u:\n", bank);
+ for (i = 0; i < cnt; i++, row++) {
+ if (!(i % 4))
+ printf("\nRow 0x%.8x:", row);
+
+ ret = fuse_sense_row(bank, row, &val);
+ if (ret)
+ goto err;
+
+ printf(" %.8x", val);
+ }
+ putc('\n');
+ } else if (!strcmp(argv[1], "prog.bit")) {
+ if (argc != 5 || strtou32(argv[4], 0, &bit))
+ return CMD_RET_USAGE;
+
+ printf("Programming bank %u row 0x%.8x bit %u...\n",
+ bank, row, bit);
+ ret = fuse_prog_bit(bank, row, bit);
+ if (ret)
+ goto err;
+ } else if (!strcmp(argv[1], "prog.row")) {
+ if (argc < 5)
+ return CMD_RET_USAGE;
+
+ for (i = 4; i < argc; i++, row++) {
+ if (strtou32(argv[i], 16, &val))
+ return CMD_RET_USAGE;
+
+ printf("Programming bank %u row 0x%.8x to 0x%.8x...\n",
+ bank, row, val);
+ ret = fuse_prog_row(bank, row, val);
+ if (ret)
+ goto err;
+ }
+ } else if (!strcmp(argv[1], "ovride.bit")) {
+ if (argc != 6 || strtou32(argv[4], 0, &bit) ||
+ strtou32(argv[5], 0, &val) || val > 1)
+ return CMD_RET_USAGE;
+
+ printf("Overriding bank %u row 0x%.8x bit %u with %u...\n",
+ bank, row, bit, val);
+ ret = fuse_override_bit(bank, row, bit, val);
+ if (ret)
+ goto err;
+ } else if (!strcmp(argv[1], "ovride.row")) {
+ if (argc < 5)
+ return CMD_RET_USAGE;
+
+ for (i = 4; i < argc; i++, row++) {
+ if (strtou32(argv[i], 16, &val))
+ return CMD_RET_USAGE;
+
+ printf("Overriding bank %u row 0x%.8x with 0x%.8x...\n",
+ bank, row, val);
+ ret = fuse_override_row(bank, row, val);
+ if (ret)
+ goto err;
+ }
+ } else {
+ return CMD_RET_USAGE;
+ }
+
+ return 0;
+
+err:
+ puts("ERROR\n");
+ return ret;
+}
+
+U_BOOT_CMD(
+ fuse, CONFIG_SYS_MAXARGS, 0, do_fuse,
+ "Fuse sub-system",
+ "read.bit <bank> <row> <bit> - read a fuse bit\n"
+ "fuse read.row <bank> <row> [<cnt>] - read 1 or 'cnt' fuse rows,\n"
+ " starting at 'row'\n"
+ "fuse sense.bit <bank> <row> <bit> - sense a fuse bit\n"
+ "fuse sense.row <bank> <row> [<cnt>] - sense 1 or 'cnt' fuse rows,\n"
+ " starting at 'row'\n"
+ "fuse prog.bit <bank> <row> <bit> - program a fuse bit (PERMANENT)\n"
+ "fuse prog.row <bank> <row> <hexval> [<hexval>...] - program 1 or\n"
+ " several fuse rows, starting at 'row' (PERMANENT)\n"
+ "fuse ovride.bit <bank> <row> <bit> <val> - override a fuse bit\n"
+ "fuse ovride.row <bank> <row> <hexval> [<hexval>...] - override 1 or\n"
+ " several fuse rows, starting at 'row'"
+);
diff --git u-boot-4d3c95f.orig/include/config_cmd_all.h u-boot-4d3c95f/include/config_cmd_all.h
index f434cd0..8f7d9ae 100644
--- u-boot-4d3c95f.orig/include/config_cmd_all.h
+++ u-boot-4d3c95f/include/config_cmd_all.h
@@ -40,6 +40,7 @@
#define CONFIG_CMD_FDOS /* Floppy DOS support */
#define CONFIG_CMD_FLASH /* flinfo, erase, protect */
#define CONFIG_CMD_FPGA /* FPGA configuration Support */
+#define CONFIG_CMD_FUSE /* Device fuse support */
#define CONFIG_CMD_HWFLOW /* RTS/CTS hw flow control */
#define CONFIG_CMD_I2C /* I2C serial bus support */
#define CONFIG_CMD_IDE /* IDE harddisk support */
diff --git u-boot-4d3c95f/include/fuse.h u-boot-4d3c95f/include/fuse.h
new file mode 100644
index 0000000..baefefe
--- /dev/null
+++ u-boot-4d3c95f/include/fuse.h
@@ -0,0 +1,49 @@
+/*
+ * (C) Copyright 2009-2012 ADVANSEE
+ * Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
+ *
+ * Based on the mpc512x iim code:
+ * Copyright 2008 Silicon Turnkey Express, Inc.
+ * Martha Marx <mmarx@silicontkx.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _FUSE_H_
+#define _FUSE_H_
+
+/*
+ * Read/Sense/Program/Override interface:
+ * bank: Fuse bank
+ * row: Fuse row within the bank
+ * bit: Fuse bit within the row
+ * val: Value to read/write
+ *
+ * Returns: 0 on success, not 0 on failure
+ */
+int fuse_read_bit(u32 bank, u32 row, u32 bit, u32 *val);
+int fuse_read_row(u32 bank, u32 row, u32 *val);
+int fuse_sense_bit(u32 bank, u32 row, u32 bit, u32 *val);
+int fuse_sense_row(u32 bank, u32 row, u32 *val);
+int fuse_prog_bit(u32 bank, u32 row, u32 bit);
+int fuse_prog_row(u32 bank, u32 row, u32 val);
+int fuse_override_bit(u32 bank, u32 row, u32 bit, u32 val);
+int fuse_override_row(u32 bank, u32 row, u32 val);
+
+#endif /* _FUSE_H_ */
next prev parent reply other threads:[~2012-08-14 12:52 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-14 12:51 [U-Boot] [PATCH 0/5] Make iim support common to mpc and imx Benoît Thébaudeau
2012-08-14 12:52 ` [U-Boot] [PATCH 1/5] imx iim: Homogenize and fix register definitions Benoît Thébaudeau
2012-11-27 13:30 ` [U-Boot] [PATCH v2 " Benoît Thébaudeau
2012-11-27 13:30 ` [U-Boot] [PATCH v2 2/5] imx iim: Add useful fuse definitions Benoît Thébaudeau
2012-11-27 13:31 ` [U-Boot] [PATCH v2 3/5] Add fuse API and commands Benoît Thébaudeau
2012-11-27 13:31 ` [U-Boot] [PATCH v2 4/5] Add fsl_iim driver Benoît Thébaudeau
2012-11-27 13:32 ` [U-Boot] [PATCH v2 5/5] mpc iim: Switch to common fsl_iim Benoît Thébaudeau
2013-03-18 12:07 ` [U-Boot] [PATCH v2 1/5] imx iim: Homogenize and fix register definitions Stefano Babic
2013-03-18 12:08 ` Benoît Thébaudeau
2013-03-18 12:13 ` Benoît Thébaudeau
2012-08-14 12:52 ` [U-Boot] [PATCH 2/5] imx iim: Add useful fuse definitions Benoît Thébaudeau
2012-08-14 12:52 ` Benoît Thébaudeau [this message]
2012-08-21 8:11 ` [U-Boot] [PATCH 3/5] Add fuse API and commands Stefano Babic
2012-08-21 10:14 ` Benoît Thébaudeau
2012-08-22 10:43 ` Dirk Behme
2012-08-22 11:11 ` Benoît Thébaudeau
2012-08-22 16:25 ` Dirk Behme
2012-08-22 16:53 ` Benoît Thébaudeau
2012-08-23 10:31 ` Stefano Babic
2012-08-23 13:23 ` Eric Nelson
2012-11-26 16:03 ` Benoît Thébaudeau
2012-11-27 7:19 ` Dirk Behme
2012-11-27 16:58 ` Eric Nelson
2012-11-27 18:27 ` Benoît Thébaudeau
2012-11-27 18:36 ` Eric Nelson
2012-11-27 19:23 ` Benoît Thébaudeau
2012-11-27 19:54 ` Eric Nelson
2012-12-03 9:03 ` Stefano Babic
2012-12-03 11:25 ` Benoît Thébaudeau
2012-12-03 11:41 ` Stefano Babic
2012-08-14 12:52 ` [U-Boot] [PATCH 4/5] Add fsl_iim driver Benoît Thébaudeau
2012-08-21 8:13 ` Stefano Babic
2012-08-21 12:56 ` Benoît Thébaudeau
2012-08-21 13:41 ` Stefano Babic
2012-08-14 12:53 ` [U-Boot] [PATCH 5/5] mpc iim: Switch to common fsl_iim Benoît Thébaudeau
2012-08-15 14:30 ` Benoît Thébaudeau
2012-08-21 8:15 ` Stefano Babic
2012-11-05 20:05 ` Benoît Thébaudeau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1038235395.2398352.1344948755663.JavaMail.root@advansee.com \
--to=benoit.thebaudeau@advansee.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox