Skip to content

Commit b85fc8d

Browse files
sjg20trini
authored andcommitted
bootstd: Add a default method to get bootflows
The code in these functions turns out to often be the same. Add a default get_bootflow() function and allow the drivers to select it by setting the method to NULL. This saves a little code space. Signed-off-by: Simon Glass <sjg@chromium.org>
1 parent 3a2cb96 commit b85fc8d

File tree

4 files changed

+29
-52
lines changed

4 files changed

+29
-52
lines changed

boot/bootdev-uclass.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,37 @@ int bootdev_find_by_any(const char *name, struct udevice **devp)
450450
return 0;
451451
}
452452

453+
static int default_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
454+
struct bootflow *bflow)
455+
{
456+
struct udevice *blk;
457+
int ret;
458+
459+
ret = bootdev_get_sibling_blk(dev, &blk);
460+
/*
461+
* If there is no media, indicate that no more partitions should be
462+
* checked
463+
*/
464+
if (ret == -EOPNOTSUPP)
465+
ret = -ESHUTDOWN;
466+
if (ret)
467+
return log_msg_ret("blk", ret);
468+
assert(blk);
469+
ret = bootdev_find_in_blk(dev, blk, iter, bflow);
470+
if (ret)
471+
return log_msg_ret("find", ret);
472+
473+
return 0;
474+
}
475+
453476
int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
454477
struct bootflow *bflow)
455478
{
456479
const struct bootdev_ops *ops = bootdev_get_ops(dev);
457480

458-
if (!ops->get_bootflow)
459-
return -ENOSYS;
460481
bootflow_init(bflow, dev, iter->method);
482+
if (!ops->get_bootflow)
483+
return default_get_bootflow(dev, iter, bflow);
461484

462485
return ops->get_bootflow(dev, iter, bflow);
463486
}

drivers/mmc/mmc_bootdev.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,6 @@
1111
#include <dm.h>
1212
#include <mmc.h>
1313

14-
static int mmc_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
15-
struct bootflow *bflow)
16-
{
17-
struct udevice *mmc_dev = dev_get_parent(dev);
18-
struct udevice *blk;
19-
int ret;
20-
21-
ret = mmc_get_blk(mmc_dev, &blk);
22-
/*
23-
* If there is no media, indicate that no more partitions should be
24-
* checked
25-
*/
26-
if (ret == -EOPNOTSUPP)
27-
ret = -ESHUTDOWN;
28-
if (ret)
29-
return log_msg_ret("blk", ret);
30-
assert(blk);
31-
ret = bootdev_find_in_blk(dev, blk, iter, bflow);
32-
if (ret)
33-
return log_msg_ret("find", ret);
34-
35-
return 0;
36-
}
37-
3814
static int mmc_bootdev_bind(struct udevice *dev)
3915
{
4016
struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
@@ -45,7 +21,6 @@ static int mmc_bootdev_bind(struct udevice *dev)
4521
}
4622

4723
struct bootdev_ops mmc_bootdev_ops = {
48-
.get_bootflow = mmc_get_bootflow,
4924
};
5025

5126
static const struct udevice_id mmc_bootdev_ids[] = {

drivers/usb/host/usb_bootdev.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@
1111
#include <dm.h>
1212
#include <usb.h>
1313

14-
static int usb_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
15-
struct bootflow *bflow)
16-
{
17-
struct udevice *blk;
18-
int ret;
19-
20-
ret = bootdev_get_sibling_blk(dev, &blk);
21-
/*
22-
* If there is no media, indicate that no more partitions should be
23-
* checked
24-
*/
25-
if (ret == -EOPNOTSUPP)
26-
ret = -ESHUTDOWN;
27-
if (ret)
28-
return log_msg_ret("blk", ret);
29-
assert(blk);
30-
ret = bootdev_find_in_blk(dev, blk, iter, bflow);
31-
if (ret)
32-
return log_msg_ret("find", ret);
33-
34-
return 0;
35-
}
36-
3714
static int usb_bootdev_bind(struct udevice *dev)
3815
{
3916
struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
@@ -44,7 +21,6 @@ static int usb_bootdev_bind(struct udevice *dev)
4421
}
4522

4623
struct bootdev_ops usb_bootdev_ops = {
47-
.get_bootflow = usb_get_bootflow,
4824
};
4925

5026
static const struct udevice_id usb_bootdev_ids[] = {

include/bootdev.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ struct bootdev_uc_plat {
5050
/** struct bootdev_ops - Operations for the bootdev uclass */
5151
struct bootdev_ops {
5252
/**
53-
* get_bootflow() - get a bootflow
53+
* get_bootflow() - get a bootflow (optional)
54+
*
55+
* If this is NULL then the default implementaton is used, which is
56+
* default_get_bootflow()
5457
*
5558
* @dev: Bootflow device to check
5659
* @iter: Provides current dev, part, method to get. Should update

0 commit comments

Comments
 (0)