@@ -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;
@@ -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)
@@ -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
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 <mathias.thore@atlascopco.com> --- src/extended_config.c | 6 ++---- src/uboot_env.c | 2 ++ src/uboot_private.h | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-)