bootstd: Add a way to set up a bootflow

Add a function to init a bootflow, to reduce code duplication.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2022-10-20 18:22:51 -06:00 committed by Tom Rini
parent cbd71fad6d
commit b190deb895
4 changed files with 23 additions and 8 deletions

View file

@ -440,10 +440,7 @@ int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
if (!ops->get_bootflow)
return -ENOSYS;
memset(bflow, '\0', sizeof(*bflow));
bflow->dev = dev;
bflow->method = iter->method;
bflow->state = BOOTFLOWST_BASE;
bootflow_init(bflow, dev, iter->method);
return ops->get_bootflow(dev, iter, bflow);
}

View file

@ -339,6 +339,15 @@ int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow)
} while (1);
}
void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
struct udevice *meth)
{
memset(bflow, '\0', sizeof(*bflow));
bflow->dev = bootdev;
bflow->method = meth;
bflow->state = BOOTFLOWST_BASE;
}
void bootflow_free(struct bootflow *bflow)
{
free(bflow->name);

View file

@ -77,10 +77,7 @@ int bootmeth_get_bootflow(struct udevice *dev, struct bootflow *bflow)
if (!ops->read_bootflow)
return -ENOSYS;
memset(bflow, '\0', sizeof(*bflow));
bflow->dev = NULL;
bflow->method = dev;
bflow->state = BOOTFLOWST_BASE;
bootflow_init(bflow, NULL, dev);
return ops->read_bootflow(dev, bflow);
}

View file

@ -144,6 +144,18 @@ struct bootflow_iter {
bool doing_global;
};
/**
* bootflow_init() - Set up a bootflow struct
*
* The bootflow is zeroed and set to state BOOTFLOWST_BASE
*
* @bflow: Struct to set up
* @bootdev: Bootdev to use
* @meth: Bootmeth to use
*/
void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
struct udevice *meth);
/**
* bootflow_iter_init() - Reset a bootflow iterator
*