* [OSS-Tools] [PATCH dt-utils 01/14] state: Remove duplicate incudes
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 02/14] state: backend_raw: fix ignoring unpack failures Marco Felsch
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 870a96a80ba69f2e7d0312a84adecb70bd11ae4a
| Author: Alexander Shiyan <eagle.alexander923@gmail.com>
| Date: Tue Jun 7 08:19:57 2022 +0300
|
| treewide: Remove duplicate incudes
|
| Fix warning fwterated by checkincludes.pl:
| ./net/nfs.c: libgen.h is included more than once.
| ./net/ifup.c: globalvar.h is included more than once.
| ./crypto/rsa.c: asm/types.h is included more than once.
| ./lib/decompress_unlz4.c: linux/decompress/mm.h is included more than once.
| ./scripts/stb_image.h: stdio.h is included more than once.
| ./scripts/kwbimage.c: unistd.h is included more than once.
| ./scripts/common.c: sys/types.h is included more than once.
| ./scripts/bareboximd.c: sys/types.h is included more than once.
| ./scripts/bareboximd.c: sys/mman.h is included more than once.
| ./fs/pstore/ram_core.c: linux/rslib.h is included more than once.
| ./fs/pstore/fs.c: fs.h is included more than once.
| ./fs/pstore/fs.c: linux/pstore.h is included more than once.
| ./fs/nfs.c: fs.h is included more than once.
| ./fs/uimagefs.c: fs.h is included more than once.
| ./fs/fs.c: command.h is included more than once.
| ./arch/sandbox/board/hostfile.c: linux/err.h is included more than once.
| ./arch/sandbox/board/devices.c: mach/linux.h is included more than once.
| ./arch/sandbox/os/common.c: signal.h is included more than once.
| ./arch/arm/boards/zii-imx51-rdu1/board.c: envfs.h is included more than once.
| ./arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c: generated/mach-types.h is
| ./arch/arm/mach-stm32mp/ddrctrl.c: mach/stm32.h is included more than once.
| ./arch/arm/mach-imx/cpu_init.c: common.h is included more than once.
| ./arch/arm/mach-imx/imx8m.c: mach/imx8m-ccm-regs.h is included more than once.
| ./common/efi/payload/init.c: efi.h is included more than once.
| ./common/state/backend_format_raw.c: common.h is included more than once.
| ./common/state/backend_format_raw.c: crc.h is included more than once.
| ./common/hush.c: libbb.h is included more than once.
| ./drivers/spi/atmel-quadspi.c: linux/clk.h is included more than once.
| ./drivers/spi/atmel-quadspi.c: linux/err.h is included more than once.
| ./drivers/net/virtio.c: net.h is included more than once.
| ./drivers/net/phy/phy.c: linux/phy.h is included more than once.
| ./drivers/net/cpsw.c: net.h is included more than once.
| ./drivers/virtio/virtio_pci_common.h: linux/list.h is included more than once.
| ./drivers/usb/host/ohci-hcd.c: dma.h is included more than once.
| ./drivers/usb/gadget/fsl_udc.c: dma.h is included more than once.
| ./drivers/nvmem/eeprom_93xx46.c: spi/spi.h is included more than once.
| ./drivers/nvmem/eeprom_93xx46.c: of.h is included more than once.
| ./drivers/video/imx-ipu-v3/imx-ldb.c: linux/clk.h is included more than once.
| ./drivers/video/imx-ipu-v3/imx-hdmi.c: linux/clk.h is included more than once.
| ./drivers/video/omap.c: common.h is included more than once.
| ./drivers/mtd/nand/nand_s3c24xx.c: asm/sections.h is included more than once.
| ./drivers/clk/imx/clk-imx6sx.c: linux/clk.h is included more than once.
| ./drivers/clk/imx/clk-imx6sl.c: linux/clk.h is included more than once.
| ./commands/bootm.c: of.h is included more than once.
|
| Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
| Link: https://lore.barebox.org/20220607051957.2497-1-eagle.alexander923@gmail.com
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/backend_format_raw.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/barebox-state/backend_format_raw.c b/src/barebox-state/backend_format_raw.c
index 5a71149..9fade5d 100644
--- a/src/barebox-state/backend_format_raw.c
+++ b/src/barebox-state/backend_format_raw.c
@@ -15,7 +15,6 @@
*
*/
-#include <common.h>
#include <common.h>
#include <crypto/keystore.h>
#include <digest.h>
@@ -23,7 +22,6 @@
#include <malloc.h>
#include <crc.h>
#include <of.h>
-#include <crc.h>
#include "state.h"
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 02/14] state: backend_raw: fix ignoring unpack failures
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 01/14] state: Remove duplicate incudes Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 03/14] state: backend_storage: deal gracefully with runtime bucket corruption Marco Felsch
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 9866966ef9b38bf49276c67f7e258bc2a8df55eb
| Author: Marco Felsch <m.felsch@pengutronix.de>
| Date: Wed Aug 25 16:49:04 2021 +0200
|
| state: backend_raw: fix ignoring unpack failures
|
| This is required to inform the state framework that the state variable
| set have changed and we need to write the new variable set. Without this
| fix the new variable set is never written since the state never sets
| dirty=1 and so state_save() will return early without saving the new
| variable set.
|
| Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
| Link: https://lore.barebox.org/20210825144904.4929-1-m.felsch@pengutronix.de
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/backend_format_raw.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/barebox-state/backend_format_raw.c b/src/barebox-state/backend_format_raw.c
index 9fade5d..982df12 100644
--- a/src/barebox-state/backend_format_raw.c
+++ b/src/barebox-state/backend_format_raw.c
@@ -181,6 +181,7 @@ static int backend_format_raw_unpack(struct state_backend_format *format,
const struct backend_raw_header *header;
const void *data;
struct state_backend_format_raw *backend_raw = get_format_raw(format);
+ int ret = 0;
header = (const struct backend_raw_header *)buf;
data = buf + sizeof(*header);
@@ -189,12 +190,13 @@ static int backend_format_raw_unpack(struct state_backend_format *format,
if (sv->start + sv->size > header->data_len) {
dev_err(backend_raw->dev, "State variable ends behind valid data, %s\n",
sv->name);
+ ret = -ENOSPC;
continue;
}
memcpy(sv->raw, data + sv->start, sv->size);
}
- return 0;
+ return ret;
}
static int backend_format_raw_pack(struct state_backend_format *format,
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 03/14] state: backend_storage: deal gracefully with runtime bucket corruption
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 01/14] state: Remove duplicate incudes Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 02/14] state: backend_raw: fix ignoring unpack failures Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 04/14] state: treat state with all-invalid buckets as dirty Marco Felsch
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit dc5100e6ba686fafd5570ce6d972383f047c7313
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date: Thu Mar 5 08:40:31 2020 +0100
|
| state: backend_storage: deal gracefully with runtime bucket corruption
|
| Corrupting an already selected bucket and then reading it again will
| crash barebox when it attempts the refresh:
|
| barebox$ state -l
| barebox$ mw -d /dev/eeprom0.state 0 0x42
| barebox$ state -l
| ERROR: state: No meta data header found
| state: Using bucket 1@0x00000040
| unable to handle NULL pointer dereference at address 0x00000000
| pc : [<4fe4f1ea>] lr : [<4fe0bcb1>]
| sp : 4ffefd5c ip : 00000000 fp : 2ff68f04
| r10: 4ffefdc8 r9 : 4b434d63 r8 : 30155f50
| r7 : 00000024 r6 : 2ff68b60 r5 : 2ff68e90 r4 : 00000000
| r3 : 00000024 r2 : 00000024 r1 : 30155f50 r0 : 00000000
| Flags: Nzcv IRQs off FIQs off Mode SVC_32
| WARNING: [<4fe4f1ea>] (memcmp+0x14/0x1a) from [<4fe0bcb1>] (bucket_refresh.isra.0+0x4d/0x78)
| WARNING: [<4fe0bcb1>] (bucket_refresh.isra.0+0x4d/0x78) from [<4fe0be1d>] (state_storage_read+0xd1/0x104)
| WARNING: [<4fe0be1d>] (state_storage_read+0xd1/0x104) from [<4fe0a5bd>] (state_do_load+0x1d/0x78)
| WARNING: [<4fe0a5bd>] (state_do_load+0x1d/0x78) from [<4fe04137>] (execute_command+0x23/0x4c)
|
| The memcmp called here is an optimization to skip I/O if the used bucket
| and the one to be refreshed compare equal. Unfortunately, if the now
| corrupt bucket was previously the used one, bucket->len will hold the
| old value and we'll run into a NULL pointer dereference.
|
| While this is quite inconvenient, it appears it doesn't affect
| correctness: after the reset, the corrupt bucket will be refreshed
| as expected.
|
| Improve upon this by setting the length to zero when we are NULLing the
| buffer. The zero length of the corrupted bucket will then compare unequal
| to used_bucket->len in bucket_refresh() and ensure we will always refresh
| the buffer if it becomes corrupted without an intermittent reset.
|
| Fixes: 238008b4bd8f ("state: Drop cache bucket")
| Cc: Enrico Jörns <ejo@pengutronix.de>
| Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/backend_storage.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/barebox-state/backend_storage.c b/src/barebox-state/backend_storage.c
index 509427f..458f2a9 100644
--- a/src/barebox-state/backend_storage.c
+++ b/src/barebox-state/backend_storage.c
@@ -192,6 +192,7 @@ int state_storage_read(struct state_backend_storage *storage,
/* Free buffer from the unused buckets */
free(bucket->buf);
bucket->buf = NULL;
+ bucket->len = 0;
}
/*
@@ -204,6 +205,7 @@ int state_storage_read(struct state_backend_storage *storage,
/* buffer from the used bucket is passed to the caller, do not free */
bucket_used->buf = NULL;
+ bucket_used->len = 0;
return 0;
}
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 04/14] state: treat state with all-invalid buckets as dirty
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (2 preceding siblings ...)
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 03/14] state: backend_storage: deal gracefully with runtime bucket corruption Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 05/14] state: remove param member from struct state_string Marco Felsch
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit f41e5160c8618455064a4ff4227105010cd56aaa
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date: Thu Mar 5 08:40:32 2020 +0100
|
| state: treat state with all-invalid buckets as dirty
|
| The state.dirty flag controls whether state_save will actually
| persist state. It is cleared when we successfully load or save
| state and set on writing a state parameter.
|
| When the state however becomes corrupt during barebox runtime and
| state.dirty == 0, reinitializing the state to defaults is quite
| cumbersome:
|
| 1. We reset twice. After the first reset, the dirty flag is reset
| and before the second, state_save will reinitialize to defaults
| 2. We write any state variable and then run the state -s command
|
| Both workarounds are quite obscure, improve the user experience
| by having state -l set the dirty flag when it fails, so a subsequent
| state -s may persist the default values to state.
|
| Steps to reproduce:
|
| barebox$ state -l
| state: Using bucket 0@0x00000000
| barebox$ memcpy -s /dev/zero -d /dev/eeprom0.state 0 0 0x400
| barebox$ state -s
| barebox$ state -l
| ERROR: state: No meta data header found
| ERROR: state: No meta data header found
| ERROR: state: No meta data header found
| ERROR: state: Failed to find any valid state copy in any bucket
| ERROR: state: Failed to read state with format raw, -2
| state: No such file or directory
|
| Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index f528b3e..f6b7817 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -93,7 +93,7 @@ out:
*/
static int state_do_load(struct state *state, enum state_flags flags)
{
- void *buf;
+ void *buf = NULL;
ssize_t len;
int ret;
@@ -102,7 +102,7 @@ static int state_do_load(struct state *state, enum state_flags flags)
if (ret) {
dev_err(&state->dev, "Failed to read state with format %s, %d\n",
state->format->name, ret);
- return ret;
+ goto out;
}
ret = state->format->unpack(state->format, state, buf, len);
@@ -113,9 +113,8 @@ static int state_do_load(struct state *state, enum state_flags flags)
}
state->init_from_defaults = 0;
- state->dirty = 0;
-
out:
+ state->dirty = !!ret; /* mark dirty on error */
free(buf);
return ret;
}
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 05/14] state: remove param member from struct state_string
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (3 preceding siblings ...)
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 04/14] state: treat state with all-invalid buckets as dirty Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 06/14] state: remove param member from state_uint32, state_enum32, state_mac Marco Felsch
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 4f4d6fc426a466109b7f8b20fb2fdfaad9130aa3
| Author: Christian Eggers <ceggers@arri.de>
| Date: Thu Jan 23 13:20:41 2020 +0100
|
| state: remove param member from struct state_string
|
| After adding the parameter, the pointer isn't required anymore.
|
| Signed-off-by: Christian Eggers <ceggers@arri.de>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state.h | 1 -
src/barebox-state/state_variables.c | 7 ++++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h
index 912d6d4..40450fe 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -191,7 +191,6 @@ struct state_mac {
*/
struct state_string {
struct state_variable var;
- struct param_d *param;
char *value;
const char *value_default;
char raw[];
diff --git a/src/barebox-state/state_variables.c b/src/barebox-state/state_variables.c
index 16f630f..18d9884 100644
--- a/src/barebox-state/state_variables.c
+++ b/src/barebox-state/state_variables.c
@@ -413,6 +413,7 @@ static struct state_variable *state_string_create(struct state *state,
{
struct state_string *string;
uint32_t start_size[2];
+ struct param_d *param;
int ret;
ret = of_property_read_u32_array(node, "reg", start_size,
@@ -432,11 +433,11 @@ static struct state_variable *state_string_create(struct state *state,
string->var.raw = &string->raw;
string->var.state = state;
- string->param = dev_add_param_string(&state->dev, name,
+ param = dev_add_param_string(&state->dev, name,
state_string_set, state_string_get,
&string->value, &string->var);
- if (IS_ERR(string->param)) {
- ret = PTR_ERR(string->param);
+ if (IS_ERR(param)) {
+ ret = PTR_ERR(param);
goto out;
}
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 06/14] state: remove param member from state_uint32, state_enum32, state_mac
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (4 preceding siblings ...)
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 05/14] state: remove param member from struct state_string Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 07/14] state: remove unused function Marco Felsch
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 8718fd1f0508ed694569df212333fff9a22b5303
| Author: Christian Eggers <ceggers@arri.de>
| Date: Thu Jan 23 13:20:43 2020 +0100
|
| state: remove param member from state_uint32, state_enum32, state_mac
|
| After adding the parameter, the pointer isn't required anymore.
|
| Signed-off-by: Christian Eggers <ceggers@arri.de>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state.h | 3 ---
src/barebox-state/state_variables.c | 16 ++++++++--------
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h
index 40450fe..1881d92 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -159,7 +159,6 @@ struct state_variable {
*/
struct state_uint32 {
struct state_variable var;
- struct param_d *param;
uint32_t value;
uint32_t value_default;
};
@@ -169,7 +168,6 @@ struct state_uint32 {
*/
struct state_enum32 {
struct state_variable var;
- struct param_d *param;
uint32_t value;
uint32_t value_default;
const char **names;
@@ -181,7 +179,6 @@ struct state_enum32 {
*/
struct state_mac {
struct state_variable var;
- struct param_d *param;
uint8_t value[6];
uint8_t value_default[6];
};
diff --git a/src/barebox-state/state_variables.c b/src/barebox-state/state_variables.c
index 18d9884..228a822 100644
--- a/src/barebox-state/state_variables.c
+++ b/src/barebox-state/state_variables.c
@@ -116,7 +116,6 @@ static struct state_variable *state_uint8_create(struct state *state,
return ERR_CAST(param);
}
- su32->param = param;
su32->var.type = vtype;
su32->var.size = sizeof(uint8_t);
#ifdef __LITTLE_ENDIAN
@@ -146,7 +145,6 @@ static struct state_variable *state_uint32_create(struct state *state,
return ERR_CAST(param);
}
- su32->param = param;
su32->var.type = vtype;
su32->var.size = sizeof(uint32_t);
su32->var.raw = &su32->value;
@@ -226,6 +224,7 @@ static struct state_variable *state_enum32_create(struct state *state,
const struct variable_type *vtype)
{
struct state_enum32 *enum32;
+ struct param_d *param;
int ret, i, num_names;
enum32 = xzalloc(sizeof(*enum32));
@@ -253,11 +252,11 @@ static struct state_variable *state_enum32_create(struct state *state,
enum32->names[i] = xstrdup(name);
}
- enum32->param = dev_add_param_enum(&state->dev, name, state_set_dirty,
+ param = dev_add_param_enum(&state->dev, name, state_set_dirty,
NULL, &enum32->value, enum32->names,
num_names, &enum32->var);
- if (IS_ERR(enum32->param)) {
- ret = PTR_ERR(enum32->param);
+ if (IS_ERR(param)) {
+ ret = PTR_ERR(param);
goto out;
}
@@ -310,6 +309,7 @@ static struct state_variable *state_mac_create(struct state *state,
const struct variable_type *vtype)
{
struct state_mac *mac;
+ struct param_d *param;
int ret;
mac = xzalloc(sizeof(*mac));
@@ -319,10 +319,10 @@ static struct state_variable *state_mac_create(struct state *state,
mac->var.raw = mac->value;
mac->var.state = state;
- mac->param = dev_add_param_mac(&state->dev, name, state_set_dirty,
+ param = dev_add_param_mac(&state->dev, name, state_set_dirty,
NULL, mac->value, &mac->var);
- if (IS_ERR(mac->param)) {
- ret = PTR_ERR(mac->param);
+ if (IS_ERR(param)) {
+ ret = PTR_ERR(param);
goto out;
}
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 07/14] state: remove unused function
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (5 preceding siblings ...)
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 06/14] state: remove param member from state_uint32, state_enum32, state_mac Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 08/14] state: propagate failure to fixup enum32 into DT Marco Felsch
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 418769972dca8ff6af08eabcf47cfe70aaa3cd43
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date: Mon Nov 19 09:34:19 2018 +0100
|
| state: remove unused function
|
| state_find_type() is unused and doesn't have a prototype. Remove it.
|
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state_variables.c | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/src/barebox-state/state_variables.c b/src/barebox-state/state_variables.c
index 228a822..66c66f3 100644
--- a/src/barebox-state/state_variables.c
+++ b/src/barebox-state/state_variables.c
@@ -493,19 +493,6 @@ struct variable_type *state_find_type_by_name(const char *name)
return NULL;
}
-struct variable_type *state_find_type(const enum state_variable_type type)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(types); i++) {
- if (type == types[i].type) {
- return &types[i];
- }
- }
-
- return NULL;
-}
-
struct state_variable *state_find_var(struct state *state, const char *name)
{
struct state_variable *sv;
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 08/14] state: propagate failure to fixup enum32 into DT
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (6 preceding siblings ...)
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 07/14] state: remove unused function Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 09/14] state: add SPDX-License-Identifier for files without explicit license Marco Felsch
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 2628c8a8e1eee3cf6727c0c8a99ff5eec8ba4d1e
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date: Mon Sep 5 11:55:35 2022 +0200
|
| state: propagate failure to fixup enum32 into DT
|
| We assign to ret, but don't use the value anywhere laments the static
| analyzer. Remedy that.
|
| Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Link: https://lore.barebox.org/20220905095557.596891-11-a.fatoum@pengutronix.de
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state_variables.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/barebox-state/state_variables.c b/src/barebox-state/state_variables.c
index 66c66f3..5d86900 100644
--- a/src/barebox-state/state_variables.c
+++ b/src/barebox-state/state_variables.c
@@ -180,6 +180,8 @@ static int state_enum32_export(struct state_variable *var,
str += sprintf(str, "%s", enum32->names[i]) + 1;
ret = of_set_property(node, "names", prop, len, 1);
+ if (ret)
+ return ret;
free(prop);
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 09/14] state: add SPDX-License-Identifier for files without explicit license
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (7 preceding siblings ...)
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 08/14] state: propagate failure to fixup enum32 into DT Marco Felsch
@ 2022-10-14 16:41 ` Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 10/14] state: fix typos found with codespell Marco Felsch
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:41 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 79cd45e6eb62c0599d82c768fbfe226eaf750340
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date: Mon Jan 3 13:05:39 2022 +0100
|
| treewide: add SPDX-License-Identifier for files without explicit license
|
| Record GPL-2.0-only as license for all files lacking an explicit license
| statement.
|
| Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Link: https://lore.barebox.org/20220103120539.1730644-12-a.fatoum@pengutronix.de
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h
index 1881d92..719f7e4 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
#include <linux/types.h>
#include <linux/list.h>
#include <driver.h>
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 10/14] state: fix typos found with codespell
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (8 preceding siblings ...)
2022-10-14 16:41 ` [OSS-Tools] [PATCH dt-utils 09/14] state: add SPDX-License-Identifier for files without explicit license Marco Felsch
@ 2022-10-14 16:42 ` Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 11/14] common: xstrdup: don't panic on xstrdup(NULL) Marco Felsch
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:42 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit 157e861aa6e93a72018c408e82863a3253550a4d
| Author: Yegor Yefremov <yegorslists@googlemail.com>
| Date: Fri Mar 20 10:41:19 2020 +0100
|
| common: fix typos found with codespell
|
| Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index f6b7817..4779574 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -698,7 +698,7 @@ struct state *state_by_name(const char *name)
/*
* state_by_node - find a state instance by of node
*
- * @node The of node of the state intance
+ * @node The of node of the state instance
*/
struct state *state_by_node(const struct device_node *node)
{
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 11/14] common: xstrdup: don't panic on xstrdup(NULL)
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (9 preceding siblings ...)
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 10/14] state: fix typos found with codespell Marco Felsch
@ 2022-10-14 16:42 ` Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 12/14] libdt: add of_property_write_strings support Marco Felsch
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:42 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
This ports the following barebox commit
| commit bf6ddd6c4dccf01c4a27761c5f73918db578f8d6
| Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
| Date: Fri Sep 9 08:37:22 2016 +0200
|
| xstrdup: don't panic on xstrdup(NULL)
|
| Instead return just NULL. This matches the behaviour of kstrdup in the
| kernel and xstrdup in busybox.
|
| This fixes a panic with CONFIG_CMD_MAGICVAR=y and
| CONFIG_CMD_MAGICVAR_HELP unset in magicvar_add() where description is
| always NULL.
|
| Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
It is required to have the same logic for the code shared with barebox.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/dt/common.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/dt/common.h b/src/dt/common.h
index c3c4f53..9b1c169 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -209,8 +209,12 @@ static inline char * safe_strncpy(char *dst, const char *src, size_t size)
static inline char *xstrdup(const char *s)
{
- char *p = strdup(s);
+ char *p;
+
+ if (!s)
+ return NULL;
+ p = strdup(s);
if (!p)
exit(EXIT_FAILURE);
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 12/14] libdt: add of_property_write_strings support
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (10 preceding siblings ...)
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 11/14] common: xstrdup: don't panic on xstrdup(NULL) Marco Felsch
@ 2022-10-14 16:42 ` Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 13/14] libdt: add partition search function Marco Felsch
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:42 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
The function is copied from barebox and based on commit
| commit 09cbc3fbdab5f3118062ceeefb0c1b043a75b3fb
| Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Date: Wed Sep 30 14:53:01 2020 +0200
|
| of: implement of_property_write_strings for multiple strings
|
| The current way to set a property with multiple values (e.g. compatible
| strings) is to have
|
| char properties[] = "st,stm32mp157c-dk2\0st,stm32mp157";
| of_set_property(np, "compatible", properties, sizeof(properties), 1);
|
| Add a new helper to make this easier at the cost of one runtime
| reallocation:
|
| of_property_write_strings(np, "compatible,
| "st,stm32mp157c-dk2", "st,stm32mp157", NULL);
|
| Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/dt/dt.h | 2 ++
src/libdt-utils.sym | 1 +
src/libdt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+)
diff --git a/src/dt/dt.h b/src/dt/dt.h
index 4ae24ba..97dd855 100644
--- a/src/dt/dt.h
+++ b/src/dt/dt.h
@@ -195,6 +195,8 @@ extern int of_property_write_u64_array(struct device_node *np,
size_t sz);
extern int of_property_write_string(struct device_node *np,
const char *propname, const char *value);
+extern int of_property_write_strings(struct device_node *np,
+ const char *propname, ...) __attribute__((__sentinel__));
extern struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name,
diff --git a/src/libdt-utils.sym b/src/libdt-utils.sym
index 2c63d55..a749317 100644
--- a/src/libdt-utils.sym
+++ b/src/libdt-utils.sym
@@ -64,6 +64,7 @@ global:
of_property_read_u8_array;
of_property_write_bool;
of_property_write_string;
+ of_property_write_strings;
of_property_write_u16_array;
of_property_write_u32_array;
of_property_write_u64_array;
diff --git a/src/libdt.c b/src/libdt.c
index 59e76d3..f18ea90 100644
--- a/src/libdt.c
+++ b/src/libdt.c
@@ -1208,6 +1208,53 @@ int of_property_write_u64_array(struct device_node *np,
return 0;
}
+/**
+ * of_property_write_strings - Write strings to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @...: pointers to strings to write
+ *
+ * Search for a property in a device node and write a string to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created, -EINVAL if no strings specified.
+ */
+int of_property_write_strings(struct device_node *np,
+ const char *propname, ...)
+{
+ const char *val;
+ char *buf = NULL, *next;
+ size_t len = 0;
+ va_list ap;
+ int ret = 0;
+
+ va_start(ap, propname);
+ for (val = va_arg(ap, char *); val; val = va_arg(ap, char *))
+ len += strlen(val) + 1;
+ va_end(ap);
+
+ if (!len)
+ return -EINVAL;
+
+ buf = malloc(len);
+ if (!buf)
+ return -ENOMEM;
+
+ next = buf;
+
+ va_start(ap, propname);
+ for (val = va_arg(ap, char *); val; val = va_arg(ap, char *))
+ next = stpcpy(next, val) + 1;
+ va_end(ap);
+
+ ret = of_set_property(np, propname, buf, len, 1);
+ free(buf);
+ return ret;
+}
+
/**
* of_property_write_string - Write a string to a property. If
* the property does not exist, it will be created and appended to the given
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 13/14] libdt: add partition search function
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (11 preceding siblings ...)
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 12/14] libdt: add of_property_write_strings support Marco Felsch
@ 2022-10-14 16:42 ` Marco Felsch
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 14/14] state: sync with barebox to support new backend type Marco Felsch
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:42 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
From: Juergen Borleis <jbe@pengutronix.de>
Add of_find_path() support which mimics the of_find_path() from barebox.
The purpose of this function is to get the device path specified by a
device-tree property like:
- proptery = &mmc2, partname:0;
- property = &of_partition;
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
[m.felsch@pengutronix.de: adapt commit message]
[m.felsch@pengutronix.de: fix of-partition use-case]
[m.felsch@pengutronix.de: use the correct udev_list_entry variable]
[m.felsch@pengutronix.de: of_find_path function behaviour with barebox]
[m.felsch@pengutronix.de: drop partuuid suport since barbeox don't support ot either]
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/dt/dt.h | 2 +
src/libdt-utils.sym | 1 +
src/libdt.c | 224 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 227 insertions(+)
diff --git a/src/dt/dt.h b/src/dt/dt.h
index 97dd855..7c27259 100644
--- a/src/dt/dt.h
+++ b/src/dt/dt.h
@@ -229,6 +229,8 @@ void of_add_memory_bank(struct device_node *node, bool dump, int r,
int of_get_devicepath(struct device_node *partition_node, char **devnode, off_t *offset,
size_t *size);
+int of_find_path(struct device_node *node, const char *propname, char **devpath,
+ off_t *offset, size_t *size);
#define for_each_node_by_name(dn, name) \
for (dn = of_find_node_by_name(NULL, name); dn; \
diff --git a/src/libdt-utils.sym b/src/libdt-utils.sym
index a749317..441c8ef 100644
--- a/src/libdt-utils.sym
+++ b/src/libdt-utils.sym
@@ -34,6 +34,7 @@ global:
of_get_child_by_name;
of_get_child_count;
of_get_devicepath;
+ of_find_path;
of_get_next_available_child;
of_get_parent;
of_get_property;
diff --git a/src/libdt.c b/src/libdt.c
index f18ea90..89ef501 100644
--- a/src/libdt.c
+++ b/src/libdt.c
@@ -30,6 +30,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <libudev.h>
+#include <limits.h>
#include <dt.h>
static int pr_level = 5;
@@ -2234,6 +2235,137 @@ out:
return ret;
}
+/**
+ * libdt_udev_scan_restrict - Restrict a udev scan to a specific device
+ * @e: The scan enumerater to restrict to a specific device
+ * @specifier: Describes the device in question in more detail
+ *
+ * Since property matches are or'ed, we can only add exactly one match based on
+ * a specific property value.
+ *
+ * Note: this function isn't thread save
+ */
+static int libdt_udev_scan_restrict(struct udev_enumerate *e, const char *specifier)
+{
+ static char part_number_match[16];
+ unsigned long int part_no;
+ char *eptr;
+
+ /*
+ * The variables: 'PARTN' (for <number>) or 'PARTNAME' (for <name>) can
+ * be queried by:
+ * udevadm info -q all /dev/<partition device node>
+ */
+
+ /* "partname:<name>" use case */
+ if (!isdigit(*specifier))
+ return udev_enumerate_add_match_property(e, "PARTNAME", specifier);
+
+ /*
+ * "partname:<number>" use case
+ * It's a little bit more complicated, since the bootloader
+ * counts beginning with '0', while userland counts
+ * beginning with '1'. Thus, we need to increase the partition
+ * number by one here - and we need it as a string.
+ */
+ part_no = strtoul(specifier, &eptr, 10);
+ if (part_no == 0 && specifier == eptr) {
+ fprintf(stderr, "Numerical partition count value expected - but found invalid value: '%s'\n", specifier);
+ return -EINVAL;
+ }
+ if (part_no == ULONG_MAX && errno == ERANGE) {
+ fprintf(stderr, "Numerical partition count expected - but found invalid number: '%s'\n", specifier);
+ return -ERANGE;
+ }
+
+ snprintf(part_number_match, sizeof(part_number_match), "%ld", part_no + 1);
+ udev_enumerate_add_match_property(e, "PARTN", part_number_match);
+ return 0;
+}
+
+/**
+ * device_find_blockdev_partition - Retrieve the device node path to a block device
+ * (which can be a of-partition as well)
+ * @parent: The base block device or of-partition
+ * @part_specifier: Specifier to define a unique partition on @parent
+ * @devpath: Return the corresponding path to the device node
+ * (e.g. /dev/<something>)
+ *
+ * Returns 0 on success (e.g. @devpath is valid) or a negative errno else
+ *
+ * @part_specifier is a string and can be one of:
+ * - "partname:<number>": restrict the scan to a partition with index <number> + 1
+ * - can be used in conjuntion with MBR or GPT partitions
+ * - "partname:<name>": restrict the scan to a partition with name <name>
+ * - can be used in conjuntion with GPT partitions
+ */
+static int device_find_blockdev_partition(struct udev_device *parent, const char *part_specifier, char **devpath)
+{
+ struct udev_list_entry *device_list, *dev_entry;
+ struct udev_enumerate *enumerate;
+ struct udev_device *part = NULL;
+ const char *devnode_path;
+ const char *sys_path;
+ struct udev *udev;
+ int ret;
+
+ udev = udev_new();
+ if (!udev) {
+ fprintf(stderr, "Failed to create udev context when retrieving block device nodes\n");
+ return -ENODEV;
+ }
+ /*
+ * Create an enumation context to match exactly one device
+ * Note: the following matches are and'ed (one per group)
+ */
+ enumerate = udev_enumerate_new(udev);
+
+ /* We are interested only in devices related to the given parent device */
+ udev_enumerate_add_match_parent(enumerate, parent);
+ /* We are interested only in subsystem 'block' devices */
+ udev_enumerate_add_match_subsystem(enumerate, "block");
+ /* We are interested in a unique ID */
+ ret = libdt_udev_scan_restrict(enumerate, part_specifier);
+ if (ret)
+ goto leave;
+
+ udev_enumerate_scan_devices(enumerate);
+
+ /* Note: this list should contain none or max *one* device */
+ device_list = udev_enumerate_get_list_entry(enumerate);
+ if (device_list == NULL) {
+ fprintf(stderr, "No device matches the partition specifier: '%s'\n", part_specifier);
+ ret = -ENODEV;
+ goto leave;
+ }
+
+ sys_path = udev_list_entry_get_name(device_list);
+ part = udev_device_new_from_syspath(udev, sys_path);
+ devnode_path = udev_device_get_devnode(part);
+
+ /* Ensure only one match is in the list */
+ dev_entry = udev_list_entry_get_next(device_list);
+ if (dev_entry == NULL) {
+ *devpath = strdup(devnode_path);
+ ret = 0;
+ } else {
+ fprintf(stderr, "Unexpected behaviour of udev matches: a single partition device node expected, but got more than one.\n");
+ fprintf(stderr, " One match to '%s'", devnode_path);
+ udev_device_unref(part);
+ sys_path = udev_list_entry_get_name(dev_entry);
+ part = udev_device_new_from_syspath(udev, sys_path);
+ fprintf(stderr, " and (at least) one more to '%s'\n", udev_device_get_devnode(part));
+ ret = -ENODEV;
+ }
+
+ udev_device_unref(part);
+leave:
+ udev_enumerate_unref(enumerate);
+ udev_unref(udev);
+
+ return ret;
+}
+
/*
* of_parse_partition - extract offset and size from a partition device_node
*
@@ -2532,3 +2664,95 @@ int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t
return -EINVAL;
}
+
+static int libdt_partition_size_get(const char *dev_node, size_t *size)
+{
+ struct stat fstat;
+ int rc;
+
+ rc = stat(dev_node, &fstat);
+ if (rc < 0) {
+ rc = -errno;
+ fprintf(stderr, "Failed to get the size of state's partition based backend memory via '%s': %m\n", dev_node);
+ return rc;
+ }
+
+ if (fstat.st_size > SIZE_MAX) {
+ fprintf(stderr, "Partition size of '%s' too big to fit into a size_t type. Cannot continue.\n", dev_node);
+ return -ERANGE;
+ }
+
+ *size = fstat.st_size;
+ return 0;
+}
+
+/**
+ * of_find_path - Translates a path description in the devicetree to a Linux
+ * device path
+ *
+ * @node: the node containing the property with the path description
+ * @propname: the property name of the path description
+ * @devpath: if this function returns 0 devpath will contain the path belonging
+ * to the input path description.
+ * @offset: Returns the offset to be used inside the partition device (always 0)
+ * @size: Returns the size of the partition device
+ *
+ * paths in the devicetree have the form of a multistring property. The first
+ * string contains the full path to the physical device containing the path or
+ * a full path to a partition described by the OF partition binding.
+ * The remaining strings have the form "<type>:<options>". Currently supported
+ * for <type> are:
+ *
+ * partname:<partname> - find a partition by its partition name. For mtd
+ * partitions this is the label. For DOS partitions
+ * this is the number beginning with 0.
+ *
+ * examples:
+ *
+ * device-path = &mmc0, "partname:0";
+ * device-path = &norflash, "partname:barebox-environment";
+ * device-path = &environment_nor;
+ */
+
+int of_find_path(struct device_node *node, const char *propname, char **devpath,
+ off_t *offset, size_t *size)
+{
+ const char partnamestr[] = "partname:";
+ struct device_node *rnode;
+ struct udev_device *udev;
+ const char *part = NULL;
+ const char *path;
+ int rc;
+
+ path = of_get_property(node, propname, NULL);
+ if (!path)
+ return -EINVAL;
+
+ rnode = of_find_node_by_path(path);
+ if (!rnode)
+ return -ENODEV;
+
+ of_property_read_string_index(node, propname, 1, &part);
+ if (part) {
+ if (!strncmp(part, partnamestr, sizeof(partnamestr) - 1)) {
+ part += sizeof(partnamestr) - 1;
+ } else {
+ pr_err("Invalid device-path: %s\n", part);
+ return -EINVAL;
+ }
+ } else {
+ /* of-partition use-case */
+ return of_get_devicepath(rnode, devpath, offset, size);
+ }
+
+ udev = of_find_device_by_node_path(rnode->full_name);
+ if (udev) {
+ *offset = 0;
+ rc = device_find_blockdev_partition(udev, part, devpath);
+ if (rc < 0)
+ return rc;
+ return libdt_partition_size_get(*devpath, size);
+ }
+
+ return -EINVAL;
+}
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [OSS-Tools] [PATCH dt-utils 14/14] state: sync with barebox to support new backend type
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (12 preceding siblings ...)
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 13/14] libdt: add partition search function Marco Felsch
@ 2022-10-14 16:42 ` Marco Felsch
2022-10-21 7:37 ` [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
2023-06-05 13:12 ` Ahmad Fatoum
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-14 16:42 UTC (permalink / raw)
To: oss-tools; +Cc: mfe
The state backend format was changed from a phandle based description to
a string based description. This was done because of the missing support
to store the state within a on-disk partition like MBR/GPT. By this sync
we import the code required to manipulate the state which is stored on a
on-disk partition.
Furthermore the sync did a few minor style fixes.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
src/barebox-state/state.c | 168 ++++++++++++++++++++++++++++----------
src/barebox-state/state.h | 6 +-
src/dt/common.h | 17 ++++
3 files changed, 145 insertions(+), 46 deletions(-)
diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index 4779574..e8c08d6 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -40,11 +40,11 @@ static LIST_HEAD(state_list);
*/
int state_save(struct state *state)
{
- void *buf;
- ssize_t len;
- int ret;
struct state_backend_storage_bucket *bucket;
struct state_backend_storage *storage;
+ ssize_t len;
+ void *buf;
+ int ret;
if (!state->dirty)
return 0;
@@ -211,13 +211,13 @@ static int state_convert_node_variable(struct state *state,
const char *parent_name,
enum state_convert conv)
{
+ struct device_node *new_node = NULL;
const struct variable_type *vtype;
+ char *short_name, *name, *indexs;
+ unsigned int start_size[2];
struct device_node *child;
- struct device_node *new_node = NULL;
struct state_variable *sv;
const char *type_name;
- char *short_name, *name, *indexs;
- unsigned int start_size[2];
int ret;
/* strip trailing @<ADDRESS> */
@@ -341,8 +341,8 @@ struct device_node *state_to_node(struct state *state,
struct device_node *parent,
enum state_convert conv)
{
- struct device_node *child;
struct device_node *root, *state_root;
+ struct device_node *child;
int ret;
state_root = of_find_node_by_path(state->of_path);
@@ -369,8 +369,8 @@ int state_from_node(struct state *state, struct device_node *node, bool create)
{
struct device_node *child;
enum state_convert conv;
- int ret;
uint32_t magic;
+ int ret;
ret = of_property_read_u32(node, "magic", &magic);
if (ret)
@@ -428,12 +428,11 @@ int state_from_node(struct state *state, struct device_node *node, bool create)
static int of_state_fixup(struct device_node *root, void *ctx)
{
- struct state *state = ctx;
- const char *compatible = "barebox,state";
struct device_node *new_node, *node, *parent, *backend_node, *aliases;
+ const char *compatible = "barebox,state";
+ struct state *state = ctx;
struct property *p;
int ret;
- phandle phandle;
node = of_find_node_by_path_from(root, state->of_path);
if (node) {
@@ -493,16 +492,26 @@ static int of_state_fixup(struct device_node *root, void *ctx)
/* backend phandle */
backend_node = of_find_node_by_reproducible_name(root,
- state->backend_reproducible_name);
+ state->backend_dts_dev_or_part);
if (!backend_node) {
ret = -ENODEV;
goto out;
}
- phandle = of_node_create_phandle(backend_node);
- ret = of_property_write_u32(new_node, "backend", phandle);
- if (ret)
- goto out;
+ if (state->backend_is_new_format) {
+ ret = of_property_write_strings(new_node, "backend",
+ backend_node->full_name,
+ state->backend_dts_partition, NULL);
+ if (ret)
+ goto out;
+ } else {
+ phandle phandle;
+
+ phandle = of_node_create_phandle(backend_node);
+ ret = of_property_write_u32(new_node, "backend", phandle);
+ if (ret)
+ goto out;
+ }
if (!strcmp("raw", state->format->name)) {
struct digest *digest =
@@ -572,12 +581,86 @@ void state_release(struct state *state)
unregister_device(&state->dev);
state_storage_free(&state->storage);
state_format_free(state->format);
- free(state->backend_path);
- free(state->backend_reproducible_name);
+ free(state->backend_dev_path);
+ free(state->backend_dts_dev_or_part);
+ free(state->backend_dts_partition);
free(state->of_path);
free(state);
}
+#ifdef __BAREBOX__
+
+#define state_of_find_path_by_node(node, path, flags, offset, size) \
+ of_find_path_by_node(node, path, flags)
+#define state_of_find_path(node, propname, outpath, flags, offset, size) \
+ of_find_path(node, propname, outpath, flags)
+
+#else
+
+#define state_of_find_path_by_node(node, path, flags, offset, size) \
+ of_get_devicepath(node, path, offset, size)
+#define state_of_find_path(node, propname, outpath, flags, offset, size) \
+ of_find_path(node, propname, outpath, offset, size)
+
+#endif /* __BAREBOX__ */
+
+static int
+state_parse_old_backend_format(struct device_node *backend_node,
+ struct state *state, off_t *offset, size_t *size)
+{
+ int ret;
+
+ ret = of_partition_ensure_probed(backend_node);
+ if (ret)
+ return ret;
+
+ ret = state_of_find_path_by_node(backend_node, &state->backend_dev_path,
+ 0, offset, size);
+ if (ret) {
+ if (ret != -EPROBE_DEFER)
+ dev_err(&state->dev, "state failed to parse path to backend: %s\n",
+ strerror(-ret));
+ return ret;
+ }
+
+ state->backend_dts_dev_or_part = of_get_reproducible_name(backend_node);
+
+ return 0;
+}
+
+static int
+state_parse_new_backend_format(struct device_node *state_node,
+ struct state *state, off_t *offset, size_t *size)
+{
+ struct device_node *backend_node;
+ const char *backend_dev_or_part;
+ const char *part = NULL;
+ int ret;
+
+ backend_dev_or_part = of_get_property(state_node, "backend", NULL);
+ if (!backend_dev_or_part)
+ return -EINVAL;
+
+ backend_node = of_find_node_by_path(backend_dev_or_part);
+ if (!backend_node)
+ return -ENODEV;
+
+ if (is_of_partition(backend_node))
+ ret = of_partition_ensure_probed(backend_node);
+ else
+ ret = of_device_ensure_probed(backend_node);
+ if (ret)
+ return ret;
+
+ of_property_read_string_index(state_node, "backend", 1, &part);
+ state->backend_dts_dev_or_part = of_get_reproducible_name(backend_node);
+ state->backend_dts_partition = xstrdup(part);
+ state->backend_is_new_format = true;
+
+ return state_of_find_path(state_node, "backend",
+ &state->backend_dev_path, 0, offset, size);
+}
+
/*
* state_new_from_node - create a new state instance from a device_node
*
@@ -587,15 +670,15 @@ void state_release(struct state *state)
*/
struct state *state_new_from_node(struct device_node *node, bool readonly)
{
- struct state *state;
- int ret = 0;
- const char *backend_type;
+ struct device_node *backend_node;
const char *storage_type = NULL;
- const char *alias;
+ const char *backend_type;
+ struct state *state;
uint32_t stridesize;
- struct device_node *partition_node;
+ const char *alias;
off_t offset = 0;
size_t size = 0;
+ int ret;
alias = of_alias_get(node);
if (!alias) {
@@ -607,26 +690,23 @@ struct state *state_new_from_node(struct device_node *node, bool readonly)
if (IS_ERR(state))
return state;
- partition_node = of_parse_phandle(node, "backend", 0);
- if (!partition_node) {
- dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n");
- ret = -EINVAL;
- goto out_release_state;
- }
-
-#ifdef __BAREBOX__
- ret = of_find_path_by_node(partition_node, &state->backend_path, 0);
-#else
- ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size);
-#endif
- if (ret) {
- if (ret != -EPROBE_DEFER)
- dev_err(&state->dev, "state failed to parse path to backend: %s\n",
- strerror(-ret));
+ /*
+ * backend can be in three formats:
+ * old) backend = <&state_part>;
+ * new) backend = &state_part;
+ * backend = &state_part_dev, "partname:0";
+ *
+ * Start with the old format for compatibility reasons.
+ */
+ backend_node = of_parse_phandle(node, "backend", 0);
+ if (backend_node)
+ ret = state_parse_old_backend_format(backend_node, state,
+ &offset, &size);
+ else
+ ret = state_parse_new_backend_format(node, state,
+ &offset, &size);
+ if (ret)
goto out_release_state;
- }
-
- state->backend_reproducible_name = of_get_reproducible_name(partition_node);
ret = of_property_read_string(node, "backend-type", &backend_type);
if (ret) {
@@ -649,7 +729,7 @@ struct state *state_new_from_node(struct device_node *node, bool readonly)
if (ret)
goto out_release_state;
- ret = state_storage_init(state, state->backend_path, offset,
+ ret = state_storage_init(state, state->backend_dev_path, offset,
size, stridesize, storage_type);
if (ret)
goto out_release_state;
@@ -744,7 +824,7 @@ void state_info(void)
if (state->format)
printf("(backend: %s, path: %s)\n",
state->format->name,
- state->backend_path);
+ state->backend_dev_path);
else
printf("(no backend)\n");
}
diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h
index 719f7e4..2d3ec41 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -118,8 +118,10 @@ struct state {
struct state_backend_format *format;
struct state_backend_storage storage;
- char *backend_path;
- char *backend_reproducible_name;
+ char *backend_dev_path;
+ char *backend_dts_dev_or_part;
+ char *backend_dts_partition;
+ bool backend_is_new_format;
};
enum state_convert {
diff --git a/src/dt/common.h b/src/dt/common.h
index 9b1c169..4cb0dc2 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -360,6 +360,23 @@ static inline int is_zero_ether_addr(const u8 *addr)
return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
}
+struct device_node;
+
+static inline int of_partition_ensure_probed(struct device_node *np)
+{
+ return 0;
+}
+
+static inline int of_device_ensure_probed(struct device_node *np)
+{
+ return 0;
+}
+
+static inline int is_of_partition(struct device_node *np)
+{
+ return 0;
+}
+
#define MAX_DRIVER_NAME 32
#define DEVICE_ID_SINGLE -1
--
2.30.2
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (13 preceding siblings ...)
2022-10-14 16:42 ` [OSS-Tools] [PATCH dt-utils 14/14] state: sync with barebox to support new backend type Marco Felsch
@ 2022-10-21 7:37 ` Marco Felsch
2023-06-05 13:12 ` Ahmad Fatoum
15 siblings, 0 replies; 17+ messages in thread
From: Marco Felsch @ 2022-10-21 7:37 UTC (permalink / raw)
To: oss-tools
Hi,
On 22-10-14, Marco Felsch wrote:
> Hi,
>
> this series sync the dt-utils barebox-state code base with a very recent
> barebox version [1]. The most import patch are patch13-14, since those adding
> the user-space support for the backend format. By this new
> backend-format we are able to store the barebox-state on a on-disk
> partition like MBR/GPT.
>
> [1] https://lore.barebox.org/barebox/20221014163534.3812272-1-m.felsch@pengutronix.de/T/#mb63a3ce9abdfc3091fff9d977e696232713fc247
As discussion showed, the approach of patches 13-14 will not make it
into mainline. Therefore please drop those. The rest can still be taken
since there is huge gap between barebox-code and this user-space code.
Regards,
Marco
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base
2022-10-14 16:41 [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
` (14 preceding siblings ...)
2022-10-21 7:37 ` [OSS-Tools] [PATCH dt-utils 00/14] Sync Barebox-State code base Marco Felsch
@ 2023-06-05 13:12 ` Ahmad Fatoum
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2023-06-05 13:12 UTC (permalink / raw)
To: Marco Felsch, oss-tools; +Cc: mfe
Hello Marco,
On 14.10.22 18:41, Marco Felsch wrote:
> Hi,
>
> this series sync the dt-utils barebox-state code base with a very recent
> barebox version [1]. The most import patch are patch13-14, since those adding
> the user-space support for the backend format. By this new
> backend-format we are able to store the barebox-state on a on-disk
> partition like MBR/GPT.
>
> [1] https://lore.barebox.org/barebox/20221014163534.3812272-1-m.felsch@pengutronix.de/T/#mb63a3ce9abdfc3091fff9d977e696232713fc247
I applied patches 1-12/14 to next. For the other two, I implemented an
alternative scheme that uses GPT Type UUIDs instead:
https://lore.pengutronix.org/oss-tools/20230531152253.1407395-1-a.fatoum@pengutronix.de/T/#t
https://lore.barebox.org/barebox/20230531145927.1399282-1-a.fatoum@pengutronix.de/T/#t
Thanks,
Ahmad
>
> Regards,
> Marco
>
> Juergen Borleis (1):
> libdt: add partition search function
>
> Marco Felsch (13):
> state: Remove duplicate incudes
> state: backend_raw: fix ignoring unpack failures
> state: backend_storage: deal gracefully with runtime bucket corruption
> state: treat state with all-invalid buckets as dirty
> state: remove param member from struct state_string
> state: remove param member from state_uint32, state_enum32, state_mac
> state: remove unused function
> state: propagate failure to fixup enum32 into DT
> state: add SPDX-License-Identifier for files without explicit license
> state: fix typos found with codespell
> common: xstrdup: don't panic on xstrdup(NULL)
> libdt: add of_property_write_strings support
> state: sync with barebox to support new backend type
>
> src/barebox-state/backend_format_raw.c | 6 +-
> src/barebox-state/backend_storage.c | 2 +
> src/barebox-state/state.c | 177 +++++++++++-----
> src/barebox-state/state.h | 12 +-
> src/barebox-state/state_variables.c | 38 ++--
> src/dt/common.h | 23 ++-
> src/dt/dt.h | 4 +
> src/libdt-utils.sym | 2 +
> src/libdt.c | 271 +++++++++++++++++++++++++
> 9 files changed, 452 insertions(+), 83 deletions(-)
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 17+ messages in thread