From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Babic Date: Tue, 21 Aug 2012 10:11:13 +0200 Subject: [U-Boot] [PATCH 3/5] Add fuse API and commands In-Reply-To: <1038235395.2398352.1344948755663.JavaMail.root@advansee.com> References: <1038235395.2398352.1344948755663.JavaMail.root@advansee.com> Message-ID: <503342A1.1040904@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 14/08/2012 14:52, Beno?t Th?baudeau wrote: > 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 > --- CC to Anatolji, he knows very well the MPC5121 that has currently support of fuses. > {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 Agree in this split: we have a general fuse command and each SOC / SOC family can add its own implementation. > +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); Each command sends this output to the console. I am thinking about if instead of printf() we shoud use debug() > +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'" > +); General question: why do we need the "bit" interface ? I have thought it is enough the read row / prog row interface (even if there is a bit programming). Best regards, Stefano Babic -- ===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================