mirror of
				https://github.com/smaeul/u-boot.git
				synced 2025-11-04 05:50:17 +00:00 
			
		
		
		
	As part of bringing the master branch back in to next, we need to allow for all of these changes to exist here. Reported-by: Jonas Karlman <jonas@kwiboo.se> Signed-off-by: Tom Rini <trini@konsulko.com>
		
			
				
	
	
		
			82 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
// SPDX-License-Identifier: GPL-2.0+
 | 
						|
/*
 | 
						|
 * Read a bootflow from SPI flash
 | 
						|
 *
 | 
						|
 * Copyright 2022 Google LLC
 | 
						|
 */
 | 
						|
 | 
						|
#include <bootdev.h>
 | 
						|
#include <bootflow.h>
 | 
						|
#include <bootmeth.h>
 | 
						|
#include <dm.h>
 | 
						|
#include <env.h>
 | 
						|
#include <malloc.h>
 | 
						|
#include <spi_flash.h>
 | 
						|
 | 
						|
static int sf_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
 | 
						|
			   struct bootflow *bflow)
 | 
						|
{
 | 
						|
	struct udevice *sf = dev_get_parent(dev);
 | 
						|
	uint size;
 | 
						|
	char *buf;
 | 
						|
	int ret;
 | 
						|
 | 
						|
	/* We only support the whole device, not partitions */
 | 
						|
	if (iter->part)
 | 
						|
		return log_msg_ret("max", -ESHUTDOWN);
 | 
						|
 | 
						|
	size = env_get_hex("script_size_f", 0);
 | 
						|
	if (!size)
 | 
						|
		return log_msg_ret("sz", -EINVAL);
 | 
						|
 | 
						|
	buf = malloc(size + 1);
 | 
						|
	if (!buf)
 | 
						|
		return log_msg_ret("buf", -ENOMEM);
 | 
						|
 | 
						|
	ret = spi_flash_read_dm(sf, env_get_hex("script_offset_f", 0),
 | 
						|
				size, buf);
 | 
						|
	if (ret)
 | 
						|
		return log_msg_ret("cmd", -EINVAL);
 | 
						|
	bflow->state = BOOTFLOWST_MEDIA;
 | 
						|
 | 
						|
	ret = bootmeth_set_bootflow(bflow->method, bflow, buf, size);
 | 
						|
	if (ret) {
 | 
						|
		free(buf);
 | 
						|
		return log_msg_ret("method", ret);
 | 
						|
	}
 | 
						|
 | 
						|
	return 0;
 | 
						|
}
 | 
						|
 | 
						|
static int sf_bootdev_bind(struct udevice *dev)
 | 
						|
{
 | 
						|
	struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
 | 
						|
 | 
						|
	ucp->prio = BOOTDEVP_4_SCAN_FAST;
 | 
						|
 | 
						|
	return 0;
 | 
						|
}
 | 
						|
 | 
						|
struct bootdev_ops sf_bootdev_ops = {
 | 
						|
	.get_bootflow	= sf_get_bootflow,
 | 
						|
};
 | 
						|
 | 
						|
static const struct udevice_id sf_bootdev_ids[] = {
 | 
						|
	{ .compatible = "u-boot,bootdev-sf" },
 | 
						|
	{ }
 | 
						|
};
 | 
						|
 | 
						|
U_BOOT_DRIVER(sf_bootdev) = {
 | 
						|
	.name		= "sf_bootdev",
 | 
						|
	.id		= UCLASS_BOOTDEV,
 | 
						|
	.ops		= &sf_bootdev_ops,
 | 
						|
	.bind		= sf_bootdev_bind,
 | 
						|
	.of_match	= sf_bootdev_ids,
 | 
						|
};
 | 
						|
 | 
						|
BOOTDEV_HUNTER(sf_bootdev_hunter) = {
 | 
						|
	.prio		= BOOTDEVP_4_SCAN_FAST,
 | 
						|
	.uclass		= UCLASS_SPI_FLASH,
 | 
						|
	.drv		= DM_DRIVER_REF(sf_bootdev),
 | 
						|
};
 |