From patchwork Tue Aug 14 12:52:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Th=C3=A9baudeau?= X-Patchwork-Id: 177244 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 646812C0080 for ; Tue, 14 Aug 2012 22:47:23 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1BF702812D; Tue, 14 Aug 2012 14:47:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jZi5Xi6k87KU; Tue, 14 Aug 2012 14:47:21 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DA60528117; Tue, 14 Aug 2012 14:47:18 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EC91B2811E for ; Tue, 14 Aug 2012 14:47:16 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jHQI6Cu3UGKN for ; Tue, 14 Aug 2012 14:47:16 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from zose-mta15.web4all.fr (zose-mta15.web4all.fr [176.31.217.11]) by theia.denx.de (Postfix) with ESMTP id 5F46D28115 for ; Tue, 14 Aug 2012 14:47:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zose-mta15.web4all.fr (Postfix) with ESMTP id 4C12A2D2CB; Tue, 14 Aug 2012 14:49:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at zose1.web4all.fr Received: from zose-mta15.web4all.fr ([127.0.0.1]) by localhost (zose-mta15.web4all.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3VcWBSPdbzlJ; Tue, 14 Aug 2012 14:49:56 +0200 (CEST) Received: from zose-store12.web4all.fr (zose-store-12.w4a.fr [178.33.204.48]) by zose-mta15.web4all.fr (Postfix) with ESMTP id 5EF062C373; Tue, 14 Aug 2012 14:49:56 +0200 (CEST) Date: Tue, 14 Aug 2012 14:52:35 +0200 (CEST) From: =?utf-8?Q?Beno=C3=AEt_Th=C3=A9baudeau?= To: U-Boot-Users ML Message-ID: <1038235395.2398352.1344948755663.JavaMail.root@advansee.com> In-Reply-To: <1047085507.2398341.1344948708040.JavaMail.root@advansee.com> MIME-Version: 1.0 X-Originating-IP: [88.188.188.98] X-Mailer: Zimbra 7.2.0_GA_2669 (ZimbraWebClient - FF3.0 (Win)/7.2.0_GA_2669) Subject: [U-Boot] [PATCH 3/5] Add fuse API and commands X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This can be useful for fuse-like hardware, OTP SoC options, etc. Signed-off-by: Benoît Thébaudeau Cc: Wolfgang Denk Cc: Stefano Babic --- {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 + * + * Based on the mpc512x iim code: + * Copyright 2008 Silicon Turnkey Express, Inc. + * Martha Marx + * + * 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 +#include +#include +#include + +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 - read a fuse bit\n" + "fuse read.row [] - read 1 or 'cnt' fuse rows,\n" + " starting at 'row'\n" + "fuse sense.bit - sense a fuse bit\n" + "fuse sense.row [] - sense 1 or 'cnt' fuse rows,\n" + " starting at 'row'\n" + "fuse prog.bit - program a fuse bit (PERMANENT)\n" + "fuse prog.row [...] - program 1 or\n" + " several fuse rows, starting at 'row' (PERMANENT)\n" + "fuse ovride.bit - override a fuse bit\n" + "fuse ovride.row [...] - 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 + * + * Based on the mpc512x iim code: + * Copyright 2008 Silicon Turnkey Express, Inc. + * Martha Marx + * + * 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_ */