]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
image: Add boot_get_fpga() to load fpga with bootm
authorMichal Simek <michal.simek@xilinx.com>
Tue, 17 May 2016 12:03:50 +0000 (14:03 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Tue, 24 May 2016 11:17:59 +0000 (13:17 +0200)
Add function boot_get_fpga() which find and load bitstream to
programmable logic if fpga entry is present.
Function is supported on Xilinx devices for full and partial bitstreams
in BIN and BIT format.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Remove additional blankline in image.h

common/bootm.c
common/image-fit.c
common/image.c
include/bootstage.h
include/image.h

index c965326db4169de9a1254282029751ecedc266e0..49414142dcd207902b96a7e93a64923c121e71ba 100644 (file)
@@ -246,6 +246,16 @@ int bootm_find_images(int flag, int argc, char * const argv[])
 #endif
 
 #if IMAGE_ENABLE_FIT
+#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+       /* find bitstreams */
+       ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT,
+                           NULL, NULL);
+       if (ret) {
+               printf("FPGA image is corrupted or invalid\n");
+               return 1;
+       }
+#endif
+
        /* find all of the loadables */
        ret = boot_get_loadable(argc, argv, &images, IH_ARCH_DEFAULT,
                               NULL, NULL);
index 8a0ca2a8038db5f3aba06cf1cc5244988b6d056f..98739572a1bdc9a585432d46acc7ad304fe5ef01 100644 (file)
@@ -422,7 +422,8 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
        }
 
        if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
-           (type == IH_TYPE_FIRMWARE) || (type == IH_TYPE_RAMDISK)) {
+           (type == IH_TYPE_FIRMWARE) || (type == IH_TYPE_RAMDISK) ||
+           (type == IH_TYPE_FPGA)) {
                ret = fit_image_get_load(fit, image_noffset, &load);
                printf("%s  Load Address: ", p);
                if (ret)
@@ -1571,6 +1572,8 @@ static const char *fit_get_image_type_property(int type)
                return FIT_SETUP_PROP;
        case IH_TYPE_LOADABLE:
                return FIT_LOADABLE_PROP;
+       case IH_TYPE_FPGA:
+               return FIT_FPGA_PROP;
        }
 
        return "unknown";
@@ -1685,7 +1688,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
                        fit_image_check_type(fit, noffset,
                                             IH_TYPE_KERNEL_NOLOAD));
 
-       os_ok = image_type == IH_TYPE_FLATDT ||
+       os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
                fit_image_check_os(fit, noffset, IH_OS_LINUX) ||
                fit_image_check_os(fit, noffset, IH_OS_OPENRTOS);
 
index ec78b7eab33663d7612c23c51370151ebf990c1c..0be09e5c6306df7973b3a45e00c6c891cef7ee26 100644 (file)
@@ -32,6 +32,8 @@
 #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT
 #include <libfdt.h>
 #include <fdt_support.h>
+#include <fpga.h>
+#include <xilinx.h>
 #endif
 
 #include <u-boot/md5.h>
@@ -1212,6 +1214,96 @@ int boot_get_setup(bootm_headers_t *images, uint8_t arch,
 }
 
 #if IMAGE_ENABLE_FIT
+#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
+                 uint8_t arch, const ulong *ld_start, ulong * const ld_len)
+{
+       ulong tmp_img_addr, img_data, img_len;
+       void *buf;
+       int conf_noffset;
+       int fit_img_result;
+       char *uname, *name;
+       int err;
+       int devnum = 0; /* TODO support multi fpga platforms */
+       const fpga_desc * const desc = fpga_get_desc(devnum);
+       xilinx_desc *desc_xilinx = desc->devdesc;
+
+       /* Check to see if the images struct has a FIT configuration */
+       if (!genimg_has_config(images)) {
+               debug("## FIT configuration was not specified\n");
+               return 0;
+       }
+
+       /*
+        * Obtain the os FIT header from the images struct
+        * copy from dataflash if needed
+        */
+       tmp_img_addr = map_to_sysmem(images->fit_hdr_os);
+       tmp_img_addr = genimg_get_image(tmp_img_addr);
+       buf = map_sysmem(tmp_img_addr, 0);
+       /*
+        * Check image type. For FIT images get FIT node
+        * and attempt to locate a generic binary.
+        */
+       switch (genimg_get_format(buf)) {
+       case IMAGE_FORMAT_FIT:
+               conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
+
+               err = fdt_get_string_index(buf, conf_noffset, FIT_FPGA_PROP, 0,
+                                          (const char **)&uname);
+               if (err < 0) {
+                       debug("## FPGA image is not specified\n");
+                       return 0;
+               }
+               fit_img_result = fit_image_load(images,
+                                               tmp_img_addr,
+                                               (const char **)&uname,
+                                               &(images->fit_uname_cfg),
+                                               arch,
+                                               IH_TYPE_FPGA,
+                                               BOOTSTAGE_ID_FPGA_INIT,
+                                               FIT_LOAD_OPTIONAL_NON_ZERO,
+                                               &img_data, &img_len);
+
+               debug("FPGA image (%s) loaded to 0x%lx/size 0x%lx\n",
+                     uname, img_data, img_len);
+
+               if (fit_img_result < 0) {
+                       /* Something went wrong! */
+                       return fit_img_result;
+               }
+
+               if (img_len >= desc_xilinx->size) {
+                       name = "full";
+                       err = fpga_loadbitstream(devnum, (char *)img_data,
+                                                img_len, BIT_FULL);
+                       if (err)
+                               err = fpga_load(devnum, (const void *)img_data,
+                                               img_len, BIT_FULL);
+               } else {
+                       name = "partial";
+                       err = fpga_loadbitstream(devnum, (char *)img_data,
+                                                img_len, BIT_PARTIAL);
+                       if (err)
+                               err = fpga_load(devnum, (const void *)img_data,
+                                               img_len, BIT_PARTIAL);
+               }
+
+               printf("   Programming %s bitstream... ", name);
+               if (err)
+                       printf("failed\n");
+               else
+                       printf("OK\n");
+               break;
+       default:
+               printf("The given image format is not supported (corrupt?)\n");
+               return 1;
+       }
+
+       return 0;
+}
+#endif
+
 int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
                uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
index 97653602d3dd1eee50510b1d0bd57805f3f44a6a..0880a680b9ea3e4472528df3542f55d592afc0b1 100644 (file)
@@ -198,6 +198,7 @@ enum bootstage_id {
        BOOTSTAGE_ID_ACCUM_SCSI,
        BOOTSTAGE_ID_ACCUM_SPI,
        BOOTSTAGE_ID_ACCUM_DECOMP,
+       BOOTSTAGE_ID_FPGA_INIT,
 
        /* a few spare for the user, from here */
        BOOTSTAGE_ID_USER,
index e2a90ca202b164d02ce619548719d6e62d791977..a8f6bd16f69c62548ebc293cf426e15d01773435 100644 (file)
@@ -496,6 +496,8 @@ int genimg_get_format(const void *img_addr);
 int genimg_has_config(bootm_headers_t *images);
 ulong genimg_get_image(ulong img_addr);
 
+int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
+               uint8_t arch, const ulong *ld_start, ulong * const ld_len);
 int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
                uint8_t arch, ulong *rd_start, ulong *rd_end);