[PATCH 1/8] spacemit: k1: select boot device via config registers

Yao Zi me at ziyao.cc
Sat Jun 13 05:50:52 CEST 2026


On Fri, Jun 12, 2026 at 04:18:54PM -0400, Raymond Mao wrote:
> From: Guodong Xu <guodong at riscstar.com>
> 
> Add logic to determine the current boot device by reading the
> SoC's configuration registers, rather than using a hardcoded
> default.
> 
> Signed-off-by: Guodong Xu <guodong at riscstar.com>
> Signed-off-by: Raymond Mao <raymond.mao at riscstar.com>
> ---
>  board/spacemit/k1/spl.c | 77 ++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 76 insertions(+), 1 deletion(-)
> 
> diff --git a/board/spacemit/k1/spl.c b/board/spacemit/k1/spl.c
> index 0db362130e4..d5e87d79fa2 100644
> --- a/board/spacemit/k1/spl.c
> +++ b/board/spacemit/k1/spl.c

...

> @@ -379,7 +401,60 @@ void board_init_f(ulong dummy)
>  
>  u32 spl_boot_device(void)
>  {
> -	return BOOT_DEVICE_SPI;
> +	void __iomem *boot_dev = (void __iomem *)BOOT_DEV_FLAG_REG;
> +	void __iomem *boot_strap = (void __iomem *)BOOT_PIN_SEL_REG;
> +	u32 mode, sel, ret = 0;
> +
> +	mode = readl(boot_dev);
> +	if (mode == BOOT_MODE_NONE || mode > BOOT_MODE_SD) {
> +		sel = readl(boot_strap);
> +		sel >>= BOOT_STRAP_MODE_OFFSET;
> +		sel &= BOOT_STRAP_MODE_MASK;

Is FIELD_GET() helpful here?

> +		switch (sel) {
> +		case BOOT_STRAP_MODE_EMMC:
> +			mode = BOOT_MODE_EMMC;
> +			break;
> +		case BOOT_STRAP_MODE_NAND:
> +			mode = BOOT_MODE_NAND;
> +			break;
> +		case BOOT_STRAP_MODE_SPI:
> +			mode = BOOT_MODE_SPI;
> +			break;
> +		case BOOT_STRAP_MODE_SD:
> +		default:
> +			mode = BOOT_MODE_SD;
> +			break;
> +		}
> +	}
> +	/* TODO:
> +	 *   The current upstream DTS file only contains the eMMC node. When
> +	 *   the SD node is added via an overlay, the eMMC device ends up as
> +	 *   MMC1 in SPL.

Why not fix this with an extra alias in the overlay dt?

> +	 *   However, the SD device should be the first device (MMC1).
> +	 *   This sequence needs to be corrected once the SD node is merged
> +	 *   into the upstream U-Boot DTS file.
> +	 */
> +	switch (mode) {
> +	case BOOT_MODE_EMMC:
> +		ret = BOOT_DEVICE_MMC1;
> +		break;
> +	case BOOT_MODE_NAND:
> +		ret = BOOT_DEVICE_NAND;
> +		break;
> +	case BOOT_MODE_SPI:
> +		ret = BOOT_DEVICE_SPI;
> +		break;
> +	case BOOT_MODE_USB:
> +		ret = BOOT_DEVICE_USB;
> +		break;
> +	case BOOT_MODE_SD:
> +		ret = BOOT_DEVICE_MMC2;
> +		break;
> +	default:
> +		ret = BOOT_DEVICE_MMC1;
> +		break;
> +	}
> +	return ret;
>  }
>  
>  void spl_board_init(void)
> -- 
> 2.25.1
> 

Regards,
Yao Zi


More information about the U-Boot mailing list