[PATCH 12/16] bootstd: cros: Add a function to read a kernel

Simon Glass sjg at chromium.org
Sun Jul 30 19:16:58 CEST 2023


The code to read the ChromiumOS information from the partition is
currently all in one function.

Create a new function which reads the kernel, assuming that the metadata
has been parsed.

For now this function is not used. Future work will plumb it in.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 boot/bootmeth_cros.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c
index 82cbdcf2c93a..8728cd18e3c1 100644
--- a/boot/bootmeth_cros.c
+++ b/boot/bootmeth_cros.c
@@ -294,6 +294,45 @@ static int cros_read_info(struct bootflow *bflow, const char *uuid,
 	return 0;
 }
 
+static int cros_read_kernel(struct bootflow *bflow)
+{
+	struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);
+	struct cros_priv *priv = bflow->bootmeth_priv;
+	ulong base, setup;
+	ulong num_blks;
+	void *buf;
+	int ret;
+
+	bflow->size = priv->body_size;
+
+	buf = memalign(SZ_1K, priv->body_size);
+	if (!buf)
+		return log_msg_ret("buf", -ENOMEM);
+
+	/* Check that the header is not smaller than permitted */
+	if (priv->body_offset < PROBE_SIZE)
+		return log_msg_ret("san", EFAULT);
+
+	/* Read kernel body */
+	num_blks = priv->body_size >> desc->log2blksz;
+	log_debug("Reading body to %lx, blk=%s, size=%lx, blocks=%lx\n",
+		  (ulong)map_to_sysmem(buf), bflow->blk->name, priv->body_size,
+		  num_blks);
+	ret = blk_read(bflow->blk,
+		       priv->part_start + (priv->body_offset >> desc->log2blksz),
+		       num_blks, buf);
+	if (ret != num_blks)
+		return log_msg_ret("inf", -EIO);
+	base = map_to_sysmem(buf) + priv->bootloader_address -
+		priv->body_load_address;
+	setup = base + X86_SETUP_OFFSET;
+
+	bflow->buf = buf;
+	bflow->x86_setup = map_sysmem(setup, 0);
+
+	return 0;
+}
+
 static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
 	struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);
-- 
2.41.0.487.g6d72f3e995-goog



More information about the U-Boot mailing list