Skip to content

Add support for SOPHGO SoCs and Milk-V boards #69594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,25 @@ Gardena Platforms:
description: >-
Gardena board(s).

SOPHGO Platforms:
status: maintained
maintainers:
- xingrz
collaborators:
- lenghonglin
files:
- boards/common/cvi-fiptool.board.cmake
- boards/milkv/duo/
- boards/milkv/duos/
- dts/riscv/sophgo/
- dts/bindings/*/sophgo,*
- drivers/*/*.sophgo
- drivers/*/*_sophgo_*.c
- scripts/west_commands/runners/cvi-fiptool.py
- soc/sophgo/
labels:
- "platform: SOPHGO"

Intel Platforms (X86):
status: maintained
maintainers:
Expand Down
4 changes: 4 additions & 0 deletions boards/common/cvi-fiptool.board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

board_set_flasher_ifnset(cvi-fiptool)
board_finalize_runner_args(cvi-fiptool)
6 changes: 6 additions & 0 deletions boards/milkv/duo/Kconfig.milkv_duo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2023-2024 Chen Xingyu <hi@xingrz.me>
# SPDX-License-Identifier: Apache-2.0

config BOARD_MILKV_DUO
select SOC_CV1800B if BOARD_MILKV_DUO_CV1800B_C906_1
select SOC_SG2002 if BOARD_MILKV_DUO_SG2002_C906_1
3 changes: 3 additions & 0 deletions boards/milkv/duo/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0

include(${ZEPHYR_BASE}/boards/common/cvi-fiptool.board.cmake)
7 changes: 7 additions & 0 deletions boards/milkv/duo/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
board:
name: milkv_duo
full_name: Duo
vendor: milkv
socs:
- name: cv1800b
- name: sg2002
62 changes: 62 additions & 0 deletions boards/milkv/duo/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. zephyr:board:: milkv_duo

Overview
********

See https://milkv.io/duo

Supported Features
==================

.. zephyr:board-supported-hw::

Programming and Debugging
*************************

Prepare a TF card and follow the instructions in the `official SDK`_ to build
and flash the image.

After that, you will get a ``fip.bin`` file at the root of the TF card, where
the RTOS image is packed.

The following steps demonstrate how to build the blinky sample and update the
``fip.bin`` file on the TF card.

.. zephyr-app-commands::
:zephyr-app: samples/basic/blinky
:board: milkv_duo/cv1800b/c906_1
:goals: build flash
:flash-args: --fiptool /path/to/duo-buildroot-sdk/fsbl/plat/cv180x/fiptool.py --fip-bin /path/to/tfcard/fip.bin

Eject the TF card and insert it into the board. Power on the board and you will
see the LED blinking.

.. note::

Notes for the official buildroot SDK

1. The Linux running on the big core uses UART0 (GP12/GP13) for the console,
while to avoid conflict, the Zephyr application (in the default board
configuration) uses UART1 (GP0/GP1).
2. Pin multiplexing can be handled either by U-Boot or Zephyr. To utilize
Zephyr's pin multiplexing, enable :kconfig:option:`CONFIG_PINCTRL` and
recompile U-Boot without the PINMUX configs. The source code for the
PINMUX configs varies by SoC:

* For Duo (CV1800B), see `PINMUX configs (Duo)`_
* For Duo 256M (SG2002), see `PINMUX configs (Duo 256M)`_

Note that U-Boot boots several seconds after Zephyr.
3. By default, the Linux running on the big core will blink the LED on the
board. To demonstrate Zephyr (specifically, the ``samples/basic/blinky``
sample), you should remove the script from the Linux filesystem located at
``/mnt/system/blink.sh``.

.. _official SDK:
https://github.com/milkv-duo/duo-buildroot-sdk

.. _PINMUX configs (Duo):
https://github.com/milkv-duo/duo-buildroot-sdk/blob/develop/build/boards/cv180x/cv1800b_milkv_duo_sd/u-boot/cvi_board_init.c

.. _PINMUX configs (Duo 256M):
https://github.com/milkv-duo/duo-buildroot-sdk/blob/develop/build/boards/cv181x/cv1812cp_milkv_duo256m_sd/u-boot/cvi_board_init.c
13 changes: 13 additions & 0 deletions boards/milkv/duo/milkv_duo-pinctrl.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2023-2024 Chen Xingyu <hi@xingrz.me>
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_default: uart1_default {
group1 {
pinmux = <CVI_PINMUX(IIC0_SCL, UART1_TX)>, /* GP0 */
<CVI_PINMUX(IIC0_SDA, UART1_RX)>; /* GP1 */
};
};
};
60 changes: 60 additions & 0 deletions boards/milkv/duo/milkv_duo_cv1800b_c906_1.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023-2024 Chen Xingyu <hi@xingrz.me>
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;

#include <sophgo/cv180x.dtsi>
#include <zephyr/dt-bindings/gpio/gpio.h>

#include "milkv_duo-pinctrl.dtsi"

/ {
model = "Milk-V Duo coprocessor";
compatible = "milkv,duo";

chosen {
zephyr,sram = &sram;
zephyr,console = &uart1;
zephyr,shell-uart = &uart1;
};

aliases {
led0 = &led;
};

leds {
compatible = "gpio-leds";

led: led {
gpios = <&gpioc 24 GPIO_ACTIVE_HIGH>;
};
};

soc {
/*
* Memory region reserved for the RTOS core.
*
* Keep in sync with FREERTOS_ADDR and FREERTOS_SIZE in
* build/boards/cv180x/cv1800b_milkv_duo_sd/memmap.py
*
* see: https://github.com/milkv-duo/duo-buildroot-sdk
*/
sram: memory@83f40000 {
compatible = "mmio-sram";
reg = <0x83f40000 DT_SIZE_K(768)>;
};
};
};

&gpioc {
status = "okay";
};

&uart1 {
status = "okay";
pinctrl-0 = <&uart1_default>;
pinctrl-names = "default";
current-speed = <115200>;
};
15 changes: 15 additions & 0 deletions boards/milkv/duo/milkv_duo_cv1800b_c906_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
identifier: milkv_duo/cv1800b/c906_1
name: Milk-V Duo coprocessor
type: mcu
arch: riscv
toolchain:
- zephyr
ram: 768
supported:
- clock
- gpio
- interrupt-controller
- mailbox
- pinctrl
- pwm
- serial
10 changes: 10 additions & 0 deletions boards/milkv/duo/milkv_duo_cv1800b_c906_1_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2023-2024 Chen Xingyu <hi@xingrz.me>
# SPDX-License-Identifier: Apache-2.0

CONFIG_XIP=n

CONFIG_GPIO=y
CONFIG_SERIAL=y

CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
60 changes: 60 additions & 0 deletions boards/milkv/duo/milkv_duo_sg2002_c906_1.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 Chen Xingyu <hi@xingrz.me>
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;

#include <sophgo/cv181x.dtsi>
#include <zephyr/dt-bindings/gpio/gpio.h>

#include "milkv_duo-pinctrl.dtsi"

/ {
model = "Milk-V Duo 256M coprosessor";
compatible = "milkv,duo";

chosen {
zephyr,sram = &sram;
zephyr,console = &uart1;
zephyr,shell-uart = &uart1;
};

aliases {
led0 = &led;
};

leds {
compatible = "gpio-leds";

led: led {
gpios = <&pwr_gpio 2 GPIO_ACTIVE_HIGH>;
};
};

soc {
/*
* Memory region reserved for the RTOS core.
*
* Keep in sync with FREERTOS_ADDR and FREERTOS_SIZE in
* build/boards/cv181x/cv1812cp_milkv_duo256m_sd/memmap.py
*
* see: https://github.com/milkv-duo/duo-buildroot-sdk
*/
sram: memory@8fe00000 {
compatible = "mmio-sram";
reg = <0x8fe00000 DT_SIZE_M(2)>;
};
};
};

&pwr_gpio {
status = "okay";
};

&uart1 {
status = "okay";
pinctrl-0 = <&uart1_default>;
pinctrl-names = "default";
current-speed = <115200>;
};
15 changes: 15 additions & 0 deletions boards/milkv/duo/milkv_duo_sg2002_c906_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
identifier: milkv_duo/sg2002/c906_1
name: Milk-V Duo 256M coprocessor
type: mcu
arch: riscv
toolchain:
- zephyr
ram: 2048
supported:
- clock
- gpio
- interrupt-controller
- mailbox
- pinctrl
- pwm
- serial
10 changes: 10 additions & 0 deletions boards/milkv/duo/milkv_duo_sg2002_c906_1_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2024 Chen Xingyu <hi@xingrz.me>
# SPDX-License-Identifier: Apache-2.0

CONFIG_XIP=n

CONFIG_GPIO=y
CONFIG_SERIAL=y

CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
5 changes: 5 additions & 0 deletions boards/milkv/duos/Kconfig.milkv_duos
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2024 Chen Xingyu <hi@xingrz.me>
# SPDX-License-Identifier: Apache-2.0

config BOARD_MILKV_DUOS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need changing to be explicit about the 906_1 core eventually. Not sure if you want to plan ahead and adjust the naming now, or just refactor when we are that support. Raising it here as a note more than anything.

select SOC_SG2000 if BOARD_MILKV_DUOS_SG2000_C906_1
3 changes: 3 additions & 0 deletions boards/milkv/duos/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0

include(${ZEPHYR_BASE}/boards/common/cvi-fiptool.board.cmake)
6 changes: 6 additions & 0 deletions boards/milkv/duos/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
board:
name: milkv_duos
full_name: Duo S
vendor: milkv
socs:
- name: sg2000
50 changes: 50 additions & 0 deletions boards/milkv/duos/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. zephyr:board:: milkv_duos

Overview
********

See https://milkv.io/duo-s

Supported Features
==================

.. zephyr:board-supported-hw::

Programming and Debugging
*************************

Prepare a TF card and follow the instructions in the `official SDK`_ to build
and flash the image.

After that, you will get a ``fip.bin`` file at the root of the TF card, where
the RTOS image is packed.

The following steps demonstrate how to build the blinky sample and update the
``fip.bin`` file on the TF card.

.. zephyr-app-commands::
:zephyr-app: samples/basic/blinky
:board: milkv_duos/sg2000/c906_1
:goals: build flash
:flash-args: --fiptool /path/to/duo-buildroot-sdk/fsbl/plat/cv181x/fiptool.py --fip-bin /path/to/tfcard/fip.bin

Eject the TF card and insert it into the board. Power on the board and you will
see the LED blinking.

.. note::

Notes for the official buildroot SDK

1. The Linux running on the big core uses UART0 (A16/A17) for the console,
while to avoid conflict, the Zephyr application (in the default board
configuration) uses UART2 (A19/A18).
2. Pin multiplexing can be handled either by U-Boot or Zephyr. To utilize
Zephyr's pin multiplexing, enable :kconfig:option:`CONFIG_PINCTRL` and
recompile U-Boot without the `PINMUX configs`_. Note that U-Boot boots
several seconds after Zephyr.

.. _official SDK:
https://github.com/milkv-duo/duo-buildroot-sdk

.. _PINMUX configs:
https://github.com/milkv-duo/duo-buildroot-sdk/blob/develop/build/boards/cv181x/cv1813h_milkv_duos_sd/u-boot/cvi_board_init.c
13 changes: 13 additions & 0 deletions boards/milkv/duos/milkv_duos-pinctrl.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2024 Chen Xingyu <hi@xingrz.me>
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_default: uart1_default {
group1 {
pinmux = <CVI_PINMUX(JTAG_CPU_TMS, UART1_TX)>, /* A19 */
<CVI_PINMUX(JTAG_CPU_TCK, UART1_RX)>; /* A18 */
};
};
};
Loading
Loading