Skip to contentSkip to conversation

Added support for Digilent Cora Z7 board

PATCH In review Johannes Roith 2 participants 4 messages May 16, 2025 – May 19, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Added support for Digilent Cora Z7 board

This patch adds support for the Digilent Cora Z7 board to barebox.

This patch includes a PBL initializing the DDR memory and the most important hardware and barebox proper which is loaded from the mmc but uses network boot as the default boot source. mmc boot is also working.

This patch only brings support for booting the PS side, loading a bitstream on the PL side is nit supported.

---
 arch/arm/boards/Makefile                      |   1 +
 arch/arm/boards/digilent-cora/Makefile        |   4 +
 arch/arm/boards/digilent-cora/board.c         |  33 ++
 arch/arm/boards/digilent-cora/cora.zynqcfg    |   4 +
 .../env/nv/linux.bootargs.console             |   1 +
 arch/arm/boards/digilent-cora/lowlevel.c      | 296 ++++++++++++++++++
 arch/arm/configs/zynq_defconfig               |   1 +
 arch/arm/dts/Makefile                         |   1 +
 arch/arm/dts/zynq-cora-linux.dts              |  62 ++++
 arch/arm/dts/zynq-cora.dts                    |  29 ++
 arch/arm/mach-zynq/Kconfig                    |   5 +
 images/Makefile.zynq                          |   6 +
 12 files changed, 443 insertions(+)
 create mode 100644 arch/arm/boards/digilent-cora/Makefile
 create mode 100644 arch/arm/boards/digilent-cora/board.c
 create mode 100644 arch/arm/boards/digilent-cora/cora.zynqcfg
 create mode 100644 arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console
 create mode 100644 arch/arm/boards/digilent-cora/lowlevel.c
 create mode 100644 arch/arm/dts/zynq-cora-linux.dts
 create mode 100644 arch/arm/dts/zynq-cora.dts
arch/arm/boards/Makefile +1 -0
index 908497cd8b..fcf4d393a1 100644
@@ -154,6 +154,7 @@ obj-$(CONFIG_MACH_USI_TOPKICK)			+= usi-topkick/
 obj-$(CONFIG_MACH_VERSATILEPB)			+= versatile/
 obj-$(CONFIG_MACH_VEXPRESS)			+= vexpress/
 obj-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard/
+obj-$(CONFIG_MACH_CORA_Z7)			+= digilent-cora/
 obj-$(CONFIG_MACH_VARISCITE_MX6)		+= variscite-mx6/
 obj-$(CONFIG_MACH_VARISCITE_SOM_MX7)		+= variscite-som-mx7/
 obj-$(CONFIG_MACH_VSCOM_BALTOS)			+= vscom-baltos/
arch/arm/boards/digilent-cora/Makefile new file +4 -0
new file mode 100644
index 0000000000..d653aa1f4b
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y += board.o
+lwl-y += lowlevel.o
arch/arm/boards/digilent-cora/board.c new file +33 -0
new file mode 100644
index 0000000000..1e70137352
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2025 Johannes Roith <[email protected]>
+
+#include <asm/armlinux.h>
+#include <bbu.h>
+#include <common.h>
+#include <environment.h>
+#include <asm/mach-types.h>
+#include <init.h>
+#include <mach/zynq/zynq7000-regs.h>
+#include <linux/sizes.h>
+#include <deep-probe.h>
+
+static int cora_probe(struct device *dev)
+{
+	barebox_set_hostname("cora");
+
+	return bbu_register_std_file_update("SD", BBU_HANDLER_FLAG_DEFAULT,
+				     "/boot/BOOT.bin", filetype_zynq_image);
+}
+
+static const struct of_device_id cora_of_match[] = {
+	{ .compatible = "xlnx,zynq-cora" },
+	{ /* sentinel */ },
+};
+BAREBOX_DEEP_PROBE_ENABLE(cora_of_match);
+
+static struct driver cora_board_driver = {
+	.name = "board-digilent-cora",
+	.probe = cora_probe,
+	.of_compatible = cora_of_match,
+};
+coredevice_platform_driver(cora_board_driver);
arch/arm/boards/digilent-cora/cora.zynqcfg new file +4 -0
new file mode 100644
index 0000000000..8e68bbf618
@@ -0,0 +1,4 @@
+#include <zynq/zynq7000-header-regs.h>
+
+/* stop */
+wm 32 0xFFFFFFFF			0x00000000
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console new file +1 -0
new file mode 100644
index 0000000000..903e90f870
@@ -0,0 +1 @@
+console=ttyPS1,115200 root=/dev/mmcblk0p2 rootwait
arch/arm/boards/digilent-cora/lowlevel.c new file +296 -0

296 lines not on this page · raw message

arch/arm/configs/zynq_defconfig +1 -0
index 1a1378d3e0..71bc5eaba7 100644
@@ -1,5 +1,6 @@
 CONFIG_ARCH_ZYNQ=y
 CONFIG_MACH_ZEDBOARD=y
+CONFIG_MACH_CORA_Z7=y
 CONFIG_AEABI=y
 CONFIG_ARM_UNWIND=y
 CONFIG_IMAGE_COMPRESSION_XZKERN=y
arch/arm/dts/Makefile +1 -0
index 3044c9bf12..8ba6385bd6 100644
@@ -240,6 +240,7 @@ lwl-$(CONFIG_MACH_LS1046ARDB) += fsl-ls1046a-rdb.dtb.o
 lwl-$(CONFIG_MACH_TQMLS1046A) += fsl-ls1046a-tqmls1046a-mbls10xxa.dtb.o
 lwl-$(CONFIG_MACH_LS1021AIOT) += fsl-ls1021a-iot.dtb.o
 lwl-$(CONFIG_MACH_ZEDBOARD) += zynq-zed.dtb.o
+lwl-$(CONFIG_MACH_CORA_Z7) += zynq-cora.dtb.o
 lwl-$(CONFIG_MACH_MNT_REFORM) += imx8mq-mnt-reform2.dtb.o
 lwl-$(CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP) += imx8mp-var-dart-dt8mcustomboard.dtb.o
 lwl-$(CONFIG_MACH_TQMA93XX) += imx93-tqma9352-mba93xxca.dtb.o \
arch/arm/dts/zynq-cora-linux.dts new file +62 -0

62 lines not on this page · raw message

arch/arm/dts/zynq-cora.dts new file +29 -0
new file mode 100644
index 0000000000..4375e840a6
@@ -0,0 +1,29 @@
+#include "zynq-cora-linux.dts"
+#include "zynq-7000.dtsi"
+
+/ {
+	chosen {
+		stdout-path = &uart0;
+
+		environment-sd {
+			compatible = "barebox,environment";
+			device-path = &sdhci0, "partname:0";
+			file-path = "barebox.env";
+		};
+	};
+};
+
+&clkc {
+	ps-clk-frequency = <50000000>;
+};
+
+&sdhci0 {
+	bootph-all;
+	bus-width = <4>;
+	status = "okay";
+};
+
+&uart0 {
+	bootph-all;
+	status = "okay";
+};
arch/arm/mach-zynq/Kconfig +5 -0
index 1d6218d407..936e41f1fc 100644
@@ -5,6 +5,7 @@ if ARCH_ZYNQ
 config ZYNQ_DEBUG_LL_UART_BASE
 	hex
 	default 0xe0001000 if MACH_ZEDBOARD
+	default 0xe0000000 if MACH_CORA_Z7
 
 config ARCH_ZYNQ7000
 	bool
@@ -22,6 +23,10 @@ config MACH_ZEDBOARD
 	bool "Avnet Zynq-7000 ZedBoard"
 	select ARCH_ZYNQ7000
 
+config MACH_CORA_Z7
+	bool "Digilent Cora Z7"
+	select ARCH_ZYNQ7000
+
 endmenu
 
 endif
images/Makefile.zynq +4 -0
index ac9ce8157b..b2a584bb15 100644
@@ -22,3 +22,7 @@ $(obj)/%.zynqimg: $(obj)/% FORCE
 CFG_start_avnet_zedboard.pblb.zynqimg = $(board)/avnet-zedboard/zedboard.zynqcfg
 FILE_barebox-avnet-zedboard.img = start_avnet_zedboard.pblb.zynqimg
 image-$(CONFIG_MACH_ZEDBOARD) += barebox-avnet-zedboard.img
+
+CFG_start_digilent_cora.pblb.zynqimg = $(board)/digilent-cora/cora.zynqcfg
+FILE_barebox-digilent-cora.img = start_digilent_cora.pblb.zynqimg
+image-$(CONFIG_MACH_CORA_Z7) += barebox-digilent-cora.img
Signature · 1 line
2.34.1
#1 lore raw

Hello Johannes,

Quoted 5 lines · Johannes Roith

This patch adds support for the Digilent Cora Z7 board to barebox.

This patch includes a PBL initializing the DDR memory and the most important hardware and barebox proper which is loaded from the mmc but uses network boot as the default boot source.

For your information, the next barebox release will have a different boot.default value by default: "bootsource net". If your SoC support sets the bootsource correctly that means that it will look for bootloader spec entries for example on your SD-Card before falling back to the net boot.

Quoted 1 line

mmc boot is also working.

How much on-chip SRAM do you have? I am wondering about the absence of MMC bootstrap code in your PBL. Is your barebox small enough that it fits into the SRAM?

Quoted 2 lines

This patch only brings support for booting the PS side, loading a bitstream on the PL side is nit supported.

Nit: s/nit/not/ ;)

Quoted 57 lines
---
 arch/arm/boards/Makefile                      |   1 +
 arch/arm/boards/digilent-cora/Makefile        |   4 +
 arch/arm/boards/digilent-cora/board.c         |  33 ++
 arch/arm/boards/digilent-cora/cora.zynqcfg    |   4 +
 .../env/nv/linux.bootargs.console             |   1 +
 arch/arm/boards/digilent-cora/lowlevel.c      | 296 ++++++++++++++++++
 arch/arm/configs/zynq_defconfig               |   1 +
 arch/arm/dts/Makefile                         |   1 +
 arch/arm/dts/zynq-cora-linux.dts              |  62 ++++
 arch/arm/dts/zynq-cora.dts                    |  29 ++
 arch/arm/mach-zynq/Kconfig                    |   5 +
 images/Makefile.zynq                          |   6 +
 12 files changed, 443 insertions(+)
 create mode 100644 arch/arm/boards/digilent-cora/Makefile
 create mode 100644 arch/arm/boards/digilent-cora/board.c
 create mode 100644 arch/arm/boards/digilent-cora/cora.zynqcfg
 create mode 100644 arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console
 create mode 100644 arch/arm/boards/digilent-cora/lowlevel.c
 create mode 100644 arch/arm/dts/zynq-cora-linux.dts
 create mode 100644 arch/arm/dts/zynq-cora.dts
arch/arm/boards/Makefile +1 -0
index 908497cd8b..fcf4d393a1 100644
@@ -154,6 +154,7 @@ obj-$(CONFIG_MACH_USI_TOPKICK)			+= usi-topkick/
 obj-$(CONFIG_MACH_VERSATILEPB)			+= versatile/
 obj-$(CONFIG_MACH_VEXPRESS)			+= vexpress/
 obj-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard/
+obj-$(CONFIG_MACH_CORA_Z7)			+= digilent-cora/
 obj-$(CONFIG_MACH_VARISCITE_MX6)		+= variscite-mx6/
 obj-$(CONFIG_MACH_VARISCITE_SOM_MX7)		+= variscite-som-mx7/
 obj-$(CONFIG_MACH_VSCOM_BALTOS)			+= vscom-baltos/
arch/arm/boards/digilent-cora/Makefile new file +4 -0
new file mode 100644
index 0000000000..d653aa1f4b
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y += board.o
+lwl-y += lowlevel.o
arch/arm/boards/digilent-cora/board.c new file +6 -0
new file mode 100644
index 0000000000..1e70137352
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2025 Johannes Roith <[email protected]>
+
+#include <asm/armlinux.h>
+#include <bbu.h>
+#include <common.h>

arch/arm/boards/digilent-cora/board.c line 16

Quoted 10 lines
arch/arm/boards/digilent-cora/board.c new file +10 -0
+#include <environment.h>
+#include <asm/mach-types.h>
+#include <init.h>
+#include <mach/zynq/zynq7000-regs.h>
+#include <linux/sizes.h>
+#include <deep-probe.h>
+
+static int cora_probe(struct device *dev)
+{
+	barebox_set_hostname("cora");

The name would already be zynq-cora by default. If that's ok with you, I wouldn't change it.

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 1 line
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +0 -0

The environment is unreferenced. You can use bbenv- to compile in environment without having to reference it in the config. This should be preferred over setting it in the Kconfig as that allows you to build a config with multiple board and only apply the env when appropriate (by calling defaultenv_append_directory in the board driver).

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 10 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +10 -0
+static void cora_z7_ps7_init(void)
+{
+	/*
+	 * Read OCM mapping configuration, if only the upper 64 KByte are
+	 * mapped to the high address, it's very likely that we just got control
+	 * from the BootROM. If the mapping is changed something other than the
+	 * BootROM was running before us. Skip PS7 init to avoid cutting the
+	 * branch we are sitting on in that case.
+	 */
+	if ((readl(0xf8000910) & 0xf) != 0x8)

Please use a macro for the address and wrap it in IOMEM(). Eventually, we will want to enforce addresses to be pointers, so it would be cool for new code to already use the correct types. If you want type checking, just add

#include <linux/io.h> at the top of your includes.

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 3 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +3 -0
+		return;
+	/* Do something!!! */
+	/* open sesame */

Is there some stuff that's generic enough here that we would want it in mach-zynq instead?

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 6 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +6 -0
+	/* pinmux: UART0 RxD: MIO_PIN_14, TxD: MIO_PIN_15 */
+	writel(0x000006E1, ZYNQ_MIO_BASE + 0x38);
+	writel(0x000006E0, ZYNQ_MIO_BASE + 0x3C);
+
+	/* set UART Clock to 50 MHz */
+	writel(0x00001403, ZYNQ_CLOCK_CTRL_BASE + ZYNQ_UART_CLK_CTRL);

I'd move that into cora_z7_pbl_console_init if you don't need it unconditionally. If it's needed outside of PBL_CONSOLE, I think clock and pinctrl drivers in barebox should already take care of it?

Quoted 8 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +8 -0
+
+	/* GEM0 */
+	writel(0x00000001, 0xf8000138);
+	writel(0x00100801, 0xf8000140);
+	writel(0x00000302, 0xf8000740);
+	writel(0x00000302, 0xf8000744);
+	writel(0x00000302, 0xf8000748);
+	writel(0x00000302, 0xf800074C);

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 10 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +10 -0
+	writel(0x00000302, 0xf8000750);
+	writel(0x00000302, 0xf8000754);
+	writel(0x00001303, 0xf8000758);
+	writel(0x00001303, 0xf800075C);
+	writel(0x00001303, 0xf8000760);
+	writel(0x00001303, 0xf8000764);
+	writel(0x00001303, 0xf8000768);
+	writel(0x00001303, 0xf800076C);
+	writel(0x00000280, 0xf80007D0);
+	writel(0x00000280, 0xf80007D4);

What are you doing to the MAC here?

Quoted 4 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +4 -0
+ENTRY_FUNCTION_WITHSTACK(start_digilent_cora, 0xfffff000, r0, r1, r2)
+{
+	/* MIO_07 in GPIO Mode 3.3V VIO, can be uncomented because it is the default value */
+	writel(0x0000DF0D, ZYNQ_SLCR_UNLOCK);

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 10 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +10 -0
+	writel(0x00000600, 0xF800071C);
+	writel(0x0000767B, ZYNQ_SLCR_LOCK);
+
+	zynq_cpu_lowlevel_init();
+
+	cora_z7_ps7_init();
+
+	relocate_to_current_adr();
+	setup_c();
+	barrier();

You don't need the barrier().

Quoted 50 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +6 -0
+
+	if (IS_ENABLED(CONFIG_PBL_CONSOLE))
+		cora_z7_pbl_console_init();
+
+	barebox_arm_entry(0, SZ_512M, __dtb_z_zynq_cora_start);
+}
arch/arm/configs/zynq_defconfig +1 -0
index 1a1378d3e0..71bc5eaba7 100644
@@ -1,5 +1,6 @@
 CONFIG_ARCH_ZYNQ=y
 CONFIG_MACH_ZEDBOARD=y
+CONFIG_MACH_CORA_Z7=y
 CONFIG_AEABI=y
 CONFIG_ARM_UNWIND=y
 CONFIG_IMAGE_COMPRESSION_XZKERN=y
arch/arm/dts/Makefile +1 -0
index 3044c9bf12..8ba6385bd6 100644
@@ -240,6 +240,7 @@ lwl-$(CONFIG_MACH_LS1046ARDB) += fsl-ls1046a-rdb.dtb.o
 lwl-$(CONFIG_MACH_TQMLS1046A) += fsl-ls1046a-tqmls1046a-mbls10xxa.dtb.o
 lwl-$(CONFIG_MACH_LS1021AIOT) += fsl-ls1021a-iot.dtb.o
 lwl-$(CONFIG_MACH_ZEDBOARD) += zynq-zed.dtb.o
+lwl-$(CONFIG_MACH_CORA_Z7) += zynq-cora.dtb.o
 lwl-$(CONFIG_MACH_MNT_REFORM) += imx8mq-mnt-reform2.dtb.o
 lwl-$(CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP) += imx8mp-var-dart-dt8mcustomboard.dtb.o
 lwl-$(CONFIG_MACH_TQMA93XX) += imx93-tqma9352-mba93xxca.dtb.o \
arch/arm/dts/zynq-cora-linux.dts new file +15 -0
new file mode 100644
index 0000000000..a75837011f
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Copyright (C) 2011 - 2014 Xilinx
+ *  Copyright (C) 2012 National Instruments Corp.
+ */
+/dts-v1/;
+#include <arm/xilinx/zynq-7000.dtsi>
+
+/ {
+	model = "Digilent Cora Z7";
+	compatible = "digilent,zynq-cora", "xlnx,zynq-cora", "xlnx,zynq-7000";
+
+	aliases {
+		ethernet0 = &gem0;
+		serial0 = &uart0;

arch/arm/dts/zynq-cora-linux.dts line 25

Quoted 10 lines
arch/arm/dts/zynq-cora-linux.dts new file +10 -0
+		mmc0 = &sdhci0;
+	};
+
+	memory@0 {
+		device_type = "memory";
+		reg = <0x0 0x20000000>;
+	};
+
+	chosen {
+		bootargs = "";

This is unnecessary, I think.

arch/arm/dts/zynq-cora-linux.dts line 29

Quoted 4 lines
arch/arm/dts/zynq-cora-linux.dts new file +4 -0
+		stdout-path = "serial0:115200n8";
+	};
+
+	usb_phy0: phy0 {

If you upstream this, you'll be probably told that you should use a descriptive node name.

Quoted 6 lines
arch/arm/dts/zynq-cora-linux.dts new file +6 -0
+		compatible = "usb-nop-xceiv";
+		#phy-cells = <0>;
+	};
+};
+
+&clkc {

arch/arm/dts/zynq-cora-linux.dts line 45

Quoted 10 lines
arch/arm/dts/zynq-cora-linux.dts new file +10 -0
+	ps-clk-frequency = <50000000>;
+};
+
+&gem0 {
+	status = "okay";
+	phy-mode = "rgmii-id";
+	phy-handle = <&ethernet_phy>;
+
+	ethernet_phy: ethernet-phy@0 {
+		reg = <0>;

Is 0 really your PHY address or does it just work by virtue of being the broadcast address? Just wondering.

Quoted 23 lines
arch/arm/dts/zynq-cora-linux.dts new file +17 -0
+		device_type = "ethernet-phy";
+	};
+};
+
+&sdhci0 {
+	status = "okay";
+};
+
+&uart0 {
+	status = "okay";
+};
+
+&usb0 {
+	status = "okay";
+	dr_mode = "host";
+	usb-phy = <&usb_phy0>;
+};
arch/arm/dts/zynq-cora.dts new file +0 -0
new file mode 100644
index 0000000000..4375e840a6

arch/arm/dts/zynq-cora.dts line 6

Quoted 6 lines
arch/arm/dts/zynq-cora.dts new file +6 -0
@@ -0,0 +1,29 @@
+#include "zynq-cora-linux.dts"
+#include "zynq-7000.dtsi"
+
+/ {
+	chosen {
+		stdout-path = &uart0;

Why overwrite what's in the Linux DTS?

arch/arm/dts/zynq-cora.dts line 17

Quoted 11 lines
arch/arm/dts/zynq-cora.dts new file +11 -0
+
+		environment-sd {
+			compatible = "barebox,environment";
+			device-path = &sdhci0, "partname:0";
+			file-path = "barebox.env";
+		};
+	};
+};
+
+&clkc {
+	ps-clk-frequency = <50000000>;

Why duplicate?

arch/arm/dts/zynq-cora.dts line 21

Quoted 4 lines
arch/arm/dts/zynq-cora.dts new file +4 -0
+};
+
+&sdhci0 {
+	bootph-all;

Unparsed by barebox.

arch/arm/dts/zynq-cora.dts line 22

Quoted 1 line
arch/arm/dts/zynq-cora.dts new file +1 -0
+	bus-width = <4>;

It's a SD-Card, so it can't be more than 4 bit. Just drop it.

Quoted 20 lines
arch/arm/dts/zynq-cora.dts new file +7 -0
+	status = "okay";
+};
+
+&uart0 {
+	bootph-all;
+	status = "okay";
+};
arch/arm/mach-zynq/Kconfig +1 -0
index 1d6218d407..936e41f1fc 100644
@@ -5,6 +5,7 @@ if ARCH_ZYNQ
 config ZYNQ_DEBUG_LL_UART_BASE
 	hex
 	default 0xe0001000 if MACH_ZEDBOARD
+	default 0xe0000000 if MACH_CORA_Z7
 
 config ARCH_ZYNQ7000
 	bool

arch/arm/mach-zynq/Kconfig config MACH_ZEDBOARD · line 28

Quoted 6 lines
arch/arm/mach-zynq/Kconfig +3 -0
@@ -22,6 +23,10 @@ config MACH_ZEDBOARD
 	bool "Avnet Zynq-7000 ZedBoard"
 	select ARCH_ZYNQ7000
 
+config MACH_CORA_Z7
+	bool "Digilent Cora Z7"
+	select ARCH_ZYNQ7000

Can you enable this in zynq_defconfig?

Cheers,
Ahmad

Quoted 16 lines
arch/arm/mach-zynq/Kconfig +1 -0
+
 endmenu
 
 endif
images/Makefile.zynq +4 -0
index ac9ce8157b..b2a584bb15 100644
@@ -22,3 +22,7 @@ $(obj)/%.zynqimg: $(obj)/% FORCE
 CFG_start_avnet_zedboard.pblb.zynqimg = $(board)/avnet-zedboard/zedboard.zynqcfg
 FILE_barebox-avnet-zedboard.img = start_avnet_zedboard.pblb.zynqimg
 image-$(CONFIG_MACH_ZEDBOARD) += barebox-avnet-zedboard.img
+
+CFG_start_digilent_cora.pblb.zynqimg = $(board)/digilent-cora/cora.zynqcfg
+FILE_barebox-digilent-cora.img = start_digilent_cora.pblb.zynqimg
+image-$(CONFIG_MACH_CORA_Z7) += barebox-digilent-cora.img
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#2 lore raw

Hello Ahmad,

thanks for your feedback.

Am Fri, May 16, 2025 at 10:05:49PM +0200 schrieb Ahmad Fatoum:

Quoted 14 lines

Hello Johannes,

Quoted 5 lines · Johannes Roith

This patch adds support for the Digilent Cora Z7 board to barebox.

This patch includes a PBL initializing the DDR memory and the most important hardware and barebox proper which is loaded from the mmc but uses network boot as the default boot source.

For your information, the next barebox release will have a different boot.default value by default: "bootsource net". If your SoC support sets the bootsource correctly that means that it will look for bootloader spec entries for example on your SD-Card before falling back to the net boot.

Quoted 5 lines
Quoted 1 line

mmc boot is also working.

How much on-chip SRAM do you have? I am wondering about the absence of MMC bootstrap code in your PBL. Is your barebox small enough that it fits into the SRAM?

It is 256kByte and it seems barebox PBL and proper is copied both into the SRAM. If I select too much commands in the config, I am getting the error that barebox is to big to fit in the OCM RAM.

Quoted 5 lines
Quoted 3 lines

This patch only brings support for booting the PS side, loading a bitstream on the PL side is nit supported.

Nit: s/nit/not/ ;)

Oops, will be fixed in Patch v2 ;)

Quoted 63 lines
Quoted 63 lines
---
 arch/arm/boards/Makefile                      |   1 +
 arch/arm/boards/digilent-cora/Makefile        |   4 +
 arch/arm/boards/digilent-cora/board.c         |  33 ++
 arch/arm/boards/digilent-cora/cora.zynqcfg    |   4 +
 .../env/nv/linux.bootargs.console             |   1 +
 arch/arm/boards/digilent-cora/lowlevel.c      | 296 ++++++++++++++++++
 arch/arm/configs/zynq_defconfig               |   1 +
 arch/arm/dts/Makefile                         |   1 +
 arch/arm/dts/zynq-cora-linux.dts              |  62 ++++
 arch/arm/dts/zynq-cora.dts                    |  29 ++
 arch/arm/mach-zynq/Kconfig                    |   5 +
 images/Makefile.zynq                          |   6 +
 12 files changed, 443 insertions(+)
 create mode 100644 arch/arm/boards/digilent-cora/Makefile
 create mode 100644 arch/arm/boards/digilent-cora/board.c
 create mode 100644 arch/arm/boards/digilent-cora/cora.zynqcfg
 create mode 100644 arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console
 create mode 100644 arch/arm/boards/digilent-cora/lowlevel.c
 create mode 100644 arch/arm/dts/zynq-cora-linux.dts
 create mode 100644 arch/arm/dts/zynq-cora.dts
arch/arm/boards/Makefile +1 -0
index 908497cd8b..fcf4d393a1 100644
@@ -154,6 +154,7 @@ obj-$(CONFIG_MACH_USI_TOPKICK)			+= usi-topkick/
 obj-$(CONFIG_MACH_VERSATILEPB)			+= versatile/
 obj-$(CONFIG_MACH_VEXPRESS)			+= vexpress/
 obj-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard/
+obj-$(CONFIG_MACH_CORA_Z7)			+= digilent-cora/
 obj-$(CONFIG_MACH_VARISCITE_MX6)		+= variscite-mx6/
 obj-$(CONFIG_MACH_VARISCITE_SOM_MX7)		+= variscite-som-mx7/
 obj-$(CONFIG_MACH_VSCOM_BALTOS)			+= vscom-baltos/
arch/arm/boards/digilent-cora/Makefile new file +4 -0
new file mode 100644
index 0000000000..d653aa1f4b
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y += board.o
+lwl-y += lowlevel.o
arch/arm/boards/digilent-cora/board.c new file +11 -0
new file mode 100644
index 0000000000..1e70137352
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2025 Johannes Roith <[email protected]>
+
+#include <asm/armlinux.h>
+#include <bbu.h>
+#include <common.h>
+#include <environment.h>
+#include <asm/mach-types.h>
+#include <init.h>
+#include <mach/zynq/zynq7000-regs.h>
+#include <linux/sizes.h>
Quoted 8 lines

arch/arm/boards/digilent-cora/board.c line 16

Quoted 5 lines
arch/arm/boards/digilent-cora/board.c new file +5 -0
+#include <deep-probe.h>
+
+static int cora_probe(struct device *dev)
+{
+	barebox_set_hostname("cora");

The name would already be zynq-cora by default. If that's ok with you, I wouldn't change it.

I will remove it.

Quoted 25 lines

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 2 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +0 -0

The environment is unreferenced. You can use bbenv- to compile in environment without having to reference it in the config. This should be preferred over setting it in the Kconfig as that allows you to build a config with multiple board and only apply the env when appropriate (by calling defaultenv_append_directory in the board driver).

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 10 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +10 -0
+static void cora_z7_ps7_init(void)
+{
+	/*
+	 * Read OCM mapping configuration, if only the upper 64 KByte are
+	 * mapped to the high address, it's very likely that we just got control
+	 * from the BootROM. If the mapping is changed something other than the
+	 * BootROM was running before us. Skip PS7 init to avoid cutting the
+	 * branch we are sitting on in that case.
+	 */
+	if ((readl(0xf8000910) & 0xf) != 0x8)

Please use a macro for the address and wrap it in IOMEM(). Eventually, we will want to enforce addresses to be pointers, so it would be cool for new code to already use the correct types. If you want type checking, just add

Quoted 2 lines

#include <linux/io.h> at the top of your includes.

So, it should look like this, right:

void __iomem *ocm_config = IOMEM(OCM_CFG);

if ((readl(ocm_config) != 0x8)

Quoted 6 lines

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 3 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +3 -0
+		return;
+	/* Do something!!! */
+	/* open sesame */

Is there some stuff that's generic enough here that we would want it in mach-zynq instead?

Hmm, good question. In theory most of the code is generic or could be implemted in functions in mach-zynq and the lowlevel board just calls these functions with the correct arguments, e.g. the DDR init. But that way it is quite time consuming to implement. This here is basically just copy paste from a Vitis generated code adopted to the coding style of barebox.

Quoted 11 lines

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 7 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +6 -0
+	/* pinmux: UART0 RxD: MIO_PIN_14, TxD: MIO_PIN_15 */
+	writel(0x000006E1, ZYNQ_MIO_BASE + 0x38);
+	writel(0x000006E0, ZYNQ_MIO_BASE + 0x3C);
+
+	/* set UART Clock to 50 MHz */
+	writel(0x00001403, ZYNQ_CLOCK_CTRL_BASE + ZYNQ_UART_CLK_CTRL);

I'd move that into cora_z7_pbl_console_init if you don't need it unconditionally. If it's needed outside of PBL_CONSOLE, I think clock and pinctrl drivers in barebox should already take care of it?

There is a clock control driver in barebox but I could not find a pinctrl driver. Also the pinctrl for ZYNQ is quite a lot to configure in the device tree:

https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/xlnx%2Czynq-pinctrl.txt

Quoted 13 lines
Quoted 13 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +12 -0
+
+	/* GEM0 */
+	writel(0x00000001, 0xf8000138);
+	writel(0x00100801, 0xf8000140);
+	writel(0x00000302, 0xf8000740);
+	writel(0x00000302, 0xf8000744);
+	writel(0x00000302, 0xf8000748);
+	writel(0x00000302, 0xf800074C);
+	writel(0x00000302, 0xf8000750);
+	writel(0x00000302, 0xf8000754);
+	writel(0x00001303, 0xf8000758);
+	writel(0x00001303, 0xf800075C);
Quoted 8 lines

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 6 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +6 -0
+	writel(0x00001303, 0xf8000760);
+	writel(0x00001303, 0xf8000764);
+	writel(0x00001303, 0xf8000768);
+	writel(0x00001303, 0xf800076C);
+	writel(0x00000280, 0xf80007D0);
+	writel(0x00000280, 0xf80007D4);

What are you doing to the MAC here?

Copy paste error from Zed Board. I think this is not needed here.

Quoted 17 lines
Quoted 5 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +4 -0
+ENTRY_FUNCTION_WITHSTACK(start_digilent_cora, 0xfffff000, r0, r1, r2)
+{
+	/* MIO_07 in GPIO Mode 3.3V VIO, can be uncomented because it is the default value */
+	writel(0x0000DF0D, ZYNQ_SLCR_UNLOCK);

arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console

Quoted 10 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +10 -0
+	writel(0x00000600, 0xF800071C);
+	writel(0x0000767B, ZYNQ_SLCR_LOCK);
+
+	zynq_cpu_lowlevel_init();
+
+	cora_z7_ps7_init();
+
+	relocate_to_current_adr();
+	setup_c();
+	barrier();

You don't need the barrier().

Thanks, got it.

Quoted 55 lines
Quoted 55 lines
arch/arm/boards/digilent-cora/env/nv/linux.bootargs.console +6 -0
+
+	if (IS_ENABLED(CONFIG_PBL_CONSOLE))
+		cora_z7_pbl_console_init();
+
+	barebox_arm_entry(0, SZ_512M, __dtb_z_zynq_cora_start);
+}
arch/arm/configs/zynq_defconfig +1 -0
index 1a1378d3e0..71bc5eaba7 100644
@@ -1,5 +1,6 @@
 CONFIG_ARCH_ZYNQ=y
 CONFIG_MACH_ZEDBOARD=y
+CONFIG_MACH_CORA_Z7=y
 CONFIG_AEABI=y
 CONFIG_ARM_UNWIND=y
 CONFIG_IMAGE_COMPRESSION_XZKERN=y
arch/arm/dts/Makefile +1 -0
index 3044c9bf12..8ba6385bd6 100644
@@ -240,6 +240,7 @@ lwl-$(CONFIG_MACH_LS1046ARDB) += fsl-ls1046a-rdb.dtb.o
 lwl-$(CONFIG_MACH_TQMLS1046A) += fsl-ls1046a-tqmls1046a-mbls10xxa.dtb.o
 lwl-$(CONFIG_MACH_LS1021AIOT) += fsl-ls1021a-iot.dtb.o
 lwl-$(CONFIG_MACH_ZEDBOARD) += zynq-zed.dtb.o
+lwl-$(CONFIG_MACH_CORA_Z7) += zynq-cora.dtb.o
 lwl-$(CONFIG_MACH_MNT_REFORM) += imx8mq-mnt-reform2.dtb.o
 lwl-$(CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP) += imx8mp-var-dart-dt8mcustomboard.dtb.o
 lwl-$(CONFIG_MACH_TQMA93XX) += imx93-tqma9352-mba93xxca.dtb.o \
arch/arm/dts/zynq-cora-linux.dts new file +19 -0
new file mode 100644
index 0000000000..a75837011f
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Copyright (C) 2011 - 2014 Xilinx
+ *  Copyright (C) 2012 National Instruments Corp.
+ */
+/dts-v1/;
+#include <arm/xilinx/zynq-7000.dtsi>
+
+/ {
+	model = "Digilent Cora Z7";
+	compatible = "digilent,zynq-cora", "xlnx,zynq-cora", "xlnx,zynq-7000";
+
+	aliases {
+		ethernet0 = &gem0;
+		serial0 = &uart0;
+		mmc0 = &sdhci0;
+	};
+
+	memory@0 {
Quoted 8 lines

arch/arm/dts/zynq-cora-linux.dts line 25

Quoted 6 lines
arch/arm/dts/zynq-cora-linux.dts new file +6 -0
+		device_type = "memory";
+		reg = <0x0 0x20000000>;
+	};
+
+	chosen {
+		bootargs = "";

This is unnecessary, I think.

I will remove it.

Quoted 8 lines

arch/arm/dts/zynq-cora-linux.dts line 29

Quoted 5 lines
arch/arm/dts/zynq-cora-linux.dts new file +4 -0
+		stdout-path = "serial0:115200n8";
+	};
+
+	usb_phy0: phy0 {

If you upstream this, you'll be probably told that you should use a descriptive node name.

Ok, I will change it. But it is only a copy of the zedboard dt adopted to the Digilent board ;)

Quoted 12 lines
Quoted 12 lines
arch/arm/dts/zynq-cora-linux.dts new file +11 -0
+		compatible = "usb-nop-xceiv";
+		#phy-cells = <0>;
+	};
+};
+
+&clkc {
+	ps-clk-frequency = <50000000>;
+};
+
+&gem0 {
+	status = "okay";
Quoted 8 lines

arch/arm/dts/zynq-cora-linux.dts line 45

Quoted 5 lines
arch/arm/dts/zynq-cora-linux.dts new file +5 -0
+	phy-mode = "rgmii-id";
+	phy-handle = <&ethernet_phy>;
+
+	ethernet_phy: ethernet-phy@0 {
+		reg = <0>;

Is 0 really your PHY address or does it just work by virtue of being the broadcast address? Just wondering.

Yes, according to ethtool the PHY SMI address is really 0.

Quoted 24 lines
Quoted 24 lines
arch/arm/dts/zynq-cora-linux.dts new file +17 -0
+		device_type = "ethernet-phy";
+	};
+};
+
+&sdhci0 {
+	status = "okay";
+};
+
+&uart0 {
+	status = "okay";
+};
+
+&usb0 {
+	status = "okay";
+	dr_mode = "host";
+	usb-phy = <&usb_phy0>;
+};
arch/arm/dts/zynq-cora.dts new file +0 -0
new file mode 100644
index 0000000000..4375e840a6
@@ -0,0 +1,29 @@
Quoted 8 lines

arch/arm/dts/zynq-cora.dts line 6

Quoted 6 lines
arch/arm/dts/zynq-cora.dts new file +6 -0
+#include "zynq-cora-linux.dts"
+#include "zynq-7000.dtsi"
+
+/ {
+	chosen {
+		stdout-path = &uart0;

Why overwrite what's in the Linux DTS?

I will remove it.

Quoted 15 lines

arch/arm/dts/zynq-cora.dts line 17

Quoted 12 lines
arch/arm/dts/zynq-cora.dts new file +11 -0
+
+		environment-sd {
+			compatible = "barebox,environment";
+			device-path = &sdhci0, "partname:0";
+			file-path = "barebox.env";
+		};
+	};
+};
+
+&clkc {
+	ps-clk-frequency = <50000000>;

Why duplicate?

I will remove it.

Quoted 7 lines

arch/arm/dts/zynq-cora.dts line 21

Quoted 4 lines
arch/arm/dts/zynq-cora.dts new file +4 -0
+};
+
+&sdhci0 {
+	bootph-all;

Unparsed by barebox.

I will remove it.

Quoted 4 lines

arch/arm/dts/zynq-cora.dts line 22

Quoted 1 line
arch/arm/dts/zynq-cora.dts new file +1 -0
+	bus-width = <4>;

It's a SD-Card, so it can't be more than 4 bit. Just drop it.

I will remove it.

Quoted 23 lines
Quoted 23 lines
arch/arm/dts/zynq-cora.dts new file +7 -0
+	status = "okay";
+};
+
+&uart0 {
+	bootph-all;
+	status = "okay";
+};
arch/arm/mach-zynq/Kconfig +1 -0
index 1d6218d407..936e41f1fc 100644
@@ -5,6 +5,7 @@ if ARCH_ZYNQ
 config ZYNQ_DEBUG_LL_UART_BASE
 	hex
 	default 0xe0001000 if MACH_ZEDBOARD
+	default 0xe0000000 if MACH_CORA_Z7
 
 config ARCH_ZYNQ7000
 	bool
@@ -22,6 +23,10 @@ config MACH_ZEDBOARD
 	bool "Avnet Zynq-7000 ZedBoard"
 	select ARCH_ZYNQ7000
 
Quoted 5 lines

arch/arm/mach-zynq/Kconfig config MACH_ZEDBOARD · line 28

Quoted 3 lines
arch/arm/mach-zynq/Kconfig +3 -0
+config MACH_CORA_Z7
+	bool "Digilent Cora Z7"
+	select ARCH_ZYNQ7000

Can you enable this in zynq_defconfig?

Yes, it is selectable in the config.

Quoted 27 lines

Cheers,
Ahmad

Quoted 16 lines
arch/arm/mach-zynq/Kconfig +1 -0
+
 endmenu
 
 endif
images/Makefile.zynq +4 -0
index ac9ce8157b..b2a584bb15 100644
@@ -22,3 +22,7 @@ $(obj)/%.zynqimg: $(obj)/% FORCE
 CFG_start_avnet_zedboard.pblb.zynqimg = $(board)/avnet-zedboard/zedboard.zynqcfg
 FILE_barebox-avnet-zedboard.img = start_avnet_zedboard.pblb.zynqimg
 image-$(CONFIG_MACH_ZEDBOARD) += barebox-avnet-zedboard.img
+
+CFG_start_digilent_cora.pblb.zynqimg = $(board)/digilent-cora/cora.zynqcfg
+FILE_barebox-digilent-cora.img = start_digilent_cora.pblb.zynqimg
+image-$(CONFIG_MACH_CORA_Z7) += barebox-digilent-cora.img
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#3 lore raw

Hi,

Quoted 17 lines · Johannes Roith

Am Fri, May 16, 2025 at 10:05:49PM +0200 schrieb Ahmad Fatoum:

Quoted 16 lines

arch/arm/boards/digilent-cora/lowlevel.c line 29

Quoted 10 lines
arch/arm/boards/digilent-cora/lowlevel.c new file +10 -0
+static void cora_z7_ps7_init(void)
+{
+	/*
+	 * Read OCM mapping configuration, if only the upper 64 KByte are
+	 * mapped to the high address, it's very likely that we just got control
+	 * from the BootROM. If the mapping is changed something other than the
+	 * BootROM was running before us. Skip PS7 init to avoid cutting the
+	 * branch we are sitting on in that case.
+	 */
+	if ((readl(0xf8000910) & 0xf) != 0x8)

Please use a macro for the address and wrap it in IOMEM(). Eventually, we will want to enforce addresses to be pointers, so it would be cool for new code to already use the correct types. If you want type checking, just add

Quoted 6 lines
Quoted 2 lines

#include <linux/io.h> at the top of your includes.

So, it should look like this, right:

void __iomem *ocm_config = IOMEM(OCM_CFG);

Or just #define OCM_CFG IOMEM(0xf8000910).

Quoted 6 lines

Hmm, good question. In theory most of the code is generic or could be implemted in functions in mach-zynq and the lowlevel board just calls these functions with the correct arguments, e.g. the DDR init. But that way it is quite time consuming to implement. This here is basically just copy paste from a Vitis generated code adopted to the coding style of barebox.

Ok. If the code is generated anyways, then it's fine to duplicate it IMO. You could also keep the generated code in a separate file and define some macros to make changes to it minimal, but this is fine too.

Quoted 7 lines
Quoted 5 lines

arch/arm/mach-zynq/Kconfig config MACH_ZEDBOARD · line 28

Quoted 3 lines
arch/arm/mach-zynq/Kconfig +3 -0
+config MACH_CORA_Z7
+	bool "Digilent Cora Z7"
+	select ARCH_ZYNQ7000

Can you enable this in zynq_defconfig?

Yes, it is selectable in the config.

Add it to the defconfigs (arch/arm/configs) that enable CONFIG_MACH_ZEDBOARD.

Cheers,
Ahmad

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |