[PATCH v3 2/4] scsi: Implement get_blk() function

Casey Connolly casey.connolly at linaro.org
Wed May 7 13:57:11 CEST 2025



On 5/7/25 13:28, Varadarajan Narayanan wrote:
> Add a function to obtain the block device for SCSI.
> 
> Signed-off-by: Varadarajan Narayanan <quic_varada at quicinc.com>
> ---
> v3: * s/scsi_get_blk/scsi_get_blk_by_uuid
>      * s/partition_name/uuid
> ---
>   drivers/scsi/scsi-uclass.c | 30 ++++++++++++++++++++++++++++++
>   include/scsi.h             | 10 ++++++++++
>   2 files changed, 40 insertions(+)
> 
> diff --git a/drivers/scsi/scsi-uclass.c b/drivers/scsi/scsi-uclass.c
> index 1ee8236c05c..3eb6069649f 100644
> --- a/drivers/scsi/scsi-uclass.c
> +++ b/drivers/scsi/scsi-uclass.c
> @@ -10,7 +10,9 @@
>   
>   #define LOG_CATEGORY UCLASS_SCSI
>   
> +#include <blk.h>
>   #include <dm.h>
> +#include <part.h>
>   #include <scsi.h>
>   
>   int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
> @@ -23,6 +25,34 @@ int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
>   	return ops->exec(dev, pccb);
>   }
>   
> +int scsi_get_blk_by_uuid(const char *uuid,
> +			 struct blk_desc **blk_desc_ptr,
> +			 struct disk_partition *part_info_ptr)
> +{
> +	static int is_scsi_scanned;
> +	struct blk_desc *blk;
> +	int i, ret;
> +
> +	if (!is_scsi_scanned) {
> +		scsi_scan(false /* no verbose */);
> +		is_scsi_scanned = 1;

At this point I think we should just unconditionally scsi_scan() like we 
do with MMC... Tom (others?) any thoughts on this? Anyhow this is 
probably fine.

One thing to be extremely wary of is that we don't call scsi_scan() 
after initialising EFI driver handles because that will cause big issues 
(ran into this one before), since scsi_scan() will unbind and rebind 
drivers if it was already called. I don't think that's a problem with 
the current ordering of things.

> +	}
> +
> +	for (i = 0; i < blk_find_max_devnum(UCLASS_SCSI) + 1; i++) {
> +		ret = blk_get_desc(UCLASS_SCSI, i, &blk);
> +		if (ret)
> +			continue;

As before, please check for the end of the list and break here (-ENODEV 
is the magic value). Really it's bad practise to ignore ret, we should 
only ever continue if ret is -ENOENT, otherwise we should return the 
errorcode (and probably translate a -ENODEV to -ENOENT since that makes 
more sense here)

Kind regards,

> +
> +		ret = part_get_info_by_uuid(blk, uuid, part_info_ptr);
> +		if (ret > 0) {
> +			*blk_desc_ptr = blk;
> +			return 0;
> +		}
> +	}
> +
> +	return -1;

	return -ENOENT;

Kind regards,> +}
> +
>   int scsi_bus_reset(struct udevice *dev)
>   {
>   	struct scsi_ops *ops = scsi_get_ops(dev);
> diff --git a/include/scsi.h b/include/scsi.h
> index ab53b47b58f..8d6c5116419 100644
> --- a/include/scsi.h
> +++ b/include/scsi.h
> @@ -351,6 +351,16 @@ int scsi_scan(bool verbose);
>    */
>   int scsi_scan_dev(struct udevice *dev, bool verbose);
>   
> +/**
> + * scsi_get_blk_by_uuid() - Provides SCSI partition information.
> + *
> + * @uuid:		UUID of the partition for fetching its info
> + * @blk_desc_ptr:	Provides the blk descriptor
> + * @part_info_ptr:	Provides partition info
> + */
> +int scsi_get_blk_by_uuid(const char *uuid, struct blk_desc **blk_desc_ptr,
> +			 struct disk_partition *part_info_ptr);
> +
>   #define SCSI_IDENTIFY					0xC0  /* not used */
>   
>   /* Hardware errors  */
-- 
Casey (she/they)



More information about the U-Boot mailing list