Extend bootmeth_openwrt's boot() to handle all three storage backends:

- Block devices: detected via bflow->blk, uses image_loader_init_blk()
  (existing path, refactored into openwrt_boot_blk() helper)
- UBI volumes: detected by checking the bootdev driver name
  ("ubi_bootdev"), uses image_loader_init_ubi() with the volume name
  from bflow->bootmeth_priv
- MTD partitions: fallback for non-block bootflows with a priv string,
  uses image_loader_init_mtd() with the partition name

The check() function does not need changes: bootflow_iter_check_blk()
already accepts non-network bootdevs including UCLASS_MTD parents.

The rest of boot() remains identical across backends — bootm_init(),
optional bootconf config selection, bootm_run(), cleanup on error.
Each backend path is guarded by IS_ENABLED(CONFIG_BOOTDEV_*) to
avoid link errors when not configured.

Signed-off-by: Daniel Golle <[email protected]>
---
 boot/bootmeth_openwrt.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/boot/bootmeth_openwrt.c b/boot/bootmeth_openwrt.c
index 82f39c17d7f..e1f47b58f61 100644
--- a/boot/bootmeth_openwrt.c
+++ b/boot/bootmeth_openwrt.c
@@ -73,21 +73,38 @@ static int openwrt_read_bootflow(struct udevice *dev, 
struct bootflow *bflow)
        return 0;
 }
 
-static int openwrt_boot(struct udevice *dev, struct bootflow *bflow)
+static int openwrt_boot_blk(struct bootflow *bflow,
+                           struct image_loader *ldr)
 {
        struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);
        const char *ifname = blk_get_devtype(bflow->blk);
+       char dev_part_str[32];
+
+       snprintf(dev_part_str, sizeof(dev_part_str), "%d:%d",
+                desc->devnum, bflow->part);
+
+       return image_loader_init_blk(ldr, ifname, dev_part_str);
+}
+
+static int openwrt_boot(struct udevice *dev, struct bootflow *bflow)
+{
        struct image_loader ldr = {};
        struct bootm_info bmi;
-       char dev_part_str[32];
        char addr_img[64];
        const char *conf;
        int ret;
 
-       snprintf(dev_part_str, sizeof(dev_part_str), "%d:%d",
-                desc->devnum, bflow->part);
-
-       ret = image_loader_init_blk(&ldr, ifname, dev_part_str);
+       if (bflow->blk) {
+               ret = openwrt_boot_blk(bflow, &ldr);
+       } else if (IS_ENABLED(CONFIG_BOOTDEV_UBI) &&
+                  !strcmp(bflow->dev->driver->name, "ubi_bootdev")) {
+               ret = image_loader_init_ubi(&ldr, bflow->bootmeth_priv);
+       } else if (IS_ENABLED(CONFIG_BOOTDEV_MTD) &&
+                  bflow->bootmeth_priv) {
+               ret = image_loader_init_mtd(&ldr, bflow->bootmeth_priv);
+       } else {
+               return log_msg_ret("typ", -ENODEV);
+       }
        if (ret)
                return log_msg_ret("ldr", ret);
 
-- 
2.53.0

Reply via email to