X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcmd_fpga.c;h=3fc4fca9ae2991540f7d410b16fc6a31258a4306;hb=d45963854eff39d575124d859419bb4953ce2c87;hp=900d35aa449460ed2a3c6cfe19d3e7399783ac1b;hpb=c3d2b4b48a225edd35f80f4b7b8e70e628366575;p=u-boot diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c index 900d35aa44..3fc4fca9ae 100644 --- a/common/cmd_fpga.c +++ b/common/cmd_fpga.c @@ -27,7 +27,7 @@ */ #include #include -#if (CONFIG_COMMANDS & CFG_CMD_NET) +#if defined(CONFIG_CMD_NET) #include #endif #include @@ -43,7 +43,7 @@ #define PRINTF(fmt,args...) #endif -#if defined (CONFIG_FPGA) && ( CONFIG_COMMANDS & CFG_CMD_FPGA ) +#if defined (CONFIG_FPGA) && defined(CONFIG_CMD_FPGA) /* Local functions */ static void fpga_usage (cmd_tbl_t * cmdtp); @@ -55,29 +55,35 @@ static int fpga_get_op (char *opstr); #define FPGA_LOAD 1 #define FPGA_LOADB 2 #define FPGA_DUMP 3 +#define FPGA_LOADMK 4 /* 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; + dataptr = (unsigned char *)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 +92,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 +180,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 +212,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; } @@ -236,12 +252,29 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) rc = fpga_loadbitstream(dev, fpga_data, data_size); break; + case FPGA_LOADMK: + { + image_header_t header; + image_header_t *hdr = &header; + ulong data; + + memmove (&header, (char *)fpga_data, sizeof(image_header_t)); + if (ntohl(hdr->ih_magic) != IH_MAGIC) { + puts ("Bad Magic Number\n"); + return 1; + } + data = ((ulong)fpga_data + sizeof(image_header_t)); + data_size = ntohl(hdr->ih_size); + rc = fpga_load (dev, (void *)data, data_size); + } + break; + case FPGA_DUMP: rc = fpga_dump (dev, fpga_data, data_size); break; default: - printf ("Unknown operation.\n"); + printf ("Unknown operation\n"); fpga_usage (cmdtp); break; } @@ -267,6 +300,8 @@ static int fpga_get_op (char *opstr) op = FPGA_LOADB; } else if (!strcmp ("load", opstr)) { op = FPGA_LOAD; + } else if (!strcmp ("loadmk", opstr)) { + op = FPGA_LOADMK; } else if (!strcmp ("dump", opstr)) { op = FPGA_DUMP; } @@ -281,8 +316,9 @@ 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"); -#endif /* CONFIG_FPGA && CONFIG_COMMANDS & CFG_CMD_FPGA */ + "\tinfo\tlist known device information\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" + "\tdump\tLoad device to memory buffer\n"); +#endif