From 8b019da650f307560e4e796ae32509c55e64176f Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Mon, 8 Aug 2005 00:14:41 +0200 Subject: Fix sign extension bug in 'fpga loadb' command; make 'fpga loadb' always print the file header info Patch by Andrew Dyer, 11 Jan 2005 --- common/cmd_fpga.c | 97 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 41 deletions(-) (limited to 'common') diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c index 900d35aa449..0c0643ccc35 100644 --- a/common/cmd_fpga.c +++ b/common/cmd_fpga.c @@ -59,25 +59,30 @@ static int fpga_get_op (char *opstr); /* Convert bitstream data and load into the fpga */ int fpga_loadbitstream(unsigned long dev, char* fpgadata, size_t size) { - int length; - char* swapdata; - int swapsize; + unsigned int length; + unsigned char* swapdata; + unsigned int swapsize; char buffer[80]; - char *ptr; - char *dataptr; - int data; - int i; + unsigned char *ptr; + unsigned char *dataptr; + unsigned char data; + unsigned int i; int rc; dataptr = fpgadata; #if CFG_FPGA_XILINX - /* skip the first 13 bytes of the bitsteam, their meaning is unknown */ - dataptr+=13; + /* skip the first bytes of the bitsteam, their meaning is unknown */ + length = (*dataptr << 8) + *(dataptr+1); + dataptr+=2; + dataptr+=length; /* get design name (identifier, length, string) */ + length = (*dataptr << 8) + *(dataptr+1); + dataptr+=2; if (*dataptr++ != 0x61) { - PRINTF("fpga_loadbitstream: Design name identifier not recognized in bitstream.\n"); + PRINTF ("%s: Design name identifier not recognized in bitstream\n", + __FUNCTION__ ); return FPGA_FAIL; } @@ -86,61 +91,71 @@ int fpga_loadbitstream(unsigned long dev, char* fpgadata, size_t size) for(i=0;i= size) { - printf("fpga_loadbitstream: Could not find right length of data in bitstream.\n"); + printf("%s: Could not find right length of data in bitstream\n", + __FUNCTION__); return FPGA_FAIL; } /* allocate memory */ - swapdata = (char *)malloc(swapsize); + swapdata = (unsigned char *)malloc(swapsize); if (swapdata == NULL) { - printf("fpga_loadbitstream: Could not allocate %d bytes memory !\n",swapsize); + printf("%s: Could not allocate %d bytes memory !\n", + __FUNCTION__, swapsize); return FPGA_FAIL; } @@ -164,7 +179,7 @@ int fpga_loadbitstream(unsigned long dev, char* fpgadata, size_t size) free(swapdata); return rc; #else - printf("Bitstream support only for Xilinx devices.\n"); + printf("Bitstream support only for Xilinx devices\n"); return FPGA_FAIL; #endif } @@ -196,25 +211,25 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) data_size = simple_strtoul (argv[4], NULL, 16); case 4: /* fpga */ fpga_data = (void *) simple_strtoul (argv[3], NULL, 16); - PRINTF ("do_fpga: fpga_data = 0x%x\n", - (uint) fpga_data); + PRINTF ("%s: fpga_data = 0x%x\n", __FUNCTION__, (uint) fpga_data); case 3: /* fpga */ dev = (int) simple_strtoul (argv[2], NULL, 16); - PRINTF ("do_fpga: device = %d\n", dev); + PRINTF ("%s: device = %d\n", __FUNCTION__, dev); /* FIXME - this is a really weak test */ if ((argc == 3) && (dev > fpga_count ())) { /* must be buffer ptr */ - PRINTF ("do_fpga: Assuming buffer pointer in arg 3\n"); + PRINTF ("%s: Assuming buffer pointer in arg 3\n", + __FUNCTION__); fpga_data = (void *) dev; - PRINTF ("do_fpga: fpga_data = 0x%x\n", - (uint) fpga_data); + PRINTF ("%s: fpga_data = 0x%x\n", + __FUNCTION__, (uint) fpga_data); dev = FPGA_INVALID_DEVICE; /* reset device num */ } case 2: /* fpga */ op = (int) fpga_get_op (argv[1]); break; default: - PRINTF ("do_fpga: Too many or too few args (%d)\n", - argc); + PRINTF ("%s: Too many or too few args (%d)\n", + __FUNCTION__, argc); op = FPGA_NONE; /* force usage display */ break; } @@ -241,7 +256,7 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) break; default: - printf ("Unknown operation.\n"); + printf ("Unknown operation\n"); fpga_usage (cmdtp); break; } @@ -281,8 +296,8 @@ U_BOOT_CMD (fpga, 6, 1, do_fpga, "fpga - loadable FPGA image support\n", "fpga [operation type] [device number] [image address] [image size]\n" "fpga operations:\n" - "\tinfo\tlist known device information.\n" - "\tload\tLoad device from memory buffer.\n" - "\tloadb\tLoad device from bitstream buffer (Xilinx devices only).\n" - "\tdump\tLoad device to memory buffer.\n"); + "\tinfo\tlist known device information\n" + "\tload\tLoad device from memory buffer\n" + "\tloadb\tLoad device from bitstream buffer (Xilinx devices only)\n" + "\tdump\tLoad device to memory buffer\n"); #endif /* CONFIG_FPGA && CONFIG_COMMANDS & CFG_CMD_FPGA */ -- cgit v1.2.3