[U-Boot] [PATCH v4 02/30] spl: fit: Break out some functions into a common file

Franklin S Cooper Jr fcooper at ti.com
Fri Jun 16 22:25:05 UTC 2017


Some of the functions within spl_fit will be used for non spl purposes.
Instead of duplicating functions simply break the functions to be reused
into its own file.

Signed-off-by: Franklin S Cooper Jr <fcooper at ti.com>
Reviewed-by: Tom Rini <trini at konsulko.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
Version 4 changes:
Updated to work with latest master.
Reviewed-bys were left in since changes weren't significant.

 common/Makefile      |  1 +
 common/common_fit.c  | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/spl/spl_fit.c | 54 +--------------------------------------------
 include/image.h      |  7 ++++++
 4 files changed, 71 insertions(+), 53 deletions(-)
 create mode 100644 common/common_fit.c

diff --git a/common/Makefile b/common/Makefile
index 539cf98..d6d0764 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -96,6 +96,7 @@ obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o
 obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o
 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o
+obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
 obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o
 obj-$(CONFIG_SPL_OF_LIBFDT) += fdt_support.o
 ifdef CONFIG_SPL_USB_HOST_SUPPORT
diff --git a/common/common_fit.c b/common/common_fit.c
new file mode 100644
index 0000000..5f5f3f9
--- /dev/null
+++ b/common/common_fit.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Google, Inc
+ * Written by Simon Glass <sjg at chromium.org>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <image.h>
+#include <libfdt.h>
+#include <spl.h>
+
+ulong fdt_getprop_u32(const void *fdt, int node, const char *prop)
+{
+	const u32 *cell;
+	int len;
+
+	cell = fdt_getprop(fdt, node, prop, &len);
+	if (!cell || len != sizeof(*cell))
+		return FDT_ERROR;
+
+	return fdt32_to_cpu(*cell);
+}
+
+/*
+ * Iterate over all /configurations subnodes and call a platform specific
+ * function to find the matching configuration.
+ * Returns the node offset or a negative error number.
+ */
+int fit_find_config_node(const void *fdt)
+{
+	const char *name;
+	int conf, node, len;
+
+	conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
+	if (conf < 0) {
+		debug("%s: Cannot find /configurations node: %d\n", __func__,
+		      conf);
+		return -EINVAL;
+	}
+	for (node = fdt_first_subnode(fdt, conf);
+	     node >= 0;
+	     node = fdt_next_subnode(fdt, node)) {
+		name = fdt_getprop(fdt, node, "description", &len);
+		if (!name) {
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+			printf("%s: Missing FDT description in DTB\n",
+			       __func__);
+#endif
+			return -EINVAL;
+		}
+		if (board_fit_config_name_match(name))
+			continue;
+
+		debug("Selecting config '%s'", name);
+
+		return node;
+	}
+
+	return -ENOENT;
+}
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 4c42a96..d2a352e 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -11,58 +11,6 @@
 #include <libfdt.h>
 #include <spl.h>
 
-#define FDT_ERROR ((ulong)(-1))
-
-static ulong fdt_getprop_u32(const void *fdt, int node, const char *prop)
-{
-	const u32 *cell;
-	int len;
-
-	cell = fdt_getprop(fdt, node, prop, &len);
-	if (!cell || len != sizeof(*cell))
-		return FDT_ERROR;
-
-	return fdt32_to_cpu(*cell);
-}
-
-/*
- * Iterate over all /configurations subnodes and call a platform specific
- * function to find the matching configuration.
- * Returns the node offset or a negative error number.
- */
-static int spl_fit_find_config_node(const void *fdt)
-{
-	const char *name;
-	int conf, node, len;
-
-	conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
-	if (conf < 0) {
-		debug("%s: Cannot find /configurations node: %d\n", __func__,
-		      conf);
-		return -EINVAL;
-	}
-	for (node = fdt_first_subnode(fdt, conf);
-	     node >= 0;
-	     node = fdt_next_subnode(fdt, node)) {
-		name = fdt_getprop(fdt, node, "description", &len);
-		if (!name) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-			printf("%s: Missing FDT description in DTB\n",
-			       __func__);
-#endif
-			return -EINVAL;
-		}
-		if (board_fit_config_name_match(name))
-			continue;
-
-		debug("Selecting config '%s'", name);
-
-		return node;
-	}
-
-	return -ENOENT;
-}
-
 /**
  * spl_fit_get_image_node(): By using the matching configuration subnode,
  * retrieve the name of an image, specified by a property name and an index
@@ -82,7 +30,7 @@ static int spl_fit_get_image_node(const void *fit, int images,
 	int node, conf_node;
 	int len, i;
 
-	conf_node = spl_fit_find_config_node(fit);
+	conf_node = fit_find_config_node(fit);
 	if (conf_node < 0) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 		printf("No matching DT out of these options:\n");
diff --git a/include/image.h b/include/image.h
index fcfe730..6c9d051 100644
--- a/include/image.h
+++ b/include/image.h
@@ -18,6 +18,7 @@
 
 #include "compiler.h"
 #include <asm/byteorder.h>
+#include <linux/kconfig.h>
 
 /* Define this to avoid #ifdefs later on */
 struct lmb;
@@ -1270,6 +1271,12 @@ int board_fit_config_name_match(const char *name);
 void board_fit_image_post_process(void **p_image, size_t *p_size);
 #endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */
 
+#if IS_ENABLED(CONFIG_SPL_LOAD_FIT)
+
+#define FDT_ERROR ((ulong)(-1))
+
+#endif
+
 /**
  * Mapping of image types to function handlers to be invoked on the associated
  * loaded images
-- 
2.10.0



More information about the U-Boot mailing list