mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] arm64: rockchip: Add support for QNAP's ts-433 4bay NAS
@ 2025-07-19 17:47 Uwe Kleine-König
  2025-07-22 16:42 ` Ahmad Fatoum
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2025-07-19 17:47 UTC (permalink / raw)
  To: barebox

The resulting image boots to a prompt using usb booting or when booting
from eMMC. Networking and USB are working.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
Hello,

some time ago I sent (implicit) v1, see
https://lore.barebox.org/cover.1740846737.git.uwe@kleine-koenig.org

In the meantime some changes to the upstream dts were applied making
this patch smaller. Also I learned that I have to unfit the boot jumper
to have a working eMMC. Also networking is functional now, see the
comment in arch/arm/dts/rk3568-qnap-ts433.dts about the workaround.

Functional changes:

 - Configure the front USB plug to gadget mode when booted from USB or
   when the copy button is pressed during bootup and disable autoboot.
 - Enabled deep probe

Thanks to the fine rk3568 base support this was an easy journey to
create a powerful bootloader for my NAS. Thanks!

Best regards
Uwe

 Documentation/boards/rockchip.rst      |  1 +
 arch/arm/boards/Makefile               |  1 +
 arch/arm/boards/qnap-tsx33/.gitignore  |  1 +
 arch/arm/boards/qnap-tsx33/Makefile    |  3 ++
 arch/arm/boards/qnap-tsx33/board.c     | 73 ++++++++++++++++++++++++++
 arch/arm/boards/qnap-tsx33/lowlevel.c  | 27 ++++++++++
 arch/arm/configs/rockchip_v8_defconfig |  1 +
 arch/arm/dts/Makefile                  |  1 +
 arch/arm/dts/rk3568-qnap-ts433.dts     | 26 +++++++++
 arch/arm/mach-rockchip/Kconfig         |  7 +++
 images/Makefile.rockchip               |  1 +
 11 files changed, 142 insertions(+)
 create mode 100644 arch/arm/boards/qnap-tsx33/.gitignore
 create mode 100644 arch/arm/boards/qnap-tsx33/Makefile
 create mode 100644 arch/arm/boards/qnap-tsx33/board.c
 create mode 100644 arch/arm/boards/qnap-tsx33/lowlevel.c
 create mode 100644 arch/arm/dts/rk3568-qnap-ts433.dts

diff --git a/Documentation/boards/rockchip.rst b/Documentation/boards/rockchip.rst
index 8bce92865e3e..d8a371079fab 100644
--- a/Documentation/boards/rockchip.rst
+++ b/Documentation/boards/rockchip.rst
@@ -61,6 +61,7 @@ Supported Boards
 - Pine64 Quartz64 Model A
 - Radxa ROCK3 Model A
 - Radxa CM3 (RK3566) IO Board
+- QNAP TS-433 NAS
 - Protonic MECSBC
 
 The steps described in the following target the RK3568 and the RK3568 EVB but
diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index ac1fa74d4c03..b686f8305e96 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -96,6 +96,7 @@ obj-$(CONFIG_MACH_PROTONIC_STM32MP1)		+= protonic-stm32mp1/
 obj-$(CONFIG_MACH_PROTONIC_STM32MP13)		+= protonic-stm32mp13/
 obj-$(CONFIG_MACH_QIL_A9260)			+= qil-a926x/
 obj-$(CONFIG_MACH_QIL_A9G20)			+= qil-a926x/
+obj-$(CONFIG_MACH_QNAP_TSX33)			+= qnap-tsx33/
 obj-$(CONFIG_MACH_RADXA_ROCK)			+= radxa-rock/
 obj-$(CONFIG_MACH_PHYTEC_SOM_RK3288)		+= phytec-som-rk3288/
 obj-$(CONFIG_MACH_REALQ7)			+= datamodul-edm-qmx6/
diff --git a/arch/arm/boards/qnap-tsx33/.gitignore b/arch/arm/boards/qnap-tsx33/.gitignore
new file mode 100644
index 000000000000..f458f794b54c
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/.gitignore
@@ -0,0 +1 @@
+sdram-init.bin
diff --git a/arch/arm/boards/qnap-tsx33/Makefile b/arch/arm/boards/qnap-tsx33/Makefile
new file mode 100644
index 000000000000..1d052d28c9fc
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+lwl-y += lowlevel.o
+obj-y += board.o
diff --git a/arch/arm/boards/qnap-tsx33/board.c b/arch/arm/boards/qnap-tsx33/board.c
new file mode 100644
index 000000000000..2611f7a6a9bf
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/board.c
@@ -0,0 +1,73 @@
+#include <common.h>
+#include <gpio.h>
+#include <init.h>
+#include <mach/rockchip/bbu.h>
+#include <bootsource.h>
+#include <environment.h>
+#include <globalvar.h>
+#include <magicvar.h>
+#include <deep-probe.h>
+
+static int ts433_usb_device_mode(void)
+{
+	struct device_node *node;
+
+	/* &usb_host0_xhci */
+	node = of_find_node_by_path("/usb@fcc00000");
+	if (!node)
+		return -ENODEV;
+
+	return of_property_write_string(node, "dr_mode", "peripheral");
+}
+
+static int ts433_probe(struct device *dev)
+{
+	enum bootsource bootsource = bootsource_get();
+	int copy_button_pressed = !gpio_get_value(14);
+
+	barebox_set_model("QNAP TS-433");
+	barebox_set_hostname("ts433");
+
+	if (bootsource == BOOTSOURCE_USB || copy_button_pressed) {
+		/*
+		 * Configure the front USB socket to USB device (i.e. like the
+		 * ROM when booting from USB. Add gadget support equivalent to
+		 * usbgadget -b -A "kernel(kernel)c,initramfs(initramfs)c,dtb(dtb)" -a
+		 */
+		ts433_usb_device_mode();
+		globalvar_add_simple("usbgadget.autostart", "1");
+		globalvar_add_simple("fastboot.bbu", "1");
+		globalvar_add_simple("fastboot.partitions", "kernel(kernel)c,initramfs(initramfs)c,dtb(dtb)c");
+		globalvar_add_simple("usbgadget.acm", "1");
+
+		/*
+		 * exit to a shell, also to give the user the chance to open the
+		 * console on USB.
+		 */
+		globalvar_add_simple("autoboot", "abort");
+
+		/*
+		 * Don't use emmc to result in a working state even with a
+		 * borked environment.
+		 */
+		of_device_disable_path("/chosen/environment-emmc");
+	}
+
+	rockchip_bbu_mmc_register("emmc", BBU_HANDLER_FLAG_DEFAULT, "/dev/mmc0");
+
+	return 0;
+}
+
+static const struct of_device_id ts433_of_match[] = {
+        { .compatible = "qnap,ts433" },
+        { /* Sentinel */},
+};
+
+static struct driver ts433_board_driver = {
+        .name = "board-ts433",
+        .probe = ts433_probe,
+        .of_compatible = ts433_of_match,
+};
+coredevice_platform_driver(ts433_board_driver);
+
+BAREBOX_DEEP_PROBE_ENABLE(ts433_of_match);
diff --git a/arch/arm/boards/qnap-tsx33/lowlevel.c b/arch/arm/boards/qnap-tsx33/lowlevel.c
new file mode 100644
index 000000000000..f852e8d00a2b
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/lowlevel.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <common.h>
+#include <linux/sizes.h>
+#include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
+#include <mach/rockchip/hardware.h>
+#include <mach/rockchip/atf.h>
+#include <debug_ll.h>
+#include <mach/rockchip/rockchip.h>
+
+extern char __dtb_rk3568_qnap_ts433_start[];
+
+ENTRY_FUNCTION(start_rk3568_qnap_ts433, r0, r1, r2)
+{
+	/*
+	 * Image execution starts at 0x0, but this is used for ATF and
+	 * OP-TEE later, so move away from here.
+	 */
+	if (current_el() == 3)
+		relocate_to_adr_full(RK3568_BAREBOX_LOAD_ADDRESS);
+	else
+		relocate_to_current_adr();
+
+	setup_c();
+
+	rk3568_barebox_entry(__dtb_rk3568_qnap_ts433_start);
+}
diff --git a/arch/arm/configs/rockchip_v8_defconfig b/arch/arm/configs/rockchip_v8_defconfig
index cc8481cc3cb9..16dbc095d4b3 100644
--- a/arch/arm/configs/rockchip_v8_defconfig
+++ b/arch/arm/configs/rockchip_v8_defconfig
@@ -4,6 +4,7 @@ CONFIG_MACH_RK3568_BPI_R2PRO=y
 CONFIG_MACH_PINE64_PINETAB2=y
 CONFIG_MACH_PINE64_QUARTZ64=y
 CONFIG_MACH_PROTONIC_MECSBC=y
+CONFIG_MACH_QNAP_TSX33=y
 CONFIG_MACH_RADXA_ROCK3=y
 CONFIG_MACH_RADXA_ROCK5=y
 CONFIG_MACH_RADXA_CM3=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 6612a5145231..77630ec20441 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -122,6 +122,7 @@ lwl-$(CONFIG_MACH_PROTONIC_STM32MP1) += \
 lwl-$(CONFIG_MACH_PROTONIC_STM32MP13) += \
 	stm32mp133c-mect1s.dtb.o \
 	stm32mp133c-prihmb.dtb.o
+lwl-$(CONFIG_MACH_QNAP_TSX33) += rk3568-qnap-ts433.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK) += rk3188-radxarock.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK3) += rk3568-rock-3a.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK5) += rk3588-rock-5b.dtb.o
diff --git a/arch/arm/dts/rk3568-qnap-ts433.dts b/arch/arm/dts/rk3568-qnap-ts433.dts
new file mode 100644
index 000000000000..5ab0220c28d7
--- /dev/null
+++ b/arch/arm/dts/rk3568-qnap-ts433.dts
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
+
+/dts-v1/;
+#include <arm64/rockchip/rk3568-qnap-ts433.dts>
+#include "rk356x.dtsi"
+
+/ {
+	chosen: chosen {
+		environment-emmc {
+			compatible = "barebox,environment";
+			device-path = &sdhci, "partname:barebox-environment";
+		};
+	};
+};
+
+&gmac0 {
+	/*
+	 * The Linux device tree uses rgmii-id and that also works iff the
+	 * matching phy driver (motorcomm) is available. The barebox motorcomm
+	 * driver however doesn't support the used phy (Motorcomm YT8521) yet
+	 * and so we have to stick to rgmii and explicit delays for now.
+	 */
+	phy-mode = "rgmii";
+	tx_delay = <0x3c>;
+	rx_delay = <0x2f>;
+};
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index d172522c6f63..138966e8f91f 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -95,6 +95,13 @@ config MACH_PROTONIC_MECSBC
 	help
 	  Say Y here if you are using a Protonic MECSBC
 
+config MACH_QNAP_TSX33
+	select ARCH_RK3568
+	bool "QNAP TS-433 NAS"
+	help
+	  Select this if you are using a QNAP TS-433 NAS.
+	  <https://www.qnap.com/en-us/product/ts-433>
+
 config MACH_RADXA_ROCK3
 	select ARCH_RK3568
 	bool "Radxa ROCK3"
diff --git a/images/Makefile.rockchip b/images/Makefile.rockchip
index 761c6b814989..2e63e554edce 100644
--- a/images/Makefile.rockchip
+++ b/images/Makefile.rockchip
@@ -35,6 +35,7 @@ $(call build_rockchip_image, CONFIG_MACH_PINE64_PINETAB2, start_pinetab2_v0, pin
 $(call build_rockchip_image, CONFIG_MACH_PINE64_PINETAB2, start_pinetab2_v2, pine64-pinetab2/sdram-init.bin, pinetab2-v2)
 $(call build_rockchip_image, CONFIG_MACH_PINE64_QUARTZ64, start_quartz64a, pine64-quartz64/sdram-init.bin, quartz64a)
 $(call build_rockchip_image, CONFIG_MACH_PROTONIC_MECSBC, start_mecsbc, protonic-mecsbc/sdram-init.bin, mecsbc)
+$(call build_rockchip_image, CONFIG_MACH_QNAP_TSX33, start_rk3568_qnap_ts433, qnap-tsx33/sdram-init.bin, qnap-ts433)
 $(call build_rockchip_image, CONFIG_MACH_RADXA_ROCK3, start_rock3a, radxa-rock3/sdram-init.bin, rock3a)
 $(call build_rockchip_image, CONFIG_MACH_RADXA_ROCK5, start_rock5b, radxa-rock5/sdram-init.bin, rock5b)
 $(call build_rockchip_image, CONFIG_MACH_RADXA_CM3, start_radxa_cm3_io, radxa-cm3/sdram-init.bin, radxa-cm3-io)

base-commit: 89bf1fcc998fc5fea0ce613d9930dd9ee39c0fb2
prerequisite-patch-id: bb15d0704d716658c1773d9be53b1e0734b94b16
-- 
2.50.0




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] arm64: rockchip: Add support for QNAP's ts-433 4bay NAS
  2025-07-19 17:47 [PATCH v2] arm64: rockchip: Add support for QNAP's ts-433 4bay NAS Uwe Kleine-König
@ 2025-07-22 16:42 ` Ahmad Fatoum
  0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2025-07-22 16:42 UTC (permalink / raw)
  To: Uwe Kleine-König, barebox

Hello Uwe,

On 7/19/25 19:47, Uwe Kleine-König wrote:
> The resulting image boots to a prompt using usb booting or when booting
> from eMMC. Networking and USB are working.

Cool stuff!

My comments below.

> Thanks to the fine rk3568 base support this was an easy journey to
> create a powerful bootloader for my NAS. Thanks!

Glad to hear. :)

> diff --git a/arch/arm/boards/qnap-tsx33/board.c b/arch/arm/boards/qnap-tsx33/board.c
> new file mode 100644
> index 000000000000..2611f7a6a9bf
> --- /dev/null
> +++ b/arch/arm/boards/qnap-tsx33/board.c
> @@ -0,0 +1,73 @@
> +#include <common.h>
> +#include <gpio.h>
> +#include <init.h>
> +#include <mach/rockchip/bbu.h>
> +#include <bootsource.h>
> +#include <environment.h>
> +#include <globalvar.h>
> +#include <magicvar.h>
> +#include <deep-probe.h>
> +
> +static int ts433_usb_device_mode(void)
> +{
> +	struct device_node *node;
> +
> +	/* &usb_host0_xhci */
> +	node = of_find_node_by_path("/usb@fcc00000");
> +	if (!node)
> +		return -ENODEV;
> +
> +	return of_property_write_string(node, "dr_mode", "peripheral");
> +}
> +
> +static int ts433_probe(struct device *dev)
> +{
> +	enum bootsource bootsource = bootsource_get();
> +	int copy_button_pressed = !gpio_get_value(14);

You need to ensure the GPIO controller is probed before you try to get
the GPIO, e.g. by calling

  of_devices_ensure_probed_by_property("gpio-controller");

first.

My preference would be using the input API for this though.

Define a gpio-keys node in the DT, wire the GPIO and then call:

  of_devices_ensure_probed_by_compatible("gpio-keys");
  input_key_get_status(keys, KEY_COPY);

For an example, see commit e44d472d128d ("ARM: boards: protonic-imx6:
prtvt7: Use the input system for key detection").


> +	barebox_set_model("QNAP TS-433");
> +	barebox_set_hostname("ts433");
> +
> +	if (bootsource == BOOTSOURCE_USB || copy_button_pressed) {
> +		/*
> +		 * Configure the front USB socket to USB device (i.e. like the
> +		 * ROM when booting from USB. Add gadget support equivalent to
> +		 * usbgadget -b -A "kernel(kernel)c,initramfs(initramfs)c,dtb(dtb)" -a
> +		 */
> +		ts433_usb_device_mode();

If you set dr_mode = "otg" in the device tree, you can just do
otg.mode=peripheral/host in barebox without having to mess with DT directly.

> +		globalvar_add_simple("usbgadget.autostart", "1");

Conceptually, this should be at the end, because it activate the
feature. It doesn't matter here though, I think, because it's only
evaluated later on.

> +		globalvar_add_simple("fastboot.bbu", "1");
> +		globalvar_add_simple("fastboot.partitions", "kernel(kernel)c,initramfs(initramfs)c,dtb(dtb)c");
> +		globalvar_add_simple("usbgadget.acm", "1");

These could have been a built-in init script, but both are fine I guess.

> +		/*
> +		 * exit to a shell, also to give the user the chance to open the
> +		 * console on USB.
> +		 */
> +		globalvar_add_simple("autoboot", "abort");

You could instead set a higher count down time, so a mistaken press
during startup will eventually boot still. For actual flashing use,
first fastboot command or console input will abort the countdown anyway.

> +
> +		/*
> +		 * Don't use emmc to result in a working state even with a
> +		 * borked environment.
> +		 */
> +		of_device_disable_path("/chosen/environment-emmc");

You will want to call globalvar_set("env.autoprobe", "0") as well, so
environment isn't autoprobed by Type UUID.

Cheers,
Ahmad

> +	}
> +
> +	rockchip_bbu_mmc_register("emmc", BBU_HANDLER_FLAG_DEFAULT, "/dev/mmc0");
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id ts433_of_match[] = {
> +        { .compatible = "qnap,ts433" },
> +        { /* Sentinel */},
> +};
> +
> +static struct driver ts433_board_driver = {
> +        .name = "board-ts433",
> +        .probe = ts433_probe,
> +        .of_compatible = ts433_of_match,
> +};
> +coredevice_platform_driver(ts433_board_driver);
> +
> +BAREBOX_DEEP_PROBE_ENABLE(ts433_of_match);
> diff --git a/arch/arm/boards/qnap-tsx33/lowlevel.c b/arch/arm/boards/qnap-tsx33/lowlevel.c
> new file mode 100644
> index 000000000000..f852e8d00a2b


> --- /dev/null
> +++ b/arch/arm/dts/rk3568-qnap-ts433.dts
> @@ -0,0 +1,26 @@
> +// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
> +
> +/dts-v1/;
> +#include <arm64/rockchip/rk3568-qnap-ts433.dts>
> +#include "rk356x.dtsi"
> +
> +/ {
> +	chosen: chosen {
> +		environment-emmc {
> +			compatible = "barebox,environment";
> +			device-path = &sdhci, "partname:barebox-environment";
> +		};
> +	};

If you choose 6C3737F2-07F8-45D1-AD45-15D260AAB24D as GPT partition type
UUID, barebox should automatically choose it as environment partition.

This would allow you to drop this node completely.

> +};
> +
> +&gmac0 {
> +	/*
> +	 * The Linux device tree uses rgmii-id and that also works iff the
> +	 * matching phy driver (motorcomm) is available. The barebox motorcomm
> +	 * driver however doesn't support the used phy (Motorcomm YT8521) yet
> +	 * and so we have to stick to rgmii and explicit delays for now.
> +	 */

Fair enough.

> +	phy-mode = "rgmii";
> +	tx_delay = <0x3c>;
> +	rx_delay = <0x2f>;
> +};

Cheers,
Ahmad

-- 
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 |




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-22 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-19 17:47 [PATCH v2] arm64: rockchip: Add support for QNAP's ts-433 4bay NAS Uwe Kleine-König
2025-07-22 16:42 ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox