Skip to contentSkip to conversation

FPGAs as Memory Technology Devices in U-Boot

PATCH In review [email protected] 5 participants 27 messages Feb 11, 2023 – Feb 23, 2023 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

cover FPGAs as Memory Technology Devices in U-Boot

As shown at a presentation in the recent OpenEmbedded Workshop, it is possible to configure an FPGA in Passive Serial mode using a standard SPI controller, each FPGA getting its own chipselect.

https://pretalx.com/openembedded-workshop-2023/talk/D3AQ3R/

This allows you to add the FPGA to the devicetree and to use standard MTD commands, instead of the FPGA commands.

I.E: The SPI portion is

&spi1 {
    u-boot,dm-spl;
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&spi1_pins>;
    num-cs = <4>; /* Needed for GPIO cs */
    cs-gpios =
        <&gpio0 12 GPIO_ACTIVE_LOW>, /* D18,0:12 uart1_ctsn.spi1_cs0 */
        <&gpio0 13 GPIO_ACTIVE_LOW>, /* D17,0:13 uart1_rtsn.spi1_cs1 */
        <&gpio0 17 GPIO_ACTIVE_LOW>, /* K15,0:17 mii_txd2.spi1_cs2 */
        <&gpio0 16 GPIO_ACTIVE_LOW>; /* J18,0:16 mii_txd3.spi1_cs3 */
        spi-max-frequency = <10000000>; ;
        gpio_spi0: gpio_spi@0 {...}
        gpio_spi1: gpio_spi@1 {...}
        spi-fpga-cfg@2 {...} /* FPGA #1 */
        spy-fpga-cfg@3 {...} /* FPGA #2 */
};

The FPGA part is.

spi-fpga-cfg@2 { /* Intel Cyclone 10, 10CL010 */

    #address-cells = <1>;
    #size-cells = <1>;
    compatible = "intel,cyclone10";
    reg = <2>; /* Chip select 2 */
    spi-max-frequency = <10000000>;
    fpga = "spif"; /* Installed as /dev/spif */
    config-size = <368011>;
    nconfig-gpios = <&gpio3 15 GPIO_ACTIVE_HIGH>; /* ,3:15 */
    nstat-gpios = <&gpio3 19 GPIO_ACTIVE_HIGH>; /* ,3:19 */
    confd-gpios = <&gpio3 18 GPIO_ACTIVE_HIGH>; /* ,3:18 */
    crc-error-gpios= <&gpio2 1 GPIO_ACTIVE_HIGH>; /* ,2:01 */
    partition@0 {
        label = "spi-fpga";
        reg = <0x0000000 0x8000>;
    };
};

To configure the FPGA, you load the config info into RAM and write it to the FPGA.

U-BOOT> mtd read spi1 ${loadaddr} 0 ${filesize} # read from SPI U-BOOT> mtd write fpga0 ${loadaddr} 0 ${filesize} # configure FPGA

A driver will pulse the nCONFIG pin of the FPGA, do an SPI transfer and then check the FPGA status outputs.

Since the MTD command set can be used (and is needed anyway) the FPGA command set can be removed from the U-Boot both simplifying the user interface and reducing code size of the u-boot image.

It relies on the (hopefully) existing SPI driver for the chip in u-boot so it should be easy to use in most systems (as long as the H/W is designed for it)

A linux driver, using the same principle would allow the FPGA to be configured using a simple statement.

$ cat <bitfile> > /dev/fpga

The approach has been tested on a development board using an AM335x and 2 x Cyclone 10.

The changes needed are
* adding the FPGA class in mtd-abi.h
* The "mtd" command hardwires the transfer to be RAW and no OOB.
* A driver wrapping the control signals around an SPI transfer 1.Claim SPI bus
2.Pulse nCONFIG low for 40 us,
3.Wait for nSTATUS high
4.Transfer bitstream using U-Boot SPI transfer 5.Release SPI bus
6.Wait until CONFIG_DONE (or error on nSTATUS)

[PATCH 1/4] include/mtd/mtd-abi.h: Add FPGA as MTD device [PATCH 2/4] cmd/mtd.c: Support FPGAs in mtd command [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10) [PATCH 4/4] mtd/Kconfig,Makefile support FPGA

#1 lore raw

PATCH 1/4 include/mtd/mtd-abi.h: Add FPGA as MTD device

From: Ulf Samuelsson <[email protected]>

---
 include/mtd/mtd-abi.h | 2 ++
 1 file changed, 2 insertions(+)
include/mtd/mtd-abi.h +2 -0
index ea244fbaeb..cd826b64dd 100644
@@ -89,6 +89,7 @@ struct mtd_write_req {
 #define MTD_DATAFLASH		6
 #define MTD_UBIVOLUME		7
 #define MTD_MLCNANDFLASH	8	/* MLC NAND (including TLC) */
+#define	MTD_FPGA		9
 
 #define MTD_WRITEABLE		0x400	/* Device is writeable */
 #define MTD_BIT_WRITEABLE	0x800	/* Single bits can be flipped */
@@ -100,6 +101,7 @@ struct mtd_write_req {
 #define MTD_CAP_RAM		(MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
 #define MTD_CAP_NORFLASH	(MTD_WRITEABLE | MTD_BIT_WRITEABLE)
 #define MTD_CAP_NANDFLASH	(MTD_WRITEABLE)
+#define MTD_CAP_FPGA		(MTD_WRITEABLE | MTD_NO_ERASE)
 
 /* Obsolete ECC byte placement modes (used with obsolete MEMGETOOBSEL) */
 #define MTD_NANDECC_OFF		0	// Switch off ECC (Not recommended)
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/4 cmd/mtd.c: Support FPGAs in mtd command

In reply to [email protected]

From: Ulf Samuelsson <[email protected]>

---
 cmd/mtd.c | 8 ++++++++
 1 file changed, 8 insertions(+)
cmd/mtd.c +8 -0
index eb6e2d6892..09d5fdaa11 100644
@@ -158,6 +158,9 @@ static void mtd_show_device(struct mtd_info *mtd)
 	case MTD_MLCNANDFLASH:
 		printf("MLC NAND flash\n");
 		break;
+	case MTD_FPGA:
+		printf("FPGA\n");
+		break;
 	case MTD_ABSENT:
 	default:
 		printf("Unknown\n");
@@ -275,6 +278,11 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
 	raw = strstr(cmd, ".raw");
 	woob = strstr(cmd, ".oob");
 	write_empty_pages = !has_pages || strstr(cmd, ".dontskipff");
+	if (mtd->type == MTD_FPGA) {
+		raw = true;
+		woob = false;
+		write_empty_pages = true;
+	}
 
 	argc -= 2;
 	argv += 2;
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/4 mtd/fpga: add fpga directory to mtd (with Cyclone 10)

In reply to [email protected]

From: Ulf Samuelsson <[email protected]>

---
 drivers/mtd/fpga/Kconfig      |  47 ++++++
 drivers/mtd/fpga/Makefile     |   6 +
 drivers/mtd/fpga/cyclone_10.c | 278 ++++++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+)
 create mode 100644 drivers/mtd/fpga/Kconfig
 create mode 100644 drivers/mtd/fpga/Makefile
 create mode 100644 drivers/mtd/fpga/cyclone_10.c
drivers/mtd/fpga/Kconfig new file +47 -0
new file mode 100644
index 0000000000..e3aa8c4522
@@ -0,0 +1,47 @@
+menu "SPI FPGA Support"
+
+config DM_SPI_FPGA
+	bool "Enable Driver Model for FPGA configuration"
+	depends on DM && DM_SPI
+	imply SPI_FPGA
+	help
+	  Enable driver model for FPGAs configurable using SPI.
+	  This SPI FPGA interface
+	  (spi_fpga_probe(), spi_fpga_write(), etc.) is then
+	  implemented by the SPI FPGA uclass.
+	  There is one standard SPI FPGA driver which knows how to probe
+	  chips supported by U-Boot. The uclass interface is defined in
+	  include/spi_fpga.h
+	  SPI and SPI FPGA must be enabled together
+	  (it is not possible to use driver model for one and not the other).
+
+if DM_SPI_FPGA
+
+config SPI_FPGA_MTD
+	bool "SPI FPGA MTD support"
+	depends on MTD
+	help
+	  Enable the MTD support for the FPGA SPI Passive Serial,
+	  This allows mtd_write commands to load an FPGA using passive serial
+	  If unsure, say N
+
+config SPI_FPGA_INTEL
+	bool "Intel/Altera FPGA Passive Serial configuration using SPI"
+	help
+	  Add support for various Intel SPI FPGA chips
+
+config SPI_FPGA_XILINX
+	bool "Xilinx FPGA Passive Serial configuration using SPI"
+	help
+	  Add support for various Xilinx FPGA chips
+
+config SPI_FPGA_CYCLONE10
+	bool "Cyclone 10 SPI FPGA MTD support"
+	depends on SPI_FPGA_MTD && SPI_FPGA_INTEL
+	help
+	  Enable the MTD support for the Cyclone 10 FPGA
+	  If unsure, say N
+
+endif
+
+endmenu # menu "SPI FPGA Support"
drivers/mtd/fpga/Makefile new file +6 -0
new file mode 100644
index 0000000000..2cf19fc7cf
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2006
+# Wolfgang Denk, DENX Software Engineering, [email protected].
+
+obj-$(CONFIG_SPI_FPGA_CYCLONE10) += cyclone_10.o
drivers/mtd/fpga/cyclone_10.c new file +278 -0

278 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

On 2/11/23 11:07, [email protected] wrote:

[...]

drivers/mtd/fpga/cyclone_10.c line 122

Quoted 7 lines
drivers/mtd/fpga/cyclone_10.c new file +7 -0
+static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t len,
+			     size_t *retlen, const u_char *buf)
+{
+	struct udevice *dev = mtd->dev;
+	struct spi_slave *slave = dev_get_parent_priv(dev);
+	struct cyc10_plat *fpga = dev_get_plat(dev);
+	int ret;

Do I read this right, that the 'write' callback is the only one doing meaningful work, all the other callbacks are just empty stubs ?

Why not update drivers/fpga/cyclon2.c which is Passive Serial implementation already present in U-Boot for Altera Cyclone II FPGA , with Cyclone 10 FPGA support ? I believe the PS protocol changed very little.

[...]

#5 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Den 2023-02-12 kl. 20:31, skrev Marek Vasut:

Quoted 17 lines · On 2/11/23 11:07, [email protected] wrote:

[...]

drivers/mtd/fpga/cyclone_10.c line 122

Quoted 7 lines
drivers/mtd/fpga/cyclone_10.c new file +7 -0
+static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t len,
+                 size_t *retlen, const u_char *buf)
+{
+    struct udevice *dev = mtd->dev;
+    struct spi_slave *slave = dev_get_parent_priv(dev);
+    struct cyc10_plat *fpga = dev_get_plat(dev);
+    int ret;

Do I read this right, that the 'write' callback is the only one doing meaningful work, all the other callbacks are just empty stubs ? Yes, you cannot read back the configuration data.

Quoted 4 lines

Why not update drivers/fpga/cyclon2.c which is Passive Serial implementation already present in U-Boot for Altera Cyclone II FPGA , with Cyclone 10 FPGA support ? I believe the PS protocol changed very little.

Since the MTD command set is enough to configure the FPGA, the FPGA commands can be removed from the build. The FPGA command set requires you to supply addresses, but the MTD command set uses devices.

So:
* Smaller U-Boot image
* Simplified user interface.
* The FPGA is an SPI peripheral, so why not add it to the SPI part of the device tree?

Best Regards
Ulf Samuelsson

Quoted 2 lines

[...]

#6 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 18 lines · Ulf Samuelsson

Den 2023-02-12 kl. 20:31, skrev Marek Vasut:

Quoted 15 lines · On 2/11/23 11:07, [email protected] wrote:

[...]

drivers/mtd/fpga/cyclone_10.c line 122

Quoted 7 lines
drivers/mtd/fpga/cyclone_10.c new file +7 -0
+static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t len,
+                 size_t *retlen, const u_char *buf)
+{
+    struct udevice *dev = mtd->dev;
+    struct spi_slave *slave = dev_get_parent_priv(dev);
+    struct cyc10_plat *fpga = dev_get_plat(dev);
+    int ret;

Do I read this right, that the 'write' callback is the only one doing meaningful work, all the other callbacks are just empty stubs ? Yes, you cannot read back the configuration data.

That makes it look like any framework which supports "write" callback would be suitable, not just MTD framework.

Quoted 8 lines
Quoted 4 lines

Why not update drivers/fpga/cyclon2.c which is Passive Serial implementation already present in U-Boot for Altera Cyclone II FPGA , with Cyclone 10 FPGA support ? I believe the PS protocol changed very little.

Since the MTD command set is enough to configure the FPGA, the FPGA commands can be removed from the build. The FPGA command set requires you to supply addresses, but the MTD command set uses devices.

So:
* Smaller U-Boot image

The MTD framework is rather large, compared to the trivial FPGA framework. Can you back this claim with any numbers ?

Quoted 1 line

* Simplified user interface.

If I am to select between 'fpga load' and 'mtd write' for FPGA bitstream loading , my obvious choice would be 'fpga load' . How is using 'mtd write' any better or simpler ?

Quoted 1 line

* The FPGA is an SPI peripheral, so why not add it to the SPI part of the device tree?

You can add the device into DT and still operate it using the U-Boot FPGA framework, just add the DT support. Why not do it that way ?

Let me be blunt about this, I have this feeling that what is happening here is just overloading of MTD framework with unrelated functionality (FPGA bitstream loading). MTD framework simply is not the right place, esp. if there is dedicated FPGA framework, with existing Altera PS driver no less.

#7 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Den 2023-02-12 kl. 21:01, skrev Marek Vasut:

Quoted 28 lines · Ulf Samuelsson
Quoted 18 lines

Den 2023-02-12 kl. 20:31, skrev Marek Vasut:

Quoted 15 lines · On 2/11/23 11:07, [email protected] wrote:

[...]

drivers/mtd/fpga/cyclone_10.c line 122

Quoted 7 lines
drivers/mtd/fpga/cyclone_10.c new file +7 -0
+static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t len,
+                 size_t *retlen, const u_char *buf)
+{
+    struct udevice *dev = mtd->dev;
+    struct spi_slave *slave = dev_get_parent_priv(dev);
+    struct cyc10_plat *fpga = dev_get_plat(dev);
+    int ret;

Do I read this right, that the 'write' callback is the only one doing meaningful work, all the other callbacks are just empty stubs ? Yes, you cannot read back the configuration data.

That makes it look like any framework which supports "write" callback would be suitable, not just MTD framework.

Quoted 6 lines
Quoted 4 lines

Why not update drivers/fpga/cyclon2.c which is Passive Serial implementation already present in U-Boot for Altera Cyclone II FPGA , with Cyclone 10 FPGA support ? I believe the PS protocol changed very little.

Since the MTD command set is enough to configure the FPGA, the FPGA commands can be removed from the build. The FPGA command set requires you to supply addresses, but the MTD command set uses devices.

Quoted 4 lines
Quoted 2 lines

So:
* Smaller U-Boot image

The MTD framework is rather large, compared to the trivial FPGA framework. Can you back this claim with any numbers ?

I am assuming that the MTD framework is needed anyway. We certainly need it.

Quoted 5 lines
Quoted 2 lines

* Simplified user interface.

If I am to select between 'fpga load' and 'mtd write' for FPGA bitstream loading , my obvious choice would be 'fpga load' . How is using 'mtd write' any better or simpler ?

fpga load 0 ${loadaddr} ${filesize}
mtd write spy ${loadaddr}

The questions I ask myself.
So is "0" the "spy" FPGA or the "spx" FPGA?
Why should I have to remember the size of the FPGA bitstream?

Quoted 3 lines
Quoted 1 line

* The FPGA is an SPI peripheral, so why not add it to the SPI part of the device tree?

You can add the device into DT and still operate it using the U-Boot FPGA framework, just add the DT support. Why not do it that way ?

I don't think you can add the device into DT in U-Boot as it is today. You can create FPGA contents and add that to the device tree, but not the configuration itself. At least, I have not seen it.
If I have missed it, where is an example?

The FPGA framework is not really setup to use device-tree to describe configuration.

Only 5 defconfigs in U-Boot uses the FPGA framework.
* astro_mcf5373l_defconfig
* syzygy_hub_defconfig
* xilinx_zynqmp_virt_defconfig
* xilinx_zynq_virt_defconfig
* bitmain_antminer_s9_defconfig

Their device trees have leafs for configuration:
* compatible = "fpga-region";
* compatible = "xlnx,zynq-devcfg-1.0";
Neither "fpga-region" or "xlnx,zynq-devcfg-1.0" have any compatible drivers, so there is really no support for configuration based on device-tree at the moment.

If I look at boards using the Altera, no board uses a driver
to configure the FPGA. Instead they implement a number of callbacks
in the board files which manually handles the SPI bus outside the SPI driver. No trace of device tree.

Quoted 2 lines

Let me be blunt about this, I have this feeling that what is happening here is just overloading of MTD framework with unrelated functionality (FPGA bitstream loading). MTD framework simply is not the right place, esp. if there is dedicated FPGA framework, with existing Altera PS driver no less.

When you are configuring an FPGA, you are writing a bitstream to an SRAM inside the FPGA. SRAM are memories.

The MTD framework does exactly what is needed for passive serial.
I do not see that there is another place to add a device-tree based
FPGA configuration, so you basically have to replicate the MTD framework, in order to have FPGA configuration in the device tree.

Best Regards
Ulf Samuelsson

#8 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 35 lines · Ulf Samuelsson

Den 2023-02-12 kl. 21:01, skrev Marek Vasut:

Quoted 9 lines · Ulf Samuelsson
Quoted 8 lines

Den 2023-02-12 kl. 20:31, skrev Marek Vasut:
  > On 2/11/23 11:07, [email protected] wrote:
  >
  > [...]
  >
  >> +static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t

len,

Quoted 8 lines
Quoted 8 lines

  >> +                 size_t *retlen, const u_char *buf) >> +{
  >> +    struct udevice *dev = mtd->dev;
  >> +    struct spi_slave *slave = dev_get_parent_priv(dev); >> +    struct cyc10_plat *fpga = dev_get_plat(dev); >> +    int ret;
  >
  > Do I read this right, that the 'write' callback is the only one

doing

Quoted 4 lines
Quoted 2 lines

  > meaningful work, all the other callbacks are just empty stubs ? > Yes, you cannot read back the configuration data.

That makes it look like any framework which supports "write" callback

would be suitable, not just MTD framework.

Quoted 3 lines
Quoted 3 lines

  > Why not update drivers/fpga/cyclon2.c which is Passive Serial > implementation already present in U-Boot for Altera Cyclone II

FPGA ,

Quoted 1 line
Quoted 1 line

  > with Cyclone 10 FPGA support ? I believe the PS protocol changed

very

Quoted 2 lines
Quoted 2 lines

  > little.
Since the MTD command set is enough to configure the FPGA, the FPGA

commands can be removed from the build. The FPGA command set requires you to supply addresses, but the MTD command set uses devices.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

So:
* Smaller U-Boot image

The MTD framework is rather large, compared to the trivial FPGA

framework. Can you back this claim with any numbers ?

I am assuming that the MTD framework is needed anyway.

FPGA and MTD support is orthogonal, you cannot make that assumption.
Consider SoC-FPGA machine booting from eMMC, Altera Cyclone V SoC does support that mode of operation, and MTD support can be disabled.

Quoted 4 lines

We certainly need it.

Quoted 3 lines
Quoted 2 lines

* Simplified user interface.

Quoted 8 lines
Quoted 1 line

If I am to select between 'fpga load' and 'mtd write' for FPGA

bitstream loading , my obvious choice would be 'fpga load' . How is using 'mtd write' any better or simpler ?

Quoted 1 line

fpga load 0   ${loadaddr} ${filesize}
mtd write spy ${loadaddr}

The questions I ask myself.
So is "0" the "spy" FPGA or the "spx" FPGA?

You can use DT /aliases node to enumerate the FPGAs the same way i2c busses, SPI NORs, SD/MMC devices etc. are enumerated . Also have a look at e.g. 'net list' command, similar functionality can be added to the FPGA command to list all registered FPGAs.

Quoted 1 line

Why should I have to remember the size of the FPGA bitstream?

Because it is not always possible to extract that information from the bitstream blob, remember, some of those blobs may be just raw binaries of the SRAM/flash content .

Quoted 10 lines
Quoted 1 line
Quoted 1 line

* The FPGA is an SPI peripheral, so why not add it to the SPI part

of the device tree?

Quoted 2 lines

You can add the device into DT and still operate it using the U-Boot

FPGA framework, just add the DT support. Why not do it that way ?

I don't think you can add the device into DT in U-Boot as it is today. You can create FPGA contents and add that to the device tree, but not the configuration itself. At least, I have not seen it.
If I have missed it, where is an example?

Have a look at the Linux FPGA DT bindings in Documentation/devicetree/bindings/fpga/ . You can implement parsing of those bindings into the U-Boot FPGA framework and then add your FPGA device configuration interface into the DT.

Quoted 8 lines

The FPGA framework is not really setup to use device-tree to describe configuration.

Only 5 defconfigs in U-Boot uses the FPGA framework.
* astro_mcf5373l_defconfig
* syzygy_hub_defconfig
* xilinx_zynqmp_virt_defconfig
* xilinx_zynq_virt_defconfig

These two ^ cover very much every zynq 7000 and zynqmp device in existence, since the way those are used is in combination with provided custom board DT.

Quoted 1 line

* bitmain_antminer_s9_defconfig

There is also arch/arm/mach-socfpga/Kconfig: imply FPGA_SOCFPGA , which activates the CONFIG_FPGA on all of Altera Cyclone V/Arria V/Stratix 10/Agilex and whatever new SoCFPGA Intel has.

Quoted 4 lines

Their device trees have leafs for configuration:
* compatible = "fpga-region";
* compatible = "xlnx,zynq-devcfg-1.0";
Neither "fpga-region" or "xlnx,zynq-devcfg-1.0" have any compatible drivers, so there is really no support for configuration based on device-tree at the moment.

That's correct

Quoted 3 lines

If I look at boards using the Altera, no board uses a driver
to configure the FPGA. Instead they implement a number of callbacks
in the board files which manually handles the SPI bus outside the SPI driver. No trace of device tree.

Which boards do you refer to ?

Quoted 9 lines
Quoted 1 line

Let me be blunt about this, I have this feeling that what is

happening here is just overloading of MTD framework with unrelated functionality (FPGA bitstream loading). MTD framework simply is not the right place, esp. if there is dedicated FPGA framework, with existing Altera PS driver no less.

When you are configuring an FPGA, you are writing a bitstream to an SRAM inside the FPGA. SRAM are memories.

The MTD framework does exactly what is needed for passive serial.
I do not see that there is another place to add a device-tree based
FPGA configuration, so you basically have to replicate the MTD framework, in order to have FPGA configuration in the device tree.

Update the existing FPGA framework to parse the necessary DT bindings.

Please do not overload existing framework (MTD or whatever) with unrelated functionality only because it provides the .write callback. While this may look like a good idea to cover one very specific use case, it would fail once all the other use cases which are already covered by the FPGA framework come into picture.

#9 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Den 2023-02-12 kl. 23:40, skrev Marek Vasut:

Quoted 35 lines · Ulf Samuelsson
Quoted 34 lines

Den 2023-02-12 kl. 21:01, skrev Marek Vasut:
 > On 2/12/23 20:52, Ulf Samuelsson wrote:
 >>
 >>
 >> Den 2023-02-12 kl. 20:31, skrev Marek Vasut:
 >>  > On 2/11/23 11:07, [email protected] wrote:
 >>  >
 >>  > [...]
 >>  >
 >>  >> +static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t len,
 >>  >> +                 size_t *retlen, const u_char *buf)
 >>  >> +{
 >>  >> +    struct udevice *dev = mtd->dev;
 >>  >> +    struct spi_slave *slave = dev_get_parent_priv(dev);
 >>  >> +    struct cyc10_plat *fpga = dev_get_plat(dev);
 >>  >> +    int ret;
 >>  >
 >>  > Do I read this right, that the 'write' callback is the only one doing
 >>  > meaningful work, all the other callbacks are just empty stubs ?
 >>  > Yes, you cannot read back the configuration data.
 >
 > That makes it look like any framework which supports "write" callback would be suitable, not just MTD framework.
 >
 >>  > Why not update drivers/fpga/cyclon2.c which is Passive Serial
 >>  > implementation already present in U-Boot for Altera Cyclone II FPGA ,
 >>  > with Cyclone 10 FPGA support ? I believe the PS protocol changed very
 >>  > little.
 >> Since the MTD command set is enough to configure the FPGA, the FPGA commands can be removed from the build. The FPGA command set requires you to supply addresses, but the MTD command set uses devices. >>
 >> So:
 >> * Smaller U-Boot image
 >
 > The MTD framework is rather large, compared to the trivial FPGA framework. Can you back this claim with any numbers ?

Quoted 4 lines
Quoted 1 line

I am assuming that the MTD framework is needed anyway.

FPGA and MTD support is orthogonal, you cannot make that assumption.
Consider SoC-FPGA machine booting from eMMC, Altera Cyclone V SoC does support that mode of operation, and MTD support can be disabled.

If I look at Altera SOCFPGAs, I find that 21 defconfigs have MTD support and 3 do not.
* socfpga_agilex_defconfig
* socfpga_chameleonv3_defconfig
* socfpga_n5x_defconfig
so in most cases there would be a reduction in code size.

Quoted 9 lines
Quoted 9 lines

We certainly need it.
 >
 >> * Simplified user interface.
 >
 > If I am to select between 'fpga load' and 'mtd write' for FPGA bitstream loading , my obvious choice would be 'fpga load' . How is using 'mtd write' any better or simpler ? >
fpga load 0   ${loadaddr} ${filesize}
mtd write spy ${loadaddr}

Quoted 9 lines
Quoted 2 lines

The questions I ask myself.
So is "0" the "spy" FPGA or the "spx" FPGA?

You can use DT /aliases node to enumerate the FPGAs the same way i2c busses, SPI NORs, SD/MMC devices etc. are enumerated . Also have a look at e.g. 'net list' command, similar functionality can be added to the FPGA command to list all registered FPGAs.

Quoted 1 line

Why should I have to remember the size of the FPGA bitstream?

Because it is not always possible to extract that information from the bitstream blob, remember, some of those blobs may be just raw binaries of the SRAM/flash content .

The size of the FPGA will be in the devicetree, so there is no need to supply that in the command itself.

Quoted 5 lines
Quoted 4 lines

 >> * The FPGA is an SPI peripheral, so why not add it to the SPI part of the device tree?
 >
 > You can add the device into DT and still operate it using the U-Boot FPGA framework, just add the DT support. Why not do it that way ?

Quoted 7 lines
Quoted 4 lines

I don't think you can add the device into DT in U-Boot as it is today. You can create FPGA contents and add that to the device tree, but not the configuration itself. At least, I have not seen it.
If I have missed it, where is an example?

Have a look at the Linux FPGA DT bindings in Documentation/devicetree/bindings/fpga/ . You can implement parsing of those bindings into the U-Boot FPGA framework and then add your FPGA device configuration interface into the DT.

The "altr,fpga-passive-serial" driver is very close to what I did. My driver supports a superset of a devicetree for that driver. It does not look like U-Boot is setup to use that.

I feel that the FPGA manager needs a total rework to make this work
and I cannot justify that. If someone adds devicetree support to the FPGA manager, I will certainly look to adopt to it.

Quoted 20 lines
Quoted 8 lines

The FPGA framework is not really setup to use device-tree to describe configuration.

Only 5 defconfigs in U-Boot uses the FPGA framework.
* astro_mcf5373l_defconfig
* syzygy_hub_defconfig
* xilinx_zynqmp_virt_defconfig
* xilinx_zynq_virt_defconfig

These two ^ cover very much every zynq 7000 and zynqmp device in existence, since the way those are used is in combination with provided custom board DT.

Quoted 1 line

* bitmain_antminer_s9_defconfig

There is also arch/arm/mach-socfpga/Kconfig: imply FPGA_SOCFPGA , which activates the CONFIG_FPGA on all of Altera Cyclone V/Arria V/Stratix 10/Agilex and whatever new SoCFPGA Intel has.

Quoted 4 lines

Their device trees have leafs for configuration:
* compatible = "fpga-region";
* compatible = "xlnx,zynq-devcfg-1.0";
Neither "fpga-region" or "xlnx,zynq-devcfg-1.0" have any compatible drivers, so there is really no support for configuration based on device-tree at the moment.

Quoted 8 lines

That's correct

Quoted 3 lines

If I look at boards using the Altera, no board uses a driver
to configure the FPGA. Instead they implement a number of callbacks
in the board files which manually handles the SPI bus outside the SPI driver. No trace of device tree.

Which boards do you refer to ?

Every board using the Altera drivers have an Altera_desc which contains links to callbacks used by the altera driver.

cls; rgrep Altera_desc | grep -v -e drivers -e include board/beckhoff/mx53cx9020/mx53cx9020.c:static Altera_desc ccat_fpga = { board/astro/mcf5373l/fpga.c:Altera_desc altera_fpga[FPGA_COUNT] = { board/theadorable/fpga.c:static Altera_desc altera_fpga[] = {

They all access the FPGA using spi, gpio etc. outside the driver model.

Not a trace of devicetree support unfortunately.

Quoted 9 lines
Quoted 8 lines

 > Let me be blunt about this, I have this feeling that what is happening here is just overloading of MTD framework with unrelated functionality (FPGA bitstream loading). MTD framework simply is not the right place, esp. if there is dedicated FPGA framework, with existing Altera PS driver no less.

When you are configuring an FPGA, you are writing a bitstream to an SRAM inside the FPGA. SRAM are memories.

The MTD framework does exactly what is needed for passive serial.
I do not see that there is another place to add a device-tree based
FPGA configuration, so you basically have to replicate the MTD framework, in order to have FPGA configuration in the device tree.

Quoted 5 lines

Update the existing FPGA framework to parse the necessary DT bindings.

Please do not overload existing framework (MTD or whatever) with unrelated functionality only because it provides the .write callback. While this may look like a good idea to cover one very specific use case, it would fail once all the other use cases which are already covered by the FPGA framework come into picture.

I do not see why other chips could not be supported by an MTD driver. Conceptually, there is not much difference between reading/writing a NAND flash and configuring an FPGA.

Obviously, someone would have to take the time to do it, but it is certainly possible.

Best Regards
Ulf Samuelsson

#10 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 40 lines · Ulf Samuelsson

Den 2023-02-12 kl. 23:40, skrev Marek Vasut:

Quoted 37 lines · Ulf Samuelsson
Quoted 35 lines

Den 2023-02-12 kl. 21:01, skrev Marek Vasut:
 > On 2/12/23 20:52, Ulf Samuelsson wrote:
 >>
 >>
 >> Den 2023-02-12 kl. 20:31, skrev Marek Vasut:
 >>  > On 2/11/23 11:07, [email protected] wrote:
 >>  >
 >>  > [...]
 >>  >
 >>  >> +static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t len,
 >>  >> +                 size_t *retlen, const u_char *buf)
 >>  >> +{
 >>  >> +    struct udevice *dev = mtd->dev;
 >>  >> +    struct spi_slave *slave = dev_get_parent_priv(dev);
 >>  >> +    struct cyc10_plat *fpga = dev_get_plat(dev);
 >>  >> +    int ret;
 >>  >
 >>  > Do I read this right, that the 'write' callback is the only one doing
 >>  > meaningful work, all the other callbacks are just empty stubs ?
 >>  > Yes, you cannot read back the configuration data.
 >
 > That makes it look like any framework which supports "write" callback would be suitable, not just MTD framework.
 >
 >>  > Why not update drivers/fpga/cyclon2.c which is Passive Serial
 >>  > implementation already present in U-Boot for Altera Cyclone II FPGA ,
 >>  > with Cyclone 10 FPGA support ? I believe the PS protocol changed very
 >>  > little.
 >> Since the MTD command set is enough to configure the FPGA, the FPGA commands can be removed from the build. The FPGA command set requires you to supply addresses, but the MTD command set uses devices. >>
 >> So:
 >> * Smaller U-Boot image
 >
 > The MTD framework is rather large, compared to the trivial FPGA framework. Can you back this claim with any numbers ?

I am assuming that the MTD framework is needed anyway.

Quoted 8 lines
Quoted 2 lines

FPGA and MTD support is orthogonal, you cannot make that assumption.
Consider SoC-FPGA machine booting from eMMC, Altera Cyclone V SoC does support that mode of operation, and MTD support can be disabled.

If I look at Altera SOCFPGAs, I find that 21 defconfigs have MTD support and 3 do not.
* socfpga_agilex_defconfig
* socfpga_chameleonv3_defconfig
* socfpga_n5x_defconfig
so in most cases there would be a reduction in code size.

All these machines already have FPGA framework enabled, just use it or extend it.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

We certainly need it.
 >
 >> * Simplified user interface.
 >
 > If I am to select between 'fpga load' and 'mtd write' for FPGA bitstream loading , my obvious choice would be 'fpga load' . How is using 'mtd write' any better or simpler ? >
fpga load 0   ${loadaddr} ${filesize}
mtd write spy ${loadaddr}

The questions I ask myself.
So is "0" the "spy" FPGA or the "spx" FPGA?

Quoted 8 lines
Quoted 6 lines

You can use DT /aliases node to enumerate the FPGAs the same way i2c busses, SPI NORs, SD/MMC devices etc. are enumerated . Also have a look at e.g. 'net list' command, similar functionality can be added to the FPGA command to list all registered FPGAs.

Quoted 1 line

Why should I have to remember the size of the FPGA bitstream?

Because it is not always possible to extract that information from the bitstream blob, remember, some of those blobs may be just raw binaries of the SRAM/flash content .

The size of the FPGA will be in the devicetree, so there is no need to supply that in the command itself.

That stops working once you start dealing with partial reconfiguration and the bitstream size varies. Then it is back to $filesize .

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

 >> * The FPGA is an SPI peripheral, so why not add it to the SPI part of the device tree?
 >
 > You can add the device into DT and still operate it using the U-Boot FPGA framework, just add the DT support. Why not do it that way ?

I don't think you can add the device into DT in U-Boot as it is today. You can create FPGA contents and add that to the device tree, but not the configuration itself. At least, I have not seen it.
If I have missed it, where is an example?

Quoted 4 lines
Quoted 2 lines

Have a look at the Linux FPGA DT bindings in Documentation/devicetree/bindings/fpga/ . You can implement parsing of those bindings into the U-Boot FPGA framework and then add your FPGA device configuration interface into the DT.

The "altr,fpga-passive-serial" driver is very close to what I did.

If there is an existing driver, extend it, rework it, but please don't introduce new driver that does the same thing.

Quoted 5 lines

My driver supports a superset of a devicetree for that driver. It does not look like U-Boot is setup to use that.

I feel that the FPGA manager needs a total rework to make this work
and I cannot justify that. If someone adds devicetree support to the FPGA manager, I will certainly look to adopt to it.

Overloading the MTD subsystem only because it has a .write() callback is not the way to go either.

Quoted 30 lines
Quoted 20 lines
Quoted 8 lines

The FPGA framework is not really setup to use device-tree to describe configuration.

Only 5 defconfigs in U-Boot uses the FPGA framework.
* astro_mcf5373l_defconfig
* syzygy_hub_defconfig
* xilinx_zynqmp_virt_defconfig
* xilinx_zynq_virt_defconfig

These two ^ cover very much every zynq 7000 and zynqmp device in existence, since the way those are used is in combination with provided custom board DT.

Quoted 1 line

* bitmain_antminer_s9_defconfig

There is also arch/arm/mach-socfpga/Kconfig: imply FPGA_SOCFPGA , which activates the CONFIG_FPGA on all of Altera Cyclone V/Arria V/Stratix 10/Agilex and whatever new SoCFPGA Intel has.

Quoted 4 lines

Their device trees have leafs for configuration:
* compatible = "fpga-region";
* compatible = "xlnx,zynq-devcfg-1.0";
Neither "fpga-region" or "xlnx,zynq-devcfg-1.0" have any compatible drivers, so there is really no support for configuration based on device-tree at the moment.

Quoted 8 lines

That's correct

Quoted 3 lines

If I look at boards using the Altera, no board uses a driver
to configure the FPGA. Instead they implement a number of callbacks
in the board files which manually handles the SPI bus outside the SPI driver. No trace of device tree.

Which boards do you refer to ?

Every board using the Altera drivers have an Altera_desc which contains links to callbacks used by the altera driver.

Quoted 8 lines

cls; rgrep Altera_desc | grep -v -e drivers -e include board/beckhoff/mx53cx9020/mx53cx9020.c:static Altera_desc ccat_fpga = { board/astro/mcf5373l/fpga.c:Altera_desc altera_fpga[FPGA_COUNT] = { board/theadorable/fpga.c:static Altera_desc altera_fpga[] = {

They all access the FPGA using spi, gpio etc. outside the driver model.

Not a trace of devicetree support unfortunately.

DT support would have to be added, but that shouldn't be all that hard. There are other simple subsystems which were extended the same way.

Quoted 13 lines
Quoted 11 lines
Quoted 8 lines

 > Let me be blunt about this, I have this feeling that what is happening here is just overloading of MTD framework with unrelated functionality (FPGA bitstream loading). MTD framework simply is not the right place, esp. if there is dedicated FPGA framework, with existing Altera PS driver no less.

When you are configuring an FPGA, you are writing a bitstream to an SRAM inside the FPGA. SRAM are memories.

The MTD framework does exactly what is needed for passive serial.
I do not see that there is another place to add a device-tree based
FPGA configuration, so you basically have to replicate the MTD framework, in order to have FPGA configuration in the device tree.

Update the existing FPGA framework to parse the necessary DT bindings.

Quoted 5 lines
Quoted 1 line

Please do not overload existing framework (MTD or whatever) with unrelated functionality only because it provides the .write callback. While this may look like a good idea to cover one very specific use case, it would fail once all the other use cases which are already covered by the FPGA framework come into picture.

I do not see why other chips could not be supported by an MTD driver. Conceptually, there is not much difference between reading/writing a NAND flash and configuring an FPGA.

See above.

To sum it up:
- The only part of the MTD subsystem that is in use by this driver is the write callback, everything else is unused. That does not make MTD subsystem the right tool.
- There is existing FPGA subsystem both in U-Boot and Linux, extend it if necessary. That also covers the usecases which go past a simple full bitstream upload.

Quoted 1 line

Obviously, someone would have to take the time to do it, but it is certainly possible.

You could make the exact same argument about making the FPGA driver a MISC device, CHAR device, BLOCK device, they all have the write callback, but that does not mean it is the right fit.

[...]

#11 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Den 2023-02-20 kl. 17:17, skrev Marek Vasut:

Quoted 44 lines · Ulf Samuelsson
Quoted 43 lines

Den 2023-02-12 kl. 23:40, skrev Marek Vasut:

Quoted 39 lines · Ulf Samuelsson
Quoted 34 lines

Den 2023-02-12 kl. 21:01, skrev Marek Vasut:
 > On 2/12/23 20:52, Ulf Samuelsson wrote:
 >>
 >>
 >> Den 2023-02-12 kl. 20:31, skrev Marek Vasut:
 >>  > On 2/11/23 11:07, [email protected] wrote:
 >>  >
 >>  > [...]
 >>  >
 >>  >> +static int cyc10_write(struct mtd_info *mtd, loff_t to, size_t len,
 >>  >> +                 size_t *retlen, const u_char *buf)
 >>  >> +{
 >>  >> +    struct udevice *dev = mtd->dev;
 >>  >> +    struct spi_slave *slave = dev_get_parent_priv(dev);
 >>  >> +    struct cyc10_plat *fpga = dev_get_plat(dev);
 >>  >> +    int ret;
 >>  >
 >>  > Do I read this right, that the 'write' callback is the only one doing
 >>  > meaningful work, all the other callbacks are just empty stubs ?
 >>  > Yes, you cannot read back the configuration data.
 >
 > That makes it look like any framework which supports "write" callback would be suitable, not just MTD framework.
 >
 >>  > Why not update drivers/fpga/cyclon2.c which is Passive Serial
 >>  > implementation already present in U-Boot for Altera Cyclone II FPGA ,
 >>  > with Cyclone 10 FPGA support ? I believe the PS protocol changed very
 >>  > little.
 >> Since the MTD command set is enough to configure the FPGA, the FPGA commands can be removed from the build. The FPGA command set requires you to supply addresses, but the MTD command set uses devices. >>
 >> So:
 >> * Smaller U-Boot image
 >
 > The MTD framework is rather large, compared to the trivial FPGA framework. Can you back this claim with any numbers ?

Quoted 1 line

I am assuming that the MTD framework is needed anyway.

FPGA and MTD support is orthogonal, you cannot make that assumption.
Consider SoC-FPGA machine booting from eMMC, Altera Cyclone V SoC does support that mode of operation, and MTD support can be disabled.

Quoted 7 lines
Quoted 5 lines

If I look at Altera SOCFPGAs, I find that 21 defconfigs have MTD support and 3 do not.
* socfpga_agilex_defconfig
* socfpga_chameleonv3_defconfig
* socfpga_n5x_defconfig
so in most cases there would be a reduction in code size.

All these machines already have FPGA framework enabled, just use it or extend it.

The argument was that some boards have FPGA framework without MTD and that gives overhead for the those board.
Since 21 out of 24 have MTD, the FPGA framework gives overhead for those boards, which could removed if FPGAs were installed as MTDs.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 10 lines

We certainly need it.
 >
 >> * Simplified user interface.
 >
 > If I am to select between 'fpga load' and 'mtd write' for FPGA bitstream loading , my obvious choice would be 'fpga load' . How is using 'mtd write' any better or simpler ? >
fpga load 0   ${loadaddr} ${filesize}
mtd write spy ${loadaddr}

Quoted 2 lines

The questions I ask myself.
So is "0" the "spy" FPGA or the "spx" FPGA?

You can use DT /aliases node to enumerate the FPGAs the same way i2c busses, SPI NORs, SD/MMC devices etc. are enumerated . Also have a look at e.g. 'net list' command, similar functionality can be added to the FPGA command to list all registered FPGAs.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Why should I have to remember the size of the FPGA bitstream?

Because it is not always possible to extract that information from the bitstream blob, remember, some of those blobs may be just raw binaries of the SRAM/flash content .

The size of the FPGA will be in the devicetree, so there is no need to supply that in the command itself.

That stops working once you start dealing with partial reconfiguration and the bitstream size varies. Then it is back to $filesize .

The MTD subsystem supports the concept of partitions.
I suspect that this would allow partial configuration to work quite OK.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

 >> * The FPGA is an SPI peripheral, so why not add it to the SPI part of the device tree?
 >
 > You can add the device into DT and still operate it using the U-Boot FPGA framework, just add the DT support. Why not do it that way ?

I don't think you can add the device into DT in U-Boot as it is today. You can create FPGA contents and add that to the device tree, but not the configuration itself. At least, I have not seen it.
If I have missed it, where is an example?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Have a look at the Linux FPGA DT bindings in Documentation/devicetree/bindings/fpga/ . You can implement parsing of those bindings into the U-Boot FPGA framework and then add your FPGA device configuration interface into the DT.

The "altr,fpga-passive-serial" driver is very close to what I did.

If there is an existing driver, extend it, rework it, but please don't introduce new driver that does the same thing.

The current passive serial solutions does not use the existing SPI drivers. They access the SPI peripheral outside the driver. A new driver would build on the existing SPI drivers.

It is not possible to test if a modified driver break the function on those boards, if you do not have access to the boards.

Quoted 43 lines
Quoted 5 lines

My driver supports a superset of a devicetree for that driver. It does not look like U-Boot is setup to use that.

I feel that the FPGA manager needs a total rework to make this work
and I cannot justify that. If someone adds devicetree support to the FPGA manager, I will certainly look to adopt to it.

Overloading the MTD subsystem only because it has a .write() callback is not the way to go either.

Quoted 35 lines
Quoted 20 lines
Quoted 8 lines

The FPGA framework is not really setup to use device-tree to describe configuration.

Only 5 defconfigs in U-Boot uses the FPGA framework.
* astro_mcf5373l_defconfig
* syzygy_hub_defconfig
* xilinx_zynqmp_virt_defconfig
* xilinx_zynq_virt_defconfig

These two ^ cover very much every zynq 7000 and zynqmp device in existence, since the way those are used is in combination with provided custom board DT.

Quoted 1 line

* bitmain_antminer_s9_defconfig

There is also arch/arm/mach-socfpga/Kconfig: imply FPGA_SOCFPGA , which activates the CONFIG_FPGA on all of Altera Cyclone V/Arria V/Stratix 10/Agilex and whatever new SoCFPGA Intel has.

Quoted 4 lines

Their device trees have leafs for configuration:
* compatible = "fpga-region";
* compatible = "xlnx,zynq-devcfg-1.0";
Neither "fpga-region" or "xlnx,zynq-devcfg-1.0" have any compatible drivers, so there is really no support for configuration based on device-tree at the moment.

Quoted 8 lines

That's correct

Quoted 3 lines

If I look at boards using the Altera, no board uses a driver
to configure the FPGA. Instead they implement a number of callbacks
in the board files which manually handles the SPI bus outside the SPI driver. No trace of device tree.

Which boards do you refer to ?

Every board using the Altera drivers have an Altera_desc which contains links to callbacks used by the altera driver.

cls; rgrep Altera_desc | grep -v -e drivers -e include board/beckhoff/mx53cx9020/mx53cx9020.c:static Altera_desc ccat_fpga = { board/astro/mcf5373l/fpga.c:Altera_desc altera_fpga[FPGA_COUNT] = { board/theadorable/fpga.c:static Altera_desc altera_fpga[] = {

Quoted 6 lines
Quoted 3 lines

They all access the FPGA using spi, gpio etc. outside the driver model.

Not a trace of devicetree support unfortunately.

DT support would have to be added, but that shouldn't be all that hard. There are other simple subsystems which were extended the same way.

As I said, I cannot justify to do that change.

Quoted 19 lines
Quoted 13 lines
Quoted 11 lines
Quoted 8 lines

 > Let me be blunt about this, I have this feeling that what is happening here is just overloading of MTD framework with unrelated functionality (FPGA bitstream loading). MTD framework simply is not the right place, esp. if there is dedicated FPGA framework, with existing Altera PS driver no less.

When you are configuring an FPGA, you are writing a bitstream to an SRAM inside the FPGA. SRAM are memories.

The MTD framework does exactly what is needed for passive serial.
I do not see that there is another place to add a device-tree based
FPGA configuration, so you basically have to replicate the MTD framework, in order to have FPGA configuration in the device tree.

Update the existing FPGA framework to parse the necessary DT bindings.

Quoted 5 lines
Quoted 1 line

Please do not overload existing framework (MTD or whatever) with unrelated functionality only because it provides the .write callback. While this may look like a good idea to cover one very specific use case, it would fail once all the other use cases which are already covered by the FPGA framework come into picture.

I do not see why other chips could not be supported by an MTD driver. Conceptually, there is not much difference between reading/writing a NAND flash and configuring an FPGA.

Quoted 5 lines

See above.

To sum it up:
- The only part of the MTD subsystem that is in use by this driver is
the write callback, everything else is unused. That does not make MTD subsystem the right tool.

No, the MTD subsystem is compatible with the device tree.
You can also get information about the FPGA when you list the mtd devices.
It allows you to support partial reconfiguration through the partition feature. You can write any size block to any part of the MTD, and you can express that in a device tree. That is what is needed.

Quoted 2 lines

- There is existing FPGA subsystem both in U-Boot and Linux, extend it
if necessary. That also covers the usecases which go past a simple full bitstream upload.

And for use, that introduces a command set, which we do not need and adds 50-100kB to the image.

Quoted 5 lines
Quoted 2 lines

Obviously, someone would have to take the time to do it, but it is certainly possible.

You could make the exact same argument about making the FPGA driver a MISC device, CHAR device, BLOCK device, they all have the write callback, but that does not mean it is the right fit.

That is because you see the "write" as the only function.

Quoted 1 line

[...]

What would work is to keep the driver as is, replacing
the MTD stuff internally with an fpga_add after generating a struct based on the device tree.

Then it would be part of the FPGA subsystem.
To add this as an Altera passive serial is high risk, since it cannot be tested on boards using that.
It would simplify things a lot to add it as another driver.

The result would of course be something which adds both complexity and code size for us, without any benefit.

Best Regards
Ulf Samuelsson

#12 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

On 2/20/23 22:29, Ulf Samuelsson wrote:

[...]

Quoted 5 lines
Quoted 3 lines

To sum it up:
- The only part of the MTD subsystem that is in use by this driver is
the write callback, everything else is unused. That does not make MTD subsystem the right tool.

No, the MTD subsystem is compatible with the device tree.

That does not justify overloading the subsystem with unrelated hardware support for which there is an existing subsystem with existing drivers for the functionality you would duplicate in the MTD subsystem. There are existing DT bindings for FPGAs, see Linux Documentation/devicetree/bindings/fpga/ , use those and add support for them into the FPGA subsystem if needed .

Quoted 1 line

You can also get information about the FPGA when you list the mtd devices.

No, you cannot, because the information you may get out of the FPGA in some cases does not map to MTD devices .

Quoted 2 lines

It allows you to support partial reconfiguration through the partition feature. You can write any size block to any part of the MTD, and you can express that in a device tree. That is what is needed.

I am afraid it is not as simple as that, see Linux Documentation/devicetree/bindings/fpga/fpga-region.txt . Furthermore, those DT bindings are already part of Linux and Linux expects the DT to contain exactly those bindings, U-Boot tries not to diverge from what Linux does in DT.

Quoted 5 lines
Quoted 2 lines

- There is existing FPGA subsystem both in U-Boot and Linux, extend it
if necessary. That also covers the usecases which go past a simple full bitstream upload.

And for use, that introduces a command set, which we do not need and adds 50-100kB to the image.

If you were to turn everything that needs read/write callback into an MTD device, you would be able to save even more space, but that does not make it right. You could try and reduce the FPGA command size if there is code which is unused for some usecases, that can be selected via Kconfig at build time.

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Obviously, someone would have to take the time to do it, but it is certainly possible.

You could make the exact same argument about making the FPGA driver a MISC device, CHAR device, BLOCK device, they all have the write callback, but that does not mean it is the right fit.

That is because you see the "write" as the only function.

Yes, because that is the only callback this patch implements, the rest are empty.

Quoted 9 lines
Quoted 1 line

[...]

What would work is to keep the driver as is, replacing
the MTD stuff internally with an fpga_add after generating a struct based on the device tree.

Then it would be part of the FPGA subsystem.
To add this as an Altera passive serial is high risk, since it cannot be tested on boards using that.
It would simplify things a lot to add it as another driver.

No, that would make things MUCH worse, because we would have a one-off driver used by one system, therefore poorly tested, which duplicates functionality of existing driver used by multiple systems and better tested. This also increases maintenance burden.

One single driver for this common functionality is always better as it gets more testing.

Quoted 1 line

The result would of course be something which adds both complexity and code size for us, without any benefit.

Please also consider the MTD maintainer point of view.

[...]

#13 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Den 2023-02-20 kl. 23:34, skrev Marek Vasut:

Quoted 11 lines · Ulf Samuelsson

[...]

Quoted 5 lines
Quoted 3 lines

To sum it up:
- The only part of the MTD subsystem that is in use by this driver is
the write callback, everything else is unused. That does not make MTD subsystem the right tool.

No, the MTD subsystem is compatible with the device tree.

That does not justify overloading the subsystem with unrelated hardware support for which there is an existing subsystem with existing drivers for the functionality you would duplicate in the MTD subsystem. There are existing DT bindings for FPGAs, see Linux Documentation/devicetree/bindings/fpga/ , use those and add support for them into the FPGA subsystem if needed .

The current u-boot FPGA support is incompatible with the linux devicetree for FPGAs. There is simply nothing there.
That is the reason for the proposal in the first place.

Quoted 4 lines
Quoted 2 lines

You can also get information about the FPGA when you list the mtd devices.

No, you cannot, because the information you may get out of the FPGA in some cases does not map to MTD devices .

Please give some examples.

Quoted 5 lines
Quoted 2 lines

It allows you to support partial reconfiguration through the partition feature. You can write any size block to any part of the MTD, and you can express that in a device tree. That is what is needed.

I am afraid it is not as simple as that, see Linux Documentation/devicetree/bindings/fpga/fpga-region.txt . Furthermore, those DT bindings are already part of Linux and Linux expects the DT to contain exactly those bindings, U-Boot tries not to diverge from what Linux does in DT.

The device tree in my driver is a superset to what linux does. It tests more status pins, and provides a name for the FPGA. It would not be difficult to make it 100% compatible.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

- There is existing FPGA subsystem both in U-Boot and Linux, extend
it if necessary. That also covers the usecases which go past a simple full bitstream upload.

And for use, that introduces a command set, which we do not need and adds 50-100kB to the image.

If you were to turn everything that needs read/write callback into an MTD device, you would be able to save even more space, but that does not make it right. You could try and reduce the FPGA command size if there is code which is unused for some usecases, that can be selected via Kconfig at build time.

From my point of view, Having the FPGA command set duplicates the functionality of the MTD. That is the major contributor to code space expansion.

The thing you are writing to is SRAM which is memory.
If it is right or wrong to use that as an MTD is a matter of opinion.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Obviously, someone would have to take the time to do it, but it is certainly possible.

You could make the exact same argument about making the FPGA driver a MISC device, CHAR device, BLOCK device, they all have the write callback, but that does not mean it is the right fit.

That is because you see the "write" as the only function.

Yes, because that is the only callback this patch implements, the rest are empty.

You cannot read back the configuration from a Cyclone 10.
A driver for an FPGA where configuration could be read back of course would have a read routine as well. The MTD subsystem can display the information the driver provides.
That is an important piece that would be missing from a MISC or CHAR driver.
You also have a "device" to work with.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

[...]

What would work is to keep the driver as is, replacing
the MTD stuff internally with an fpga_add after generating a struct based on the device tree.

Quoted 6 lines
Quoted 4 lines

Then it would be part of the FPGA subsystem.
To add this as an Altera passive serial is high risk, since it cannot be tested on boards using that.
It would simplify things a lot to add it as another driver.

No, that would make things MUCH worse, because we would have a one-off driver used by one system, therefore poorly tested, which duplicates functionality of existing driver used by multiple systems and better tested. This also increases maintenance burden.

Today you have a custom functionality to access the FPGA in each board package. That only gets tested when building that board. So if you have 'n' boards, you have 'n' different ways of accessing the FPGA. Each poorly tested, if number of users are the measurement. The only thing in common is the multiplexing code.

Anyone that designs a new system, would have to choose between
using the new driver, or write their own access method.
They cannot use what is in u-boot today, because it is in the board directory. Even if they have the same chip as a board with existing support, they cannot add it in, since it is in the board directory. Only solution is to duplicate the code in their own board directory,
but the likelyhood of using the same CPU is slim.

Are you happy with this?

I wager that anyone wanting to use passive serial would adopt the new driver.

One solution is of course to ask the maintainers of those boards if they would consider moving to a device tree solution. Then the new driver would be the only driver.

Quoted 6 lines

One single driver for this common functionality is always better as it gets more testing.

Quoted 1 line

The result would of course be something which adds both complexity and code size for us, without any benefit.

Please also consider the MTD maintainer point of view.

I do not see that this adds much more complexity than any other MTD device.

Quoted 1 line

[...]

Best Regards
Ulf Samuelsson

#14 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 11 lines · Ulf Samuelsson

Den 2023-02-20 kl. 23:34, skrev Marek Vasut:

Quoted 8 lines · Ulf Samuelsson

[...]

Quoted 4 lines
Quoted 3 lines

To sum it up:
- The only part of the MTD subsystem that is in use by this driver
is the write callback, everything else is unused. That does not make MTD subsystem the right tool.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

No, the MTD subsystem is compatible with the device tree.

That does not justify overloading the subsystem with unrelated hardware support for which there is an existing subsystem with existing drivers for the functionality you would duplicate in the MTD subsystem. There are existing DT bindings for FPGAs, see Linux Documentation/devicetree/bindings/fpga/ , use those and add support for them into the FPGA subsystem if needed .

The current u-boot FPGA support is incompatible with the linux devicetree for FPGAs. There is simply nothing there.
That is the reason for the proposal in the first place.

Add it, that seems like the best approach here.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

You can also get information about the FPGA when you list the mtd devices.

No, you cannot, because the information you may get out of the FPGA in some cases does not map to MTD devices .

Please give some examples.

Which FPGA bus bridge(s) are enabled for example . This is something present on SoCFPGA solutions , e.g. an AXI bridge into the fabric .

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

It allows you to support partial reconfiguration through the partition feature. You can write any size block to any part of the MTD, and you can express that in a device tree. That is what is needed.

I am afraid it is not as simple as that, see Linux Documentation/devicetree/bindings/fpga/fpga-region.txt . Furthermore, those DT bindings are already part of Linux and Linux expects the DT to contain exactly those bindings, U-Boot tries not to diverge from what Linux does in DT.

The device tree in my driver is a superset to what linux does. It tests more status pins, and provides a name for the FPGA. It would not be difficult to make it 100% compatible.

Extend the Linux DT bindings if they are insufficient, but please don't try and reinvent the wheel.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

- There is existing FPGA subsystem both in U-Boot and Linux, extend
it if necessary. That also covers the usecases which go past a simple full bitstream upload.

And for use, that introduces a command set, which we do not need and adds 50-100kB to the image.

Quoted 8 lines
Quoted 2 lines

If you were to turn everything that needs read/write callback into an MTD device, you would be able to save even more space, but that does not make it right. You could try and reduce the FPGA command size if there is code which is unused for some usecases, that can be selected via Kconfig at build time.

From my point of view, Having the FPGA command set duplicates the
functionality of the MTD.
That is the major contributor to code space expansion.

The thing you are writing to is SRAM which is memory.

There are flash based FPGAs , like Altera MAXV.
There are CPLDs which are not even flash based.

Quoted 1 line

If it is right or wrong to use that as an MTD is a matter of opinion.

I am still hoping the MTD maintainer would provide input here.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Obviously, someone would have to take the time to do it, but it is certainly possible.

You could make the exact same argument about making the FPGA driver a MISC device, CHAR device, BLOCK device, they all have the write callback, but that does not mean it is the right fit.

That is because you see the "write" as the only function.

Yes, because that is the only callback this patch implements, the rest are empty.

You cannot read back the configuration from a Cyclone 10.

Therefore, the entire read part of whatever subsystem is unnecessary.

Erase as well for most FPGAs which are SRAM based, even for flash based FPGA, per-sector erase is not available, since there is no concept of sectors or erase blocks at all.

Quoted 4 lines

A driver for an FPGA where configuration could be read back of course would have a read routine as well. The MTD subsystem can display the information the driver provides.
That is an important piece that would be missing from a MISC or CHAR driver.
You also have a "device" to work with.

All this is already in the FPGA subsystem, and it is designed toward the FPGA use case.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line

[...]

What would work is to keep the driver as is, replacing
the MTD stuff internally with an fpga_add after generating a struct based on the device tree.

Then it would be part of the FPGA subsystem.
To add this as an Altera passive serial is high risk, since it cannot be tested on boards using that.
It would simplify things a lot to add it as another driver.

Quoted 4 lines
Quoted 1 line

No, that would make things MUCH worse, because we would have a one-off driver used by one system, therefore poorly tested, which duplicates functionality of existing driver used by multiple systems and better tested. This also increases maintenance burden.

Today you have a custom functionality to access the FPGA in each board package.  That only gets tested when building that board.

No, at least the Altera SoCFPGA and Xilinx anything newer than Zynq/ZynqMP is tested regularly on actual hardware, and the code is common to all those systems, and lives in drivers/fpga/ .

Quoted 2 lines

So if you have 'n' boards, you have 'n' different ways of accessing the FPGA. Each poorly tested, if number of users are the measurement. The only thing in common is the multiplexing code.

Not really, on SoCFPGA systems, even the programming logic is common. For external FPGAs, sure, you need to provide the pin or interface mapping in some way, via platform data, DT, ACPI, whatever. If that is platform data, it should be moved to DT, the FPGA framework DT bindings should provide guidance how to do that. But even then, the driver itself should be generic, and reside in drivers/fpga/ .

Quoted 2 lines

Anyone that designs a new system, would have to choose between using the new driver, or write their own access method.

I vote "reuse existing driver, plug in DT/platform_data/... as needed" .

Quoted 1 line

They cannot use what is in u-boot today, because it is in the board directory.

This is not true for majority of FPGA systems, see drivers/fpga/ .

Quoted 1 line

Even if they have the same chip as a board with existing support, they cannot add it in, since it is in the board directory.

Are you actually talking about platform data which are used during driver instantiation, or, full driver, in board/ ?

Platform data are fine-ish, full drivers in board/ should be on the way out.

Quoted 4 lines

Only solution is to duplicate the code in their own board directory, but the likelyhood of using the same CPU is slim.

Are you happy with this?

I think we have a vastly different picture of the current situation .

Quoted 5 lines

I wager that anyone wanting to use passive serial would adopt the new driver.

One solution is of course to ask the maintainers of those boards if they would consider moving to a device tree solution. Then the new driver would be the only driver.

Put them on CC, there is scripts/get_maintainer.pl script, use -f parameter to point it to specific files. I have a feeling a lot of those boards with external FPGAs being configured by poking registers in board/ are going to be dropped sooner rather than later.

Quoted 7 lines
Quoted 6 lines

One single driver for this common functionality is always better as it gets more testing.

Quoted 1 line

The result would of course be something which adds both complexity and code size for us, without any benefit.

Please also consider the MTD maintainer point of view.

I do not see that this adds much more complexity than any other MTD device.

Again, there is a separate subsystem/framework for FPGAs . I disagree one should conflate MTD and FPGA subsystems.

#15 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 3 lines
Quoted 1 line

If it is right or wrong to use that as an MTD is a matter of opinion.

I am still hoping the MTD maintainer would provide input here.

I might be missing something, but what is the reasoning here, to add this to the mtd subsystem? One is saving space, but I agree with Marek, this isn't a valid argument to just put any (unrelated) stuff into the MTD subsystem.

Also, as Marek pointed out, there are many different 'programming' solutions for CPLDs/FPGAs and most of them don't share anything with MTD. You seem to be just focusing on the "passive serial" one.

Now, I saw you mentioned that

| the current passive serial solutions does not use the existing SPI | drivers.

What do you mean with SPI drivers? SPI flash drivers or SPI controller drivers? Does the "passive serial solution" expose an SPI bus and you can access the SPI flash on it in a generic way? Then the solution should be to write a SPI (controller) driver, the flash should then be automatically be detected.

-michael

#16 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Hi Guys,
We are currently discussing how to support passive serial configuration of FPGAs in u-boot.

Checking the u-boot source code reveals that only your boards actually supports this.

board/beckhoff/mx53cx9020/mx53cx9020.c:...Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/beckhoff/mx53cx9020/mx53cx9020.c
Patrick Bruenn <[email protected]> (maintainer:MX53 CX9020)

board/astro/mcf5373l/fpga.c:Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/astro/mcf5373l/fpga.c
Wolfgang Wegner <[email protected]> (maintainer:MCF5373L BOARD)

The proposed ideas is to have the FPGA as an SPI peripheral in the device tree.

I have a working version, where the FPGA is an MTD device and the general idea is to add it to the FPGA manager, which unfortunately needs a major rewrite to support device tree.

Your board support configuring the FPGA in the 'board' files.

* Are these boards still active and will require updates of u-boot?

* If so, would it be a problem porting the FPGA configuration to the device tree?

Marek does not want two drivers supporting passive serial, and supporting both 'board' drivers and devicetree drivers seems to result in unclean code.

Best Regards
Ulf Samuelsson

#17 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Hi!

Quoted 11 lines · Ulf Samuelsson

CAUTION: External Email!!
Hi Guys,
We are currently discussing how to support passive serial configuration of FPGAs in u-boot.

Checking the u-boot source code reveals that only your boards actually supports this.

board/beckhoff/mx53cx9020/mx53cx9020.c:...Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/beckhoff/mx53cx9020/mx53cx9020.c
Patrick Bruenn <[email protected]> (maintainer:MX53 CX9020)

This doesn't seem immediately relevant to our board as we don't really use spi, but the (w)eim interface as far as i can tell right now. (has been a while since I looked at it, have not read the imx datasheet again to see if this is spi in disguise)

If anything the binding should be shared between u-boot and the kernel. We just had a bug because of differences between the two.
Something like the "altr,fpga-passive-serial" in arch/arm/boot/dts/imx6q-evi.dts in the kernel would match the usecase.

We wouldn't be opposed to changing the dt and also just repaired our CI for these devices and can test changes quickly.

Best Regards
Steffen Dirkwinkel

Quoted 20 lines

board/astro/mcf5373l/fpga.c:Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/astro/mcf5373l/fpga.c
Wolfgang Wegner <[email protected]> (maintainer:MCF5373L BOARD)

The proposed ideas is to have the FPGA as an SPI peripheral in the device tree.

I have a working version, where the FPGA is an MTD device and the general idea is to add it to the FPGA manager, which unfortunately needs a major rewrite to support device tree.

Your board support configuring the FPGA in the 'board' files.

* Are these boards still active and will require updates of u-boot?

* If so, would it be a problem porting the FPGA configuration to the device tree?

Quoted 6 lines

Marek does not want two drivers supporting passive serial, and supporting both 'board' drivers and devicetree drivers seems to result in unclean code.

Best Regards
Ulf Samuelsson

This email contains confidential information. If you have received it in error, you must not read, use, copy or pass on this e-mail or its attachments. If you have received the e-mail in error, please inform me immediately by reply e-mail and then delete this e-mail from your system. Thank you

Diese E-Mail enthält vertrauliche Informationen. Sollten Sie sie irrtümlich erhalten haben, dürfen Sie diese E-Mail oder ihre Anhänge nicht lesen, verwenden, kopieren oder weitergeben. Sollten Sie die Mail versehentlich erhalten haben, teilen Sie mir dies bitte umgehend per Antwort-E-Mail mit und löschen Sie diese E-Mail dann aus Ihrem System. Vielen Dank

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff Registered office: Verl, Germany | Register court: Guetersloh HRA 7075

#18 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 19 lines · Steffen Dirkwinkel

Hi!

Quoted 11 lines · Ulf Samuelsson

CAUTION: External Email!!
Hi Guys,
We are currently discussing how to support passive serial configuration of FPGAs in u-boot.

Checking the u-boot source code reveals that only your boards actually supports this.

board/beckhoff/mx53cx9020/mx53cx9020.c:...Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/beckhoff/mx53cx9020/mx53cx9020.c
Patrick Bruenn <[email protected]> (maintainer:MX53 CX9020)

This doesn't seem immediately relevant to our board as we don't really use spi, but the (w)eim interface as far as i can tell right now. (has been a while since I looked at it, have not read the imx datasheet again to see if this is spi in disguise)

Quoted 7 lines

If anything the binding should be shared between u-boot and the kernel. We just had a bug because of differences between the two.
Something like the "altr,fpga-passive-serial" in arch/arm/boot/dts/imx6q-evi.dts in the kernel would match the usecase.

We wouldn't be opposed to changing the dt and also just repaired our CI for these devices and can test changes quickly.

I had a look at your code again.
It appears that you are using the Altera "passive serial" interface in U-Boot, but your board routine appears to write 8-bit bytes to the external bus.

The only two reasons for this I can think of is that you are either using an external serializer converting the 8 bit words to a serial stream or you are actually using the passive "parallell interface" on the FPGA, but use the "passive serial" routines in u-boot.

Can you please confirm how the hardware works?

The maintainer of the other board using "passive serial" ([email protected] <[email protected]>) bounced as an unknown user. This means that the "board/astro/mcf5373" does not have an active MAINTAINER.

The board was added in 2010, and has not seen any updates from astro-kom.de since then. All the maintenance has been by people maintaining subsystems.

Best Regards
Ulf Samuelsson

Quoted 38 lines

Best Regards
Steffen Dirkwinkel

Quoted 20 lines

board/astro/mcf5373l/fpga.c:Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/astro/mcf5373l/fpga.c
Wolfgang Wegner <[email protected]> (maintainer:MCF5373L BOARD)

The proposed ideas is to have the FPGA as an SPI peripheral in the device tree.

I have a working version, where the FPGA is an MTD device and the general idea is to add it to the FPGA manager, which unfortunately needs a major rewrite to support device tree.

Your board support configuring the FPGA in the 'board' files.

* Are these boards still active and will require updates of u-boot?

* If so, would it be a problem porting the FPGA configuration to the device tree?

Quoted 6 lines

Marek does not want two drivers supporting passive serial, and supporting both 'board' drivers and devicetree drivers seems to result in unclean code.

Best Regards
Ulf Samuelsson

This email contains confidential information. If you have received it in error, you must not read, use, copy or pass on this e-mail or its attachments. If you have received the e-mail in error, please inform me immediately by reply e-mail and then delete this e-mail from your system. Thank you

Diese E-Mail enthält vertrauliche Informationen. Sollten Sie sie irrtümlich erhalten haben, dürfen Sie diese E-Mail oder ihre Anhänge nicht lesen, verwenden, kopieren oder weitergeben. Sollten Sie die Mail versehentlich erhalten haben, teilen Sie mir dies bitte umgehend per Antwort-E-Mail mit und löschen Sie diese E-Mail dann aus Ihrem System. Vielen Dank

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff Registered office: Verl, Germany | Register court: Guetersloh HRA 7075

#19 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 33 lines · Ulf Samuelsson

CAUTION: External Email!!

Quoted 13 lines · Steffen Dirkwinkel

Hi!

Quoted 11 lines · Ulf Samuelsson

CAUTION: External Email!!
Hi Guys,
We are currently discussing how to support passive serial configuration of FPGAs in u-boot.

Checking the u-boot source code reveals that only your boards actually supports this.

board/beckhoff/mx53cx9020/mx53cx9020.c:...Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/beckhoff/mx53cx9020/mx53cx9020.c
Patrick Bruenn <[email protected]> (maintainer:MX53 CX9020)
Quoted 8 lines

This doesn't seem immediately relevant to our board as we don't really use spi,
but the (w)eim interface as far as i can tell right now. (has been a while since I looked
at it, have not read the imx datasheet again to see if this is spi in disguise)
If anything the binding should be shared between u-boot and the kernel. We just had a bug
because of differences between the two.
Something like the "altr,fpga-passive-serial" in arch/arm/boot/dts/imx6q-evi.dts in the kernel would match the usecase.
We wouldn't be opposed to changing the dt and also just repaired our CI for these devices and can test changes quickly.

I had a look at your code again.
It appears that you are using the Altera "passive serial" interface in U-Boot, but your board routine appears to write 8-bit bytes to the external bus.

Quoted 7 lines

The only two reasons for this I can think of is that you are either using an external serializer converting the 8 bit words to a serial stream or you are actually using the passive "parallell interface" on the FPGA, but use the "passive serial" routines in u-boot.

Can you please confirm how the hardware works?

I checked the schematic, we’re using fast_passive_parallel.
Since both are using the same codepaths right now it didn’t matter. I’ll send a patch

Quoted 44 lines

The maintainer of the other board using "passive serial" ([email protected] <[email protected]>) bounced as an unknown user. This means that the "board/astro/mcf5373" does not have an active MAINTAINER.

The board was added in 2010, and has not seen any updates from
https://nospamproxywebp.beckhoff.com/enqsig/link?id=BCAAAABGd7m3lfMOLOIhx3uNR_1Qav4Ffx8-jQB0torD82ts_G8AAAB_Q13kS5en5WiHBszxeeaYjAQwTPXiCeF8gx_zVjByVYRebkfOfUTW4VnpSmQ2VlvWczqoVxWwP7qF1C4VccAGIB-3QCgtp-eMVgM5VcCkSRCJT8HehzvaoUnQ6YYu2ofkD0GMhgmICiFDb8Cv_2k1 since then. All the maintenance has been by people maintaining subsystems.

Best Regards
Ulf Samuelsson

Quoted 32 lines

Best Regards
Steffen Dirkwinkel

Quoted 20 lines

board/astro/mcf5373l/fpga.c:Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/astro/mcf5373l/fpga.c
Wolfgang Wegner <[email protected]> (maintainer:MCF5373L BOARD)

The proposed ideas is to have the FPGA as an SPI peripheral in the device tree.

I have a working version, where the FPGA is an MTD device and the general idea is to add it to the FPGA manager, which unfortunately needs a major rewrite to support device tree.

Your board support configuring the FPGA in the 'board' files.

* Are these boards still active and will require updates of u-boot?

* If so, would it be a problem porting the FPGA configuration to the device tree?

Quoted 6 lines

Marek does not want two drivers supporting passive serial, and supporting both 'board' drivers and devicetree drivers seems to result in unclean code.

Best Regards
Ulf Samuelsson

This email contains confidential information. If you have received it in error, you must not read, use, copy or pass on this e-mail or its attachments. If you have received the e-mail in error, please inform me immediately by reply e-mail and then delete this e-mail from your system. Thank you Diese E-Mail enthält vertrauliche Informationen. Sollten Sie sie irrtümlich erhalten haben, dürfen Sie diese E-Mail oder ihre Anhänge nicht lesen, verwenden, kopieren oder weitergeben. Sollten Sie die Mail versehentlich erhalten haben, teilen Sie mir dies bitte umgehend per Antwort-E-Mail mit und löschen Sie diese E-Mail dann aus Ihrem System. Vielen Dank Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075

This email contains confidential information. If you have received it in error, you must not read, use, copy or pass on this e-mail or its attachments. If you have received the e-mail in error, please inform me immediately by reply e-mail and then delete this e-mail from your system. Thank you

Diese E-Mail enthält vertrauliche Informationen. Sollten Sie sie irrtümlich erhalten haben, dürfen Sie diese E-Mail oder ihre Anhänge nicht lesen, verwenden, kopieren oder weitergeben. Sollten Sie die Mail versehentlich erhalten haben, teilen Sie mir dies bitte umgehend per Antwort-E-Mail mit und löschen Sie diese E-Mail dann aus Ihrem System. Vielen Dank

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff Registered office: Verl, Germany | Register court: Guetersloh HRA 7075

#20 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

In reply to Michael Walle

Den 2023-02-21 kl. 10:08, skrev Michael Walle:

Quoted 10 lines
Quoted 2 lines
Quoted 1 line

If it is right or wrong to use that as an MTD is a matter of opinion.

I am still hoping the MTD maintainer would provide input here.

I might be missing something, but what is the reasoning here, to add this to the mtd subsystem? One is saving space, but I agree with Marek, this isn't a valid argument to just put any (unrelated) stuff into the MTD subsystem.

Also, as Marek pointed out, there are many different 'programming' solutions for CPLDs/FPGAs and most of them don't share anything with MTD. You seem to be just focusing on the "passive serial" one.

Yes, the passive serial is very different from the other ways of configuring an FPGA.

It is write only. You cannot read back the configuration and no partial reconfiguration.

You do not have to go through AXI/PCIe busses.

You access through an SPI device, but todays solution does not support using the SPI driver.

Quoted 11 lines

Now, I saw you mentioned that

| the current passive serial solutions does not use the existing SPI | drivers.

What do you mean with SPI drivers? SPI flash drivers or SPI controller drivers? Does the "passive serial solution" expose an SPI bus and you can access the SPI flash on it in a generic way? Then the solution should be to write a SPI (controller) driver, the flash should then be automatically be detected.

The proposed solution is similar to an SPI flash driver.

The FPGA bitstream is typically stored in the CPU boot flash.

The CPU reads the bitstream and does an SPI transfer to the FPGA.

The FPGA is not connected to any flash memory.

The FPGA chip exposes (in SPI terms) SCK, nCS and MOSI, but not MISO so you cannot read back anything.

The driver will return an empty block on read.

The SPI transfer to configure the FPGA is doing

* toggle a GPIO signal (nCONFIG)

* Do an SPI write (using the SPI controller driver)

* After the SPI transfer complete, you check the status of some GPIO (nSTATUS etc.).

This is all hidden from the MTD.

What the MTD subsystem sees is a "write-only memory" that has to be written with exactly 'n' bytes.

The additional features of MTD simplifies the user interaction by exposing a device and providing info on the device.

The only difference the MTD subsystem would see is that there is a new subdirectory "fpga" with drivers and the Kconfig + Makefile changes to support the directory. Otherwise it plugs right in.

====

The current solutions for passive serial cannot use the SPI controller driver so each board implements SPI controller inside their 'board' files. You cannot reuse this code in practice, so every one that wants to have passive serial has to write their own SPI access routines.

====
The FPGA manager does not support device tree, and I will not be able to spend time on introducing this, as Marek advices.

Best Regards
Ulf Samuelsson

Quoted 2 lines

-michael

Signature · 5 lines
Best Regards,
Ulf Samuelsson
eMagii
+46 722 427437
[email protected]
#21 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Am 2023-02-21 11:42, schrieb Ulf Samuelsson:

Quoted 14 lines

Den 2023-02-21 kl. 10:08, skrev Michael Walle:

Quoted 10 lines
Quoted 2 lines
Quoted 1 line

If it is right or wrong to use that as an MTD is a matter of opinion.

I am still hoping the MTD maintainer would provide input here.

I might be missing something, but what is the reasoning here, to add this to the mtd subsystem? One is saving space, but I agree with Marek, this isn't a valid argument to just put any (unrelated) stuff into the MTD subsystem.

Also, as Marek pointed out, there are many different 'programming' solutions for CPLDs/FPGAs and most of them don't share anything with MTD. You seem to be just focusing on the "passive serial" one.

Yes, the passive serial is very different from the other ways of configuring an FPGA.

Quoted 7 lines

It is write only. You cannot read back the configuration and no partial reconfiguration.

You do not have to go through AXI/PCIe busses.

You access through an SPI device, but todays solution does not support using the SPI driver.

I can't follow you here.

Quoted 11 lines
Quoted 10 lines

Now, I saw you mentioned that

| the current passive serial solutions does not use the existing SPI | drivers.

What do you mean with SPI drivers? SPI flash drivers or SPI controller drivers? Does the "passive serial solution" expose an SPI bus and you can access the SPI flash on it in a generic way? Then the solution should be to write a SPI (controller) driver, the flash should then be automatically be detected.

Quoted 7 lines

The proposed solution is similar to an SPI flash driver.

The FPGA bitstream is typically stored in the CPU boot flash.

The CPU reads the bitstream and does an SPI transfer to the FPGA.

The FPGA is not connected to any flash memory.

Ah I missed that. So you don't want to program the SPI flash behind the FPGA, but the FPGA directly. You are loading a bitstream from somewhere and configure the FPGA. Using a SPI like interface, i.e. it is write only as it lacks the DO.

Quoted 2 lines

The FPGA chip exposes (in SPI terms) SCK, nCS and MOSI, but not MISO so you cannot read back anything.

it should read "This FPGA chip". I expect there are much more variants how to configure an FPGA. Would these also use your proposed solution?

Quoted 8 lines

The driver will return an empty block on read.

The SPI transfer to configure the FPGA is doing

* toggle a GPIO signal (nCONFIG)

* Do an SPI write (using the SPI controller driver)

Quoted 7 lines

* After the SPI transfer complete, you check the status of some GPIO (nSTATUS etc.).

This is all hidden from the MTD.

What the MTD subsystem sees is a "write-only memory" that has to be written with exactly 'n' bytes.

MTD is mainly around erasable blocks, although there are some exotic things like mtdram. I fail to see how this would apply to your FPGA.

Quoted 3 lines

The additional features of MTD simplifies the user interaction by exposing a device and
providing info on the device.

Which would that be? What are the features of MTD which you need here? You've mentioned MTD partitions, but I'm not sure these really apply to partial reconfigurations. I know that Linux has a different device tree binding for it. So making u-boot use mtd partitions (if thats possible at all) and not the linux bindings means they'll diverge, which is something we want to avoid.

Quoted 4 lines

The only difference the MTD subsystem would see is that there is a new subdirectory "fpga" with drivers and the Kconfig + Makefile changes to support the directory. Otherwise it plugs right in.

From a user point of view this is really confusing. Why would you sometimes configure an fpga with the mtd command and sometimes with the fpga command depening whether it is using this passive programming thingy.

Quoted 4 lines

The current solutions for passive serial cannot use the SPI controller driver so each board implements SPI controller inside their 'board' files. You cannot reuse this code in practice, so every one that wants to have passive serial has to write their own SPI access routines.

Sorry, I didn't follow this too closely. Do you have some pointers?

-michael

Quoted 9 lines

====
The FPGA manager does not support device tree, and I will not be able to spend time on introducing this, as Marek advices.

Best Regards
Ulf Samuelsson

Quoted 2 lines

-michael

#22 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 1 line

Sorry, I didn't follow this too closely. Do you have some pointers?

I just saw your latest mail. Thanks.

-michael

#23 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

In reply to Michael Walle

Den 2023-02-21 kl. 12:19, skrev Michael Walle:

Quoted 18 lines

Am 2023-02-21 11:42, schrieb Ulf Samuelsson:

Quoted 17 lines

Den 2023-02-21 kl. 10:08, skrev Michael Walle:

Quoted 10 lines
Quoted 2 lines
Quoted 1 line

If it is right or wrong to use that as an MTD is a matter of opinion.

I am still hoping the MTD maintainer would provide input here.

I might be missing something, but what is the reasoning here, to add this to the mtd subsystem? One is saving space, but I agree with Marek, this isn't a valid argument to just put any (unrelated) stuff into the MTD subsystem.

Also, as Marek pointed out, there are many different 'programming' solutions for CPLDs/FPGAs and most of them don't share anything with MTD. You seem to be just focusing on the "passive serial" one.

Yes, the passive serial is very different from the other ways of configuring an FPGA.

It is write only. You cannot read back the configuration and no partial reconfiguration.

Quoted 7 lines
Quoted 4 lines

You do not have to go through AXI/PCIe busses.

You access through an SPI device, but todays solution does not support using the SPI driver.

I can't follow you here.

You have a chip that is connected to an SPI bus using SCK, MOSI, nCS. All the accesses are handled by the SPI controller driver outside the chip.

Quoted 15 lines
Quoted 15 lines
Quoted 10 lines

Now, I saw you mentioned that

  | the current passive serial solutions does not use the existing SPI | drivers.

What do you mean with SPI drivers? SPI flash drivers or SPI controller drivers? Does the "passive serial solution" expose an SPI bus and you can access the SPI flash on it in a generic way? Then the solution should be to write a SPI (controller) driver, the flash should then be automatically be detected.

The proposed solution is similar to an SPI flash driver.

The FPGA bitstream is typically stored in the CPU boot flash.

Quoted 9 lines
Quoted 3 lines

The CPU reads the bitstream and does an SPI transfer to the FPGA.

The FPGA is not connected to any flash memory.

Ah I missed that. So you don't want to program the SPI flash behind the FPGA, but the FPGA directly. You are loading a bitstream from somewhere and configure the FPGA. Using a SPI like interface, i.e. it is write only as it lacks the DO.

Exactly.

Quoted 6 lines
Quoted 2 lines

The FPGA chip exposes (in SPI terms) SCK, nCS and MOSI, but not MISO so you cannot read back anything.

it should read "This FPGA chip". I expect there are much more variants how to configure an FPGA. Would these also use your proposed solution?

There are the following methods I am aware of.

Active Serial - the FPGA is connected to an SPI flash, and loads this
flash at reset. The CPU may or may not have the capability to program the flash, and then it is a normal MTD SPI Flash. The FPGA manager is not involved at all.

Passive Serial: The CPU SPI controller (or similar) is connected to
pins on the FPGA and the only operation allowed is writing a fixed size to the FPGA.
The user needs to know the size of the FPGA.
The support for this in u-boot is very old-fashioned and new users get very little help.
The user needs to write an SPI access routine as the SPI driver structure is incompatible with the FPGA manager code for passive serial.

Passive Parallel: The CPU loads the FPGA through the parallell bus.
I doubt this is rarely used.

SOC: The Intel/Altera and AMD/Xilinx have internal FPGA
configuration interfaces. It is parallell. They are supported in the FPGA manager.

If the use of MTD is restricted to passive serial, this is OK with me.

Quoted 11 lines
Quoted 11 lines

The driver will return an empty block on read.

The SPI transfer to configure the FPGA is doing

* toggle a GPIO signal (nCONFIG)

* Do an SPI write (using the SPI controller driver)

* After the SPI transfer complete, you check the status of some GPIO (nSTATUS etc.).

Quoted 7 lines
Quoted 4 lines

This is all hidden from the MTD.

What the MTD subsystem sees is a "write-only memory" that has to be written with exactly 'n' bytes.

MTD is mainly around erasable blocks, although there are some exotic things like mtdram. I fail to see how this would apply to your FPGA.

These are the things I want to achieve.

* transfer data using the SPI driver and not use board files. For that, the FPGA should be under the SPI in the device tree.
* The size of the FPGA bitstream should be specified in the device tree.
* The FPGA should be accessed as a device, not an address.
* I want a list of the FPGAs connected in the system
* Minimize code.
* Simplify user interface.

From the CPU point of view, the FPGA is just a RAM location on the SPI bus. It cannot be read, but it can be written.

This is not surprising, because it is simply a RAM. It happens to have side effects, but that is not important.

The MTD subsystem supplies everything I need, and adding the driver there is much less work than anything else.

Quoted 11 lines
Quoted 4 lines

The additional features of MTD simplifies the user interaction by exposing a device and
providing info on the device.

Which would that be? What are the features of MTD which you need here? You've mentioned MTD partitions, but I'm not sure these really apply to partial reconfigurations. I know that Linux has a different device tree binding for it. So making u-boot use mtd partitions (if thats possible at all) and not the linux bindings means they'll diverge, which is something we want to avoid.

You cannot do partial reconfiguration on passive serial, so it is only of interest if someone feels a need to expand the MTD to other configuration methods.

Here is how an FPGA region looks in Linux.
If I understand things correctly, you have one memory region per partial configuration. This looks quite a lot like partitions.

&fpga_region0 {
	#address-cells = <1>;
	#size-cells = <1>;

	firmware-name = "soc_system.rbf";
	fpga-bridges = <&fpga_bridge1>;
	ranges = <0x20000 0xff200000 0x100000>,
		 <0x0 0xc0000000 0x20000000>;

	gpio@10040 {
		compatible = "altr,pio-1.0";
		reg = <0x10040 0x20>;
		altr,ngpio = <4>;
		#gpio-cells = <2>;
		clocks = <2>;
		gpio-controller;
	};

	onchip-memory {
		device_type = "memory";
		compatible = "altr,onchipmem-15.1";
		reg = <0x0 0x10000>;
	};
};
Quoted 10 lines
Quoted 5 lines

The only difference the MTD subsystem would see is that there is a new subdirectory "fpga" with drivers and the Kconfig + Makefile changes to support the directory. Otherwise it plugs right in.

From a user point of view this is really confusing. Why would
you sometimes configure an fpga with the mtd command and sometimes with the fpga command depening whether it is using this passive programming thingy.

I think that most board designers would select one method of configuring
the FPGA and they would only have either the FPGA or the MTD command set. I would be surprised if an engineer would be confused by this.

Quoted 19 lines
Quoted 5 lines

The current solutions for passive serial cannot use the SPI controller driver so each board implements SPI controller inside their 'board' files. You cannot reuse this code in practice, so every one that wants to have passive serial has to write their own SPI access routines.

Sorry, I didn't follow this too closely. Do you have some pointers?

-michael

Quoted 9 lines

====
The FPGA manager does not support device tree, and I will not be able to spend time on introducing this, as Marek advices.

Best Regards
Ulf Samuelsson

Quoted 2 lines

-michael

#24 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

Quoted 1 line

If the use of MTD is restricted to passive serial, this is OK with me.

Yeah, but that is not how upstream things work. You need to also think of any other use cases.

Quoted 4 lines

These are the things I want to achieve.

* transfer data using the SPI driver and not use board files. For that, the FPGA should be under the SPI in the device tree.

So to me it sounds like you actually want a "altera passive spi" driver which uses the spi subsytem (and not the MTD layer).

Quoted 1 line

* The size of the FPGA bitstream should be specified in the device tree.

I'm not experienced with the fpga bindings, but maybe they have something like that. Or you can deduce it from the compatible string. What's your usecase here? It sounds like a u-boot limitation to me (if you don't use files).

Quoted 4 lines

* The FPGA should be accessed as a device, not an address.
* I want a list of the FPGAs connected in the system
* Minimize code.
* Simplify user interface.

agreed.

Quoted 5 lines

From the CPU point of view, the FPGA is just a RAM location on the SPI bus. It cannot be read, but it can be written.

This is not surprising, because it is simply a RAM. It happens to have side effects, but that is not important.

Can't follow you here. How can the FPGA be a location in RAM if it's behind an SPI bus? Thats not how SPI works.

Quoted 2 lines

The MTD subsystem supplies everything I need, and adding the driver there is much less work than anything else.

Yeah but just because it has everything you need, doesn't mean it is a good fit for your use case.

Again. I think you want to have a passive serial driver which represents your fpga as a device which then can be configured. There is already an empty (sigh) FPGA_UCLASS. That should probably be extended. Ideally, this should be probed by the linux fpga bindings.

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

The additional features of MTD simplifies the user interaction by exposing a device and
providing info on the device.

Which would that be? What are the features of MTD which you need here? You've mentioned MTD partitions, but I'm not sure these really apply to partial reconfigurations. I know that Linux has a different device tree binding for it. So making u-boot use mtd partitions (if thats possible at all) and not the linux bindings means they'll diverge, which is something we want to avoid.

Quoted 3 lines

You cannot do partial reconfiguration on passive serial, so it is only of interest if someone feels a need to expand the MTD to other configuration methods.

So.. what MTD features are then used by your approach?

Quoted 35 lines

Here is how an FPGA region looks in Linux.
If I understand things correctly, you have one memory region per partial configuration. This looks quite a lot like partitions.

&fpga_region0 {
	#address-cells = <1>;
	#size-cells = <1>;

	firmware-name = "soc_system.rbf";
	fpga-bridges = <&fpga_bridge1>;
	ranges = <0x20000 0xff200000 0x100000>,
		 <0x0 0xc0000000 0x20000000>;

	gpio@10040 {
		compatible = "altr,pio-1.0";
		reg = <0x10040 0x20>;
		altr,ngpio = <4>;
		#gpio-cells = <2>;
		clocks = <2>;
		gpio-controller;
	};

	onchip-memory {
		device_type = "memory";
		compatible = "altr,onchipmem-15.1";
		reg = <0x0 0x10000>;
	};
};
Quoted 6 lines
Quoted 5 lines

The only difference the MTD subsystem would see is that there is a new subdirectory "fpga" with drivers and the Kconfig + Makefile changes to support the directory. Otherwise it plugs right in.

Quoted 8 lines
Quoted 4 lines

From a user point of view this is really confusing. Why would
you sometimes configure an fpga with the mtd command and sometimes with the fpga command depening whether it is using this passive programming thingy.

I think that most board designers would select one method of configuring the FPGA and they would only have either the FPGA or the MTD command set. I would be surprised if an engineer would be confused by this.

As a user I'd expect one command for any similar devices. As a board integrator, the fpga would be loaded by the board file anyway if needed during u-boot/bootup.

Just my two cents as a spi-nor reviewer in linux. You'd have to convince the u-boot maintainers. There is already an FPGA subsystem in linux so I doubt your approach would make it into linux.

-michael

#25 lore raw

Re: [PATCH 3/4] mtd/fpga: add fpga directory to mtd (with Cyclone 10)

In reply to Marek Vasut

Den 2023-02-21 kl. 02:13, skrev Marek Vasut:

Quoted 14 lines · Ulf Samuelsson
Quoted 13 lines

Den 2023-02-20 kl. 23:34, skrev Marek Vasut:

Quoted 10 lines · Ulf Samuelsson

[...]

Quoted 5 lines
Quoted 3 lines

To sum it up:
- The only part of the MTD subsystem that is in use by this driver
is the write callback, everything else is unused. That does not make MTD subsystem the right tool.

No, the MTD subsystem is compatible with the device tree.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

That does not justify overloading the subsystem with unrelated hardware support for which there is an existing subsystem with existing drivers for the functionality you would duplicate in the MTD subsystem. There are existing DT bindings for FPGAs, see Linux Documentation/devicetree/bindings/fpga/ , use those and add support for them into the FPGA subsystem if needed .

The current u-boot FPGA support is incompatible with the linux devicetree for FPGAs. There is simply nothing there.
That is the reason for the proposal in the first place.

Add it, that seems like the best approach here.

As I said, this is not an option for me.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

You can also get information about the FPGA when you list the mtd devices.

No, you cannot, because the information you may get out of the FPGA in some cases does not map to MTD devices .

Please give some examples.

Which FPGA bus bridge(s) are enabled for example . This is something present on SoCFPGA solutions , e.g. an AXI bridge into the fabric .

Is that not something which you handle by placing your FPGA configuration block under the bus bridge in the device tree?

In the proposed driver, the FPGA is under the SPI bus and the FPGA driver calls the access functions of the bus.

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

It allows you to support partial reconfiguration through the partition feature. You can write any size block to any part of the MTD, and you can express that in a device tree. That is what is needed.

I am afraid it is not as simple as that, see Linux Documentation/devicetree/bindings/fpga/fpga-region.txt . Furthermore, those DT bindings are already part of Linux and Linux expects the DT to contain exactly those bindings, U-Boot tries not to diverge from what Linux does in DT.

The device tree in my driver is a superset to what linux does. It tests more status pins, and provides a name for the FPGA. It would not be difficult to make it 100% compatible.

Extend the Linux DT bindings if they are insufficient, but please don't try and reinvent the wheel.

That is the plan.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

- There is existing FPGA subsystem both in U-Boot and Linux, extend
it if necessary. That also covers the usecases which go past a simple full bitstream upload.

And for use, that introduces a command set, which we do not need and adds 50-100kB to the image.

If you were to turn everything that needs read/write callback into an MTD device, you would be able to save even more space, but that does not make it right. You could try and reduce the FPGA command size if there is code which is unused for some usecases, that can be selected via Kconfig at build time.

Quoted 7 lines
Quoted 4 lines

 From my point of view, Having the FPGA command set duplicates the functionality of the MTD. That is the major contributor to code space expansion.

The thing you are writing to is SRAM which is memory.

There are flash based FPGAs , like Altera MAXV.
There are CPLDs which are not even flash based.

AFAIK, they are never configured by a CPU.
They are not supported by U-Boot.

Quoted 4 lines
Quoted 2 lines

If it is right or wrong to use that as an MTD is a matter of opinion.

I am still hoping the MTD maintainer would provide input here.

There are maintainers of MTD memories but
there is no maintainer of the MTD uclass in MAINTAINERS..

The last major contributors were

Name                    Year            lines
Heiko Schocher          2014-2015       1600
Stefan Roese            2009             811
Boris Brezillon		2017-2018	 600
Miquel Raynal		2018-2019	 564
Sergej Lapin            2013             215
Kyungmin Park           2008             197

Marek Behún 2021 178

Miquel Raynal is already on copy.

Quoted 42 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Obviously, someone would have to take the time to do it, but it is certainly possible.

You could make the exact same argument about making the FPGA driver a MISC device, CHAR device, BLOCK device, they all have the write callback, but that does not mean it is the right fit.

That is because you see the "write" as the only function.

Yes, because that is the only callback this patch implements, the rest are empty.

You cannot read back the configuration from a Cyclone 10.

Therefore, the entire read part of whatever subsystem is unnecessary.

Erase as well for most FPGAs which are SRAM based, even for flash based FPGA, per-sector erase is not available, since there is no concept of sectors or erase blocks at all.

Quoted 4 lines

A driver for an FPGA where configuration could be read back of course would have a read routine as well. The MTD subsystem can display the information the driver provides.
That is an important piece that would be missing from a MISC or CHAR driver.
You also have a "device" to work with.

All this is already in the FPGA subsystem, and it is designed toward the FPGA use case.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line

[...]

What would work is to keep the driver as is, replacing
the MTD stuff internally with an fpga_add after generating a struct based on the device tree.

Then it would be part of the FPGA subsystem.
To add this as an Altera passive serial is high risk, since it cannot be tested on boards using that.
It would simplify things a lot to add it as another driver.

Quoted 4 lines
Quoted 1 line

No, that would make things MUCH worse, because we would have a one-off driver used by one system, therefore poorly tested, which duplicates functionality of existing driver used by multiple systems and better tested. This also increases maintenance burden.

Today you have a custom functionality to access the FPGA in each board package.  That only gets tested when building that board.

No, at least the Altera SoCFPGA and Xilinx anything newer than Zynq/ZynqMP is tested regularly on actual hardware, and the code is common to all those systems, and lives in drivers/fpga/ .

Quoted 2 lines

So if you have 'n' boards, you have 'n' different ways of accessing the FPGA. Each poorly tested, if number of users are the measurement. The only thing in common is the multiplexing code.

Quoted 6 lines

Not really, on SoCFPGA systems, even the programming logic is common. For external FPGAs, sure, you need to provide the pin or interface mapping in some way, via platform data, DT, ACPI, whatever. If that is platform data, it should be moved to DT, the FPGA framework DT bindings should provide guidance how to do that. But even then, the driver itself should be generic, and reside in drivers/fpga/ .

Quoted 2 lines

Anyone that designs a new system, would have to choose between using the new driver, or write their own access method.

I vote "reuse existing driver, plug in DT/platform_data/... as needed" .

The choice is for passive serial solutions.
You have the choice between
* using the proposed driver (which will use the SPI driver)
* write your own access routine in your board files.

You do not have a choice to use an existing driver, because there is no existing driver. That is the problem with passive serial.

Quoted 4 lines
Quoted 2 lines

They cannot use what is in u-boot today, because it is in the board directory.

This is not true for majority of FPGA systems, see drivers/fpga/ .

The proposed driver replaces the passive serial driver only. The statement is true for all passive serial. Please have a look at how it is implemented today.

Quoted 4 lines
Quoted 1 line

Even if they have the same chip as a board with existing support, they cannot add it in, since it is in the board directory.

Are you actually talking about platform data which are used during driver instantiation, or, full driver, in board/ ?

When you use passive serial and connect using SPI, you cannot use the U-Boot SPI driver. Everyone are accessing their SPI peripheral to configure the FPGA in the board files.
Each solution is unique to that board.

Quoted 1 line

Platform data are fine-ish, full drivers in board/ should be on the way out.

I agree totally.

Quoted 8 lines
Quoted 5 lines

Only solution is to duplicate the code in their own board directory, but the likelyhood of using the same CPU is slim.

Are you happy with this?

I think we have a vastly different picture of the current situation .

I speak of passive serial only.

Quoted 8 lines
Quoted 5 lines

I wager that anyone wanting to use passive serial would adopt the new driver.

One solution is of course to ask the maintainers of those boards if they would consider moving to a device tree solution. Then the new driver would be the only driver.

Put them on CC, there is scripts/get_maintainer.pl script, use -f parameter to point it to specific files. I have a feeling a lot of those boards with external FPGAs being configured by poking registers in board/ are going to be dropped sooner rather than later.

There are only two boards that use the current passive serial driver.

$ rgrep _Passive_Serial_fns
include/ACEX1K.h:} Altera_ACEX1K_Passive_Serial_fns;
include/ACEX1K.h:} Altera_CYC2_Passive_Serial_fns;
drivers/fpga/cyclon2.c:	Altera_CYC2_Passive_Serial_fns ...
drivers/fpga/ACEX1K.c:	Altera_ACEX1K_Passive_Serial_fns ...

board/beckhoff/mx53cx9020/mx53cx9020.c:...Altera_CYC2_Passive_Serial ... board/astro/mcf5373l/fpga.c:Altera_CYC2_Passive_Serial ...

$ scripts/get_maintainer.pl board/beckhoff/mx53cx9020/mx53cx9020.c
Patrick Bruenn <[email protected]> (maintainer:MX53 CX9020)
$ scripts/get_maintainer.pl board/astro/mcf5373l/fpga.c
Wolfgang Wegner <[email protected]> (maintainer:MCF5373L BOARD)

Patrick Bruenn <[email protected]>
Wolfgang Wegner <[email protected]>

I will ask them in a separate email.

Quoted 9 lines
Quoted 7 lines
Quoted 6 lines

One single driver for this common functionality is always better as it gets more testing.

Quoted 1 line

The result would of course be something which adds both complexity and code size for us, without any benefit.

Please also consider the MTD maintainer point of view.

I do not see that this adds much more complexity than any other MTD device.

Again, there is a separate subsystem/framework for FPGAs . I disagree one should conflate MTD and FPGA subsystems.

It works well for passive serial.

Best Regards
Ulf Samuelsson

#26 lore raw

PATCH 4/4 mtd/Kconfig,Makefile support FPGA

In reply to [email protected]

From: Ulf Samuelsson <[email protected]>

---
 drivers/mtd/Kconfig  | 2 ++
 drivers/mtd/Makefile | 1 +
 2 files changed, 3 insertions(+)
drivers/mtd/Kconfig +2 -0
index af45ef00da..495211e314 100644
@@ -238,6 +238,8 @@ config SYS_MAX_FLASH_BANKS_DETECT
 	 to reduce the effective number of flash bank, between 0 and
 	 CONFIG_SYS_MAX_FLASH_BANKS
 
+source "drivers/mtd/fpga/Kconfig"
+
 source "drivers/mtd/nand/Kconfig"
 
 config SYS_NAND_MAX_OOBFREE
drivers/mtd/Makefile +1 -0
index 3a78590aaa..d15ca24ec5 100644
@@ -24,6 +24,7 @@ endif
 obj-y += nand/
 obj-y += onenand/
 obj-y += spi/
+obj-$(CONFIG_DM_SPI_FPGA) += fpga/
 obj-$(CONFIG_MTD_UBI) += ubi/
 
 #SPL/TPL build
Signature · 1 line
2.17.1