summaryrefslogtreecommitdiff
path: root/fs/fs.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-07-14 13:26:42 -0400
committerTom Rini <trini@konsulko.com>2023-07-14 13:26:42 -0400
commitb3bbad816e97538c8c3b8acad7c7e134261cf3a3 (patch)
tree0cfdcc657a9e0b3a5cf91e5fbb3ef2415aa2b12f /fs/fs.c
parentcef36755094f0c5463ff34ac89de8d88ef68982b (diff)
parent04f3dcd503a537fab50329686874559dae8a1a22 (diff)
Merge branch '2023-07-14-expo-initial-config-editor'
To quote the author: This series provides a means to edit board configuration in U-Boot in a graphical manner. It supports multiple menu items and allows moving between them and selecting items. The configuration is defined in a data format so that code is not needed in most cases. This allows the board configuration to be provided in the devicetree. This is still at an early stage, since it only supports menus. Numeric values are not supported. Most importantly it does not yet support loading or saving the configuration selected by the user. To try it out you can use something like: ./tools/expo.py -e test/boot/files/expo_layout.dts \ -l test/boot/files/expo_layout.dts -o cedit.dtb ./u-boot -Tl -c "cedit load hostfs - cedit.dtb; cedit run" Use the arrow keys to move between menus, enter to open a menu, escape to exit. Various minor fixes and improvements are provided in this series: - Update STB TrueType library to latest - Support clearing part of the video display - Support multiple livetrees loaded at runtime - Support loading and allocating a file - Support proper measuring of text in expo - Support simple themes for expo
Diffstat (limited to 'fs/fs.c')
-rw-r--r--fs/fs.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 8324b4a22f2..2b815b1db0f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -13,6 +13,7 @@
#include <env.h>
#include <lmb.h>
#include <log.h>
+#include <malloc.h>
#include <mapmem.h>
#include <part.h>
#include <ext4fs.h>
@@ -26,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>
@@ -1008,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;
+}