* [U-Boot-Users] [PATCH] adds loadi sub command to fpag
@ 2007-06-21 6:25 eran liberty
2007-06-21 11:47 ` Stefan Roese
2007-06-21 21:03 ` Wolfgang Denk
0 siblings, 2 replies; 4+ messages in thread
From: eran liberty @ 2007-06-21 6:25 UTC (permalink / raw)
To: u-boot
fpga loadi <dev> <image addr>
Signed-off-by: Eran Liberty
diff -x .svn -Nuar
u-boot.git-5ffa76a032279bc6d3230b703eda32d13305ba13/common/cmd_fpga.c
u-boot.exsw6000/common/cmd_fpga.c
--- u-boot.git-5ffa76a032279bc6d3230b703eda32d13305ba13/common/cmd_fpga.c 2007-06-18
22:38:46.000000000 +0300
+++ u-boot.exsw6000/common/cmd_fpga.c 2007-06-20 19:25:51.000000000 +0300
@@ -32,6 +32,7 @@
#endif
#include <fpga.h>
#include <malloc.h>
+#include <bzlib.h>
#if 0
#define FPGA_DEBUG
@@ -45,6 +46,8 @@
#if defined (CONFIG_FPGA) && ( CONFIG_COMMANDS & CFG_CMD_FPGA )
+extern int gunzip(void *dst, int dstlen, unsigned char *src, unsigned
long *lenp);
+
/* Local functions */
static void fpga_usage (cmd_tbl_t * cmdtp);
static int fpga_get_op (char *opstr);
@@ -56,6 +59,89 @@
#define FPGA_LOADB 2
#define FPGA_DUMP 3
#define FPGA_LOADMK 4
+#define FPGA_LOADI 5
+
+/* Load an image */
+int fpga_loadi( int devnum, void *buf)
+{
+ ulong addr = (ulong)(buf);
+ ulong data, len, checksum;
+ image_header_t hdr;
+ unsigned int unc_len;
+ unsigned int *punc_len = &unc_len;
+ int i;
+
+ /* Copy header so we can blank CRC field for re-calculation */
+#ifdef CONFIG_HAS_DATAFLASH
+ if (addr_dataflash(addr)){
+ read_dataflash(addr, sizeof(image_header_t), (char *)&hdr);
+ } else
+#endif
+ memmove (&hdr, (char *)addr, sizeof(image_header_t));
+ if (ntohl(hdr.ih_magic) != IH_MAGIC) {
+ puts ("Bad Magic Number\n");
+ return 1;
+ }
+ data = (ulong)&hdr;
+ len = sizeof(image_header_t);
+
+ checksum = ntohl(hdr.ih_hcrc);
+ hdr.ih_hcrc = 0;
+
+ if (crc32 (0, (uchar *)data, len) != checksum) {
+ puts ("Bad Header Checksum\n");
+ return 1;
+ }
+#ifdef CONFIG_HAS_DATAFLASH
+ if (addr_dataflash(addr)){
+ len = ntohl(hdr.ih_size) + sizeof(image_header_t);
+ read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
+ addr = CFG_LOAD_ADDR;
+ }
+#endif
+
+ print_image_hdr ((image_header_t *)addr);
+
+ data = addr + sizeof(image_header_t);
+ len = ntohl(hdr.ih_size);
+
+ puts (" Verifying Checksum ... ");
+ if (crc32 (0, (uchar *)data, len) != ntohl(hdr.ih_dcrc)) {
+ printf ("Bad Data CRC\n");
+ return 1;
+ }
+ puts ("OK\n");
+
+ switch (hdr.ih_comp) {
+ case IH_COMP_NONE:
+ memmove ((char *)CFG_LOAD_ADDR,(void *)data,len);
+ break;
+ case IH_COMP_GZIP:
+ if (gunzip ((char *)CFG_LOAD_ADDR,unc_len,(uchar *)data, &len) != 0) {
+ puts ("GUNZIP ERROR - FPGA not loaded\n");
+ return 1;
+ }
+ len = unc_len;
+ break;
+
+#ifdef CONFIG_BZIP2
+ case IH_COMP_BZIP2:
+ i = BZ2_bzBuffToBuffDecompress ((char *)CFG_LOAD_ADDR,punc_len,
(char *)data, len,
+ 1, 0);
+ if (i != BZ_OK) {
+ printf ("BUNZIP2 ERROR %d - FPGA not loaded!\n", i);
+ return 1;
+ }
+ len = unc_len;
+ break;
+#endif /* CONFIG_BZIP2 */
+ default:
+ printf ("Unimplemented compression type %d\n", hdr.ih_comp);
+ return 1;
+ }
+
+ return fpga_load(devnum,(char *)CFG_LOAD_ADDR,len);
+}
/* Convert bitstream data and load into the fpga */
int fpga_loadbitstream(unsigned long dev, char* fpgadata, size_t size)
@@ -248,6 +334,10 @@
rc = fpga_load (dev, fpga_data, data_size);
break;
+ case FPGA_LOADI:
+ rc = fpga_loadi (dev, fpga_data);
+ break;
+
case FPGA_LOADB:
rc = fpga_loadbitstream(dev, fpga_data, data_size);
break;
@@ -298,6 +388,8 @@
op = FPGA_INFO;
} else if (!strcmp ("loadb", opstr)) {
op = FPGA_LOADB;
+ } else if (!strcmp ("loadi", opstr)) {
+ op = FPGA_LOADI;
} else if (!strcmp ("load", opstr)) {
op = FPGA_LOAD;
} else if (!strcmp ("loadmk", opstr)) {
@@ -317,6 +409,7 @@
"fpga [operation type] [device number] [image address] [image size]\n"
"fpga operations:\n"
"\tinfo\tlist known device information\n"
+ "\tloadi\tLoad device from u-boot image\n"
"\tload\tLoad device from memory buffer\n"
"\tloadb\tLoad device from bitstream buffer (Xilinx devices only)\n"
"\tloadmk\tLoad device generated with mkimage\n"
^ permalink raw reply [flat|nested] 4+ messages in thread* [U-Boot-Users] [PATCH] adds loadi sub command to fpag
2007-06-21 6:25 [U-Boot-Users] [PATCH] adds loadi sub command to fpag eran liberty
@ 2007-06-21 11:47 ` Stefan Roese
2007-06-21 21:03 ` Wolfgang Denk
1 sibling, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2007-06-21 11:47 UTC (permalink / raw)
To: u-boot
Hi Eran,
Please find some comments below.
On Thursday 21 June 2007, eran liberty wrote:
> fpga loadi <dev> <image addr>
> Signed-off-by: Eran Liberty
Please add a more descriptive commit log. What does "loadi" do?
> diff -x .svn -Nuar
> u-boot.git-5ffa76a032279bc6d3230b703eda32d13305ba13/common/cmd_fpga.c
> u-boot.exsw6000/common/cmd_fpga.c
> ---
> u-boot.git-5ffa76a032279bc6d3230b703eda32d13305ba13/common/cmd_fpga.c 2007-
>06-18 22:38:46.000000000 +0300
> +++ u-boot.exsw6000/common/cmd_fpga.c 2007-06-20 19:25:51.000000000 +0300
> @@ -32,6 +32,7 @@
> #endif
> #include <fpga.h>
> #include <malloc.h>
> +#include <bzlib.h>
>
> #if 0
> #define FPGA_DEBUG
> @@ -45,6 +46,8 @@
>
> #if defined (CONFIG_FPGA) && ( CONFIG_COMMANDS & CFG_CMD_FPGA )
>
> +extern int gunzip(void *dst, int dstlen, unsigned char *src, unsigned
> long *lenp);
Line wrapped.
> +
> /* Local functions */
> static void fpga_usage (cmd_tbl_t * cmdtp);
> static int fpga_get_op (char *opstr);
> @@ -56,6 +59,89 @@
> #define FPGA_LOADB 2
> #define FPGA_DUMP 3
> #define FPGA_LOADMK 4
> +#define FPGA_LOADI 5
> +
> +/* Load an image */
> +int fpga_loadi( int devnum, void *buf)
No space after "(" please.
> +{
> + ulong addr = (ulong)(buf);
> + ulong data, len, checksum;
> + image_header_t hdr;
> + unsigned int unc_len;
> + unsigned int *punc_len = &unc_len;
> + int i;
> +
> + /* Copy header so we can blank CRC field for re-calculation */
> +#ifdef CONFIG_HAS_DATAFLASH
> + if (addr_dataflash(addr)){
> + read_dataflash(addr, sizeof(image_header_t), (char *)&hdr);
> + } else
No parentheses for single line statements.
> +#endif
> + memmove (&hdr, (char *)addr, sizeof(image_header_t));
> + if (ntohl(hdr.ih_magic) != IH_MAGIC) {
> + puts ("Bad Magic Number\n");
> + return 1;
> + }
> + data = (ulong)&hdr;
> + len = sizeof(image_header_t);
> +
> + checksum = ntohl(hdr.ih_hcrc);
> + hdr.ih_hcrc = 0;
> +
> + if (crc32 (0, (uchar *)data, len) != checksum) {
> + puts ("Bad Header Checksum\n");
> + return 1;
> + }
> +#ifdef CONFIG_HAS_DATAFLASH
> + if (addr_dataflash(addr)){
> + len = ntohl(hdr.ih_size) + sizeof(image_header_t);
> + read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
> + addr = CFG_LOAD_ADDR;
> + }
> +#endif
> +
> + print_image_hdr ((image_header_t *)addr);
> +
> + data = addr + sizeof(image_header_t);
> + len = ntohl(hdr.ih_size);
> +
> + puts (" Verifying Checksum ... ");
> + if (crc32 (0, (uchar *)data, len) != ntohl(hdr.ih_dcrc)) {
> + printf ("Bad Data CRC\n");
> + return 1;
> + }
> + puts ("OK\n");
> +
> + switch (hdr.ih_comp) {
> + case IH_COMP_NONE:
> + memmove ((char *)CFG_LOAD_ADDR,(void *)data,len);
> + break;
> + case IH_COMP_GZIP:
> + if (gunzip ((char *)CFG_LOAD_ADDR,unc_len,(uchar *)data, &len) != 0) {
> + puts ("GUNZIP ERROR - FPGA not loaded\n");
> + return 1;
> + }
> + len = unc_len;
> + break;
> +
> +#ifdef CONFIG_BZIP2
> + case IH_COMP_BZIP2:
> + i = BZ2_bzBuffToBuffDecompress ((char *)CFG_LOAD_ADDR,punc_len,
> (char *)data, len,
> + 1, 0);
> + if (i != BZ_OK) {
> + printf ("BUNZIP2 ERROR %d - FPGA not loaded!\n", i);
> + return 1;
> + }
> + len = unc_len;
> + break;
> +#endif /* CONFIG_BZIP2 */
> + default:
> + printf ("Unimplemented compression type %d\n", hdr.ih_comp);
> + return 1;
> + }
> +
> + return fpga_load(devnum,(char *)CFG_LOAD_ADDR,len);
> +}
>
> /* Convert bitstream data and load into the fpga */
> int fpga_loadbitstream(unsigned long dev, char* fpgadata, size_t size)
> @@ -248,6 +334,10 @@
> rc = fpga_load (dev, fpga_data, data_size);
> break;
>
> + case FPGA_LOADI:
> + rc = fpga_loadi (dev, fpga_data);
> + break;
> +
> case FPGA_LOADB:
> rc = fpga_loadbitstream(dev, fpga_data, data_size);
> break;
> @@ -298,6 +388,8 @@
> op = FPGA_INFO;
> } else if (!strcmp ("loadb", opstr)) {
> op = FPGA_LOADB;
> + } else if (!strcmp ("loadi", opstr)) {
> + op = FPGA_LOADI;
> } else if (!strcmp ("load", opstr)) {
> op = FPGA_LOAD;
> } else if (!strcmp ("loadmk", opstr)) {
> @@ -317,6 +409,7 @@
> "fpga [operation type] [device number] [image address] [image
> size]\n" "fpga operations:\n"
> "\tinfo\tlist known device information\n"
> + "\tloadi\tLoad device from u-boot image\n"
> "\tload\tLoad device from memory buffer\n"
> "\tloadb\tLoad device from bitstream buffer (Xilinx devices only)\n"
> "\tloadmk\tLoad device generated with mkimage\n"
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> U-Boot-Users mailing list
> U-Boot-Users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/u-boot-users
--
Viele Gr??e,
Stefan
=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================
^ permalink raw reply [flat|nested] 4+ messages in thread* [U-Boot-Users] [PATCH] adds loadi sub command to fpag
2007-06-21 6:25 [U-Boot-Users] [PATCH] adds loadi sub command to fpag eran liberty
2007-06-21 11:47 ` Stefan Roese
@ 2007-06-21 21:03 ` Wolfgang Denk
2007-06-22 0:24 ` eran liberty
1 sibling, 1 reply; 4+ messages in thread
From: Wolfgang Denk @ 2007-06-21 21:03 UTC (permalink / raw)
To: u-boot
In message <ffc2b1d40706202325y222f1ab5ge4cae49d32162c2c@mail.gmail.com> you wrote:
> fpga loadi <dev> <image addr>
I think you should provide a bit more of a description oif what you
are doing and why. This is a bit too cryptic.
Also, I think the function you implement might be redundant. Why do
you think it's necessary to add all this code?
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"If it ain't broke, don't fix it." - Bert Lantz
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot-Users] [PATCH] adds loadi sub command to fpag
2007-06-21 21:03 ` Wolfgang Denk
@ 2007-06-22 0:24 ` eran liberty
0 siblings, 0 replies; 4+ messages in thread
From: eran liberty @ 2007-06-22 0:24 UTC (permalink / raw)
To: u-boot
On 6/22/07, Wolfgang Denk <wd@denx.de> wrote:
> In message <ffc2b1d40706202325y222f1ab5ge4cae49d32162c2c@mail.gmail.com> you wrote:
> > fpga loadi <dev> <image addr>
>
> I think you should provide a bit more of a description oif what you
> are doing and why. This is a bit too cryptic.
>
this function "knows" to open an Image of an fpga design that was
bzip2/gzip/raw compressed and packages with mkimage and burn it.
> Also, I think the function you implement might be redundant. Why do
> you think it's necessary to add all this code?
up on closer look there is an image opener there but i need to relook
at it to tell if it can decompress bzip2 / gzip images. Anyway when i
implemented it I was unaware of the other implementation (it was not
there yet)
so we can either merge this code to the one already there adding it
whatever it lack (if it lacks)... or keep this one and trash the
other... whichever you find more eye pleasing.
>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> "If it ain't broke, don't fix it." - Bert Lantz
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-06-22 0:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-21 6:25 [U-Boot-Users] [PATCH] adds loadi sub command to fpag eran liberty
2007-06-21 11:47 ` Stefan Roese
2007-06-21 21:03 ` Wolfgang Denk
2007-06-22 0:24 ` eran liberty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox