diff mbox series

[4/4] spl: atf: Reduce SPL code size

Message ID 20230916082507.583405-1-massimo.pegorer+oss@gmail.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series spl: atf: Fix potential bug on getting FIT data | expand

Commit Message

Massimo Pegorer Sept. 16, 2023, 8:25 a.m. UTC
Previous fix commit increases code size of a few bytes. This minor
rework finally reduces SPL size of about 64-72 bytes (tested with
buildman on several aarch64 boards).

Signed-off-by: Massimo Pegorer <massimo.pegorer+oss@gmail.com>
---
 common/spl/spl_atf.c | 42 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)

Comments

Simon Glass Sept. 21, 2023, 1:02 a.m. UTC | #1
On Sat, 16 Sept 2023 at 02:25, Massimo Pegorer
<massimo.pegorer+oss@gmail.com> wrote:
>
> Previous fix commit increases code size of a few bytes. This minor
> rework finally reduces SPL size of about 64-72 bytes (tested with
> buildman on several aarch64 boards).
>
> Signed-off-by: Massimo Pegorer <massimo.pegorer+oss@gmail.com>
> ---
>  common/spl/spl_atf.c | 42 +++++++++++++++++++-----------------------
>  1 file changed, 19 insertions(+), 23 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

It would be nice to have test coverage of this code, in a sandbox_spl test
diff mbox series

Patch

diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c
index 0d8db2d14e..fa79f73be2 100644
--- a/common/spl/spl_atf.c
+++ b/common/spl/spl_atf.c
@@ -209,7 +209,19 @@  static void spl_enter_atf(uintptr_t bl31_entry, uintptr_t bl32_entry,
 	atf_entry(bl31_params, (void *)fdt_addr);
 }
 
-static int spl_fit_images_find(void *blob, int os)
+static void spl_fit_images_get_entry(void *blob, int node, uintptr_t *entry_p)
+{
+	ulong val;
+
+	if (fit_image_get_entry(blob, node, &val))
+		if (fit_image_get_load(blob, node, &val))
+			return;
+
+	debug("%s: entry point 0x%lx\n", __func__, val);
+	*entry_p = val;
+}
+
+static int spl_fit_images_get_os_entry(void *blob, int os, uintptr_t *entry_p)
 {
 	int parent, node, ndepth = 0;
 	const void *data;
@@ -231,41 +243,28 @@  static int spl_fit_images_find(void *blob, int os)
 		if (!data)
 			continue;
 
-		if (genimg_get_os_id(data) == os)
-			return node;
+		if (genimg_get_os_id(data) == os) {
+			spl_fit_images_get_entry(blob, node, entry_p);
+			return 0;
+		}
 	};
 
 	return -FDT_ERR_NOTFOUND;
 }
 
-void spl_fit_images_get_entry(void *blob, int node, uintptr_t *entry_p)
-{
-	ulong val;
-
-	if (fit_image_get_entry(blob, node, &val))
-		if (fit_image_get_load(blob, node, &val))
-			return;
-
-	debug("%s: entry point 0x%lx\n", __func__, val);
-	*entry_p = val;
-}
-
 void spl_invoke_atf(struct spl_image_info *spl_image)
 {
 	uintptr_t bl32_entry = 0;
 	uintptr_t bl33_entry = CONFIG_TEXT_BASE;
 	void *blob = spl_image->fdt_addr;
 	uintptr_t platform_param = (uintptr_t)blob;
-	int node;
 
 	/*
 	 * Find (in /fit-images) the TEE binary entry point address
 	 * (or load address if entry point is missing) and pass it as
 	 * the BL3-2 entry point. This is optional.
 	 */
-	node = spl_fit_images_find(blob, IH_OS_TEE);
-	if (node >= 0)
-		spl_fit_images_get_entry(blob, node, &bl32_entry);
+	spl_fit_images_get_os_entry(blob, IH_OS_TEE, &bl32_entry);
 
 	/*
 	 * Find (in /fit-images) the U-Boot binary entry point address
@@ -273,10 +272,7 @@  void spl_invoke_atf(struct spl_image_info *spl_image)
 	 * the BL3-3 entry point.
 	 * This will need to be extended to support Falcon mode.
 	 */
-
-	node = spl_fit_images_find(blob, IH_OS_U_BOOT);
-	if (node >= 0)
-		spl_fit_images_get_entry(blob, node, &bl33_entry);
+	spl_fit_images_get_os_entry(blob, IH_OS_U_BOOT, &bl33_entry);
 
 	/*
 	 * If ATF_NO_PLATFORM_PARAM is set, we override the platform