mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* state support updates
@ 2015-05-30 13:11 Jan Luebbe
  2015-05-30 13:11 ` [PATCH 1/2] state: add some more error messages Jan Luebbe
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jan Luebbe @ 2015-05-30 13:11 UTC (permalink / raw)
  To: barebox

Hi,

these patches apply to for-next/state. The first improves the error reporting
and the second makes it easier to use the state framework with small EEPROMs.

Regards,
Jan


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 1/2] state: add some more error messages
  2015-05-30 13:11 state support updates Jan Luebbe
@ 2015-05-30 13:11 ` Jan Luebbe
  2015-05-30 13:11 ` [PATCH 2/2] state: add support for uint8 variables Jan Luebbe
  2015-06-03  8:21 ` state support updates Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Jan Luebbe @ 2015-05-30 13:11 UTC (permalink / raw)
  To: barebox

This helps with finding out why the state cannot be loaded correctly.

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
---
 common/state.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/common/state.c b/common/state.c
index d243de8..0be0efe 100644
--- a/common/state.c
+++ b/common/state.c
@@ -848,10 +848,13 @@ int state_load(struct state *state)
 		return -ENOSYS;
 
 	ret = state->backend->load(state->backend, state);
-	if (ret)
+	if (ret) {
+		dev_warn(&state->dev, "load failed\n");
 		state->dirty = 1;
-	else
+	} else {
+		dev_info(&state->dev, "load successful\n");
 		state->dirty = 0;
+	}
 
 	return ret;
 }
@@ -1065,8 +1068,11 @@ static int backend_raw_load_one(struct state_backend_raw *backend_raw,
 
 	ret = read_full(fd, &header, sizeof(header));
 	max_len -= sizeof(header);
-	if (ret < 0)
+	if (ret < 0) {
+		dev_err(&state->dev,
+			"cannot read header from backend device");
 		return ret;
+	}
 
 	crc = crc32(0, &header, sizeof(header) - sizeof(uint32_t));
 	if (crc != header.header_crc) {
@@ -1127,8 +1133,10 @@ static int state_backend_raw_load(struct state_backend *backend,
 	int ret = 0, fd, i;
 
 	fd = open(backend->path, O_RDONLY);
-	if (fd < 0)
+	if (fd < 0) {
+		dev_err(&state->dev, "cannot open %s\n", backend->path);
 		return fd;
+	}
 
 	for (i = 0; i < RAW_BACKEND_COPIES; i++) {
 		off_t offset = backend_raw->offset + i * backend_raw->stride;
@@ -1352,7 +1360,8 @@ int state_backend_raw_file(struct state *state, const char *of_path,
 	}
 
 	if (backend_raw->size / backend_raw->stride < RAW_BACKEND_COPIES) {
-		dev_err(&state->dev, "not enough space for two copies\n");
+		dev_err(&state->dev, "not enough space for two copies (%lu each)\n",
+			backend_raw->stride);
 		ret = -ENOSPC;
 		goto err;
 	}
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/2] state: add support for uint8 variables
  2015-05-30 13:11 state support updates Jan Luebbe
  2015-05-30 13:11 ` [PATCH 1/2] state: add some more error messages Jan Luebbe
@ 2015-05-30 13:11 ` Jan Luebbe
  2015-06-03  8:21 ` state support updates Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Jan Luebbe @ 2015-05-30 13:11 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
---
 common/state.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/common/state.c b/common/state.c
index 0be0efe..7076f57 100644
--- a/common/state.c
+++ b/common/state.c
@@ -61,6 +61,7 @@ struct state_backend {
 enum state_variable_type {
 	STATE_TYPE_INVALID = 0,
 	STATE_TYPE_ENUM,
+	STATE_TYPE_U8,
 	STATE_TYPE_U32,
 	STATE_TYPE_MAC,
 };
@@ -162,6 +163,32 @@ static int state_uint32_import(struct state_variable *sv,
 	return 0;
 }
 
+static struct state_variable *state_uint8_create(struct state *state,
+		const char *name, struct device_node *node)
+{
+	struct state_uint32 *su32;
+	struct param_d *param;
+
+	su32 = xzalloc(sizeof(*su32));
+
+	param = dev_add_param_int(&state->dev, name, state_set_dirty,
+				  NULL, &su32->value, "%d", state);
+	if (IS_ERR(param)) {
+		free(su32);
+		return ERR_CAST(param);
+	}
+
+	su32->param = param;
+	su32->var.size = sizeof(uint8_t);
+#ifdef __LITTLE_ENDIAN
+	su32->var.raw = &su32->value;
+#else
+	su32->var.raw = &su32->value + 3;
+#endif
+
+	return &su32->var;
+}
+
 static struct state_variable *state_uint32_create(struct state *state,
 		const char *name, struct device_node *node)
 {
@@ -372,6 +399,12 @@ out:
 
 static struct variable_type types[] =  {
 	{
+		.type = STATE_TYPE_U8,
+		.type_name = "uint8",
+		.export = state_uint32_export,
+		.import = state_uint32_import,
+		.create = state_uint8_create,
+	}, {
 		.type = STATE_TYPE_U32,
 		.type_name = "uint32",
 		.export = state_uint32_export,
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: state support updates
  2015-05-30 13:11 state support updates Jan Luebbe
  2015-05-30 13:11 ` [PATCH 1/2] state: add some more error messages Jan Luebbe
  2015-05-30 13:11 ` [PATCH 2/2] state: add support for uint8 variables Jan Luebbe
@ 2015-06-03  8:21 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-06-03  8:21 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: barebox

On Sat, May 30, 2015 at 03:11:43PM +0200, Jan Luebbe wrote:
> Hi,
> 
> these patches apply to for-next/state. The first improves the error reporting
> and the second makes it easier to use the state framework with small EEPROMs.

Applied, thanks

Sascha


-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2015-06-03  8:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-30 13:11 state support updates Jan Luebbe
2015-05-30 13:11 ` [PATCH 1/2] state: add some more error messages Jan Luebbe
2015-05-30 13:11 ` [PATCH 2/2] state: add support for uint8 variables Jan Luebbe
2015-06-03  8:21 ` state support updates Sascha Hauer

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