public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alexandru Gagniuc <mr.nuke.me@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 7/8] spl: fit: Replace #ifdef blocks with more readable constructs
Date: Tue, 22 Dec 2020 17:54:48 -0600	[thread overview]
Message-ID: <20201222235449.460100-8-mr.nuke.me@gmail.com> (raw)
In-Reply-To: <20201216000944.2832585-1-mr.nuke.me@gmail.com>

Use the IS_ENABLED() macro to control code flow, instead of the
caveman approach of sprinkling #ifdefs. Code size is not affected, as
the linker garbage-collects unused functions. However, readability is
improved significantly.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 common/spl/spl_fit.c | 53 ++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index c3da5b1443..35d7d8ec40 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -302,18 +302,16 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 		src = (void *)data;
 	}
 
-#ifdef CONFIG_SPL_FIT_SIGNATURE
-	printf("## Checking hash(es) for Image %s ... ",
-	       fit_get_name(fit, node, NULL));
-	if (!fit_image_verify_with_data(fit, node,
-					 src, length))
-		return -EPERM;
-	puts("OK\n");
-#endif
+	if (CONFIG_IS_ENABLED(FIT_SIGNATURE)) {
+		printf("## Checking hash(es) for Image %s ... ",
+		       fit_get_name(fit, node, NULL));
+		if (!fit_image_verify_with_data(fit, node, src, length))
+			return -EPERM;
+		puts("OK\n");
+	}
 
-#ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
-	board_fit_image_post_process(&src, &length);
-#endif
+	if (CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS))
+		board_fit_image_post_process(&src, &length);
 
 	if (IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP) {
 		size = length;
@@ -378,7 +376,9 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 
 	/* Make the load-address of the FDT available for the SPL framework */
 	spl_image->fdt_addr = (void *)image_info.load_addr;
-#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
+	if (CONFIG_IS_ENABLED(FIT_IMAGE_TINY))
+		return 0;
+
 	if (CONFIG_IS_ENABLED(LOAD_FIT_APPLY_OVERLAY)) {
 		void *tmpbuffer = NULL;
 
@@ -436,7 +436,6 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 	ret = fdt_shrink_to_minimum(spl_image->fdt_addr, 8192);
 	if (ret < 0)
 		return ret;
-#endif
 
 	return ret;
 }
@@ -445,10 +444,12 @@ static int spl_fit_record_loadable(const struct spl_fit_info *ctx, int index,
 				   void *blob, struct spl_image_info *image)
 {
 	int ret = 0;
-#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
 	const char *name;
 	int node;
 
+	if (CONFIG_IS_ENABLED(FIT_IMAGE_TINY))
+		return 0;
+
 	ret = spl_fit_get_image_name(ctx, "loadables", index, &name);
 	if (ret < 0)
 		return ret;
@@ -459,15 +460,15 @@ static int spl_fit_record_loadable(const struct spl_fit_info *ctx, int index,
 				  image->size, image->entry_point,
 				  fdt_getprop(ctx->fit, node, "type", NULL),
 				  fdt_getprop(ctx->fit, node, "os", NULL));
-#endif
 	return ret;
 }
 
 static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
 {
-#if CONFIG_IS_ENABLED(FIT_IMAGE_TINY) && !defined(CONFIG_SPL_OS_BOOT)
-	const char *name = fdt_getprop(fit, noffset, FIT_OS_PROP, NULL);
+	if (!CONFIG_IS_ENABLED(FIT_IMAGE_TINY) || CONFIG_IS_ENABLED(OS_BOOT))
+		return fit_image_get_os(fit, noffset, os);
 
+	const char *name = fdt_getprop(fit, noffset, FIT_OS_PROP, NULL);
 	if (!name)
 		return -ENOENT;
 
@@ -482,9 +483,6 @@ static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
 		*os = IH_OS_INVALID;
 
 	return 0;
-#else
-	return fit_image_get_os(fit, noffset, os);
-#endif
 }
 
 /*
@@ -628,10 +626,10 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	 */
 	if (node < 0)
 		node = spl_fit_get_image_node(&ctx, FIT_FIRMWARE_PROP, 0);
-#ifdef CONFIG_SPL_OS_BOOT
-	if (node < 0)
+
+	if (node < 0 && IS_ENABLED(CONFIG_SPL_OS_BOOT))
 		node = spl_fit_get_image_node(&ctx, FIT_KERNEL_PROP, 0);
-#endif
+
 	if (node < 0) {
 		debug("could not find firmware image, trying loadables...\n");
 		node = spl_fit_get_image_node(&ctx, "loadables", 0);
@@ -658,10 +656,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	 */
 	if (!spl_fit_image_get_os(ctx.fit, node, &spl_image->os))
 		debug("Image OS is %s\n", genimg_get_os_name(spl_image->os));
-#if !defined(CONFIG_SPL_OS_BOOT)
-	else
+	else if (!IS_ENABLED(CONFIG_SPL_OS_BOOT))
 		spl_image->os = IH_OS_U_BOOT;
-#endif
 
 	/*
 	 * Booting a next-stage U-Boot may require us to append the FDT.
@@ -727,9 +723,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 
 	spl_image->flags |= SPL_FIT_FOUND;
 
-#ifdef CONFIG_IMX_HAB
-	board_spl_fit_post_load(ctx.fit);
-#endif
+	if (IS_ENABLED(CONFIG_IMX_HAB))
+		board_spl_fit_post_load(ctx.fit);
 
 	return 0;
 }
-- 
2.26.2

  parent reply	other threads:[~2020-12-22 23:54 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16  0:09 [PATCH 0/8] spl: fit: Play nicely with OP-TEE and Linux Alexandru Gagniuc
2020-12-16  0:09 ` [PATCH 1/8] spl: fit: Drop 'length' argument to board_spl_fit_post_load() Alexandru Gagniuc
2020-12-16  7:13   ` Peng Fan
2020-12-16 14:32     ` Alex G.
2020-12-19  2:28   ` Simon Glass
2020-12-16  0:09 ` [PATCH 2/8] spl: fit: Factor out FIT parsing and use a context struct Alexandru Gagniuc
2020-12-19  2:28   ` Simon Glass
2020-12-21 19:28     ` Alex G.
2020-12-21 20:23       ` Simon Glass
2020-12-21 22:24         ` Alex G.
2020-12-29  3:33           ` Simon Glass
2020-12-30  0:07             ` Alex G.
2020-12-30 14:15               ` Tom Rini
2020-12-31  2:57               ` Simon Glass
2021-01-31  3:45                 ` Simon Glass
2020-12-16  0:09 ` [PATCH 3/8] spl: fit: Pass FIT context via a structure pointer Alexandru Gagniuc
2020-12-19  2:28   ` Simon Glass
2020-12-16  0:09 ` [PATCH 4/8] spl: fit: Remove useless loop in spl_fit_get_image_name() Alexandru Gagniuc
2020-12-19  2:29   ` Simon Glass
2020-12-16  0:09 ` [PATCH 5/8] spl: fit: Only look up FIT configuration node once Alexandru Gagniuc
2020-12-19  2:29   ` Simon Glass
2020-12-16  0:09 ` [PATCH 6/8] image: Do not #if guard board_fit_config_name_match() prototype Alexandru Gagniuc
2020-12-19  2:29   ` Simon Glass
2020-12-16  0:09 ` [PATCH 7/8] spl: fit: Replace #ifdef blocks with more readable constructs Alexandru Gagniuc
2020-12-19  2:29   ` Simon Glass
2020-12-21 17:43     ` Alex G.
2020-12-21 20:23       ` Simon Glass
2020-12-16  0:09 ` [PATCH 8/8] spl: fit: Load devicetree when a Linux payload is found Alexandru Gagniuc
2020-12-16 17:26   ` Alex G.
2020-12-22 23:54 ` [PATCH v2 0/8] spl: fit: Play nicely with OP-TEE and Linux Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 " Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 1/8] spl: fit: Drop 'length' argument to board_spl_fit_post_load() Alexandru Gagniuc
2021-01-16  2:33     ` Tom Rini
2021-01-18 16:28       ` Alex G.
2021-01-18 16:59         ` Tom Rini
2020-12-23 14:44   ` [PATCH v3 2/8] spl: fit: Factor out FIT parsing and use a context struct Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 3/8] spl: fit: Pass FIT context via a structure pointer Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 4/8] spl: fit: Remove useless loop in spl_fit_get_image_name() Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 5/8] spl: fit: Only look up FIT configuration node once Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 6/8] image: Do not #if guard board_fit_config_name_match() prototype Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 7/8] spl: fit: Replace #ifdef blocks with more readable constructs Alexandru Gagniuc
2020-12-23 14:44   ` [PATCH v3 8/8] spl: fit: Load devicetree when a Linux payload is found Alexandru Gagniuc
2020-12-22 23:54 ` [PATCH v2 1/8] spl: fit: Drop 'length' argument to board_spl_fit_post_load() Alexandru Gagniuc
2020-12-22 23:54 ` [PATCH v2 2/8] spl: fit: Factor out FIT parsing and use a context struct Alexandru Gagniuc
2020-12-29  3:32   ` Simon Glass
2020-12-22 23:54 ` [PATCH v2 3/8] spl: fit: Pass FIT context via a structure pointer Alexandru Gagniuc
2020-12-22 23:54 ` [PATCH v2 4/8] spl: fit: Remove useless loop in spl_fit_get_image_name() Alexandru Gagniuc
2020-12-22 23:54 ` [PATCH v2 5/8] spl: fit: Only look up FIT configuration node once Alexandru Gagniuc
2020-12-22 23:54 ` [PATCH v2 6/8] image: Do not #if guard board_fit_config_name_match() prototype Alexandru Gagniuc
2020-12-22 23:54 ` Alexandru Gagniuc [this message]
2020-12-22 23:54 ` [PATCH v2 8/8] spl: fit: Load devicetree when a Linux payload is found Alexandru Gagniuc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201222235449.460100-8-mr.nuke.me@gmail.com \
    --to=mr.nuke.me@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox