u-boot/common/spl/spl_ufs.c
Alexey Charkov c664b4d5f3 spl: Make UFS available for SPL builds
Add minimal infrastructure to build SPL images with support for UFS
storage devices. This also pulls in SCSI support and charset functions,
which are dependencies of the UFS code.

With this, only a fixed offset is supported for loading the next image,
which should be specified in CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR as the
number of 4096-byte sectors into the UFS block device.

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Alexey Charkov <alchark@gmail.com>
Link: https://patch.msgid.link/20260120-rk3576-ufs-v5-1-0edb61b301b7@gmail.com
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
2026-03-12 09:30:44 +01:00

50 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2025 Alexey Charkov <alchark@gmail.com>
*/
#include <spl.h>
#include <spl_load.h>
#include <scsi.h>
#include <errno.h>
#include <image.h>
#include <linux/compiler.h>
#include <log.h>
static ulong spl_ufs_load_read(struct spl_load_info *load, ulong off, ulong size, void *buf)
{
struct blk_desc *bd = load->priv;
lbaint_t sector = off >> bd->log2blksz;
lbaint_t count = size >> bd->log2blksz;
return blk_dread(bd, sector, count, buf) << bd->log2blksz;
}
static int spl_ufs_load_image(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
{
unsigned long sector = CONFIG_SPL_UFS_RAW_U_BOOT_SECTOR;
int devnum = CONFIG_SPL_UFS_RAW_U_BOOT_DEVNUM;
struct spl_load_info load;
struct blk_desc *bd;
int err;
/* try to recognize storage devices immediately */
scsi_scan(false);
bd = blk_get_devnum_by_uclass_id(UCLASS_SCSI, devnum);
if (!bd)
return -ENODEV;
spl_load_init(&load, spl_ufs_load_read, bd, bd->blksz);
err = spl_load(spl_image, bootdev, &load, 0, sector << bd->log2blksz);
if (err) {
puts("spl_ufs_load_image: ufs block read error\n");
log_debug("(error=%d)\n", err);
return err;
}
return 0;
}
SPL_LOAD_IMAGE_METHOD("UFS", 0, BOOT_DEVICE_UFS, spl_ufs_load_image);