Currently, all device paths listed in yaml config file must be
available, or fw_printenv will bail out with the error message "Cannot
initialize environment", even if the missing device path belongs to a
namespace that won't be accessed. This situation can arise in systems
with environments on removable media.
This patch aims to defer the error checking until the device path is
actually accessed, by collecting error flags during config file
parsing, and checking the flags only when the device path is accessed.
Signed-off-by: Mathias Thore <
mathia...@atlascopco.com>
---
src/extended_config.c | 6 ++----
src/uboot_env.c | 2 ++
src/uboot_private.h | 4 ++++
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/extended_config.c b/src/extended_config.c
index ec814f4..7e4fac7 100644
--- a/src/extended_config.c
+++ b/src/extended_config.c
@@ -231,7 +231,7 @@ static int consume_event(struct parser_state *s, yaml_event_t *event)
break;
case YAML_MAPPING_END_EVENT:
dev = &s->ctx->envdevs[s->cdev];
- if (check_env_device(dev) < 0) {
+ if (!dev->error_mask && check_env_device(dev) < 0) {
s->error = YAML_BAD_DEVICE;
s->event_type = event->type;
return FAILURE;
@@ -335,9 +335,7 @@ static int consume_event(struct parser_state *s, yaml_event_t *event)
dev = &s->ctx->envdevs[s->cdev];
value = (char *)event->data.scalar.value;
if (normalize_device_path(value, dev) < 0) {
- s->error = YAML_BAD_DEVNAME;
- s->event_type = event->type;
- return FAILURE;
+ dev->error_mask |= DEVICE_ERROR_BAD_DEVNAME;
}
dev->envsize = s->ctx->size;
s->state = STATE_DEVVALUES;
diff --git a/src/uboot_env.c b/src/uboot_env.c
index d8b93da..8da0763 100644
--- a/src/uboot_env.c
+++ b/src/uboot_env.c
@@ -322,6 +322,8 @@ static int devread(struct uboot_ctx *ctx, unsigned int copy, void *data)
return -EINVAL;
dev = &ctx->envdevs[copy];
+ if (dev->error_mask)
+ return -EBADF;
dev->fd = open(dev->devname, O_RDONLY);
if (dev->fd < 0)
diff --git a/src/uboot_private.h b/src/uboot_private.h
index 4e96d9e..7f0ec88 100644
--- a/src/uboot_private.h
+++ b/src/uboot_private.h
@@ -90,6 +90,8 @@ enum device_type {
DEVICE_UBI,
};
+#define DEVICE_ERROR_BAD_DEVNAME 1
+
/**
* U-Boot environment should always be redundant, but
* for compatibility reasons a single copy must
@@ -137,6 +139,8 @@ struct uboot_flash_env {
enum device_type device_type;
/** Disable lock mechanism (required by some flashes */
int disable_mtd_lock;
+ /** error flags collected during config parsing */
+ uint32_t error_mask;
};
/** Internal structure for an environment variable
--
2.43.0