public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Dirk Behme <dirk.behme@de.bosch.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/5] Add fuse API and commands
Date: Wed, 22 Aug 2012 12:43:05 +0200	[thread overview]
Message-ID: <5034B7B9.2020801@de.bosch.com> (raw)
In-Reply-To: <1038235395.2398352.1344948755663.JavaMail.root@advansee.com>

On 14.08.2012 14:52, Beno?t Th?baudeau wrote:
> This can be useful for fuse-like hardware, OTP SoC options, etc.

For i.MX6, I have a port of the OTP support from Freescale's U-Boot to 
our mainline U-Boot in the queue [1].

As I don't have the overview over the various i.MXxx SoCs and don't 
understand much of this patch below: Should this implement the same 
functionality like my patch [1] for i.MX6?

Or shall I send my patch [1] to this mailing list for official review 
because the functionality here and there is orthogonal?

Thanks

Dirk

[1] 
https://github.com/dirkbehme/u-boot-imx6/commit/da718b338a79af160f7b7e542fe97b24edbfc36a

> 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_ */
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot


-- 
======================================================================
Dirk Behme                      Robert Bosch Car Multimedia GmbH
                                 CM-AI/PJ-CF32
Phone: +49 5121 49-3274         Dirk Behme
Fax:   +49 711 811 5053274      PO Box 77 77 77
mailto:dirk.behme at de.bosch.com  D-31132 Hildesheim - Germany

Bosch Group, Car Multimedia (CM)
              Automotive Navigation and Infotainment Systems (AI)
              ProJect - CoreFunctions (PJ-CF)

Robert Bosch Car Multimedia GmbH - Ein Unternehmen der Bosch Gruppe
Sitz: Hildesheim
Registergericht: Amtsgericht Hildesheim HRB 201334
Aufsichtsratsvorsitzender: Volkmar Denner
Gesch?ftsf?hrung: Uwe Thomas, Michael Bolle, Robby Drave, Egbert Hellwig
======================================================================

  parent reply	other threads:[~2012-08-22 10:43 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 ` [U-Boot] [PATCH 3/5] Add fuse API and commands Benoît Thébaudeau
2012-08-21  8:11   ` Stefano Babic
2012-08-21 10:14     ` Benoît Thébaudeau
2012-08-22 10:43   ` Dirk Behme [this message]
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=5034B7B9.2020801@de.bosch.com \
    --to=dirk.behme@de.bosch.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