From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from ptx.hi.pengutronix.de ([2001:6f8:1178:2:5054:ff:fec0:8e10] ident=Debian-exim) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1UCYqE-0005J0-P2 for ptxdist@pengutronix.de; Mon, 04 Mar 2013 18:06:22 +0100 Received: from mol by ptx.hi.pengutronix.de with local (Exim 4.72) (envelope-from ) id 1UCYqE-0006ob-OT for ptxdist@pengutronix.de; Mon, 04 Mar 2013 18:06:22 +0100 Date: Mon, 4 Mar 2013 18:06:22 +0100 From: Michael Olbrich Message-ID: <20130304170622.GZ5360@pengutronix.de> References: <1361391279-27702-1-git-send-email-u.kleine-koenig@pengutronix.de> <1362058793-27151-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1362058793-27151-1-git-send-email-u.kleine-koenig@pengutronix.de> Subject: Re: [ptxdist] [PATCH v2] mtd-utils: allow building and installing of flash_otp_{lock, write} Reply-To: ptxdist@pengutronix.de List-Id: PTXdist Development Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: ptxdist-bounces@pengutronix.de Errors-To: ptxdist-bounces@pengutronix.de To: ptxdist@pengutronix.de On Thu, Feb 28, 2013 at 02:39:53PM +0100, Uwe Kleine-K=F6nig 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=F6nig > --- > 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-form= at-string-warning.patch > create mode 100644 patches/mtd-utils-1.5.0/0004-flash_otp_write-fix-writ= ing-to-NAND-in-presence-of-p.patch > create mode 100644 patches/mtd-utils-1.5.0/0005-flash_otp_write-fix-a-bu= ffer-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-stri= ng-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-warn= ing.patch > @@ -0,0 +1,30 @@ > +From: =3D?UTF-8?q?Uwe=3D20Kleine-K=3DC3=3DB6nig?=3D > +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=3DUTF-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=F6nig > +Forwarded: id:1361378469-18631-1-git-send-email-u.kleine-koenig@pengutro= nix.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], offse= t); > ++ printf("Writing OTP user data on %s at offset 0x%lx\n", argv[2], (unsi= gned long)offset); > + = > + if (mtdInfo.type =3D=3D MTD_NANDFLASH) > + len =3D 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: =3D?UTF-8?q?Uwe=3D20Kleine-K=3DC3=3DB6nig?=3D > +Date: Wed, 27 Feb 2013 17:49:06 +0100 > +Subject: [PATCH] flash_otp_write: fix writing to NAND in presence of par= tial > + reads > +MIME-Version: 1.0 > +Content-Type: text/plain; charset=3DUTF-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=F6nig > +Forwarded: id:1362044529-511-1-git-send-email-u.kleine-koenig@pengutroni= x.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 > + = > ++ssize_t xread(int fd, void *buf, size_t count) > ++{ > ++ ssize_t ret, done =3D 0; > ++ > ++retry: > ++ ret =3D read(fd, buf + done, count - done); > ++ if (ret < 0) > ++ return ret; > ++ > ++ done +=3D ret; > ++ > ++ if (ret =3D=3D 0 /* EOF */ || done =3D=3D 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 =3D 256; > + = > + wrote =3D 0; > +- while ((size =3D read(0, buf, len))) { > ++ while ((size =3D 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-ov= erflow-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: =3D?UTF-8?q?Uwe=3D20Kleine-K=3DC3=3DB6nig?=3D > +Date: Thu, 28 Feb 2013 10:28:29 +0100 > +Subject: [PATCH] flash_otp_write: fix a buffer overflow on NAND with wri= te > + size > 2048 > +MIME-Version: 1.0 > +Content-Type: text/plain; charset=3DUTF-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=F6nig > +Forwarded: id:1362044546-559-1-git-send-email-u.kleine-koenig@pengutroni= x.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 =3D 256; > + = > ++ if (len > sizeof(buf)) { > ++ printf("huh, writesize (%d) bigger than buffer (%zu)\n", > ++ len, sizeof(buf)); > ++ return ENOMEM; > ++ } > ++ > + wrote =3D 0; > + while ((size =3D 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-bu= ild-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: =3D?UTF-8?q?Uwe=3D20Kleine-K=3DC3=3DB6nig?=3D > +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=3DUTF-8 > +Content-Transfer-Encoding: 8bit > + > +Signed-off-by: Uwe Kleine-K=F6nig > +Forwarded: id:1361378491-18687-1-git-send-email-u.kleine-koenig@pengutro= nix.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 =3D tests > + MTD_BINS =3D \ > + 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/ser= ies > 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