mbox series

[v3,00/16] Add board support for Spacemit K1 SoC in SPL

Message ID 20260325223232.1553212-1-raymondmaoca@gmail.com
Headers show
Series Add board support for Spacemit K1 SoC in SPL | expand

Message

Raymond Mao March 25, 2026, 10:32 p.m. UTC
From: Raymond Mao <raymond.mao@riscstar.com>

This series adds SPL support for the SpacemiT K1 SoC, enabling boot
on K1-based boards such as the BananaPi F3.

To verify, please refer to the doc patch "doc: spacemit: add K1 SPL build
and test guide" [1], which is still valid and suggest to be included to
riscv/next.

[1] https://lore.kernel.org/u-boot/20260311073741.80616-1-guodong@riscstar.com/

Changes in v3:
- Merge CONFIG_ARCH_K1 and CONFIG_TARGET_BANANAPI_F3 into
  CONFIG_TARGET_SPACEMIT_K1. This configuration should be used for all
  boards with Spacemit K1 SoC.
- Remove CONFIG_SPL_RESET_SPACEMIT_K1, CONFIG_SPL_CLK_SPACEMIT_K1,
  CONFIG_SPL_PMIC_SPACEMIT_P1, CONFIG_SPL_DM_REGULATOR_SPACEMIT_P1.
  Since they're redundant for SPL stage.
- Fix the calculation on clock ID. While the clock driver is
  initialized in uboot stage, it'll be run twice. Without the
  protection, it'll cause panic in the second time.

Change in v2:
  - Use read_poll_timeout() in k1 i2c driver.
  - Abandon to parse offset and size from Kconfig & Makefile for binman.
  - Abandon to attach firmware image into the patch set.
  - Update the related document and some minor changes.

Junhui Liu (1):
  clk: spacemit: Add support for K1 SoC

Raymond Mao (15):
  spacemit: k1: support multi-board infrastructure
  spacemit: k1: enable SPL with debug UART
  configs: k1: enable early timer support
  reset: k1: remove TWSI8 reset restriction
  dt-bindings: clock: import k1-syscon from upstream
  dts: k1: import dts file from upstream folder
  dts: k1: enable clocks in SPL
  board: k1: initialize clock and serial devices in SPL
  configs: k1: add default option for clock driver in SPL
  i2c: k1: add I2C driver support
  spacemit: k1: add TLV EEPROM support in SPL
  spacemit: k1: Add DDR firmware support to SPL
  power: pmic: add support for Spacemit P1 PMIC
  power: regulator: add support for Spacemit P1 SoC
  board: k1: enable pmic in spl

 arch/riscv/Kconfig                            |    8 +-
 arch/riscv/cpu/k1/Kconfig                     |    6 +
 arch/riscv/dts/Makefile                       |    2 +-
 arch/riscv/dts/k1-spl.dts                     |  228 +++
 arch/riscv/dts/k1.dtsi                        |  666 +++++-
 board/spacemit/bananapi-f3/MAINTAINERS        |    6 -
 board/spacemit/bananapi-f3/Makefile           |    5 -
 board/spacemit/{bananapi-f3 => k1}/Kconfig    |    6 +-
 board/spacemit/k1/MAINTAINERS                 |   11 +
 board/spacemit/k1/Makefile                    |   27 +
 board/spacemit/{bananapi-f3 => k1}/board.c    |    0
 board/spacemit/k1/spl.c                       |  347 ++++
 board/spacemit/k1/tlv_codes.h                 |   22 +
 configs/bananapi-f3_defconfig                 |   24 -
 configs/spacemit_k1_defconfig                 |   76 +
 doc/board/spacemit/bananapi-f3.rst            |    2 +-
 drivers/clk/Kconfig                           |    5 +-
 drivers/clk/Makefile                          |    1 +
 drivers/clk/spacemit/Kconfig                  |   22 +
 drivers/clk/spacemit/Makefile                 |    7 +
 drivers/clk/spacemit/clk-k1.c                 | 1798 +++++++++++++++++
 drivers/clk/spacemit/clk_common.h             |   79 +
 drivers/clk/spacemit/clk_ddn.c                |   93 +
 drivers/clk/spacemit/clk_ddn.h                |   53 +
 drivers/clk/spacemit/clk_mix.c                |  403 ++++
 drivers/clk/spacemit/clk_mix.h                |  224 ++
 drivers/clk/spacemit/clk_pll.c                |  157 ++
 drivers/clk/spacemit/clk_pll.h                |   81 +
 drivers/i2c/Kconfig                           |    7 +
 drivers/i2c/Makefile                          |    1 +
 drivers/i2c/k1_i2c.c                          |  516 +++++
 drivers/i2c/k1_i2c.h                          |   69 +
 drivers/power/pmic/Kconfig                    |    8 +
 drivers/power/pmic/Makefile                   |    1 +
 drivers/power/pmic/pmic_spacemit_p1.c         |   94 +
 drivers/power/regulator/Kconfig               |    8 +
 drivers/power/regulator/Makefile              |    1 +
 .../power/regulator/spacemit_p1_regulator.c   |  460 +++++
 drivers/reset/reset-spacemit-k1.c             |    4 -
 include/configs/bananapi-f3.h                 |   13 -
 include/configs/k1.h                          |   19 +
 .../dt-bindings/clock/spacemit,k1-syscon.h    |  253 +++
 include/power/spacemit_p1.h                   |  163 ++
 include/soc/spacemit/k1-syscon.h              |  149 ++
 44 files changed, 5960 insertions(+), 165 deletions(-)
 create mode 100644 arch/riscv/dts/k1-spl.dts
 delete mode 100644 board/spacemit/bananapi-f3/MAINTAINERS
 delete mode 100644 board/spacemit/bananapi-f3/Makefile
 rename board/spacemit/{bananapi-f3 => k1}/Kconfig (79%)
 create mode 100644 board/spacemit/k1/MAINTAINERS
 create mode 100644 board/spacemit/k1/Makefile
 rename board/spacemit/{bananapi-f3 => k1}/board.c (100%)
 create mode 100644 board/spacemit/k1/spl.c
 create mode 100644 board/spacemit/k1/tlv_codes.h
 delete mode 100644 configs/bananapi-f3_defconfig
 create mode 100644 configs/spacemit_k1_defconfig
 create mode 100644 drivers/clk/spacemit/Kconfig
 create mode 100644 drivers/clk/spacemit/Makefile
 create mode 100644 drivers/clk/spacemit/clk-k1.c
 create mode 100644 drivers/clk/spacemit/clk_common.h
 create mode 100644 drivers/clk/spacemit/clk_ddn.c
 create mode 100644 drivers/clk/spacemit/clk_ddn.h
 create mode 100644 drivers/clk/spacemit/clk_mix.c
 create mode 100644 drivers/clk/spacemit/clk_mix.h
 create mode 100644 drivers/clk/spacemit/clk_pll.c
 create mode 100644 drivers/clk/spacemit/clk_pll.h
 create mode 100644 drivers/i2c/k1_i2c.c
 create mode 100644 drivers/i2c/k1_i2c.h
 create mode 100644 drivers/power/pmic/pmic_spacemit_p1.c
 create mode 100644 drivers/power/regulator/spacemit_p1_regulator.c
 delete mode 100644 include/configs/bananapi-f3.h
 create mode 100644 include/configs/k1.h
 create mode 100644 include/dt-bindings/clock/spacemit,k1-syscon.h
 create mode 100644 include/power/spacemit_p1.h
 create mode 100644 include/soc/spacemit/k1-syscon.h

Comments

Vincent Legoll March 26, 2026, 6:35 p.m. UTC | #1
Hello,

I wanted to try this series (applied to upstream u-boot, next branch),
but it failed to boot properly.

Note that I tried to follow instructions from:
Subject: [PATCH] doc: spacemit: add K1 SPL build and test guide
https://lore.kernel.org/u-boot/20260311073741.80616-1-guodong@riscstar.com/

But they looked wrong at times so I tried to guess what was intended.

Can someone see why it failed like that ?

Find the detailed description of what I did below:

## Get the repos

git clone https://github.com/u-boot/u-boot
git clone https://github.com/spacemit-com/spacemit-firmware
git clone https://gitee.com/bianbu-linux/uboot-2022.10 bianbu-uboot-2022.10

## Build u-boot

BUILD_PATH=$(pwd)
UBOOT_UPSTREAM_DIR="${BUILD_PATH}/u-boot"
UBOOT_BIANBU_DIR="${BUILD_PATH}/bianbu-uboot-2022.10"
SPACEMIT_FW_DIR="${BUILD_PATH}/spacemit-firmware"

cd "${UBOOT_UPSTREAM_DIR}"

git checkout -b spacemit-k1 upstream/next

# Grab the series link from:
# 
https://patchwork.ozlabs.org/project/uboot/patch/20260325223232.1553212-2-raymondmaoca@gmail.com/

curl https://patchwork.ozlabs.org/series/497518/mbox/ > 
Add-board-support-for-Spacemit-K1-SoC-in-SPL.patch
git am < Add-board-support-for-Spacemit-K1-SoC-in-SPL.patch

export CROSS_COMPILE=riscv64-linux-musl-
export ARCH=riscv
export DDR_FW_FILE="${SPACEMIT_FW_DIR}/k1/v0.2/ddr_fw.bin"

make spacemit_k1_defconfig
make -j $(nproc)

# Here the path to fsbl.json was not right
# See: 
https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/board/spacemit/k1-x/configs/fsbl.json

mkdir -p "${UBOOT_BIANBU_DIR}/spl_bin/configs"
sed 's/u-boot-spl\.bin/u-boot-spl-ddr.bin/g' \
   < "${UBOOT_BIANBU_DIR}/board/spacemit/k1-x/configs/fsbl.json" \
   > "${UBOOT_BIANBU_DIR}/spl_bin/configs/fsbl_ddr.json"

echo "Clean binaries in ${UBOOT_BIANBU_DIR}/spl_bin"
rm -f "${UBOOT_BIANBU_DIR}/spl_bin/u-boot-spl-ddr.bin"
rm -f "${UBOOT_BIANBU_DIR}/spl_bin/u-boot-spl.bin"

cp "${UBOOT_UPSTREAM_DIR}/u-boot-spl-ddr.bin" "${UBOOT_BIANBU_DIR}/spl_bin"

python3 "${UBOOT_BIANBU_DIR}/tools/build_binary_file.py" \
   -c "${UBOOT_BIANBU_DIR}/spl_bin/configs/fsbl_ddr.json" \
   -o "${UBOOT_BIANBU_DIR}/spl_bin/FSBL.bin"

# This created a FSBL.bin in the specified directory.

## Setup serial console, boot with FDL button pressed, then USB upload:

FSBL="${UBOOT_BIANBU_DIR}/spl_bin/FSBL.bin"

fastboot stage "${FSBL}"
fastboot continue

## Serial console output

sys: 0x1000
bm:2
ROM: usb download handler
usb2d_initialize : enter
Controller Run
usb rst int
SETUP: 0x80 0x6 0x100
usb rst int
SETUP: 0x0 0x5 0x1
SETUP: 0x80 0x6 0x100
SETUP: 0x80 0x6 0x200
SETUP: 0x80 0x6 0x200
SETUP: 0x80 0x6 0x300
SETUP: 0x80 0x6 0x302
SETUP: 0x80 0x6 0x301
SETUP: 0x80 0x6 0x30a
SETUP: 0x0 0x9 0x1
usb_rx_bytes : len= 4096 pBuf= 0xc0838720
SETUP: 0x80 0x6 0x302
SETUP: 0x80 0x6 0x304
fastboot_handle_command: max-download-size
usb_tx_bytes : len= 65 pBuf= 0xc083fe88
usb_rx_bytes : len= 4096 pBuf= 0xc0838720
fastboot_handle_command: 0001e860
Starting download of 125024 bytes
usb_tx_bytes : len= 65 pBuf= 0xc083fe88
usb_rx_bytes : len= 125024 pBuf= 0xc0800000
usb_tx_bytes : len= 65 pBuf= 0xc083fe88
usb_rx_bytes : len= 4096 pBuf= 0xc0838720
fastboot_handle_command: continue
usb_tx_bytes : len= 65 pBuf= 0xc083fe88
j...

<debug_uart>

U-Boot SPL 2026.04-rc4-00543-g2ba03a569e61 (Mar 26 2026 - 16:48:44 +0100)
Fail to detect board:-2
vdd_core, value:900000
vdd_1v8, value:1800000
vdd_1v8_mmc, value:500000
DDR firmware: [0xc08159c0]:0xf0227179, size:0x8d98
DDR is ready
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

## More details

[bianbu-uboot-2022.10]$ git log --oneline -1
d61c8c77 (HEAD -> k1-bl-v2.2.y, tag: k1-bl-v2.2.9-release, 
origin/k1-bl-v2.2.y, origin/HEAD) Update for v2.2.9

[spacemit-firmware]$ git log --oneline -1
3eca456 (HEAD -> master, origin/master, origin/HEAD) Merge pull request 
#1 from docularxu/add-readme

$ ls -la $DDR_FW_FILE
-rw-r--r-- 1 user user 36248 Mar 26 16:38 
.../spacemit-firmware/k1/v0.2/ddr_fw.bin
$ sha256sum $DDR_FW_FILE
4ca729dae39580fe6d52ff6a1ead95fd18cd6394c942cc4a323882ccf2840148 
.../spacemit-firmware/k1/v0.2/ddr_fw.bin

[u-boot]$ git remote -v | grep upstream
upstream        https://source.denx.de/u-boot/u-boot.git (fetch)
upstream        https://source.denx.de/u-boot/u-boot.git (push)

$ git log --oneline upstream/next^..HEAD
2ba03a569e6 (HEAD -> spacemit-k1) board: k1: enable pmic in spl
d4b07728ec7 power: regulator: add support for Spacemit P1 SoC
698e1dac98b power: pmic: add support for Spacemit P1 PMIC
76b9c476576 spacemit: k1: Add DDR firmware support to SPL
d8bc52c01f2 spacemit: k1: add TLV EEPROM support in SPL
06ac4c0cc55 i2c: k1: add I2C driver support
29c9f971bbe configs: k1: add default option for clock driver in SPL
66fd60bea6e board: k1: initialize clock and serial devices in SPL
1c69ee27980 dts: k1: enable clocks in SPL
fdad5fdcc0d clk: spacemit: Add support for K1 SoC
0e4f554b274 dts: k1: import dts file from upstream folder
a8cd1f828c4 dt-bindings: clock: import k1-syscon from upstream
0dd6c089190 reset: k1: remove TWSI8 reset restriction
a46bdb334d7 configs: k1: enable early timer support
052c15d331a spacemit: k1: enable SPL with debug UART
25905d01c7e spacemit: k1: support multi-board infrastructure
8813d74163e (upstream/next, upstream/WIP/25Mar2026-next, origin/next, 
origin/WIP/25Mar2026-next) Merge patch series "test/py: gpio: cleanups 
and improvement"
0f101dac8fb test/py: gpio: allow omitting gpio_op_pin
908db6c647c test/py: gpio: removing trailing semicolons
b02b0a0c6cb test/py: gpio: remove unused imports

Thanks

PS: I just (re-)subscribed to the list. I tried to get the email 
threading right, hopefully it'll work.
Vincent Legoll March 26, 2026, 7:10 p.m. UTC | #2
And I forgot to add a small piece of info...

The board is Bananapi-F3 (8GB), with something that looks like a "v10" 
printed, but a bit blurry.
Guodong Xu March 27, 2026, 3:10 a.m. UTC | #3
Hi, Vincent

On Fri, Mar 27, 2026 at 2:36 AM Vincent Legoll <legoll@online.fr> wrote:
>
> Hello,
>
> I wanted to try this series (applied to upstream u-boot, next branch),
> but it failed to boot properly.
>

Thanks for testing the v3 K1 SPL patchset.
Actually your result confirms the SPL patchset is working correctly and the
build/test procedure is generally complete.

PS: I added some walk through to the key lines in your log below (for you
and for the community's future reference purpose), but for here please be
noted that as I said in the doc patch [1]:

"After DDR init succeeds, SPL proceeds to load U-Boot proper. If
 U-Boot proper is not yet available (as in SPL-only testing), you
 will see SPL: failed to boot from all boot devices - this is
 expected and confirms that SPL with DDR init is working correctly."

[1] https://lore.kernel.org/u-boot/20260311073741.80616-1-guodong@riscstar.com/

> Note that I tried to follow instructions from:
> Subject: [PATCH] doc: spacemit: add K1 SPL build and test guide
> https://lore.kernel.org/u-boot/20260311073741.80616-1-guodong@riscstar.com/
>
...
>
> # Here the path to fsbl.json was not right
> # See:
> https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/board/spacemit/k1-x/configs/fsbl.json

Thanks for bringing this up.

Regarding the fsbl.json path: allow me to explain the upstream gitee
repository URL has been redirected from
  https://gitee.com/bianbu-linux/uboot-2022.10
to
  https://gitee.com/spacemit-buildroot/uboot-2022.10

Somehow it causes the fsbl.json path in my doc [1] didn't match.
I will update the repository URL and fix the fsbl.json path in v2 of
the doc patch.

>
> U-Boot SPL 2026.04-rc4-00543-g2ba03a569e61 (Mar 26 2026 - 16:48:44 +0100)
> Fail to detect board:-2
> vdd_core, value:900000
> vdd_1v8, value:1800000
> vdd_1v8_mmc, value:500000
> DDR firmware: [0xc08159c0]:0xf0227179, size:0x8d98
> DDR is ready
> SPL: Unsupported Boot Device!
> SPL: failed to boot from all boot devices
> ### ERROR ### Please RESET the board ###

To walk through the key lines:
 "DDR firmware: [...], size:0x8d98" - DDR firmware loaded successfully
 "DDR is ready" - DDR initialization completed
 "SPL: failed to boot from all boot devices" - expected, since no
    storage driver (SPI NOR, MMC, etc.) is included in this patchset
    to load U-Boot proper

Back to the patch series itself, your log is a good validation of
the v3 SPL patchset.

Thank you again for taking the time.

BR,
Guodong

>
> Thanks
>
> PS: I just (re-)subscribed to the list. I tried to get the email
> threading right, hopefully it'll work.
Vincent Legoll March 27, 2026, 5:24 p.m. UTC | #4
Hi Guodong Xu,

On 3/27/26 04:10, Guodong Xu wrote:
> Thanks for testing the v3 K1 SPL patchset.
> Actually your result confirms the SPL patchset is working correctly and the
> build/test procedure is generally complete.

OK, thanks for confirming.

> PS: I added some walk through to the key lines in your log below (for you
> and for the community's future reference purpose), but for here please be
> noted that as I said in the doc patch [1]:
>
> "After DDR init succeeds, SPL proceeds to load U-Boot proper. If
>   U-Boot proper is not yet available (as in SPL-only testing), you
>   will see SPL: failed to boot from all boot devices - this is
>   expected and confirms that SPL with DDR init is working correctly."
>
> [1] https://lore.kernel.org/u-boot/20260311073741.80616-1-guodong@riscstar.com/

Yes, I missed that part of your doc, so as Heinrich says in

his comment to the v2, you should move that higher or make

it more obvious to see.


I was expecting to see some of what you had in v1 of the

doc patch, in "Expected Output".


Is there some debug macro to enable that output ?

> Back to the patch series itself, your log is a good validation of
> the v3 SPL patchset.

OK, in this case you can add my:

Tested-by: Vincent Legoll<legoll@online.fr> # BPI-F3 (8GB)

for the next iteration, or directly to this v3 if there

is no further one.
Vincent Legoll April 15, 2026, 7:04 a.m. UTC | #5
Hello,


Is there something we can do to help this series move forward ?


What are the next steps ?

How can we get a fully booting board after this is enabled ?


Thanks for all the work !


Best regards
Raymond Mao April 15, 2026, 2:32 p.m. UTC | #6
Hi Vincent,

On Wed, Apr 15, 2026 at 3:04 AM Vincent Legoll <legoll@online.fr> wrote:
>
> Hello,
>
>
> Is there something we can do to help this series move forward ?
>
>
> What are the next steps ?
>
> How can we get a fully booting board after this is enabled ?
>

There are two upcoming pinmux and SPI patches that can support U-boot
proper, and eMMC support is on the way.
If you're using banana-pi, it may not boot fully since SPI NOR is
missing on the board.

Raymond

>
> Thanks for all the work !
>
>
> Best regards
>
Raymond Mao April 28, 2026, 2:12 p.m. UTC | #7
Hi Tom, Leo,

Do you have a chance to pull or merge this series?

Thanks a lot!
Raymond

On Wed, Apr 15, 2026 at 10:32 AM Raymond Mao <raymondmaoca@gmail.com> wrote:
>
> Hi Vincent,
>
> On Wed, Apr 15, 2026 at 3:04 AM Vincent Legoll <legoll@online.fr> wrote:
> >
> > Hello,
> >
> >
> > Is there something we can do to help this series move forward ?
> >
> >
> > What are the next steps ?
> >
> > How can we get a fully booting board after this is enabled ?
> >
>
> There are two upcoming pinmux and SPI patches that can support U-boot
> proper, and eMMC support is on the way.
> If you're using banana-pi, it may not boot fully since SPI NOR is
> missing on the board.
>
> Raymond
>
> >
> > Thanks for all the work !
> >
> >
> > Best regards
> >