<div dir="ltr">hi<br><div class="gmail_extra"><br><br><div class="gmail_quote">2013/1/21 Jean-Christophe PLAGNIOL-VILLARD <span dir="ltr"><<a href="mailto:plagnioj@jcrosoft.com" target="_blank">plagnioj@jcrosoft.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnioj@jcrosoft.com">plagnioj@jcrosoft.com</a>><br>
---<br>
arch/arm/mach-at91/Kconfig | 6 +++<br>
arch/arm/mach-at91/Makefile | 1 +<br>
arch/arm/mach-at91/boot_test_cmd.c | 95 ++++++++++++++++++++++++++++++++++++<br>
3 files changed, 102 insertions(+)<br>
create mode 100644 arch/arm/mach-at91/boot_test_cmd.c<br>
<br>
diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig<br>
index 0fd9122..2815d5f 100644<br>
--- a/arch/arm/mach-at91/Kconfig<br>
+++ b/arch/arm/mach-at91/Kconfig<br>
@@ -485,6 +485,12 @@ config CMD_AT91MUX<br>
bool "at91mux dump command"<br>
default y<br>
<br>
+config CMD_AT91_BOOT_TEST<br>
+ bool "at91_boot_test"<br>
+ help<br>
+ allow to upload a boot binary to sram and execute it<br>
+ usefull to test bootstrap or barebox lowlevel init<br>
+<br>
endif<br>
<br>
endif<br>
diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile<br>
index 53b4dd8..4404d23 100644<br>
--- a/arch/arm/mach-at91/Makefile<br>
+++ b/arch/arm/mach-at91/Makefile<br>
@@ -1,4 +1,5 @@<br>
obj-y += setup.o clock.o gpio.o<br>
+obj-$(CONFIG_CMD_AT91_BOOT_TEST) += boot_test_cmd.o<br>
<br>
lowlevel_init-y = at91sam926x_lowlevel_init.o<br>
lowlevel_init-$(CONFIG_ARCH_AT91RM9200) = at91rm9200_lowlevel_init.o<br>
diff --git a/arch/arm/mach-at91/boot_test_cmd.c b/arch/arm/mach-at91/boot_test_cmd.c<br>
new file mode 100644<br>
index 0000000..90093d8<br>
--- /dev/null<br>
+++ b/arch/arm/mach-at91/boot_test_cmd.c<br>
@@ -0,0 +1,95 @@<br>
+/*<br>
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnioj@jcrosoft.com">plagnioj@jcrosoft.com</a>><br>
+ *<br>
+ * Under GPLv2 only<br>
+ */<br>
+<br>
+#include <common.h><br>
+#include <command.h><br>
+#include <libbb.h><br>
+#include <getopt.h><br>
+#include <fs.h><br>
+#include <fcntl.h><br>
+#include <malloc.h><br>
+#include <errno.h><br>
+<br>
+static int do_at91_boot_test(int argc, char *argv[])<br>
+{<br>
+ int opt;<br>
+ u32 *buf32;<br>
+ void *buf;<br>
+ void (*jump)(void) = NULL;<br>
+ int fd;<br>
+ int ret = 1;<br>
+ char *sram = "/dev/sram0";<br>
+ u32 read_size, write_size;<br>
+ u32 tmp = 0;<br>
+<br>
+ while ((opt = getopt(argc, argv, "j:s:")) > 0) {<br>
+ switch (opt) {<br>
+ case 'j':<br>
+ jump = (void*)simple_strtoul(optarg, NULL, 0);<br>
+ break;<br>
+ case 's':<br>
+ sram = optarg;<br>
+ break;<br>
+ default:<br>
+ return COMMAND_ERROR_USAGE;<br>
+ }<br>
+ }<br>
+<br>
+ if (argc < optind + 1)<br>
+ return COMMAND_ERROR_USAGE;<br>
+<br>
+ buf32 = buf = read_file(argv[optind], &read_size);<br>
+ if (!buf)<br>
+ return -EINVAL;<br>
+<br>
+ write_size = buf32[5];<br>
+<br>
+ printf("size of the size %d\n", read_size);<br>
+ printf("size to load in sram %d\n", write_size);<br>
+<br>
+ if (write_size > read_size) {<br>
+ printf("file smaller than requested sram loading size (%d < %d)\n", write_size, read_size);<br>
+ goto err;<br>
+ }<br>
+<br>
+ fd = open(sram, O_WRONLY);<br>
+ if (fd < 0) {<br>
+ printf("could not open %s: %s\n", sram, errno_str());<br>
+ ret = fd;<br>
+ goto err;<br>
+ }<br>
+<br>
+ while(write_size) {<br></blockquote><div>while (foo)<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ tmp = write(fd, buf, write_size);<br>
+ if (tmp < 0) {<br>
+ perror("write");<br>
+ goto err_open;<br>
+ }<br>
+ buf += tmp;<br>
+ write_size -= tmp;<br>
+ }<br>
+<br>
+ shutdown_barebox();<br>
+<br>
+ jump();<br>
+<br>
+err_open:<br>
+ close(fd);<br>
+err:<br>
+ free(buf);<br>
+ return ret;<br>
+}<br>
+<br>
+BAREBOX_CMD_HELP_START(at91_boot_test)<br>
+BAREBOX_CMD_HELP_USAGE("at91_boot_test [-j <jump addr>] [-s <sram>] file\n")<br>
+BAREBOX_CMD_HELP_SHORT("upload the binary to sram and jump as will do the romcode\n")<br>
+BAREBOX_CMD_HELP_END<br>
+<br>
+BAREBOX_CMD_START(at91_boot_test)<br>
+ .cmd = do_at91_boot_test,<br>
+ .usage = "upload the binary to sram and jump as will do the romcode",<br>
+ BAREBOX_CMD_HELP(cmd_at91_boot_test_help)<br>
+BAREBOX_CMD_END<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.10.4<br>
<br>
<br>
_______________________________________________<br>
barebox mailing list<br>
<a href="mailto:barebox@lists.infradead.org">barebox@lists.infradead.org</a><br>
<a href="http://lists.infradead.org/mailman/listinfo/barebox" target="_blank">http://lists.infradead.org/mailman/listinfo/barebox</a><br>
</font></span></blockquote></div><br></div></div>