From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-wg0-f53.google.com ([74.125.82.53]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TxFBt-00013L-IR for barebox@lists.infradead.org; Mon, 21 Jan 2013 11:05:32 +0000 Received: by mail-wg0-f53.google.com with SMTP id fn15so3558921wgb.8 for ; Mon, 21 Jan 2013 03:04:19 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1358764040-10690-4-git-send-email-plagnioj@jcrosoft.com> References: <20130121102319.GE26329@game.jcrosoft.org> <1358764040-10690-1-git-send-email-plagnioj@jcrosoft.com> <1358764040-10690-4-git-send-email-plagnioj@jcrosoft.com> Date: Mon, 21 Jan 2013 12:04:19 +0100 Message-ID: From: Alexander Aring List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============8769840020172532683==" Sender: barebox-bounces@lists.infradead.org Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: Re: [PATCH 04/10] at91: add test commamd to emulate bootrom boot To: Jean-Christophe PLAGNIOL-VILLARD Cc: barebox --===============8769840020172532683== Content-Type: multipart/alternative; boundary=047d7bfd046e3554f904d3ca6c5f --047d7bfd046e3554f904d3ca6c5f Content-Type: text/plain; charset=UTF-8 hi 2013/1/21 Jean-Christophe PLAGNIOL-VILLARD > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD > --- > arch/arm/mach-at91/Kconfig | 6 +++ > arch/arm/mach-at91/Makefile | 1 + > arch/arm/mach-at91/boot_test_cmd.c | 95 > ++++++++++++++++++++++++++++++++++++ > 3 files changed, 102 insertions(+) > create mode 100644 arch/arm/mach-at91/boot_test_cmd.c > > diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig > index 0fd9122..2815d5f 100644 > --- a/arch/arm/mach-at91/Kconfig > +++ b/arch/arm/mach-at91/Kconfig > @@ -485,6 +485,12 @@ config CMD_AT91MUX > bool "at91mux dump command" > default y > > +config CMD_AT91_BOOT_TEST > + bool "at91_boot_test" > + help > + allow to upload a boot binary to sram and execute it > + usefull to test bootstrap or barebox lowlevel init > + > endif > > endif > diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile > index 53b4dd8..4404d23 100644 > --- a/arch/arm/mach-at91/Makefile > +++ b/arch/arm/mach-at91/Makefile > @@ -1,4 +1,5 @@ > obj-y += setup.o clock.o gpio.o > +obj-$(CONFIG_CMD_AT91_BOOT_TEST) += boot_test_cmd.o > > lowlevel_init-y = at91sam926x_lowlevel_init.o > lowlevel_init-$(CONFIG_ARCH_AT91RM9200) = at91rm9200_lowlevel_init.o > diff --git a/arch/arm/mach-at91/boot_test_cmd.c > b/arch/arm/mach-at91/boot_test_cmd.c > new file mode 100644 > index 0000000..90093d8 > --- /dev/null > +++ b/arch/arm/mach-at91/boot_test_cmd.c > @@ -0,0 +1,95 @@ > +/* > + * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD < > plagnioj@jcrosoft.com> > + * > + * Under GPLv2 only > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int do_at91_boot_test(int argc, char *argv[]) > +{ > + int opt; > + u32 *buf32; > + void *buf; > + void (*jump)(void) = NULL; > + int fd; > + int ret = 1; > + char *sram = "/dev/sram0"; > + u32 read_size, write_size; > + u32 tmp = 0; > + > + while ((opt = getopt(argc, argv, "j:s:")) > 0) { > + switch (opt) { > + case 'j': > + jump = (void*)simple_strtoul(optarg, NULL, 0); > + break; > + case 's': > + sram = optarg; > + break; > + default: > + return COMMAND_ERROR_USAGE; > + } > + } > + > + if (argc < optind + 1) > + return COMMAND_ERROR_USAGE; > + > + buf32 = buf = read_file(argv[optind], &read_size); > + if (!buf) > + return -EINVAL; > + > + write_size = buf32[5]; > + > + printf("size of the size %d\n", read_size); > + printf("size to load in sram %d\n", write_size); > + > + if (write_size > read_size) { > + printf("file smaller than requested sram loading size (%d > < %d)\n", write_size, read_size); > + goto err; > + } > + > + fd = open(sram, O_WRONLY); > + if (fd < 0) { > + printf("could not open %s: %s\n", sram, errno_str()); > + ret = fd; > + goto err; > + } > + > + while(write_size) { > while (foo) > + tmp = write(fd, buf, write_size); > + if (tmp < 0) { > + perror("write"); > + goto err_open; > + } > + buf += tmp; > + write_size -= tmp; > + } > + > + shutdown_barebox(); > + > + jump(); > + > +err_open: > + close(fd); > +err: > + free(buf); > + return ret; > +} > + > +BAREBOX_CMD_HELP_START(at91_boot_test) > +BAREBOX_CMD_HELP_USAGE("at91_boot_test [-j ] [-s ] > file\n") > +BAREBOX_CMD_HELP_SHORT("upload the binary to sram and jump as will do the > romcode\n") > +BAREBOX_CMD_HELP_END > + > +BAREBOX_CMD_START(at91_boot_test) > + .cmd = do_at91_boot_test, > + .usage = "upload the binary to sram and jump as will do > the romcode", > + BAREBOX_CMD_HELP(cmd_at91_boot_test_help) > +BAREBOX_CMD_END > -- > 1.7.10.4 > > > _______________________________________________ > barebox mailing list > barebox@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/barebox > --047d7bfd046e3554f904d3ca6c5f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
hi


2013/1/21 Jean-Christophe PLAGNIOL-VILLARD <= plagnioj@jcrosof= t.com>
Signed-off-by: Jean-Christophe PLAGNIOL-VILL= ARD <plagnioj@jcrosoft.com&= gt;
---
=C2=A0arch/arm/mach-at91/Kconfig =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2= =A06 +++
=C2=A0arch/arm/mach-at91/Makefile =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2= =A01 +
=C2=A0arch/arm/mach-at91/boot_test_cmd.c | =C2=A0 95 ++++++++++++++++++++++= ++++++++++++++
=C2=A03 files changed, 102 insertions(+)
=C2=A0create mode 100644 arch/arm/mach-at91/boot_test_cmd.c

diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index 0fd9122..2815d5f 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -485,6 +485,12 @@ config CMD_AT91MUX
=C2=A0 =C2=A0 =C2=A0 =C2=A0 bool "at91mux dump command"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 default y

+config CMD_AT91_BOOT_TEST
+ =C2=A0 =C2=A0 =C2=A0 bool "at91_boot_test"
+ =C2=A0 =C2=A0 =C2=A0 help
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 allow to upload a boot binary to sram and exe= cute it
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 usefull to test bootstrap or barebox lowlevel= init
+
=C2=A0endif

=C2=A0endif
diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index 53b4dd8..4404d23 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -1,4 +1,5 @@
=C2=A0obj-y +=3D setup.o clock.o gpio.o
+obj-$(CONFIG_CMD_AT91_BOOT_TEST) +=3D boot_test_cmd.o

=C2=A0lowlevel_init-y =3D at91sam926x_lowlevel_init.o
=C2=A0lowlevel_init-$(CONFIG_ARCH_AT91RM9200) =3D at91rm9200_lowlevel_init.= o
diff --git a/arch/arm/mach-at91/boot_test_cmd.c b/arch/arm/mach-at91/boot_t= est_cmd.c
new file mode 100644
index 0000000..90093d8
--- /dev/null
+++ b/arch/arm/mach-at91/boot_test_cmd.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * Under GPLv2 only
+ */
+
+#include <common.h>
+#include <command.h>
+#include <libbb.h>
+#include <getopt.h>
+#include <fs.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <errno.h>
+
+static int do_at91_boot_test(int argc, char *argv[])
+{
+ =C2=A0 =C2=A0 =C2=A0 int opt;
+ =C2=A0 =C2=A0 =C2=A0 u32 *buf32;
+ =C2=A0 =C2=A0 =C2=A0 void *buf;
+ =C2=A0 =C2=A0 =C2=A0 void (*jump)(void) =3D NULL;
+ =C2=A0 =C2=A0 =C2=A0 int fd;
+ =C2=A0 =C2=A0 =C2=A0 int ret =3D 1;
+ =C2=A0 =C2=A0 =C2=A0 char *sram =3D "/dev/sram0";
+ =C2=A0 =C2=A0 =C2=A0 u32 read_size, write_size;
+ =C2=A0 =C2=A0 =C2=A0 u32 tmp =3D 0;
+
+ =C2=A0 =C2=A0 =C2=A0 while ((opt =3D getopt(argc, argv, "j:s:")= ) > 0) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 switch (opt) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 case 'j':
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 jump =3D (void*)simple_strtoul(optarg, NULL, 0);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 break;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 case 's':
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 sram =3D optarg;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 break;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 default:
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 return COMMAND_ERROR_USAGE;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 if (argc < optind + 1)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return COMMAND_ERROR_USA= GE;
+
+ =C2=A0 =C2=A0 =C2=A0 buf32 =3D buf =3D read_file(argv[optind], &read_= size);
+ =C2=A0 =C2=A0 =C2=A0 if (!buf)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
+
+ =C2=A0 =C2=A0 =C2=A0 write_size =3D buf32[5];
+
+ =C2=A0 =C2=A0 =C2=A0 printf("size of the size %d\n", read_size)= ;
+ =C2=A0 =C2=A0 =C2=A0 printf("size to load in sram %d\n", write_= size);
+
+ =C2=A0 =C2=A0 =C2=A0 if (write_size > read_size) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("file smalle= r than requested sram loading size (%d < %d)\n", write_size, read_s= ize);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto err;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 fd =3D open(sram, O_WRONLY);
+ =C2=A0 =C2=A0 =C2=A0 if (fd < 0) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("could not o= pen %s: %s\n", sram, errno_str());
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D fd;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto err;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 while(write_size) {
while (foo)=
=C2=A0
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 tmp =3D write(fd, buf, w= rite_size);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (tmp < 0) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 perror("write");
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 goto err_open;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 buf +=3D tmp;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 write_size -=3D tmp;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 shutdown_barebox();
+
+ =C2=A0 =C2=A0 =C2=A0 jump();
+
+err_open:
+ =C2=A0 =C2=A0 =C2=A0 close(fd);
+err:
+ =C2=A0 =C2=A0 =C2=A0 free(buf);
+ =C2=A0 =C2=A0 =C2=A0 return ret;
+}
+
+BAREBOX_CMD_HELP_START(at91_boot_test)
+BAREBOX_CMD_HELP_USAGE("at91_boot_test [-j <jump addr>] [-s <= ;sram>] file\n")
+BAREBOX_CMD_HELP_SHORT("upload the binary to sram and jump as will do= the romcode\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(at91_boot_test)
+ =C2=A0 =C2=A0 =C2=A0 .cmd =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D do= _at91_boot_test,
+ =C2=A0 =C2=A0 =C2=A0 .usage =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D "u= pload the binary to sram and jump as will do the romcode",
+ =C2=A0 =C2=A0 =C2=A0 BAREBOX_CMD_HELP(cmd_at91_boot_test_help)
+BAREBOX_CMD_END
--
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org<= /a>
http://lists.infradead.org/mailman/listinfo/barebox

--047d7bfd046e3554f904d3ca6c5f-- --===============8769840020172532683== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox --===============8769840020172532683==--