Skip to contentSkip to conversation

Support multi-dtb in SPL on Unmatched board

PATCH In review Zong Li 2 participants 13 messages Jun 30, 2021 – Jul 6, 2021

Subsystems (2)
lore
Share & tools
lore

Zong Li

author
#0 lore raw

cover Support multi-dtb in SPL on Unmatched board

This patch set contains the support I2C platform EEPROM and multi-dtb mechanism on Unmatched board. There are two revisions of Unmatched with different DDR timing respectively, so we'd like to support multi-dtb in SPL, then it can select the right DTB at runtime according to PCB revision in I2C EEPROM to initialize the right DDR timing.

The I2C EEPROM support is refactored based on Paul Welmsley's porting and adopt many suggestions from David Abdurachmanov.

Zong Li (6):
board: sifive: unmatched: add initial support for a platform ID EEPROM
riscv: sifive: fu740: kconfig: Enable support for Opencores I2C
controller
riscv: sifive: fu740: Support i2c in spl
board: sifive: Add an interface to get PCB revision
riscv: dts: add dts for unmatched rev1
board: sifive: support spl multi-dtb on unmatched board

 arch/riscv/cpu/fu740/Kconfig                  |    3 +
 arch/riscv/dts/Makefile                       |    2 +-
 arch/riscv/dts/fu740-c000-u-boot.dtsi         |    4 +
 .../fu740-hifive-unmatched-a00-ddr-rev1.dtsi  | 1489 +++++++++++++++++
 .../dts/hifive-unmatched-a00-rev1-u-boot.dtsi |    7 +
 arch/riscv/dts/hifive-unmatched-a00-rev1.dts  |    4 +
 arch/riscv/include/asm/arch-fu740/eeprom.h    |   15 +
 board/sifive/unmatched/Kconfig                |    1 +
 board/sifive/unmatched/Makefile               |    1 +
 .../unmatched/hifive-platform-i2c-eeprom.c    |  574 +++++++
 board/sifive/unmatched/spl.c                  |   28 +-
 configs/sifive_unmatched_defconfig            |    4 +
 include/configs/sifive-unmatched.h            |    6 +
 13 files changed, 2135 insertions(+), 3 deletions(-)
 create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr-rev1.dtsi
 create mode 100644 arch/riscv/dts/hifive-unmatched-a00-rev1-u-boot.dtsi
 create mode 100644 arch/riscv/dts/hifive-unmatched-a00-rev1.dts
 create mode 100644 arch/riscv/include/asm/arch-fu740/eeprom.h
 create mode 100644 board/sifive/unmatched/hifive-platform-i2c-eeprom.c
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/6 board: sifive: unmatched: add initial support for a platform ID EEPROM

Add initial support for the PCB description EEPROM for SiFive HiFive Unmatched boards.

This implementation is refactored based on Paul Walmsley's porting and adopt the suggestions from David Abdurachmanov.

---
 board/sifive/unmatched/Makefile               |   1 +
 .../unmatched/hifive-platform-i2c-eeprom.c    | 542 ++++++++++++++++++
 include/configs/sifive-unmatched.h            |   6 +
 3 files changed, 549 insertions(+)
 create mode 100644 board/sifive/unmatched/hifive-platform-i2c-eeprom.c
board/sifive/unmatched/Makefile +1 -0
index 6308c80d64..e00b330e8c 100644
@@ -3,6 +3,7 @@
 # Copyright (c) 2020-2021 SiFive, Inc
 
 obj-y   += unmatched.o
+obj-$(CONFIG_ID_EEPROM) += hifive-platform-i2c-eeprom.o
 
 ifdef CONFIG_SPL_BUILD
 obj-y += spl.o
board/sifive/unmatched/hifive-platform-i2c-eeprom.c new file +542 -0

542 lines not on this page · raw message

include/configs/sifive-unmatched.h +6 -0
index 4fad69bb19..9e1859cd54 100644
@@ -80,4 +80,10 @@
 	"fdt addr ${fdtcontroladdr};"
 #endif /* CONFIG_SPL_BUILD */
 
+#define CONFIG_SYS_EEPROM_BUS_NUM		0
+#define CONFIG_SYS_I2C_EEPROM_ADDR		0x54
+#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		0x1
+
+#define CONFIG_ID_EEPROM
+
 #endif /* __SIFIVE_UNMATCHED_H */
Signature · 1 line
2.31.1
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] board: sifive: unmatched: add initial support for a platform ID EEPROM

Quoted 9 lines · Zong Li

Add initial support for the PCB description EEPROM for SiFive HiFive Unmatched boards.

This implementation is refactored based on Paul Walmsley's porting and adopt the suggestions from David Abdurachmanov.

Quoted 6 lines
---
 board/sifive/unmatched/Makefile               |   1 +
 .../unmatched/hifive-platform-i2c-eeprom.c    | 542 ++++++++++++++++++
 include/configs/sifive-unmatched.h            |   6 +
 3 files changed, 549 insertions(+)
 create mode 100644 board/sifive/unmatched/hifive-platform-i2c-eeprom.c
author
#3 lore raw

PATCH 2/6 riscv: sifive: fu740: kconfig: Enable support for Opencores I2C controller

In reply to Zong Li

Enable the Opencores I2C controller on FU740

---
 arch/riscv/cpu/fu740/Kconfig   | 2 ++
 board/sifive/unmatched/Kconfig | 1 +
 2 files changed, 3 insertions(+)
arch/riscv/cpu/fu740/Kconfig +2 -0
index 3a5f6e47f5..1dc052ba31 100644
@@ -35,3 +35,5 @@ config SIFIVE_FU740
 	imply SIFIVE_OTP
 	imply DM_PWM
 	imply PWM_SIFIVE
+	imply DM_I2C
+	imply SYS_I2C_OCORES
board/sifive/unmatched/Kconfig +1 -0
index 88b5883cae..fb2c1fbb58 100644
@@ -47,5 +47,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply PHY_MSCC
 	imply SYSRESET
 	imply SYSRESET_GPIO
+	imply CMD_I2C
 
 endif
Signature · 1 line
2.31.1
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] riscv: sifive: fu740: kconfig: Enable support for Opencores I2C controller

Quoted 8 lines · Zong Li

Enable the Opencores I2C controller on FU740

---
 arch/riscv/cpu/fu740/Kconfig   | 2 ++
 board/sifive/unmatched/Kconfig | 1 +
 2 files changed, 3 insertions(+)
author
#5 lore raw

PATCH 3/6 riscv: sifive: fu740: Support i2c in spl

In reply to Zong Li

Enable SPL_I2C_SUPPORT for fu740, and add 'u-boot,dm-spl' property in i2c node.

---
 arch/riscv/cpu/fu740/Kconfig          | 1 +
 arch/riscv/dts/fu740-c000-u-boot.dtsi | 4 ++++
 2 files changed, 5 insertions(+)
arch/riscv/cpu/fu740/Kconfig +1 -0
index 1dc052ba31..8e54310b9c 100644
@@ -37,3 +37,4 @@ config SIFIVE_FU740
 	imply PWM_SIFIVE
 	imply DM_I2C
 	imply SYS_I2C_OCORES
+	imply SPL_I2C_SUPPORT
arch/riscv/dts/fu740-c000-u-boot.dtsi +4 -0
index a5d0688b06..a6f7a0873e 100644
@@ -95,6 +95,10 @@
 	u-boot,dm-spl;
 };
 
+&i2c0 {
+	u-boot,dm-spl;
+};
+
 &eth0 {
 	assigned-clocks = <&prci PRCI_CLK_GEMGXLPLL>;
 	assigned-clock-rates = <125125000>;
Signature · 1 line
2.31.1
Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] riscv: sifive: fu740: Support i2c in spl

Quoted 8 lines · Zong Li

Enable SPL_I2C_SUPPORT for fu740, and add 'u-boot,dm-spl' property in i2c node.

---
 arch/riscv/cpu/fu740/Kconfig          | 1 +
 arch/riscv/dts/fu740-c000-u-boot.dtsi | 4 ++++
 2 files changed, 5 insertions(+)
author
#7 lore raw

PATCH 4/6 board: sifive: Add an interface to get PCB revision

In reply to Zong Li

There are different DDR parameter settings for different board revisions. Add a new interface to get the PCB revision to determine which DT should be selected at runtime.

---
 arch/riscv/include/asm/arch-fu740/eeprom.h    | 15 +++++++++
 .../unmatched/hifive-platform-i2c-eeprom.c    | 32 +++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 arch/riscv/include/asm/arch-fu740/eeprom.h
arch/riscv/include/asm/arch-fu740/eeprom.h new file +15 -0
new file mode 100644
index 0000000000..0e1220e558
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 SiFive, Inc.
+ *
+ * Zong Li <[email protected]>
+ */
+
+#ifndef _ASM_RISCV_EEPROM_H
+#define _ASM_RISCV_EEPROM_H
+
+#define PCB_REVISION_REV3	0x3
+
+u8 get_pcb_revision_from_eeprom(void);
+
+#endif /* _ASM_RISCV_EEPROM_H */
board/sifive/unmatched/hifive-platform-i2c-eeprom.c +32 -0
index 9a62d32453..a2151f15e0 100644
@@ -540,3 +540,35 @@ int mac_read_from_eeprom(void)
 
 	return 0;
 }
+
+/**
+ * get_pcb_revision_from_eeprom - get the PCB revision
+ *
+ * Read the EEPROM to determine the board revision.
+ *
+ * This function is called before relocation, so we need to read a private
+ * copy of the EEPROM into a local variable on the stack.
+ */
+u8 get_pcb_revision_from_eeprom(void)
+{
+	struct __attribute__ ((__packed__)) board_eeprom {
+		u8 magic[MAGIC_NUMBER_BYTES];
+		u8 format_ver;
+		u16 product_id;
+		u8 pcb_revision;
+	} be;
+
+	int ret;
+	struct udevice *dev;
+
+	ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
+				      CONFIG_SYS_I2C_EEPROM_ADDR,
+				      1,
+				      &dev);
+
+	if (!ret)
+		dm_i2c_read(dev, 0, (void *)&be,
+			    sizeof(struct board_eeprom));
+
+	return be.pcb_revision;
+}
Signature · 1 line
2.31.1
Reviewed-by on v1 4/6
#8 lore raw

Re: [PATCH 4/6] board: sifive: Add an interface to get PCB revision

Quoted 10 lines · Zong Li

There are different DDR parameter settings for different board revisions. Add a new interface to get the PCB revision to determine which DT should be selected at runtime.

---
 arch/riscv/include/asm/arch-fu740/eeprom.h    | 15 +++++++++
 .../unmatched/hifive-platform-i2c-eeprom.c    | 32 +++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 arch/riscv/include/asm/arch-fu740/eeprom.h
author
#9 lore raw

PATCH 5/6 riscv: dts: add dts for unmatched rev1

In reply to Zong Li

The difference between unmatched rev3 and rev1 is DDR timing, the rev3 uses 1866 MT/s for 16GiB, and rev1 uses 2133 MT/s for 8GiB.

---
 arch/riscv/dts/Makefile                       |    2 +-
 .../fu740-hifive-unmatched-a00-ddr-rev1.dtsi  | 1489 +++++++++++++++++
 .../dts/hifive-unmatched-a00-rev1-u-boot.dtsi |    7 +
 arch/riscv/dts/hifive-unmatched-a00-rev1.dts  |    4 +
 4 files changed, 1501 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr-rev1.dtsi
 create mode 100644 arch/riscv/dts/hifive-unmatched-a00-rev1-u-boot.dtsi
 create mode 100644 arch/riscv/dts/hifive-unmatched-a00-rev1.dts
arch/riscv/dts/Makefile +1 -1
index 7778874831..7faeeaf664 100644
@@ -4,7 +4,7 @@ dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
 dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
 dtb-$(CONFIG_TARGET_QEMU_VIRT) += qemu-virt.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNLEASHED) += hifive-unleashed-a00.dtb
-dtb-$(CONFIG_TARGET_SIFIVE_UNMATCHED) += hifive-unmatched-a00.dtb
+dtb-$(CONFIG_TARGET_SIFIVE_UNMATCHED) += hifive-unmatched-a00.dtb hifive-unmatched-a00-rev1.dtb
 dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
 
 targets += $(dtb-y)
arch/riscv/dts/fu740-hifive-unmatched-a00-ddr-rev1.dtsi new file +1489 -0

1,489 lines not on this page · raw message

arch/riscv/dts/hifive-unmatched-a00-rev1-u-boot.dtsi new file +7 -0
new file mode 100644
index 0000000000..70c9526f90
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Copyright (C) 2021 SiFive, Inc
+ */
+
+#include "hifive-unmatched-a00-u-boot.dtsi"
+#include "fu740-hifive-unmatched-a00-ddr-rev1.dtsi"
arch/riscv/dts/hifive-unmatched-a00-rev1.dts new file +4 -0
new file mode 100644
index 0000000000..02edc4e60f
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (c) 2021 SiFive, Inc */
+
+#include "hifive-unmatched-a00.dts"
Signature · 1 line
2.31.1
Reviewed-by on v1 5/6
#10 lore raw

Re: [PATCH 5/6] riscv: dts: add dts for unmatched rev1

Quoted 4 lines · Zong Li

The difference between unmatched rev3 and rev1 is DDR timing, the rev3 uses 1866 MT/s for 16GiB, and rev1 uses 2133 MT/s for 8GiB.

Quoted 9 lines
---
 arch/riscv/dts/Makefile                       |    2 +-
 .../fu740-hifive-unmatched-a00-ddr-rev1.dtsi  | 1489 +++++++++++++++++
 .../dts/hifive-unmatched-a00-rev1-u-boot.dtsi |    7 +
 arch/riscv/dts/hifive-unmatched-a00-rev1.dts  |    4 +
 4 files changed, 1501 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr-rev1.dtsi
 create mode 100644 arch/riscv/dts/hifive-unmatched-a00-rev1-u-boot.dtsi
 create mode 100644 arch/riscv/dts/hifive-unmatched-a00-rev1.dts
author
#11 lore raw

PATCH 6/6 board: sifive: support spl multi-dtb on unmatched board

In reply to Zong Li

There are two revisions of unmatched board with different DDR timing, we'd like to support multi-dtb mechanism in SPL, then it selects the right DTB at runtime according to PCB revision in I2C EEPROM.

---
 board/sifive/unmatched/spl.c       | 28 ++++++++++++++++++++++++++--
 configs/sifive_unmatched_defconfig |  4 ++++
 2 files changed, 30 insertions(+), 2 deletions(-)
board/sifive/unmatched/spl.c +26 -2
index 5e1333b09a..74134b03ee 100644
@@ -10,11 +10,14 @@
 #include <spl.h>
 #include <misc.h>
 #include <log.h>
+#include <fdtdec.h>
+#include <dm/root.h>
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <asm/gpio.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/spl.h>
+#include <asm/arch/eeprom.h>
 
 #define GEM_PHY_RESET	SIFIVE_GENERIC_GPIO_NR(0, 12)
 
@@ -26,6 +29,16 @@ int spl_board_init_f(void)
 {
 	int ret;
 
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
+	int rescan;
+
+	ret = fdtdec_resetup(&rescan);
+	if (!ret && rescan) {
+		dm_uninit();
+		dm_init_and_scan(true);
+	}
+#endif
+
 	ret = spl_soc_init();
 	if (ret) {
 		debug("HiFive Unmatched FU740 SPL init failed: %d\n", ret);
@@ -79,7 +92,18 @@ u32 spl_boot_device(void)
 #ifdef CONFIG_SPL_LOAD_FIT
 int board_fit_config_name_match(const char *name)
 {
-	/* boot using first FIT config */
-	return 0;
+	/*
+	 * Apply different DDR params on different board revision.
+	 * Use PCB revision which is byte 0x7 in I2C platform EEPROM
+	 * to distinguish that.
+	 */
+	if (get_pcb_revision_from_eeprom() == PCB_REVISION_REV3 &&
+	    !strcmp(name, "hifive-unmatched-a00"))
+		return 0;
+	else if (get_pcb_revision_from_eeprom() != PCB_REVISION_REV3 &&
+		 !strcmp(name, "hifive-unmatched-a00-rev1"))
+		return 0;
+
+	return -1;
 }
 #endif
configs/sifive_unmatched_defconfig +4 -0
index 4c26504867..74b59738cd 100644
@@ -40,3 +40,7 @@ CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_PCI=y
+CONFIG_SPL_MULTI_DTB_FIT=y
+CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y
+CONFIG_SPL_OF_LIST="hifive-unmatched-a00 hifive-unmatched-a00-rev1"
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x100000
Signature · 1 line
2.31.1
Reviewed-by on v1 6/6
#12 lore raw

Re: [PATCH 6/6] board: sifive: support spl multi-dtb on unmatched board

Quoted 9 lines · Zong Li

There are two revisions of unmatched board with different DDR timing, we'd like to support multi-dtb mechanism in SPL, then it selects the right DTB at runtime according to PCB revision in I2C EEPROM.

---
 board/sifive/unmatched/spl.c       | 28 ++++++++++++++++++++++++++--
 configs/sifive_unmatched_defconfig |  4 ++++
 2 files changed, 30 insertions(+), 2 deletions(-)