Skip to contentSkip to conversation

common: fitimage support for arbitrary fpga type

PATCH New Dalon Westergreen 4 participants 11 messages Feb 20, 2017 – Feb 24, 2017

lore
Share & tools
lore
#0 lore raw

v3 cover common: fitimage support for arbitrary fpga type

The intent of these patches is to modify existing fitimage support for fpga configuration to allow configuration of any fpga type supported by the fpga_load command.

In the fpga node, two additional optional parameters are used to indicate the fpga device number (for systems with multiple fpgas) and whether the fpga image is a full or partial image.

fpga-devnum: FPGA device number, defaults to 0
fpga-partial-image: 0 = full, other = partial, defaults to full

Changes in v3:
- Fix typos and caps in comments
Changes in v2:
- Add support for devnum and partial
- for backward compatibility, do check of image size for xilinx to determine if the image is a partial image

Dalon Westergreen (2):
common: image: update boot_get_fpga to support arbitrary fpga image
common: bootm: add support for arbitrary fgpa configuration

 common/bootm.c     |  2 +-
 common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     | 51 ++++++++++++++++++++++++++++++++-------------------
 include/image.h    |  5 +++++
 4 files changed, 89 insertions(+), 20 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

--
Changes in v3:
- Fix typos/caps in comments
Changes in v2:
- Add fitimage support for fpga-devnum and fpga-partial-image
- Use above in boot_get_fpga
- for xilinx fpgas double check using image size to determine if image is a partial image

---
 common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     | 51 ++++++++++++++++++++++++++++++++-------------------
 include/image.h    |  5 +++++
 3 files changed, 88 insertions(+), 19 deletions(-)
common/image-fit.c +51 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 }
 
 /**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga data is
+ * intended.  If the property is not found, we default to 0.
+ *
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found
+ */
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP, &len);
+	if (value == NULL || len != sizeof(int))
+		*devnum = 0;
+	else
+		*devnum = *value;
+
+	return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found
+ */
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP, &len);
+	if ((value == NULL || len != sizeof(int)) || (value == 0))
+		return 0;
+	else
+		return 1;
+}
+
+/**
  * fit_set_timestamp - set node timestamp property
  * @fit: pointer to the FIT format image header
  * @noffset: node offset
common/image.c +32 -19

74 lines not on this page · raw message

include/image.h +5 -0
index 1e686b7..75d2afc 100644
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
 #define FIT_COMP_PROP		"compression"
 #define FIT_ENTRY_PROP		"entry"
 #define FIT_LOAD_PROP		"load"
+#define FIT_FPGA_DEVNUM_PROP	"fpga-devnum"
+#define FIT_FPGA_PARTIAL_PROP	"fpga-partial-image"
 
 /* configuration node */
 #define FIT_KERNEL_PROP		"kernel"
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
 
 int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);
+
 /**
  * fit_add_verification_data() - add verification data to FIT image nodes
  *
Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

Quoted 46 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

--
Changes in v3:
- Fix typos/caps in comments
Changes in v2:
- Add fitimage support for fpga-devnum and fpga-partial-image
- Use above in boot_get_fpga
- for xilinx fpgas double check using image size to determine if image is a partial image

---
 common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     | 51 ++++++++++++++++++++++++++++++++-------------------
 include/image.h    |  5 +++++
 3 files changed, 88 insertions(+), 19 deletions(-)
common/image-fit.c +18 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 }
 
 /**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga data is
+ * intended.  If the property is not found, we default to 0.
+ *
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found
+ */
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP, &len);

common/image-fit.c ulong fit_get_end(const void *fit) · line 946

Quoted 10 lines
common/image-fit.c +10 -0
+	if (value == NULL || len != sizeof(int))
+		*devnum = 0;
+	else
+		*devnum = *value;
+
+	return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga

bitstream.

Quoted 112 lines
common/image-fit.c +23 -0
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found
+ */
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP, &len);
+	if ((value == NULL || len != sizeof(int)) || (value == 0))
+		return 0;
+	else
+		return 1;
+}
+
+/**
  * fit_set_timestamp - set node timestamp property
  * @fit: pointer to the FIT format image header
  * @noffset: node offset
common/image.c +32 -19
index 0f88984..6480b0a 100644
@@ -1306,7 +1306,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t arch,
 }
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)
 int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 		  uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
@@ -1316,9 +1316,10 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 	int fit_img_result;
 	const 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;
+	int devnum;
+	const fpga_desc *desc;
+	xilinx_desc *desc_xilinx;
+	bitstream_type bstype = BIT_FULL;
 
 	/* Check to see if the images struct has a FIT configuration */
 	if (!genimg_has_config(images)) {
@@ -1365,26 +1366,38 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 			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);
+		/* Get FPGA device number, defaults to 0 */
+		fit_image_fpga_get_devnum(buf, conf_noffset, &devnum);
+
+		/* Check bitstream type */
+		if (fit_image_fpga_is_partial(buf, conf_noffset))
+			bstype = BIT_PARTIAL;
+
+		/* Legacy support detecting partial config files for Xilinx */
+		desc = fpga_get_desc(devnum);
+		if (desc->devtype == fpga_xilinx) {
+			desc_xilinx = desc->devdesc;
+			if (img_len < desc_xilinx->size)
+				bstype = BIT_PARTIAL;
 		}
 
+		/* Try bitstream format first */
+		err = fpga_loadbitstream(devnum, (char *)img_data,
+					 img_len, bstype);
+		if (err)
+			err = fpga_load(devnum, (const void *)img_data,
+					img_len, bstype);
+
 		if (err)
 			return err;
 
-		printf("   Programming %s bitstream... OK\n", name);
+		if (bstype == BIT_PARTIAL)
+			name = "partial";
+		else
+			name = "full";
+
+		printf("   Programming %s bitstream into fpga %d... OK\n",
+		       name, devnum);
 		break;
 	default:
 		printf("The given image format is not supported (corrupt?)\n");
include/image.h +0 -0
index 1e686b7..75d2afc 100644

include/image.h int bootz_setup(ulong image, ulong *start, ulong *end); · line 879

Quoted 4 lines
include/image.h +1 -0
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
 #define FIT_COMP_PROP		"compression"
 #define FIT_ENTRY_PROP		"entry"
 #define FIT_LOAD_PROP		"load"
+#define FIT_FPGA_DEVNUM_PROP	"fpga-devnum"

tbh I am not quite sure if we should introduce this. Please look below.

include/image.h int bootz_setup(ulong image, ulong *start, ulong *end); · line 880

Quoted 1 line
include/image.h +1 -0
+#define FIT_FPGA_PARTIAL_PROP	"fpga-partial-image"

I would suggest to use "partial-fpga-config" because this is what Alan is pushing to mainline kernel. Make no sense to use something different.

Quoted 5 lines
include/image.h +0 -0
 /* configuration node */
 #define FIT_KERNEL_PROP		"kernel"

include/image.h int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, · line 965

Quoted 9 lines
include/image.h +3 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
 
 int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);
+
 /**
  * fit_add_verification_data() - add verification data to FIT image nodes
  *

I have not a problem with this patch. I didn't test it yet but I will do it. It should probably go through my tree anyway.

There are some things which should be good to keep in mind.
1. DM - all fpga drivers are using legacy model and we should really consider to move that stuff to DM and use binding for it.

2. overlays. DT overlays were added recently to u-boot and we should add support for it. Then in general fpga commands can go away entirely and we will just apply overlays directly and this will require DM.

/ {
        fragment {
                target = <&fpga_region0>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <1>;
                        firmware-name = "XXXX";
                        partial-fpga-config;
                        gpio_on: gpio at 412c0000 {
...
                        };
                };
        };
};

Here is visible that target replaces devnum.

3. maybe before overlays we can add support for simple cases as I supported now.

Definitely there is a lot of work which need to be done.

Thanks,
Michal

#3 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

Quoted 54 lines · Michal Simek
Quoted 53 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

--
Changes in v3:
?- Fix typos/caps in comments
Changes in v2:
?- Add fitimage support for fpga-devnum and fpga-partial-image ?- Use above in boot_get_fpga
?- for xilinx fpgas double check using image size to determine ???if image is a partial image
---

?common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
?common/image.c?????| 51 ++++++++++++++++++++++++++++++++-------------------
?include/image.h????|??5 +++++

?3 files changed, 88 insertions(+), 19 deletions(-)

common/image-fit.c +0 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 ?}

?
?/**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga data is
+ * intended.??If the property is not found, we default to 0.
+ *
+ * returns:
+ *?????0, on devnum not found
+ *?????value, on devnum found
+ */

common/image-fit.c +6 -0
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP,

&len);

common/image-fit.c +4 -0
+	if (value == NULL || len != sizeof(int))
+		*devnum = 0;
+	else
+		*devnum = *value;
Quoted 8 lines

common/image-fit.c ulong fit_get_end(const void *fit) · line 946

Quoted 6 lines
common/image-fit.c +6 -0
+
+	return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga

bitstream.

will do.

Quoted 132 lines
Quoted 122 lines

+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ *?????0, on devnum not found
+ *?????value, on devnum found
+ */

common/image-fit.c +6 -0
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP,

&len);

common/image-fit.c +7 -0
+	if ((value == NULL || len != sizeof(int)) || (value == 0))
+		return 0;
+	else
+		return 1;
+}
+
+/**

? * fit_set_timestamp - set node timestamp property ? * @fit: pointer to the FIT format image header ? * @noffset: node offset

common/image.c +0 -0
index 0f88984..6480b0a 100644
@@ -1306,7 +1306,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t
 arch,
 ?}

?
?#if IMAGE_ENABLE_FIT

common/image.c +1 -1
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)

?int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
? ??uint8_t arch, const ulong *ld_start, ulong * const
ld_len)
?{

common/image.c +4 -3
@@ -1316,9 +1316,10 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 ?	int fit_img_result;
 ?	const 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;
+	int devnum;
+	const fpga_desc *desc;
+	xilinx_desc *desc_xilinx;
+	bitstream_type bstype = BIT_FULL;

?
? /* Check to see if the images struct has a FIT configuration */
? if (!genimg_has_config(images)) {

common/image.c +0 -0
@@ -1365,26 +1366,38 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 ?			return fit_img_result;
 ?		}

?

common/image.c +0 -6
-		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,

common/image.c +0 -7
-						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,

common/image.c +8 -1
-						img_len, BIT_PARTIAL);
+		/* Get FPGA device number, defaults to 0 */
+		fit_image_fpga_get_devnum(buf, conf_noffset, &devnum);
+
+		/* Check bitstream type */
+		if (fit_image_fpga_is_partial(buf, conf_noffset))
+			bstype = BIT_PARTIAL;
+
+		/* Legacy support detecting partial config files for Xilinx

*/

common/image.c +5 -0
+		desc = fpga_get_desc(devnum);
+		if (desc->devtype == fpga_xilinx) {
+			desc_xilinx = desc->devdesc;
+			if (img_len < desc_xilinx->size)
+				bstype = BIT_PARTIAL;

? }
?

common/image.c +7 -0
+		/* Try bitstream format first */
+		err = fpga_loadbitstream(devnum, (char *)img_data,
+					?img_len, bstype);
+		if (err)
+			err = fpga_load(devnum, (const void *)img_data,
+					img_len, bstype);
+

? if (err)
? return err;
?

common/image.c +7 -1
-		printf("???Programming %s bitstream... OK\n", name);
+		if (bstype == BIT_PARTIAL)
+			name = "partial";
+		else
+			name = "full";
+
+		printf("???Programming %s bitstream into fpga %d... OK\n",
+		???????name, devnum);

? break;
? default:
? printf("The given image format is not supported
(corrupt?)\n");

include/image.h +0 -0
index 1e686b7..75d2afc 100644
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
Quoted 4 lines

?#define FIT_COMP_PROP "compression"
?#define FIT_ENTRY_PROP "entry"
?#define FIT_LOAD_PROP "load"
+#define FIT_FPGA_DEVNUM_PROP "fpga-devnum"

tbh I am not quite sure if we should introduce this. Please look below.

Quoted 1 line
Quoted 4 lines
Quoted 1 line

+#define FIT_FPGA_PARTIAL_PROP "fpga-partial-image"

I would suggest to use "partial-fpga-config" because this is what Alan is pushing to mainline kernel. Make no sense to use something different.

Good point.

Quoted 43 lines
Quoted 12 lines

?
?/* configuration node */
?#define FIT_KERNEL_PROP "kernel"

include/image.h +0 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int
 noffset, uint8_t **value,

?
?int fit_set_timestamp(void *fit, int noffset, time_t timestamp); ?

include/image.h +3 -0
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);
+
Quoted 4 lines

?/**
? * fit_add_verification_data() - add verification data to FIT image nodes ? *

I have not a problem with this patch. I didn't test it yet but I will do it. It should probably go through my tree anyway.

There are some things which should be good to keep in mind.
1. DM - all fpga drivers are using legacy model and we should really consider to move that stuff to DM and use binding for it.

2. overlays. DT overlays were added recently to u-boot and we should add support for it. Then in general fpga commands can go away entirely and we will just apply overlays directly and this will require DM.

/ {
????????fragment {
????????????????target = <&fpga_region0>; ????????????????__overlay__ { ????????????????????????#address-cells = <1>; ????????????????????????#size-cells = <1>; ????????????????????????firmware-name = "XXXX"; ????????????????????????partial-fpga-config; ????????????????????????gpio_on: gpio at 412c0000 {
...
????????????????????????}; ????????????????};
????????};
};

Quoted 1 line

Here is visible that target replaces devnum.

I do love overlays, but am not sure if target would replace devnum. ?My intent for devnum is to support multiple fpgas, not multiple fpga regions. That said, nothing says an fpga region couldnt point to fpga managers for the different fgpa devices...

I also think that even if support for overlays is implemented in uboot there is a case for the simpler method where the end os is not linux. Maybe after DM is implemented the fitimage can use target instead of devnum?

--dalon

Quoted 7 lines

3. maybe before overlays we can add support for simple cases as I supported now.

Definitely there is a lot of work which need to be done.

Thanks,
Michal

#4 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

Quoted 248 lines · Dalon Westergreen
Quoted 54 lines · Michal Simek
Quoted 53 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

--
Changes in v3:
- Fix typos/caps in comments
Changes in v2:
- Add fitimage support for fpga-devnum and fpga-partial-image
- Use above in boot_get_fpga
- for xilinx fpgas double check using image size to determine if image is a partial image

---
 common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     | 51 ++++++++++++++++++++++++++++++++-------------------
 include/image.h    |  5 +++++
 3 files changed, 88 insertions(+), 19 deletions(-)
common/image-fit.c +6 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 }
 
 /**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga

data is
+ * intended. If the property is not found, we default to 0.
+ *
+ * returns:
+ * 0, on devnum not found
+ * value, on devnum found
+ */

common/image-fit.c +6 -0
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP,

&len);

common/image-fit.c +4 -0
+	if (value == NULL || len != sizeof(int))
+		*devnum = 0;
+	else
+		*devnum = *value;
Quoted 8 lines

common/image-fit.c ulong fit_get_end(const void *fit) · line 946

Quoted 6 lines
common/image-fit.c +6 -0
+
+	return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga

bitstream.

will do.

Quoted 132 lines
Quoted 122 lines

+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ * 0, on devnum not found
+ * value, on devnum found
+ */

common/image-fit.c +6 -0
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+	int len;
+	int *value;
+
+	value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP,

&len);

common/image-fit.c +7 -0
+	if ((value == NULL || len != sizeof(int)) || (value == 0))
+		return 0;
+	else
+		return 1;
+}
+
+/**
  * fit_set_timestamp - set node timestamp property
  * @fit: pointer to the FIT format image header
  * @noffset: node offset
common/image.c +1 -1
index 0f88984..6480b0a 100644
@@ -1306,7 +1306,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t
 arch,
 }
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)
 int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 		  uint8_t arch, const ulong *ld_start, ulong * const

ld_len)
{

common/image.c +4 -3
@@ -1316,9 +1316,10 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 	int fit_img_result;
 	const 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;
+	int devnum;
+	const fpga_desc *desc;
+	xilinx_desc *desc_xilinx;
+	bitstream_type bstype = BIT_FULL;
 
 	/* Check to see if the images struct has a FIT configuration */
common/image.c +27 -15
 	if (!genimg_has_config(images)) {
@@ -1365,26 +1366,38 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 			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);
+		/* Get FPGA device number, defaults to 0 */
+		fit_image_fpga_get_devnum(buf, conf_noffset, &devnum);
+
+		/* Check bitstream type */
+		if (fit_image_fpga_is_partial(buf, conf_noffset))
+			bstype = BIT_PARTIAL;
+
+		/* Legacy support detecting partial config files for Xilinx
 */
+		desc = fpga_get_desc(devnum);
+		if (desc->devtype == fpga_xilinx) {
+			desc_xilinx = desc->devdesc;
+			if (img_len < desc_xilinx->size)
+				bstype = BIT_PARTIAL;
 		}
 
+		/* Try bitstream format first */
+		err = fpga_loadbitstream(devnum, (char *)img_data,
+					 img_len, bstype);
+		if (err)
+			err = fpga_load(devnum, (const void *)img_data,
+					img_len, bstype);
+
 		if (err)
 			return err;
 
-		printf("   Programming %s bitstream... OK\n", name);
+		if (bstype == BIT_PARTIAL)
+			name = "partial";
+		else
+			name = "full";
+
+		printf("   Programming %s bitstream into fpga %d... OK\n",
+		       name, devnum);
 		break;
 	default:
 		printf("The given image format is not supported

(corrupt?)\n");

include/image.h +0 -0
index 1e686b7..75d2afc 100644

include/image.h int bootz_setup(ulong image, ulong *start, ulong *end); · line 879

Quoted 4 lines
include/image.h +1 -0
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
 #define FIT_COMP_PROP		"compression"
 #define FIT_ENTRY_PROP		"entry"
 #define FIT_LOAD_PROP		"load"
+#define FIT_FPGA_DEVNUM_PROP	"fpga-devnum"

tbh I am not quite sure if we should introduce this. Please look below.

Quoted 1 line
Quoted 4 lines
Quoted 1 line

+#define FIT_FPGA_PARTIAL_PROP "fpga-partial-image"

I would suggest to use "partial-fpga-config" because this is what Alan is pushing to mainline kernel. Make no sense to use something different.

Good point.

Quoted 43 lines
Quoted 14 lines

/* configuration node */
#define FIT_KERNEL_PROP "kernel"

include/image.h +3 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int
 noffset, uint8_t **value,
 
 int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);
+
 /**
  * fit_add_verification_data() - add verification data to FIT image nodes
Quoted 2 lines

*

I have not a problem with this patch. I didn't test it yet but I will do it. It should probably go through my tree anyway.

There are some things which should be good to keep in mind.
1. DM - all fpga drivers are using legacy model and we should really consider to move that stuff to DM and use binding for it.

2. overlays. DT overlays were added recently to u-boot and we should add support for it. Then in general fpga commands can go away entirely and we will just apply overlays directly and this will require DM.

/ {
        fragment {
                target = <&fpga_region0>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <1>;
                        firmware-name = "XXXX";
                        partial-fpga-config;
                        gpio_on: gpio at 412c0000 {
...
                        };
                };
        };
};
Quoted 6 lines
Quoted 1 line

Here is visible that target replaces devnum.

I do love overlays, but am not sure if target would replace devnum. My intent for devnum is to support multiple fpgas, not multiple fpga regions. That said, nothing says an fpga region couldnt point to fpga managers for the different fgpa devices...

right. fpga region has fpga-mgr property and in general you can use this link as target instead.

Quoted 5 lines

I also think that even if support for overlays is implemented in uboot there is a case for the simpler method where the end os is not linux. Maybe after DM is implemented the fitimage can use target instead of devnum?

not sure if you have system with multiple fpgas to load. Definitely it is easy to set it up.
If you don't have this setup I would add this patch without devnum specified and 0 is used all the time which is common case.
And let's start to look at DM where we can get that link for others fpgas.

Thanks,
Michal

#5 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

In reply to Dalon Westergreen

Hi Dalon,

Quoted 3 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

Can you add some docs somewhere to explain how this is used? E.g. you could update something in doc/uImage.FIT/

Quoted 33 lines

--
Changes in v3:
- Fix typos/caps in comments
Changes in v2:
- Add fitimage support for fpga-devnum and fpga-partial-image
- Use above in boot_get_fpga
- for xilinx fpgas double check using image size to determine if image is a partial image

---
 common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     | 51 ++++++++++++++++++++++++++++++++-------------------
 include/image.h    |  5 +++++
 3 files changed, 88 insertions(+), 19 deletions(-)
common/image-fit.c +8 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 }
 
 /**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga data is
+ * intended.  If the property is not found, we default to 0.
+ *

common/image-fit.c ulong fit_get_end(const void *fit) · line 936

Quoted 10 lines
common/image-fit.c +10 -0
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found
+ */
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+       int len;
+       int *value;
+
+       value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP, &len);

Can you use fdtdec_get_int()? It handles the endian conversion automatically.

common/image-fit.c ulong fit_get_end(const void *fit) · line 946

Quoted 10 lines
common/image-fit.c +10 -0
+       if (value == NULL || len != sizeof(int))
+               *devnum = 0;
+       else
+               *devnum = *value;
+
+       return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga

This doesn't explain very much - can you rephrase?

common/image-fit.c ulong fit_get_end(const void *fit) · line 955

Quoted 9 lines
common/image-fit.c +9 -0
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found

But it seems to return 0 or 1?

common/image-fit.c ulong fit_get_end(const void *fit) · line 963

Quoted 8 lines
common/image-fit.c +8 -0
+ */
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+       int len;
+       int *value;
+
+       value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP, &len);
+       if ((value == NULL || len != sizeof(int)) || (value == 0))

Is this boolean? Could you use fdtdec_get_bool()?

Quoted 54 lines
common/image-fit.c +6 -0
+               return 0;
+       else
+               return 1;
+}
+
+/**
  * fit_set_timestamp - set node timestamp property
  * @fit: pointer to the FIT format image header
  * @noffset: node offset
common/image.c +5 -18
index 0f88984..6480b0a 100644
@@ -1306,7 +1306,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t arch,
 }
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)
 int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
                  uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
@@ -1316,9 +1316,10 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
        int fit_img_result;
        const 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;
+       int devnum;
+       const fpga_desc *desc;
+       xilinx_desc *desc_xilinx;
+       bitstream_type bstype = BIT_FULL;
 
        /* Check to see if the images struct has a FIT configuration */
        if (!genimg_has_config(images)) {
@@ -1365,26 +1366,38 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
                        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);

common/image.c int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images, · line 1378

Quoted 10 lines
common/image.c +10 -0
+               /* Get FPGA device number, defaults to 0 */
+               fit_image_fpga_get_devnum(buf, conf_noffset, &devnum);
+
+               /* Check bitstream type */
+               if (fit_image_fpga_is_partial(buf, conf_noffset))
+                       bstype = BIT_PARTIAL;
+
+               /* Legacy support detecting partial config files for Xilinx */
+               desc = fpga_get_desc(devnum);
+               if (desc->devtype == fpga_xilinx) {

Can we use FPGA_XILINX?

Quoted 40 lines
common/image.c +17 -1
+                       desc_xilinx = desc->devdesc;
+                       if (img_len < desc_xilinx->size)
+                               bstype = BIT_PARTIAL;
                }
 
+               /* Try bitstream format first */
+               err = fpga_loadbitstream(devnum, (char *)img_data,
+                                        img_len, bstype);
+               if (err)
+                       err = fpga_load(devnum, (const void *)img_data,
+                                       img_len, bstype);
+
                if (err)
                        return err;
 
-               printf("   Programming %s bitstream... OK\n", name);
+               if (bstype == BIT_PARTIAL)
+                       name = "partial";
+               else
+                       name = "full";
+
+               printf("   Programming %s bitstream into fpga %d... OK\n",
+                      name, devnum);
                break;
        default:
                printf("The given image format is not supported (corrupt?)\n");
include/image.h +2 -0
index 1e686b7..75d2afc 100644
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
 #define FIT_COMP_PROP          "compression"
 #define FIT_ENTRY_PROP         "entry"
 #define FIT_LOAD_PROP          "load"
+#define FIT_FPGA_DEVNUM_PROP   "fpga-devnum"
+#define FIT_FPGA_PARTIAL_PROP  "fpga-partial-image"
 
 /* configuration node */
 #define FIT_KERNEL_PROP                "kernel"

include/image.h int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, · line 961

Quoted 5 lines
include/image.h +2 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
 
 int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);

Can you put the function comments here instead of in the C file?

Quoted 11 lines
include/image.h +1 -1
+
 /**
  * fit_add_verification_data() - add verification data to FIT image nodes
  *
--

2.7.4

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

#6 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

Hi Dalon,

Quoted 34 lines · Simon Glass

Hi Dalon,

Quoted 3 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

Can you add some docs somewhere to explain how this is used? E.g. you could update something in doc/uImage.FIT/

Quoted 24 lines

--
Changes in v3:
- Fix typos/caps in comments
Changes in v2:
- Add fitimage support for fpga-devnum and fpga-partial-image
- Use above in boot_get_fpga
- for xilinx fpgas double check using image size to determine if image is a partial image

---
 common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     | 51 ++++++++++++++++++++++++++++++++-------------------
 include/image.h    |  5 +++++
 3 files changed, 88 insertions(+), 19 deletions(-)
common/image-fit.c +0 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 }
 
Quoted 8 lines

common/image-fit.c ulong fit_get_end(const void *fit) · line 925

Quoted 8 lines
common/image-fit.c +7 -0
 /**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga data is
+ * intended.  If the property is not found, we default to 0.

Repeating these function names in the decriptions could IMHO be avoided. Also please check double spacing.

Quoted 4 lines

common/image-fit.c ulong fit_get_end(const void *fit) · line 929

Quoted 4 lines
common/image-fit.c +4 -0
+ *
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found

This seems to always return 0. Should it instead of providing devnum as an argument return devnum?

Quoted 128 lines

common/image-fit.c ulong fit_get_end(const void *fit) · line 936

Quoted 7 lines
common/image-fit.c +7 -0
+ */
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+       int len;
+       int *value;
+
+       value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP, &len);

Can you use fdtdec_get_int()? It handles the endian conversion automatically.

common/image-fit.c ulong fit_get_end(const void *fit) · line 946

Quoted 10 lines
common/image-fit.c +10 -0
+       if (value == NULL || len != sizeof(int))
+               *devnum = 0;
+       else
+               *devnum = *value;
+
+       return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga

This doesn't explain very much - can you rephrase?

common/image-fit.c ulong fit_get_end(const void *fit) · line 955

Quoted 9 lines
common/image-fit.c +9 -0
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ *     0, on devnum not found
+ *     value, on devnum found

But it seems to return 0 or 1?

common/image-fit.c ulong fit_get_end(const void *fit) · line 963

Quoted 8 lines
common/image-fit.c +8 -0
+ */
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+       int len;
+       int *value;
+
+       value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP, &len);
+       if ((value == NULL || len != sizeof(int)) || (value == 0))

Is this boolean? Could you use fdtdec_get_bool()?

Quoted 54 lines
common/image-fit.c +6 -0
+               return 0;
+       else
+               return 1;
+}
+
+/**
  * fit_set_timestamp - set node timestamp property
  * @fit: pointer to the FIT format image header
  * @noffset: node offset
common/image.c +5 -18
index 0f88984..6480b0a 100644
@@ -1306,7 +1306,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t arch,
 }
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)
 int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
                  uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
@@ -1316,9 +1316,10 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
        int fit_img_result;
        const 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;
+       int devnum;
+       const fpga_desc *desc;
+       xilinx_desc *desc_xilinx;
+       bitstream_type bstype = BIT_FULL;
 
        /* Check to see if the images struct has a FIT configuration */
        if (!genimg_has_config(images)) {
@@ -1365,26 +1366,38 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
                        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);

common/image.c int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images, · line 1378

Quoted 10 lines
common/image.c +10 -0
+               /* Get FPGA device number, defaults to 0 */
+               fit_image_fpga_get_devnum(buf, conf_noffset, &devnum);
+
+               /* Check bitstream type */
+               if (fit_image_fpga_is_partial(buf, conf_noffset))
+                       bstype = BIT_PARTIAL;
+
+               /* Legacy support detecting partial config files for Xilinx */
+               desc = fpga_get_desc(devnum);
+               if (desc->devtype == fpga_xilinx) {

Can we use FPGA_XILINX?

Quoted 15 lines
common/image.c +10 -0
+                       desc_xilinx = desc->devdesc;
+                       if (img_len < desc_xilinx->size)
+                               bstype = BIT_PARTIAL;
                }
 
+               /* Try bitstream format first */
+               err = fpga_loadbitstream(devnum, (char *)img_data,
+                                        img_len, bstype);
+               if (err)
+                       err = fpga_load(devnum, (const void *)img_data,
+                                       img_len, bstype);
+
                if (err)
                        return err;
 
Quoted 8 lines

common/image.c int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images, · line 1400

Quoted 8 lines
common/image.c +7 -1
-               printf("   Programming %s bitstream... OK\n", name);
+               if (bstype == BIT_PARTIAL)
+                       name = "partial";
+               else
+                       name = "full";
+
+               printf("   Programming %s bitstream into fpga %d... OK\n",
+                      name, devnum);

At this point the bitstream is already programmed. Should the above print reflect this? Also, why the extra spacing?

BR,
Tomas

Quoted 44 lines
Quoted 17 lines
common/image.c +0 -0
                break;
        default:
                printf("The given image format is not supported (corrupt?)\n");
include/image.h +2 -0
index 1e686b7..75d2afc 100644
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong *end);
 #define FIT_COMP_PROP          "compression"
 #define FIT_ENTRY_PROP         "entry"
 #define FIT_LOAD_PROP          "load"
+#define FIT_FPGA_DEVNUM_PROP   "fpga-devnum"
+#define FIT_FPGA_PARTIAL_PROP  "fpga-partial-image"
 
 /* configuration node */
 #define FIT_KERNEL_PROP                "kernel"

include/image.h int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, · line 961

Quoted 5 lines
include/image.h +2 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
 
 int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);

Can you put the function comments here instead of in the C file?

Quoted 11 lines
include/image.h +1 -1
+
 /**
  * fit_add_verification_data() - add verification data to FIT image nodes
  *
--

2.7.4

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#7 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

Quoted 42 lines · Tomas Melin

Hi Dalon,

Quoted 39 lines · Simon Glass

Hi Dalon,

Quoted 4 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

Can you add some docs somewhere to explain how this is used? E.g. you could update something in doc/uImage.FIT/

Quoted 27 lines

--
Changes in v3:
?- Fix typos/caps in comments
Changes in v2:
?- Add fitimage support for fpga-devnum and fpga-partial-image ?- Use above in boot_get_fpga
?- for xilinx fpgas double check using image size to determine ???if image is a partial image
---
?common/image-fit.c | 51
+++++++++++++++++++++++++++++++++++++++++++++++++++
?common/image.c?????| 51 ++++++++++++++++++++++++++++++++----------------- --
?include/image.h????|??5 +++++
?3 files changed, 88 insertions(+), 19 deletions(-)

common/image-fit.c +0 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 ?}
 
Quoted 12 lines
Quoted 9 lines
Quoted 9 lines

?/**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga data is
+ * intended.??If the property is not found, we default to 0.

Repeating these function names in the decriptions could IMHO be avoided. Also please check double spacing.

i can remove that, i just followed what seemed like the convention in the functions surrounding this one.

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

+ *
+ * returns:
+ *?????0, on devnum not found
+ *?????value, on devnum found

This seems to always return 0. Should it instead of providing devnum as an argument return devnum?

Yes, easy enough.?

Quoted 145 lines
Quoted 145 lines
Quoted 10 lines

+ */

common/image-fit.c +6 -0
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+???????int len;
+???????int *value;
+
+???????value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP,

&len);

Can you use fdtdec_get_int()? It handles the endian conversion automatically.

common/image-fit.c ulong fit_get_end(const void *fit) · line 946

Quoted 11 lines

+???????if (value == NULL || len != sizeof(int))
+???????????????*devnum = 0;
+???????else
+???????????????*devnum = *value;

common/image-fit.c +6 -0
+
+???????return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga

This doesn't explain very much - can you rephrase?

Quoted 10 lines

+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ *?????0, on devnum not found
+ *?????value, on devnum found

But it seems to return 0 or 1?

Quoted 10 lines

+ */

common/image-fit.c +6 -0
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+???????int len;
+???????int *value;
+
+???????value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP,

&len);
+???????if ((value == NULL || len != sizeof(int)) || (value == 0))

Is this boolean? Could you use fdtdec_get_bool()?

Quoted 69 lines

+???????????????return 0;
+???????else
+???????????????return 1;

common/image-fit.c +3 -0
+}
+
+/**

? * fit_set_timestamp - set node timestamp property ? * @fit: pointer to the FIT format image header ? * @noffset: node offset

common/image.c +0 -0
index 0f88984..6480b0a 100644
@@ -1306,7 +1306,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t
 arch,
 ?}
 

?#if IMAGE_ENABLE_FIT

common/image.c +1 -1
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)

?int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images, ??????????????????uint8_t arch, const ulong *ld_start, ulong * const ld_len)
?{

common/image.c +4 -3
@@ -1316,9 +1316,10 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 ????????int fit_img_result;
 ????????const 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;
+???????int devnum;
+???????const fpga_desc *desc;
+???????xilinx_desc *desc_xilinx;
+???????bitstream_type bstype = BIT_FULL;
 

????????/* Check to see if the images struct has a FIT configuration */ ????????if (!genimg_has_config(images)) {

common/image.c +8 -14
@@ -1365,26 +1366,38 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 ????????????????????????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);
+???????????????/* Get FPGA device number, defaults to 0 */
+???????????????fit_image_fpga_get_devnum(buf, conf_noffset, &devnum);
+
+???????????????/* Check bitstream type */
+???????????????if (fit_image_fpga_is_partial(buf, conf_noffset))
+???????????????????????bstype = BIT_PARTIAL;
+
+???????????????/* Legacy support detecting partial config files for
Quoted 3 lines

Xilinx */
+???????????????desc = fpga_get_desc(devnum); +???????????????if (desc->devtype == fpga_xilinx) {

Can we use FPGA_XILINX?

Quoted 16 lines

+???????????????????????desc_xilinx = desc->devdesc; +???????????????????????if (img_len < desc_xilinx->size) +???????????????????????????????bstype = BIT_PARTIAL; ????????????????}

+???????????????/* Try bitstream format first */ +???????????????err = fpga_loadbitstream(devnum, (char *)img_data, +????????????????????????????????????????img_len, bstype); +???????????????if (err)
+???????????????????????err = fpga_load(devnum, (const void *)img_data, +???????????????????????????????????????img_len, bstype);
+
????????????????if (err)
????????????????????????return err;

Quoted 11 lines
Quoted 8 lines
Quoted 8 lines

-???????????????printf("???Programming %s bitstream... OK\n", name); +???????????????if (bstype == BIT_PARTIAL) +???????????????????????name = "partial";
+???????????????else
+???????????????????????name = "full";
+
+???????????????printf("???Programming %s bitstream into fpga %d... OK\n", +??????????????????????name, devnum);

At this point the bitstream is already programmed. Should the above print reflect this? Also, why the extra spacing?

I agree, frankly i just left this how it was originally. ?I will reorder this.

Thanks,
Dalon

Quoted 54 lines

BR,
Tomas

Quoted 50 lines
Quoted 21 lines

????????????????break;
????????default:
????????????????printf("The given image format is not supported (corrupt?)\n");

include/image.h +0 -0
index 1e686b7..75d2afc 100644
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong
 *end);

?#define FIT_COMP_PROP??????????"compression"
?#define FIT_ENTRY_PROP?????????"entry"
?#define FIT_LOAD_PROP??????????"load"

include/image.h +2 -0
+#define FIT_FPGA_DEVNUM_PROP???"fpga-devnum"
+#define FIT_FPGA_PARTIAL_PROP??"fpga-partial-image"

?/* configuration node */
?#define FIT_KERNEL_PROP????????????????"kernel"

include/image.h int fit_image_hash_get_value(const void *fit, int · line 962

Quoted 6 lines
include/image.h +2 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int
 noffset, uint8_t **value,
 
 ?int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);

Can you put the function comments here instead of in the C file?

Quoted 8 lines
include/image.h +1 -0
+

?/**
? * fit_add_verification_data() - add verification data to FIT image nodes ? *
--
2.7.4

Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#8 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

In reply to Simon Glass
Quoted 10 lines · Simon Glass

Hi Dalon,

Quoted 4 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

Can you add some docs somewhere to explain how this is used? E.g. you could update something in doc/uImage.FIT/

sure thing.?

Quoted 50 lines
Quoted 45 lines

--
Changes in v3:
?- Fix typos/caps in comments
Changes in v2:
?- Add fitimage support for fpga-devnum and fpga-partial-image ?- Use above in boot_get_fpga
?- for xilinx fpgas double check using image size to determine ???if image is a partial image
---

?common/image-fit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
?common/image.c?????| 51 ++++++++++++++++++++++++++++++++-------------------
?include/image.h????|??5 +++++

?3 files changed, 88 insertions(+), 19 deletions(-)

common/image-fit.c +0 -0
index 109ecfa..eb0c633 100644
@@ -916,6 +916,57 @@ ulong fit_get_end(const void *fit)
 ?}
 

?/**
+ * fit_image_fpga_get_devnum - get fpga devnum
+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ * @devnum: pointer to an int, will hold fpga devnum
+ *
+ * fit_image_fpga_get_devnum() finds the fpga devnum for which the fpga data is
+ * intended.??If the property is not found, we default to 0.
+ *
+ * returns:
+ *?????0, on devnum not found
+ *?????value, on devnum found
+ */

common/image-fit.c +6 -0
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum)
+{
+???????int len;
+???????int *value;
+
+???????value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_DEVNUM_PROP,
Quoted 1 line

&len);

Can you use fdtdec_get_int()? It handles the endian conversion automatically.

Quoted 1 line
Quoted 12 lines

common/image-fit.c ulong fit_get_end(const void *fit) · line 946

Quoted 10 lines

+???????if (value == NULL || len != sizeof(int))
+???????????????*devnum = 0;
+???????else
+???????????????*devnum = *value;

common/image-fit.c +6 -0
+
+???????return 0;
+}
+
+/**
+ * fit_image_fpga_is_partial - is partial fpga

This doesn't explain very much - can you rephrase?

Yes, i will elaboate

Quoted 12 lines
Quoted 11 lines

+ * @fit: pointer to the FIT format image header
+ * @noffset: fpga node offset
+ *
+ * fit_image_fpga_is_partial() checks if the fpga node sets the property
+ * indicating the data represents a partial fpga image.
+ *
+ * returns:
+ *?????0, on devnum not found
+ *?????value, on devnum found

Quoted 1 line

But it seems to return 0 or 1?

Bad cut and paste... i will fix this.

Quoted 78 lines
Quoted 10 lines

+ */

common/image-fit.c +6 -0
+int fit_image_fpga_is_partial(const void *fit, int noffset)
+{
+???????int len;
+???????int *value;
+
+???????value = (int *)fdt_getprop(fit, noffset, FIT_FPGA_PARTIAL_PROP,

&len);
+???????if ((value == NULL || len != sizeof(int)) || (value == 0))

Is this boolean? Could you use fdtdec_get_bool()?

Quoted 65 lines

+???????????????return 0;
+???????else
+???????????????return 1;

common/image-fit.c +3 -0
+}
+
+/**

? * fit_set_timestamp - set node timestamp property ? * @fit: pointer to the FIT format image header ? * @noffset: node offset

common/image.c +0 -0
index 0f88984..6480b0a 100644
@@ -1306,7 +1306,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t
 arch,
 ?}
 

?#if IMAGE_ENABLE_FIT

common/image.c +1 -1
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)

?int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images, ??????????????????uint8_t arch, const ulong *ld_start, ulong * const ld_len) ?{

common/image.c +4 -3
@@ -1316,9 +1316,10 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 ????????int fit_img_result;
 ????????const 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;
+???????int devnum;
+???????const fpga_desc *desc;
+???????xilinx_desc *desc_xilinx;
+???????bitstream_type bstype = BIT_FULL;
 

????????/* Check to see if the images struct has a FIT configuration */ ????????if (!genimg_has_config(images)) {

common/image.c +5 -14
@@ -1365,26 +1366,38 @@ int boot_get_fpga(int argc, char * const argv[],
 bootm_headers_t *images,
 ????????????????????????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);
+???????????????/* Get FPGA device number, defaults to 0 */
+???????????????fit_image_fpga_get_devnum(buf, conf_noffset, &devnum);
+
+???????????????/* Check bitstream type */
+???????????????if (fit_image_fpga_is_partial(buf, conf_noffset))
Quoted 8 lines

common/image.c int boot_get_fpga(int argc, char * const argv[], · line 1382

Quoted 6 lines
common/image.c +5 -0
+???????????????????????bstype = BIT_PARTIAL;
+
+???????????????/* Legacy support detecting partial config files for Xilinx
 */
+???????????????desc = fpga_get_desc(devnum);
+???????????????if (desc->devtype == fpga_xilinx) {

Can we use FPGA_XILINX?

This enum type is defined in fpga.h and is lower case there as well.

Quoted 44 lines
Quoted 44 lines
common/image.c +17 -1
+???????????????????????desc_xilinx = desc->devdesc;
+???????????????????????if (img_len < desc_xilinx->size)
+???????????????????????????????bstype = BIT_PARTIAL;
 ????????????????}
 
+???????????????/* Try bitstream format first */
+???????????????err = fpga_loadbitstream(devnum, (char *)img_data,
+????????????????????????????????????????img_len, bstype);
+???????????????if (err)
+???????????????????????err = fpga_load(devnum, (const void *)img_data,
+???????????????????????????????????????img_len, bstype);
+
 ????????????????if (err)
 ????????????????????????return err;
 
-???????????????printf("???Programming %s bitstream... OK\n", name);
+???????????????if (bstype == BIT_PARTIAL)
+???????????????????????name = "partial";
+???????????????else
+???????????????????????name = "full";
+
+???????????????printf("???Programming %s bitstream into fpga %d... OK\n",
+??????????????????????name, devnum);

????????????????break;
????????default:
????????????????printf("The given image format is not supported (corrupt?)\n");

include/image.h +0 -0
index 1e686b7..75d2afc 100644
@@ -876,6 +876,8 @@ int bootz_setup(ulong image, ulong *start, ulong *end);

?#define FIT_COMP_PROP??????????"compression"
?#define FIT_ENTRY_PROP?????????"entry"
?#define FIT_LOAD_PROP??????????"load"

include/image.h +2 -0
+#define FIT_FPGA_DEVNUM_PROP???"fpga-devnum"
+#define FIT_FPGA_PARTIAL_PROP??"fpga-partial-image"

?/* configuration node */
?#define FIT_KERNEL_PROP????????????????"kernel"

include/image.h +0 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int
 noffset, uint8_t **value,
 
Quoted 6 lines

include/image.h int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, · line 961

Quoted 4 lines
include/image.h +2 -0
 ?int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);

Can you put the function comments here instead of in the C file?

sure thing.

Thanks for the feedback.

--dalon

Quoted 15 lines
Quoted 8 lines
include/image.h +1 -0
+

?/**
? * fit_add_verification_data() - add verification data to FIT image nodes ? *
--
2.7.4

Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

#9 lore raw

PATCH v3 1/2 common: image: update boot_get_fpga to support arbitrary fpga image

In reply to Simon Glass
Quoted 8 lines · Simon Glass

Hi Dalon,

Quoted 4 lines · Dalon Westergreen

The implementation of boot_get_fpga only supported one fpga family. This modification allows for any of the fpga devices supported by fpga_load to be used.

[snip ...]

Quoted 6 lines
Quoted 6 lines

?/* configuration node */
?#define FIT_KERNEL_PROP????????????????"kernel"

(quoted diff) +0 -0
@@ -955,6 +957,9 @@ int fit_image_hash_get_value(const void *fit, int
 noffset, uint8_t **value,
 
Quoted 6 lines

include/image.h int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, · line 961

Quoted 4 lines
include/image.h +2 -0
 ?int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
 
+int fit_image_fpga_get_devnum(const void *fit, int noffset, int *devnum);
+int fit_image_fpga_is_partial(const void *fit, int noffset);

Can you put the function comments here instead of in the C file?

Doing this would be counter to every other function in the c file these are added to, so i think it best to leave as is.

--dalon

Quoted 15 lines
Quoted 8 lines
(quoted diff) +1 -0
+

?/**
? * fit_add_verification_data() - add verification data to FIT image nodes ? *
--
2.7.4

Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

#10 lore raw

PATCH v3 2/2 common: bootm: add support for arbitrary fgpa configuration

In reply to Dalon Westergreen

This adds support for fpga configuration data in fitimages for any fpga device supported by fpga_load. At this point fitimages only support configuration of fpga images for fpga devnum 0.

---
 common/bootm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/bootm.c +1 -1
index b2c0912..4a4b47c 100644
@@ -248,7 +248,7 @@ int bootm_find_images(int flag, int argc, char * const argv[])
 #endif
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_XILINX)
+#if defined(CONFIG_FPGA)
 	/* find bitstreams */
 	ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT,
 			    NULL, NULL);
Signature · 1 line
2.7.4