openwrt-6.x/package/boot/uboot-mediatek/patches/220-cmd-env-readmem.patch
Daniel Golle 011ba05fd3 uboot-mediatek: update to U-Boot v2025.10
The most relevant change is the removal of the empty board_init()
functions by u-boot/u-boot@70a4d1fa1d, which makes many patches not
apply anymore and also requires most board defconfigs to be updated
by adding "# CONFIG_BOARD_INIT is not set" to them.

Also some config symbols have been renamed and downstream boards
had to be adapted accordingly:

u-boot/u-boot@0fd9a3480a ("env: Rename OVERWRITE_ETHADDR_ONCE to
                            ENV_OVERWRITE_ETHADDR_ONCE")

u-boot/u-boot@5fb88fa725 ("env: Rename SYS_REDUNDAND_ENVIRONMENT to
                            ENV_REDUNDANT")

u-boot/u-boot@123682c765 ("env: Rename SYS_RELOC_GD_ENV_ADDR to
                            ENV_RELOC_GD_ENV_ADDR")

u-boot/u-boot@0f44d5549e ("env: Rename SYS_MMC_ENV_DEV to
                            ENV_MMC_DEVICE_INDEX")

u-boot/u-boot@31617b880a ("env: Rename SYS_MMC_ENV_PART to
                            ENV_MMC_EMMC_HW_PARTITION")

u-boot/u-boot@ffc4914703 ("env: Rename ENV_MMC_PARTITION to
                            ENV_MMC_SW_PARTITION")

u-boot/u-boot@fb5235239a ("env: Rename DEFAULT_ENV_FILE to
                            ENV_DEFAULT_ENV_TEXT_FILE")

(also renamed USE_DEFAULT_ENV_FILE to USE_ENV_DEFAULT_ENV_TEXT_FILE)

Remove upstreamed patches:
 * 001-mtd-spinand-winbond-add-Winbond-W25N04KV-flash-suppo.patch
   u-boot/u-boot@fe37fb8214

 * 002-mtd-spinand-gigadevice-sync-supported-chips-with-lin.patch
   u-boot/u-boot@506ceddffd

 * 003-net-mediatek-correct-the-AN8855-TPID-value-in-port-i.patch
   u-boot/u-boot@70db2be9fb

 * 004-01-serial-mediatek-fix-register-names-and-offsets.patch
   u-boot/u-boot@6e15d3f91a

 * 004-02-serial-mediatek-enable-baudrate-accuracy-compensatio.patch
   u-boot/u-boot@6952209ef2

 * 005-clk-mediatek-add-dummy-clk-enable-disable-ops-for-ap.patch
   u-boot/u-boot@1bf2121297

 * 006-env-Fix-possible-out-of-bound-access-in-env_do_env_s.patch
   u-boot/u-boot@0ffd456516

 * 130-01-env-mtd-add-the-missing-put_mtd_device.patch
   u-boot/u-boot@39ae954b04

 * 130-02-env-mtd-initialize-saved_buf-pointer.patch
   u-boot/u-boot@7e842bd331

 * 170-cmd-bootmenu-permit-to-select-bootmenu-entry-with.patch
   u-boot/u-boot@8c986521c3

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2025-10-10 16:35:58 +01:00

117 lines
2.9 KiB
Diff

--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -715,6 +715,12 @@ config CMD_ENV_EXISTS
Check if a variable is defined in the environment for use in
shell scripting.
+config CMD_ENV_READMEM
+ bool "env readmem"
+ default y
+ help
+ Store memory content into environment variable.
+
config CMD_ENV_CALLBACK
bool "env callbacks - print callbacks and their associated variables"
help
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -273,6 +273,60 @@ static int do_env_ask(struct cmd_tbl *cm
}
#endif
+#if defined(CONFIG_CMD_ENV_READMEM)
+int do_env_readmem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ char varstr[CONFIG_SYS_CBSIZE];
+ const void *buf;
+ char *local_args[4];
+ ulong addr, bytes = 6;
+ int hexdump = 0;
+
+ /*
+ * Check the syntax:
+ *
+ * readmem [-b] name address [size]
+ */
+ if (argc < 3)
+ return CMD_RET_USAGE;
+
+ local_args[0] = argv[0];
+
+ if (!strncmp(argv[1], "-b", 3))
+ hexdump = 1;
+
+ local_args[1] = argv[hexdump + 1];
+ local_args[2] = varstr;
+ local_args[3] = NULL;
+
+ addr = simple_strtoul(argv[hexdump + 2], NULL, 16);
+
+ if (!hexdump)
+ bytes = simple_strtoul(argv[hexdump + 3], NULL, 16);
+
+ if (bytes < 1)
+ return 1;
+
+ if ((hexdump * 3) * bytes >= CONFIG_SYS_CBSIZE)
+ return 1;
+
+ buf = map_sysmem(addr, bytes);
+ if (!buf)
+ return 1;
+
+ if (hexdump) {
+ sprintf(varstr, "%pM", buf);
+ } else {
+ memcpy(varstr, buf, bytes);
+ varstr[bytes] = '\0';
+ }
+ unmap_sysmem(buf);
+
+ /* Continue calling setenv code */
+ return env_do_env_set(flag, 3, local_args, H_INTERACTIVE);
+}
+#endif
+
#if defined(CONFIG_CMD_ENV_CALLBACK)
static int print_static_binding(const char *var_name, const char *callback_name,
void *priv)
@@ -1092,6 +1146,9 @@ static struct cmd_tbl cmd_env_sub[] = {
U_BOOT_CMD_MKENT(load, 1, 0, do_env_load, "", ""),
#endif
U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
+#if defined(CONFIG_CMD_ENV_READMEM)
+ U_BOOT_CMD_MKENT(readmem, CONFIG_SYS_MAXARGS, 3, do_env_readmem, "", ""),
+#endif
#if defined(CONFIG_CMD_RUN)
U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
#endif
@@ -1176,6 +1233,9 @@ U_BOOT_LONGHELP(env,
#if defined(CONFIG_CMD_NVEDIT_EFI)
"env print -e [-guid guid] [-n] [name ...] - print UEFI environment\n"
#endif
+#if defined(CONFIG_CMD_ENV_READMEM)
+ "env readmem [-b] name address size - read variable from memory\n"
+#endif
#if defined(CONFIG_CMD_RUN)
"env run var [...] - run commands in an environment variable\n"
#endif
@@ -1284,6 +1344,17 @@ U_BOOT_CMD(
);
#endif
+#if defined(CONFIG_CMD_ENV_READMEM)
+U_BOOT_CMD_COMPLETE(
+ readmem, CONFIG_SYS_MAXARGS, 3, do_env_readmem,
+ "get environment variable from memory address",
+ "name [-b] address size\n"
+ " - store memory address to env variable\n"
+ " \"-b\": read binary ethaddr",
+ var_complete
+);
+#endif
+
#if defined(CONFIG_CMD_RUN)
U_BOOT_CMD_COMPLETE(
run, CONFIG_SYS_MAXARGS, 1, do_run,