From: Michael Olbrich <m.olbrich@pengutronix.de>
To: ptxdist@pengutronix.de
Subject: Re: [ptxdist] [PATCH v2] mtd-utils: allow building and installing of flash_otp_{lock, write}
Date: Mon, 4 Mar 2013 18:06:22 +0100 [thread overview]
Message-ID: <20130304170622.GZ5360@pengutronix.de> (raw)
In-Reply-To: <1362058793-27151-1-git-send-email-u.kleine-koenig@pengutronix.de>
On Thu, Feb 28, 2013 at 02:39:53PM +0100, Uwe Kleine-König wrote:
> Also fix a few flaws in flash_otp that are only relevant for writing to
> NAND chips.
>
tnx, applied
Michael
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> changes since (implicit) v1:
> - add a S-o-b line
> - two more patches for flash_otp_write
>
> Thanks
> Uwe
>
> ...flash_otp_write-fix-format-string-warning.patch | 30 ++++++++++
> ...rite-fix-writing-to-NAND-in-presence-of-p.patch | 61 ++++++++++++++++++++
> ...rite-fix-a-buffer-overflow-on-NAND-with-w.patch | 35 +++++++++++
> ...so-build-and-install-flash_otp_lock-and-f.patch | 42 ++++++++++++++
> patches/mtd-utils-1.5.0/series | 6 +-
> rules/mtd-utils.in | 12 ++++
> rules/mtd-utils.make | 8 +++
> 7 files changed, 193 insertions(+), 1 deletion(-)
> create mode 100644 patches/mtd-utils-1.5.0/0003-flash_otp_write-fix-format-string-warning.patch
> create mode 100644 patches/mtd-utils-1.5.0/0004-flash_otp_write-fix-writing-to-NAND-in-presence-of-p.patch
> create mode 100644 patches/mtd-utils-1.5.0/0005-flash_otp_write-fix-a-buffer-overflow-on-NAND-with-w.patch
> create mode 100644 patches/mtd-utils-1.5.0/0006-Makefile-also-build-and-install-flash_otp_lock-and-f.patch
>
> diff --git a/patches/mtd-utils-1.5.0/0003-flash_otp_write-fix-format-string-warning.patch b/patches/mtd-utils-1.5.0/0003-flash_otp_write-fix-format-string-warning.patch
> new file mode 100644
> index 0000000..ae49c4e
> --- /dev/null
> +++ b/patches/mtd-utils-1.5.0/0003-flash_otp_write-fix-format-string-warning.patch
> @@ -0,0 +1,30 @@
> +From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
> +Date: Wed, 20 Feb 2013 17:25:30 +0100
> +Subject: [PATCH] flash_otp_write: fix format string warning
> +MIME-Version: 1.0
> +Content-Type: text/plain; charset=UTF-8
> +Content-Transfer-Encoding: 8bit
> +
> +This fixes
> + flash_otp_write.c: In function 'main':
> + flash_otp_write.c:61:2: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'off_t' [-Wformat]
> +
> +Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> +Forwarded: id:1361378469-18631-1-git-send-email-u.kleine-koenig@pengutronix.de
> +---
> + flash_otp_write.c | 2 +-
> + 1 file changed, 1 insertion(+), 1 deletion(-)
> +
> +diff --git a/flash_otp_write.c b/flash_otp_write.c
> +index d407ebb..41cf1c5 100644
> +--- a/flash_otp_write.c
> ++++ b/flash_otp_write.c
> +@@ -58,7 +58,7 @@ int main(int argc,char *argv[])
> + return errno;
> + }
> +
> +- printf("Writing OTP user data on %s at offset 0x%lx\n", argv[2], offset);
> ++ printf("Writing OTP user data on %s at offset 0x%lx\n", argv[2], (unsigned long)offset);
> +
> + if (mtdInfo.type == MTD_NANDFLASH)
> + len = mtdInfo.writesize;
> diff --git a/patches/mtd-utils-1.5.0/0004-flash_otp_write-fix-writing-to-NAND-in-presence-of-p.patch b/patches/mtd-utils-1.5.0/0004-flash_otp_write-fix-writing-to-NAND-in-presence-of-p.patch
> new file mode 100644
> index 0000000..f6c2aac
> --- /dev/null
> +++ b/patches/mtd-utils-1.5.0/0004-flash_otp_write-fix-writing-to-NAND-in-presence-of-p.patch
> @@ -0,0 +1,61 @@
> +From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
> +Date: Wed, 27 Feb 2013 17:49:06 +0100
> +Subject: [PATCH] flash_otp_write: fix writing to NAND in presence of partial
> + reads
> +MIME-Version: 1.0
> +Content-Type: text/plain; charset=UTF-8
> +Content-Transfer-Encoding: 8bit
> +
> +When doing something like:
> +
> + { printf "\xff"; printf "\xfe"; } | flash_otp_write -u /dev/mtd0 0
> +
> +flash_otp_write might see only a single byte when reading from stdin for
> +the first tim. In this case (and without this patch) it pads to
> +$writesize with '\xff's and writes that out. In the next iteration it
> +reads the 2nd byte, pads and writes again. So the 2nd byte is written to
> +offset $writesize instead of 1.
> +
> +Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> +Forwarded: id:1362044529-511-1-git-send-email-u.kleine-koenig@pengutronix.de
> +---
> + flash_otp_write.c | 19 ++++++++++++++++++-
> + 1 file changed, 18 insertions(+), 1 deletion(-)
> +
> +diff --git a/flash_otp_write.c b/flash_otp_write.c
> +index 41cf1c5..0aa872e 100644
> +--- a/flash_otp_write.c
> ++++ b/flash_otp_write.c
> +@@ -15,6 +15,23 @@
> +
> + #include <mtd/mtd-user.h>
> +
> ++ssize_t xread(int fd, void *buf, size_t count)
> ++{
> ++ ssize_t ret, done = 0;
> ++
> ++retry:
> ++ ret = read(fd, buf + done, count - done);
> ++ if (ret < 0)
> ++ return ret;
> ++
> ++ done += ret;
> ++
> ++ if (ret == 0 /* EOF */ || done == count)
> ++ return done;
> ++ else
> ++ goto retry;
> ++}
> ++
> + int main(int argc,char *argv[])
> + {
> + int fd, val, ret, size, wrote, len;
> +@@ -66,7 +83,7 @@ int main(int argc,char *argv[])
> + len = 256;
> +
> + wrote = 0;
> +- while ((size = read(0, buf, len))) {
> ++ while ((size = xread(0, buf, len))) {
> + if (size < 0) {
> + perror("read()");
> + return errno;
> diff --git a/patches/mtd-utils-1.5.0/0005-flash_otp_write-fix-a-buffer-overflow-on-NAND-with-w.patch b/patches/mtd-utils-1.5.0/0005-flash_otp_write-fix-a-buffer-overflow-on-NAND-with-w.patch
> new file mode 100644
> index 0000000..d1102c0
> --- /dev/null
> +++ b/patches/mtd-utils-1.5.0/0005-flash_otp_write-fix-a-buffer-overflow-on-NAND-with-w.patch
> @@ -0,0 +1,35 @@
> +From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
> +Date: Thu, 28 Feb 2013 10:28:29 +0100
> +Subject: [PATCH] flash_otp_write: fix a buffer overflow on NAND with write
> + size > 2048
> +MIME-Version: 1.0
> +Content-Type: text/plain; charset=UTF-8
> +Content-Transfer-Encoding: 8bit
> +
> +I'm not aware of any chip having a write size bigger than 2048 today.
> +Still checking for that instead of a sleeping problem to bite us maybe
> +in a few years is easy.
> +
> +Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> +Forwarded: id:1362044546-559-1-git-send-email-u.kleine-koenig@pengutronix.de
> +---
> + flash_otp_write.c | 6 ++++++
> + 1 file changed, 6 insertions(+)
> +
> +diff --git a/flash_otp_write.c b/flash_otp_write.c
> +index 0aa872e..5114e6b 100644
> +--- a/flash_otp_write.c
> ++++ b/flash_otp_write.c
> +@@ -82,6 +82,12 @@ int main(int argc,char *argv[])
> + else
> + len = 256;
> +
> ++ if (len > sizeof(buf)) {
> ++ printf("huh, writesize (%d) bigger than buffer (%zu)\n",
> ++ len, sizeof(buf));
> ++ return ENOMEM;
> ++ }
> ++
> + wrote = 0;
> + while ((size = xread(0, buf, len))) {
> + if (size < 0) {
> diff --git a/patches/mtd-utils-1.5.0/0006-Makefile-also-build-and-install-flash_otp_lock-and-f.patch b/patches/mtd-utils-1.5.0/0006-Makefile-also-build-and-install-flash_otp_lock-and-f.patch
> new file mode 100644
> index 0000000..9727290
> --- /dev/null
> +++ b/patches/mtd-utils-1.5.0/0006-Makefile-also-build-and-install-flash_otp_lock-and-f.patch
> @@ -0,0 +1,42 @@
> +From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
> +Date: Wed, 20 Feb 2013 17:29:12 +0100
> +Subject: [PATCH] Makefile: also build and install flash_otp_lock and
> + flash_otp_write
> +MIME-Version: 1.0
> +Content-Type: text/plain; charset=UTF-8
> +Content-Transfer-Encoding: 8bit
> +
> +Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> +Forwarded: id:1361378491-18687-1-git-send-email-u.kleine-koenig@pengutronix.de
> +---
> + .gitignore | 2 ++
> + Makefile | 3 ++-
> + 2 files changed, 4 insertions(+), 1 deletion(-)
> +
> +diff --git a/.gitignore b/.gitignore
> +index d4771fb..83ca938 100644
> +--- a/.gitignore
> ++++ b/.gitignore
> +@@ -25,6 +25,8 @@
> + /flash_lock
> + /flash_otp_dump
> + /flash_otp_info
> ++/flash_otp_lock
> ++/flash_otp_write
> + /flash_unlock
> + /flashcp
> + /ftl_check
> +diff --git a/Makefile b/Makefile
> +index 190db58..3f9c24f 100644
> +--- a/Makefile
> ++++ b/Makefile
> +@@ -19,7 +19,8 @@ TESTS = tests
> + MTD_BINS = \
> + ftl_format flash_erase nanddump doc_loadbios \
> + ftl_check mkfs.jffs2 flash_lock flash_unlock \
> +- flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
> ++ flash_otp_info flash_otp_dump flash_otp_lock flash_otp_write \
> ++ mtd_debug flashcp nandwrite nandtest \
> + jffs2dump \
> + nftldump nftl_format docfdisk \
> + rfddump rfdformat \
> diff --git a/patches/mtd-utils-1.5.0/series b/patches/mtd-utils-1.5.0/series
> index 38ac3d1..5739202 100644
> --- a/patches/mtd-utils-1.5.0/series
> +++ b/patches/mtd-utils-1.5.0/series
> @@ -2,4 +2,8 @@
> #tag:base --start-number 1
> 0001-make-ubifs-optional.patch
> 0002-Make-liblzo-optional-for-ubifs-tools.patch
> -# c7b83aac3f84d721cecd9e53605999f9 - git-ptx-patches magic
> +0003-flash_otp_write-fix-format-string-warning.patch
> +0004-flash_otp_write-fix-writing-to-NAND-in-presence-of-p.patch
> +0005-flash_otp_write-fix-a-buffer-overflow-on-NAND-with-w.patch
> +0006-Makefile-also-build-and-install-flash_otp_lock-and-f.patch
> +# e4c91e5314fff3767797bd4aab24a7e3 - git-ptx-patches magic
> diff --git a/rules/mtd-utils.in b/rules/mtd-utils.in
> index 45ab8e7..d1c46bd 100644
> --- a/rules/mtd-utils.in
> +++ b/rules/mtd-utils.in
> @@ -68,6 +68,18 @@ config MTD_UTILS_FLASH_OTP_INFO
> help
> Print info about one-time programmable data.
>
> +config MTD_UTILS_FLASH_OTP_LOCK
> + bool
> + prompt "flash_otp_lock"
> + help
> + Lock one-time programmable data.
> +
> +config MTD_UTILS_FLASH_OTP_WRITE
> + bool
> + prompt "flash_otp_write"
> + help
> + Write one-time programmable data.
> +
> config MTD_UTILS_FLASH_UNLOCK
> bool
> prompt "flash_unlock"
> diff --git a/rules/mtd-utils.make b/rules/mtd-utils.make
> index d20050e..75be7db 100644
> --- a/rules/mtd-utils.make
> +++ b/rules/mtd-utils.make
> @@ -91,6 +91,14 @@ ifdef PTXCONF_MTD_UTILS_FLASH_OTP_INFO
> @$(call install_copy, mtd-utils, 0, 0, 0755, -, \
> /usr/sbin/flash_otp_info)
> endif
> +ifdef PTXCONF_MTD_UTILS_FLASH_OTP_LOCK
> + @$(call install_copy, mtd-utils, 0, 0, 0755, -, \
> + /usr/sbin/flash_otp_lock)
> +endif
> +ifdef PTXCONF_MTD_UTILS_FLASH_OTP_WRITE
> + @$(call install_copy, mtd-utils, 0, 0, 0755, -, \
> + /usr/sbin/flash_otp_write)
> +endif
> ifdef PTXCONF_MTD_UTILS_FLASH_UNLOCK
> @$(call install_copy, mtd-utils, 0, 0, 0755, -, \
> /usr/sbin/flash_unlock)
> --
> 1.7.10.4
>
>
> --
> ptxdist mailing list
> ptxdist@pengutronix.de
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
--
ptxdist mailing list
ptxdist@pengutronix.de
prev parent reply other threads:[~2013-03-04 17:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-20 20:14 [ptxdist] [PATCH] mtd-utils: allow building and installing of flash_otp_{lock,write} Uwe Kleine-König
2013-02-28 13:39 ` [ptxdist] [PATCH v2] mtd-utils: allow building and installing of flash_otp_{lock, write} Uwe Kleine-König
2013-03-04 17:06 ` Michael Olbrich [this message]
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=20130304170622.GZ5360@pengutronix.de \
--to=m.olbrich@pengutronix.de \
--cc=ptxdist@pengutronix.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