From patchwork Thu Apr 11 04:25:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Watts X-Patchwork-Id: 1922373 X-Patchwork-Delegate: andre.przywara@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.a=rsa-sha256 header.s=key1 header.b=n+qWO1Xs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VFRYc5MxQz1yY8 for ; Thu, 11 Apr 2024 14:29:40 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 942FC88229; Thu, 11 Apr 2024 06:29:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.b="n+qWO1Xs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 29E5288227; Thu, 11 Apr 2024 06:29:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [IPv6:2001:41d0:1004:224b::af]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3F54C88229 for ; Thu, 11 Apr 2024 06:29:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=contact@jookia.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1712809740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7mIJlPD/fYwcElW7PtXXO+XgsDkwy8SYfxHm/zU86nk=; b=n+qWO1XsR0asjtUNaQIbZyV7w2bNZ6MRNQNN6EjQ5coYLJOSkvbjl2Nce1EB2Nxa+8bEMR jCdjt+6W1qbjCLO2NkHGbAVSBcKBjHvTl4bY/wbZR15EGKpA5AwPvTfMw6Ls60RHmIwEpm TN/c0LImFKcqfAZCl6NCzpZXScjfBflWRliAbkVlxiDEpP8pXHyfcgQtmizxQ6rtaQZBdh Dmy4ZrKDHUoxzsxsHWdtePolGptzI/qFLj7DvHI3mgLDYuxlLI8nn/qAZ0O9hzfm6m3q6V eFnRj9IWOwlSK9ULlrzBfrQKkGdUiuqqenW1jBXPUkMZA/h82vbL6P01iPUzCg== From: John Watts Date: Thu, 11 Apr 2024 14:25:32 +1000 Subject: [PATCH RFC 15/15] spl: Support loading FIT images in UBI MIME-Version: 1.0 Message-Id: <20240411-spinand-v1-15-62d31bb188e8@jookia.org> References: <20240411-spinand-v1-0-62d31bb188e8@jookia.org> In-Reply-To: <20240411-spinand-v1-0-62d31bb188e8@jookia.org> To: Jagan Teki , Andre Przywara , Tom Rini , Daniel Schwierzeck , Rick Chen , Leo , Simon Glass Cc: u-boot@lists.denx.de, John Watts X-Developer-Signature: v=1; a=openssh-sha256; t=1712809597; l=2116; i=contact@jookia.org; h=from:subject:message-id; bh=p32ZDMbTt+1k+r9iLkbLQ+GXhRsHxSBhxzI9xAFqIAo=; b=U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgpGuA3uho2 8zVxm554DVLHyl4gq5/nBHglU5WIWN8/zYAAAAEc3NoOgAAAAZwYXRhdHQAAAAAAAAABnNoYTUx MgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAC4WZkakmxAMkzrmuW3sI5At V6XkSVjAsRsXSULDIzM9iJixbAsH9HrF22mQlDwEDXHz28wG3p3Htp4HY/tzHBgUAAOmK X-Developer-Key: i=contact@jookia.org; a=openssh; fpr=SHA256:6LBQmZH5u7i/edmEZXzCTwCrpSevs/ZshZxNmlD1thY X-Migadu-Flow: FLOW_OUT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The FIT loader doesn't support access through UBI, so load the FIT image ourself in to memory then boot it normally. Signed-off-by: John Watts --- common/spl/spl_ubi.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c index 72b4b195ed..b64f595160 100644 --- a/common/spl/spl_ubi.c +++ b/common/spl/spl_ubi.c @@ -12,6 +12,16 @@ #include #include +static ulong ram_spl_load_read(struct spl_load_info *load, ulong sector, + ulong count, void *buf) +{ + char *ubi_contents = load->priv; + + memcpy(buf, ubi_contents + sector, count); + + return count; +} + int spl_ubi_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { @@ -69,10 +79,11 @@ int spl_ubi_load_image(struct spl_image_info *spl_image, puts("Loading Linux failed, falling back to U-Boot.\n"); } #endif - header = spl_get_load_buffer(-sizeof(*header), sizeof(header)); + /* Ensure there's enough room for the full UBI volume! */ + header = (void *)CONFIG_SYS_LOAD_ADDR; #ifdef CONFIG_SPL_UBI_LOAD_BY_VOLNAME volumes[0].vol_id = -1; - strncpy(volumes[0].name, + strlcpy(volumes[0].name, CONFIG_SPL_UBI_LOAD_MONITOR_VOLNAME, UBI_VOL_NAME_MAX + 1); #else @@ -81,8 +92,23 @@ int spl_ubi_load_image(struct spl_image_info *spl_image, volumes[0].load_addr = (void *)header; ret = ubispl_load_volumes(&info, volumes, 1); - if (!ret) - spl_parse_image_header(spl_image, bootdev, header); + if (ret) + goto out; + + spl_parse_image_header(spl_image, bootdev, header); + + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) { + struct spl_load_info load; + + printf("Found FIT\n"); + load.priv = (char *)header; + load.read = ram_spl_load_read; + spl_set_bl_len(&load, 1); + + ret = spl_load_simple_fit(spl_image, &load, 0, header); + } + out: #ifdef CONFIG_SPL_SPINAND_SUPPORT if (bootdev->boot_device == BOOT_DEVICE_SPINAND)