From: matthias.schiffer@ew.tq-group.com
To: barebox@lists.infradead.org
Cc: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Subject: [PATCH] environment: do not attempt to erase devices with MTD_NO_ERASE
Date: Tue, 20 Nov 2018 10:40:34 +0100 [thread overview]
Message-ID: <20181120094035.18252-2-matthias.schiffer@ew.tq-group.com> (raw)
In-Reply-To: <20181120094035.18252-1-matthias.schiffer@ew.tq-group.com>
From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Devices like MRAM do not need to be erased; in fact, trying to do a partial
erase will fail with -EINVAL, as they don't have a proper erase block size
defined.
The State backend checks for the MTD_NO_ERASE flag before attempting to
erase a device. Add a similar check to envfs_save().
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
common/environment.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/common/environment.c b/common/environment.c
index 56a030eda..28deb3468 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -38,6 +38,8 @@
#include <environment.h>
#include <globalvar.h>
#include <libfile.h>
+#include <asm-generic/ioctl.h>
+#include <linux/mtd/mtd-abi.h>
#else
# define errno_str(x) ("void")
#define EXPORT_SYMBOL(x)
@@ -88,6 +90,17 @@ static int do_compare_file(const char *filename, const char *base)
return ret;
}
+static inline int can_erase(int fd)
+{
+ struct mtd_info_user meminfo;
+ int ret = -ENODEV;
+
+ if (IS_ENABLED(CONFIG_MTD))
+ ret = ioctl(fd, MEMGETINFO, &meminfo);
+
+ return ret || !(meminfo.flags & MTD_NO_ERASE);
+}
+
#else
#define ERASE_SIZE_ALL 0
static inline int protect(int fd, size_t count, unsigned long offset, int prot)
@@ -104,6 +117,11 @@ static int do_compare_file(const char *filename, const char *base)
{
return 1;
}
+
+static inline int can_erase(int fd)
+{
+ return 0;
+}
#endif
static int file_action(const char *filename, struct stat *statbuf,
@@ -334,12 +352,16 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
goto out;
}
- ret = erase(envfd, ERASE_SIZE_ALL, 0);
+ if (can_erase(envfd)) {
+ ret = erase(envfd, ERASE_SIZE_ALL, 0);
- /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */
- if (ret && errno != ENOSYS && errno != EOPNOTSUPP) {
- printf("could not erase %s: %s\n", filename, errno_str());
- goto out;
+ /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't
+ * need it */
+ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) {
+ printf("could not erase %s: %s\n", filename,
+ errno_str());
+ goto out;
+ }
}
size += sizeof(struct envfs_super);
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-11-20 9:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-20 9:40 [PATCH] clk: fix NULL deref without OF node in debug message matthias.schiffer
2018-11-20 9:40 ` matthias.schiffer [this message]
2018-11-21 7:56 ` [PATCH] environment: do not attempt to erase devices with MTD_NO_ERASE Sascha Hauer
2018-11-22 10:19 ` Matthias Schiffer
2018-11-23 8:05 ` Sascha Hauer
2018-11-23 14:50 ` [PATCH v2] mtd: return EOPNOTSUPP when attempting to erase an MTD_NO_ERASE device Matthias Schiffer
2018-11-26 7:46 ` Sascha Hauer
2018-11-20 9:40 ` [PATCH] FIT: look for hash-1 as well as hash@1 nodes in signature check matthias.schiffer
2018-11-21 8:01 ` Sascha Hauer
2018-11-22 10:41 ` [PATCH v2] FIT: support hash-1/signature-1 " Matthias Schiffer
2018-11-23 8:07 ` [PATCH] clk: fix NULL deref without OF node in debug message Sascha Hauer
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=20181120094035.18252-2-matthias.schiffer@ew.tq-group.com \
--to=matthias.schiffer@ew.tq-group.com \
--cc=barebox@lists.infradead.org \
/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