[PATCH RFC 0/2] board: visionfive2: Select fdtfile based on revision

From: Jami Kettunen jami.kettunen@protonmail.com
Currently booting a mainline Linux kernel via extlinux with fdtdir set doesn't load a proper DTB but passes on the U-Boot one to the kernel which as far as I know is very incorrect and prevents user (normally distro) provided DTB usage in a sensible/generic way.
A uEnv.txt or similar manual environment changes were not used and should not be required to boot the board as per: https://u-boot.readthedocs.io/en/latest/develop/distro.html
This also currently needs a kernel patch[1] for my board to have the full 8GB of memory available to Linux instead of just 4GB it shows with these patches alone.
[1] https://gitlab.alpinelinux.org/nmeum/alpine-visionfive/-/blob/main/starfive/...
Jami Kettunen (2): board: visionfive2: Select fdtfile based on revision configs: visionfive2: Enable MISC_INIT_R
.../visionfive2/starfive_visionfive2.c | 25 +++++++++++++++++++ configs/starfive_visionfive2_defconfig | 1 + 2 files changed, 26 insertions(+)

From: Jami Kettunen jami.kettunen@protonmail.com
Linux mainline kernel device tree files[1] are named: - jh7110-starfive-visionfive-2-v1.2a - jh7110-starfive-visionfive-2-v1.3b
which should be selected accordingly by U-Boot to have a proper extlinux experience with fdtdir set by the distribution.
[1] https://github.com/torvalds/linux/tree/master/arch/riscv/boot/dts/starfive
Signed-off-by: Jami Kettunen jami.kettunen@protonmail.com --- .../visionfive2/starfive_visionfive2.c | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c index d609262b67..9244d4654b 100644 --- a/board/starfive/visionfive2/starfive_visionfive2.c +++ b/board/starfive/visionfive2/starfive_visionfive2.c @@ -10,6 +10,8 @@ #include <cpu_func.h> #include <dm.h> #include <linux/bitops.h> +#include <asm/arch-jh7110/eeprom.h> +#include <env.h>
#define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000 #define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000 @@ -41,6 +43,29 @@ int board_init(void) return 0; }
+int misc_init_r(void) +{ + u8 rev; + const char *linux_dtb_file; + + rev = get_pcb_revision_from_eeprom(); + switch (rev) { + case 'a': + case 'A': + linux_dtb_file = "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb"; + break; + + case 'b': + case 'B': + default: + linux_dtb_file = "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb"; + break; + }; + + env_set("fdtfile", linux_dtb_file); + return 0; +} + void *board_fdt_blob_setup(int *err) { *err = 0;

On Mon, 2023-09-11 at 18:32, Jami Kettunen wrote:
From: Jami Kettunen jami.kettunen@protonmail.com
Linux mainline kernel device tree files[1] are named:
- jh7110-starfive-visionfive-2-v1.2a
- jh7110-starfive-visionfive-2-v1.3b
which should be selected accordingly by U-Boot to have a proper extlinux experience with fdtdir set by the distribution.
[1] https://github.com/torvalds/linux/tree/master/arch/riscv/boot/dts/starfive
Signed-off-by: Jami Kettunen jami.kettunen@protonmail.com
Tested-by: Milan P. Stanić mps@arvanta.net
.../visionfive2/starfive_visionfive2.c | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c index d609262b67..9244d4654b 100644 --- a/board/starfive/visionfive2/starfive_visionfive2.c +++ b/board/starfive/visionfive2/starfive_visionfive2.c @@ -10,6 +10,8 @@ #include <cpu_func.h> #include <dm.h> #include <linux/bitops.h> +#include <asm/arch-jh7110/eeprom.h> +#include <env.h>
#define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000 #define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000 @@ -41,6 +43,29 @@ int board_init(void) return 0; }
+int misc_init_r(void) +{
- u8 rev;
- const char *linux_dtb_file;
- rev = get_pcb_revision_from_eeprom();
- switch (rev) {
- case 'a':
- case 'A':
linux_dtb_file = "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb";
break;
- case 'b':
- case 'B':
- default:
linux_dtb_file = "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb";
break;
- };
- env_set("fdtfile", linux_dtb_file);
- return 0;
+}
void *board_fdt_blob_setup(int *err) { *err = 0;

From: Jami Kettunen jami.kettunen@protonmail.com
Used to select mainline kernel fdtfile based on board revision.
Signed-off-by: Jami Kettunen jami.kettunen@protonmail.com --- configs/starfive_visionfive2_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/starfive_visionfive2_defconfig b/configs/starfive_visionfive2_defconfig index e9b63e5b84..33f9ec8ad6 100644 --- a/configs/starfive_visionfive2_defconfig +++ b/configs/starfive_visionfive2_defconfig @@ -125,3 +125,4 @@ CONFIG_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PCI=y CONFIG_USB_KEYBOARD=y +CONFIG_MISC_INIT_R=y

On Mon, 2023-09-11 at 18:32, Jami Kettunen wrote:
From: Jami Kettunen jami.kettunen@protonmail.com
Used to select mainline kernel fdtfile based on board revision.
Signed-off-by: Jami Kettunen jami.kettunen@protonmail.com
Tested-by: Milan P. Stanić mps@arvanta.net
configs/starfive_visionfive2_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/starfive_visionfive2_defconfig b/configs/starfive_visionfive2_defconfig index e9b63e5b84..33f9ec8ad6 100644 --- a/configs/starfive_visionfive2_defconfig +++ b/configs/starfive_visionfive2_defconfig @@ -125,3 +125,4 @@ CONFIG_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PCI=y CONFIG_USB_KEYBOARD=y +CONFIG_MISC_INIT_R=y

Hello Jami, For DDR size problem, I think we could enable CONFIG_OF_BOARD_SETUP, then use ft_board_setup() to apply fdt_fixup_memory()? Just like what they did in spl.c: https://patchwork.ozlabs.org/project/uboot/patch/20230615093652.23161-12-yan... Best regards, Shengyu (This mail is sent twice because the first one didn't use reply all)
From: Jami Kettunen jami.kettunen@protonmail.com
Currently booting a mainline Linux kernel via extlinux with fdtdir set doesn't load a proper DTB but passes on the U-Boot one to the kernel which as far as I know is very incorrect and prevents user (normally distro) provided DTB usage in a sensible/generic way.
A uEnv.txt or similar manual environment changes were not used and should not be required to boot the board as per: https://u-boot.readthedocs.io/en/latest/develop/distro.html
This also currently needs a kernel patch[1] for my board to have the full 8GB of memory available to Linux instead of just 4GB it shows with these patches alone.
[1] https://gitlab.alpinelinux.org/nmeum/alpine-visionfive/-/blob/main/starfive/...
Jami Kettunen (2): board: visionfive2: Select fdtfile based on revision configs: visionfive2: Enable MISC_INIT_R
.../visionfive2/starfive_visionfive2.c | 25 +++++++++++++++++++ configs/starfive_visionfive2_defconfig | 1 + 2 files changed, 26 insertions(+)

Hello Jami,
I made a fix for memory size problem based on your series, but I can't try
that because I'm using 4GB version. Could you test this?
https://github.com/Headcrabed/u-boot/tree/ddr_fix_v1
Best regards,
Shengyu
From: Jami Kettunen jami.kettunen@protonmail.com
Currently booting a mainline Linux kernel via extlinux with fdtdir set doesn't load a proper DTB but passes on the U-Boot one to the kernel which as far as I know is very incorrect and prevents user (normally distro) provided DTB usage in a sensible/generic way.
A uEnv.txt or similar manual environment changes were not used and should not be required to boot the board as per: https://u-boot.readthedocs.io/en/latest/develop/distro.html
This also currently needs a kernel patch[1] for my board to have the full 8GB of memory available to Linux instead of just 4GB it shows with these patches alone.
[1] https://gitlab.alpinelinux.org/nmeum/alpine-visionfive/-/blob/main/starfive/...
Jami Kettunen (2): board: visionfive2: Select fdtfile based on revision configs: visionfive2: Enable MISC_INIT_R
.../visionfive2/starfive_visionfive2.c | 25 +++++++++++++++++++ configs/starfive_visionfive2_defconfig | 1 + 2 files changed, 26 insertions(+)
participants (3)
-
Jami Kettunen
-
Milan P. Stanić
-
Shengyu Qu