]> git.ipfire.org Git - thirdparty/u-boot.git/blobdiff - fs/fs.c
part: Add accessors for struct disk_partition uuid
[thirdparty/u-boot.git] / fs / fs.c
diff --git a/fs/fs.c b/fs/fs.c
index c3a2ed97541c1a2dfbf28c4ca80ae72be1c86a41..2b815b1db0fed61086a27528aa5bc9a28efa05c8 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -7,11 +7,13 @@
 
 #include <command.h>
 #include <config.h>
+#include <display_options.h>
 #include <errno.h>
 #include <common.h>
 #include <env.h>
 #include <lmb.h>
 #include <log.h>
+#include <malloc.h>
 #include <mapmem.h>
 #include <part.h>
 #include <ext4fs.h>
@@ -25,6 +27,7 @@
 #include <asm/io.h>
 #include <div64.h>
 #include <linux/math64.h>
+#include <linux/sizes.h>
 #include <efi_loader.h>
 #include <squashfs.h>
 #include <erofs.h>
@@ -36,6 +39,11 @@ static int fs_dev_part;
 static struct disk_partition fs_partition;
 static int fs_type = FS_TYPE_ANY;
 
+void fs_set_type(int type)
+{
+       fs_type = type;
+}
+
 static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
                                      struct disk_partition *fs_partition)
 {
@@ -177,7 +185,7 @@ struct fstype_info {
 };
 
 static struct fstype_info fstypes[] = {
-#ifdef CONFIG_FS_FAT
+#if CONFIG_IS_ENABLED(FS_FAT)
        {
                .fstype = FS_TYPE_FAT,
                .name = "fat",
@@ -267,6 +275,7 @@ static struct fstype_info fstypes[] = {
                .ln = fs_ln_unsupported,
        },
 #endif
+#ifndef CONFIG_SPL_BUILD
 #ifdef CONFIG_CMD_UBIFS
        {
                .fstype = FS_TYPE_UBIFS,
@@ -286,6 +295,8 @@ static struct fstype_info fstypes[] = {
                .ln = fs_ln_unsupported,
        },
 #endif
+#endif
+#ifndef CONFIG_SPL_BUILD
 #ifdef CONFIG_FS_BTRFS
        {
                .fstype = FS_TYPE_BTRFS,
@@ -305,7 +316,8 @@ static struct fstype_info fstypes[] = {
                .ln = fs_ln_unsupported,
        },
 #endif
-#if IS_ENABLED(CONFIG_FS_SQUASHFS)
+#endif
+#if CONFIG_IS_ENABLED(FS_SQUASHFS)
        {
                .fstype = FS_TYPE_SQUASHFS,
                .name = "squashfs",
@@ -998,3 +1010,59 @@ int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
        puts("\n");
        return CMD_RET_SUCCESS;
 }
+
+int fs_read_alloc(const char *fname, ulong size, uint align, void **bufp)
+{
+       loff_t bytes_read;
+       ulong addr;
+       char *buf;
+       int ret;
+
+       buf = memalign(align, 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 fs_load_alloc(const char *ifname, const char *dev_part_str,
+                 const char *fname, ulong max_size, ulong align, void **bufp,
+                 ulong *sizep)
+{
+       loff_t size;
+       void *buf;
+       int ret;
+
+       if (fs_set_blk_dev(ifname, dev_part_str, FS_TYPE_ANY))
+               return log_msg_ret("set", -ENOMEDIUM);
+
+       ret = fs_size(fname, &size);
+       if (ret)
+               return log_msg_ret("sz", -ENOENT);
+
+       if (size >= (max_size ?: SZ_1G))
+               return log_msg_ret("sz", -E2BIG);
+
+       if (fs_set_blk_dev(ifname, dev_part_str, FS_TYPE_ANY))
+               return log_msg_ret("set", -ENOMEDIUM);
+
+       ret = fs_read_alloc(fname, size, align, &buf);
+       if (ret)
+               return log_msg_ret("al", ret);
+       *sizep = size;
+       *bufp = buf;
+
+       return 0;
+}