mailarchive of the pengutronix oss-tools mailing list
 help / color / mirror / Atom feed
* [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base
@ 2019-09-30  7:26 Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 01/13] state: Fix lseek error check in state_backend_bucket_direct_read() Ulrich Ölmann
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

As barebox' state implementation changed since we harmonized the code bases the
last time lets adjust them again.

While at it clear away the unused build time options '--disable-logging' and
'--enable-debug'.

Ulrich Ölmann (13):
  state: Fix lseek error check in state_backend_bucket_direct_read()
  state: Fix lseek error check in state_backend_bucket_direct_write()
  state: Fix lseek error check in state_mtd_peb_read()
  state: Fix lseek error check in state_mtd_peb_write()
  state: check length
  state: backend_bucket_circular: mark block as bad if mtd_peb_torture()
    failed
  state: drop unused code and declarations for non-existing functions
  state: keep backward compatibility
  state: backend_storage: harmonize code with barebox
  state: harmonize code with barebox
  state: harmonize code with barebox
  configure: remove build time option '--disable-logging'
  configure: remove build time option '--enable-debug'

 configure.ac                                | 38 +++++++-------
 src/barebox-state.c                         |  2 +
 src/barebox-state/backend_bucket_circular.c | 16 +++---
 src/barebox-state/backend_bucket_direct.c   | 58 +++++++++++++--------
 src/barebox-state/backend_storage.c         |  6 ++-
 src/barebox-state/state.c                   |  7 ---
 src/state.h                                 | 43 ++++++++++++---
 7 files changed, 105 insertions(+), 65 deletions(-)

-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 01/13] state: Fix lseek error check in state_backend_bucket_direct_read()
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 02/13] state: Fix lseek error check in state_backend_bucket_direct_write() Ulrich Ölmann
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit 219b954a11e82afbbd7b6ef13d8c5ba94a5b0ff3
| Author: Andrey Smirnov <andrew.smirnov@gmail.com>
| Date:   Wed Mar 6 23:49:21 2019 -0800
|
|     state: Fix lseek error check in state_backend_bucket_direct_read()
|
|     Don't use 'int' to store lseek()'s return value to avoid problems with
|     large seek offsets. While at it, make sure to populate return error
|     code from 'errno'.
|
|     Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/barebox-state/backend_bucket_direct.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index dc00de0647a1..efa13ce0948a 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -56,10 +56,9 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 	void *buf;
 	int ret;
 
-	ret = lseek(direct->fd, direct->offset, SEEK_SET);
-	if (ret < 0) {
-		dev_err(direct->dev, "Failed to seek file, %d\n", ret);
-		return ret;
+	if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) {
+		dev_err(direct->dev, "Failed to seek file, %d\n", -errno);
+		return -errno;
 	}
 	ret = read_full(direct->fd, &meta, sizeof(meta));
 	if (ret < 0) {
@@ -72,10 +71,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 		if (meta.magic != ~0 && !!meta.magic)
 			bucket->wrong_magic = 1;
 		read_len = direct->max_size;
-		ret = lseek(direct->fd, direct->offset, SEEK_SET);
-		if (ret < 0) {
-			dev_err(direct->dev, "Failed to seek file, %d\n", ret);
-			return ret;
+		if (lseek(direct->fd, direct->offset, SEEK_SET) !=
+		    direct->offset) {
+			dev_err(direct->dev, "Failed to seek file, %d\n",
+				-errno);
+			return -errno;
 		}
 	}
 
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 02/13] state: Fix lseek error check in state_backend_bucket_direct_write()
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 01/13] state: Fix lseek error check in state_backend_bucket_direct_read() Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 03/13] state: Fix lseek error check in state_mtd_peb_read() Ulrich Ölmann
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit ec25ecfbcb47cb83b310b9e177a5b65de3781dec
| Author: Andrey Smirnov <andrew.smirnov@gmail.com>
| Date:   Wed Mar 6 23:49:22 2019 -0800
|
|     state: Fix lseek error check in state_backend_bucket_direct_write()
|
|     Don't use 'int' to store lseek()'s return value to avoid problems with
|     large seek offsets. While at it, make sure to populate return error
|     code from 'errno'.
|
|     Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/barebox-state/backend_bucket_direct.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index efa13ce0948a..7e83578edb0d 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -108,10 +108,9 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
 	if (len > direct->max_size - sizeof(meta))
 		return -E2BIG;
 
-	ret = lseek(direct->fd, direct->offset, SEEK_SET);
-	if (ret < 0) {
-		dev_err(direct->dev, "Failed to seek file, %d\n", ret);
-		return ret;
+	if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) {
+		dev_err(direct->dev, "Failed to seek file, %d\n", -errno);
+		return -errno;
 	}
 
 	meta.magic = direct_magic;
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 03/13] state: Fix lseek error check in state_mtd_peb_read()
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 01/13] state: Fix lseek error check in state_backend_bucket_direct_read() Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 02/13] state: Fix lseek error check in state_backend_bucket_direct_write() Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 04/13] state: Fix lseek error check in state_mtd_peb_write() Ulrich Ölmann
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit 8a6a9fbcecffab1b076edfad94d4f32bb2cc9435
| Author: Andrey Smirnov <andrew.smirnov@gmail.com>
| Date:   Wed Mar 6 23:49:23 2019 -0800
|
|     state: Fix lseek error check in state_mtd_peb_read()
|
|     Don't use 'int' to store lseek()'s return value to avoid problems with
|     large seek offsets. While at it, make sure to populate return error
|     code from 'errno'.
|
|     Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/barebox-state/backend_bucket_circular.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/barebox-state/backend_bucket_circular.c b/src/barebox-state/backend_bucket_circular.c
index f665c3b4539a..8cc7514d5f55 100644
--- a/src/barebox-state/backend_bucket_circular.c
+++ b/src/barebox-state/backend_bucket_circular.c
@@ -162,11 +162,10 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ
 
 	offset += (off_t)circ->eraseblock * circ->mtd->erasesize;
 
-	ret = lseek(circ->fd, offset, SEEK_SET);
-	if (ret < 0) {
+	if (lseek(circ->fd, offset, SEEK_SET) != offset) {
 		dev_err(circ->dev, "Failed to set circular read position to %lld, %d\n",
-			(long long) offset, ret);
-		return ret;
+			(long long) offset, -errno);
+		return -errno;
 	}
 
 	dev_dbg(circ->dev, "Read state from %lld length %d\n", (long long) offset,
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 04/13] state: Fix lseek error check in state_mtd_peb_write()
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (2 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 03/13] state: Fix lseek error check in state_mtd_peb_read() Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 05/13] state: check length Ulrich Ölmann
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit 5eadd11d4795afb6b521b5c3249c6341c0be7117
| Author: Andrey Smirnov <andrew.smirnov@gmail.com>
| Date:   Wed Mar 6 23:49:24 2019 -0800
|
|     state: Fix lseek error check in state_mtd_peb_write()
|
|     Don't use 'int' to store lseek()'s return value to avoid problems with
|     large seek offsets. While at it, make sure to populate return error
|     code from 'errno'.
|
|     Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/barebox-state/backend_bucket_circular.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/barebox-state/backend_bucket_circular.c b/src/barebox-state/backend_bucket_circular.c
index 8cc7514d5f55..b2577bcd5ee3 100644
--- a/src/barebox-state/backend_bucket_circular.c
+++ b/src/barebox-state/backend_bucket_circular.c
@@ -190,11 +190,10 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir
 
 	offset += circ->eraseblock * circ->mtd->erasesize;
 
-	ret = lseek(circ->fd, offset, SEEK_SET);
-	if (ret < 0) {
+	if (lseek(circ->fd, offset, SEEK_SET) != offset) {
 		dev_err(circ->dev, "Failed to set position for circular write %lld, %d\n",
-			(long long) offset, ret);
-		return ret;
+			(long long) offset, -errno);
+		return -errno;
 	}
 
 	ret = write_full(circ->fd, buf, len);
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 05/13] state: check length
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (3 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 04/13] state: Fix lseek error check in state_mtd_peb_write() Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 06/13] state: backend_bucket_circular: mark block as bad if mtd_peb_torture() failed Ulrich Ölmann
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit 9271182f3b32d41a83ca802a63580c0c4fef9b9e
| Author: Jan Remmet <j.remmet@phytec.de>
| Date:   Thu May 23 09:49:00 2019 +0200
|
|     common: state: check length
|
|     if written_length is read from a partial written bucket it may be to
|     big and xmalloc will panic barebox.
|
|     Check if the value is sane. Make read_len unsigned to avoid negative
|     values.
|
|     Signed-off-by: Jan Remmet <j.remmet@phytec.de>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/barebox-state/backend_bucket_direct.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index 7e83578edb0d..5b5506be002e 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -52,7 +52,7 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 	struct state_backend_storage_bucket_direct *direct =
 	    get_bucket_direct(bucket);
 	struct state_backend_storage_bucket_direct_meta meta;
-	ssize_t read_len;
+	uint32_t read_len;
 	void *buf;
 	int ret;
 
@@ -67,6 +67,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 	}
 	if (meta.magic == direct_magic) {
 		read_len = meta.written_length;
+		if (read_len > direct->max_size) {
+			dev_err(direct->dev, "Wrong length in meta data\n");
+			return -EINVAL;
+
+		}
 	} else {
 		if (meta.magic != ~0 && !!meta.magic)
 			bucket->wrong_magic = 1;
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 06/13] state: backend_bucket_circular: mark block as bad if mtd_peb_torture() failed
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (4 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 05/13] state: check length Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 07/13] state: drop unused code and declarations for non-existing functions Ulrich Ölmann
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit 3b68dbcbfce830bdf91f50943e5ee41463717abf
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date:   Mon Jul 15 15:28:55 2019 +0200
|
|     mtd: peb: Do not mark as bad in mtd_peb_torture()
|
|     Both the Kernel and mtd-utils have peb torture functions and both
|     do not mark the block as bad automatically. Instead, the caller
|     must mark the block as bad when -EIO is returned from the torture
|     function. Do the same in barebox. This is necessary as the UBI code
|     otherwise may mark a block as bad twice: Once indirectly in
|     mtd_peb_torture() and then directly afterwards.
|
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/barebox-state/backend_bucket_circular.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/barebox-state/backend_bucket_circular.c b/src/barebox-state/backend_bucket_circular.c
index b2577bcd5ee3..735510e0d36b 100644
--- a/src/barebox-state/backend_bucket_circular.c
+++ b/src/barebox-state/backend_bucket_circular.c
@@ -95,6 +95,7 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ
 	if (ret == -EBADMSG) {
 		ret = mtd_peb_torture(circ->mtd, circ->eraseblock);
 		if (ret == -EIO) {
+			mtd_peb_mark_bad(circ->mtd, circ->eraseblock);
 			dev_err(circ->dev, "Tortured eraseblock failed and is marked bad now, PEB %u\n",
 				circ->eraseblock);
 			return -EIO;
@@ -132,6 +133,7 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir
 	if (ret == -EBADMSG) {
 		ret = mtd_peb_torture(circ->mtd, circ->eraseblock);
 		if (ret == -EIO) {
+			mtd_peb_mark_bad(circ->mtd, circ->eraseblock);
 			dev_err(circ->dev, "Tortured eraseblock failed and is marked bad now, PEB %u\n",
 				circ->eraseblock);
 			return -EIO;
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 07/13] state: drop unused code and declarations for non-existing functions
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (5 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 06/13] state: backend_bucket_circular: mark block as bad if mtd_peb_torture() failed Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility Ulrich Ölmann
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit 452a99483cec36933ff59e6f0a796ec2ee1aea65
| Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
| Date:   Wed Sep 11 21:27:37 2019 +0200
|
|     state: drop unused code and declarations for non-existing functions
|
|     state_get_name() is not used and so can be removed.
|     state_backend_dtb_file() and state_backend_raw_file() were dropped in
|     c999b507da98 ("state: Refactor state framework").
|
|     Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/barebox-state/state.c | 7 -------
 src/state.h               | 5 -----
 2 files changed, 12 deletions(-)

diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index e95f91e29cd5..f528b3e19f21 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -713,13 +713,6 @@ struct state *state_by_node(const struct device_node *node)
 	return NULL;
 }
 
-int state_get_name(const struct state *state, char const **name)
-{
-	*name = xstrdup(state->name);
-
-	return 0;
-}
-
 int state_read_mac(struct state *state, const char *name, u8 *buf)
 {
 	struct state_variable *svar;
diff --git a/src/state.h b/src/state.h
index 132c0c363861..c4db9fe84ac5 100644
--- a/src/state.h
+++ b/src/state.h
@@ -5,17 +5,12 @@
 
 struct state;
 
-int state_backend_dtb_file(struct state *state, const char *of_path,
-		const char *path);
-int state_backend_raw_file(struct state *state, const char *of_path,
-		const char *path, off_t offset, size_t size);
 
 struct state *state_new_from_node(struct device_node *node, bool readonly);
 void state_release(struct state *state);
 
 struct state *state_by_name(const char *name);
 struct state *state_by_node(const struct device_node *node);
-int state_get_name(const struct state *state, char const **name);
 
 int state_load(struct state *state);
 int state_load_no_auth(struct state *state);
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (6 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 07/13] state: drop unused code and declarations for non-existing functions Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-10-22  9:46   ` Roland Hieber
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 09/13] state: backend_storage: harmonize code with barebox Ulrich Ölmann
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

Introduce the new build time option '--enable-state-backward-compatibility' to
port the following barebox commit.

NOTE: This changes barebox-state's default behaviour.

| commit 480cde1b22831febacc2a8ab91dfe99d2e5be8e9
| Author: Juergen Borleis <jbe@pengutronix.de>
| Date:   Tue Aug 15 15:46:31 2017 +0200
|
|     state: keep backward compatibility
|
|     Previous 'state' variable set variants do not know and use metadata. The
|     'direct' storage backend's read function honors this, but not its
|     counterpart the write function. This makes an update of the 'state'
|     variable set impossible.
|     This change makes backward compatibility explicit, else it complains in
|     the read function as well. With some more debug output it helps the
|     developer to do things right.
|
|     Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 configure.ac                              | 28 +++++++++++++++--------
 src/barebox-state.c                       |  2 ++
 src/barebox-state/backend_bucket_direct.c | 28 +++++++++++++++--------
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/configure.ac b/configure.ac
index 777f4956ba5f..04c2226625c1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,15 @@ AS_IF([test "x$enable_debug" = "xyes"], [
         AC_DEFINE(DEBUG, [1], [Debug messages.])
 ])
 
+AC_ARG_ENABLE([state-backward-compatibility],
+        AS_HELP_STRING([--enable-state-backward-compatibility], [keep the 'direct' storage backend backward compatible @<:@default=disabled@:>@]),
+        [], [enable_state_backward_compatibility=no])
+AS_IF([test "x${enable_state_backward_compatibility}" = "xyes"], [
+        AC_DEFINE(CONFIG_STATE_BACKWARD_COMPATIBLE, [1], ['direct' storage backend backward compatibility.])
+], [
+        AC_DEFINE(CONFIG_STATE_BACKWARD_COMPATIBLE, [0])
+])
+
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
 
 my_CFLAGS="-Wall \
@@ -53,15 +62,16 @@ AC_MSG_RESULT([
         $PACKAGE $VERSION
         =====
 
-        prefix:                 ${prefix}
-        sysconfdir:             ${sysconfdir}
-        libdir:                 ${libdir}
-        includedir:             ${includedir}
+        prefix:                         ${prefix}
+        sysconfdir:                     ${sysconfdir}
+        libdir:                         ${libdir}
+        includedir:                     ${includedir}
 
-        compiler:               ${CC}
-        cflags:                 ${CFLAGS}
-        ldflags:                ${LDFLAGS}
+        compiler:                       ${CC}
+        cflags:                         ${CFLAGS}
+        ldflags:                        ${LDFLAGS}
 
-        logging:                ${enable_logging}
-        debug:                  ${enable_debug}
+        logging:                        ${enable_logging}
+        debug:                          ${enable_debug}
+        state-backward-compatibility:   ${enable_state_backward_compatibility}
 ])
diff --git a/src/barebox-state.c b/src/barebox-state.c
index 946a8dba6d8c..6b166bfe6e02 100644
--- a/src/barebox-state.c
+++ b/src/barebox-state.c
@@ -439,6 +439,8 @@ int main(int argc, char *argv[])
 			exit(0);
 		case OPT_VERSION:
 			printf(PACKAGE_STRING "\n");
+			printf("Configured with build-time option '--%s-state-backward-compatibility'.\n",
+			       (CONFIG_STATE_BACKWARD_COMPATIBLE) ? "enable" : "disable");
 			exit(0);
 		case 'g':
 			sg = xzalloc(sizeof(*sg));
diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index 5b5506be002e..4522f0170f3d 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -75,6 +75,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
 	} else {
 		if (meta.magic != ~0 && !!meta.magic)
 			bucket->wrong_magic = 1;
+		if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
+			dev_err(direct->dev, "No meta data header found\n");
+			dev_dbg(direct->dev, "Enable backward compatibility or increase stride size\n");
+			return -EINVAL;
+		}
 		read_len = direct->max_size;
 		if (lseek(direct->fd, direct->offset, SEEK_SET) !=
 		    direct->offset) {
@@ -110,20 +115,25 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
 	int ret;
 	struct state_backend_storage_bucket_direct_meta meta;
 
-	if (len > direct->max_size - sizeof(meta))
-		return -E2BIG;
-
 	if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) {
 		dev_err(direct->dev, "Failed to seek file, %d\n", -errno);
 		return -errno;
 	}
 
-	meta.magic = direct_magic;
-	meta.written_length = len;
-	ret = write_full(direct->fd, &meta, sizeof(meta));
-	if (ret < 0) {
-		dev_err(direct->dev, "Failed to write metadata to file, %d\n", ret);
-		return ret;
+	/* write the meta data only if there is head room */
+	if (len <= direct->max_size - sizeof(meta)) {
+		meta.magic = direct_magic;
+		meta.written_length = len;
+		ret = write_full(direct->fd, &meta, sizeof(meta));
+		if (ret < 0) {
+			dev_err(direct->dev, "Failed to write metadata to file, %d\n", ret);
+			return ret;
+		}
+	} else {
+		if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
+			dev_dbg(direct->dev, "Too small stride size: must skip metadata! Increase stride size\n");
+			return -EINVAL;
+		}
 	}
 
 	ret = write_full(direct->fd, buf, len);
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 09/13] state: backend_storage: harmonize code with barebox
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (7 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 10/13] state: " Ulrich Ölmann
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit f3895311ef49171b58b5ea1f06942408c8685a1e
| Author: Lucas Stach <l.stach@pengutronix.de>
| Date:   Fri Jul 22 15:00:19 2016 +0200
|
|     state: only build circular backend if MTD is enabled
|
|     The circular backend depends on MTD symbols and is only useful
|     if MTD is present. Exclude it from the build if MTD is not enabled.
|
|     Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 configure.ac                        | 2 ++
 src/barebox-state/backend_storage.c | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 04c2226625c1..30332620190d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,8 @@ AS_IF([test "x${enable_state_backward_compatibility}" = "xyes"], [
         AC_DEFINE(CONFIG_STATE_BACKWARD_COMPATIBLE, [0])
 ])
 
+AC_DEFINE(CONFIG_MTD, [1], [Statically define to be enabled to harmonize barebox' & dt-utils' code base.])
+
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
 
 my_CFLAGS="-Wall \
diff --git a/src/barebox-state/backend_storage.c b/src/barebox-state/backend_storage.c
index 3879a8d35666..509427f16f1d 100644
--- a/src/barebox-state/backend_storage.c
+++ b/src/barebox-state/backend_storage.c
@@ -369,7 +369,7 @@ int state_storage_init(struct state *state, const char *path,
 		       const char *storagetype)
 {
 	struct state_backend_storage *storage = &state->storage;
-	int ret;
+	int ret = -ENODEV;
 	struct mtd_info_user meminfo;
 
 	INIT_LIST_HEAD(&storage->buckets);
@@ -380,7 +380,9 @@ int state_storage_init(struct state *state, const char *path,
 	storage->max_size = max_size;
 	storage->path = xstrdup(path);
 
-	ret = mtd_get_meminfo(path, &meminfo);
+	if (IS_ENABLED(CONFIG_MTD))
+		ret = mtd_get_meminfo(path, &meminfo);
+
 	if (!ret && !(meminfo.flags & MTD_NO_ERASE)) {
 		bool circular;
 		if (!storagetype || !strcmp(storagetype, "circular")) {
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 10/13] state: harmonize code with barebox
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (8 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 09/13] state: backend_storage: harmonize code with barebox Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 11/13] " Ulrich Ölmann
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

Sort the function declarations in the same order that barebox uses.

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 src/state.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/state.h b/src/state.h
index c4db9fe84ac5..a49155ef2779 100644
--- a/src/state.h
+++ b/src/state.h
@@ -12,8 +12,8 @@ void state_release(struct state *state);
 struct state *state_by_name(const char *name);
 struct state *state_by_node(const struct device_node *node);
 
-int state_load(struct state *state);
 int state_load_no_auth(struct state *state);
+int state_load(struct state *state);
 int state_save(struct state *state);
 void state_info(void);
 
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 11/13] state: harmonize code with barebox
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (9 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 10/13] state: " Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 12/13] configure: remove build time option '--disable-logging' Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 13/13] configure: remove build time option '--enable-debug' Ulrich Ölmann
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

This ports the following barebox commit:

| commit cdbeddf62b7a01f09f00e0fe94430789f4b0b05e
| Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
| Date:   Wed Sep 11 21:27:38 2019 +0200
|
|     state: provide dummy implementations for some functions when STATE is
|     disabled
|
|     This allows to simplify some callers as can be seen from the
|     phytec-som-am335x/board.c change. (The check for state != NULL could be
|     dropped already before.)
|
|     Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
|     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 configure.ac |  2 ++
 src/state.h  | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/configure.ac b/configure.ac
index 30332620190d..c2486af9436f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,6 +43,8 @@ AS_IF([test "x${enable_state_backward_compatibility}" = "xyes"], [
 
 AC_DEFINE(CONFIG_MTD, [1], [Statically define to be enabled to harmonize barebox' & dt-utils' code base.])
 
+AC_DEFINE(CONFIG_STATE, [1], [Statically define to be enabled to harmonize barebox' & dt-utils' code base.])
+
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
 
 my_CFLAGS="-Wall \
diff --git a/src/state.h b/src/state.h
index a49155ef2779..d98b781c2089 100644
--- a/src/state.h
+++ b/src/state.h
@@ -5,6 +5,7 @@
 
 struct state;
 
+#if IS_ENABLED(CONFIG_STATE)
 
 struct state *state_new_from_node(struct device_node *node, bool readonly);
 void state_release(struct state *state);
@@ -19,4 +20,39 @@ void state_info(void);
 
 int state_read_mac(struct state *state, const char *name, u8 *buf);
 
+#else /* #if IS_ENABLED(CONFIG_STATE) */
+
+static inline struct state *state_new_from_node(struct device_node *node,
+						bool readonly)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
+static inline struct state *state_by_name(const char *name)
+{
+	return NULL;
+}
+
+static inline struct state *state_by_node(const struct device_node *node)
+{
+	return NULL;
+};
+
+static inline int state_load(struct state *state)
+{
+	return -ENOSYS;
+}
+
+static inline int state_save(struct state *state)
+{
+	return -ENOSYS;
+}
+
+static inline int state_read_mac(struct state *state, const char *name, u8 *buf)
+{
+	return -ENOSYS;
+}
+
+#endif /* #if IS_ENABLED(CONFIG_STATE) / #else */
+
 #endif /* __STATE_H */
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 12/13] configure: remove build time option '--disable-logging'
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (10 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 11/13] " Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 13/13] configure: remove build time option '--enable-debug' Ulrich Ölmann
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

If enabled it defined the C preprocessor macro 'ENABLE_LOGGING' which wasn't
used anywhere.

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 configure.ac | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index c2486af9436f..5dd17b20809b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,13 +18,6 @@ AC_PREFIX_DEFAULT([/usr])
 AC_PROG_SED
 AC_PROG_MKDIR_P
 
-AC_ARG_ENABLE([logging],
-        AS_HELP_STRING([--disable-logging], [disable system logging @<:@default=enabled@:>@]),
-        [], enable_logging=yes)
-AS_IF([test "x$enable_logging" = "xyes"], [
-        AC_DEFINE(ENABLE_LOGGING, [1], [System logging.])
-])
-
 AC_ARG_ENABLE([debug],
         AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
         [], [enable_debug=no])
@@ -75,7 +68,6 @@ AC_MSG_RESULT([
         cflags:                         ${CFLAGS}
         ldflags:                        ${LDFLAGS}
 
-        logging:                        ${enable_logging}
         debug:                          ${enable_debug}
         state-backward-compatibility:   ${enable_state_backward_compatibility}
 ])
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [OSS-Tools] [PATCH dt-utils 13/13] configure: remove build time option '--enable-debug'
  2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
                   ` (11 preceding siblings ...)
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 12/13] configure: remove build time option '--disable-logging' Ulrich Ölmann
@ 2019-09-30  7:26 ` Ulrich Ölmann
  12 siblings, 0 replies; 15+ messages in thread
From: Ulrich Ölmann @ 2019-09-30  7:26 UTC (permalink / raw)
  To: Pengutronix Public Open-Source-Development; +Cc: Ulrich Ölmann

If enabled it defined the C preprocessor macro 'DEBUG' which wasn't used
anywhere.

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 configure.ac | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5dd17b20809b..d679fa335919 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,13 +18,6 @@ AC_PREFIX_DEFAULT([/usr])
 AC_PROG_SED
 AC_PROG_MKDIR_P
 
-AC_ARG_ENABLE([debug],
-        AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
-        [], [enable_debug=no])
-AS_IF([test "x$enable_debug" = "xyes"], [
-        AC_DEFINE(DEBUG, [1], [Debug messages.])
-])
-
 AC_ARG_ENABLE([state-backward-compatibility],
         AS_HELP_STRING([--enable-state-backward-compatibility], [keep the 'direct' storage backend backward compatible @<:@default=disabled@:>@]),
         [], [enable_state_backward_compatibility=no])
@@ -68,6 +61,5 @@ AC_MSG_RESULT([
         cflags:                         ${CFLAGS}
         ldflags:                        ${LDFLAGS}
 
-        debug:                          ${enable_debug}
         state-backward-compatibility:   ${enable_state_backward_compatibility}
 ])
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility
  2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility Ulrich Ölmann
@ 2019-10-22  9:46   ` Roland Hieber
  0 siblings, 0 replies; 15+ messages in thread
From: Roland Hieber @ 2019-10-22  9:46 UTC (permalink / raw)
  To: Ulrich Ölmann; +Cc: Pengutronix Public Open-Source-Development

On Mon, Sep 30, 2019 at 09:26:08AM +0200, Ulrich Ölmann wrote:
> Introduce the new build time option '--enable-state-backward-compatibility' to
> port the following barebox commit.
> 
> NOTE: This changes barebox-state's default behaviour.
> 
> | commit 480cde1b22831febacc2a8ab91dfe99d2e5be8e9
> | Author: Juergen Borleis <jbe@pengutronix.de>
> | Date:   Tue Aug 15 15:46:31 2017 +0200
> |
> |     state: keep backward compatibility
> |
> |     Previous 'state' variable set variants do not know and use metadata. The
> |     'direct' storage backend's read function honors this, but not its
> |     counterpart the write function. This makes an update of the 'state'
> |     variable set impossible.
> |     This change makes backward compatibility explicit, else it complains in
> |     the read function as well. With some more debug output it helps the
> |     developer to do things right.
> |
> |     Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
> |     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> 
> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
> ---
>  configure.ac                              | 28 +++++++++++++++--------
>  src/barebox-state.c                       |  2 ++
>  src/barebox-state/backend_bucket_direct.c | 28 +++++++++++++++--------
>  3 files changed, 40 insertions(+), 18 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 777f4956ba5f..04c2226625c1 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -32,6 +32,15 @@ AS_IF([test "x$enable_debug" = "xyes"], [
>          AC_DEFINE(DEBUG, [1], [Debug messages.])
>  ])
>  
> +AC_ARG_ENABLE([state-backward-compatibility],
> +        AS_HELP_STRING([--enable-state-backward-compatibility], [keep the 'direct' storage backend backward compatible @<:@default=disabled@:>@]),
> +        [], [enable_state_backward_compatibility=no])
> +AS_IF([test "x${enable_state_backward_compatibility}" = "xyes"], [
> +        AC_DEFINE(CONFIG_STATE_BACKWARD_COMPATIBLE, [1], ['direct' storage backend backward compatibility.])
> +], [
> +        AC_DEFINE(CONFIG_STATE_BACKWARD_COMPATIBLE, [0])
> +])
> +
>  AC_CHECK_FUNCS([__secure_getenv secure_getenv])
>  
>  my_CFLAGS="-Wall \
> @@ -53,15 +62,16 @@ AC_MSG_RESULT([
>          $PACKAGE $VERSION
>          =====
>  
> -        prefix:                 ${prefix}
> -        sysconfdir:             ${sysconfdir}
> -        libdir:                 ${libdir}
> -        includedir:             ${includedir}
> +        prefix:                         ${prefix}
> +        sysconfdir:                     ${sysconfdir}
> +        libdir:                         ${libdir}
> +        includedir:                     ${includedir}
>  
> -        compiler:               ${CC}
> -        cflags:                 ${CFLAGS}
> -        ldflags:                ${LDFLAGS}
> +        compiler:                       ${CC}
> +        cflags:                         ${CFLAGS}
> +        ldflags:                        ${LDFLAGS}
>  
> -        logging:                ${enable_logging}
> -        debug:                  ${enable_debug}
> +        logging:                        ${enable_logging}
> +        debug:                          ${enable_debug}
> +        state-backward-compatibility:   ${enable_state_backward_compatibility}
>  ])

It's good to have this as a build-time option. I have just sent a
barebox patch to clarify that behaviour [1], and I would suggest the
following fixup here:

-        AS_HELP_STRING([--enable-state-backward-compatibility], [keep the 'direct' storage backend backward compatible @<:@default=disabled@:>@]),
+        AS_HELP_STRING([--enable-state-backward-compatibility], [barebox-state: when using the 'direct' storage backend, keep the on-disk format readable by barebox <= v2016.08.0 @<:@default=disabled@:>@])

[1]: https://www.mail-archive.com/barebox@lists.infradead.org/msg32865.html

> diff --git a/src/barebox-state.c b/src/barebox-state.c
> index 946a8dba6d8c..6b166bfe6e02 100644
> --- a/src/barebox-state.c
> +++ b/src/barebox-state.c
> @@ -439,6 +439,8 @@ int main(int argc, char *argv[])
>  			exit(0);
>  		case OPT_VERSION:
>  			printf(PACKAGE_STRING "\n");
> +			printf("Configured with build-time option '--%s-state-backward-compatibility'.\n",
> +			       (CONFIG_STATE_BACKWARD_COMPATIBLE) ? "enable" : "disable");

Oh yes, that's very reasonable too.

 - Roland

>  			exit(0);
>  		case 'g':
>  			sg = xzalloc(sizeof(*sg));
> diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
> index 5b5506be002e..4522f0170f3d 100644
> --- a/src/barebox-state/backend_bucket_direct.c
> +++ b/src/barebox-state/backend_bucket_direct.c
> @@ -75,6 +75,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
>  	} else {
>  		if (meta.magic != ~0 && !!meta.magic)
>  			bucket->wrong_magic = 1;
> +		if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
> +			dev_err(direct->dev, "No meta data header found\n");
> +			dev_dbg(direct->dev, "Enable backward compatibility or increase stride size\n");
> +			return -EINVAL;
> +		}
>  		read_len = direct->max_size;
>  		if (lseek(direct->fd, direct->offset, SEEK_SET) !=
>  		    direct->offset) {
> @@ -110,20 +115,25 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
>  	int ret;
>  	struct state_backend_storage_bucket_direct_meta meta;
>  
> -	if (len > direct->max_size - sizeof(meta))
> -		return -E2BIG;
> -
>  	if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) {
>  		dev_err(direct->dev, "Failed to seek file, %d\n", -errno);
>  		return -errno;
>  	}
>  
> -	meta.magic = direct_magic;
> -	meta.written_length = len;
> -	ret = write_full(direct->fd, &meta, sizeof(meta));
> -	if (ret < 0) {
> -		dev_err(direct->dev, "Failed to write metadata to file, %d\n", ret);
> -		return ret;
> +	/* write the meta data only if there is head room */
> +	if (len <= direct->max_size - sizeof(meta)) {
> +		meta.magic = direct_magic;
> +		meta.written_length = len;
> +		ret = write_full(direct->fd, &meta, sizeof(meta));
> +		if (ret < 0) {
> +			dev_err(direct->dev, "Failed to write metadata to file, %d\n", ret);
> +			return ret;
> +		}
> +	} else {
> +		if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
> +			dev_dbg(direct->dev, "Too small stride size: must skip metadata! Increase stride size\n");
> +			return -EINVAL;
> +		}
>  	}
>  
>  	ret = write_full(direct->fd, buf, len);
> -- 
> 2.23.0
> 
> 
> _______________________________________________
> OSS-Tools mailing list
> OSS-Tools@pengutronix.de

-- 
Roland Hieber                     | r.hieber@pengutronix.de     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-10-22  9:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 01/13] state: Fix lseek error check in state_backend_bucket_direct_read() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 02/13] state: Fix lseek error check in state_backend_bucket_direct_write() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 03/13] state: Fix lseek error check in state_mtd_peb_read() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 04/13] state: Fix lseek error check in state_mtd_peb_write() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 05/13] state: check length Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 06/13] state: backend_bucket_circular: mark block as bad if mtd_peb_torture() failed Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 07/13] state: drop unused code and declarations for non-existing functions Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility Ulrich Ölmann
2019-10-22  9:46   ` Roland Hieber
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 09/13] state: backend_storage: harmonize code with barebox Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 10/13] state: " Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 11/13] " Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 12/13] configure: remove build time option '--disable-logging' Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 13/13] configure: remove build time option '--enable-debug' Ulrich Ölmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox