From 9fef9d457eebbb2c505986ef0a7eb34998f84cc9 Mon Sep 17 00:00:00 2001 From: Liangbin Lian Date: Wed, 11 Jun 2025 17:05:26 +0800 Subject: [PATCH] uboot-rockchip: add rk3582 support Signed-off-by: Liangbin Lian --- package/boot/uboot-rockchip/Makefile | 2 +- .../201-backport-rk3588-checkboard.patch | 120 ++++++++++++ .../202-pending-1-rk3582-support.patch | 176 ++++++++++++++++++ .../202-pending-2-rk3582-support.patch | 44 +++++ .../patches/203-rk3582-disable-bad-vpu.patch | 78 ++++++++ .../204-rk3582-unlock-good-big-cores.patch | 28 +++ .../src/configs/easepi-rk3588_defconfig | 1 + 7 files changed, 448 insertions(+), 1 deletion(-) create mode 100644 package/boot/uboot-rockchip/patches/201-backport-rk3588-checkboard.patch create mode 100644 package/boot/uboot-rockchip/patches/202-pending-1-rk3582-support.patch create mode 100644 package/boot/uboot-rockchip/patches/202-pending-2-rk3582-support.patch create mode 100644 package/boot/uboot-rockchip/patches/203-rk3582-disable-bad-vpu.patch create mode 100644 package/boot/uboot-rockchip/patches/204-rk3582-unlock-good-big-cores.patch diff --git a/package/boot/uboot-rockchip/Makefile b/package/boot/uboot-rockchip/Makefile index cb8efcf07e..3ef5a01025 100644 --- a/package/boot/uboot-rockchip/Makefile +++ b/package/boot/uboot-rockchip/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_VERSION:=2024.10 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_HASH:=b28daf4ac17e43156363078bf510297584137f6df50fced9b12df34f61a92fb0 PKG_MAINTAINER:=Sarah Maedel diff --git a/package/boot/uboot-rockchip/patches/201-backport-rk3588-checkboard.patch b/package/boot/uboot-rockchip/patches/201-backport-rk3588-checkboard.patch new file mode 100644 index 0000000000..900d0afffe --- /dev/null +++ b/package/boot/uboot-rockchip/patches/201-backport-rk3588-checkboard.patch @@ -0,0 +1,120 @@ +From 46fcbfcbc1fffbfefd75a5ba186e6bb56f27b859 Mon Sep 17 00:00:00 2001 +From: Jonas Karlman +Date: Sun, 10 Nov 2024 00:56:16 +0000 +Subject: [PATCH] rockchip: rk3588: Implement checkboard() to print SoC variant + +Implement checkboard() to print current SoC model used by a board, +e.g. one of: + + SoC: RK3582 + SoC: RK3588 + SoC: RK3588J + SoC: RK3588S + SoC: RK3588S2 + +when U-Boot proper is running. + + U-Boot 2025.01-rc1 (Nov 10 2024 - 00:31:29 +0000) + + Model: Generic RK3588S/RK3588 + SoC: RK3588S2 + DRAM: 8 GiB + +Information about the SoC model and variant is read from OTP. + +Also update rk3588s-u-boot.dtsi to include OTP in U-Boot pre-reloc phase, +where checkboard() is called. + +Signed-off-by: Jonas Karlman +Tested-by: FUKAUMI Naoki +Reviewed-by: Kever Yang +--- + arch/arm/dts/rk3588s-u-boot.dtsi | 4 ++ + arch/arm/mach-rockchip/rk3588/rk3588.c | 52 ++++++++++++++++++++++++++ + 2 files changed, 56 insertions(+) + +diff --git a/arch/arm/dts/rk3588s-u-boot.dtsi b/arch/arm/dts/rk3588s-u-boot.dtsi +index 09d8b311cec..8880d162b11 100644 +--- a/arch/arm/dts/rk3588s-u-boot.dtsi ++++ b/arch/arm/dts/rk3588s-u-boot.dtsi +@@ -69,6 +69,10 @@ + bootph-all; + }; + ++&otp { ++ bootph-some-ram; ++}; ++ + &pcfg_pull_down { + bootph-all; + }; +diff --git a/arch/arm/mach-rockchip/rk3588/rk3588.c b/arch/arm/mach-rockchip/rk3588/rk3588.c +index d3162d3447e..84a9ed6611c 100644 +--- a/arch/arm/mach-rockchip/rk3588/rk3588.c ++++ b/arch/arm/mach-rockchip/rk3588/rk3588.c +@@ -4,6 +4,10 @@ + * Copyright (c) 2022 Edgeble AI Technologies Pvt. Ltd. + */ + ++#define LOG_CATEGORY LOGC_ARCH ++ ++#include ++#include + #include + #include + #include +@@ -178,3 +182,51 @@ int arch_cpu_init(void) + return 0; + } + #endif ++ ++#define RK3588_OTP_CPU_CODE_OFFSET 0x02 ++#define RK3588_OTP_SPECIFICATION_OFFSET 0x06 ++ ++int checkboard(void) ++{ ++ u8 cpu_code[2], specification, package; ++ struct udevice *dev; ++ char suffix[3]; ++ int ret; ++ ++ if (!IS_ENABLED(CONFIG_ROCKCHIP_OTP) || !CONFIG_IS_ENABLED(MISC)) ++ return 0; ++ ++ ret = uclass_get_device_by_driver(UCLASS_MISC, ++ DM_DRIVER_GET(rockchip_otp), &dev); ++ if (ret) { ++ log_debug("Could not find otp device, ret=%d\n", ret); ++ return 0; ++ } ++ ++ /* cpu-code: SoC model, e.g. 0x35 0x82 or 0x35 0x88 */ ++ ret = misc_read(dev, RK3588_OTP_CPU_CODE_OFFSET, cpu_code, 2); ++ if (ret < 0) { ++ log_debug("Could not read cpu-code, ret=%d\n", ret); ++ return 0; ++ } ++ ++ /* specification: SoC variant, e.g. 0xA for RK3588J and 0x13 for RK3588S */ ++ ret = misc_read(dev, RK3588_OTP_SPECIFICATION_OFFSET, &specification, 1); ++ if (ret < 0) { ++ log_debug("Could not read specification, ret=%d\n", ret); ++ return 0; ++ } ++ /* package: likely SoC variant revision, 0x2 for RK3588S2 */ ++ package = specification >> 5; ++ specification &= 0x1f; ++ ++ /* for RK3588J i.e. '@' + 0xA = 'J' */ ++ suffix[0] = specification > 1 ? '@' + specification : '\0'; ++ /* for RK3588S2 i.e. '0' + 0x2 = '2' */ ++ suffix[1] = package > 1 ? '0' + package : '\0'; ++ suffix[2] = '\0'; ++ ++ printf("SoC: RK%02x%02x%s\n", cpu_code[0], cpu_code[1], suffix); ++ ++ return 0; ++} +-- +2.46.0 + diff --git a/package/boot/uboot-rockchip/patches/202-pending-1-rk3582-support.patch b/package/boot/uboot-rockchip/patches/202-pending-1-rk3582-support.patch new file mode 100644 index 0000000000..0452d89dd7 --- /dev/null +++ b/package/boot/uboot-rockchip/patches/202-pending-1-rk3582-support.patch @@ -0,0 +1,176 @@ +From d432653975cf1f4f738addde721e50ebaa4c0065 Mon Sep 17 00:00:00 2001 +From: Jonas Karlman +Date: Tue, 10 Dec 2024 22:23:35 +0000 +Subject: [PATCH] rockchip: Add initial RK3582 support + +The RK3582 SoC is a variant of the RK3588S with some IP blocks disabled. +What blocks are disabled/non-working is indicated by ip-state in OTP. + +This add initial support for RK3582 by using ft_system_setup() to mark +any cpu and/or gpu node with status=fail as indicated by ip-state. + +This apply same policy as vendor U-Boot for RK3582, i.e. two big cpu +cores and the gpu is always failed/disabled. + +Enable Kconfig option OF_SYSTEM_SETUP in board defconfig to make use of +the required DT fixups for RK3582 board variants. + +Signed-off-by: Jonas Karlman +Tested-by: FUKAUMI Naoki +--- + arch/arm/mach-rockchip/rk3588/rk3588.c | 128 +++++++++++++++++++++++++ + 1 file changed, 128 insertions(+) + +diff --git a/arch/arm/mach-rockchip/rk3588/rk3588.c b/arch/arm/mach-rockchip/rk3588/rk3588.c +index 84a9ed6611c..1e660cc24d4 100644 +--- a/arch/arm/mach-rockchip/rk3588/rk3588.c ++++ b/arch/arm/mach-rockchip/rk3588/rk3588.c +@@ -7,6 +7,7 @@ + #define LOG_CATEGORY LOGC_ARCH + + #include ++#include + #include + #include + #include +@@ -185,6 +186,12 @@ int arch_cpu_init(void) + + #define RK3588_OTP_CPU_CODE_OFFSET 0x02 + #define RK3588_OTP_SPECIFICATION_OFFSET 0x06 ++#define RK3588_OTP_IP_STATE_OFFSET 0x1d ++ ++#define BAD_CPU_CLUSTER0 GENMASK(3, 0) ++#define BAD_CPU_CLUSTER1 GENMASK(5, 4) ++#define BAD_CPU_CLUSTER2 GENMASK(7, 6) ++#define BAD_GPU GENMASK(4, 1) + + int checkboard(void) + { +@@ -230,3 +237,124 @@ int checkboard(void) + + return 0; + } ++ ++#ifdef CONFIG_OF_SYSTEM_SETUP ++static int fdt_path_del_node(void *fdt, const char *path) ++{ ++ int nodeoffset; ++ ++ nodeoffset = fdt_path_offset(fdt, path); ++ if (nodeoffset < 0) ++ return nodeoffset; ++ ++ return fdt_del_node(fdt, nodeoffset); ++} ++ ++static int fdt_path_set_name(void *fdt, const char *path, const char *name) ++{ ++ int nodeoffset; ++ ++ nodeoffset = fdt_path_offset(fdt, path); ++ if (nodeoffset < 0) ++ return nodeoffset; ++ ++ return fdt_set_name(fdt, nodeoffset, name); ++} ++ ++int ft_system_setup(void *blob, struct bd_info *bd) ++{ ++ static const char * const cpu_node_names[] = { ++ "cpu@0", "cpu@100", "cpu@200", "cpu@300", ++ "cpu@400", "cpu@500", "cpu@600", "cpu@700", ++ }; ++ u8 cpu_code[2], ip_state[3]; ++ int parent, node, i, ret; ++ struct udevice *dev; ++ ++ if (!IS_ENABLED(CONFIG_ROCKCHIP_OTP) || !CONFIG_IS_ENABLED(MISC)) ++ return -ENOSYS; ++ ++ ret = uclass_get_device_by_driver(UCLASS_MISC, ++ DM_DRIVER_GET(rockchip_otp), &dev); ++ if (ret) { ++ log_debug("Could not find otp device, ret=%d\n", ret); ++ return ret; ++ } ++ ++ /* cpu-code: SoC model, e.g. 0x35 0x82 or 0x35 0x88 */ ++ ret = misc_read(dev, RK3588_OTP_CPU_CODE_OFFSET, cpu_code, 2); ++ if (ret < 0) { ++ log_debug("Could not read cpu-code, ret=%d\n", ret); ++ return ret; ++ } ++ ++ log_debug("cpu-code: %02x %02x\n", cpu_code[0], cpu_code[1]); ++ ++ /* skip on rk3588 */ ++ if (cpu_code[0] == 0x35 && cpu_code[1] == 0x88) ++ return 0; ++ ++ ret = misc_read(dev, RK3588_OTP_IP_STATE_OFFSET, &ip_state, 3); ++ if (ret < 0) { ++ log_debug("Could not read ip-state, ret=%d\n", ret); ++ return ret; ++ } ++ ++ log_debug("ip-state: %02x %02x %02x\n", ++ ip_state[0], ip_state[1], ip_state[2]); ++ ++ if (cpu_code[0] == 0x35 && cpu_code[1] == 0x82) { ++ /* policy: always disable gpu */ ++ ip_state[1] |= BAD_GPU; ++ ++ /* policy: always disable one big core cluster */ ++ if (!(ip_state[0] & (BAD_CPU_CLUSTER1 | BAD_CPU_CLUSTER2))) ++ ip_state[0] |= BAD_CPU_CLUSTER2; ++ } ++ ++ if (ip_state[0] & BAD_CPU_CLUSTER1) { ++ /* fail entire cluster when one or more core is bad */ ++ ip_state[0] |= BAD_CPU_CLUSTER1; ++ fdt_path_del_node(blob, "/cpus/cpu-map/cluster1"); ++ } ++ ++ if (ip_state[0] & BAD_CPU_CLUSTER2) { ++ /* fail entire cluster when one or more core is bad */ ++ ip_state[0] |= BAD_CPU_CLUSTER2; ++ fdt_path_del_node(blob, "/cpus/cpu-map/cluster2"); ++ } else if (ip_state[0] & BAD_CPU_CLUSTER1) { ++ /* cluster nodes must be named in a continuous series */ ++ fdt_path_set_name(blob, "/cpus/cpu-map/cluster2", "cluster1"); ++ } ++ ++ /* gpu: ip_state[1]: bit1~4 */ ++ if (ip_state[1] & BAD_GPU) { ++ log_debug("fail gpu\n"); ++ fdt_status_fail_by_pathf(blob, "/gpu@fb000000"); ++ } ++ ++ parent = fdt_path_offset(blob, "/cpus"); ++ if (parent < 0) { ++ log_debug("Could not find /cpus, parent=%d\n", parent); ++ return 0; ++ } ++ ++ /* cpu: ip_state[0]: bit0~7 */ ++ for (i = 0; i < 8; i++) { ++ /* fail any bad cpu core */ ++ if (!(ip_state[0] & BIT(i))) ++ continue; ++ ++ node = fdt_subnode_offset(blob, parent, cpu_node_names[i]); ++ if (node >= 0) { ++ log_debug("fail cpu %s\n", cpu_node_names[i]); ++ fdt_status_fail(blob, node); ++ } else { ++ log_debug("Could not find %s, node=%d\n", ++ cpu_node_names[i], node); ++ } ++ } ++ ++ return 0; ++} ++#endif +-- +2.46.0 + diff --git a/package/boot/uboot-rockchip/patches/202-pending-2-rk3582-support.patch b/package/boot/uboot-rockchip/patches/202-pending-2-rk3582-support.patch new file mode 100644 index 0000000000..511818b91d --- /dev/null +++ b/package/boot/uboot-rockchip/patches/202-pending-2-rk3582-support.patch @@ -0,0 +1,44 @@ +From 43ad56b7176e57a92fe6846883817ca271da1c61 Mon Sep 17 00:00:00 2001 +From: Jonas Karlman +Date: Tue, 10 Dec 2024 22:23:36 +0000 +Subject: [PATCH] rockchip: rk3588-generic: Enable support for RK3582 + +Add Kconfig option OF_SYSTEM_SETUP=y to support booting boards with a +RK3582 SoC. CPU and GPU cores are failed based on ip-state and policy. + +Tested on a ROCK 5C Lite v1.1: + + cpu-code: 35 82 + ip-state: 10 00 00 + fail gpu + fail cpu cpu@400 + fail cpu cpu@500 + +and on a Radxa E52C: + + cpu-code: 35 82 + ip-state: 00 04 00 + fail gpu + fail cpu cpu@600 + fail cpu cpu@700 + +Signed-off-by: Jonas Karlman +--- + configs/generic-rk3588_defconfig | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/configs/generic-rk3588_defconfig b/configs/generic-rk3588_defconfig +index 42bc2c9a765..cbcbb6e91f1 100644 +--- a/configs/generic-rk3588_defconfig ++++ b/configs/generic-rk3588_defconfig +@@ -16,6 +16,7 @@ CONFIG_SPL_FIT_SIGNATURE=y + CONFIG_SPL_LOAD_FIT=y + # CONFIG_BOOTMETH_VBE is not set + CONFIG_LEGACY_IMAGE_FORMAT=y ++CONFIG_OF_SYSTEM_SETUP=y + CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-generic.dtb" + # CONFIG_DISPLAY_CPUINFO is not set + CONFIG_DISPLAY_BOARDINFO_LATE=y +-- +2.46.0 + diff --git a/package/boot/uboot-rockchip/patches/203-rk3582-disable-bad-vpu.patch b/package/boot/uboot-rockchip/patches/203-rk3582-disable-bad-vpu.patch new file mode 100644 index 0000000000..23c1895532 --- /dev/null +++ b/package/boot/uboot-rockchip/patches/203-rk3582-disable-bad-vpu.patch @@ -0,0 +1,78 @@ +From 00f76e94d0b9472b5deb045dc417e191a4abbb7d Mon Sep 17 00:00:00 2001 +From: Liangbin Lian +Date: Wed, 11 Jun 2025 16:55:37 +0800 +Subject: [PATCH] rockchip: rk3588: disable bad vpu in RK3582 + +--- + arch/arm/mach-rockchip/rk3588/rk3588.c | 38 ++++++++++++++++++++++++++ + 1 file changed, 38 insertions(+) + +diff --git a/arch/arm/mach-rockchip/rk3588/rk3588.c b/arch/arm/mach-rockchip/rk3588/rk3588.c +index 1e660cc24d4..1db0101d6da 100644 +--- a/arch/arm/mach-rockchip/rk3588/rk3588.c ++++ b/arch/arm/mach-rockchip/rk3588/rk3588.c +@@ -193,6 +193,14 @@ int arch_cpu_init(void) + #define BAD_CPU_CLUSTER2 GENMASK(7, 6) + #define BAD_GPU GENMASK(4, 1) + ++#define BAD_VDEC0 (1<<6) ++#define BAD_VDEC1 (1<<7) ++#define BAD_VDEC (BAD_VDEC0|BAD_VDEC1) ++ ++#define BAD_VENC0 (1<<0) ++#define BAD_VENC1 (1<<2) ++#define BAD_VENC (BAD_VENC0|BAD_VENC1) ++ + int checkboard(void) + { + u8 cpu_code[2], specification, package; +@@ -306,6 +314,8 @@ int ft_system_setup(void *blob, struct bd_info *bd) + if (cpu_code[0] == 0x35 && cpu_code[1] == 0x82) { + /* policy: always disable gpu */ + ip_state[1] |= BAD_GPU; ++ /* policy: always disable vdec */ ++ ip_state[1] |= BAD_VDEC; + + /* policy: always disable one big core cluster */ + if (!(ip_state[0] & (BAD_CPU_CLUSTER1 | BAD_CPU_CLUSTER2))) +@@ -330,9 +340,37 @@ int ft_system_setup(void *blob, struct bd_info *bd) + /* gpu: ip_state[1]: bit1~4 */ + if (ip_state[1] & BAD_GPU) { + log_debug("fail gpu\n"); ++ fdt_status_fail_by_pathf(blob, "/gpu-panthor@fb000000"); + fdt_status_fail_by_pathf(blob, "/gpu@fb000000"); + } + ++ if (ip_state[1] & BAD_VDEC0) { ++ log_debug("fail vdec0\n"); ++ fdt_status_fail_by_pathf(blob, "/rkvdec-core@fdc38000"); ++ fdt_status_fail_by_pathf(blob, "/iommu@fdc38700"); ++ } ++ if (ip_state[1] & BAD_VDEC1) { ++ log_debug("fail vdec1\n"); ++ fdt_status_fail_by_pathf(blob, "/rkvdec-core@fdc48000"); ++ fdt_status_fail_by_pathf(blob, "/iommu@fdc48700"); ++ } ++ if (ip_state[1] & BAD_VDEC) { ++ fdt_status_fail_by_pathf(blob, "/rkvdec-ccu@fdc30000"); ++ } ++ if (ip_state[2] & BAD_VENC0) { ++ log_debug("fail venc0\n"); ++ fdt_status_fail_by_pathf(blob, "/rkvenc-core@fdbd0000"); ++ fdt_status_fail_by_pathf(blob, "/iommu@fdbdf000"); ++ } ++ if (ip_state[2] & BAD_VENC1) { ++ log_debug("fail venc1\n"); ++ fdt_status_fail_by_pathf(blob, "/rkvenc-core@fdbe0000"); ++ fdt_status_fail_by_pathf(blob, "/iommu@fdbef000"); ++ } ++ if (ip_state[2] & BAD_VENC) { ++ fdt_status_fail_by_pathf(blob, "/rkvenc-ccu"); ++ } ++ + parent = fdt_path_offset(blob, "/cpus"); + if (parent < 0) { + log_debug("Could not find /cpus, parent=%d\n", parent); +-- +2.46.0 + diff --git a/package/boot/uboot-rockchip/patches/204-rk3582-unlock-good-big-cores.patch b/package/boot/uboot-rockchip/patches/204-rk3582-unlock-good-big-cores.patch new file mode 100644 index 0000000000..e69f6c469f --- /dev/null +++ b/package/boot/uboot-rockchip/patches/204-rk3582-unlock-good-big-cores.patch @@ -0,0 +1,28 @@ +From 1db20ba9b8e91ade04e0bf1cea159127ccab42b3 Mon Sep 17 00:00:00 2001 +From: Liangbin Lian +Date: Wed, 11 Jun 2025 17:01:10 +0800 +Subject: [PATCH] rockchip: rk3588: unlock good big cores in RK3582 + +--- + arch/arm/mach-rockchip/rk3588/rk3588.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/arch/arm/mach-rockchip/rk3588/rk3588.c b/arch/arm/mach-rockchip/rk3588/rk3588.c +index 1db0101d6da..3c800c30b11 100644 +--- a/arch/arm/mach-rockchip/rk3588/rk3588.c ++++ b/arch/arm/mach-rockchip/rk3588/rk3588.c +@@ -317,9 +317,11 @@ int ft_system_setup(void *blob, struct bd_info *bd) + /* policy: always disable vdec */ + ip_state[1] |= BAD_VDEC; + ++#if 0 + /* policy: always disable one big core cluster */ + if (!(ip_state[0] & (BAD_CPU_CLUSTER1 | BAD_CPU_CLUSTER2))) + ip_state[0] |= BAD_CPU_CLUSTER2; ++#endif + } + + if (ip_state[0] & BAD_CPU_CLUSTER1) { +-- +2.46.0 + diff --git a/package/boot/uboot-rockchip/src/configs/easepi-rk3588_defconfig b/package/boot/uboot-rockchip/src/configs/easepi-rk3588_defconfig index fa54c635d5..505b98b97a 100644 --- a/package/boot/uboot-rockchip/src/configs/easepi-rk3588_defconfig +++ b/package/boot/uboot-rockchip/src/configs/easepi-rk3588_defconfig @@ -16,6 +16,7 @@ CONFIG_FIT_VERBOSE=y CONFIG_SPL_FIT_SIGNATURE=y CONFIG_SPL_LOAD_FIT=y CONFIG_LEGACY_IMAGE_FORMAT=y +CONFIG_OF_SYSTEM_SETUP=y CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-easepi.dtb" # CONFIG_DISPLAY_CPUINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y