]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_fpga.c
FSL: Move board/mpc7448hpc2 under board/freescale
[u-boot] / common / cmd_fpga.c
index c4b73929493b1cc487895011709434caabee9cbf..f55447ab1fed70790523817cbf697ba46a6fee2b 100644 (file)
@@ -27,7 +27,7 @@
  */
 #include <common.h>
 #include <command.h>
-#if (CONFIG_COMMANDS & CFG_CMD_NET)
+#if defined(CONFIG_CMD_NET)
 #include <net.h>
 #endif
 #include <fpga.h>
@@ -43,8 +43,6 @@
 #define PRINTF(fmt,args...)
 #endif
 
-#if defined (CONFIG_FPGA) && ( CONFIG_COMMANDS & CFG_CMD_FPGA )
-
 /* Local functions */
 static void fpga_usage (cmd_tbl_t * cmdtp);
 static int fpga_get_op (char *opstr);
@@ -55,23 +53,21 @@ 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)
 {
+#if defined(CONFIG_FPGA_XILINX)
        unsigned int length;
-       unsigned char* swapdata;
        unsigned int swapsize;
        char buffer[80];
-       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 bytes of the bitsteam, their meaning is unknown */
        length = (*dataptr << 8) + *(dataptr+1);
        dataptr+=2;
@@ -144,39 +140,7 @@ int fpga_loadbitstream(unsigned long dev, char* fpgadata, size_t size)
        dataptr+=4;
        printf("  bytes in bitstream = %d\n", swapsize);
 
-       /* check consistency of length obtained */
-       if (swapsize >= size) {
-               printf("%s: Could not find right length of data in bitstream\n",
-                       __FUNCTION__);
-               return FPGA_FAIL;
-       }
-
-       /* allocate memory */
-       swapdata = (unsigned char *)malloc(swapsize);
-       if (swapdata == NULL) {
-               printf("%s: Could not allocate %d bytes memory !\n",
-                       __FUNCTION__, swapsize);
-               return FPGA_FAIL;
-       }
-
-       /* read data into memory and swap bits */
-       ptr = swapdata;
-       for (i = 0; i < swapsize; i++) {
-               data = 0x00;
-               data |= (*dataptr & 0x01) << 7;
-               data |= (*dataptr & 0x02) << 5;
-               data |= (*dataptr & 0x04) << 3;
-               data |= (*dataptr & 0x08) << 1;
-               data |= (*dataptr & 0x10) >> 1;
-               data |= (*dataptr & 0x20) >> 3;
-               data |= (*dataptr & 0x40) >> 5;
-               data |= (*dataptr & 0x80) >> 7;
-               *ptr++ = data;
-               dataptr++;
-       }
-
-       rc = fpga_load(dev, swapdata, swapsize);
-       free(swapdata);
+       rc = fpga_load(dev, dataptr, swapsize);
        return rc;
 #else
        printf("Bitstream support only for Xilinx devices\n");
@@ -251,6 +215,23 @@ 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;
@@ -282,6 +263,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;
        }
@@ -299,5 +282,5 @@ U_BOOT_CMD (fpga, 6, 1, do_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 /* CONFIG_FPGA && CONFIG_COMMANDS & CFG_CMD_FPGA */