|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ricardo Pardini < [email protected]> |
| 3 | +Date: Fri, 31 Jan 2025 15:52:03 +0100 |
| 4 | +Subject: cmd: fileenv: read string from file into env |
| 5 | + |
| 6 | +- rpardini: adapted from vendor/legacy patch from 2018 |
| 7 | + |
| 8 | +Signed-off-by: Pascal Vizeli < [email protected]> |
| 9 | +Signed-off-by: Stefan Agner < [email protected]> |
| 10 | +Signed-off-by: Ricardo Pardini < [email protected]> |
| 11 | +--- |
| 12 | + cmd/Kconfig | 5 + |
| 13 | + cmd/Makefile | 1 + |
| 14 | + cmd/fileenv.c | 46 ++++++++++ |
| 15 | + 3 files changed, 52 insertions(+) |
| 16 | + |
| 17 | +diff --git a/cmd/Kconfig b/cmd/Kconfig |
| 18 | +index 111111111111..222222222222 100644 |
| 19 | +--- a/cmd/Kconfig |
| 20 | ++++ b/cmd/Kconfig |
| 21 | +@@ -1792,6 +1792,11 @@ config CMD_XXD |
| 22 | + help |
| 23 | + Print file as hexdump to standard output |
| 24 | + |
| 25 | ++config CMD_FILEENV |
| 26 | ++ bool "fileenv" |
| 27 | ++ help |
| 28 | ++ Read a file into memory and store it to env. |
| 29 | ++ |
| 30 | + endmenu |
| 31 | + |
| 32 | + if NET || NET_LWIP |
| 33 | +diff --git a/cmd/Makefile b/cmd/Makefile |
| 34 | +index 111111111111..222222222222 100644 |
| 35 | +--- a/cmd/Makefile |
| 36 | ++++ b/cmd/Makefile |
| 37 | +@@ -170,6 +170,7 @@ obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o |
| 38 | + obj-$(CONFIG_CMD_SEAMA) += seama.o |
| 39 | + obj-$(CONFIG_CMD_SETEXPR) += setexpr.o |
| 40 | + obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o |
| 41 | ++obj-$(CONFIG_CMD_FILEENV) += fileenv.o |
| 42 | + obj-$(CONFIG_CMD_SPI) += spi.o |
| 43 | + obj-$(CONFIG_CMD_STRINGS) += strings.o |
| 44 | + obj-$(CONFIG_CMD_SMBIOS) += smbios.o |
| 45 | +diff --git a/cmd/fileenv.c b/cmd/fileenv.c |
| 46 | +new file mode 100644 |
| 47 | +index 000000000000..111111111111 |
| 48 | +--- /dev/null |
| 49 | ++++ b/cmd/fileenv.c |
| 50 | +@@ -0,0 +1,46 @@ |
| 51 | ++#include <config.h> |
| 52 | ++#include <command.h> |
| 53 | ++#include <fs.h> |
| 54 | ++#include <linux/ctype.h> |
| 55 | ++#include <vsprintf.h> |
| 56 | ++ |
| 57 | ++static char *fs_argv[5]; |
| 58 | ++ |
| 59 | ++int do_fileenv(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) |
| 60 | ++{ |
| 61 | ++ if (argc < 6) |
| 62 | ++ return CMD_RET_USAGE; |
| 63 | ++ |
| 64 | ++ fs_argv[0] = "fatload"; |
| 65 | ++ fs_argv[1] = argv[1]; |
| 66 | ++ fs_argv[2] = argv[2]; |
| 67 | ++ fs_argv[3] = argv[3]; |
| 68 | ++ fs_argv[4] = argv[4]; |
| 69 | ++ |
| 70 | ++ if (do_fat_fsload(cmdtp, 0, 5, fs_argv) != 0) |
| 71 | ++ return 1; |
| 72 | ++ |
| 73 | ++ char *addr = (char *)simple_strtoul(argv[3], NULL, 16); |
| 74 | ++ size_t size = env_get_hex("filesize", 0); |
| 75 | ++ |
| 76 | ++ // Prepare string |
| 77 | ++ addr[size] = 0x00; |
| 78 | ++ char *s = addr; |
| 79 | ++ while(*s != 0x00) { |
| 80 | ++ if (isprint(*s)) { |
| 81 | ++ s++; |
| 82 | ++ } |
| 83 | ++ else { |
| 84 | ++ *s = 0x00; |
| 85 | ++ } |
| 86 | ++ } |
| 87 | ++ |
| 88 | ++ return env_set(argv[5], addr); |
| 89 | ++} |
| 90 | ++ |
| 91 | ++U_BOOT_CMD( |
| 92 | ++ fileenv, 6, 0, do_fileenv, |
| 93 | ++ "Read file and store it into env.", |
| 94 | ++ "<interface> <dev:part> <addr> <filename> <envname>\n" |
| 95 | ++ " - Read file from fat32 and store it as env." |
| 96 | ++); |
| 97 | +-- |
| 98 | +Armbian |
| 99 | + |
0 commit comments