diff mbox series

[U-Boot,v2,11/11] riscv: Add SiFive FU540 board support

Message ID 20190118111820.71349-12-anup.patel@wdc.com
State Superseded
Delegated to: Andes
Headers show
Series SiFive FU540 Support | expand

Commit Message

Anup Patel Jan. 18, 2019, 11:19 a.m. UTC
This patch adds SiFive FU540 board support. For now, only
SiFive serial, SiFive PRCI, and Cadance MACB drivers are
only enabled. The SiFive FU540 defconfig by default builds
U-Boot for S-Mode because U-Boot on SiFive FU540 will run
in S-Mode as payload of BBL or OpenSBI.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
---
 arch/riscv/Kconfig             |  4 ++++
 board/sifive/fu540/Kconfig     | 42 +++++++++++++++++++++++++++++++++
 board/sifive/fu540/MAINTAINERS |  9 +++++++
 board/sifive/fu540/Makefile    |  5 ++++
 board/sifive/fu540/fu540.c     | 17 ++++++++++++++
 configs/sifive_fu540_defconfig | 11 +++++++++
 include/configs/sifive-fu540.h | 43 ++++++++++++++++++++++++++++++++++
 7 files changed, 131 insertions(+)
 create mode 100644 board/sifive/fu540/Kconfig
 create mode 100644 board/sifive/fu540/MAINTAINERS
 create mode 100644 board/sifive/fu540/Makefile
 create mode 100644 board/sifive/fu540/fu540.c
 create mode 100644 configs/sifive_fu540_defconfig
 create mode 100644 include/configs/sifive-fu540.h

Comments

Lukas Auer Jan. 20, 2019, 8:26 p.m. UTC | #1
Hi Anup,

On Fri, 2019-01-18 at 11:19 +0000, Anup Patel wrote:
> This patch adds SiFive FU540 board support. For now, only
> SiFive serial, SiFive PRCI, and Cadance MACB drivers are
> only enabled. The SiFive FU540 defconfig by default builds
> U-Boot for S-Mode because U-Boot on SiFive FU540 will run
> in S-Mode as payload of BBL or OpenSBI.
> 
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> Signed-off-by: Anup Patel <anup.patel@wdc.com>
> Reviewed-by: Alexander Graf <agraf@suse.de>
> ---
>  arch/riscv/Kconfig             |  4 ++++
>  board/sifive/fu540/Kconfig     | 42
> +++++++++++++++++++++++++++++++++
>  board/sifive/fu540/MAINTAINERS |  9 +++++++
>  board/sifive/fu540/Makefile    |  5 ++++
>  board/sifive/fu540/fu540.c     | 17 ++++++++++++++
>  configs/sifive_fu540_defconfig | 11 +++++++++
>  include/configs/sifive-fu540.h | 43
> ++++++++++++++++++++++++++++++++++
>  7 files changed, 131 insertions(+)
>  create mode 100644 board/sifive/fu540/Kconfig
>  create mode 100644 board/sifive/fu540/MAINTAINERS
>  create mode 100644 board/sifive/fu540/Makefile
>  create mode 100644 board/sifive/fu540/fu540.c
>  create mode 100644 configs/sifive_fu540_defconfig
>  create mode 100644 include/configs/sifive-fu540.h
> 

Reviewed-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>

Can you add a short README on how to flash and use U-Boot on the HiFive
Unleashed?

Please also see one more comment below.

> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 6879047ff7..36512a8995 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -14,11 +14,15 @@ config TARGET_AX25_AE350
>  config TARGET_QEMU_VIRT
>  	bool "Support QEMU Virt Board"
>  
> +config TARGET_SIFIVE_FU540
> +	bool "Support SiFive FU540 Board"
> +
>  endchoice
>  
>  # board-specific options below
>  source "board/AndesTech/ax25-ae350/Kconfig"
>  source "board/emulation/qemu-riscv/Kconfig"
> +source "board/sifive/fu540/Kconfig"
>  
>  # platform-specific options below
>  source "arch/riscv/cpu/ax25/Kconfig"
> diff --git a/board/sifive/fu540/Kconfig b/board/sifive/fu540/Kconfig
> new file mode 100644
> index 0000000000..6be3d88144
> --- /dev/null
> +++ b/board/sifive/fu540/Kconfig
> @@ -0,0 +1,42 @@
> +if TARGET_SIFIVE_FU540
> +
> +config SYS_BOARD
> +	default "fu540"
> +
> +config SYS_VENDOR
> +	default "sifive"
> +
> +config SYS_CPU
> +	default "generic"
> +
> +config SYS_CONFIG_NAME
> +	default "sifive-fu540"
> +
> +config SYS_TEXT_BASE
> +	default 0x80000000 if !RISCV_SMODE
> +	default 0x80200000 if RISCV_SMODE
> +
> +config BOARD_SPECIFIC_OPTIONS # dummy
> +	def_bool y
> +	select GENERIC_RISCV
> +	imply CMD_DHCP
> +	imply CMD_EXT2
> +	imply CMD_EXT4
> +	imply CMD_FAT
> +	imply CMD_FS_GENERIC
> +	imply CMD_NET
> +	imply CMD_PING
> +	imply CLK_SIFIVE
> +	imply CLK_SIFIVE_FU540_PRCI
> +	imply DOS_PARTITION
> +	imply EFI_PARTITION
> +	imply IP_DYN
> +	imply ISO_PARTITION
> +	imply MACB
> +	imply MII
> +	imply NET_RANDOM_ETHADDR
> +	imply PHY_LIB
> +	imply PHY_MSCC
> +	imply SIFIVE_SERIAL
> +
> +endif
> diff --git a/board/sifive/fu540/MAINTAINERS
> b/board/sifive/fu540/MAINTAINERS
> new file mode 100644
> index 0000000000..702d803ad8
> --- /dev/null
> +++ b/board/sifive/fu540/MAINTAINERS
> @@ -0,0 +1,9 @@
> +SiFive FU540 BOARD
> +M:	Paul Walmsley <paul.walmsley@sifive.com>
> +M:	Palmer Dabbelt <palmer@sifive.com>
> +M:	Anup Patel <anup.patel@wdc.com>
> +M:	Atish Patra <atish.patra@wdc.com>
> +S:	Maintained
> +F:	board/sifive/fu540/
> +F:	include/configs/sifive-fu540.h
> +F:	configs/sifive_fu540_defconfig
> diff --git a/board/sifive/fu540/Makefile
> b/board/sifive/fu540/Makefile
> new file mode 100644
> index 0000000000..6e1862c475
> --- /dev/null
> +++ b/board/sifive/fu540/Makefile
> @@ -0,0 +1,5 @@
> +# SPDX-License-Identifier: GPL-2.0+
> +#
> +# Copyright (c) 2019 Western Digital Corporation or its affiliates.
> +
> +obj-y	+= fu540.o
> diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
> new file mode 100644
> index 0000000000..5adc4a3d4a
> --- /dev/null
> +++ b/board/sifive/fu540/fu540.c
> @@ -0,0 +1,17 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (c) 2019 Western Digital Corporation or its affiliates.
> + *
> + * Authors:
> + *   Anup Patel <anup.patel@wdc.com>
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +
> +int board_init(void)
> +{
> +	/* For now nothing to do here. */
> +
> +	return 0;
> +}
> diff --git a/configs/sifive_fu540_defconfig
> b/configs/sifive_fu540_defconfig
> new file mode 100644
> index 0000000000..2f8cca9de0
> --- /dev/null
> +++ b/configs/sifive_fu540_defconfig
> @@ -0,0 +1,11 @@
> +CONFIG_RISCV=y
> +CONFIG_TARGET_SIFIVE_FU540=y
> +CONFIG_RISCV_SMODE=y
> +CONFIG_ARCH_RV64I=y
> +CONFIG_DISTRO_DEFAULTS=y
> +CONFIG_NR_DRAM_BANKS=1
> +CONFIG_FIT=y
> +CONFIG_DISPLAY_CPUINFO=y
> +CONFIG_DISPLAY_BOARDINFO=y
> +CONFIG_CMD_MII=y
> +CONFIG_OF_PRIOR_STAGE=y
> diff --git a/include/configs/sifive-fu540.h b/include/configs/sifive-
> fu540.h
> new file mode 100644
> index 0000000000..7007b5f6af
> --- /dev/null
> +++ b/include/configs/sifive-fu540.h
> @@ -0,0 +1,43 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (c) 2019 Western Digital Corporation or its affiliates.
> + *
> + * Authors:
> + *   Anup Patel <anup.patel@wdc.com>
> + */
> +
> +#ifndef __CONFIG_H
> +#define __CONFIG_H
> +
> +#include <linux/sizes.h>
> +
> +#define CONFIG_SYS_SDRAM_BASE		0x80000000
> +#define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_SDRAM_BASE
> + SZ_2M)
> +
> +#define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE + SZ_2M)
> +
> +#define CONFIG_SYS_MALLOC_LEN		SZ_8M
> +
> +#define CONFIG_SYS_BOOTM_LEN		SZ_16M
> +
> +#define CONFIG_STANDALONE_LOAD_ADDR	0x80200000
> +
> +/* Environment options */
> +#define CONFIG_ENV_SIZE			SZ_4K
> +
> +#define BOOT_TARGET_DEVICES(func) \
> +	func(DHCP, dhcp, na)
> +
> +#include <config_distro_bootcmd.h>
> +
> +#define CONFIG_EXTRA_ENV_SETTINGS \
> +	"fdt_high=0xffffffffffffffff\0" \
> +	"initrd_high=0xffffffffffffffff\0" \
> +	"kernel_addr_r=0x80600000\0" \
> +	"fdt_addr_r=0x82200000\0" \
> +	"scriptaddr=0x82300000\0" \
> +	"pxefile_addr_r=0x82400000\0" \
> +	"ramdisk_addr_r=0x82500000\0" \
> +	BOOTENV

I think it would be helpful to define the kernel command line using the
bootargs environment variable here. For testing I used
"bootargs=console=ttySI0 earlyprintk root=/dev/mmcblk0p2 rootwait"
locally.

Thanks,
Lukas
Atish Patra Jan. 21, 2019, 1:22 a.m. UTC | #2
On 1/20/19 12:26 PM, Auer, Lukas wrote:
> Hi Anup,
> 
> On Fri, 2019-01-18 at 11:19 +0000, Anup Patel wrote:
>> This patch adds SiFive FU540 board support. For now, only
>> SiFive serial, SiFive PRCI, and Cadance MACB drivers are
>> only enabled. The SiFive FU540 defconfig by default builds
>> U-Boot for S-Mode because U-Boot on SiFive FU540 will run
>> in S-Mode as payload of BBL or OpenSBI.
>>
>> Signed-off-by: Atish Patra <atish.patra@wdc.com>
>> Signed-off-by: Anup Patel <anup.patel@wdc.com>
>> Reviewed-by: Alexander Graf <agraf@suse.de>
>> ---
>>   arch/riscv/Kconfig             |  4 ++++
>>   board/sifive/fu540/Kconfig     | 42
>> +++++++++++++++++++++++++++++++++
>>   board/sifive/fu540/MAINTAINERS |  9 +++++++
>>   board/sifive/fu540/Makefile    |  5 ++++
>>   board/sifive/fu540/fu540.c     | 17 ++++++++++++++
>>   configs/sifive_fu540_defconfig | 11 +++++++++
>>   include/configs/sifive-fu540.h | 43
>> ++++++++++++++++++++++++++++++++++
>>   7 files changed, 131 insertions(+)
>>   create mode 100644 board/sifive/fu540/Kconfig
>>   create mode 100644 board/sifive/fu540/MAINTAINERS
>>   create mode 100644 board/sifive/fu540/Makefile
>>   create mode 100644 board/sifive/fu540/fu540.c
>>   create mode 100644 configs/sifive_fu540_defconfig
>>   create mode 100644 include/configs/sifive-fu540.h
>>
> 
> Reviewed-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> 
> Can you add a short README on how to flash and use U-Boot on the HiFive
> Unleashed?
> 

Thanks for the review. Sure. We will add a README document.

> Please also see one more comment below.
> 
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> index 6879047ff7..36512a8995 100644
>> --- a/arch/riscv/Kconfig
>> +++ b/arch/riscv/Kconfig
>> @@ -14,11 +14,15 @@ config TARGET_AX25_AE350
>>   config TARGET_QEMU_VIRT
>>   	bool "Support QEMU Virt Board"
>>   
>> +config TARGET_SIFIVE_FU540
>> +	bool "Support SiFive FU540 Board"
>> +
>>   endchoice
>>   
>>   # board-specific options below
>>   source "board/AndesTech/ax25-ae350/Kconfig"
>>   source "board/emulation/qemu-riscv/Kconfig"
>> +source "board/sifive/fu540/Kconfig"
>>   
>>   # platform-specific options below
>>   source "arch/riscv/cpu/ax25/Kconfig"
>> diff --git a/board/sifive/fu540/Kconfig b/board/sifive/fu540/Kconfig
>> new file mode 100644
>> index 0000000000..6be3d88144
>> --- /dev/null
>> +++ b/board/sifive/fu540/Kconfig
>> @@ -0,0 +1,42 @@
>> +if TARGET_SIFIVE_FU540
>> +
>> +config SYS_BOARD
>> +	default "fu540"
>> +
>> +config SYS_VENDOR
>> +	default "sifive"
>> +
>> +config SYS_CPU
>> +	default "generic"
>> +
>> +config SYS_CONFIG_NAME
>> +	default "sifive-fu540"
>> +
>> +config SYS_TEXT_BASE
>> +	default 0x80000000 if !RISCV_SMODE
>> +	default 0x80200000 if RISCV_SMODE
>> +
>> +config BOARD_SPECIFIC_OPTIONS # dummy
>> +	def_bool y
>> +	select GENERIC_RISCV
>> +	imply CMD_DHCP
>> +	imply CMD_EXT2
>> +	imply CMD_EXT4
>> +	imply CMD_FAT
>> +	imply CMD_FS_GENERIC
>> +	imply CMD_NET
>> +	imply CMD_PING
>> +	imply CLK_SIFIVE
>> +	imply CLK_SIFIVE_FU540_PRCI
>> +	imply DOS_PARTITION
>> +	imply EFI_PARTITION
>> +	imply IP_DYN
>> +	imply ISO_PARTITION
>> +	imply MACB
>> +	imply MII
>> +	imply NET_RANDOM_ETHADDR
>> +	imply PHY_LIB
>> +	imply PHY_MSCC
>> +	imply SIFIVE_SERIAL
>> +
>> +endif
>> diff --git a/board/sifive/fu540/MAINTAINERS
>> b/board/sifive/fu540/MAINTAINERS
>> new file mode 100644
>> index 0000000000..702d803ad8
>> --- /dev/null
>> +++ b/board/sifive/fu540/MAINTAINERS
>> @@ -0,0 +1,9 @@
>> +SiFive FU540 BOARD
>> +M:	Paul Walmsley <paul.walmsley@sifive.com>
>> +M:	Palmer Dabbelt <palmer@sifive.com>
>> +M:	Anup Patel <anup.patel@wdc.com>
>> +M:	Atish Patra <atish.patra@wdc.com>
>> +S:	Maintained
>> +F:	board/sifive/fu540/
>> +F:	include/configs/sifive-fu540.h
>> +F:	configs/sifive_fu540_defconfig
>> diff --git a/board/sifive/fu540/Makefile
>> b/board/sifive/fu540/Makefile
>> new file mode 100644
>> index 0000000000..6e1862c475
>> --- /dev/null
>> +++ b/board/sifive/fu540/Makefile
>> @@ -0,0 +1,5 @@
>> +# SPDX-License-Identifier: GPL-2.0+
>> +#
>> +# Copyright (c) 2019 Western Digital Corporation or its affiliates.
>> +
>> +obj-y	+= fu540.o
>> diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
>> new file mode 100644
>> index 0000000000..5adc4a3d4a
>> --- /dev/null
>> +++ b/board/sifive/fu540/fu540.c
>> @@ -0,0 +1,17 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Copyright (c) 2019 Western Digital Corporation or its affiliates.
>> + *
>> + * Authors:
>> + *   Anup Patel <anup.patel@wdc.com>
>> + */
>> +
>> +#include <common.h>
>> +#include <dm.h>
>> +
>> +int board_init(void)
>> +{
>> +	/* For now nothing to do here. */
>> +
>> +	return 0;
>> +}
>> diff --git a/configs/sifive_fu540_defconfig
>> b/configs/sifive_fu540_defconfig
>> new file mode 100644
>> index 0000000000..2f8cca9de0
>> --- /dev/null
>> +++ b/configs/sifive_fu540_defconfig
>> @@ -0,0 +1,11 @@
>> +CONFIG_RISCV=y
>> +CONFIG_TARGET_SIFIVE_FU540=y
>> +CONFIG_RISCV_SMODE=y
>> +CONFIG_ARCH_RV64I=y
>> +CONFIG_DISTRO_DEFAULTS=y
>> +CONFIG_NR_DRAM_BANKS=1
>> +CONFIG_FIT=y
>> +CONFIG_DISPLAY_CPUINFO=y
>> +CONFIG_DISPLAY_BOARDINFO=y
>> +CONFIG_CMD_MII=y
>> +CONFIG_OF_PRIOR_STAGE=y
>> diff --git a/include/configs/sifive-fu540.h b/include/configs/sifive-
>> fu540.h
>> new file mode 100644
>> index 0000000000..7007b5f6af
>> --- /dev/null
>> +++ b/include/configs/sifive-fu540.h
>> @@ -0,0 +1,43 @@
>> +/* SPDX-License-Identifier: GPL-2.0+ */
>> +/*
>> + * Copyright (c) 2019 Western Digital Corporation or its affiliates.
>> + *
>> + * Authors:
>> + *   Anup Patel <anup.patel@wdc.com>
>> + */
>> +
>> +#ifndef __CONFIG_H
>> +#define __CONFIG_H
>> +
>> +#include <linux/sizes.h>
>> +
>> +#define CONFIG_SYS_SDRAM_BASE		0x80000000
>> +#define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_SDRAM_BASE
>> + SZ_2M)
>> +
>> +#define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE + SZ_2M)
>> +
>> +#define CONFIG_SYS_MALLOC_LEN		SZ_8M
>> +
>> +#define CONFIG_SYS_BOOTM_LEN		SZ_16M
>> +
>> +#define CONFIG_STANDALONE_LOAD_ADDR	0x80200000
>> +
>> +/* Environment options */
>> +#define CONFIG_ENV_SIZE			SZ_4K
>> +
>> +#define BOOT_TARGET_DEVICES(func) \
>> +	func(DHCP, dhcp, na)
>> +
>> +#include <config_distro_bootcmd.h>
>> +
>> +#define CONFIG_EXTRA_ENV_SETTINGS \
>> +	"fdt_high=0xffffffffffffffff\0" \
>> +	"initrd_high=0xffffffffffffffff\0" \
>> +	"kernel_addr_r=0x80600000\0" \
>> +	"fdt_addr_r=0x82200000\0" \
>> +	"scriptaddr=0x82300000\0" \
>> +	"pxefile_addr_r=0x82400000\0" \
>> +	"ramdisk_addr_r=0x82500000\0" \
>> +	BOOTENV
> 
> I think it would be helpful to define the kernel command line using the
> bootargs environment variable here. For testing I used
> "bootargs=console=ttySI0 earlyprintk root=/dev/mmcblk0p2 rootwait"
> locally.
> 
The root partition might be different in different setup. For example, 
if expansion board is connected, root partition might be on sata or nvme 
drive. Should we add a fixed root partition to the bootargs ?

Regards,
Atish
> Thanks,
> Lukas
>
Andreas Schwab Jan. 21, 2019, 9:48 a.m. UTC | #3
On Jan 18 2019, Anup Patel <Anup.Patel@wdc.com> wrote:

> This patch adds SiFive FU540 board support. For now, only
> SiFive serial, SiFive PRCI, and Cadance MACB drivers are
> only enabled. The SiFive FU540 defconfig by default builds
> U-Boot for S-Mode because U-Boot on SiFive FU540 will run
> in S-Mode as payload of BBL or OpenSBI.

What am I expected to see when started with BBL?  All I see is the logo,
then nothing.

Andreas.
Lukas Auer Jan. 21, 2019, 12:57 p.m. UTC | #4
On Sun, 2019-01-20 at 17:22 -0800, Atish Patra wrote:
> On 1/20/19 12:26 PM, Auer, Lukas wrote:
> > Hi Anup,
> > 
> > On Fri, 2019-01-18 at 11:19 +0000, Anup Patel wrote:
> > > This patch adds SiFive FU540 board support. For now, only
> > > SiFive serial, SiFive PRCI, and Cadance MACB drivers are
> > > only enabled. The SiFive FU540 defconfig by default builds
> > > U-Boot for S-Mode because U-Boot on SiFive FU540 will run
> > > in S-Mode as payload of BBL or OpenSBI.
> > > 
> > > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > > Signed-off-by: Anup Patel <anup.patel@wdc.com>
> > > Reviewed-by: Alexander Graf <agraf@suse.de>
> > > ---
> > >   arch/riscv/Kconfig             |  4 ++++
> > >   board/sifive/fu540/Kconfig     | 42
> > > +++++++++++++++++++++++++++++++++
> > >   board/sifive/fu540/MAINTAINERS |  9 +++++++
> > >   board/sifive/fu540/Makefile    |  5 ++++
> > >   board/sifive/fu540/fu540.c     | 17 ++++++++++++++
> > >   configs/sifive_fu540_defconfig | 11 +++++++++
> > >   include/configs/sifive-fu540.h | 43
> > > ++++++++++++++++++++++++++++++++++
> > >   7 files changed, 131 insertions(+)
> > >   create mode 100644 board/sifive/fu540/Kconfig
> > >   create mode 100644 board/sifive/fu540/MAINTAINERS
> > >   create mode 100644 board/sifive/fu540/Makefile
> > >   create mode 100644 board/sifive/fu540/fu540.c
> > >   create mode 100644 configs/sifive_fu540_defconfig
> > >   create mode 100644 include/configs/sifive-fu540.h
> > > 
> > 
> > Reviewed-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> > 
> > Can you add a short README on how to flash and use U-Boot on the
> > HiFive
> > Unleashed?
> > 
> 
> Thanks for the review. Sure. We will add a README document.
> 
> > Please also see one more comment below.
> > 
> > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > > index 6879047ff7..36512a8995 100644
> > > --- a/arch/riscv/Kconfig
> > > +++ b/arch/riscv/Kconfig
> > > @@ -14,11 +14,15 @@ config TARGET_AX25_AE350
> > >   config TARGET_QEMU_VIRT
> > >   	bool "Support QEMU Virt Board"
> > >   
> > > +config TARGET_SIFIVE_FU540
> > > +	bool "Support SiFive FU540 Board"
> > > +
> > >   endchoice
> > >   
> > >   # board-specific options below
> > >   source "board/AndesTech/ax25-ae350/Kconfig"
> > >   source "board/emulation/qemu-riscv/Kconfig"
> > > +source "board/sifive/fu540/Kconfig"
> > >   
> > >   # platform-specific options below
> > >   source "arch/riscv/cpu/ax25/Kconfig"
> > > diff --git a/board/sifive/fu540/Kconfig
> > > b/board/sifive/fu540/Kconfig
> > > new file mode 100644
> > > index 0000000000..6be3d88144
> > > --- /dev/null
> > > +++ b/board/sifive/fu540/Kconfig
> > > @@ -0,0 +1,42 @@
> > > +if TARGET_SIFIVE_FU540
> > > +
> > > +config SYS_BOARD
> > > +	default "fu540"
> > > +
> > > +config SYS_VENDOR
> > > +	default "sifive"
> > > +
> > > +config SYS_CPU
> > > +	default "generic"
> > > +
> > > +config SYS_CONFIG_NAME
> > > +	default "sifive-fu540"
> > > +
> > > +config SYS_TEXT_BASE
> > > +	default 0x80000000 if !RISCV_SMODE
> > > +	default 0x80200000 if RISCV_SMODE
> > > +
> > > +config BOARD_SPECIFIC_OPTIONS # dummy
> > > +	def_bool y
> > > +	select GENERIC_RISCV
> > > +	imply CMD_DHCP
> > > +	imply CMD_EXT2
> > > +	imply CMD_EXT4
> > > +	imply CMD_FAT
> > > +	imply CMD_FS_GENERIC
> > > +	imply CMD_NET
> > > +	imply CMD_PING
> > > +	imply CLK_SIFIVE
> > > +	imply CLK_SIFIVE_FU540_PRCI
> > > +	imply DOS_PARTITION
> > > +	imply EFI_PARTITION
> > > +	imply IP_DYN
> > > +	imply ISO_PARTITION
> > > +	imply MACB
> > > +	imply MII
> > > +	imply NET_RANDOM_ETHADDR
> > > +	imply PHY_LIB
> > > +	imply PHY_MSCC
> > > +	imply SIFIVE_SERIAL
> > > +
> > > +endif
> > > diff --git a/board/sifive/fu540/MAINTAINERS
> > > b/board/sifive/fu540/MAINTAINERS
> > > new file mode 100644
> > > index 0000000000..702d803ad8
> > > --- /dev/null
> > > +++ b/board/sifive/fu540/MAINTAINERS
> > > @@ -0,0 +1,9 @@
> > > +SiFive FU540 BOARD
> > > +M:	Paul Walmsley <paul.walmsley@sifive.com>
> > > +M:	Palmer Dabbelt <palmer@sifive.com>
> > > +M:	Anup Patel <anup.patel@wdc.com>
> > > +M:	Atish Patra <atish.patra@wdc.com>
> > > +S:	Maintained
> > > +F:	board/sifive/fu540/
> > > +F:	include/configs/sifive-fu540.h
> > > +F:	configs/sifive_fu540_defconfig
> > > diff --git a/board/sifive/fu540/Makefile
> > > b/board/sifive/fu540/Makefile
> > > new file mode 100644
> > > index 0000000000..6e1862c475
> > > --- /dev/null
> > > +++ b/board/sifive/fu540/Makefile
> > > @@ -0,0 +1,5 @@
> > > +# SPDX-License-Identifier: GPL-2.0+
> > > +#
> > > +# Copyright (c) 2019 Western Digital Corporation or its
> > > affiliates.
> > > +
> > > +obj-y	+= fu540.o
> > > diff --git a/board/sifive/fu540/fu540.c
> > > b/board/sifive/fu540/fu540.c
> > > new file mode 100644
> > > index 0000000000..5adc4a3d4a
> > > --- /dev/null
> > > +++ b/board/sifive/fu540/fu540.c
> > > @@ -0,0 +1,17 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * Copyright (c) 2019 Western Digital Corporation or its
> > > affiliates.
> > > + *
> > > + * Authors:
> > > + *   Anup Patel <anup.patel@wdc.com>
> > > + */
> > > +
> > > +#include <common.h>
> > > +#include <dm.h>
> > > +
> > > +int board_init(void)
> > > +{
> > > +	/* For now nothing to do here. */
> > > +
> > > +	return 0;
> > > +}
> > > diff --git a/configs/sifive_fu540_defconfig
> > > b/configs/sifive_fu540_defconfig
> > > new file mode 100644
> > > index 0000000000..2f8cca9de0
> > > --- /dev/null
> > > +++ b/configs/sifive_fu540_defconfig
> > > @@ -0,0 +1,11 @@
> > > +CONFIG_RISCV=y
> > > +CONFIG_TARGET_SIFIVE_FU540=y
> > > +CONFIG_RISCV_SMODE=y
> > > +CONFIG_ARCH_RV64I=y
> > > +CONFIG_DISTRO_DEFAULTS=y
> > > +CONFIG_NR_DRAM_BANKS=1
> > > +CONFIG_FIT=y
> > > +CONFIG_DISPLAY_CPUINFO=y
> > > +CONFIG_DISPLAY_BOARDINFO=y
> > > +CONFIG_CMD_MII=y
> > > +CONFIG_OF_PRIOR_STAGE=y
> > > diff --git a/include/configs/sifive-fu540.h
> > > b/include/configs/sifive-
> > > fu540.h
> > > new file mode 100644
> > > index 0000000000..7007b5f6af
> > > --- /dev/null
> > > +++ b/include/configs/sifive-fu540.h
> > > @@ -0,0 +1,43 @@
> > > +/* SPDX-License-Identifier: GPL-2.0+ */
> > > +/*
> > > + * Copyright (c) 2019 Western Digital Corporation or its
> > > affiliates.
> > > + *
> > > + * Authors:
> > > + *   Anup Patel <anup.patel@wdc.com>
> > > + */
> > > +
> > > +#ifndef __CONFIG_H
> > > +#define __CONFIG_H
> > > +
> > > +#include <linux/sizes.h>
> > > +
> > > +#define CONFIG_SYS_SDRAM_BASE		0x80000000
> > > +#define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_SDRAM_BASE
> > > + SZ_2M)
> > > +
> > > +#define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE
> > > + SZ_2M)
> > > +
> > > +#define CONFIG_SYS_MALLOC_LEN		SZ_8M
> > > +
> > > +#define CONFIG_SYS_BOOTM_LEN		SZ_16M
> > > +
> > > +#define CONFIG_STANDALONE_LOAD_ADDR	0x80200000
> > > +
> > > +/* Environment options */
> > > +#define CONFIG_ENV_SIZE			SZ_4K
> > > +
> > > +#define BOOT_TARGET_DEVICES(func) \
> > > +	func(DHCP, dhcp, na)
> > > +
> > > +#include <config_distro_bootcmd.h>
> > > +
> > > +#define CONFIG_EXTRA_ENV_SETTINGS \
> > > +	"fdt_high=0xffffffffffffffff\0" \
> > > +	"initrd_high=0xffffffffffffffff\0" \
> > > +	"kernel_addr_r=0x80600000\0" \
> > > +	"fdt_addr_r=0x82200000\0" \
> > > +	"scriptaddr=0x82300000\0" \
> > > +	"pxefile_addr_r=0x82400000\0" \
> > > +	"ramdisk_addr_r=0x82500000\0" \
> > > +	BOOTENV
> > 
> > I think it would be helpful to define the kernel command line using
> > the
> > bootargs environment variable here. For testing I used
> > "bootargs=console=ttySI0 earlyprintk root=/dev/mmcblk0p2 rootwait"
> > locally.
> > 
> The root partition might be different in different setup. For
> example, 
> if expansion board is connected, root partition might be on sata or
> nvme 
> drive. Should we add a fixed root partition to the bootargs ?
> 

Hm, good point. It's probably better to leave it as is and document it
as part of the boot flow in the board README.

Thanks,
Lukas
Anup Patel Jan. 21, 2019, 4:17 p.m. UTC | #5
On Mon, Jan 21, 2019 at 7:26 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Jan 18 2019, Anup Patel <Anup.Patel@wdc.com> wrote:
>
> > This patch adds SiFive FU540 board support. For now, only
> > SiFive serial, SiFive PRCI, and Cadance MACB drivers are
> > only enabled. The SiFive FU540 defconfig by default builds
> > U-Boot for S-Mode because U-Boot on SiFive FU540 will run
> > in S-Mode as payload of BBL or OpenSBI.
>
> What am I expected to see when started with BBL?  All I see is the logo,
> then nothing.
>

Here's the log of BBL+U-Boot on QEMU sifive_u machine:

anup@anup-ubuntu64:~/Work/riscv-test$ qemu-system-riscv64 -M sifive_u
-m 256M -display none -serial stdio -kernel build-riscv-pk-uboot/bbl
bbl loader


U-Boot 2019.01-00018-gc3a9211ebc (Jan 21 2019 - 21:36:12 +0530)

CPU:   rv64imafdcsu
Model: ucbbar,spike-bare,qemu
DRAM:  256 MiB
In:    uart@10013000
Out:   uart@10013000
Err:   uart@10013000
Net:
Warning: ethernet@100900fc (eth0) using random MAC address - 02:4a:de:c3:c8:80
eth0: ethernet@100900fc
Hit any key to stop autoboot:  0
ethernet@100900fc: PHY present at 0
ethernet@100900fc: link up, 1000Mbps full-duplex (lpa: 0x7c00)
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (2 ms)
Using ethernet@100900fc device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x82300000
Loading: *
TFTP error: 'Access violation' (2)
Not retrying...
ethernet@100900fc: PHY present at 0
ethernet@100900fc: link up, 1000Mbps full-duplex (lpa: 0x7c00)
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (0 ms)
Using ethernet@100900fc device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x80600000
Loading: *
TFTP error: 'Access violation' (2)
Not retrying...
=> ping 10.0.2.2
ethernet@100900fc: PHY present at 0
ethernet@100900fc: link up, 1000Mbps full-duplex (lpa: 0x7c00)
Using ethernet@100900fc device
host 10.0.2.2 is alive
=>
ethernet@100900fc: PHY present at 0
ethernet@100900fc: link up, 1000Mbps full-duplex (lpa: 0x7c00)
Using ethernet@100900fc device
host 10.0.2.2 is alive
=> qemu-system-riscv64: terminating on signal 2


On real board, we generally boot OpenSBI+U-Boot. We will
try and share log of BBL+U-Boot on real board but the log will
look exactly like above.

Regards,
Anup
Andreas Schwab Jan. 21, 2019, 4:36 p.m. UTC | #6
On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:

> On real board, we generally boot OpenSBI+U-Boot. We will
> try and share log of BBL+U-Boot on real board but the log will
> look exactly like above.

Nothing is seen on the real board.

Andreas.
Anup Patel Jan. 21, 2019, 4:53 p.m. UTC | #7
On Mon, Jan 21, 2019 at 10:06 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:
>
> > On real board, we generally boot OpenSBI+U-Boot. We will
> > try and share log of BBL+U-Boot on real board but the log will
> > look exactly like above.
>
> Nothing is seen on the real board.

There is a fix required in BBL for real board. We have not send
this fix to riscv-pk.

BBL does not set "stdout-path" in /chosen DT node so you are not
seeing any output from U-Boot on real board. On QEMU, "stdout-path"
is set in DTB by QEMU itself so we don't see any issue on QEMU.

We typically run OpenSBI+U-Boot on real board and OpenSBI sets
"stdout-path" properly before jumping to next stage (i.e. U-Boot) so
even we don't see this issue at our end.

You can easily hack BBL for above fix at your end.

Regards,
Anup
Andreas Schwab Jan. 21, 2019, 5:10 p.m. UTC | #8
On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:

> There is a fix required in BBL for real board. We have not send
> this fix to riscv-pk.

Where can I find the patch?

Andreas.
Anup Patel Jan. 21, 2019, 5:32 p.m. UTC | #9
On Mon, Jan 21, 2019 at 10:40 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:
>
> > There is a fix required in BBL for real board. We have not send
> > this fix to riscv-pk.
>
> Where can I find the patch?

The fix is to set following DT prop in /chosen DT node:
stdout-path = "/soc/serial@10010000:115200"

As we can see, the "stdout-path" is specific to SiFive
FU540 board so setting it in BBL is a nasty hack
hence we did not push it anywhere.

Ideally, we should set above mentioned stdout-path
DT prop in SiFive FU540 DTS passed by FSBL.

Regards,
Anup
Bin Meng Jan. 22, 2019, 2:06 a.m. UTC | #10
On Fri, Jan 18, 2019 at 7:19 PM Anup Patel <Anup.Patel@wdc.com> wrote:
>
> This patch adds SiFive FU540 board support. For now, only
> SiFive serial, SiFive PRCI, and Cadance MACB drivers are
> only enabled. The SiFive FU540 defconfig by default builds
> U-Boot for S-Mode because U-Boot on SiFive FU540 will run
> in S-Mode as payload of BBL or OpenSBI.
>
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> Signed-off-by: Anup Patel <anup.patel@wdc.com>
> Reviewed-by: Alexander Graf <agraf@suse.de>
> ---
>  arch/riscv/Kconfig             |  4 ++++
>  board/sifive/fu540/Kconfig     | 42 +++++++++++++++++++++++++++++++++
>  board/sifive/fu540/MAINTAINERS |  9 +++++++
>  board/sifive/fu540/Makefile    |  5 ++++
>  board/sifive/fu540/fu540.c     | 17 ++++++++++++++
>  configs/sifive_fu540_defconfig | 11 +++++++++
>  include/configs/sifive-fu540.h | 43 ++++++++++++++++++++++++++++++++++
>  7 files changed, 131 insertions(+)
>  create mode 100644 board/sifive/fu540/Kconfig
>  create mode 100644 board/sifive/fu540/MAINTAINERS
>  create mode 100644 board/sifive/fu540/Makefile
>  create mode 100644 board/sifive/fu540/fu540.c
>  create mode 100644 configs/sifive_fu540_defconfig
>  create mode 100644 include/configs/sifive-fu540.h
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Andreas Schwab Jan. 22, 2019, 9:30 a.m. UTC | #11
On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:

> On Mon, Jan 21, 2019 at 10:40 PM Andreas Schwab <schwab@suse.de> wrote:
>>
>> On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:
>>
>> > There is a fix required in BBL for real board. We have not send
>> > this fix to riscv-pk.
>>
>> Where can I find the patch?
>
> The fix is to set following DT prop in /chosen DT node:
> stdout-path = "/soc/serial@10010000:115200"

How can I do that?  I cannot find any function in fdt.c to add new
nodes.

Andreas.
Atish Patra Jan. 23, 2019, 7:01 p.m. UTC | #12
On 1/22/19 1:30 AM, Andreas Schwab wrote:
> On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:
> 
>> On Mon, Jan 21, 2019 at 10:40 PM Andreas Schwab <schwab@suse.de> wrote:
>>>
>>> On Jan 21 2019, Anup Patel <anup@brainfault.org> wrote:
>>>
>>>> There is a fix required in BBL for real board. We have not send
>>>> this fix to riscv-pk.
>>>

Just to clarify, we hacked U-boot to add the serial driver not BBL.
Later, we modified the DT directly in OpenSBI to add the required node.

>>> Where can I find the patch?
>>
>> The fix is to set following DT prop in /chosen DT node:
>> stdout-path = "/soc/serial@10010000:115200"
> 
> How can I do that?I cannot find any function in fdt.c to add new
> nodes.
>   

There are several ways to do the hack.

BBL doesn't have libfdt included by default. Libfdt is included in 
u-boot. You can try adding that node in u-boot.

or
Here is another hack in U-boot until the OpenSBI is available (Early 
next week).

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index ffcd6d15..aa5ee2cc 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -54,6 +54,16 @@ static int serial_check_stdout(const void *blob, 
struct udevice **devp)
         }
         if (node < 0)
                 node = fdt_path_offset(blob, "console");
+
+       if (node < 0) {
+               const char *sname;
+               sname = fdt_get_alias(blob, "serial0");
+               printf("sname = [%s]\n", sname);
+               if (sname)
+                       node = fdt_path_offset(blob, sname);
+               printf("node = [%d]\n", node);
+       }
+
         if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, devp))
                 return 0;


or you can try to edit the DT directly and update the FSBL if you are 
comfortable with it.

Apologies, for the inconvenience. Sending these patches to U-boot 
doesn't make any sense its very board specific. In an ideal world, DT 
should be fixed directly to address these issues.

Regards,
Atish
> Andreas.
>
Andreas Schwab Jan. 24, 2019, 9:53 a.m. UTC | #13
On Jan 23 2019, Atish Patra <atish.patra@wdc.com> wrote:

> or you can try to edit the DT directly and update the FSBL if you are
> comfortable with it.

I think it would make sense to add the node in the board init function.
That way it would work whether or not the FSBL is updated.

Andreas.
Anup Patel Jan. 24, 2019, 10:43 a.m. UTC | #14
> -----Original Message-----
> From: Andreas Schwab [mailto:schwab@suse.de]
> Sent: Thursday, January 24, 2019 3:24 PM
> To: Atish Patra <Atish.Patra@wdc.com>
> Cc: Anup Patel <anup@brainfault.org>; Anup Patel <Anup.Patel@wdc.com>;
> Joe Hershberger <joe.hershberger@ni.com>; U-Boot Mailing List <u-
> boot@lists.denx.de>; Palmer Dabbelt <palmer@sifive.com>; Alexander Graf
> <agraf@suse.de>; Christoph Hellwig <hch@infradead.org>; Paul Walmsley
> <paul.walmsley@sifive.com>
> Subject: Re: [U-Boot] [PATCH v2 11/11] riscv: Add SiFive FU540 board support
> 
> On Jan 23 2019, Atish Patra <atish.patra@wdc.com> wrote:
> 
> > or you can try to edit the DT directly and update the FSBL if you are
> > comfortable with it.
> 
> I think it would make sense to add the node in the board init function.
> That way it would work whether or not the FSBL is updated.

Best way is to either fix in DTS itself or BBL/OpenSBI.

For BBL it is difficult due to lack of matured FDT manipulation APIs.
My bad for previous misinformation about BBL. I thought Atish had
hacked this in BBL but he had hacked U-Boot.

We already have taken care of this in OpenSBI using LibFDT so with
OpenSBI no hacks would be required.

We are just few days away from OpenSBI being made public so no point
of adding work-around for "stdout-path" in U-Boot as well.

Regards,
Anup
Alexander Graf Jan. 24, 2019, 10:46 a.m. UTC | #15
On 24.01.19 11:43, Anup Patel wrote:
> 
> 
>> -----Original Message-----
>> From: Andreas Schwab [mailto:schwab@suse.de]
>> Sent: Thursday, January 24, 2019 3:24 PM
>> To: Atish Patra <Atish.Patra@wdc.com>
>> Cc: Anup Patel <anup@brainfault.org>; Anup Patel <Anup.Patel@wdc.com>;
>> Joe Hershberger <joe.hershberger@ni.com>; U-Boot Mailing List <u-
>> boot@lists.denx.de>; Palmer Dabbelt <palmer@sifive.com>; Alexander Graf
>> <agraf@suse.de>; Christoph Hellwig <hch@infradead.org>; Paul Walmsley
>> <paul.walmsley@sifive.com>
>> Subject: Re: [U-Boot] [PATCH v2 11/11] riscv: Add SiFive FU540 board support
>>
>> On Jan 23 2019, Atish Patra <atish.patra@wdc.com> wrote:
>>
>>> or you can try to edit the DT directly and update the FSBL if you are
>>> comfortable with it.
>>
>> I think it would make sense to add the node in the board init function.
>> That way it would work whether or not the FSBL is updated.
> 
> Best way is to either fix in DTS itself or BBL/OpenSBI.
> 
> For BBL it is difficult due to lack of matured FDT manipulation APIs.
> My bad for previous misinformation about BBL. I thought Atish had
> hacked this in BBL but he had hacked U-Boot.
> 
> We already have taken care of this in OpenSBI using LibFDT so with
> OpenSBI no hacks would be required.
> 
> We are just few days away from OpenSBI being made public so no point
> of adding work-around for "stdout-path" in U-Boot as well.

I disagree. We want people to easily use this code, and not use it as a
means to push for the OpenSBI vs BBL discussion.

So IMHO a quirk that adds the stdout-path property in an early board
init function is the best way to move forward here. That way the "good"
case keeps behaving the same, but we stay compatible to current,
existing previous stage firmware.

Please, don't *ever* consider DT something that you "just modify". If
anything worked with a DT before, you are required to keep it that way.
Otherwise you break the compatibility contract between your firmware layers.


Alex
Anup Patel Jan. 24, 2019, 11:05 a.m. UTC | #16
On Thu, Jan 24, 2019 at 4:16 PM Alexander Graf <agraf@suse.de> wrote:
>
>
>
> On 24.01.19 11:43, Anup Patel wrote:
> >
> >
> >> -----Original Message-----
> >> From: Andreas Schwab [mailto:schwab@suse.de]
> >> Sent: Thursday, January 24, 2019 3:24 PM
> >> To: Atish Patra <Atish.Patra@wdc.com>
> >> Cc: Anup Patel <anup@brainfault.org>; Anup Patel <Anup.Patel@wdc.com>;
> >> Joe Hershberger <joe.hershberger@ni.com>; U-Boot Mailing List <u-
> >> boot@lists.denx.de>; Palmer Dabbelt <palmer@sifive.com>; Alexander Graf
> >> <agraf@suse.de>; Christoph Hellwig <hch@infradead.org>; Paul Walmsley
> >> <paul.walmsley@sifive.com>
> >> Subject: Re: [U-Boot] [PATCH v2 11/11] riscv: Add SiFive FU540 board support
> >>
> >> On Jan 23 2019, Atish Patra <atish.patra@wdc.com> wrote:
> >>
> >>> or you can try to edit the DT directly and update the FSBL if you are
> >>> comfortable with it.
> >>
> >> I think it would make sense to add the node in the board init function.
> >> That way it would work whether or not the FSBL is updated.
> >
> > Best way is to either fix in DTS itself or BBL/OpenSBI.
> >
> > For BBL it is difficult due to lack of matured FDT manipulation APIs.
> > My bad for previous misinformation about BBL. I thought Atish had
> > hacked this in BBL but he had hacked U-Boot.
> >
> > We already have taken care of this in OpenSBI using LibFDT so with
> > OpenSBI no hacks would be required.
> >
> > We are just few days away from OpenSBI being made public so no point
> > of adding work-around for "stdout-path" in U-Boot as well.
>
> I disagree. We want people to easily use this code, and not use it as a
> means to push for the OpenSBI vs BBL discussion.
>
> So IMHO a quirk that adds the stdout-path property in an early board
> init function is the best way to move forward here. That way the "good"
> case keeps behaving the same, but we stay compatible to current,
> existing previous stage firmware.
>
> Please, don't *ever* consider DT something that you "just modify". If
> anything worked with a DT before, you are required to keep it that way.
> Otherwise you break the compatibility contract between your firmware layers.

No issues, I will try to add it board_init().

Regards,
Anup
Alexander Graf Jan. 24, 2019, 11:18 a.m. UTC | #17
On 24.01.19 12:05, Anup Patel wrote:
> On Thu, Jan 24, 2019 at 4:16 PM Alexander Graf <agraf@suse.de> wrote:
>>
>>
>>
>> On 24.01.19 11:43, Anup Patel wrote:
>>>
>>>
>>>> -----Original Message-----
>>>> From: Andreas Schwab [mailto:schwab@suse.de]
>>>> Sent: Thursday, January 24, 2019 3:24 PM
>>>> To: Atish Patra <Atish.Patra@wdc.com>
>>>> Cc: Anup Patel <anup@brainfault.org>; Anup Patel <Anup.Patel@wdc.com>;
>>>> Joe Hershberger <joe.hershberger@ni.com>; U-Boot Mailing List <u-
>>>> boot@lists.denx.de>; Palmer Dabbelt <palmer@sifive.com>; Alexander Graf
>>>> <agraf@suse.de>; Christoph Hellwig <hch@infradead.org>; Paul Walmsley
>>>> <paul.walmsley@sifive.com>
>>>> Subject: Re: [U-Boot] [PATCH v2 11/11] riscv: Add SiFive FU540 board support
>>>>
>>>> On Jan 23 2019, Atish Patra <atish.patra@wdc.com> wrote:
>>>>
>>>>> or you can try to edit the DT directly and update the FSBL if you are
>>>>> comfortable with it.
>>>>
>>>> I think it would make sense to add the node in the board init function.
>>>> That way it would work whether or not the FSBL is updated.
>>>
>>> Best way is to either fix in DTS itself or BBL/OpenSBI.
>>>
>>> For BBL it is difficult due to lack of matured FDT manipulation APIs.
>>> My bad for previous misinformation about BBL. I thought Atish had
>>> hacked this in BBL but he had hacked U-Boot.
>>>
>>> We already have taken care of this in OpenSBI using LibFDT so with
>>> OpenSBI no hacks would be required.
>>>
>>> We are just few days away from OpenSBI being made public so no point
>>> of adding work-around for "stdout-path" in U-Boot as well.
>>
>> I disagree. We want people to easily use this code, and not use it as a
>> means to push for the OpenSBI vs BBL discussion.
>>
>> So IMHO a quirk that adds the stdout-path property in an early board
>> init function is the best way to move forward here. That way the "good"
>> case keeps behaving the same, but we stay compatible to current,
>> existing previous stage firmware.
>>
>> Please, don't *ever* consider DT something that you "just modify". If
>> anything worked with a DT before, you are required to keep it that way.
>> Otherwise you break the compatibility contract between your firmware layers.
> 
> No issues, I will try to add it board_init().

Board_init() is too late. This needs to go into early_board_init_f().
IIUC Andreas is prototyping that approach right now.


Alex
Anup Patel Jan. 24, 2019, 12:52 p.m. UTC | #18
On Thu, Jan 24, 2019 at 4:48 PM Alexander Graf <agraf@suse.de> wrote:
>
>
>
> On 24.01.19 12:05, Anup Patel wrote:
> > On Thu, Jan 24, 2019 at 4:16 PM Alexander Graf <agraf@suse.de> wrote:
> >>
> >>
> >>
> >> On 24.01.19 11:43, Anup Patel wrote:
> >>>
> >>>
> >>>> -----Original Message-----
> >>>> From: Andreas Schwab [mailto:schwab@suse.de]
> >>>> Sent: Thursday, January 24, 2019 3:24 PM
> >>>> To: Atish Patra <Atish.Patra@wdc.com>
> >>>> Cc: Anup Patel <anup@brainfault.org>; Anup Patel <Anup.Patel@wdc.com>;
> >>>> Joe Hershberger <joe.hershberger@ni.com>; U-Boot Mailing List <u-
> >>>> boot@lists.denx.de>; Palmer Dabbelt <palmer@sifive.com>; Alexander Graf
> >>>> <agraf@suse.de>; Christoph Hellwig <hch@infradead.org>; Paul Walmsley
> >>>> <paul.walmsley@sifive.com>
> >>>> Subject: Re: [U-Boot] [PATCH v2 11/11] riscv: Add SiFive FU540 board support
> >>>>
> >>>> On Jan 23 2019, Atish Patra <atish.patra@wdc.com> wrote:
> >>>>
> >>>>> or you can try to edit the DT directly and update the FSBL if you are
> >>>>> comfortable with it.
> >>>>
> >>>> I think it would make sense to add the node in the board init function.
> >>>> That way it would work whether or not the FSBL is updated.
> >>>
> >>> Best way is to either fix in DTS itself or BBL/OpenSBI.
> >>>
> >>> For BBL it is difficult due to lack of matured FDT manipulation APIs.
> >>> My bad for previous misinformation about BBL. I thought Atish had
> >>> hacked this in BBL but he had hacked U-Boot.
> >>>
> >>> We already have taken care of this in OpenSBI using LibFDT so with
> >>> OpenSBI no hacks would be required.
> >>>
> >>> We are just few days away from OpenSBI being made public so no point
> >>> of adding work-around for "stdout-path" in U-Boot as well.
> >>
> >> I disagree. We want people to easily use this code, and not use it as a
> >> means to push for the OpenSBI vs BBL discussion.
> >>
> >> So IMHO a quirk that adds the stdout-path property in an early board
> >> init function is the best way to move forward here. That way the "good"
> >> case keeps behaving the same, but we stay compatible to current,
> >> existing previous stage firmware.
> >>
> >> Please, don't *ever* consider DT something that you "just modify". If
> >> anything worked with a DT before, you are required to keep it that way.
> >> Otherwise you break the compatibility contract between your firmware layers.
> >
> > No issues, I will try to add it board_init().
>
> Board_init() is too late. This needs to go into early_board_init_f().
> IIUC Andreas is prototyping that approach right now.

Thanks Alex and Andreas.

My latest patches are in riscv_sifive_fu540_v4 branch of
https://github.com/avpatel/u-boot

I can include Andreas's patch in my v5. If he is fine with it.

Regards,
Anup

>
>
> Alex
Andreas Schwab Jan. 24, 2019, 1:38 p.m. UTC | #19
On Jan 24 2019, Alexander Graf <agraf@suse.de> wrote:

> Board_init() is too late. This needs to go into early_board_init_f().

I don't think we can modify the DT that early.

Andreas.
Alexander Graf Jan. 24, 2019, 1:53 p.m. UTC | #20
On 24.01.19 14:38, Andreas Schwab wrote:
> On Jan 24 2019, Alexander Graf <agraf@suse.de> wrote:
> 
>> Board_init() is too late. This needs to go into early_board_init_f().
> 
> I don't think we can modify the DT that early.

I'm sure we can. Worst case we have to copy it over to RAM first.

What obstacle exactly did you run into? Did you try to prototype the
change in a QEMU environment first to get some better debugging insights?


Alex
Andreas Schwab Jan. 24, 2019, 1:57 p.m. UTC | #21
On Jan 24 2019, Alexander Graf <agraf@suse.de> wrote:

> On 24.01.19 14:38, Andreas Schwab wrote:
>> On Jan 24 2019, Alexander Graf <agraf@suse.de> wrote:
>> 
>>> Board_init() is too late. This needs to go into early_board_init_f().
>> 
>> I don't think we can modify the DT that early.
>
> I'm sure we can. Worst case we have to copy it over to RAM first.

reserve_fdt is only called much later.

Andreas.
Anup Patel Feb. 3, 2019, 7:41 a.m. UTC | #22
On Thu, Jan 24, 2019 at 7:27 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Jan 24 2019, Alexander Graf <agraf@suse.de> wrote:
>
> > On 24.01.19 14:38, Andreas Schwab wrote:
> >> On Jan 24 2019, Alexander Graf <agraf@suse.de> wrote:
> >>
> >>> Board_init() is too late. This needs to go into early_board_init_f().
> >>
> >> I don't think we can modify the DT that early.
> >
> > I'm sure we can. Worst case we have to copy it over to RAM first.
>
> reserve_fdt is only called much later.

OpenSBI is public now.

Can try with https://github.com/riscv/opensbi.git ?

There is README for SiFive FU540 at
<opensbi_sources>/docs/platform/sifive_fu540.md

Regards,
Anup
Andreas Schwab Feb. 4, 2019, 11:17 a.m. UTC | #23
On Feb 03 2019, Anup Patel <anup@brainfault.org> wrote:

> Can try with https://github.com/riscv/opensbi.git ?

 AS-DEP    platform/sifive/fu540/firmware/fw_payload.dep
/bin/sh: -g: command not found

Andreas.
Atish Patra Feb. 4, 2019, 1:03 p.m. UTC | #24
Probably your cross compilation is not set. Can you try this ?

export ARCH=riscv
export CROSS_COMPILE= <riscv cross compile prefix>

Sent from my iPhone

> On Feb 4, 2019, at 11:17 AM, Andreas Schwab <schwab@suse.de> wrote:
> 
>> On Feb 03 2019, Anup Patel <anup@brainfault.org> wrote:
>> 
>> Can try with https://github.com/riscv/opensbi.git ?
> 
> AS-DEP    platform/sifive/fu540/firmware/fw_payload.dep
> /bin/sh: -g: command not found
> 
> Andreas.
> 
> -- 
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."
Andreas Schwab Feb. 4, 2019, 1:10 p.m. UTC | #25
On Feb 04 2019, Atish Patra <Atish.Patra@wdc.com> wrote:

> Probably your cross compilation is not set. Can you try this ?
>
> export ARCH=riscv
> export CROSS_COMPILE= <riscv cross compile prefix>

There is no cross compile prefix.

Andreas.
Anup Patel Feb. 5, 2019, 12:14 p.m. UTC | #26
On Mon, Feb 4, 2019 at 6:40 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Feb 04 2019, Atish Patra <Atish.Patra@wdc.com> wrote:
>
> > Probably your cross compilation is not set. Can you try this ?
> >
> > export ARCH=riscv
> > export CROSS_COMPILE= <riscv cross compile prefix>
>
> There is no cross compile prefix.
>

The OpenSBI build is similar to Linux and U-Boot. We expect
CROSS_COMPILE environment variable to be set.

Make sure, CROSS_COMPILE environment variable is set and
exported before running make.

Example, if you cross-compiler is riscv64-unknown-linux-gnu-gcc
then do:
# export CROSS_COMPILE=riscv64-unknown-linux-gnu-

Regards,
Anup
Andreas Schwab Feb. 5, 2019, 12:51 p.m. UTC | #27
On Feb 05 2019, Anup Patel <anup@brainfault.org> wrote:

> The OpenSBI build is similar to Linux and U-Boot. We expect
> CROSS_COMPILE environment variable to be set.

Why?  That doesn't make sense.

> Example, if you cross-compiler

I don't have a cross compiler.

Andreas.
Anup Patel Feb. 5, 2019, 12:58 p.m. UTC | #28
On Tue, Feb 5, 2019 at 6:21 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Feb 05 2019, Anup Patel <anup@brainfault.org> wrote:
>
> > The OpenSBI build is similar to Linux and U-Boot. We expect
> > CROSS_COMPILE environment variable to be set.
>
> Why?  That doesn't make sense.

Use of CROSS_COMPILE environment variable is
pretty common across open-source projects to support
cross compilation.

>
> > Example, if you cross-compiler
>
> I don't have a cross compiler.

Okay, if you are doing native compilation then
make sure CROSS_COMPILE is not set so that
makefile will take native compiler instead of
cross-compiler.

Regards.
Anup
Andreas Schwab Feb. 5, 2019, 1:40 p.m. UTC | #29
On Feb 05 2019, Anup Patel <anup@brainfault.org> wrote:

> Okay, if you are doing native compilation then
> make sure CROSS_COMPILE is not set so that
> makefile will take native compiler instead of
> cross-compiler.

 AS-DEP    platform/sifive/fu540/firmware/fw_payload.dep
/bin/sh: -g: command not found

Andreas.
Anup Patel Feb. 5, 2019, 2:28 p.m. UTC | #30
On Tue, Feb 5, 2019 at 7:10 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Feb 05 2019, Anup Patel <anup@brainfault.org> wrote:
>
> > Okay, if you are doing native compilation then
> > make sure CROSS_COMPILE is not set so that
> > makefile will take native compiler instead of
> > cross-compiler.
>
>  AS-DEP    platform/sifive/fu540/firmware/fw_payload.dep
> /bin/sh: -g: command not found

Can you share output of make with "V=1" parameter?

Regards,
Anup
Andreas Schwab Feb. 5, 2019, 2:39 p.m. UTC | #31
mkdir -p `dirname /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep`; echo " AS-DEP    platform/sifive/fu540/firmware/fw_payload.dep"; echo -n `dirname /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep`/ > /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep &&  -g -Wall -nostdlib -D__ASSEMBLY__ -fno-omit-frame-pointer -fno-optimize-sibling-calls -mno-save-restore -mstrict-align -I/net/hawking/daten/src/riscv/opensbi/platform/sifive/fu540/include -I/net/hawking/daten/src/riscv/opensbi/platform/common/include -I/net/hawking/daten/src/riscv/opensbi/include -I/net/hawking/daten/src/riscv/opensbi/platform/common/libfdt/   -DFW_TEXT_START=0x80000000 -DFW_JUMP_ADDR=0x80200000 -DFW_JUMP_FDT_ADDR=0x82200000 -DFW_PAYLOAD_PATH=/boot/Image-5.0.0-rc5-00011-gcf1db34127ee -DFW_PAYLOAD_OFFSET=0x200000 -DFW_PAYLOAD_FDT_ADDR=0x82200000 -mabi=lp64 -march=rv64imafdc -mcmodel=medany  -I/net/hawking/daten/src/riscv/opensbi/firmware -D__OBJNAME__=fw_payload.dep -MM /net/hawking/daten/src/riscv/opensbi/firmware/fw_payload.S >> /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep || rm -f /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep

Andreas.
Anup Patel Feb. 5, 2019, 2:43 p.m. UTC | #32
On Tue, Feb 5, 2019 at 8:09 PM Andreas Schwab <schwab@suse.de> wrote:
>
> mkdir -p `dirname /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep`; echo " AS-DEP    platform/sifive/fu540/firmware/fw_payload.dep"; echo -n `dirname /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep`/ > /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep &&  -g -Wall -nostdlib -D__ASSEMBLY__ -fno-omit-frame-pointer -fno-optimize-sibling-calls -mno-save-restore -mstrict-align -I/net/hawking/daten/src/riscv/opensbi/platform/sifive/fu540/include -I/net/hawking/daten/src/riscv/opensbi/platform/common/include -I/net/hawking/daten/src/riscv/opensbi/include -I/net/hawking/daten/src/riscv/opensbi/platform/common/libfdt/   -DFW_TEXT_START=0x80000000 -DFW_JUMP_ADDR=0x80200000 -DFW_JUMP_FDT_ADDR=0x82200000 -DFW_PAYLOAD_PATH=/boot/Image-5.0.0-rc5-00011-gcf1db34127ee -DFW_PAYLOAD_OFFSET=0x200000 -DFW_PAYLOAD_FDT_ADDR=0x82200000 -mabi=lp64 -march=rv64imafdc -mcmodel=medany  -I/net/hawking/daten/src/riscv/opensbi/firmware -D__OBJNAME__=fw_payload.dep -MM /net/hawking/daten/src/riscv/opensbi/firmware/fw_payload.S >> /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep || rm -f /net/hawking/daten/src/riscv/opensbi/build/platform/sifive/fu540/firmware/fw_payload.dep

Ahh, looks like it is not picking up "CC" set by Makefile. This might
be because you have removed "-R" from MAKEFLAGS.

CC should be either "$(CROSS_COMPILE)gcc" or "gcc".

Regards,
Anup
Andreas Schwab Feb. 5, 2019, 3 p.m. UTC | #33
On Feb 05 2019, Anup Patel <anup@brainfault.org> wrote:

> Ahh, looks like it is not picking up "CC" set by Makefile. This might
> be because you have removed "-R" from MAKEFLAGS.

Nope.  That fixed it.

Andreas.
Anup Patel Feb. 5, 2019, 3:04 p.m. UTC | #34
On Tue, Feb 5, 2019 at 8:30 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Feb 05 2019, Anup Patel <anup@brainfault.org> wrote:
>
> > Ahh, looks like it is not picking up "CC" set by Makefile. This might
> > be because you have removed "-R" from MAKEFLAGS.
>
> Nope.  That fixed it.

Cool, I had already approved your PR on OpenSBI Github.

Most of us just do cross-compilation so thanks for trying
native compilation.

Regards,
Anup
diff mbox series

Patch

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 6879047ff7..36512a8995 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -14,11 +14,15 @@  config TARGET_AX25_AE350
 config TARGET_QEMU_VIRT
 	bool "Support QEMU Virt Board"
 
+config TARGET_SIFIVE_FU540
+	bool "Support SiFive FU540 Board"
+
 endchoice
 
 # board-specific options below
 source "board/AndesTech/ax25-ae350/Kconfig"
 source "board/emulation/qemu-riscv/Kconfig"
+source "board/sifive/fu540/Kconfig"
 
 # platform-specific options below
 source "arch/riscv/cpu/ax25/Kconfig"
diff --git a/board/sifive/fu540/Kconfig b/board/sifive/fu540/Kconfig
new file mode 100644
index 0000000000..6be3d88144
--- /dev/null
+++ b/board/sifive/fu540/Kconfig
@@ -0,0 +1,42 @@ 
+if TARGET_SIFIVE_FU540
+
+config SYS_BOARD
+	default "fu540"
+
+config SYS_VENDOR
+	default "sifive"
+
+config SYS_CPU
+	default "generic"
+
+config SYS_CONFIG_NAME
+	default "sifive-fu540"
+
+config SYS_TEXT_BASE
+	default 0x80000000 if !RISCV_SMODE
+	default 0x80200000 if RISCV_SMODE
+
+config BOARD_SPECIFIC_OPTIONS # dummy
+	def_bool y
+	select GENERIC_RISCV
+	imply CMD_DHCP
+	imply CMD_EXT2
+	imply CMD_EXT4
+	imply CMD_FAT
+	imply CMD_FS_GENERIC
+	imply CMD_NET
+	imply CMD_PING
+	imply CLK_SIFIVE
+	imply CLK_SIFIVE_FU540_PRCI
+	imply DOS_PARTITION
+	imply EFI_PARTITION
+	imply IP_DYN
+	imply ISO_PARTITION
+	imply MACB
+	imply MII
+	imply NET_RANDOM_ETHADDR
+	imply PHY_LIB
+	imply PHY_MSCC
+	imply SIFIVE_SERIAL
+
+endif
diff --git a/board/sifive/fu540/MAINTAINERS b/board/sifive/fu540/MAINTAINERS
new file mode 100644
index 0000000000..702d803ad8
--- /dev/null
+++ b/board/sifive/fu540/MAINTAINERS
@@ -0,0 +1,9 @@ 
+SiFive FU540 BOARD
+M:	Paul Walmsley <paul.walmsley@sifive.com>
+M:	Palmer Dabbelt <palmer@sifive.com>
+M:	Anup Patel <anup.patel@wdc.com>
+M:	Atish Patra <atish.patra@wdc.com>
+S:	Maintained
+F:	board/sifive/fu540/
+F:	include/configs/sifive-fu540.h
+F:	configs/sifive_fu540_defconfig
diff --git a/board/sifive/fu540/Makefile b/board/sifive/fu540/Makefile
new file mode 100644
index 0000000000..6e1862c475
--- /dev/null
+++ b/board/sifive/fu540/Makefile
@@ -0,0 +1,5 @@ 
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2019 Western Digital Corporation or its affiliates.
+
+obj-y	+= fu540.o
diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
new file mode 100644
index 0000000000..5adc4a3d4a
--- /dev/null
+++ b/board/sifive/fu540/fu540.c
@@ -0,0 +1,17 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *   Anup Patel <anup.patel@wdc.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+
+int board_init(void)
+{
+	/* For now nothing to do here. */
+
+	return 0;
+}
diff --git a/configs/sifive_fu540_defconfig b/configs/sifive_fu540_defconfig
new file mode 100644
index 0000000000..2f8cca9de0
--- /dev/null
+++ b/configs/sifive_fu540_defconfig
@@ -0,0 +1,11 @@ 
+CONFIG_RISCV=y
+CONFIG_TARGET_SIFIVE_FU540=y
+CONFIG_RISCV_SMODE=y
+CONFIG_ARCH_RV64I=y
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_FIT=y
+CONFIG_DISPLAY_CPUINFO=y
+CONFIG_DISPLAY_BOARDINFO=y
+CONFIG_CMD_MII=y
+CONFIG_OF_PRIOR_STAGE=y
diff --git a/include/configs/sifive-fu540.h b/include/configs/sifive-fu540.h
new file mode 100644
index 0000000000..7007b5f6af
--- /dev/null
+++ b/include/configs/sifive-fu540.h
@@ -0,0 +1,43 @@ 
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2019 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *   Anup Patel <anup.patel@wdc.com>
+ */
+
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#include <linux/sizes.h>
+
+#define CONFIG_SYS_SDRAM_BASE		0x80000000
+#define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_SDRAM_BASE + SZ_2M)
+
+#define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE + SZ_2M)
+
+#define CONFIG_SYS_MALLOC_LEN		SZ_8M
+
+#define CONFIG_SYS_BOOTM_LEN		SZ_16M
+
+#define CONFIG_STANDALONE_LOAD_ADDR	0x80200000
+
+/* Environment options */
+#define CONFIG_ENV_SIZE			SZ_4K
+
+#define BOOT_TARGET_DEVICES(func) \
+	func(DHCP, dhcp, na)
+
+#include <config_distro_bootcmd.h>
+
+#define CONFIG_EXTRA_ENV_SETTINGS \
+	"fdt_high=0xffffffffffffffff\0" \
+	"initrd_high=0xffffffffffffffff\0" \
+	"kernel_addr_r=0x80600000\0" \
+	"fdt_addr_r=0x82200000\0" \
+	"scriptaddr=0x82300000\0" \
+	"pxefile_addr_r=0x82400000\0" \
+	"ramdisk_addr_r=0x82500000\0" \
+	BOOTENV
+
+#endif /* __CONFIG_H */