[PATCH v5 07/11] spl: Convert NVMe to spl_load

Sean Anderson sean.anderson at seco.com
Thu Aug 3 17:46:30 CEST 2023


On 8/3/23 04:32, Xavier Drudis Ferran wrote:
> El Mon, Jul 31, 2023 at 06:42:59PM -0400, Sean Anderson deia:
>> This converts the blk load method (used exclusively by NVMe) to use
>> spl_load. As a consequence, it also adds support for LOAD_FIT_FULL and
>> IMX images.
>> 
>> Signed-off-by: Sean Anderson <sean.anderson at seco.com>
>> ---
>> 
>> Changes in v5:
>> - New
>> 
>>  common/spl/spl_blk_fs.c | 68 ++++++++---------------------------------
>>  1 file changed, 12 insertions(+), 56 deletions(-)
>> 
>> diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
>> index d97adc4d39..eb5775a470 100644
>> --- a/common/spl/spl_blk_fs.c
>> +++ b/common/spl/spl_blk_fs.c
>> @@ -45,24 +45,28 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
>>  {
>>  	const char *filename = CONFIG_SPL_PAYLOAD;
>>  	struct disk_partition part_info = {};
>> -	struct legacy_img_hdr *header;
>>  	struct blk_desc *blk_desc;
>> -	loff_t actlen, filesize;
>> +	loff_t filesize;
>>  	struct blk_dev dev;
>>  	int ret;
>> +	struct spl_load_info load = {
>> +		.read = spl_fit_read,
>> +		.bl_len = 1,
>> +		.filename = filename,
>> +		.priv = &dev,
>> +	};
>>  
>>  	blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum);
>>  	if (!blk_desc) {
>>  		printf("blk desc for %d %d not found\n", uclass_id, devnum);
>> -		goto out;
>> +		return ret;
> 
> What do you mean return ret ?
> ret is unused yet ?
> maybe return -1 or return -ENODEV or something ?
> 
> I think the error was already there before your patch, but maybe worth
> fixing ?

Yes.

--Sean

>>  	}
>>  
>>  	blk_show_device(uclass_id, devnum);
>> -	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
>>  	ret = part_get_info(blk_desc, 1, &part_info);
>>  	if (ret) {
>>  		printf("spl: no partition table found. Err - %d\n", ret);
>> -		goto out;
>> +		return ret;
>>  	}
>>  
>>  	dev.ifname = blk_get_uclass_name(uclass_id);
>> @@ -72,63 +76,15 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
>>  	if (ret) {
>>  		printf("spl: unable to set blk_dev %s %s. Err - %d\n",
>>  		       dev.ifname, dev.dev_part_str, ret);
>> -		goto out;
>> -	}
>> -
>> -	ret = fs_read(filename, (ulong)header, 0,
>> -		      sizeof(struct legacy_img_hdr), &actlen);
>> -	if (ret) {
>> -		printf("spl: unable to read file %s. Err - %d\n", filename,
>> -		       ret);
>> -		goto out;
>> -	}
>> -
>> -	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
>> -	    image_get_magic(header) == FDT_MAGIC) {
>> -		struct spl_load_info load;
>> -
>> -		debug("Found FIT\n");
>> -		load.read = spl_fit_read;
>> -		load.bl_len = 1;
>> -		load.filename = (void *)filename;
>> -		load.priv = &dev;
>> -
>> -		return spl_load_simple_fit(spl_image, &load, 0, header);
>> -	}
>> -
>> -	ret = spl_parse_image_header(spl_image, bootdev, header);
>> -	if (ret) {
>> -		printf("spl: unable to parse image header. Err - %d\n",
>> -		       ret);
>> -		goto out;
>> -	}
>> -
>> -	ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY);
>> -	if (ret) {
>> -		printf("spl: unable to set blk_dev %s %s. Err - %d\n",
>> -		       dev.ifname, dev.dev_part_str, ret);
>> -		goto out;
>> +		return ret;
>>  	}
>>  
>>  	ret = fs_size(filename, &filesize);
>>  	if (ret) {
>>  		printf("spl: unable to get file size: %s. Err - %d\n",
>>  		       filename, ret);
>> -		goto out;
>> +		return ret;
>>  	}
>>  
>> -	ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY);
>> -	if (ret) {
>> -		printf("spl: unable to set blk_dev %s %s. Err - %d\n",
>> -		       dev.ifname, dev.dev_part_str, ret);
>> -		goto out;
>> -	}
>> -
>> -	ret = fs_read(filename, (ulong)spl_image->load_addr, 0, filesize,
>> -		      &actlen);
>> -	if (ret)
>> -		printf("spl: unable to read file %s. Err - %d\n",
>> -		       filename, ret);
>> -out:
>> -	return ret;
>> +	return spl_load(spl_image, bootdev, &load, filesize, 0);
>>  }
>> -- 
>> 2.40.1
>> 



More information about the U-Boot mailing list