Skip to contentSkip to conversation

libmtd: add lock/unlock helpers

PATCH In review Mike Frysinger 4 participants 31 messages Sep 24, 2010 – Sep 28, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 libmtd: add lock/unlock helpers

---
 include/libmtd.h |   24 ++++++++++++++++++++++++
 lib/libmtd.c     |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
include/libmtd.h +24 -0
index afaba42..f73af4c 100644
@@ -138,6 +138,30 @@ int mtd_get_dev_info(libmtd_t desc, const char *node, struct mtd_dev_info *mtd);
 int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd);
 
 /**
+ * mtd_lock - lock eraseblocks
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @eb: eraseblock to lock
+ *
+ * This function locks eraseblock @eb. Returns %0 in case of success and %-1
+ * in case of failure.
+ */
+int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb);
+
+/**
+ * mtd_unlock - unlock eraseblocks
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @eb: eraseblock to lock
+ *
+ * This function unlocks eraseblock @eb. Returns %0 in case of success and %-1
+ * in case of failure.
+ */
+int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb);
+
+/**
  * mtd_erase - erase an eraseblock.
  * @desc: MTD library descriptor
  * @mtd: MTD device description object
lib/libmtd.c +32 -0
index d57ae8f..1b3d597 100644
@@ -802,6 +802,38 @@ static int mtd_valid_erase_block(const struct mtd_dev_info *mtd, int eb)
 	return 0;
 }
 
+static int mtd_xlock(const struct mtd_dev_info *mtd, int fd, int eb, int req,
+		     const char *sreq)
+{
+	int ret;
+	struct erase_info_user ei;
+
+	ret = mtd_valid_erase_block(mtd, eb);
+	if (ret)
+		return ret;
+
+	ei.start = eb * mtd->eb_size;
+	ei.length = mtd->eb_size;
+
+	ret = ioctl(fd, req, &ei);
+	if (ret < 0)
+		return sys_errmsg("%s ioctl failed for eraseblock %d "
+				  "(mtd%d)", sreq, eb, mtd->mtd_num);
+
+	return 0;
+}
+#define mtd_xlock(mtd, fd, eb, req) mtd_xlock(mtd, fd, eb, req, #req)
+
+int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb)
+{
+	return mtd_xlock(mtd, fd, eb, MEMLOCK);
+}
+
+int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb)
+{
+	return mtd_xlock(mtd, fd, eb, MEMUNLOCK);
+}
+
 int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
 {
 	int ret;
Signature · 1 line
1.7.3
#1 lore raw

PATCH 2/4 mtd-utils: new bareverbose() helper

Add a new helper that let's people do simple verbose output without any implicit strings added around it. Good for progress bars and such.

---
 include/common.h |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
include/common.h +4 -2
index e87b215..11b0cf6 100644
@@ -38,10 +38,12 @@ extern "C" {
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 /* Verbose messages */
-#define verbose(verbose, fmt, ...) do {                            \
+#define bareverbose(verbose, fmt, ...) do {                        \
 	if (verbose)                                               \
-		printf(PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__); \
+		printf(fmt, ##__VA_ARGS__);                        \
 } while(0)
+#define verbose(verbose, fmt, ...) \
+	bareverbose(verbose, PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__)
 
 /* Normal messages */
 #define normsg(fmt, ...) do {                              \
Signature · 1 line
1.7.3
#2 lore raw

RE: [PATCH 2/4] mtd-utils: new bareverbose() helper

Quoted 1 line · [email protected] wrote:

Add a new helper that let's people do simple verbose output

Punctuation nit: "lets"

--
Jon Povey
[email protected]

Racelogic is a limited company registered in England. Registered number 2743719 . Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .

The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network

#3 lore raw

PATCH v2 2/4 mtd-utils: new bareverbose() helper

In reply to Mike Frysinger

Add a new helper that lets people do simple verbose output without any implicit strings added around it. Good for progress bars and such.

---
v2
- fix typo in changelog

 include/common.h |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
include/common.h +4 -2
index e87b215..11b0cf6 100644
@@ -38,10 +38,12 @@ extern "C" {
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 /* Verbose messages */
-#define verbose(verbose, fmt, ...) do {                            \
+#define bareverbose(verbose, fmt, ...) do {                        \
 	if (verbose)                                               \
-		printf(PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__); \
+		printf(fmt, ##__VA_ARGS__);                        \
 } while(0)
+#define verbose(verbose, fmt, ...) \
+	bareverbose(verbose, PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__)
 
 /* Normal messages */
 #define normsg(fmt, ...) do {                              \
Signature · 1 line
1.7.2.3
#4 lore raw

Re: [PATCH 2/4 v2] mtd-utils: new bareverbose() helper

Quoted 4 lines · Mike Frysinger

Add a new helper that lets people do simple verbose output without any implicit strings added around it. Good for progress bars and such.

Pushed, thanks.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
#5 lore raw

PATCH 3/4 mtd-utils: new strtoX helpers

In reply to Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

---
 include/strtox.h |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)
 create mode 100644 include/strtox.h
include/strtox.h new file +63 -0
new file mode 100644
index 0000000..f7ae824
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) Artem Bityutskiy, 2007, 2008
+ * Copyright (c) Mike Frysinger, 2010
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MTD_UTILS_STRTOX_H__
+#define __MTD_UTILS_STRTOX_H__
+
+#include "common.h"
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * simple_strtoX - convert a hex/dec string into a number
+ * @snum: buffer to convert
+ * @error: set to 1 when buffer isn't fully consumed
+ */
+#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \
+{ \
+	type ret; \
+	char *endptr; \
+ \
+	if (snum[0] == '0' && snum[1] == 'x') \
+		ret = func(snum, &endptr, 16); \
+	else \
+		ret = func(snum, &endptr, 10); \
+ \
+	if (!*snum || *endptr) { \
+		errmsg("%s: unable to parse the number '%s'", #func, snum); \
+		if (error) \
+			*error = 1; \
+	} \
+ \
+	return ret; \
+}
+simple_strtoX(strtol, long int)
+simple_strtoX(strtoll, long int)
+simple_strtoX(strtoul, unsigned long int)
+simple_strtoX(strtoull, unsigned long int)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__MTD_UTILS_STRTOX_H__ */
Signature · 1 line
1.7.3
#6 lore raw

RE: [PATCH 3/4] mtd-utils: new strtoX helpers

Quoted 7 lines · [email protected] wrote:

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

+ */ +#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \ +{ \

Why inline? won't this bloat code, better to remove inline?

include/strtox.h line 44

Quoted 4 lines
include/strtox.h new file +4 -0
+       if (snum[0] == '0' && snum[1] == 'x') \
+               ret = func(snum, &endptr, 16); \
+       else \
+               ret = func(snum, &endptr, 10); \

Can just call strtol etc. with 0 instead of 10 or 16, it will autodetect 0xnnn as base 16.

--
Jon Povey
[email protected]

Racelogic is a limited company registered in England. Registered number 2743719 . Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .

The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network

#7 lore raw

Re: [PATCH 3/4] mtd-utils: new strtoX helpers

Quoted 10 lines · Jon Povey
Quoted 7 lines · [email protected] wrote:

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions.  These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

+ */ +#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \ +{ \

Why inline? won't this bloat code, better to remove inline?

because uninlined static definitions will generate unused warnings

Quoted 7 lines
Quoted 4 lines

+       if (snum[0] == '0' && snum[1] == 'x') \
+               ret = func(snum, &endptr, 16); \
+       else \
+               ret = func(snum, &endptr, 10); \

Can just call strtol etc. with 0 instead of 10 or 16, it will autodetect 0xnnn as base 16.

true ... i'll fix that up
-mike

#8 lore raw

RE: [PATCH 3/4] mtd-utils: new strtoX helpers

Quoted 8 lines · Mike Frysinger
Quoted 7 lines · Jon Povey
Quoted 5 lines · [email protected] wrote:

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

Quoted 7 lines
Quoted 5 lines

include/strtox.h line 37

Quoted 3 lines

+ */ +#define simple_strtoX(func, type) \

include/strtox.h new file +2 -0
+static inline type simple_##func(const char *snum, int *error) \
+{ \

Why inline? won't this bloat code, better to remove inline?

because uninlined static definitions will generate unused warnings

you could do
__attribute__((unused)) static type simple_##func(...

I assume the compiler will still optimise them away, not sure.

but with the 0xnn handling going away, does this header now offer much over just calling strtol et al directly?

I'd argue it just adds complexity and maintainence hassle.

--
Jon Povey
[email protected]

Racelogic is a limited company registered in England. Registered number 2743719 . Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .

The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network

#9 lore raw

Re: [PATCH 3/4] mtd-utils: new strtoX helpers

Quoted 17 lines · Jon Povey
Quoted 8 lines · Mike Frysinger
Quoted 7 lines · Jon Povey
Quoted 5 lines · [email protected] wrote:

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions.  These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

Quoted 7 lines
Quoted 5 lines

include/strtox.h line 37

Quoted 3 lines

+ */ +#define simple_strtoX(func, type) \

include/strtox.h new file +2 -0
+static inline type simple_##func(const char *snum, int *error) \
+{ \

Why inline? won't this bloat code, better to remove inline?

because uninlined static definitions will generate unused warnings

Quoted 7 lines

you could do
__attribute__((unused)) static type simple_##func(...

I assume the compiler will still optimise them away, not sure.

but with the 0xnn handling going away, does this header now offer much over just calling strtol et al directly?

that depends on whether you're comfortable breaking out your own endptr and knowing the exact semantics
-mike

#10 lore raw

PATCH v2 3/4 mtd-utils: new strtoX helpers

In reply to Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

---
v2
- drop redundant parsing logic

 include/strtox.h |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 include/strtox.h
include/strtox.h new file +58 -0
new file mode 100644
index 0000000..0dcafc7
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) Artem Bityutskiy, 2007, 2008
+ * Copyright (c) Mike Frysinger, 2010
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MTD_UTILS_STRTOX_H__
+#define __MTD_UTILS_STRTOX_H__
+
+#include "common.h"
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * simple_strtoX - convert a hex/dec string into a number
+ * @snum: buffer to convert
+ * @error: set to 1 when buffer isn't fully consumed
+ */
+#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \
+{ \
+	char *endptr; \
+	type ret = func(snum, &endptr, 0); \
+ \
+	if (!*snum || *endptr) { \
+		errmsg("%s: unable to parse the number '%s'", #func, snum); \
+		if (error) \
+			*error = 1; \
+	} \
+ \
+	return ret; \
+}
+simple_strtoX(strtol, long int)
+simple_strtoX(strtoll, long int)
+simple_strtoX(strtoul, unsigned long int)
+simple_strtoX(strtoull, unsigned long int)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__MTD_UTILS_STRTOX_H__ */
Signature · 1 line
1.7.2.3
#11 lore raw

Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers

Quoted 9 lines · Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

---
v2
- drop redundant parsing logic

Why do you need a separate file for this? common.h does not suit this?

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
#12 lore raw

Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers

Quoted 7 lines · Artem Bityutskiy
Quoted 4 lines · Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions.  These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

Why do you need a separate file for this? common.h does not suit this?

the expansion of PROGRAM_NAME causes build errors for programs that do not define it but include common.h
-mike

#13 lore raw

Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers

Quoted 7 lines · Mike Frysinger
Quoted 6 lines · Artem Bityutskiy
Quoted 4 lines · Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

Quoted 5 lines
Quoted 1 line

Why do you need a separate file for this? common.h does not suit this?

the expansion of PROGRAM_NAME causes build errors for programs that do not define it but include common.h
-mike

May be

#ifndef PROGRAM_NAME
#define PROGRAM_NAME "undefined"
#endif

?

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
#14 lore raw

Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers

Quoted 10 lines · Artem Bityutskiy
Quoted 9 lines · Mike Frysinger
Quoted 7 lines · Artem Bityutskiy
Quoted 4 lines · Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions.  These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

Why do you need a separate file for this? common.h does not suit this?

Quoted 8 lines
Quoted 2 lines

the expansion of PROGRAM_NAME causes build errors for programs that do not define it but include common.h

May be

#ifndef PROGRAM_NAME
#define PROGRAM_NAME "undefined"
#endif

if we're going to go that route, i'd rather just go through the few files not defining PROGRAM_NAME, add it, and then turn the comment in common.h about people defining it into an error
-mike

#15 lore raw

Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers

Quoted 16 lines · Mike Frysinger
Quoted 15 lines · Artem Bityutskiy
Quoted 11 lines · Mike Frysinger
Quoted 7 lines · Artem Bityutskiy
Quoted 4 lines · Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

Why do you need a separate file for this? common.h does not suit this?

the expansion of PROGRAM_NAME causes build errors for programs that do not define it but include common.h

May be

Quoted 7 lines
Quoted 3 lines

#ifndef PROGRAM_NAME
#define PROGRAM_NAME "undefined"
#endif

if we're going to go that route, i'd rather just go through the few files not defining PROGRAM_NAME, add it, and then turn the comment in common.h about people defining it into an error

Sounds good as well.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
#16 lore raw

Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers

In reply to Mike Frysinger

include/strtox.h line 24

Quoted 5 lines · Mike Frysinger
include/strtox.h new file +5 -0
+#ifndef __MTD_UTILS_STRTOX_H__
+#define __MTD_UTILS_STRTOX_H__
+
+#include "common.h"
+#include <stdlib.h>

Hmm, but you include this file here anyway.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
#17 lore raw

Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers

In reply to Mike Frysinger
Quoted 10 lines · Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers support both hex and dec numbers transparently, and the caller need only provide a ptr to an error integer if they want to be notified of problems.

---
v2
- drop redundant parsing logic

Mike, so will you move this to common.h or you insist this should be a separate header file?

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#18 lore raw

PATCH v3 1/1 mtd-utils: new strtoX helpers

In reply to Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers simplify the api of these functions a bit by providing an optional "error" pointer and automatic error message.

---
v3
- merge into common.h now that PROGRAM_NAME has been sorted out

 include/common.h |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
include/common.h +24 -0
index dce067b..472315e 100644
@@ -20,6 +20,7 @@
 #define __MTD_UTILS_COMMON_H__
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
@@ -79,6 +80,29 @@ static inline int is_power_of_2(unsigned long long n)
 	        return (n != 0 && ((n & (n - 1)) == 0));
 }
 
+/**
+ * simple_strtoX - convert a hex/dec/oct string into a number
+ * @snum: buffer to convert
+ * @error: set to 1 when buffer isn't fully consumed
+ */
+#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \
+{ \
+	char *endptr; \
+	type ret = func(snum, &endptr, 0); \
+ \
+	if (error && (!*snum || *endptr)) { \
+		errmsg("%s: unable to parse the number '%s'", #func, snum); \
+		*error = 1; \
+	} \
+ \
+	return ret; \
+}
+simple_strtoX(strtol, long int)
+simple_strtoX(strtoll, long int)
+simple_strtoX(strtoul, unsigned long int)
+simple_strtoX(strtoull, unsigned long int)
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.7.2.3
#19 lore raw

Re: [PATCH v3] mtd-utils: new strtoX helpers

Quoted 9 lines · Mike Frysinger

Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers simplify the api of these functions a bit by providing an optional "error" pointer and automatic error message.

---
v3
- merge into common.h now that PROGRAM_NAME has been sorted out

Pushed, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#20 lore raw

PATCH 4/4 mtd-utils: unify flash_erase and flash_eraseall

In reply to Mike Frysinger

These have overlapping functionality, and while flash_eraseall supports newer 64bit ioctls, flash_erase does not. So rather than graft support onto flash_erase, merge the functionality of two into flash_erase so we only have to support one util from now on.

A simple wrapper is provided to ease old flash_eraseall users into the new combined flash_erase util.

---
 .gitignore       |    1 -
 Makefile         |    2 +-
 flash_erase.c    |  418 ++++++++++++++++++++++++++++++++++--------------------
 flash_eraseall   |    4 +
 flash_eraseall.c |  276 -----------------------------------
 5 files changed, 266 insertions(+), 435 deletions(-)
 create mode 100755 flash_eraseall
 delete mode 100644 flash_eraseall.c
.gitignore +0 -1
index defbd57..2dbf198 100644
@@ -20,7 +20,6 @@
 /doc_loadbios
 /docfdisk
 /flash_erase
-/flash_eraseall
 /flash_info
 /flash_lock
 /flash_otp_dump
Makefile +1 -1
index d315f39..6151fb2 100644
@@ -9,7 +9,7 @@ endif
 
 SUBDIRS = lib ubi-utils mkfs.ubifs
 
-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
+TARGETS = ftl_format flash_erase nanddump doc_loadbios \
 	ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
 	flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
 	jffs2dump \
flash_erase.c +261 -157

450 lines not on this page · raw message

flash_eraseall new file +4 -0
new file mode 100755
index 0000000..c5539b3
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase <mtddev> 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"
flash_eraseall.c deleted +0 -276

276 lines not on this page · raw message

Signature · 1 line
1.7.3
#21 lore raw

RE: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall

Quoted 12 lines · [email protected] wrote:

These have overlapping functionality, and while flash_eraseall supports
newer 64bit ioctls, flash_erase does not. So rather than graft support
onto flash_erase, merge the functionality of two into flash_erase so we
only have to support one util from now on.

A simple wrapper is provided to ease old flash_eraseall users into the new combined flash_erase util.

Quoted 6 lines

-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \ +TARGETS = ftl_format flash_erase nanddump
doc_loadbios \ ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \ flash_otp_info flash_otp_dump mtd_debug flashcp

nandwrite nandtest \
        jffs2dump \

Wow, my mailer really mangles patches.

But anyway; will the flash_eraseall script still get installed by make install? it needs to.

--
Jon Povey
[email protected]

Racelogic is a limited company registered in England. Registered number 2743719 . Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .

The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network

#22 lore raw

Re: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall

Quoted 19 lines · Jon Povey
Quoted 11 lines · [email protected] wrote:

These have overlapping functionality, and while flash_eraseall supports
newer 64bit ioctls, flash_erase does not.  So rather than graft support
onto flash_erase, merge the functionality of two into flash_erase so we
only have to support one util from now on.

A simple wrapper is provided to ease old flash_eraseall users into the new combined flash_erase util.

Quoted 6 lines

-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \ +TARGETS = ftl_format flash_erase nanddump doc_loadbios \ ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \ flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
        jffs2dump \

Quoted 2 lines

But anyway; will the flash_eraseall script still get installed by make install? it needs to.

it will not, but i didnt think that to be too much of a problem. people usually dont use make install for their embedded system ... they pluck out the one or two utils they actually need. -mike

#23 lore raw

RE: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall

Quoted 8 lines · Mike Frysinger
Quoted 2 lines · Jon Povey

But anyway; will the flash_eraseall script still get installed by make install? it needs to.

it will not, but i didnt think that to be too much of a problem. people usually dont use make install for their embedded system ... they pluck out the one or two utils they actually need.

"I suppose" is not much of an argument for breaking make install. It can be made to work.. I could do this but don't have time right now.

--
Jon Povey
[email protected]

Racelogic is a limited company registered in England. Registered number 2743719 . Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .

The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network

#24 lore raw

Re: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall

Quoted 11 lines · Jon Povey
Quoted 7 lines · Mike Frysinger
Quoted 2 lines · Jon Povey

But anyway; will the flash_eraseall script still get installed by make install? it needs to.

it will not, but i didnt think that to be too much of a problem. people usually dont use make install for their embedded system ... they pluck out the one or two utils they actually need.

"I suppose" is not much of an argument for breaking make install. It can be made to work.. I could do this but don't have time right now.

you call it "breakage", i call it "intended behavior"

it's trivial to make it work as a one off:
+install: TARGETS += flash_eraseall
-mike

#25 lore raw

PATCH v2 4/4 mtd-utils: unify flash_erase and flash_eraseall

In reply to Mike Frysinger

These have overlapping functionality, and while flash_eraseall supports newer 64bit ioctls, flash_erase does not. So rather than graft support onto flash_erase, merge the functionality of two into flash_erase so we only have to support one util from now on.

A simple wrapper is provided to ease old flash_eraseall users into the new combined flash_erase util.

---
v2
- add SCRIPTS var for install

 .gitignore       |    1 -
 Makefile         |    7 +-
 flash_erase.c    |  418 ++++++++++++++++++++++++++++++++++--------------------
 flash_eraseall   |    4 +
 flash_eraseall.c |  276 -----------------------------------
 5 files changed, 269 insertions(+), 437 deletions(-)
 create mode 100755 flash_eraseall
 delete mode 100644 flash_eraseall.c
.gitignore +0 -1
index defbd57..2dbf198 100644
@@ -20,7 +20,6 @@
 /doc_loadbios
 /docfdisk
 /flash_erase
-/flash_eraseall
 /flash_info
 /flash_lock
 /flash_otp_dump
Makefile +4 -3
index d315f39..9160fac 100644
@@ -9,7 +9,7 @@ endif
 
 SUBDIRS = lib ubi-utils mkfs.ubifs
 
-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
+TARGETS = ftl_format flash_erase nanddump doc_loadbios \
 	ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
 	flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
 	jffs2dump \
@@ -17,6 +17,7 @@ TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
 	rfddump rfdformat \
 	serve_image recv_image \
 	sumtool #jffs2reader
+SCRIPTS = flash_eraseall
 
 SYMLINKS =
 
@@ -53,8 +54,8 @@ LDLIBS_jffs2reader  = -lz -llzo2
 
 $(BUILDDIR)/lib/libmtd.a: subdirs_lib_all ;
 
-install:: ${TARGETS}
+install:: ${TARGETS} ${SCRIPTS}
 	mkdir -p ${DESTDIR}/${SBINDIR}
-	install -m 0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/
+	install -m 0755 $^ ${DESTDIR}/${SBINDIR}/
 	mkdir -p ${DESTDIR}/${MANDIR}/man1
 	gzip -9c mkfs.jffs2.1 > ${DESTDIR}/${MANDIR}/man1/mkfs.jffs2.1.gz
flash_erase.c +261 -157

450 lines not on this page · raw message

flash_eraseall new file +4 -0
new file mode 100755
index 0000000..c5539b3
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase <mtddev> 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"
flash_eraseall.c deleted +0 -276

276 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#26 lore raw

PATCH v3 1/1 mtd-utils: unify flash_erase and flash_eraseall

These have overlapping functionality, and while flash_eraseall supports newer 64bit ioctls, flash_erase does not. So rather than graft support onto flash_erase, merge the functionality of two into flash_erase so we only have to support one util from now on.

A simple wrapper is provided to ease old flash_eraseall users into the new combined flash_erase util.

---
v3
- rebase after recent common.h changes

 .gitignore       |    1 -
 Makefile         |    7 +-
 flash_erase.c    |  418 ++++++++++++++++++++++++++++++++++--------------------
 flash_eraseall   |    4 +
 flash_eraseall.c |  276 -----------------------------------
 5 files changed, 269 insertions(+), 437 deletions(-)
 create mode 100755 flash_eraseall
 delete mode 100644 flash_eraseall.c
.gitignore +0 -1
index defbd57..2dbf198 100644
@@ -20,7 +20,6 @@
 /doc_loadbios
 /docfdisk
 /flash_erase
-/flash_eraseall
 /flash_info
 /flash_lock
 /flash_otp_dump
Makefile +4 -3
index d315f39..93661cb 100644
@@ -9,7 +9,7 @@ endif
 
 SUBDIRS = lib ubi-utils mkfs.ubifs
 
-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
+TARGETS = ftl_format flash_erase nanddump doc_loadbios \
 	ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
 	flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
 	jffs2dump \
@@ -17,6 +17,7 @@ TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
 	rfddump rfdformat \
 	serve_image recv_image \
 	sumtool #jffs2reader
+SCRIPTS = flash_eraseall
 
 SYMLINKS =
 
@@ -53,8 +54,8 @@ LDLIBS_jffs2reader  = -lz -llzo2
 
 $(BUILDDIR)/lib/libmtd.a: subdirs_lib_all ;
 
-install:: ${TARGETS}
+install:: ${TARGETS} ${SCRIPTS}
 	mkdir -p ${DESTDIR}/${SBINDIR}
-	install -m 0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/
+	install -m 0755 ${TARGETS} ${SCRIPTS} ${DESTDIR}/${SBINDIR}/
 	mkdir -p ${DESTDIR}/${MANDIR}/man1
 	gzip -9c mkfs.jffs2.1 > ${DESTDIR}/${MANDIR}/man1/mkfs.jffs2.1.gz
flash_erase.c +261 -157

450 lines not on this page · raw message

flash_eraseall new file +4 -0
new file mode 100755
index 0000000..c5539b3
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase <mtddev> 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"
flash_eraseall.c deleted +0 -276

276 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#27 lore raw

Re: [PATCH v3] mtd-utils: unify flash_erase and flash_eraseall

Quoted 5 lines · Mike Frysinger

These have overlapping functionality, and while flash_eraseall supports newer 64bit ioctls, flash_erase does not. So rather than graft support onto flash_erase, merge the functionality of two into flash_erase so we only have to support one util from now on.

Quoted 7 lines

A simple wrapper is provided to ease old flash_eraseall users into the new combined flash_erase util.

---
v3
- rebase after recent common.h changes

Pushed, thanks.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#28 lore raw

Issue : jffs2 and ecc layout

In reply to Mike Frysinger

Hi,
I was using the following ecc layout which is not working to mount the jffs2 File-system. I was using this in 2.6.32 kernel and was working; but same layout is not working with latest 2.6 kernel.

Observation is that - no read request issued to the driver (say omap2.c).

# mount -t jffs2 /dev/mtdblock4 /mnt/nand
[   32.505218] cannot read OOB for EB at 00000000, requested 8 bytes, read 0 bytes, error -22
mount: Mounting /dev/mtdblock4 on /mnt/nand failed: Input/output error
# dmesg 
<3>[   32.505218] cannot read OOB for EB at 00000000, requested 8 bytes, read 0 bytes, error -22

Code:
178 static struct nand_ecclayout hw_x16_romcode_oob_64 = {
179 .eccbytes = 12,
180 .eccpos = {
181 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
182 },
183 .oobfree = {
184 {.offset = 14,
185 .length = 50}
186 }
187 };

1188 info->nand.ecc.layout = &hw_x16_romcode_oob_64;

Regards,
Ghorai

#29 lore raw

Re: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall

In reply to Mike Frysinger
Quoted 9 lines · Mike Frysinger

These have overlapping functionality, and while flash_eraseall supports newer 64bit ioctls, flash_erase does not. So rather than graft support onto flash_erase, merge the functionality of two into flash_erase so we only have to support one util from now on.

A simple wrapper is provided to ease old flash_eraseall users into the new combined flash_erase util.

And BTW, thanks for good clean-ups!

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#30 lore raw
In reply to Mike Frysinger
Quoted 5 lines · Mike Frysinger
---
 include/libmtd.h |   24 ++++++++++++++++++++++++
 lib/libmtd.c     |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

Pushed with a minor tweak, thanks.

Quoted 2 lines

/**
+ * mtd_lock - lock eraseblocks

Put a dot at the end, for consistency.

Quoted 2 lines

+/**
+ * mtd_unlock - unlock eraseblocks

Ditto.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)