Re: [PATCH v2 07/11] riscv: Add initial Sipeed Maix support

2020-02-01 Thread Sean Anderson
On 1/30/20 5:21 PM, Lukas Auer wrote:
> Interesting, I thought all SD cards support SPI mode.

I think it's a different issue, but I wasn't sure.

>> The board I am using has some serial issues which makes it difficult to
>> flash any large images. I can get u-boot to flash after several
>> attempts, but something like the linux kernel is far too unreliable to
>> test regularly. I'm going to see if I can get my hands on another k210
>> board which hopefully doesn't have these issues.
> 
> Ah ok, that's unfortunate. Thank you for your efforts!

I have since found a computer where the serial works fine (which implies
that the USB hardware on my current computer has some issues).  I should
be able to flash larger binaries fine now, but the current issue is
getting the SPI to work.  I think there may be some subtle differences
between the driver and the manufacturer's sdk.

I am also having some clock problems, despite (obstensibly) performing
the same incantations as the sdk. I guess this is what happens when they
refuse to release a technical reference...

--Sean



Re: [PATCH v2 07/11] riscv: Add initial Sipeed Maix support

2020-01-30 Thread Lukas Auer
On Sun, 2020-01-26 at 20:09 -0500, Sean Anderson wrote:
> On 1/26/20 5:17 PM, Lukas Auer wrote:
> > Hi Sean,
> > 
> > 
> > On Wed, 2020-01-15 at 18:04 -0500, Sean Anderson wrote:
> > > The Sipeed Maix series is a collection of boards built around the RISC-V
> > > Kendryte K210 processor. This processor contains several peripherals to
> > > accelerate neural network processing and other "ai" tasks. This includes 
> > > a "KPU"
> > > neural network processor, an audio processor supporting beamforming 
> > > reception,
> > > and a digital video port supporting capture and output at VGA resolution. 
> > > Other
> > > peripherals include 8M of sram (accessible with and without caching);
> > > remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a 
> > > DMA
> > > controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but
> > > include spi flash; on-board usb-serial bridges; ports for cameras, 
> > > displays, and
> > > sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 
> > > (bitm) is
> > > supported, but the boards are fairly similar.
> > > 
> > > Documentation for Maix boards is located at 
> > > ;;.
> > > Documentation for the Kendryte K210 is located at
> > > ;;. However, hardware details are rather 
> > > lacking,
> > > so most technical reference has been taken from the standalone sdk 
> > > located at
> > > ;;.
> > > 
> > > Signed-off-by: Sean Anderson 
> > 
> > This patch should be the last in the patch series, because it requires
> > all other patches in the series.
> 
> Ok, will reorder it for v3.
> 
> > > ---
> > > Changes for v2:
> > >   Select CONFIG_SYS_RISCV_NOCOUNTER.
> > >   Imply CONFIG_CLK_K210.
> > >   Remove spurious references to CONFIG_ARCH_K210.
> > >   Remove many configs from defconfig where the defaults were fine.
> > >   Add a few "not set" lines to suppress unneeded defaults.
> > >   Reduce pre-reloc malloc space, now that clocks initialization happens
> > >   later.
> > >   
> > >  arch/riscv/Kconfig |  4 ++
> > >  board/sipeed/maix/Kconfig  | 41 +
> > >  board/sipeed/maix/MAINTAINERS  | 13 +
> > >  board/sipeed/maix/Makefile |  5 ++
> > >  board/sipeed/maix/maix.c   |  9 +++
> > >  configs/sipeed_maix_bitm_defconfig | 93 ++
> > >  include/configs/sipeed-maix.h  | 19 ++
> > >  7 files changed, 184 insertions(+)
> > >  create mode 100644 board/sipeed/maix/Kconfig
> > >  create mode 100644 board/sipeed/maix/MAINTAINERS
> > >  create mode 100644 board/sipeed/maix/Makefile
> > >  create mode 100644 board/sipeed/maix/maix.c
> > >  create mode 100644 configs/sipeed_maix_bitm_defconfig
> > >  create mode 100644 include/configs/sipeed-maix.h
> > > 
> > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > > index 4f8c62dcff..4c62b8dd77 100644
> > > --- a/arch/riscv/Kconfig
> > > +++ b/arch/riscv/Kconfig
> > > @@ -20,6 +20,9 @@ config TARGET_QEMU_VIRT
> > >  config TARGET_SIFIVE_FU540
> > >   bool "Support SiFive FU540 Board"
> > >  
> > > +config TARGET_SIPEED_MAIX
> > > + bool "Support Sipeed Maix Board"
> > > +
> > >  endchoice
> > >  
> > >  config SYS_ICACHE_OFF
> > > @@ -53,6 +56,7 @@ source "board/AndesTech/ax25-ae350/Kconfig"
> > >  source "board/emulation/qemu-riscv/Kconfig"
> > >  source "board/microchip/mpfs_icicle/Kconfig"
> > >  source "board/sifive/fu540/Kconfig"
> > > +source "board/sipeed/maix/Kconfig"
> > >  
> > >  # platform-specific options below
> > >  source "arch/riscv/cpu/ax25/Kconfig"
> > > diff --git a/board/sipeed/maix/Kconfig b/board/sipeed/maix/Kconfig
> > > new file mode 100644
> > > index 00..9259eb34aa
> > > --- /dev/null
> > > +++ b/board/sipeed/maix/Kconfig
> > > @@ -0,0 +1,41 @@
> > > +# SPDX-License-Identifier: GPL-2.0+
> > > +# Copyright (C) 2019 Sean Anderson 
> > > +
> > > +if TARGET_SIPEED_MAIX
> > > +
> > > +config SYS_BOARD
> > > + default "maix"
> > > +
> > > +config SYS_VENDOR
> > > + default "sipeed"
> > > +
> > > +config SYS_CPU
> > > + default "generic"
> > > +
> > > +config SYS_CONFIG_NAME
> > > + default "sipeed-maix"
> > > +
> > > +config SYS_TEXT_BASE
> > > + default 0x8000
> > > +
> > > +config NR_CPUS
> > > + default 2
> > > +
> > > +config NR_DRAM_BANKS
> > > + default 2
> > > +
> > > +config BOARD_SPECIFIC_OPTIONS
> > > + def_bool y
> > > + select GENERIC_RISCV
> > > + select DM_SERIAL
> > > + select SIFIVE_SERIAL
> > > + select ARCH_DEFAULT_RV64I
> > > + select ENV_IS_NOWHERE
> > 
> > ENV_IS_NOWHERE is automatically selected if no other environment
> > provider is available, so no need to include it here.
> 
> Ok, I will remove that in v3. As a general rule, what sort of things
> should be in Kconfig vs in the default config? I initially thought that
> all dependencies should be in Kconfig, but "imply" just seems to set the
> default, which means it won't 

Re: [PATCH v2 07/11] riscv: Add initial Sipeed Maix support

2020-01-26 Thread Sean Anderson
On 1/26/20 5:17 PM, Lukas Auer wrote:
> Hi Sean,
> 
> 
> On Wed, 2020-01-15 at 18:04 -0500, Sean Anderson wrote:
>> The Sipeed Maix series is a collection of boards built around the RISC-V
>> Kendryte K210 processor. This processor contains several peripherals to
>> accelerate neural network processing and other "ai" tasks. This includes a 
>> "KPU"
>> neural network processor, an audio processor supporting beamforming 
>> reception,
>> and a digital video port supporting capture and output at VGA resolution. 
>> Other
>> peripherals include 8M of sram (accessible with and without caching);
>> remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA
>> controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but
>> include spi flash; on-board usb-serial bridges; ports for cameras, displays, 
>> and
>> sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is
>> supported, but the boards are fairly similar.
>>
>> Documentation for Maix boards is located at 
>> ;.
>> Documentation for the Kendryte K210 is located at
>> ;. However, hardware details are rather 
>> lacking,
>> so most technical reference has been taken from the standalone sdk located at
>> ;.
>>
>> Signed-off-by: Sean Anderson 
> 
> This patch should be the last in the patch series, because it requires
> all other patches in the series.

Ok, will reorder it for v3.

>> ---
>> Changes for v2:
>>   Select CONFIG_SYS_RISCV_NOCOUNTER.
>>   Imply CONFIG_CLK_K210.
>>   Remove spurious references to CONFIG_ARCH_K210.
>>   Remove many configs from defconfig where the defaults were fine.
>>   Add a few "not set" lines to suppress unneeded defaults.
>>   Reduce pre-reloc malloc space, now that clocks initialization happens
>>   later.
>>   
>>  arch/riscv/Kconfig |  4 ++
>>  board/sipeed/maix/Kconfig  | 41 +
>>  board/sipeed/maix/MAINTAINERS  | 13 +
>>  board/sipeed/maix/Makefile |  5 ++
>>  board/sipeed/maix/maix.c   |  9 +++
>>  configs/sipeed_maix_bitm_defconfig | 93 ++
>>  include/configs/sipeed-maix.h  | 19 ++
>>  7 files changed, 184 insertions(+)
>>  create mode 100644 board/sipeed/maix/Kconfig
>>  create mode 100644 board/sipeed/maix/MAINTAINERS
>>  create mode 100644 board/sipeed/maix/Makefile
>>  create mode 100644 board/sipeed/maix/maix.c
>>  create mode 100644 configs/sipeed_maix_bitm_defconfig
>>  create mode 100644 include/configs/sipeed-maix.h
>>
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> index 4f8c62dcff..4c62b8dd77 100644
>> --- a/arch/riscv/Kconfig
>> +++ b/arch/riscv/Kconfig
>> @@ -20,6 +20,9 @@ config TARGET_QEMU_VIRT
>>  config TARGET_SIFIVE_FU540
>>  bool "Support SiFive FU540 Board"
>>  
>> +config TARGET_SIPEED_MAIX
>> +bool "Support Sipeed Maix Board"
>> +
>>  endchoice
>>  
>>  config SYS_ICACHE_OFF
>> @@ -53,6 +56,7 @@ source "board/AndesTech/ax25-ae350/Kconfig"
>>  source "board/emulation/qemu-riscv/Kconfig"
>>  source "board/microchip/mpfs_icicle/Kconfig"
>>  source "board/sifive/fu540/Kconfig"
>> +source "board/sipeed/maix/Kconfig"
>>  
>>  # platform-specific options below
>>  source "arch/riscv/cpu/ax25/Kconfig"
>> diff --git a/board/sipeed/maix/Kconfig b/board/sipeed/maix/Kconfig
>> new file mode 100644
>> index 00..9259eb34aa
>> --- /dev/null
>> +++ b/board/sipeed/maix/Kconfig
>> @@ -0,0 +1,41 @@
>> +# SPDX-License-Identifier: GPL-2.0+
>> +# Copyright (C) 2019 Sean Anderson 
>> +
>> +if TARGET_SIPEED_MAIX
>> +
>> +config SYS_BOARD
>> +default "maix"
>> +
>> +config SYS_VENDOR
>> +default "sipeed"
>> +
>> +config SYS_CPU
>> +default "generic"
>> +
>> +config SYS_CONFIG_NAME
>> +default "sipeed-maix"
>> +
>> +config SYS_TEXT_BASE
>> +default 0x8000
>> +
>> +config NR_CPUS
>> +default 2
>> +
>> +config NR_DRAM_BANKS
>> +default 2
>> +
>> +config BOARD_SPECIFIC_OPTIONS
>> +def_bool y
>> +select GENERIC_RISCV
>> +select DM_SERIAL
>> +select SIFIVE_SERIAL
>> +select ARCH_DEFAULT_RV64I
>> +select ENV_IS_NOWHERE
> 
> ENV_IS_NOWHERE is automatically selected if no other environment
> provider is available, so no need to include it here.

Ok, I will remove that in v3. As a general rule, what sort of things
should be in Kconfig vs in the default config? I initially thought that
all dependencies should be in Kconfig, but "imply" just seems to set the
default, which means it won't be changed if you pick another board and
then pick this one.

> Also, why are you not using the SD card to store the environment?

I haven't managed to get my SD card working yet. I think it may be too
big (it's 32G), so I am planning to find a smaller one. 

>> +select SYS_RISCV_NOCOUNTER
>> +imply SIFIVE_CLINT
>> +imply SPI
>> +imply DM_GPIO
>> +imply CMD_GPIO
>> +imply SYS_NS16550

Re: [PATCH v2 07/11] riscv: Add initial Sipeed Maix support

2020-01-26 Thread Lukas Auer
Hi Sean,


On Wed, 2020-01-15 at 18:04 -0500, Sean Anderson wrote:
> The Sipeed Maix series is a collection of boards built around the RISC-V
> Kendryte K210 processor. This processor contains several peripherals to
> accelerate neural network processing and other "ai" tasks. This includes a 
> "KPU"
> neural network processor, an audio processor supporting beamforming reception,
> and a digital video port supporting capture and output at VGA resolution. 
> Other
> peripherals include 8M of sram (accessible with and without caching);
> remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA
> controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but
> include spi flash; on-board usb-serial bridges; ports for cameras, displays, 
> and
> sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is
> supported, but the boards are fairly similar.
> 
> Documentation for Maix boards is located at ;.
> Documentation for the Kendryte K210 is located at
> ;. However, hardware details are rather 
> lacking,
> so most technical reference has been taken from the standalone sdk located at
> ;.
> 
> Signed-off-by: Sean Anderson 

This patch should be the last in the patch series, because it requires
all other patches in the series.

> ---
> Changes for v2:
>   Select CONFIG_SYS_RISCV_NOCOUNTER.
>   Imply CONFIG_CLK_K210.
>   Remove spurious references to CONFIG_ARCH_K210.
>   Remove many configs from defconfig where the defaults were fine.
>   Add a few "not set" lines to suppress unneeded defaults.
>   Reduce pre-reloc malloc space, now that clocks initialization happens
>   later.
>   
>  arch/riscv/Kconfig |  4 ++
>  board/sipeed/maix/Kconfig  | 41 +
>  board/sipeed/maix/MAINTAINERS  | 13 +
>  board/sipeed/maix/Makefile |  5 ++
>  board/sipeed/maix/maix.c   |  9 +++
>  configs/sipeed_maix_bitm_defconfig | 93 ++
>  include/configs/sipeed-maix.h  | 19 ++
>  7 files changed, 184 insertions(+)
>  create mode 100644 board/sipeed/maix/Kconfig
>  create mode 100644 board/sipeed/maix/MAINTAINERS
>  create mode 100644 board/sipeed/maix/Makefile
>  create mode 100644 board/sipeed/maix/maix.c
>  create mode 100644 configs/sipeed_maix_bitm_defconfig
>  create mode 100644 include/configs/sipeed-maix.h
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 4f8c62dcff..4c62b8dd77 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -20,6 +20,9 @@ config TARGET_QEMU_VIRT
>  config TARGET_SIFIVE_FU540
>   bool "Support SiFive FU540 Board"
>  
> +config TARGET_SIPEED_MAIX
> + bool "Support Sipeed Maix Board"
> +
>  endchoice
>  
>  config SYS_ICACHE_OFF
> @@ -53,6 +56,7 @@ source "board/AndesTech/ax25-ae350/Kconfig"
>  source "board/emulation/qemu-riscv/Kconfig"
>  source "board/microchip/mpfs_icicle/Kconfig"
>  source "board/sifive/fu540/Kconfig"
> +source "board/sipeed/maix/Kconfig"
>  
>  # platform-specific options below
>  source "arch/riscv/cpu/ax25/Kconfig"
> diff --git a/board/sipeed/maix/Kconfig b/board/sipeed/maix/Kconfig
> new file mode 100644
> index 00..9259eb34aa
> --- /dev/null
> +++ b/board/sipeed/maix/Kconfig
> @@ -0,0 +1,41 @@
> +# SPDX-License-Identifier: GPL-2.0+
> +# Copyright (C) 2019 Sean Anderson 
> +
> +if TARGET_SIPEED_MAIX
> +
> +config SYS_BOARD
> + default "maix"
> +
> +config SYS_VENDOR
> + default "sipeed"
> +
> +config SYS_CPU
> + default "generic"
> +
> +config SYS_CONFIG_NAME
> + default "sipeed-maix"
> +
> +config SYS_TEXT_BASE
> + default 0x8000
> +
> +config NR_CPUS
> + default 2
> +
> +config NR_DRAM_BANKS
> + default 2
> +
> +config BOARD_SPECIFIC_OPTIONS
> + def_bool y
> + select GENERIC_RISCV
> + select DM_SERIAL
> + select SIFIVE_SERIAL
> + select ARCH_DEFAULT_RV64I
> + select ENV_IS_NOWHERE

ENV_IS_NOWHERE is automatically selected if no other environment
provider is available, so no need to include it here.
Also, why are you not using the SD card to store the environment?

> + select SYS_RISCV_NOCOUNTER
> + imply SIFIVE_CLINT
> + imply SPI
> + imply DM_GPIO
> + imply CMD_GPIO
> + imply SYS_NS16550
> + imply SYS_MALLOC_F
> +endif
> diff --git a/board/sipeed/maix/MAINTAINERS b/board/sipeed/maix/MAINTAINERS
> new file mode 100644
> index 00..217de45970
> --- /dev/null
> +++ b/board/sipeed/maix/MAINTAINERS
> @@ -0,0 +1,13 @@
> +Sipeed Maix BOARD
> +M:   Sean Anderson 
> +S:   Maintained
> +F:   arch/riscv/dts/k210.dtsi
> +F:   arch/riscv/dts/k210-maix-bit.dts
> +F:   arch/riscv/include/asm/k210_sysctl.h
> +F:   arch/riscv/lib/k210_sysctl.c
> +F:   board/sipeed/maix/
> +F:   configs/sipeed_maix_defconfig
> +F:   drivers/clk/kendryte/
> +F:   include/configs/sipeed-maix.h
> +F:   

[PATCH v2 07/11] riscv: Add initial Sipeed Maix support

2020-01-15 Thread Sean Anderson
The Sipeed Maix series is a collection of boards built around the RISC-V
Kendryte K210 processor. This processor contains several peripherals to
accelerate neural network processing and other "ai" tasks. This includes a "KPU"
neural network processor, an audio processor supporting beamforming reception,
and a digital video port supporting capture and output at VGA resolution. Other
peripherals include 8M of sram (accessible with and without caching);
remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA
controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but
include spi flash; on-board usb-serial bridges; ports for cameras, displays, and
sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is
supported, but the boards are fairly similar.

Documentation for Maix boards is located at .
Documentation for the Kendryte K210 is located at
. However, hardware details are rather lacking,
so most technical reference has been taken from the standalone sdk located at
.

Signed-off-by: Sean Anderson 
---
Changes for v2:
  Select CONFIG_SYS_RISCV_NOCOUNTER.
  Imply CONFIG_CLK_K210.
  Remove spurious references to CONFIG_ARCH_K210.
  Remove many configs from defconfig where the defaults were fine.
  Add a few "not set" lines to suppress unneeded defaults.
  Reduce pre-reloc malloc space, now that clocks initialization happens
  later.
  
 arch/riscv/Kconfig |  4 ++
 board/sipeed/maix/Kconfig  | 41 +
 board/sipeed/maix/MAINTAINERS  | 13 +
 board/sipeed/maix/Makefile |  5 ++
 board/sipeed/maix/maix.c   |  9 +++
 configs/sipeed_maix_bitm_defconfig | 93 ++
 include/configs/sipeed-maix.h  | 19 ++
 7 files changed, 184 insertions(+)
 create mode 100644 board/sipeed/maix/Kconfig
 create mode 100644 board/sipeed/maix/MAINTAINERS
 create mode 100644 board/sipeed/maix/Makefile
 create mode 100644 board/sipeed/maix/maix.c
 create mode 100644 configs/sipeed_maix_bitm_defconfig
 create mode 100644 include/configs/sipeed-maix.h

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 4f8c62dcff..4c62b8dd77 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -20,6 +20,9 @@ config TARGET_QEMU_VIRT
 config TARGET_SIFIVE_FU540
bool "Support SiFive FU540 Board"
 
+config TARGET_SIPEED_MAIX
+   bool "Support Sipeed Maix Board"
+
 endchoice
 
 config SYS_ICACHE_OFF
@@ -53,6 +56,7 @@ source "board/AndesTech/ax25-ae350/Kconfig"
 source "board/emulation/qemu-riscv/Kconfig"
 source "board/microchip/mpfs_icicle/Kconfig"
 source "board/sifive/fu540/Kconfig"
+source "board/sipeed/maix/Kconfig"
 
 # platform-specific options below
 source "arch/riscv/cpu/ax25/Kconfig"
diff --git a/board/sipeed/maix/Kconfig b/board/sipeed/maix/Kconfig
new file mode 100644
index 00..9259eb34aa
--- /dev/null
+++ b/board/sipeed/maix/Kconfig
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2019 Sean Anderson 
+
+if TARGET_SIPEED_MAIX
+
+config SYS_BOARD
+   default "maix"
+
+config SYS_VENDOR
+   default "sipeed"
+
+config SYS_CPU
+   default "generic"
+
+config SYS_CONFIG_NAME
+   default "sipeed-maix"
+
+config SYS_TEXT_BASE
+   default 0x8000
+
+config NR_CPUS
+   default 2
+
+config NR_DRAM_BANKS
+   default 2
+
+config BOARD_SPECIFIC_OPTIONS
+   def_bool y
+   select GENERIC_RISCV
+   select DM_SERIAL
+   select SIFIVE_SERIAL
+   select ARCH_DEFAULT_RV64I
+   select ENV_IS_NOWHERE
+   select SYS_RISCV_NOCOUNTER
+   imply SIFIVE_CLINT
+   imply SPI
+   imply DM_GPIO
+   imply CMD_GPIO
+   imply SYS_NS16550
+   imply SYS_MALLOC_F
+endif
diff --git a/board/sipeed/maix/MAINTAINERS b/board/sipeed/maix/MAINTAINERS
new file mode 100644
index 00..217de45970
--- /dev/null
+++ b/board/sipeed/maix/MAINTAINERS
@@ -0,0 +1,13 @@
+Sipeed Maix BOARD
+M: Sean Anderson 
+S: Maintained
+F: arch/riscv/dts/k210.dtsi
+F: arch/riscv/dts/k210-maix-bit.dts
+F: arch/riscv/include/asm/k210_sysctl.h
+F: arch/riscv/lib/k210_sysctl.c
+F: board/sipeed/maix/
+F: configs/sipeed_maix_defconfig
+F: drivers/clk/kendryte/
+F: include/configs/sipeed-maix.h
+F: include/dt-bindings/clock/k210-sysctl.h
+F: include/dt-bindings/reset/k210-sysctl.h
diff --git a/board/sipeed/maix/Makefile b/board/sipeed/maix/Makefile
new file mode 100644
index 00..4acff5b31e
--- /dev/null
+++ b/board/sipeed/maix/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2019 Western Digital Corporation or its affiliates.
+
+obj-y += maix.o
diff --git a/board/sipeed/maix/maix.c b/board/sipeed/maix/maix.c
new file mode 100644
index 00..f8e773acf7
--- /dev/null
+++ b/board/sipeed/maix/maix.c
@@ -0,0 +1,9 @@
+//