summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRui Miguel Silva <[email protected]>2022-05-11 10:55:40 +0100
committerTom Rini <[email protected]>2022-06-22 11:35:47 -0400
commitbfef72e4dd1c1d6dfc680867bf24a78597ab0438 (patch)
treed403ba89ce489bb4a0e56acd7342ecdff45a95de /test
parenta47ce34403f27178c1264bf60496bbb9a21e5842 (diff)
cmd: load: add load command for memory mapped
cp.b is used a lot as a way to load binaries to memory and execute them, however we may need to integrate this with the efi subsystem to set it up as a bootdev. So, introduce a loadm command that will be consistent with the other loadX commands and will call the efi API's. ex: loadm $kernel_addr $kernel_addr_r $kernel_size with this a kernel with CONFIG_EFI_STUB enabled will be loaded and then subsequently booted with bootefi command. Signed-off-by: Rui Miguel Silva <[email protected]> Reviewed-by: Tom Rini <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/cmd/Makefile1
-rw-r--r--test/cmd/loadm.c72
-rw-r--r--test/cmd_ut.c6
3 files changed, 79 insertions, 0 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index a59adb1e6d6..4b2d7df0d2e 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
endif
obj-y += mem.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
+obj-$(CONFIG_CMD_LOADM) += loadm.o
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
obj-$(CONFIG_CMD_PINMUX) += pinmux.o
obj-$(CONFIG_CMD_PWM) += pwm.o
diff --git a/test/cmd/loadm.c b/test/cmd/loadm.c
new file mode 100644
index 00000000000..41e005ac592
--- /dev/null
+++ b/test/cmd/loadm.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for loadm command
+ *
+ * Copyright 2022 ARM Limited
+ * Copyright 2022 Linaro
+ *
+ * Authors:
+ * Rui Miguel Silva <[email protected]>
+ */
+
+#include <common.h>
+#include <console.h>
+#include <mapmem.h>
+#include <asm/global_data.h>
+#include <dm/test.h>
+#include <test/suites.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+#define BUF_SIZE 0x100
+
+#define LOADM_TEST(_name, _flags) UNIT_TEST(_name, _flags, loadm_test)
+
+static int loadm_test_params(struct unit_test_state *uts)
+{
+ ut_assertok(console_record_reset_enable());
+ run_command("loadm", 0);
+ ut_assert_nextline("loadm - load binary blob from source address to destination address");
+
+ ut_assertok(console_record_reset_enable());
+ run_command("loadm 0x12345678", 0);
+ ut_assert_nextline("loadm - load binary blob from source address to destination address");
+
+ ut_assertok(console_record_reset_enable());
+ run_command("loadm 0x12345678 0x12345678", 0);
+ ut_assert_nextline("loadm - load binary blob from source address to destination address");
+
+ ut_assertok(console_record_reset_enable());
+ run_command("loadm 0x12345678 0x12345678 0", 0);
+ ut_assert_nextline("loadm: can not load zero bytes");
+
+ return 0;
+}
+LOADM_TEST(loadm_test_params, UT_TESTF_CONSOLE_REC);
+
+static int loadm_test_load (struct unit_test_state *uts)
+{
+ char *buf;
+
+ buf = map_sysmem(0, BUF_SIZE);
+ memset(buf, '\0', BUF_SIZE);
+ memset(buf, 0xaa, BUF_SIZE / 2);
+
+ ut_assertok(console_record_reset_enable());
+ run_command("loadm 0x0 0x80 0x80", 0);
+ ut_assert_nextline("loaded bin to memory: size: 128");
+
+ unmap_sysmem(buf);
+
+ return 0;
+}
+LOADM_TEST(loadm_test_load, UT_TESTF_CONSOLE_REC);
+
+int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ struct unit_test *tests = UNIT_TEST_SUITE_START(loadm_test);
+ const int n_ents = UNIT_TEST_SUITE_COUNT(loadm_test);
+
+ return cmd_ut_category("loadm", "loadm_test_", tests, n_ents, argc,
+ argv);
+}
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 67a13ee32b8..d70b72678ae 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -74,6 +74,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
#ifdef CONFIG_CMD_ADDRMAP
U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
#endif
+#ifdef CONFIG_CMD_LOADM
+ U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
+#endif
};
static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -156,6 +159,9 @@ static char ut_help_text[] =
#ifdef CONFIG_CMD_ADDRMAP
"ut addrmap - Very basic test of addrmap command\n"
#endif
+#ifdef CONFIG_CMD_LOADM
+ "ut loadm [test-name]- test of parameters and load memory blob\n"
+#endif
;
#endif /* CONFIG_SYS_LONGHELP */