Skip to contentSkip to conversation

RISC-V SiFive FU540 support SPL

PATCH Superseded Pragnesh Patel 5 participants 26 messages Feb 24, 2020 – Apr 20, 2020

Subsystems (5)

v4 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v4 cover RISC-V SiFive FU540 support SPL

This series add support for SPL to FU540.U-Boot SPL can boot from L2 LIM (0x0800_0000) and jump to OpenSBI(FW_DYNAMIC firmware) and U-Boot proper from MMC devices.

How to test this patch:
1) Go to OpenSBI-dir : make PLATFORM=sifive/fu540 O=build_dir I=install_dir FW_DYNAMIC=y install
2) cp install_dir/platform/sifive/fu540/firmware/fw_dynamic.bin <u-boot-dir>/
3) Change to u-boot-dir
4) make sifive_fu540_defconfig
5) make all
6) ZSBL loads the U-boot SPL(u-boot-spl.bin) from a partition with
GUID type 5B193300-FC78-40CD-8002-E86C45580B47

sudo dd if=spl/u-boot-spl.bin of=/dev/sdc4 bs=1M

7) U-boot SPL expects a u-boot FIT image(u-boot.itb) from 1st partition(/dev/sdc1) of SD card irrespective of GUID

sudo dd if=u-boot.itb of=/dev/sdc1 bs=1M

Thanks to Yash Shah <[email protected]> for testing the series.

Changes in v4:
- Split misc DM driver patch into multiple patches
- Added new SPL_CRC7_SUPPORT Kconfig option
- Added DM driver for DDR
- Added clk_enable and clk_disable ops in SiFive PRCI driver
- Added early clock initialization for SPL in SiFive PRCI driver
- Added SPL config options in sifive_fu540_defconfig instead of creatiing a new config file for SPL
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v3:
- Remove arch-fu540 and arch-sifive from arch/riscv/include/asm/
- Split SPL patches into DDR and SPL and spl defconfig
- Update fu540/MAINTAINERS file
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v2:
- Add DM driver Sifive OTP
- Split SPL patches into multiple patches
- Add a seprate patch for _image_binary_end and crc7.c
- Add a seprate patch to add board -u-boot.dtsi files
- Update FU540 RISC-V documentation

Pragnesh Patel (14):
misc: add driver for the SiFive otp controller
riscv: sifive: fu540: Use OTP DM driver for serial environment
variable
riscv: Add _image_binary_end for SPL
lib: Makefile: build crc7.c when CONFIG_MMC_SPI
riscv: sifive: dts: fu540: Add board -u-boot.dtsi files
sifive: fu540: add ddr driver
sifive: dts: fu540: Add DDR controller and phy register settings
clk: sifive: fu540-prci: Add clock enable and disable ops
clk: sifive: fu540-prci: Add clock initialization for SPL
riscv: sifive: fu540: add SPL configuration
configs: fu540: Add config options for U-boot SPL
riscv: sifive: fu540: enable all cache ways from u-boot proper
sifive: fix palmer's email address
doc: update FU540 RISC-V documentation

 arch/riscv/cpu/u-boot-spl.lds                 |    1 +
 arch/riscv/dts/fu540-c000-u-boot.dtsi         |   63 +
 arch/riscv/dts/fu540-sdram-lpddr4.dtsi        | 1489 +++++++++++++++++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      |   23 +
 board/sifive/fu540/Kconfig                    |   10 +
 board/sifive/fu540/MAINTAINERS                |    2 +-
 board/sifive/fu540/Makefile                   |    5 +
 board/sifive/fu540/cache.c                    |   20 +
 board/sifive/fu540/cache.h                    |   13 +
 board/sifive/fu540/fu540-memory-map.h         |   33 +
 board/sifive/fu540/fu540.c                    |  139 +-
 board/sifive/fu540/spl.c                      |   78 +
 board/sifive/fu540/ux00prci.h                 |   56 +
 common/spl/Kconfig                            |    7 +
 configs/sifive_fu540_defconfig                |   11 +
 doc/board/sifive/fu540.rst                    |  409 ++++-
 drivers/clk/sifive/fu540-prci.c               |  169 +-
 drivers/misc/Kconfig                          |    7 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/sifive-otp.c                     |  241 +++
 drivers/ram/Kconfig                           |    7 +
 drivers/ram/Makefile                          |    2 +
 drivers/ram/sifive/Kconfig                    |    8 +
 drivers/ram/sifive/Makefile                   |    6 +
 drivers/ram/sifive/sdram_fu540.c              |  295 ++++
 drivers/ram/sifive/sdram_fu540.h              |   94 ++
 include/configs/sifive-fu540.h                |   18 +
 lib/Makefile                                  |    1 +
 28 files changed, 3107 insertions(+), 101 deletions(-)
 create mode 100644 arch/riscv/dts/fu540-c000-u-boot.dtsi
 create mode 100644 arch/riscv/dts/fu540-sdram-lpddr4.dtsi
 create mode 100644 arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
 create mode 100644 board/sifive/fu540/cache.c
 create mode 100644 board/sifive/fu540/cache.h
 create mode 100644 board/sifive/fu540/fu540-memory-map.h
 create mode 100644 board/sifive/fu540/spl.c
 create mode 100644 board/sifive/fu540/ux00prci.h
 create mode 100644 drivers/misc/sifive-otp.c
 create mode 100644 drivers/ram/sifive/Kconfig
 create mode 100644 drivers/ram/sifive/Makefile
 create mode 100644 drivers/ram/sifive/sdram_fu540.c
 create mode 100644 drivers/ram/sifive/sdram_fu540.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v4 1/14 misc: add driver for the SiFive otp controller

Added a misc driver to handle OTP memory in SiFive SoCs.

---
 drivers/misc/Kconfig      |   7 ++
 drivers/misc/Makefile     |   1 +
 drivers/misc/sifive-otp.c | 241 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 249 insertions(+)
 create mode 100644 drivers/misc/sifive-otp.c
drivers/misc/Kconfig +7 -0
index f18aa8f7ba..fcb45c63d4 100644
@@ -68,6 +68,13 @@ config ROCKCHIP_OTP
 	  addressing and a length or through child-nodes that are generated
 	  based on the e-fuse map retrieved from the DTS.
 
+config SIFIVE_OTP
+	bool "SiFive Ememory OTP driver"
+	depends on RISCV && MISC
+	help
+	  Enable support for reading and writing the ememory OTP on the
+	  SiFive SoCs.
+
 config VEXPRESS_CONFIG
 	bool "Enable support for Arm Versatile Express config bus"
 	depends on MISC
drivers/misc/Makefile +1 -0
index 2b843de93c..ee888631b6 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 obj-$(CONFIG_QFW) += qfw.o
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
+obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
 obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
 obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o
drivers/misc/sifive-otp.c new file +241 -0

241 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH v4 1/14 misc: add driver for the SiFive otp controller

Hi,

Quoted 163 lines

From: U-Boot <[email protected]> On Behalf Of Pragnesh Patel
Sent: lundi 24 f?vrier 2020 09:33

Added a misc driver to handle OTP memory in SiFive SoCs.

---
 drivers/misc/Kconfig      |   7 ++
 drivers/misc/Makefile     |   1 +
 drivers/misc/sifive-otp.c | 241 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 249 insertions(+)
 create mode 100644 drivers/misc/sifive-otp.c
drivers/misc/Kconfig index renamed from drivers/misc/Kconfig +0 -0

f18aa8f7ba..fcb45c63d4 100644

drivers/misc/Kconfig +7 -0
@@ -68,6 +68,13 @@ config ROCKCHIP_OTP
 	  addressing and a length or through child-nodes that are generated
 	  based on the e-fuse map retrieved from the DTS.
 
+config SIFIVE_OTP
+	bool "SiFive Ememory OTP driver"
+	depends on RISCV && MISC
+	help
+	  Enable support for reading and writing the ememory OTP on the
+	  SiFive SoCs.
+
 config VEXPRESS_CONFIG
 	bool "Enable support for Arm Versatile Express config bus"
 	depends on MISC
drivers/misc/Makefile index renamed from drivers/misc/Makefile +0 -0

2b843de93c..ee888631b6 100644

drivers/misc/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 obj-$(CONFIG_QFW) += qfw.o
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
+obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
 obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
 obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o diff --git

a/drivers/misc/sifive-otp.c b/drivers/misc/sifive-otp.c new file mode 100644 index 0000000000..6a39ec42df

drivers/misc/sifive-otp.c new file +115 -0
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This is a driver for the eMemory EG004K32TQ028XW01 NeoFuse
+ * One-Time-Programmable (OTP) memory used within the SiFive FU540.
+ * It is documented in the FU540 manual here:
+ * https://www.sifive.com/documentation/chips/freedom-u540-c000-manual/
+ *
+ * Copyright (C) 2018 Philipp Hug <[email protected]>
+ * Copyright (C) 2018 Joey Hewitt <[email protected]>
+ *
+ * Copyright (C) 2020 SiFive, Inc
+ */
+
+/*
+ * The FU540 stores 4096x32 bit (16KiB) values.
+ * Index 0x00-0xff are reserved for SiFive internal use. (first 1KiB)
+ * Right now first 1KB is used to store only serial number.
+ */
+
+#include <common.h>
+#include <dm/device.h>
+#include <dm/read.h>
+#include <linux/io.h>
+#include <misc.h>
+
+#define BYTES_PER_FUSE		4
+
+#define PA_RESET_VAL		0x00
+#define PAS_RESET_VAL		0x00
+#define PAIO_RESET_VAL		0x00
+#define PDIN_RESET_VAL		0x00
+#define PTM_RESET_VAL		0x00
+
+#define PCLK_ENABLE_VAL			BIT(0)
+#define PCLK_DISABLE_VAL		0x00
+
+#define PWE_WRITE_ENABLE		BIT(0)
+#define PWE_WRITE_DISABLE		0x00
+
+#define PTM_FUSE_PROGRAM_VAL		BIT(1)
+
+#define PCE_ENABLE_INPUT		BIT(0)
+#define PCE_DISABLE_INPUT		0x00
+
+#define PPROG_ENABLE_INPUT		BIT(0)
+#define PPROG_DISABLE_INPUT		0x00
+
+#define PTRIM_ENABLE_INPUT		BIT(0)
+#define PTRIM_DISABLE_INPUT		0x00
+
+#define PDSTB_DEEP_STANDBY_ENABLE	BIT(0)
+#define PDSTB_DEEP_STANDBY_DISABLE	0x00
+
+struct sifive_otp_regs {
+	u32 pa;     /* Address input */
+	u32 paio;   /* Program address input */
+	u32 pas;    /* Program redundancy cell selection input */
+	u32 pce;    /* OTP Macro enable input */
+	u32 pclk;   /* Clock input */
+	u32 pdin;   /* Write data input */
+	u32 pdout;  /* Read data output */
+	u32 pdstb;  /* Deep standby mode enable input (active low) */
+	u32 pprog;  /* Program mode enable input */
+	u32 ptc;    /* Test column enable input */
+	u32 ptm;    /* Test mode enable input */
+	u32 ptm_rep;/* Repair function test mode enable input */
+	u32 ptr;    /* Test row enable input */
+	u32 ptrim;  /* Repair function enable input */
+	u32 pwe;    /* Write enable input (defines program cycle) */
+} __packed;
+
+struct sifive_otp_platdata {
+	struct sifive_otp_regs __iomem *regs;
+	u32 total_fuses;
+};
+
+/*
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_read(struct udevice *dev, int offset,
+			   void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 fusebuf[fusecount];
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+
+	/* read all requested fuses */
+	for (unsigned int i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+
+		/* cycle clock to read */
+		iowrite32(PCLK_ENABLE_VAL, &regs->pclk);
+		mdelay(1);
+		iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+		mdelay(1);
+
+		/* read the value */
+		fusebuf[i] = ioread32(&regs->pdout);
+	}

drivers/misc/sifive-otp.c line 125

Quoted 10 lines
drivers/misc/sifive-otp.c new file +10 -0
+
+	/* shut down */
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	// copy out
+	memcpy(buf, fusebuf, size);
+
+	return 0;

Since the commit 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

	return  size;
Quoted 70 lines
drivers/misc/sifive-otp.c new file +70 -0
+}
+
+/*
+ * Caution:
+ * OTP can be written only once, so use carefully.
+ *
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_write(struct udevice *dev, int offset,
+			    const void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 *write_buf = (u32 *)buf;
+	u32 write_data;
+	int i, pas, bit;
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* reset registers */
+	iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+	iowrite32(PA_RESET_VAL, &regs->pa);
+	iowrite32(PAS_RESET_VAL, &regs->pas);
+	iowrite32(PAIO_RESET_VAL, &regs->paio);
+	iowrite32(PDIN_RESET_VAL, &regs->pdin);
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PTM_FUSE_PROGRAM_VAL, &regs->ptm);
+	mdelay(1);
+
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+	iowrite32(PPROG_ENABLE_INPUT, &regs->pprog);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* write all requested fuses */
+	for (i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+		write_data = *(write_buf++);
+
+		for (pas = 0; pas < 2; pas++) {
+			iowrite32(pas, &regs->pas);
+
+			for (bit = 0; bit < 32; bit++) {
+				iowrite32(bit, &regs->paio);
+				iowrite32(((write_data >> bit) & 1),
+					  &regs->pdin);
+				mdelay(1);
+
+				iowrite32(PWE_WRITE_ENABLE, &regs->pwe);
+				mdelay(1);
+				iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+				mdelay(1);
+			}
+		}
+
+		iowrite32(PAS_RESET_VAL, &regs->pas);
+	}
+

drivers/misc/sifive-otp.c line 205

Quoted 10 lines
drivers/misc/sifive-otp.c new file +10 -0
+	/* shut down */
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PPROG_DISABLE_INPUT, &regs->pprog);
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTM_RESET_VAL, &regs->ptm);
+
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	return 0;

Since the commit 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

	return  size;
Quoted 36 lines
drivers/misc/sifive-otp.c new file +35 -1
+}
+
+static int sifive_otp_ofdata_to_platdata(struct udevice *dev) {
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	int ret;
+
+	plat->regs = dev_read_addr_ptr(dev);
+
+	ret = dev_read_u32(dev, "fuse-count", &plat->total_fuses);
+	if (ret < 0) {
+		pr_err("\"fuse-count\" not found\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct misc_ops sifive_otp_ops = {
+	.read = sifive_otp_read,
+	.write = sifive_otp_write,
+};
+
+static const struct udevice_id sifive_otp_ids[] = {
+	{ .compatible = "sifive,fu540-otp" },
+	{}
+};
+
+U_BOOT_DRIVER(sifive_otp) = {
+	.name = "sifive_otp",
+	.id = UCLASS_MISC,
+	.of_match = sifive_otp_ids,
+	.ofdata_to_platdata = sifive_otp_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct sifive_otp_platdata),
+	.ops = &sifive_otp_ops,
+};
--
Quoted 1 line

2.17.1

Regards

Patrick

#3 lore raw

PATCH v4 1/14 misc: add driver for the SiFive otp controller

Hi Patrick,

Quoted 198 lines

-----Original Message-----
From: Patrick DELAUNAY <[email protected]>
Sent: 24 February 2020 23:34
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; jagan at amarulasolutions.com; Troy Benjegerdes ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; Simon Glass <[email protected]>; Finley Xiao <[email protected]>; Marcel Ziswiler <[email protected]>; Tero Kristo <[email protected]>; Adam Ford <[email protected]>; Peng Fan <[email protected]>; Eugen Hristev <[email protected]>; Keerthy <[email protected]>
Subject: RE: [PATCH v4 01/14] misc: add driver for the SiFive otp controller

Hi,

Quoted 50 lines

From: U-Boot <[email protected]> On Behalf Of Pragnesh Patel
Sent: lundi 24 f?vrier 2020 09:33

Added a misc driver to handle OTP memory in SiFive SoCs.

---
 drivers/misc/Kconfig      |   7 ++
 drivers/misc/Makefile     |   1 +
 drivers/misc/sifive-otp.c | 241
++++++++++++++++++++++++++++++++++++++
 3 files changed, 249 insertions(+)
 create mode 100644 drivers/misc/sifive-otp.c
drivers/misc/Kconfig index renamed from drivers/misc/Kconfig +0 -0

f18aa8f7ba..fcb45c63d4 100644

drivers/misc/Kconfig +7 -0
@@ -68,6 +68,13 @@ config ROCKCHIP_OTP
 	  addressing and a length or through child-nodes that are generated
 	  based on the e-fuse map retrieved from the DTS.
 
+config SIFIVE_OTP
+	bool "SiFive Ememory OTP driver"
+	depends on RISCV && MISC
+	help
+	  Enable support for reading and writing the ememory OTP on the
+	  SiFive SoCs.
+
 config VEXPRESS_CONFIG
 	bool "Enable support for Arm Versatile Express config bus"
 	depends on MISC
drivers/misc/Makefile index renamed from drivers/misc/Makefile +0 -0

2b843de93c..ee888631b6 100644

drivers/misc/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 obj-$(CONFIG_QFW) += qfw.o
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
+obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
 obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
 obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o diff --git

a/drivers/misc/sifive-otp.c b/drivers/misc/sifive-otp.c new file mode 100644 index 0000000000..6a39ec42df

drivers/misc/sifive-otp.c line 7

Quoted 7 lines
drivers/misc/sifive-otp.c new file +7 -0
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This is a driver for the eMemory EG004K32TQ028XW01 NeoFuse
+ * One-Time-Programmable (OTP) memory used within the SiFive FU540.
+ * It is documented in the FU540 manual here:
+ *
+https://www.sifive.com/documentation/chips/freedom-u540-c000-

manual/

Quoted 109 lines
drivers/misc/sifive-otp.c new file +109 -0
+ *
+ * Copyright (C) 2018 Philipp Hug <[email protected]>
+ * Copyright (C) 2018 Joey Hewitt <[email protected]>
+ *
+ * Copyright (C) 2020 SiFive, Inc
+ */
+
+/*
+ * The FU540 stores 4096x32 bit (16KiB) values.
+ * Index 0x00-0xff are reserved for SiFive internal use. (first 1KiB)
+ * Right now first 1KB is used to store only serial number.
+ */
+
+#include <common.h>
+#include <dm/device.h>
+#include <dm/read.h>
+#include <linux/io.h>
+#include <misc.h>
+
+#define BYTES_PER_FUSE		4
+
+#define PA_RESET_VAL		0x00
+#define PAS_RESET_VAL		0x00
+#define PAIO_RESET_VAL		0x00
+#define PDIN_RESET_VAL		0x00
+#define PTM_RESET_VAL		0x00
+
+#define PCLK_ENABLE_VAL			BIT(0)
+#define PCLK_DISABLE_VAL		0x00
+
+#define PWE_WRITE_ENABLE		BIT(0)
+#define PWE_WRITE_DISABLE		0x00
+
+#define PTM_FUSE_PROGRAM_VAL		BIT(1)
+
+#define PCE_ENABLE_INPUT		BIT(0)
+#define PCE_DISABLE_INPUT		0x00
+
+#define PPROG_ENABLE_INPUT		BIT(0)
+#define PPROG_DISABLE_INPUT		0x00
+
+#define PTRIM_ENABLE_INPUT		BIT(0)
+#define PTRIM_DISABLE_INPUT		0x00
+
+#define PDSTB_DEEP_STANDBY_ENABLE	BIT(0)
+#define PDSTB_DEEP_STANDBY_DISABLE	0x00
+
+struct sifive_otp_regs {
+	u32 pa;     /* Address input */
+	u32 paio;   /* Program address input */
+	u32 pas;    /* Program redundancy cell selection input */
+	u32 pce;    /* OTP Macro enable input */
+	u32 pclk;   /* Clock input */
+	u32 pdin;   /* Write data input */
+	u32 pdout;  /* Read data output */
+	u32 pdstb;  /* Deep standby mode enable input (active low) */
+	u32 pprog;  /* Program mode enable input */
+	u32 ptc;    /* Test column enable input */
+	u32 ptm;    /* Test mode enable input */
+	u32 ptm_rep;/* Repair function test mode enable input */
+	u32 ptr;    /* Test row enable input */
+	u32 ptrim;  /* Repair function enable input */
+	u32 pwe;    /* Write enable input (defines program cycle) */
+} __packed;
+
+struct sifive_otp_platdata {
+	struct sifive_otp_regs __iomem *regs;
+	u32 total_fuses;
+};
+
+/*
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_read(struct udevice *dev, int offset,
+			   void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 fusebuf[fusecount];
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+
+	/* read all requested fuses */
+	for (unsigned int i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+
+		/* cycle clock to read */
+		iowrite32(PCLK_ENABLE_VAL, &regs->pclk);
+		mdelay(1);
+		iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+		mdelay(1);
+
+		/* read the value */
+		fusebuf[i] = ioread32(&regs->pdout);
+	}

drivers/misc/sifive-otp.c line 125

Quoted 10 lines
drivers/misc/sifive-otp.c new file +10 -0
+
+	/* shut down */
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	// copy out
+	memcpy(buf, fusebuf, size);
+
+	return 0;

Since the commit 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

Quoted 2 lines
	return  size;

Yes, you are right. Will update in v5.

Quoted 84 lines
Quoted 70 lines
drivers/misc/sifive-otp.c new file +70 -0
+}
+
+/*
+ * Caution:
+ * OTP can be written only once, so use carefully.
+ *
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_write(struct udevice *dev, int offset,
+			    const void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 *write_buf = (u32 *)buf;
+	u32 write_data;
+	int i, pas, bit;
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* reset registers */
+	iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+	iowrite32(PA_RESET_VAL, &regs->pa);
+	iowrite32(PAS_RESET_VAL, &regs->pas);
+	iowrite32(PAIO_RESET_VAL, &regs->paio);
+	iowrite32(PDIN_RESET_VAL, &regs->pdin);
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PTM_FUSE_PROGRAM_VAL, &regs->ptm);
+	mdelay(1);
+
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+	iowrite32(PPROG_ENABLE_INPUT, &regs->pprog);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* write all requested fuses */
+	for (i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+		write_data = *(write_buf++);
+
+		for (pas = 0; pas < 2; pas++) {
+			iowrite32(pas, &regs->pas);
+
+			for (bit = 0; bit < 32; bit++) {
+				iowrite32(bit, &regs->paio);
+				iowrite32(((write_data >> bit) & 1),
+					  &regs->pdin);
+				mdelay(1);
+
+				iowrite32(PWE_WRITE_ENABLE, &regs->pwe);
+				mdelay(1);
+				iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+				mdelay(1);
+			}
+		}
+
+		iowrite32(PAS_RESET_VAL, &regs->pas);
+	}
+

drivers/misc/sifive-otp.c line 205

Quoted 10 lines
drivers/misc/sifive-otp.c new file +10 -0
+	/* shut down */
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PPROG_DISABLE_INPUT, &regs->pprog);
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTM_RESET_VAL, &regs->ptm);
+
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	return 0;

Since the commit 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

Quoted 2 lines
	return  size;

Yes, you are right. Will update in v5. Thanks for the review.

Quoted 41 lines
Quoted 36 lines
drivers/misc/sifive-otp.c new file +35 -1
+}
+
+static int sifive_otp_ofdata_to_platdata(struct udevice *dev) {
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	int ret;
+
+	plat->regs = dev_read_addr_ptr(dev);
+
+	ret = dev_read_u32(dev, "fuse-count", &plat->total_fuses);
+	if (ret < 0) {
+		pr_err("\"fuse-count\" not found\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct misc_ops sifive_otp_ops = {
+	.read = sifive_otp_read,
+	.write = sifive_otp_write,
+};
+
+static const struct udevice_id sifive_otp_ids[] = {
+	{ .compatible = "sifive,fu540-otp" },
+	{}
+};
+
+U_BOOT_DRIVER(sifive_otp) = {
+	.name = "sifive_otp",
+	.id = UCLASS_MISC,
+	.of_match = sifive_otp_ids,
+	.ofdata_to_platdata = sifive_otp_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct sifive_otp_platdata),
+	.ops = &sifive_otp_ops,
+};
--
Quoted 1 line

2.17.1

Regards

Patrick

#4 lore raw

PATCH v4 1/14 misc: add driver for the SiFive otp controller

In reply to Pragnesh Patel
Quoted 225 lines · pragnesh.patel at sifive.com

Added a misc driver to handle OTP memory in SiFive SoCs.

---
 drivers/misc/Kconfig      |   7 ++
 drivers/misc/Makefile     |   1 +
 drivers/misc/sifive-otp.c | 241 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 249 insertions(+)
 create mode 100644 drivers/misc/sifive-otp.c
drivers/misc/Kconfig +7 -0
index f18aa8f7ba..fcb45c63d4 100644
@@ -68,6 +68,13 @@ config ROCKCHIP_OTP
 	  addressing and a length or through child-nodes that are generated
 	  based on the e-fuse map retrieved from the DTS.
 
+config SIFIVE_OTP
+	bool "SiFive Ememory OTP driver"
+	depends on RISCV && MISC
+	help
+	  Enable support for reading and writing the ememory OTP on the
+	  SiFive SoCs.
+
 config VEXPRESS_CONFIG
 	bool "Enable support for Arm Versatile Express config bus"
 	depends on MISC
drivers/misc/Makefile +1 -0
index 2b843de93c..ee888631b6 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 obj-$(CONFIG_QFW) += qfw.o
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
+obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
 obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
 obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o
drivers/misc/sifive-otp.c new file +179 -0
new file mode 100644
index 0000000000..6a39ec42df
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This is a driver for the eMemory EG004K32TQ028XW01 NeoFuse
+ * One-Time-Programmable (OTP) memory used within the SiFive FU540.
+ * It is documented in the FU540 manual here:
+ * https://www.sifive.com/documentation/chips/freedom-u540-c000-manual/
+ *
+ * Copyright (C) 2018 Philipp Hug <[email protected]>
+ * Copyright (C) 2018 Joey Hewitt <[email protected]>
+ *
+ * Copyright (C) 2020 SiFive, Inc
+ */
+
+/*
+ * The FU540 stores 4096x32 bit (16KiB) values.
+ * Index 0x00-0xff are reserved for SiFive internal use. (first 1KiB)
+ * Right now first 1KB is used to store only serial number.
+ */
+
+#include <common.h>
+#include <dm/device.h>
+#include <dm/read.h>
+#include <linux/io.h>
+#include <misc.h>
+
+#define BYTES_PER_FUSE		4
+
+#define PA_RESET_VAL		0x00
+#define PAS_RESET_VAL		0x00
+#define PAIO_RESET_VAL		0x00
+#define PDIN_RESET_VAL		0x00
+#define PTM_RESET_VAL		0x00
+
+#define PCLK_ENABLE_VAL			BIT(0)
+#define PCLK_DISABLE_VAL		0x00
+
+#define PWE_WRITE_ENABLE		BIT(0)
+#define PWE_WRITE_DISABLE		0x00
+
+#define PTM_FUSE_PROGRAM_VAL		BIT(1)
+
+#define PCE_ENABLE_INPUT		BIT(0)
+#define PCE_DISABLE_INPUT		0x00
+
+#define PPROG_ENABLE_INPUT		BIT(0)
+#define PPROG_DISABLE_INPUT		0x00
+
+#define PTRIM_ENABLE_INPUT		BIT(0)
+#define PTRIM_DISABLE_INPUT		0x00
+
+#define PDSTB_DEEP_STANDBY_ENABLE	BIT(0)
+#define PDSTB_DEEP_STANDBY_DISABLE	0x00
+
+struct sifive_otp_regs {
+	u32 pa;     /* Address input */
+	u32 paio;   /* Program address input */
+	u32 pas;    /* Program redundancy cell selection input */
+	u32 pce;    /* OTP Macro enable input */
+	u32 pclk;   /* Clock input */
+	u32 pdin;   /* Write data input */
+	u32 pdout;  /* Read data output */
+	u32 pdstb;  /* Deep standby mode enable input (active low) */
+	u32 pprog;  /* Program mode enable input */
+	u32 ptc;    /* Test column enable input */
+	u32 ptm;    /* Test mode enable input */
+	u32 ptm_rep;/* Repair function test mode enable input */
+	u32 ptr;    /* Test row enable input */
+	u32 ptrim;  /* Repair function enable input */
+	u32 pwe;    /* Write enable input (defines program cycle) */
+} __packed;
+
+struct sifive_otp_platdata {
+	struct sifive_otp_regs __iomem *regs;
+	u32 total_fuses;
+};
+
+/*
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_read(struct udevice *dev, int offset,
+			   void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 fusebuf[fusecount];
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+
+	/* read all requested fuses */
+	for (unsigned int i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+
+		/* cycle clock to read */
+		iowrite32(PCLK_ENABLE_VAL, &regs->pclk);
+		mdelay(1);
+		iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+		mdelay(1);
+
+		/* read the value */
+		fusebuf[i] = ioread32(&regs->pdout);
+	}
+
+	/* shut down */
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	// copy out
+	memcpy(buf, fusebuf, size);
+
+	return 0;
+}
+
+/*
+ * Caution:
+ * OTP can be written only once, so use carefully.
+ *
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_write(struct udevice *dev, int offset,
+			    const void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 *write_buf = (u32 *)buf;
+	u32 write_data;
+	int i, pas, bit;
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* reset registers */
+	iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+	iowrite32(PA_RESET_VAL, &regs->pa);
+	iowrite32(PAS_RESET_VAL, &regs->pas);
+	iowrite32(PAIO_RESET_VAL, &regs->paio);
+	iowrite32(PDIN_RESET_VAL, &regs->pdin);
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PTM_FUSE_PROGRAM_VAL, &regs->ptm);
+	mdelay(1);
+
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+	iowrite32(PPROG_ENABLE_INPUT, &regs->pprog);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* write all requested fuses */
+	for (i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+		write_data = *(write_buf++);
+
+		for (pas = 0; pas < 2; pas++) {
+			iowrite32(pas, &regs->pas);
+

drivers/misc/sifive-otp.c line 189

Quoted 10 lines
drivers/misc/sifive-otp.c new file +10 -0
+			for (bit = 0; bit < 32; bit++) {
+				iowrite32(bit, &regs->paio);
+				iowrite32(((write_data >> bit) & 1),
+					  &regs->pdin);
+				mdelay(1);
+
+				iowrite32(PWE_WRITE_ENABLE, &regs->pwe);
+				mdelay(1);
+				iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+				mdelay(1);

IIRC, interrupting this sequence will cause irreversable damage to the chip. I don't know u-boot well enough to know if this executes in a context that can be interrupted, though.

Quoted 52 lines
drivers/misc/sifive-otp.c new file +52 -0
+			}
+		}
+
+		iowrite32(PAS_RESET_VAL, &regs->pas);
+	}
+
+	/* shut down */
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PPROG_DISABLE_INPUT, &regs->pprog);
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTM_RESET_VAL, &regs->ptm);
+
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	return 0;
+}
+
+static int sifive_otp_ofdata_to_platdata(struct udevice *dev)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	int ret;
+
+	plat->regs = dev_read_addr_ptr(dev);
+
+	ret = dev_read_u32(dev, "fuse-count", &plat->total_fuses);
+	if (ret < 0) {
+		pr_err("\"fuse-count\" not found\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct misc_ops sifive_otp_ops = {
+	.read = sifive_otp_read,
+	.write = sifive_otp_write,
+};
+
+static const struct udevice_id sifive_otp_ids[] = {
+	{ .compatible = "sifive,fu540-otp" },
+	{}
+};
+
+U_BOOT_DRIVER(sifive_otp) = {
+	.name = "sifive_otp",
+	.id = UCLASS_MISC,
+	.of_match = sifive_otp_ids,
+	.ofdata_to_platdata = sifive_otp_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct sifive_otp_platdata),
+	.ops = &sifive_otp_ops,
+};
#5 lore raw

PATCH v4 1/14 misc: add driver for the SiFive otp controller

Hi Palmer,

Quoted 249 lines

-----Original Message-----
From: Palmer Dabbelt <[email protected]>
Sent: 06 March 2020 06:07
To: Pragnesh Patel <[email protected]>
Cc: u-boot at lists.denx.de; Atish Patra <[email protected]>; bmeng.cn at gmail.com; Paul Walmsley <[email protected]>; jagan at amarulasolutions.com; Troy Benjegerdes <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Pragnesh Patel <[email protected]>; sjg at chromium.org; finley.xiao at rock- chips.com; marcel.ziswiler at toradex.com; t-kristo at ti.com; aford173 at gmail.com; peng.fan at nxp.com; eugen.hristev at microchip.com; j- keerthy at ti.com
Subject: Re: [PATCH v4 01/14] misc: add driver for the SiFive otp controller

Quoted 46 lines · pragnesh.patel at sifive.com

Added a misc driver to handle OTP memory in SiFive SoCs.

---
 drivers/misc/Kconfig      |   7 ++
 drivers/misc/Makefile     |   1 +
 drivers/misc/sifive-otp.c | 241
++++++++++++++++++++++++++++++++++++++
 3 files changed, 249 insertions(+)
 create mode 100644 drivers/misc/sifive-otp.c
drivers/misc/Kconfig index renamed from drivers/misc/Kconfig +0 -0

f18aa8f7ba..fcb45c63d4 100644

drivers/misc/Kconfig +7 -0
@@ -68,6 +68,13 @@ config ROCKCHIP_OTP
 	  addressing and a length or through child-nodes that are generated
 	  based on the e-fuse map retrieved from the DTS.
 
+config SIFIVE_OTP
+	bool "SiFive Ememory OTP driver"
+	depends on RISCV && MISC
+	help
+	  Enable support for reading and writing the ememory OTP on the
+	  SiFive SoCs.
+
 config VEXPRESS_CONFIG
 	bool "Enable support for Arm Versatile Express config bus"
 	depends on MISC
drivers/misc/Makefile index renamed from drivers/misc/Makefile +0 -0

2b843de93c..ee888631b6 100644

drivers/misc/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 obj-$(CONFIG_QFW) += qfw.o
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
+obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
 obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
 obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o diff --git

a/drivers/misc/sifive-otp.c b/drivers/misc/sifive-otp.c new file mode 100644 index 0000000000..6a39ec42df

drivers/misc/sifive-otp.c line 7

Quoted 7 lines
drivers/misc/sifive-otp.c new file +7 -0
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This is a driver for the eMemory EG004K32TQ028XW01 NeoFuse
+ * One-Time-Programmable (OTP) memory used within the SiFive FU540.
+ * It is documented in the FU540 manual here:
+ *
+https://www.sifive.com/documentation/chips/freedom-u540-c000-

manual/

Quoted 179 lines
drivers/misc/sifive-otp.c new file +179 -0
+ *
+ * Copyright (C) 2018 Philipp Hug <[email protected]>
+ * Copyright (C) 2018 Joey Hewitt <[email protected]>
+ *
+ * Copyright (C) 2020 SiFive, Inc
+ */
+
+/*
+ * The FU540 stores 4096x32 bit (16KiB) values.
+ * Index 0x00-0xff are reserved for SiFive internal use. (first 1KiB)
+ * Right now first 1KB is used to store only serial number.
+ */
+
+#include <common.h>
+#include <dm/device.h>
+#include <dm/read.h>
+#include <linux/io.h>
+#include <misc.h>
+
+#define BYTES_PER_FUSE		4
+
+#define PA_RESET_VAL		0x00
+#define PAS_RESET_VAL		0x00
+#define PAIO_RESET_VAL		0x00
+#define PDIN_RESET_VAL		0x00
+#define PTM_RESET_VAL		0x00
+
+#define PCLK_ENABLE_VAL			BIT(0)
+#define PCLK_DISABLE_VAL		0x00
+
+#define PWE_WRITE_ENABLE		BIT(0)
+#define PWE_WRITE_DISABLE		0x00
+
+#define PTM_FUSE_PROGRAM_VAL		BIT(1)
+
+#define PCE_ENABLE_INPUT		BIT(0)
+#define PCE_DISABLE_INPUT		0x00
+
+#define PPROG_ENABLE_INPUT		BIT(0)
+#define PPROG_DISABLE_INPUT		0x00
+
+#define PTRIM_ENABLE_INPUT		BIT(0)
+#define PTRIM_DISABLE_INPUT		0x00
+
+#define PDSTB_DEEP_STANDBY_ENABLE	BIT(0)
+#define PDSTB_DEEP_STANDBY_DISABLE	0x00
+
+struct sifive_otp_regs {
+	u32 pa;     /* Address input */
+	u32 paio;   /* Program address input */
+	u32 pas;    /* Program redundancy cell selection input */
+	u32 pce;    /* OTP Macro enable input */
+	u32 pclk;   /* Clock input */
+	u32 pdin;   /* Write data input */
+	u32 pdout;  /* Read data output */
+	u32 pdstb;  /* Deep standby mode enable input (active low) */
+	u32 pprog;  /* Program mode enable input */
+	u32 ptc;    /* Test column enable input */
+	u32 ptm;    /* Test mode enable input */
+	u32 ptm_rep;/* Repair function test mode enable input */
+	u32 ptr;    /* Test row enable input */
+	u32 ptrim;  /* Repair function enable input */
+	u32 pwe;    /* Write enable input (defines program cycle) */
+} __packed;
+
+struct sifive_otp_platdata {
+	struct sifive_otp_regs __iomem *regs;
+	u32 total_fuses;
+};
+
+/*
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_read(struct udevice *dev, int offset,
+			   void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 fusebuf[fusecount];
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+
+	/* read all requested fuses */
+	for (unsigned int i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+
+		/* cycle clock to read */
+		iowrite32(PCLK_ENABLE_VAL, &regs->pclk);
+		mdelay(1);
+		iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+		mdelay(1);
+
+		/* read the value */
+		fusebuf[i] = ioread32(&regs->pdout);
+	}
+
+	/* shut down */
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	// copy out
+	memcpy(buf, fusebuf, size);
+
+	return 0;
+}
+
+/*
+ * Caution:
+ * OTP can be written only once, so use carefully.
+ *
+ * offset and size are assumed aligned to the size of the fuses (32bit).
+ */
+static int sifive_otp_write(struct udevice *dev, int offset,
+			    const void *buf, int size)
+{
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	struct sifive_otp_regs *regs = (struct sifive_otp_regs *)plat->regs;
+
+	int fuseidx = offset / BYTES_PER_FUSE;
+	int fusecount = size / BYTES_PER_FUSE;
+	u32 *write_buf = (u32 *)buf;
+	u32 write_data;
+	int i, pas, bit;
+
+	/* check bounds */
+	if (offset < 0 || size < 0)
+		return -EINVAL;
+	if (fuseidx >= plat->total_fuses)
+		return -EINVAL;
+	if ((fuseidx + fusecount) > plat->total_fuses)
+		return -EINVAL;
+
+	/* init OTP */
+	iowrite32(PDSTB_DEEP_STANDBY_ENABLE, &regs->pdstb);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* reset registers */
+	iowrite32(PCLK_DISABLE_VAL, &regs->pclk);
+	iowrite32(PA_RESET_VAL, &regs->pa);
+	iowrite32(PAS_RESET_VAL, &regs->pas);
+	iowrite32(PAIO_RESET_VAL, &regs->paio);
+	iowrite32(PDIN_RESET_VAL, &regs->pdin);
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PTM_FUSE_PROGRAM_VAL, &regs->ptm);
+	mdelay(1);
+
+	iowrite32(PCE_ENABLE_INPUT, &regs->pce);
+	iowrite32(PPROG_ENABLE_INPUT, &regs->pprog);
+	iowrite32(PTRIM_ENABLE_INPUT, &regs->ptrim);
+
+	/* write all requested fuses */
+	for (i = 0; i < fusecount; i++, fuseidx++) {
+		iowrite32(fuseidx, &regs->pa);
+		write_data = *(write_buf++);
+
+		for (pas = 0; pas < 2; pas++) {
+			iowrite32(pas, &regs->pas);
+
+			for (bit = 0; bit < 32; bit++) {
+				iowrite32(bit, &regs->paio);
+				iowrite32(((write_data >> bit) & 1),
+					  &regs->pdin);
+				mdelay(1);
+
Quoted 8 lines

drivers/misc/sifive-otp.c line 189

Quoted 4 lines
drivers/misc/sifive-otp.c new file +4 -0
+				iowrite32(PWE_WRITE_ENABLE, &regs->pwe);
+				mdelay(1);
+				iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+				mdelay(1);

IIRC, interrupting this sequence will cause irreversable damage to the chip. I don't know u-boot well enough to know if this executes in a context that can be interrupted, though.

Thanks for pointing me to this.

As far as I know, u-boot is strictly single-threaded and all drivers use polling only.
https://lists.denx.de/pipermail/u-boot/2011-May/092772.html

Interrupts are not really used in U-Boot.
https://stackoverflow.com/questions/23491365/handling-gpio-interrupts-in-u-boot

So there is very less chances of this sequence will be interrupted.

Quoted 52 lines
Quoted 52 lines
drivers/misc/sifive-otp.c new file +51 -0
+			}
+		}
+
+		iowrite32(PAS_RESET_VAL, &regs->pas);
+	}
+
+	/* shut down */
+	iowrite32(PWE_WRITE_DISABLE, &regs->pwe);
+	iowrite32(PPROG_DISABLE_INPUT, &regs->pprog);
+	iowrite32(PCE_DISABLE_INPUT, &regs->pce);
+	iowrite32(PTM_RESET_VAL, &regs->ptm);
+
+	iowrite32(PTRIM_DISABLE_INPUT, &regs->ptrim);
+	iowrite32(PDSTB_DEEP_STANDBY_DISABLE, &regs->pdstb);
+
+	return 0;
+}
+
+static int sifive_otp_ofdata_to_platdata(struct udevice *dev) {
+	struct sifive_otp_platdata *plat = dev_get_platdata(dev);
+	int ret;
+
+	plat->regs = dev_read_addr_ptr(dev);
+
+	ret = dev_read_u32(dev, "fuse-count", &plat->total_fuses);
+	if (ret < 0) {
+		pr_err("\"fuse-count\" not found\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct misc_ops sifive_otp_ops = {
+	.read = sifive_otp_read,
+	.write = sifive_otp_write,
+};
+
+static const struct udevice_id sifive_otp_ids[] = {
+	{ .compatible = "sifive,fu540-otp" },
+	{}
+};
+
+U_BOOT_DRIVER(sifive_otp) = {
+	.name = "sifive_otp",
+	.id = UCLASS_MISC,
+	.of_match = sifive_otp_ids,
+	.ofdata_to_platdata = sifive_otp_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct sifive_otp_platdata),
+	.ops = &sifive_otp_ops,
+};
#6 lore raw

PATCH v4 2/14 riscv: sifive: fu540: Use OTP DM driver for serial environment variable

In reply to Pragnesh Patel

Use the OTP DM driver to set the serial environment variable.

---
 arch/riscv/dts/fu540-c000-u-boot.dtsi         |  14 +++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      |   6 +
 board/sifive/fu540/Kconfig                    |   2 +
 board/sifive/fu540/fu540.c                    | 113 +++++++-----------
 4 files changed, 62 insertions(+), 73 deletions(-)
 create mode 100644 arch/riscv/dts/fu540-c000-u-boot.dtsi
 create mode 100644 arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
arch/riscv/dts/fu540-c000-u-boot.dtsi new file +14 -0
new file mode 100644
index 0000000000..31fd113c7d
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019 SiFive, Inc
+ */
+
+/ {
+	soc {
+		otp: otp at 10070000 {
+			compatible = "sifive,fu540-otp";
+			reg = <0x0 0x10070000 0x0 0x0FFF>;
+			fuse-count = <0x1000>;
+		};
+	};
+};
arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi new file +6 -0
new file mode 100644
index 0000000000..bec0d19134
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 SiFive, Inc
+ */
+
+#include "fu540-c000-u-boot.dtsi"
board/sifive/fu540/Kconfig +2 -0
index 5ca21474de..900197bbb2 100644
@@ -48,5 +48,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply SIFIVE_GPIO
 	imply CMD_GPIO
 	imply SMP
+	imply MISC
+	imply SIFIVE_OTP
 
 endif
board/sifive/fu540/fu540.c +40 -73

134 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH v4 2/14 riscv: sifive: fu540: Use OTP DM driver for serial environment variable

Hi,

Just a warning as I had the same issue with 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

Quoted 151 lines

From: U-Boot <[email protected]> On Behalf Of Pragnesh Patel
Sent: lundi 24 f?vrier 2020 09:33

Use the OTP DM driver to set the serial environment variable.

---
 arch/riscv/dts/fu540-c000-u-boot.dtsi         |  14 +++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      |   6 +
 board/sifive/fu540/Kconfig                    |   2 +
 board/sifive/fu540/fu540.c                    | 113 +++++++-----------
 4 files changed, 62 insertions(+), 73 deletions(-)  create mode 100644
arch/riscv/dts/fu540-c000-u-boot.dtsi
 create mode 100644 arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
arch/riscv/dts/fu540-c000-u- renamed from arch/riscv/dts/fu540-c000-u-boot.dtsi +0 -0

boot.dtsi
new file mode 100644
index 0000000000..31fd113c7d

arch/riscv/dts/fu540-c000-u-boot.dtsi new file +14 -0
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019 SiFive, Inc
+ */
+
+/ {
+	soc {
+		otp: otp at 10070000 {
+			compatible = "sifive,fu540-otp";
+			reg = <0x0 0x10070000 0x0 0x0FFF>;
+			fuse-count = <0x1000>;
+		};
+	};
+};
arch/riscv/dts/hifive- renamed from arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi +0 -0

unleashed-a00-u-boot.dtsi
new file mode 100644
index 0000000000..bec0d19134

arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi new file +6 -0
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 SiFive, Inc
+ */
+
+#include "fu540-c000-u-boot.dtsi"
board/sifive/fu540/Kconfig index renamed from board/sifive/fu540/Kconfig +0 -0

5ca21474de..900197bbb2 100644

board/sifive/fu540/Kconfig +2 -0
@@ -48,5 +48,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply SIFIVE_GPIO
 	imply CMD_GPIO
 	imply SMP
+	imply MISC
+	imply SIFIVE_OTP
 
 endif
board/sifive/fu540/fu540.c index renamed from board/sifive/fu540/fu540.c +0 -0

47a2090251..409471effc 100644

board/sifive/fu540/fu540.c +9 -69
@@ -10,94 +10,61 @@
 #include <dm.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <misc.h>
 
-#ifdef CONFIG_MISC_INIT_R
-
-#define FU540_OTP_BASE_ADDR			0x10070000
-
-struct fu540_otp_regs {
-	u32 pa;     /* Address input */
-	u32 paio;   /* Program address input */
-	u32 pas;    /* Program redundancy cell selection input */
-	u32 pce;    /* OTP Macro enable input */
-	u32 pclk;   /* Clock input */
-	u32 pdin;   /* Write data input */
-	u32 pdout;  /* Read data output */
-	u32 pdstb;  /* Deep standby mode enable input (active low) */
-	u32 pprog;  /* Program mode enable input */
-	u32 ptc;    /* Test column enable input */
-	u32 ptm;    /* Test mode enable input */
-	u32 ptm_rep;/* Repair function test mode enable input */
-	u32 ptr;    /* Test row enable input */
-	u32 ptrim;  /* Repair function enable input */
-	u32 pwe;    /* Write enable input (defines program cycle) */
-} __packed;
-
-#define BYTES_PER_FUSE				4
-#define NUM_FUSES				0x1000
-
-static int fu540_otp_read(int offset, void *buf, int size) -{
-	struct fu540_otp_regs *regs = (void __iomem
 *)FU540_OTP_BASE_ADDR;
-	unsigned int i;
-	int fuseidx = offset / BYTES_PER_FUSE;
-	int fusecount = size / BYTES_PER_FUSE;
-	u32 fusebuf[fusecount];
-
-	/* check bounds */
-	if (offset < 0 || size < 0)
-		return -EINVAL;
-	if (fuseidx >= NUM_FUSES)
-		return -EINVAL;
-	if ((fuseidx + fusecount) > NUM_FUSES)
-		return -EINVAL;
-
-	/* init OTP */
-	writel(0x01, &regs->pdstb); /* wake up from stand-by */
-	writel(0x01, &regs->ptrim); /* enable repair function */
-	writel(0x01, &regs->pce);   /* enable input */
-
-	/* read all requested fuses */
-	for (i = 0; i < fusecount; i++, fuseidx++) {
-		writel(fuseidx, &regs->pa);
-
-		/* cycle clock to read */
-		writel(0x01, &regs->pclk);
-		mdelay(1);
-		writel(0x00, &regs->pclk);
-		mdelay(1);
-
-		/* read the value */
-		fusebuf[i] = readl(&regs->pdout);
-	}
-
-	/* shut down */
-	writel(0, &regs->pce);
-	writel(0, &regs->ptrim);
-	writel(0, &regs->pdstb);
-
-	/* copy out */
-	memcpy(buf, fusebuf, size);
+/*
+ * This define is a value used for error/unknown serial.
+ * If we really care about distinguishing errors and 0 is
+ * valid, we'll need a different one.
+ */
+#define ERROR_READING_SERIAL_NUMBER       0
 
-	return 0;
-}
+#ifdef CONFIG_MISC_INIT_R
 
-static u32 fu540_read_serialnum(void)
+#if CONFIG_IS_ENABLED(SIFIVE_OTP)

board/sifive/fu540/fu540.c line 34

Quoted 10 lines
board/sifive/fu540/fu540.c +3 -1
+static u32 otp_read_serialnum(struct udevice *dev)
 {
 	int ret;
 	u32 serial[2] = {0};
 
 	for (int i = 0xfe * 4; i > 0; i -= 8) {
-		ret = fu540_otp_read(i, serial, sizeof(serial));
+		ret = misc_read(dev, i, serial, sizeof(serial));
+
 		if (ret) {

Warning here, misc_read returns now the size of the data (sizeof(serial)), since commit 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

So I think the test need to change to

if (ret < 0)

or

if (ret != sizeof(serial))

Quoted 40 lines
board/sifive/fu540/fu540.c +28 -3
-			printf("%s: error reading from OTP\n", __func__);
+			printf("%s: error reading serial from OTP\n", __func__);
 			break;
 		}
+
 		if (serial[0] == ~serial[1])
 			return serial[0];
 	}
 
-	return 0;
+	return ERROR_READING_SERIAL_NUMBER;
+}
+#endif
+
+static u32 fu540_read_serialnum(void)
+{
+	u32 serial = ERROR_READING_SERIAL_NUMBER;
+
+#if CONFIG_IS_ENABLED(SIFIVE_OTP)
+	struct udevice *dev;
+	int ret;
+
+	// init OTP
+	ret = uclass_get_device_by_driver(UCLASS_MISC,
+					  DM_GET_DRIVER(sifive_otp), &dev);
+
+	if (ret) {
+		debug("%s: could not find otp device\n", __func__);
+		return serial;
+	}
+
+	// read serial from OTP and set env var
+	serial = otp_read_serialnum(dev);
+#endif
+
+	return serial;
 }
 
 static void fu540_setup_macaddr(u32 serialnum)
--
Quoted 1 line

2.17.1

Patrick

#8 lore raw

PATCH v4 2/14 riscv: sifive: fu540: Use OTP DM driver for serial environment variable

Hi Patrick,

Quoted 183 lines

-----Original Message-----
From: Patrick DELAUNAY <[email protected]>
Sent: 24 February 2020 23:30
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;
bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; jagan at amarulasolutions.com; Troy Benjegerdes ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; Rick Chen <[email protected]>
Subject: RE: [PATCH v4 02/14] riscv: sifive: fu540: Use OTP DM driver for serial environment variable

Hi,

Just a warning as I had the same issue with 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

Quoted 151 lines

From: U-Boot <[email protected]> On Behalf Of Pragnesh Patel
Sent: lundi 24 f?vrier 2020 09:33

Use the OTP DM driver to set the serial environment variable.

---
 arch/riscv/dts/fu540-c000-u-boot.dtsi         |  14 +++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      |   6 +
 board/sifive/fu540/Kconfig                    |   2 +
 board/sifive/fu540/fu540.c                    | 113 +++++++-----------
 4 files changed, 62 insertions(+), 73 deletions(-)  create mode
100644 arch/riscv/dts/fu540-c000-u-boot.dtsi
 create mode 100644 arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
(quoted diff) +0 -0

b/arch/riscv/dts/fu540-c000-u- boot.dtsi new file mode 100644 index 0000000000..31fd113c7d

arch/riscv/dts/fu540-c000-u-boot.dtsi new file +14 -0
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019 SiFive, Inc
+ */
+
+/ {
+	soc {
+		otp: otp at 10070000 {
+			compatible = "sifive,fu540-otp";
+			reg = <0x0 0x10070000 0x0 0x0FFF>;
+			fuse-count = <0x1000>;
+		};
+	};
+};
(quoted diff) +0 -0

b/arch/riscv/dts/hifive- unleashed-a00-u-boot.dtsi new file mode 100644 index 0000000000..bec0d19134

arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi new file +6 -0
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 SiFive, Inc
+ */
+
+#include "fu540-c000-u-boot.dtsi"
board/sifive/fu540/Kconfig +0 -0

index
5ca21474de..900197bbb2 100644

board/sifive/fu540/Kconfig +2 -0
@@ -48,5 +48,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply SIFIVE_GPIO
 	imply CMD_GPIO
 	imply SMP
+	imply MISC
+	imply SIFIVE_OTP
 
 endif
board/sifive/fu540/fu540.c +9 -69
index 47a2090251..409471effc 100644
@@ -10,94 +10,61 @@
 #include <dm.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <misc.h>
 
-#ifdef CONFIG_MISC_INIT_R
-
-#define FU540_OTP_BASE_ADDR			0x10070000
-
-struct fu540_otp_regs {
-	u32 pa;     /* Address input */
-	u32 paio;   /* Program address input */
-	u32 pas;    /* Program redundancy cell selection input */
-	u32 pce;    /* OTP Macro enable input */
-	u32 pclk;   /* Clock input */
-	u32 pdin;   /* Write data input */
-	u32 pdout;  /* Read data output */
-	u32 pdstb;  /* Deep standby mode enable input (active low) */
-	u32 pprog;  /* Program mode enable input */
-	u32 ptc;    /* Test column enable input */
-	u32 ptm;    /* Test mode enable input */
-	u32 ptm_rep;/* Repair function test mode enable input */
-	u32 ptr;    /* Test row enable input */
-	u32 ptrim;  /* Repair function enable input */
-	u32 pwe;    /* Write enable input (defines program cycle) */
-} __packed;
-
-#define BYTES_PER_FUSE				4
-#define NUM_FUSES				0x1000
-
-static int fu540_otp_read(int offset, void *buf, int size) -{
-	struct fu540_otp_regs *regs = (void __iomem
 *)FU540_OTP_BASE_ADDR;
-	unsigned int i;
-	int fuseidx = offset / BYTES_PER_FUSE;
-	int fusecount = size / BYTES_PER_FUSE;
-	u32 fusebuf[fusecount];
-
-	/* check bounds */
-	if (offset < 0 || size < 0)
-		return -EINVAL;
-	if (fuseidx >= NUM_FUSES)
-		return -EINVAL;
-	if ((fuseidx + fusecount) > NUM_FUSES)
-		return -EINVAL;
-
-	/* init OTP */
-	writel(0x01, &regs->pdstb); /* wake up from stand-by */
-	writel(0x01, &regs->ptrim); /* enable repair function */
-	writel(0x01, &regs->pce);   /* enable input */
-
-	/* read all requested fuses */
-	for (i = 0; i < fusecount; i++, fuseidx++) {
-		writel(fuseidx, &regs->pa);
-
-		/* cycle clock to read */
-		writel(0x01, &regs->pclk);
-		mdelay(1);
-		writel(0x00, &regs->pclk);
-		mdelay(1);
-
-		/* read the value */
-		fusebuf[i] = readl(&regs->pdout);
-	}
-
-	/* shut down */
-	writel(0, &regs->pce);
-	writel(0, &regs->ptrim);
-	writel(0, &regs->pdstb);
-
-	/* copy out */
-	memcpy(buf, fusebuf, size);
+/*
+ * This define is a value used for error/unknown serial.
+ * If we really care about distinguishing errors and 0 is
+ * valid, we'll need a different one.
+ */
+#define ERROR_READING_SERIAL_NUMBER       0
 
-	return 0;
-}
+#ifdef CONFIG_MISC_INIT_R
 
-static u32 fu540_read_serialnum(void)
+#if CONFIG_IS_ENABLED(SIFIVE_OTP)

board/sifive/fu540/fu540.c line 34

Quoted 10 lines
board/sifive/fu540/fu540.c +3 -1
+static u32 otp_read_serialnum(struct udevice *dev)
 {
 	int ret;
 	u32 serial[2] = {0};
 
 	for (int i = 0xfe * 4; i > 0; i -= 8) {
-		ret = fu540_otp_read(i, serial, sizeof(serial));
+		ret = misc_read(dev, i, serial, sizeof(serial));
+
 		if (ret) {

Warning here, misc_read returns now the size of the data (sizeof(serial)), since commit 8729b1ae2cbd ("misc: Update read() and write() methods to return bytes xfered")

Quoted 8 lines

So I think the test need to change to

if (ret < 0)

or

if (ret != sizeof(serial))

Yes, you are right. Will update in v5. Thanks for the review.

Quoted 43 lines

board/sifive/fu540/fu540.c line 35

Quoted 2 lines
board/sifive/fu540/fu540.c +1 -1
-			printf("%s: error reading from OTP\n", __func__);
+			printf("%s: error reading serial from OTP\n",

__func__);

Quoted 37 lines
board/sifive/fu540/fu540.c +26 -2
 			break;
 		}
+
 		if (serial[0] == ~serial[1])
 			return serial[0];
 	}
 
-	return 0;
+	return ERROR_READING_SERIAL_NUMBER;
+}
+#endif
+
+static u32 fu540_read_serialnum(void) {
+	u32 serial = ERROR_READING_SERIAL_NUMBER;
+
+#if CONFIG_IS_ENABLED(SIFIVE_OTP)
+	struct udevice *dev;
+	int ret;
+
+	// init OTP
+	ret = uclass_get_device_by_driver(UCLASS_MISC,
+					  DM_GET_DRIVER(sifive_otp), &dev);
+
+	if (ret) {
+		debug("%s: could not find otp device\n", __func__);
+		return serial;
+	}
+
+	// read serial from OTP and set env var
+	serial = otp_read_serialnum(dev);
+#endif
+
+	return serial;
 }
 
 static void fu540_setup_macaddr(u32 serialnum)
--
Quoted 1 line

2.17.1

Patrick

#9 lore raw

PATCH v4 3/14 riscv: Add _image_binary_end for SPL

In reply to Pragnesh Patel

For SPL_SEPARATE_BSS, Device tree will be put at _image_binary_end

---
 arch/riscv/cpu/u-boot-spl.lds | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/cpu/u-boot-spl.lds +1 -0
index 955dd3106d..d0495ce248 100644
@@ -72,6 +72,7 @@ SECTIONS
 	. = ALIGN(4);
 
 	_end = .;
+	_image_binary_end = .;
 
 	.bss : {
 		__bss_start = .;
Signature · 1 line
2.17.1
#10 lore raw

PATCH v4 4/14 lib: Makefile: build crc7.c when CONFIG_MMC_SPI

In reply to Pragnesh Patel

When build U-boot SPL, meet an issue of undefined reference to 'crc7' for drivers/mmc/mmc_spi.c, so let's compile crc7.c when CONFIG_MMC_SPI selected.

---
 common/spl/Kconfig | 7 +++++++
 lib/Makefile       | 1 +
 2 files changed, 8 insertions(+)
common/spl/Kconfig +7 -0
index b03a476b9f..f93f552f5e 100644
@@ -401,6 +401,13 @@ config SPL_CRC32_SUPPORT
 	  for detected accidental image corruption. For secure applications you
 	  should consider SHA1 or SHA256.
 
+config SPL_CRC7_SUPPORT
+	bool "Support CRC7"
+	default y if MMC_SPI
+	help
+	  Enable CRC7 hashing for drivers which are using in SPL.
+	  This is a 32-bit checksum value that can be used to verify images.
+
 config SPL_MD5_SUPPORT
 	bool "Support MD5"
 	depends on SPL_FIT
lib/Makefile +1 -0
index 15259d0473..7a50aa56ef 100644
@@ -78,6 +78,7 @@ endif
 
 ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o
+obj-$(CONFIG_SPL_CRC7_SUPPORT) += crc7.o
 obj-$(CONFIG_$(SPL_TPL_)HASH_SUPPORT) += crc16.o
 obj-y += net_utils.o
 endif
Signature · 1 line
2.17.1
#11 lore raw

PATCH v4 5/14 riscv: sifive: dts: fu540: Add board -u-boot.dtsi files

In reply to Pragnesh Patel

Devicetree files in FU540 platform is synced from Linux, like other platforms does. Apart from these u-boot in FU540 would also require some u-boot specific node like clint.

So, create board specific -u-boot.dtsi files. This would help of maintain u-boot specific changes separately without touching Linux dts(i) files which indeed easy for syncing from Linux between releases.

---
 arch/riscv/dts/fu540-c000-u-boot.dtsi         | 42 +++++++++++++++++++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      | 16 +++++++
 2 files changed, 58 insertions(+)
arch/riscv/dts/fu540-c000-u-boot.dtsi +42 -0
index 31fd113c7d..2d3d62801f 100644
@@ -4,11 +4,53 @@
  */
 
 / {
+	cpus {
+		u-boot,dm-spl;
+		cpu0: cpu at 0 {
+			u-boot,dm-spl;
+			status = "okay";
+			cpu0_intc: interrupt-controller {
+				u-boot,dm-spl;
+			};
+		};
+		cpu1: cpu at 1 {
+			u-boot,dm-spl;
+		};
+		cpu2: cpu at 2 {
+			u-boot,dm-spl;
+		};
+		cpu3: cpu at 3 {
+			u-boot,dm-spl;
+		};
+		cpu4: cpu at 4 {
+			u-boot,dm-spl;
+		};
+	};
+
 	soc {
+		u-boot,dm-spl;
 		otp: otp at 10070000 {
 			compatible = "sifive,fu540-otp";
 			reg = <0x0 0x10070000 0x0 0x0FFF>;
 			fuse-count = <0x1000>;
 		};
+		clint at 2000000 {
+			compatible = "riscv,clint0";
+			interrupts-extended = <&cpu0_intc 3 &cpu0_intc 7 >;
+			reg = <0x0 0x2000000 0x0 0xc0000>;
+			u-boot,dm-spl;
+		};
 	};
 };
+
+&prci {
+	u-boot,dm-spl;
+};
+
+&uart0 {
+	u-boot,dm-spl;
+};
+
+&qspi2 {
+	u-boot,dm-spl;
+};
arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi +16 -0
index bec0d19134..cce1bd943e 100644
@@ -4,3 +4,19 @@
  */
 
 #include "fu540-c000-u-boot.dtsi"
+
+/ {
+	hfclk {
+		u-boot,dm-spl;
+	};
+
+	rtcclk {
+		u-boot,dm-spl;
+	};
+};
+
+&qspi2 {
+	mmc at 0 {
+		u-boot,dm-spl;
+	};
+};
Signature · 1 line
2.17.1
#12 lore raw

PATCH v4 6/14 sifive: fu540: add ddr driver

In reply to Pragnesh Patel

Add driver for fu540 to support ddr initialization in SPL. This driver is based on FSBL
(https://github.com/sifive/freedom-u540-c000-bootloader.git)

---
 drivers/ram/Kconfig              |   7 +
 drivers/ram/Makefile             |   2 +
 drivers/ram/sifive/Kconfig       |   8 +
 drivers/ram/sifive/Makefile      |   6 +
 drivers/ram/sifive/sdram_fu540.c | 295 +++++++++++++++++++++++++++++++
 drivers/ram/sifive/sdram_fu540.h |  94 ++++++++++
 6 files changed, 412 insertions(+)
 create mode 100644 drivers/ram/sifive/Kconfig
 create mode 100644 drivers/ram/sifive/Makefile
 create mode 100644 drivers/ram/sifive/sdram_fu540.c
 create mode 100644 drivers/ram/sifive/sdram_fu540.h
drivers/ram/Kconfig +7 -0
index 56fea7c94c..c60c63204c 100644
@@ -73,5 +73,12 @@ config IMXRT_SDRAM
 	  to support external memories like sdram, psram & nand.
 	  This driver is for the sdram memory interface with the SEMC.
 
+config SIFIVE_DDR
+	bool "Enable SiFive DDR support"
+	depends on RAM
+	help
+	  Enable support for the internal DDR Memory Controller of SiFive SoCs.
+
 source "drivers/ram/rockchip/Kconfig"
 source "drivers/ram/stm32mp1/Kconfig"
+source "drivers/ram/sifive/Kconfig"
drivers/ram/Makefile +2 -0
index 5c897410c6..12bf61510b 100644
@@ -17,3 +17,5 @@ obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
 obj-$(CONFIG_K3_J721E_DDRSS) += k3-j721e/
 
 obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o
+
+obj-$(CONFIG_SIFIVE_DDR) += sifive/
drivers/ram/sifive/Kconfig new file +8 -0
new file mode 100644
index 0000000000..b754700db8
@@ -0,0 +1,8 @@
+config SIFIVE_FU540_DDR
+	bool "SiFive FU540 DDR driver"
+	depends on DM && OF_CONTROL
+	select RAM
+	select SPL_RAM if SPL
+	select SIFIVE_DDR
+	help
+	  This enables DDR support for the platforms based on SiFive FU540 SoC.
drivers/ram/sifive/Makefile new file +6 -0
new file mode 100644
index 0000000000..0187805199
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2020 SiFive, Inc
+#
+
+obj-$(CONFIG_SIFIVE_FU540_DDR) += sdram_fu540.o
drivers/ram/sifive/sdram_fu540.c new file +295 -0

295 lines not on this page · raw message

drivers/ram/sifive/sdram_fu540.h new file +94 -0

94 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

PATCH v4 7/14 sifive: dts: fu540: Add DDR controller and phy register settings

In reply to Pragnesh Patel

Add DDR controller and phy register settings, taken from fsbl
(https://github.com/sifive/freedom-u540-c000-bootloader.git)

---
 arch/riscv/dts/fu540-c000-u-boot.dtsi         |    7 +
 arch/riscv/dts/fu540-sdram-lpddr4.dtsi        | 1489 +++++++++++++++++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      |    1 +
 3 files changed, 1497 insertions(+)
 create mode 100644 arch/riscv/dts/fu540-sdram-lpddr4.dtsi
arch/riscv/dts/fu540-c000-u-boot.dtsi +7 -0
index 2d3d62801f..b8cef67885 100644
@@ -40,6 +40,13 @@
 			reg = <0x0 0x2000000 0x0 0xc0000>;
 			u-boot,dm-spl;
 		};
+		dmc: dmc at 100b0000 {
+			compatible = "sifive,fu540-ddr";
+			reg = <0x0 0x100b0000 0x0 0x0800
+			       0x0 0x100b2000 0x0 0x2000
+			       0x0 0x100b8000 0x0 0x0fff>;
+			u-boot,dm-spl;
+		};
 	};
 };
 
arch/riscv/dts/fu540-sdram-lpddr4.dtsi new file +1489 -0

1,489 lines not on this page · raw message

arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi +1 -0
index cce1bd943e..204177e3d3 100644
@@ -4,6 +4,7 @@
  */
 
 #include "fu540-c000-u-boot.dtsi"
+#include "fu540-sdram-lpddr4.dtsi"
 
 / {
 	hfclk {
Signature · 1 line
2.17.1
#14 lore raw

PATCH v4 8/14 clk: sifive: fu540-prci: Add clock enable and disable ops

In reply to Pragnesh Patel

Added clock enable and disable functions in prci ops

---
 drivers/clk/sifive/fu540-prci.c | 75 +++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 3 deletions(-)
drivers/clk/sifive/fu540-prci.c +72 -3
index 8847178001..c02c0466a8 100644
@@ -68,6 +68,11 @@
 #define PRCI_COREPLLCFG0_LOCK_SHIFT	31
 #define PRCI_COREPLLCFG0_LOCK_MASK	(0x1 << PRCI_COREPLLCFG0_LOCK_SHIFT)
 
+/* COREPLLCFG1 */
+#define PRCI_COREPLLCFG1_OFFSET		0x8
+#define PRCI_COREPLLCFG1_CKE_SHIFT	31
+#define PRCI_COREPLLCFG1_CKE_MASK	(0x1 << PRCI_COREPLLCFG1_CKE_SHIFT)
+
 /* DDRPLLCFG0 */
 #define PRCI_DDRPLLCFG0_OFFSET		0xc
 #define PRCI_DDRPLLCFG0_DIVR_SHIFT	0
@@ -87,7 +92,7 @@
 
 /* DDRPLLCFG1 */
 #define PRCI_DDRPLLCFG1_OFFSET		0x10
-#define PRCI_DDRPLLCFG1_CKE_SHIFT	24
+#define PRCI_DDRPLLCFG1_CKE_SHIFT	31
 #define PRCI_DDRPLLCFG1_CKE_MASK	(0x1 << PRCI_DDRPLLCFG1_CKE_SHIFT)
 
 /* GEMGXLPLLCFG0 */
@@ -114,7 +119,7 @@
 
 /* GEMGXLPLLCFG1 */
 #define PRCI_GEMGXLPLLCFG1_OFFSET	0x20
-#define PRCI_GEMGXLPLLCFG1_CKE_SHIFT	24
+#define PRCI_GEMGXLPLLCFG1_CKE_SHIFT	31
 #define PRCI_GEMGXLPLLCFG1_CKE_MASK	(0x1 << PRCI_GEMGXLPLLCFG1_CKE_SHIFT)
 
 /* CORECLKSEL */
@@ -142,7 +147,7 @@
 			(0x1 << PRCI_DEVICESRESETREG_GEMGXL_RST_N_SHIFT)
 
 /* CLKMUXSTATUSREG */
-#define PRCI_CLKMUXSTATUSREG_OFFSET		0x2c
+#define PRCI_CLKMUXSTATUSREG_OFFSET	0x2c
 #define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT 1
 #define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK \
 			(0x1 << PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT)
@@ -170,6 +175,7 @@ struct __prci_data {
  * @enable_bypass: fn ptr to code to bypass the WRPLL (if applicable; else NULL)
  * @disable_bypass: fn ptr to code to not bypass the WRPLL (or NULL)
  * @cfg0_offs: WRPLL CFG0 register offset (in bytes) from the PRCI base address
+ * @cfg1_offs: WRPLL CFG1 register offset (in bytes) from the PRCI base address
  *
  * @enable_bypass and @disable_bypass are used for WRPLL instances
  * that contain a separate external glitchless clock mux downstream
@@ -180,6 +186,7 @@ struct __prci_wrpll_data {
 	void (*enable_bypass)(struct __prci_data *pd);
 	void (*disable_bypass)(struct __prci_data *pd);
 	u8 cfg0_offs;
+	u8 cfg1_offs;
 };
 
 struct __prci_clock;
@@ -194,6 +201,7 @@ struct __prci_clock_ops {
 				    unsigned long *parent_rate);
 	unsigned long (*recalc_rate)(struct __prci_clock *pc,
 				     unsigned long parent_rate);
+	int (*enable_clk)(struct __prci_clock *pc, bool enable);
 };
 
 /**
@@ -356,6 +364,13 @@ static void __prci_wrpll_write_cfg(struct __prci_data *pd,
 	memcpy(&pwd->c, c, sizeof(*c));
 }
 
+static void __prci_wrpll_write_cfg1(struct __prci_data *pd,
+				    struct __prci_wrpll_data *pwd,
+				    u32 enable)
+{
+	__prci_writel(enable, pwd->cfg1_offs, pd);
+}
+
 /* Core clock mux control */
 
 /**
@@ -447,14 +462,35 @@ static int sifive_fu540_prci_wrpll_set_rate(struct __prci_clock *pc,
 	return 0;
 }
 
+static int sifive_fu540_prci_clock_enable(struct __prci_clock *pc, bool enable)
+{
+	struct __prci_wrpll_data *pwd = pc->pwd;
+	struct __prci_data *pd = pc->pd;
+
+	if (enable) {
+		__prci_wrpll_write_cfg1(pd, pwd, PRCI_COREPLLCFG1_CKE_MASK);
+	} else {
+		u32 r;
+
+		r = __prci_readl(pd, pwd->cfg1_offs);
+		r &= ~PRCI_COREPLLCFG1_CKE_MASK;
+
+		__prci_wrpll_write_cfg1(pd, pwd, r);
+	}
+
+	return 0;
+}
+
 static const struct __prci_clock_ops sifive_fu540_prci_wrpll_clk_ops = {
 	.set_rate = sifive_fu540_prci_wrpll_set_rate,
 	.round_rate = sifive_fu540_prci_wrpll_round_rate,
 	.recalc_rate = sifive_fu540_prci_wrpll_recalc_rate,
+	.enable_clk = sifive_fu540_prci_clock_enable,
 };
 
 static const struct __prci_clock_ops sifive_fu540_prci_wrpll_ro_clk_ops = {
 	.recalc_rate = sifive_fu540_prci_wrpll_recalc_rate,
+	.enable_clk = sifive_fu540_prci_clock_enable,
 };
 
 /* TLCLKSEL clock integration */
@@ -484,16 +520,19 @@ static const struct __prci_clock_ops sifive_fu540_prci_tlclksel_clk_ops = {
 
 static struct __prci_wrpll_data __prci_corepll_data = {
 	.cfg0_offs = PRCI_COREPLLCFG0_OFFSET,
+	.cfg1_offs = PRCI_COREPLLCFG1_OFFSET,
 	.enable_bypass = __prci_coreclksel_use_hfclk,
 	.disable_bypass = __prci_coreclksel_use_corepll,
 };
 
 static struct __prci_wrpll_data __prci_ddrpll_data = {
 	.cfg0_offs = PRCI_DDRPLLCFG0_OFFSET,
+	.cfg1_offs = PRCI_DDRPLLCFG1_OFFSET,
 };
 
 static struct __prci_wrpll_data __prci_gemgxlpll_data = {
 	.cfg0_offs = PRCI_GEMGXLPLLCFG0_OFFSET,
+	.cfg1_offs = PRCI_GEMGXLPLLCFG1_OFFSET,
 };
 
 /*
@@ -580,6 +619,34 @@ static ulong sifive_fu540_prci_set_rate(struct clk *clk, ulong rate)
 	return rate;
 }
 
+static int sifive_fu540_prci_enable(struct clk *clk)
+{
+	struct __prci_clock *pc;
+
+	if (ARRAY_SIZE(__prci_init_clocks) <= clk->id)
+		return -ENXIO;
+
+	pc = &__prci_init_clocks[clk->id];
+	if (!pc->pd || !pc->ops->enable_clk)
+		return -ENXIO;
+
+	return pc->ops->enable_clk(pc, 1);
+}
+
+static int sifive_fu540_prci_disable(struct clk *clk)
+{
+	struct __prci_clock *pc;
+
+	if (ARRAY_SIZE(__prci_init_clocks) <= clk->id)
+		return -ENXIO;
+
+	pc = &__prci_init_clocks[clk->id];
+	if (!pc->pd || !pc->ops->enable_clk)
+		return -ENXIO;
+
+	return pc->ops->enable_clk(pc, 0);
+}
+
 static int sifive_fu540_prci_probe(struct udevice *dev)
 {
 	int i, err;
@@ -611,6 +678,8 @@ static int sifive_fu540_prci_probe(struct udevice *dev)
 static struct clk_ops sifive_fu540_prci_ops = {
 	.set_rate = sifive_fu540_prci_set_rate,
 	.get_rate = sifive_fu540_prci_get_rate,
+	.enable = sifive_fu540_prci_enable,
+	.disable = sifive_fu540_prci_disable,
 };
 
 static const struct udevice_id sifive_fu540_prci_ids[] = {
Signature · 1 line
2.17.1
#15 lore raw

PATCH v4 9/14 clk: sifive: fu540-prci: Add clock initialization for SPL

In reply to Pragnesh Patel

Set corepll, ddrpll and ethernet PLL for u-boot-spl

---
 drivers/clk/sifive/fu540-prci.c | 94 +++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
drivers/clk/sifive/fu540-prci.c +94 -0
index c02c0466a8..f043b0eccb 100644
@@ -41,6 +41,10 @@
 #include <linux/clk/analogbits-wrpll-cln28hpc.h>
 #include <dt-bindings/clock/sifive-fu540-prci.h>
 
+#define DDRCTLPLL_F	55
+#define DDRCTLPLL_Q	2
+#define MHz		1000000
+
 /*
  * EXPECTED_CLK_PARENT_COUNT: how many parent clocks this driver expects:
  *     hfclk and rtcclk
@@ -152,6 +156,27 @@
 #define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK \
 			(0x1 << PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT)
 
+/* PROCMONCFG */
+#define PRCI_PROCMONCFG_OFFSET			0xF0
+#define PRCI_PROCMONCFG_CORE_CLOCK_SHIFT	24
+#define PRCI_PROCMONCFG_CORE_CLOCK_MASK \
+			(0x1 << PRCI_PROCMONCFG_CORE_CLOCK_SHIFT)
+
+#define PLL_R(x) \
+	((x) << PRCI_DDRPLLCFG0_DIVR_SHIFT) & PRCI_DDRPLLCFG0_DIVR_MASK
+#define PLL_F(x) \
+	((x) << PRCI_DDRPLLCFG0_DIVF_SHIFT) & PRCI_DDRPLLCFG0_DIVF_MASK
+#define PLL_Q(x) \
+	((x) << PRCI_DDRPLLCFG0_DIVQ_SHIFT) & PRCI_DDRPLLCFG0_DIVQ_MASK
+#define PLL_RANGE(x) \
+	((x) << PRCI_DDRPLLCFG0_RANGE_SHIFT) & PRCI_DDRPLLCFG0_RANGE_MASK
+#define PLL_BYPASS(x) \
+	((x) << PRCI_DDRPLLCFG0_BYPASS_SHIFT) & PRCI_DDRPLLCFG0_BYPASS_MASK
+#define PLL_FSE(x) \
+	((x) << PRCI_DDRPLLCFG0_FSE_SHIFT) & PRCI_DDRPLLCFG0_FSE_MASK
+#define PLL_LOCK(x) \
+	((x) << PRCI_DDRPLLCFG0_LOCK_SHIFT) & PRCI_DDRPLLCFG0_LOCK_MASK
+
 /*
  * Private structures
  */
@@ -672,6 +697,75 @@ static int sifive_fu540_prci_probe(struct udevice *dev)
 			__prci_wrpll_read_cfg(pd, pc->pwd);
 	}
 
+#ifdef CONFIG_SPL_BUILD
+	u32 v;
+	struct clk clock;
+
+	v = __prci_readl(pd, PRCI_CLKMUXSTATUSREG_OFFSET);
+	v &= PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK;
+
+	clock.id = PRCI_CLK_COREPLL;
+
+	if (v) {
+		/* corepll 500 Mhz */
+		sifive_fu540_prci_set_rate(&clock, 500UL * MHz);
+	} else {
+		/* corepll 1 Ghz */
+		sifive_fu540_prci_set_rate(&clock, 1000UL * MHz);
+	}
+
+	sifive_fu540_prci_clock_enable(&__prci_init_clocks[clock.id], 1);
+
+	//DDR init
+	u32 ddrctlmhz =
+		(PLL_R(0)) |
+		(PLL_F(DDRCTLPLL_F)) |
+		(PLL_Q(DDRCTLPLL_Q)) |
+		(PLL_RANGE(0x4)) |
+		(PLL_BYPASS(0)) |
+		(PLL_FSE(1));
+	__prci_writel(ddrctlmhz, PRCI_DDRPLLCFG0_OFFSET, pd);
+
+	clock.id = PRCI_CLK_DDRPLL;
+	sifive_fu540_prci_clock_enable(&__prci_init_clocks[clock.id], 1);
+
+	/* Release DDR reset */
+	v = __prci_readl(pd, PRCI_DEVICESRESETREG_OFFSET);
+	v |= PRCI_DEVICESRESETREG_DDR_CTRL_RST_N_MASK;
+	__prci_writel(v, PRCI_DEVICESRESETREG_OFFSET, pd);
+
+	// HACK to get the '1 full controller clock cycle'.
+	asm volatile ("fence");
+	v = __prci_readl(pd, PRCI_DEVICESRESETREG_OFFSET);
+	v |= (PRCI_DEVICESRESETREG_DDR_AXI_RST_N_MASK |
+	      PRCI_DEVICESRESETREG_DDR_AHB_RST_N_MASK |
+	      PRCI_DEVICESRESETREG_DDR_PHY_RST_N_MASK);
+	__prci_writel(v, PRCI_DEVICESRESETREG_OFFSET, pd);
+	// HACK to get the '1 full controller clock cycle'.
+	asm volatile ("fence");
+
+	/* These take like 16 cycles to actually propagate. We can't go sending
+	 * stuff before they come out of reset. So wait. (TODO: Add a register
+	 * to read the current reset states, or DDR Control device?)
+	 */
+	for (int i = 0; i < 256; i++)
+		asm volatile ("nop");
+
+	/* GEMGXL init */
+	clock.id = PRCI_CLK_GEMGXLPLL;
+	sifive_fu540_prci_set_rate(&clock, 125UL * MHz);
+	sifive_fu540_prci_clock_enable(&__prci_init_clocks[clock.id], 1);
+
+	/* Release GEMGXL reset */
+	v = __prci_readl(pd, PRCI_DEVICESRESETREG_OFFSET);
+	v |= PRCI_DEVICESRESETREG_GEMGXL_RST_N_MASK;
+	__prci_writel(v, PRCI_DEVICESRESETREG_OFFSET, pd);
+
+	/* Procmon => core clock */
+	__prci_writel(PRCI_PROCMONCFG_CORE_CLOCK_MASK, PRCI_PROCMONCFG_OFFSET,
+		      pd);
+#endif
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
#16 lore raw

PATCH v4 10/14 riscv: sifive: fu540: add SPL configuration

In reply to Pragnesh Patel

Add a support for SPL which will boot from L2 LIM (0x0800_0000) and then boot U-boot FIT image including OpenSBI FW_DYNAMIC firmware and U-Boot proper images from 1st partition of MMC boot devices.

SPL related code is leverage from FSBL
(https://github.com/sifive/freedom-u540-c000-bootloader.git)

---
 board/sifive/fu540/Kconfig            |  8 +++
 board/sifive/fu540/Makefile           |  4 ++
 board/sifive/fu540/fu540-memory-map.h | 33 ++++++++++++
 board/sifive/fu540/fu540.c            | 24 +++++++++
 board/sifive/fu540/spl.c              | 78 +++++++++++++++++++++++++++
 board/sifive/fu540/ux00prci.h         | 56 +++++++++++++++++++
 include/configs/sifive-fu540.h        | 18 +++++++
 7 files changed, 221 insertions(+)
 create mode 100644 board/sifive/fu540/fu540-memory-map.h
 create mode 100644 board/sifive/fu540/spl.c
 create mode 100644 board/sifive/fu540/ux00prci.h
board/sifive/fu540/Kconfig +8 -0
index 900197bbb2..ebe3472f9a 100644
@@ -13,12 +13,20 @@ config SYS_CONFIG_NAME
 	default "sifive-fu540"
 
 config SYS_TEXT_BASE
+	default 0x80200000 if SPL
 	default 0x80000000 if !RISCV_SMODE
 	default 0x80200000 if RISCV_SMODE
 
+config SPL_TEXT_BASE
+	default 0x08000000
+
+config SPL_OPENSBI_LOAD_ADDR
+	default 0x80000000
+
 config BOARD_SPECIFIC_OPTIONS # dummy
 	def_bool y
 	select GENERIC_RISCV
+	select SUPPORT_SPL
 	imply CMD_DHCP
 	imply CMD_EXT2
 	imply CMD_EXT4
board/sifive/fu540/Makefile +4 -0
index 6e1862c475..b05e2f5807 100644
@@ -3,3 +3,7 @@
 # Copyright (c) 2019 Western Digital Corporation or its affiliates.
 
 obj-y	+= fu540.o
+
+ifdef CONFIG_SPL_BUILD
+obj-y += spl.o
+endif
board/sifive/fu540/fu540-memory-map.h new file +33 -0
new file mode 100644
index 0000000000..c65203726b
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2019 SiFive, Inc
+ */
+
+#ifndef FU540_MEMORY_MAP
+#define FU540_MEMORY_MAP
+
+#include <asm/arch/gpio.h>
+#include "ux00prci.h"
+
+/****************************************************************************
+ * Platform definitions
+ *****************************************************************************/
+
+/* Memory map */
+#define GPIO_CTRL_ADDR                 _AC(0x10060000, UL)
+
+#define PHYSICAL_FILTER_CTRL_ADDR      _AC(0x100b8000, UL)
+
+#define UX00DDR_CTRL_ADDR              _AC(0x100b0000, UL)
+#define UX00PRCI_CTRL_ADDR             _AC(0x10000000, UL)
+
+/* Helper functions */
+#define _REG32(p, i)    (*(volatile uint32_t *)((p) + (i)))
+
+#define UX00PRCI_REG(offset)  \
+	_REG32(UX00PRCI_CTRL_ADDR, \
+			offset)
+
+#define GPIO_REG(offset)      _REG32(GPIO_CTRL_ADDR, offset)
+
+#endif /* FU540_MEMORY_MAP */
board/sifive/fu540/fu540.c +24 -0
index 409471effc..fba9469c2d 100644
@@ -11,6 +11,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <misc.h>
+#include <spl.h>
 
 /*
  * This define is a value used for error/unknown serial.
@@ -114,3 +115,26 @@ int board_init(void)
 
 	return 0;
 }
+
+#ifdef CONFIG_SPL
+void board_boot_order(u32 *spl_boot_list)
+{
+	u8 i;
+	u32 boot_devices[] = {
+#ifdef CONFIG_SPL_MMC_SUPPORT
+		BOOT_DEVICE_MMC1,
+#endif
+	};
+
+	for (i = 0; i < ARRAY_SIZE(boot_devices); i++)
+		spl_boot_list[i] = boot_devices[i];
+}
+#endif
+
+#ifdef CONFIG_SPL_LOAD_FIT
+int board_fit_config_name_match(const char *name)
+{
+	/* boot using first FIT config */
+	return 0;
+}
+#endif
board/sifive/fu540/spl.c new file +78 -0

78 lines not on this page · raw message

board/sifive/fu540/ux00prci.h new file +56 -0

56 lines not on this page · raw message

include/configs/sifive-fu540.h +18 -0
index 2756ed5a77..ef3ae9b650 100644
@@ -11,6 +11,22 @@
 
 #include <linux/sizes.h>
 
+#ifdef CONFIG_SPL
+
+#define CONFIG_SPL_MAX_SIZE		0x00100000
+#define CONFIG_SPL_BSS_START_ADDR	0x85000000
+#define CONFIG_SPL_BSS_MAX_SIZE		0x00100000
+#define CONFIG_SYS_SPL_MALLOC_START	(CONFIG_SPL_BSS_START_ADDR + \
+					 CONFIG_SPL_BSS_MAX_SIZE)
+#define CONFIG_SYS_SPL_MALLOC_SIZE	0x00100000
+
+#define CONFIG_SPL_LOAD_FIT_ADDRESS	0x84000000
+
+#define CONFIG_SPL_STACK	(0x08000000 + 0x001D0000 - \
+				 GENERATED_GBL_DATA_SIZE)
+
+#endif
+
 #define CONFIG_SYS_SDRAM_BASE		0x80000000
 #define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_SDRAM_BASE + SZ_2M)
 
@@ -24,6 +40,7 @@
 
 /* Environment options */
 
+#ifndef CONFIG_SPL_BUILD
 #define BOOT_TARGET_DEVICES(func) \
 	func(MMC, mmc, 0) \
 	func(DHCP, dhcp, na)
@@ -43,5 +60,6 @@
 #define CONFIG_PREBOOT \
 	"setenv fdt_addr ${fdtcontroladdr};" \
 	"fdt addr ${fdtcontroladdr};"
+#endif
 
 #endif /* __CONFIG_H */
Signature · 1 line
2.17.1
#17 lore raw

PATCH v4 11/14 configs: fu540: Add config options for U-boot SPL

In reply to Pragnesh Patel

With sifive_fu540_defconfig:

User can use FSBL or u-boot-spl.bin anyone at a time.

For FSBL,
fsbl->fw_payload.bin(opensbi+u-boot)

For u-boot-spl.bin,
u-boot-spl.bin->FIT image(opensbi+u-boot+dtb)

U-Boot SPL will be loaded by ZSBL from SD card (replace fsbl.bin with u-boot-spl.bin) and runs in L2 LIM in machine mode and then load FIT image u-boot.itb from 1st partition of SD card (replace fw_payload.bin with u-boot.itb) into RAM.

U-boot SPL expects u-boot.itb FIT image in the 1st partition of SD card irrespective of GUID

---
 configs/sifive_fu540_defconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
configs/sifive_fu540_defconfig +11 -0
index 6d61e6c960..24aab7783b 100644
@@ -12,3 +12,14 @@ CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_DEFAULT_DEVICE_TREE="hifive-unleashed-a00"
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_MTD=y
+CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SPL=y
+CONFIG_SPL_MMC_SUPPORT=y
+CONFIG_SPL_SPI_SUPPORT=y
+CONFIG_SPL_YMODEM_SUPPORT=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=1
+CONFIG_SPL_CLK=y
+CONFIG_SPL_PAYLOAD="u-boot.itb"
+CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_SIFIVE_FU540_DDR=y
Signature · 1 line
2.17.1
#18 lore raw

PATCH v4 12/14 riscv: sifive: fu540: enable all cache ways from u-boot proper

In reply to Pragnesh Patel

Enable all cache ways from u-boot proper.

---
 board/sifive/fu540/Makefile |  1 +
 board/sifive/fu540/cache.c  | 20 ++++++++++++++++++++
 board/sifive/fu540/cache.h  | 13 +++++++++++++
 board/sifive/fu540/fu540.c  |  6 ++++--
 4 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 board/sifive/fu540/cache.c
 create mode 100644 board/sifive/fu540/cache.h
board/sifive/fu540/Makefile +1 -0
index b05e2f5807..3b867bbd89 100644
@@ -3,6 +3,7 @@
 # Copyright (c) 2019 Western Digital Corporation or its affiliates.
 
 obj-y	+= fu540.o
+obj-y	+= cache.o
 
 ifdef CONFIG_SPL_BUILD
 obj-y += spl.o
board/sifive/fu540/cache.c new file +20 -0
new file mode 100644
index 0000000000..a0bcd2ba48
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 SiFive, Inc
+ */
+#include <asm/io.h>
+
+/* Register offsets */
+#define CACHE_ENABLE           0x008
+
+/* Enable ways; allow cache to use these ways */
+void cache_enable_ways(u64 base_addr, u8 value)
+{
+	volatile u32 *enable = (volatile u32 *)(base_addr +
+					  CACHE_ENABLE);
+	/* memory barrier */
+	mb();
+	(*enable) = value;
+	/* memory barrier */
+	mb();
+}
board/sifive/fu540/cache.h new file +13 -0
new file mode 100644
index 0000000000..425124a23b
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2019 SiFive, Inc
+ */
+
+#ifndef FU540_CACHE_H
+#define FU540_CACHE_H
+
+#define CACHE_CTRL_ADDR               _AC(0x2010000, UL)
+
+void cache_enable_ways(u64 base_addr, u8 value);
+
+#endif /* FU540_CACHE_H */
board/sifive/fu540/fu540.c +4 -2
index fba9469c2d..661b2ad282 100644
@@ -13,6 +13,8 @@
 #include <misc.h>
 #include <spl.h>
 
+#include "cache.h"
+
 /*
  * This define is a value used for error/unknown serial.
  * If we really care about distinguishing errors and 0 is
@@ -111,8 +113,8 @@ int misc_init_r(void)
 
 int board_init(void)
 {
-	/* For now nothing to do here. */
-
+	/* enable all cache ways */
+	cache_enable_ways(CACHE_CTRL_ADDR, 15);
 	return 0;
 }
 
Signature · 1 line
2.17.1
#19 lore raw

PATCH v4 13/14 sifive: fix palmer's email address

In reply to Pragnesh Patel

Fix Palmer's email address

---
 board/sifive/fu540/MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/sifive/fu540/MAINTAINERS +1 -1
index 702d803ad8..9bae3d3db7 100644
@@ -1,6 +1,6 @@
 SiFive FU540 BOARD
 M:	Paul Walmsley <[email protected]>
-M:	Palmer Dabbelt <[email protected]>
+M:	Palmer Dabbelt <[email protected]>
 M:	Anup Patel <[email protected]>
 M:	Atish Patra <[email protected]>
 S:	Maintained
Signature · 1 line
2.17.1
maintainer
#20 lore raw

PATCH v4 13/14 sifive: fix palmer's email address

Quoted 12 lines · pragnesh.patel at sifive.com

Fix Palmer's email address

---
 board/sifive/fu540/MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/sifive/fu540/MAINTAINERS +0 -0
index 702d803ad8..9bae3d3db7 100644

board/sifive/fu540/MAINTAINERS line 6

Quoted 7 lines
board/sifive/fu540/MAINTAINERS +1 -1
@@ -1,6 +1,6 @@
 SiFive FU540 BOARD
 M:	Paul Walmsley <[email protected]>
-M:	Palmer Dabbelt <[email protected]>
+M:	Palmer Dabbelt <[email protected]>
 M:	Anup Patel <[email protected]>
 M:	Atish Patra <[email protected]>
 S:	Maintained

Thanks, these are all over the place and I'm afraid I've lost track of them. I decided to use palmer at dabbelt.com because I've yet to get the Google passing DMARC checks.

#21 lore raw

PATCH v4 13/14 sifive: fix palmer's email address

Hi,

Quoted 23 lines

-----Original Message-----
From: Palmer Dabbelt <[email protected]>
Sent: 06 March 2020 06:01
To: Pragnesh Patel <[email protected]>
Cc: u-boot at lists.denx.de; Atish Patra <[email protected]>; bmeng.cn at gmail.com; Paul Walmsley <[email protected]>; jagan at amarulasolutions.com; Troy Benjegerdes <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Pragnesh Patel <[email protected]>
Subject: Re: [PATCH v4 13/14] sifive: fix palmer's email address

Quoted 9 lines · pragnesh.patel at sifive.com

Fix Palmer's email address

---
 board/sifive/fu540/MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/board/sifive/fu540/MAINTAINERS index 702d803ad8..9bae3d3db7

100644

Quoted 14 lines

board/sifive/fu540/MAINTAINERS line 6

Quoted 10 lines
board/sifive/fu540/MAINTAINERS +1 -1
@@ -1,6 +1,6 @@
 SiFive FU540 BOARD
 M:	Paul Walmsley <[email protected]>
-M:	Palmer Dabbelt <[email protected]>
+M:	Palmer Dabbelt <[email protected]>
 M:	Anup Patel <[email protected]>
 M:	Atish Patra <[email protected]>
 S:	Maintained

Thanks, these are all over the place and I'm afraid I've lost track of them. I decided to use palmer at dabbelt.com because I've yet to get the Google passing DMARC checks.

Will update in v5.

#22 lore raw

PATCH v4 14/14 doc: update FU540 RISC-V documentation

In reply to Pragnesh Patel

Add descriptions about U-Boot SPL feature and how to build and run.

---
 doc/board/sifive/fu540.rst | 409 ++++++++++++++++++++++++++++++++++---
 1 file changed, 385 insertions(+), 24 deletions(-)
doc/board/sifive/fu540.rst +385 -24
index 3937222c6c..e5414f4eef 100644
@@ -42,8 +42,60 @@ Building
    export ARCH=riscv
    export CROSS_COMPILE=<riscv64 toolchain prefix>
 
-3. make sifive_fu540_defconfig
-4. make
+User can use FSBL or u-boot-spl as a 1st stage bootloader.
+
+1) Use FSBL as a 1st stage bootloader
+
+.. code-block:: console
+
+	git clone https://github.com/sifive/freedom-u540-c000-bootloader.git
+	cd freedom-u540-c000-bootloader
+	make
+
+	cd <u-boot-dir>
+	make sifive_fu540_defconfig
+	make
+
+	git clone https://github.com/riscv/opensbi.git
+	cd opensbi
+	make PLATFORM=sifive/fu540 FW_PAYLOAD_PATH=<path to u-boot.bin>
+
+This will generate a fw_payload.bin(build/platform/sifive/fu540/firmware/fw_payload.bin)
+
+u-boot.bin is used as a payload of the OpenSBI FW_PAYLOAD firmware.
+
+More detailed description of steps required to build FW_PAYLOAD firmware
+is beyond the scope of this document. Please refer OpenSBI documenation.
+(Note: OpenSBI git repo is at https://github.com/riscv/opensbi.git)
+
+2) Use u-boot-spl as a 1st stage bootloader
+
+Before building U-Boot SPL, OpenSBI must be build first. OpenSBI can be
+cloned and build for FU540 as below:
+
+.. code-block:: console
+
+	git clone https://github.com/riscv/opensbi.git
+	cd opensbi
+	make PLATFORM=sifive/fu540
+
+Copy OpenSBI FW_DYNAMIC image (build/platform/sifive/fu540/firmware/fw_dynamic.bin)
+into U-Boot root directory
+
+.. code-block:: console
+
+	cp build/platform/sifive/fu540/firmware/fw_dynamic.bin <u-boot-dir>
+
+Now build the u-boot-spl and u-boot proper
+
+.. code-block:: console
+
+	cd <u-boot-dir>
+	make sifive_fu540_defconfig
+	make
+
+This will generate spl/u-boot-spl.bin and FIT image(u-boot.itb)
+
 
 Flashing
 --------
@@ -53,28 +105,55 @@ The current U-Boot port is supported in S-mode only and loaded from DRAM.
 A prior stage M-mode firmware/bootloader (e.g OpenSBI) is required to
 boot the u-boot.bin in S-mode and provide M-mode runtime services.
 
-Currently, the u-boot.bin is used as a payload of the OpenSBI FW_PAYLOAD
-firmware. We need to compile OpenSBI with below command:
+1) Use FSBL as a 1st stage bootloader
+
+ZSBL loads the FSBL(fsbl.bin) from a partition with GUID type
+5B193300-FC78-40CD-8002-E86C45580B47
+
+FSBL loads the fw_payload.bin from a partition with GUID type
+2E54B353-1271-4842-806F-E436D6AF6985
+
+Once the prior stage firmware/bootloader binary is generated, it should be
+copied to the first partition of the sdcard.
 
 .. code-block:: none
 
-make PLATFORM=sifive/fu540 FW_PAYLOAD_PATH=<path to u-boot-dtb.bin>
+     sudo dd if=fsbl.bin of=/dev/disk2s4 bs=1024
+     sudo dd if=fw_payload.bin of=/dev/disk2s1 bs=1024
 
-More detailed description of steps required to build FW_PAYLOAD firmware
-is beyond the scope of this document. Please refer OpenSBI documenation.
-(Note: OpenSBI git repo is at https://github.com/riscv/opensbi.git)
+Assuming that /dev/disk2s4 partition is of GUID type
+5B193300-FC78-40CD-8002-E86C45580B47 and /dev/disk2s1 partition
+is of GUID type 2E54B353-1271-4842-806F-E436D6AF6985
+
+2) Use u-boot-spl as a 1st stage bootloader
+
+ZSBL loads the U-boot SPL(u-boot-spl.bin) from a partition with GUID type
+5B193300-FC78-40CD-8002-E86C45580B47
+
+U-boot SPL expects a u-boot FIT image(u-boot.itb) from 1st partition(/dev/sdc1)
+of SD card irrespective of GUID
+
+FIT image(u-boot.itb) is a combination of fw_dynamic.bin, u-boot-nodtb.bin and
+device tree blob(hifive-unleashed-a00.dtb)
 
 Once the prior stage firmware/bootloader binary is generated, it should be
 copied to the first partition of the sdcard.
 
 .. code-block:: none
 
-    sudo dd if=<prior_stage_firmware_binary> of=/dev/disk2s1 bs=1024
+    sudo dd if=spl/u-boot-spl.bin of=/dev/disk2s4 bs=1024
+    sudo dd if=u-boot.itb of=/dev/disk2s1 bs=1024
+
+Assuming that /dev/disk2s4 partition is of GUID type
+5B193300-FC78-40CD-8002-E86C45580B47 and /dev/disk2s1 is of
+any GUID type raw partition.
 
 Booting
 -------
 Once you plugin the sdcard and power up, you should see the U-Boot prompt.
 
+1) Use FSBL as a 1st stage bootloader
+
 Sample boot log from HiFive Unleashed board
 -------------------------------------------
 
@@ -145,19 +224,6 @@ load uImage.
    Filename '/sifive/fu540/Image'.
    Load address: 0x84000000
    Loading: #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
-            #################################################################
             #################################################################
             #################################################################
             #################################################################
@@ -184,8 +250,6 @@ load uImage.
    Filename '/sifive/fu540/uRamdisk'.
    Load address: 0x88300000
    Loading: #################################################################
-            #################################################################
-            #################################################################
             #################################################################
             #################################################################
             #################################################################
@@ -363,3 +427,300 @@ load uImage.
 
    Please press Enter to activate this console.
    / #
+
+
+2) Use u-boot-spl as a 1st stage bootloader
+
+The U-Boot SPL will boot in M mode and load the FIT image which include
+OpenSBI and U-Boot proper images. After loading progress, it will jump
+to OpenSBI first and then U-Boot proper which will run in S mode.
+
+Sample boot log from HiFive Unleashed board
+-------------------------------------------
+
+.. code-block:: none
+
+   U-Boot SPL 2020.04-rc1-00212-g375b0a2dad-dirty (Feb 13 2020 - 17:45:44 +0530)
+   Trying to boot from MMC1
+
+
+   U-Boot 2020.04-rc1-00212-g375b0a2dad-dirty (Feb 13 2020 - 17:45:44 +0530)
+
+   CPU:   rv64imafdc
+   Model: SiFive HiFive Unleashed A00
+   DRAM:  8 GiB
+   MMC:   spi at 10050000:mmc at 0: 0
+   In:    serial at 10010000
+   Out:   serial at 10010000
+   Err:   serial at 10010000
+   Board serial number should not be 0 !!
+   Net:
+   Warning: ethernet at 10090000 (eth0) using random MAC address - 92:79:17:2d:7b:b7
+   eth0: ethernet at 10090000
+   Hit any key to stop autoboot:  0
+   => version
+   U-Boot 2020.04-rc1-00212-g375b0a2dad-dirty (Feb 13 2020 - 17:45:44 +0530)
+
+   riscv64-unknown-linux-gnu-gcc (crosstool-NG 1.24.0.37-3f461da) 9.2.0
+   GNU ld (crosstool-NG 1.24.0.37-3f461da) 2.32
+   => mmc info
+   Device: spi at 10050000:mmc at 0
+   Manufacturer ID: 3
+   OEM: 5344
+   Name: SC16G
+   Bus Speed: 20000000
+   Mode: SD Legacy
+   Rd Block Len: 512
+   SD version 2.0
+   High Capacity: Yes
+   Capacity: 14.8 GiB
+   Bus Width: 1-bit
+   Erase Group Size: 512 Bytes
+   => mmc part
+
+   Partition Map for MMC device 0  --   Partition Type: EFI
+
+   Part    Start LBA       End LBA         Name
+   Attributes
+   Type GUID
+   Partition GUID
+   1     0x00000800      0x000107ff      "SiFive bare-metal (or stage 2 loader"
+   attrs:  0x0000000000000000
+   type:   2e54b353-1271-4842-806f-e436d6af6985
+   guid:   3c9eabe1-b16b-4a2e-9b4e-f065c740bb86
+   2     0x00040800      0x00ecdfde      "Linux filesystem"
+   attrs:  0x0000000000000000
+   type:   0fc63daf-8483-4772-8e79-3d69d8477de4
+   guid:   ad9309ff-d204-42f0-9f99-f3275a83f565
+
+Now you can configure your networking, tftp server and use tftp boot method to
+load uImage.
+
+.. code-block:: none
+
+   => setenv serverip 172.16.35.74
+   => setenv ipaddr 172.16.35.40
+   => tftpboot 0x83000000 fit.itb
+   ethernet at 10090000: PHY present at 0
+   ethernet at 10090000: Starting autonegotiation...
+   ethernet at 10090000: Autonegotiation complete
+   ethernet at 10090000: link up, 100Mbps full-duplex (lpa: 0x41e1)
+   Using ethernet at 10090000 device
+   TFTP from server 172.16.35.74; our IP address is 172.16.35.40
+   Filename 'fit.itb'.
+   Load address: 0x83000000
+   Loading: #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   #################################################################
+   ################################################################
+   ###################################
+   878.9 KiB/s
+   done
+   Bytes transferred = 13823823 (d2ef4f hex)
+   => bootm 0x83000000
+   ## Loading kernel from FIT Image at 83000000 ...
+   Using 'config-1' configuration
+   Trying 'kernel at 1' kernel subimage
+   Description:  Linux kernel
+   Type:         Kernel Image
+   Compression:  uncompressed
+   Data Start:   0x830000d8
+   Data Size:    9247260 Bytes = 8.8 MiB
+   Architecture: RISC-V
+   OS:           Linux
+   Load Address: 0x80200000
+   Entry Point:  0x80200000
+   Verifying Hash Integrity ... OK
+   ## Loading ramdisk from FIT Image at 83000000 ...
+   Using 'config-1' configuration
+   Trying 'ramdisk at 1' ramdisk subimage
+   Description:  ramdisk
+   Type:         RAMDisk Image
+   Compression:  gzip compressed
+   Data Start:   0x838d3378
+   Data Size:    4568674 Bytes = 4.4 MiB
+   Architecture: RISC-V
+   OS:           Linux
+   Load Address: 0x82000000
+   Entry Point:  unavailable
+   Verifying Hash Integrity ... OK
+   Loading ramdisk from 0x838d3378 to 0x82000000
+   WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file!
+   ## Loading fdt from FIT Image at 83000000 ...
+   Using 'config-1' configuration
+   Trying 'fdt at 1' fdt subimage
+   Description:  unavailable
+   Type:         Flat Device Tree
+   Compression:  uncompressed
+   Data Start:   0x838d1b80
+   Data Size:    6023 Bytes = 5.9 KiB
+   Architecture: RISC-V
+   Verifying Hash Integrity ... OK
+   Booting using the fdt blob at 0x838d1b80
+   Loading Kernel Image
+   Using Device Tree in place at 00000000838d1b80, end 00000000838d6306
+
+   Starting kernel ...
+
+   [    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
+   [    0.000000] Linux version 5.3.0-13236-g97f9a3c4eee5 (pragneshp at sachinj2-OptiPlex-7010) (gcc version 8.2.0 (Buildroot 2018.11-rc2-00003-ga0787e9
+   [    0.000000] earlycon: sifive0 at MMIO 0x0000000010010000 (options '')
+   [    0.000000] printk: bootconsole [sifive0] enabled
+   [    0.000000] Initial ramdisk at: 0x(____ptrval____) (4568674 bytes)
+   [    0.000000] Zone ranges:
+   [    0.000000]   DMA32    [mem 0x0000000080200000-0x00000000ffffffff]
+   [    0.000000]   Normal   [mem 0x0000000100000000-0x000000027fffffff]
+   [    0.000000] Movable zone start for each node
+   [    0.000000] Early memory node ranges
+   [    0.000000]   node   0: [mem 0x0000000080200000-0x000000027fffffff]
+   [    0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x000000027fffffff]
+   [    0.000000] software IO TLB: mapped [mem 0xfbfff000-0xfffff000] (64MB)
+   [    0.000000] CPU with hartid=0 is not available
+   [    0.000000] CPU with hartid=0 is not available
+   [    0.000000] elf_hwcap is 0x112d
+   [    0.000000] percpu: Embedded 17 pages/cpu s30680 r8192 d30760 u69632
+   [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 2067975
+   [    0.000000] Kernel command line: earlycon=sifive,0x10010000 console=ttySIF0,115200
+   [    0.000000] Dentry cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
+   [    0.000000] Inode-cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)
+   [    0.000000] Sorting __ex_table...
+   [    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
+   [    0.000000] Memory: 8179828K/8386560K available (6081K kernel code, 388K rwdata, 2025K rodata, 209K init, 307K bss, 206732K reserved, 0K cma-r)
+   [    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
+   [    0.000000] rcu: Hierarchical RCU implementation.
+   [    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
+   [    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
+   [    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
+   [    0.000000] NR_IRQS: 0, nr_irqs: 0, preallocated irqs: 0
+   [    0.000000] plic: mapped 53 interrupts with 4 handlers for 9 contexts.
+   [    0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [2]
+   [    0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x1d854df40, max_idle_ns: 3526361616960 ns
+   [    0.000006] sched_clock: 64 bits at 1000kHz, resolution 1000ns, wraps every 2199023255500ns
+   [    0.008467] Console: colour dummy device 80x25
+   [    0.012819] Calibrating delay loop (skipped), value calculated using timer frequency.. 2.00 BogoMIPS (lpj=4000)
+   [    0.022844] pid_max: default: 32768 minimum: 301
+   [    0.027915] Mount-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
+   [    0.035332] Mountpoint-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
+   [    0.044791] rcu: Hierarchical SRCU implementation.
+   [    0.049255] smp: Bringing up secondary CPUs ...
+   [    0.055034] smp: Brought up 1 node, 4 CPUs
+   [    0.059664] devtmpfs: initialized
+   [    0.063818] random: get_random_u32 called from bucket_table_alloc.isra.29+0x4e/0x160 with crng_init=0
+   [    0.072588] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
+   [    0.082000] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
+   [    0.089513] NET: Registered protocol family 16
+   [    0.105911] vgaarb: loaded
+   [    0.108166] SCSI subsystem initialized
+   [    0.111946] usbcore: registered new interface driver usbfs
+   [    0.117105] usbcore: registered new interface driver hub
+   [    0.122486] usbcore: registered new device driver usb
+   [    0.128073] clocksource: Switched to clocksource riscv_clocksource
+   [    0.140277] NET: Registered protocol family 2
+   [    0.144449] tcp_listen_portaddr_hash hash table entries: 4096 (order: 4, 65536 bytes, linear)
+   [    0.152620] TCP established hash table entries: 65536 (order: 7, 524288 bytes, linear)
+   [    0.162238] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
+   [    0.172159] TCP: Hash tables configured (established 65536 bind 65536)
+   [    0.178343] UDP hash table entries: 4096 (order: 5, 131072 bytes, linear)
+   [    0.185140] UDP-Lite hash table entries: 4096 (order: 5, 131072 bytes, linear)
+   [    0.192553] NET: Registered protocol family 1
+   [    0.196752] RPC: Registered named UNIX socket transport module.
+   [    0.202145] RPC: Registered udp transport module.
+   [    0.206828] RPC: Registered tcp transport module.
+   [    0.211512] RPC: Registered tcp NFSv4.1 backchannel transport module.
+   [    0.217939] PCI: CLS 0 bytes, default 64
+   [    0.222139] Unpacking initramfs...
+   [    0.578803] Freeing initrd memory: 4460K
+   [    0.582972] workingset: timestamp_bits=62 max_order=21 bucket_order=0
+   [    0.596643] NFS: Registering the id_resolver key type
+   [    0.600950] Key type id_resolver registered
+   [    0.605134] Key type id_legacy registered
+   [    0.609090] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
+   [    0.615928] 9p: Installing v9fs 9p2000 file system support
+   [    0.621581] NET: Registered protocol family 38
+   [    0.625700] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
+   [    0.633051] io scheduler mq-deadline registered
+   [    0.637559] io scheduler kyber registered
+   [    0.685592] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
+   [    0.692184] 10010000.serial: ttySIF0 at MMIO 0x10010000 (irq = 4, base_baud = 0) is a SiFive UART v0
+   [    0.700566] printk: console [ttySIF0] enabled
+   [    0.700566] printk: console [ttySIF0] enabled
+   [    0.709228] printk: bootconsole [sifive0] disabled
+   [    0.709228] printk: bootconsole [sifive0] disabled
+   [    0.719030] 10011000.serial: ttySIF1 at MMIO 0x10011000 (irq = 1, base_baud = 0) is a SiFive UART v0
+   [    0.728364] [drm] radeon kernel modesetting enabled.
+   [    0.745292] loop: module loaded
+   [    0.748208] sifive_spi 10040000.spi: mapped; irq=3, cs=1
+   [    0.753490] sifive_spi 10050000.spi: mapped; irq=5, cs=1
+   [    0.758811] libphy: Fixed MDIO Bus: probed
+   [    0.762886] macb 10090000.ethernet: Registered clk switch 'sifive-gemgxl-mgmt'
+   [    0.769643] macb: GEM doesn't support hardware ptp.
+   [    0.774532] libphy: MACB_mii_bus: probed
+   [    0.940349] Microsemi VSC8541 SyncE 10090000.ethernet-ffffffff:00: attached PHY driver [Microsemi VSC8541 SyncE] (mii_bus:phy_addr=10090000.et)
+   [    0.954893] macb 10090000.ethernet eth0: Cadence GEM rev 0x10070109 at 0x10090000 irq 6 (92:79:17:2d:7b:b7)
+   [    0.964698] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
+   [    0.970417] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
+   [    0.976410] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
+   [    0.982832] ehci-pci: EHCI PCI platform driver
+   [    0.987288] ehci-platform: EHCI generic platform driver
+   [    0.992547] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
+   [    0.998646] ohci-pci: OHCI PCI platform driver
+   [    1.003092] ohci-platform: OHCI generic platform driver
+   [    1.008557] usbcore: registered new interface driver uas
+   [    1.013621] usbcore: registered new interface driver usb-storage
+   [    1.019695] mousedev: PS/2 mouse device common for all mice
+   [    1.050569] mmc_spi spi1.0: SD/MMC host mmc0, no DMA, no WP, no poweroff, cd polling
+   [    1.057714] usbcore: registered new interface driver usbhid
+   [    1.063098] usbhid: USB HID core driver
+   [    1.067805] NET: Registered protocol family 10
+   [    1.072421] Segment Routing with IPv6
+   [    1.075367] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
+   [    1.081745] NET: Registered protocol family 17
+   [    1.085867] 9pnet: Installing 9P2000 support
+   [    1.089951] Key type dns_resolver registered
+   [    1.096367] Freeing unused kernel memory: 208K
+   [    1.100023] This architecture does not have kernel memory protection.
+   [    1.106468] Run /init as init process
+   Starting syslogd: OK
+   Starting klogd: OK
+   Starting mdev...
+   /etc/init.d/S10mdev: line 9: can't create /proc/sys/kernel/hotplug: nonexistent directory
+   [    1.167972] mmc0: host does not support reading read-only switch, assuming write-enable
+   [    1.175224] mmc0: new SDHC card on SPI
+   [    1.180428] mmcblk0: mmc0:0000 SC16G 14.8 GiB
+   [    1.214935]  mmcblk0: p1 p2 p4
+   modprobe: can't change directory to '/lib/modules': No such file or directory
+   Initializing random number generator... [    1.664435] random: dd: uninitialized urandom read (512 bytes read)
+   done.
+   Starting network: udhcpc: started, v1.29.3
+   udhcpc: sending discover
+   [    3.756700] macb 10090000.ethernet eth0: link up (100/Full)
+   [    3.761515] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
+   udhcpc: sending discover
+   udhcpc: sending select for 172.16.35.4
+   udhcpc: lease of 172.16.35.4 obtained, lease time 3600
+   deleting routers
+   adding dns 172.16.34.75
+   adding dns 172.16.24.25
+   OK
+   Starting dropbear sshd: [    4.893179] random: dropbear: uninitialized urandom read (32 bytes read)
+   OK
+
+   Welcome to Buildroot
+   buildroot login: root
+   Password:
+   #
Signature · 1 line
2.17.1
#23 lore raw

v4 cover RISC-V SiFive FU540 support SPL

In reply to Pragnesh Patel
Quoted 46 lines · pragnesh.patel at sifive.com

This series add support for SPL to FU540.U-Boot SPL can boot from L2 LIM (0x0800_0000) and jump to OpenSBI(FW_DYNAMIC firmware) and U-Boot proper from MMC devices.

How to test this patch:
1) Go to OpenSBI-dir : make PLATFORM=sifive/fu540 O=build_dir I=install_dir FW_DYNAMIC=y install
2) cp install_dir/platform/sifive/fu540/firmware/fw_dynamic.bin <u-boot-dir>/
3) Change to u-boot-dir
4) make sifive_fu540_defconfig
5) make all
6) ZSBL loads the U-boot SPL(u-boot-spl.bin) from a partition with
GUID type 5B193300-FC78-40CD-8002-E86C45580B47

sudo dd if=spl/u-boot-spl.bin of=/dev/sdc4 bs=1M

7) U-boot SPL expects a u-boot FIT image(u-boot.itb) from 1st partition(/dev/sdc1) of SD card irrespective of GUID

sudo dd if=u-boot.itb of=/dev/sdc1 bs=1M

Thanks to Yash Shah <[email protected]> for testing the series.

Changes in v4:
- Split misc DM driver patch into multiple patches
- Added new SPL_CRC7_SUPPORT Kconfig option
- Added DM driver for DDR
- Added clk_enable and clk_disable ops in SiFive PRCI driver
- Added early clock initialization for SPL in SiFive PRCI driver
- Added SPL config options in sifive_fu540_defconfig instead of creatiing a new config file for SPL
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v3:
- Remove arch-fu540 and arch-sifive from arch/riscv/include/asm/
- Split SPL patches into DDR and SPL and spl defconfig
- Update fu540/MAINTAINERS file
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v2:
- Add DM driver Sifive OTP
- Split SPL patches into multiple patches
- Add a seprate patch for _image_binary_end and crc7.c
- Add a seprate patch to add board -u-boot.dtsi files
- Update FU540 RISC-V documentation

Quoted 16 lines

Pragnesh Patel (14):
misc: add driver for the SiFive otp controller
riscv: sifive: fu540: Use OTP DM driver for serial environment
variable
riscv: Add _image_binary_end for SPL
lib: Makefile: build crc7.c when CONFIG_MMC_SPI
riscv: sifive: dts: fu540: Add board -u-boot.dtsi files
sifive: fu540: add ddr driver
sifive: dts: fu540: Add DDR controller and phy register settings
clk: sifive: fu540-prci: Add clock enable and disable ops
clk: sifive: fu540-prci: Add clock initialization for SPL
riscv: sifive: fu540: add SPL configuration
configs: fu540: Add config options for U-boot SPL
riscv: sifive: fu540: enable all cache ways from u-boot proper
sifive: fix palmer's email address
doc: update FU540 RISC-V documentation

Thanks for doing this. I don't see any responses here and I'm afraid I'm not even remotely familiar with u-boot development, but I took a look and don't see any issues aside from what I replied to.

Quoted 43 lines
 arch/riscv/cpu/u-boot-spl.lds                 |    1 +
 arch/riscv/dts/fu540-c000-u-boot.dtsi         |   63 +
 arch/riscv/dts/fu540-sdram-lpddr4.dtsi        | 1489 +++++++++++++++++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      |   23 +
 board/sifive/fu540/Kconfig                    |   10 +
 board/sifive/fu540/MAINTAINERS                |    2 +-
 board/sifive/fu540/Makefile                   |    5 +
 board/sifive/fu540/cache.c                    |   20 +
 board/sifive/fu540/cache.h                    |   13 +
 board/sifive/fu540/fu540-memory-map.h         |   33 +
 board/sifive/fu540/fu540.c                    |  139 +-
 board/sifive/fu540/spl.c                      |   78 +
 board/sifive/fu540/ux00prci.h                 |   56 +
 common/spl/Kconfig                            |    7 +
 configs/sifive_fu540_defconfig                |   11 +
 doc/board/sifive/fu540.rst                    |  409 ++++-
 drivers/clk/sifive/fu540-prci.c               |  169 +-
 drivers/misc/Kconfig                          |    7 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/sifive-otp.c                     |  241 +++
 drivers/ram/Kconfig                           |    7 +
 drivers/ram/Makefile                          |    2 +
 drivers/ram/sifive/Kconfig                    |    8 +
 drivers/ram/sifive/Makefile                   |    6 +
 drivers/ram/sifive/sdram_fu540.c              |  295 ++++
 drivers/ram/sifive/sdram_fu540.h              |   94 ++
 include/configs/sifive-fu540.h                |   18 +
 lib/Makefile                                  |    1 +
 28 files changed, 3107 insertions(+), 101 deletions(-)
 create mode 100644 arch/riscv/dts/fu540-c000-u-boot.dtsi
 create mode 100644 arch/riscv/dts/fu540-sdram-lpddr4.dtsi
 create mode 100644 arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
 create mode 100644 board/sifive/fu540/cache.c
 create mode 100644 board/sifive/fu540/cache.h
 create mode 100644 board/sifive/fu540/fu540-memory-map.h
 create mode 100644 board/sifive/fu540/spl.c
 create mode 100644 board/sifive/fu540/ux00prci.h
 create mode 100644 drivers/misc/sifive-otp.c
 create mode 100644 drivers/ram/sifive/Kconfig
 create mode 100644 drivers/ram/sifive/Makefile
 create mode 100644 drivers/ram/sifive/sdram_fu540.c
 create mode 100644 drivers/ram/sifive/sdram_fu540.h
#24 lore raw

v4 cover RISC-V SiFive FU540 support SPL

Hi,

Quoted 79 lines

-----Original Message-----
From: Palmer Dabbelt <[email protected]>
Sent: 06 March 2020 22:32
To: Pragnesh Patel <[email protected]>
Cc: u-boot at lists.denx.de; Atish Patra <[email protected]>; bmeng.cn at gmail.com; Paul Walmsley <[email protected]>; jagan at amarulasolutions.com; Troy Benjegerdes <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Pragnesh Patel <[email protected]>
Subject: Re: [PATCH v4 00/14] RISC-V SiFive FU540 support SPL

Quoted 15 lines · pragnesh.patel at sifive.com

This series add support for SPL to FU540.U-Boot SPL can boot from L2 LIM (0x0800_0000) and jump to OpenSBI(FW_DYNAMIC firmware) and U-Boot proper from MMC devices.

How to test this patch:
1) Go to OpenSBI-dir : make PLATFORM=sifive/fu540 O=build_dir I=install_dir FW_DYNAMIC=y install
2) cp install_dir/platform/sifive/fu540/firmware/fw_dynamic.bin <u-boot-dir>/
3) Change to u-boot-dir
4) make sifive_fu540_defconfig
5) make all
6) ZSBL loads the U-boot SPL(u-boot-spl.bin) from a partition with GUID type 5B193300-FC78-40CD-8002-E86C45580B47

Quoted 3 lines

sudo dd if=spl/u-boot-spl.bin of=/dev/sdc4 bs=1M

7) U-boot SPL expects a u-boot FIT image(u-boot.itb) from 1st

partition(/dev/sdc1)

Quoted 30 lines

of SD card irrespective of GUID

sudo dd if=u-boot.itb of=/dev/sdc1 bs=1M

Thanks to Yash Shah <[email protected]> for testing the series.

Changes in v4:
- Split misc DM driver patch into multiple patches
- Added new SPL_CRC7_SUPPORT Kconfig option
- Added DM driver for DDR
- Added clk_enable and clk_disable ops in SiFive PRCI driver
- Added early clock initialization for SPL in SiFive PRCI driver
- Added SPL config options in sifive_fu540_defconfig instead of creatiing a new config file for SPL
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v3:
- Remove arch-fu540 and arch-sifive from arch/riscv/include/asm/
- Split SPL patches into DDR and SPL and spl defconfig
- Update fu540/MAINTAINERS file
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v2:
- Add DM driver Sifive OTP
- Split SPL patches into multiple patches
- Add a seprate patch for _image_binary_end and crc7.c
- Add a seprate patch to add board -u-boot.dtsi files
- Update FU540 RISC-V documentation

Quoted 16 lines

Pragnesh Patel (14):
misc: add driver for the SiFive otp controller
riscv: sifive: fu540: Use OTP DM driver for serial environment
variable
riscv: Add _image_binary_end for SPL
lib: Makefile: build crc7.c when CONFIG_MMC_SPI
riscv: sifive: dts: fu540: Add board -u-boot.dtsi files
sifive: fu540: add ddr driver
sifive: dts: fu540: Add DDR controller and phy register settings
clk: sifive: fu540-prci: Add clock enable and disable ops
clk: sifive: fu540-prci: Add clock initialization for SPL
riscv: sifive: fu540: add SPL configuration
configs: fu540: Add config options for U-boot SPL
riscv: sifive: fu540: enable all cache ways from u-boot proper
sifive: fix palmer's email address
doc: update FU540 RISC-V documentation

Quoted 3 lines

Thanks for doing this. I don't see any responses here and I'm afraid I'm not even remotely familiar with u-boot development, but I took a look and don't see any issues aside from what I replied to.

Thanks Palmer.
@jagan at amarulasolutions.com Do you have any comment on this series ?

Quoted 44 lines
Quoted 44 lines

 arch/riscv/cpu/u-boot-spl.lds                 |    1 +
 arch/riscv/dts/fu540-c000-u-boot.dtsi         |   63 +
 arch/riscv/dts/fu540-sdram-lpddr4.dtsi        | 1489 +++++++++++++++++
 .../dts/hifive-unleashed-a00-u-boot.dtsi      |   23 +
 board/sifive/fu540/Kconfig                    |   10 +
 board/sifive/fu540/MAINTAINERS                |    2 +-
 board/sifive/fu540/Makefile                   |    5 +
 board/sifive/fu540/cache.c                    |   20 +
 board/sifive/fu540/cache.h                    |   13 +
 board/sifive/fu540/fu540-memory-map.h         |   33 +
 board/sifive/fu540/fu540.c                    |  139 +-
 board/sifive/fu540/spl.c                      |   78 +
 board/sifive/fu540/ux00prci.h                 |   56 +
 common/spl/Kconfig                            |    7 +
 configs/sifive_fu540_defconfig                |   11 +
 doc/board/sifive/fu540.rst                    |  409 ++++-
 drivers/clk/sifive/fu540-prci.c               |  169 +-
 drivers/misc/Kconfig                          |    7 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/sifive-otp.c                     |  241 +++
 drivers/ram/Kconfig                           |    7 +
 drivers/ram/Makefile                          |    2 +
 drivers/ram/sifive/Kconfig                    |    8 +
 drivers/ram/sifive/Makefile                   |    6 +
 drivers/ram/sifive/sdram_fu540.c              |  295 ++++
 drivers/ram/sifive/sdram_fu540.h              |   94 ++
 include/configs/sifive-fu540.h                |   18 +
 lib/Makefile                                  |    1 +
 28 files changed, 3107 insertions(+), 101 deletions(-)  create mode
100644 arch/riscv/dts/fu540-c000-u-boot.dtsi
 create mode 100644 arch/riscv/dts/fu540-sdram-lpddr4.dtsi
 create mode 100644 arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
 create mode 100644 board/sifive/fu540/cache.c  create mode 100644
board/sifive/fu540/cache.h  create mode 100644
board/sifive/fu540/fu540-memory-map.h
 create mode 100644 board/sifive/fu540/spl.c  create mode 100644

board/sifive/fu540/ux00prci.h create mode 100644 drivers/misc/sifive-otp.c create mode 100644 drivers/ram/sifive/Kconfig create mode 100644 drivers/ram/sifive/Makefile create mode 100644 drivers/ram/sifive/sdram_fu540.c create mode 100644 drivers/ram/sifive/sdram_fu540.h

#25 lore raw

v4 cover RISC-V SiFive FU540 support SPL

Quoted 82 lines · Pragnesh Patel

Hi,

Quoted 79 lines

-----Original Message-----
From: Palmer Dabbelt <[email protected]>
Sent: 06 March 2020 22:32
To: Pragnesh Patel <[email protected]>
Cc: u-boot at lists.denx.de; Atish Patra <[email protected]>; bmeng.cn at gmail.com; Paul Walmsley <[email protected]>; jagan at amarulasolutions.com; Troy Benjegerdes <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Pragnesh Patel <[email protected]>
Subject: Re: [PATCH v4 00/14] RISC-V SiFive FU540 support SPL

Quoted 15 lines · pragnesh.patel at sifive.com

This series add support for SPL to FU540.U-Boot SPL can boot from L2 LIM (0x0800_0000) and jump to OpenSBI(FW_DYNAMIC firmware) and U-Boot proper from MMC devices.

How to test this patch:
1) Go to OpenSBI-dir : make PLATFORM=sifive/fu540 O=build_dir I=install_dir FW_DYNAMIC=y install
2) cp install_dir/platform/sifive/fu540/firmware/fw_dynamic.bin <u-boot-dir>/
3) Change to u-boot-dir
4) make sifive_fu540_defconfig
5) make all
6) ZSBL loads the U-boot SPL(u-boot-spl.bin) from a partition with GUID type 5B193300-FC78-40CD-8002-E86C45580B47

Quoted 3 lines

sudo dd if=spl/u-boot-spl.bin of=/dev/sdc4 bs=1M

7) U-boot SPL expects a u-boot FIT image(u-boot.itb) from 1st

partition(/dev/sdc1)

Quoted 46 lines

of SD card irrespective of GUID

sudo dd if=u-boot.itb of=/dev/sdc1 bs=1M

Thanks to Yash Shah <[email protected]> for testing the series.

Changes in v4:
- Split misc DM driver patch into multiple patches
- Added new SPL_CRC7_SUPPORT Kconfig option
- Added DM driver for DDR
- Added clk_enable and clk_disable ops in SiFive PRCI driver
- Added early clock initialization for SPL in SiFive PRCI driver
- Added SPL config options in sifive_fu540_defconfig instead of creatiing a new config file for SPL
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v3:
- Remove arch-fu540 and arch-sifive from arch/riscv/include/asm/
- Split SPL patches into DDR and SPL and spl defconfig
- Update fu540/MAINTAINERS file
- Update fu540.rst on how to build and flash U-boot SPL

Changes in v2:
- Add DM driver Sifive OTP
- Split SPL patches into multiple patches
- Add a seprate patch for _image_binary_end and crc7.c
- Add a seprate patch to add board -u-boot.dtsi files
- Update FU540 RISC-V documentation

Pragnesh Patel (14):
misc: add driver for the SiFive otp controller
riscv: sifive: fu540: Use OTP DM driver for serial environment
variable
riscv: Add _image_binary_end for SPL
lib: Makefile: build crc7.c when CONFIG_MMC_SPI
riscv: sifive: dts: fu540: Add board -u-boot.dtsi files
sifive: fu540: add ddr driver
sifive: dts: fu540: Add DDR controller and phy register settings
clk: sifive: fu540-prci: Add clock enable and disable ops
clk: sifive: fu540-prci: Add clock initialization for SPL
riscv: sifive: fu540: add SPL configuration
configs: fu540: Add config options for U-boot SPL
riscv: sifive: fu540: enable all cache ways from u-boot proper
sifive: fix palmer's email address
doc: update FU540 RISC-V documentation

Quoted 6 lines
Quoted 3 lines

Thanks for doing this. I don't see any responses here and I'm afraid I'm not even remotely familiar with u-boot development, but I took a look and don't see any issues aside from what I replied to.

Thanks Palmer.
@jagan at amarulasolutions.com Do you have any comment on this series ?

We should target to bring the FU540 U-Boot SPL support in U-Boot v2020.07. I would like to have some test on this series.

Regards,
Bin