#define LOG_CATEGORY UCLASS_BOOTSTD
-#include <common.h>
#include <blk.h>
#include <bootflow.h>
#include <bootmeth.h>
return ops->set_bootflow(dev, bflow, buf, size);
}
+#if CONFIG_IS_ENABLED(BOOTSTD_FULL)
+int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow)
+{
+ const struct bootmeth_ops *ops = bootmeth_get_ops(dev);
+
+ if (!ops->read_all)
+ return -ENOSYS;
+
+ return ops->read_all(dev, bflow);
+}
+#endif /* BOOTSTD_FULL */
+
int bootmeth_boot(struct udevice *dev, struct bootflow *bflow)
{
const struct bootmeth_ops *ops = bootmeth_get_ops(dev);
return 0;
}
-/**
- * setup_fs() - Set up read to read a file
- *
- * We must redo the setup before each filesystem operation. This function
- * handles that, including setting the filesystem type if a block device is not
- * being used
- *
- * @bflow: Information about file to try
- * @desc: Block descriptor to read from (NULL if not a block device)
- * Return: 0 if OK, -ve on error
- */
-static int setup_fs(struct bootflow *bflow, struct blk_desc *desc)
+int bootmeth_set_property(const char *name, const char *property, const char *value)
+{
+ int ret;
+ int len;
+ struct udevice *dev;
+ const struct bootmeth_ops *ops;
+
+ len = strlen(name);
+
+ ret = uclass_find_device_by_namelen(UCLASS_BOOTMETH, name, len,
+ &dev);
+ if (ret) {
+ printf("Unknown bootmeth '%s'\n", name);
+ return ret;
+ }
+
+ ops = bootmeth_get_ops(dev);
+ if (!ops->set_property) {
+ printf("set_property not found\n");
+ return -ENODEV;
+ }
+
+ return ops->set_property(dev, property, value);
+}
+
+int bootmeth_setup_fs(struct bootflow *bflow, struct blk_desc *desc)
{
int ret;
log_debug(" %s - err=%d\n", path, ret);
/* Sadly FS closes the file after fs_size() so we must redo this */
- ret2 = setup_fs(bflow, desc);
+ ret2 = bootmeth_setup_fs(bflow, desc);
if (ret2)
return log_msg_ret("fs", ret2);
return 0;
}
-static int alloc_file(const char *fname, uint size, void **bufp)
-{
- loff_t bytes_read;
- ulong addr;
- char *buf;
- int ret;
-
- buf = malloc(size + 1);
- if (!buf)
- return log_msg_ret("buf", -ENOMEM);
- addr = map_to_sysmem(buf);
-
- ret = fs_read(fname, addr, 0, size, &bytes_read);
- if (ret) {
- free(buf);
- return log_msg_ret("read", ret);
- }
- if (size != bytes_read)
- return log_msg_ret("bread", -EIO);
- buf[size] = '\0';
-
- *bufp = buf;
-
- return 0;
-}
-
int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
{
void *buf;
if (size > size_limit)
return log_msg_ret("chk", -E2BIG);
- ret = alloc_file(bflow->fname, bflow->size, &buf);
+ ret = fs_read_alloc(bflow->fname, bflow->size, align, &buf);
if (ret)
return log_msg_ret("all", ret);
if (bflow->blk)
desc = dev_get_uclass_plat(bflow->blk);
- ret = setup_fs(bflow, desc);
+ ret = bootmeth_setup_fs(bflow, desc);
if (ret)
return log_msg_ret("fs", ret);
ret = fs_size(path, &size);
log_debug(" %s - err=%d\n", path, ret);
- ret = setup_fs(bflow, desc);
+ ret = bootmeth_setup_fs(bflow, desc);
if (ret)
return log_msg_ret("fs", ret);
- ret = alloc_file(path, size, &buf);
+ ret = fs_read_alloc(path, size, 0, &buf);
if (ret)
return log_msg_ret("all", ret);
if (bflow->blk)
desc = dev_get_uclass_plat(bflow->blk);
- ret = setup_fs(bflow, desc);
+ ret = bootmeth_setup_fs(bflow, desc);
if (ret)
return log_msg_ret("fs", ret);
if (size > *sizep)
return log_msg_ret("spc", -ENOSPC);
- ret = setup_fs(bflow, desc);
+ ret = bootmeth_setup_fs(bflow, desc);
if (ret)
return log_msg_ret("fs", ret);
/**
* on_bootmeths() - Update the bootmeth order
*
- * This will check for a valid baudrate and only apply it if valid.
+ * This will check for a valid list of bootmeths and only apply it if valid.
*/
static int on_bootmeths(const char *name, const char *value, enum env_op op,
int flags)