Files
operating-system/buildroot-external/patches/uboot/0001-CMD-read-string-from-fileinto-env.patch
Stefan Agner e916d9f93c Move patch to fix U-Boot 2021.10 build (#1576)
We only have a single U-Boot version currently, so there is no value in
storing the patch file in a version specific directory. This makes sure
U-Boot 2021.10 final release also has fileenv support.
2021-10-07 14:01:55 +02:00

98 lines
2.4 KiB
Diff

From d87c6d3bb3de5f574d472dc5390f3f162db81823 Mon Sep 17 00:00:00 2001
Message-Id: <d87c6d3bb3de5f574d472dc5390f3f162db81823.1632759065.git.stefan@agner.ch>
From: Pascal Vizeli <pvizeli@syshack.ch>
Date: Sun, 5 Aug 2018 20:43:03 +0000
Subject: [PATCH] CMD: read string from fileinto env
Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch>
---
cmd/Kconfig | 5 +++++
cmd/Makefile | 1 +
cmd/fileenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+)
create mode 100644 cmd/fileenv.c
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 3a857b3f6e..9dc88988ac 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1422,6 +1422,11 @@ config CMD_SETEXPR_FMT
Evaluate format string expression and store result in an environment
variable.
+config CMD_FILEENV
+ bool "fileenv"
+ help
+ Read a file into memory and store it to env.
+
endmenu
menu "Android support commands"
diff --git a/cmd/Makefile b/cmd/Makefile
index ed3669411e..a11b4b692e 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -142,6 +142,7 @@ obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
+obj-$(CONFIG_CMD_FILEENV) += fileenv.o
obj-$(CONFIG_CMD_SPI) += spi.o
obj-$(CONFIG_CMD_STRINGS) += strings.o
obj-$(CONFIG_CMD_SMC) += smccc.o
diff --git a/cmd/fileenv.c b/cmd/fileenv.c
new file mode 100644
index 0000000000..9891cb05ab
--- /dev/null
+++ b/cmd/fileenv.c
@@ -0,0 +1,46 @@
+#include <config.h>
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <linux/ctype.h>
+
+static char *fs_argv[5];
+
+int do_fileenv(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
+{
+ if (argc < 6)
+ return CMD_RET_USAGE;
+
+ fs_argv[0] = "fatload";
+ fs_argv[1] = argv[1];
+ fs_argv[2] = argv[2];
+ fs_argv[3] = argv[3];
+ fs_argv[4] = argv[4];
+
+ if (do_fat_fsload(cmdtp, 0, 5, fs_argv) != 0)
+ return 1;
+
+ char *addr = (char *)simple_strtoul(argv[3], NULL, 16);
+ size_t size = env_get_hex("filesize", 0);
+
+ // Prepare string
+ addr[size] = 0x00;
+ char *s = addr;
+ while(*s != 0x00) {
+ if (isprint(*s)) {
+ s++;
+ }
+ else {
+ *s = 0x00;
+ }
+ }
+
+ return env_set(argv[5], addr);
+}
+
+U_BOOT_CMD(
+ fileenv, 6, 0, do_fileenv,
+ "Read file and store it into env.",
+ "<interface> <dev:part> <addr> <filename> <envname>\n"
+ " - Read file from fat32 and store it as env."
+);
--
2.33.0