diff mbox

[U-Boot,02/31] spl: fit: Break out some functions into a common file

Message ID 20170302190435.23212-3-fcooper@ti.com
State Changes Requested
Delegated to: Tom Rini
Headers show

Commit Message

Franklin S Cooper Jr March 2, 2017, 7:04 p.m. UTC
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@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
 common/Makefile      |  1 +
 common/common_fit.c  | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/spl/spl_fit.c | 76 +---------------------------------------------
 include/image.h      |  8 +++++
 4 files changed, 96 insertions(+), 75 deletions(-)
 create mode 100644 common/common_fit.c

Comments

Simon Glass March 8, 2017, 9:01 p.m. UTC | #1
Hi Franklin,

On 2 March 2017 at 12:04, Franklin S Cooper Jr <fcooper@ti.com> wrote:
> 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@ti.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> ---
>  common/Makefile      |  1 +
>  common/common_fit.c  | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  common/spl/spl_fit.c | 76 +---------------------------------------------
>  include/image.h      |  8 +++++
>  4 files changed, 96 insertions(+), 75 deletions(-)
>  create mode 100644 common/common_fit.c

This seems to conflict with Andre's series. What is the plan here?

- Simon
Franklin S Cooper Jr March 8, 2017, 9:30 p.m. UTC | #2
+Andre

On 03/08/2017 03:01 PM, Simon Glass wrote:
> Hi Franklin,
> 
> On 2 March 2017 at 12:04, Franklin S Cooper Jr <fcooper@ti.com> wrote:
>> 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@ti.com>
>> Reviewed-by: Tom Rini <trini@konsulko.com>
>> ---
>>  common/Makefile      |  1 +
>>  common/common_fit.c  | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  common/spl/spl_fit.c | 76 +---------------------------------------------
>>  include/image.h      |  8 +++++
>>  4 files changed, 96 insertions(+), 75 deletions(-)
>>  create mode 100644 common/common_fit.c
> 
> This seems to conflict with Andre's series. What is the plan here?

I'll have to look at it closely again but from what I remember Andre's
series was adding additional functionality to functions within spl_fit
while I only care about making those same functions accessible beyond
SPL. So it depends on whose code is merged first but I don't think it is
a big problem to manage.

> 
> - Simon
>
Simon Glass March 13, 2017, 12:33 p.m. UTC | #3
On 2 March 2017 at 12:04, Franklin S Cooper Jr <fcooper@ti.com> wrote:
> 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@ti.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> ---
>  common/Makefile      |  1 +
>  common/common_fit.c  | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  common/spl/spl_fit.c | 76 +---------------------------------------------
>  include/image.h      |  8 +++++
>  4 files changed, 96 insertions(+), 75 deletions(-)
>  create mode 100644 common/common_fit.c

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

Patch

diff --git a/common/Makefile b/common/Makefile
index 86225f1..692ebc4 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -94,6 +94,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_TRANSLATE) += 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..a08af72
--- /dev/null
+++ b/common/common_fit.c
@@ -0,0 +1,86 @@ 
+/*
+ * Copyright (C) 2016 Google, Inc
+ * Written by Simon Glass <sjg@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 (len != sizeof(*cell))
+		return -1U;
+	return fdt32_to_cpu(*cell);
+}
+
+int fit_select_fdt(const void *fdt, int images, int *fdt_offsetp)
+{
+	const char *name, *fdt_name;
+	int conf, node, fdt_node;
+	int len;
+
+	*fdt_offsetp = 0;
+	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);
+		fdt_name = fdt_getprop(fdt, node, FIT_FDT_PROP, &len);
+		if (!fdt_name) {
+			debug("%s: Cannot find fdt name property: %d\n",
+			      __func__, len);
+			return -EINVAL;
+		}
+
+		debug(", fdt '%s'\n", fdt_name);
+		fdt_node = fdt_subnode_offset(fdt, images, fdt_name);
+		if (fdt_node < 0) {
+			debug("%s: Cannot find fdt node '%s': %d\n",
+			      __func__, fdt_name, fdt_node);
+			return -EINVAL;
+		}
+
+		*fdt_offsetp = fdt_getprop_u32(fdt, fdt_node, "data-offset");
+		len = fdt_getprop_u32(fdt, fdt_node, "data-size");
+		debug("FIT: Selected '%s'\n", name);
+
+		return len;
+	}
+
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+	printf("No matching DT out of these options:\n");
+	for (node = fdt_first_subnode(fdt, conf);
+	     node >= 0;
+	     node = fdt_next_subnode(fdt, node)) {
+		name = fdt_getprop(fdt, node, "description", &len);
+		printf("   %s\n", name);
+	}
+#endif
+
+	return -ENOENT;
+}
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index aae556f..3a722d3 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -11,80 +11,6 @@ 
 #include <libfdt.h>
 #include <spl.h>
 
-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 (len != sizeof(*cell))
-		return -1U;
-	return fdt32_to_cpu(*cell);
-}
-
-static int spl_fit_select_fdt(const void *fdt, int images, int *fdt_offsetp)
-{
-	const char *name, *fdt_name;
-	int conf, node, fdt_node;
-	int len;
-
-	*fdt_offsetp = 0;
-	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);
-		fdt_name = fdt_getprop(fdt, node, FIT_FDT_PROP, &len);
-		if (!fdt_name) {
-			debug("%s: Cannot find fdt name property: %d\n",
-			      __func__, len);
-			return -EINVAL;
-		}
-
-		debug(", fdt '%s'\n", fdt_name);
-		fdt_node = fdt_subnode_offset(fdt, images, fdt_name);
-		if (fdt_node < 0) {
-			debug("%s: Cannot find fdt node '%s': %d\n",
-			      __func__, fdt_name, fdt_node);
-			return -EINVAL;
-		}
-
-		*fdt_offsetp = fdt_getprop_u32(fdt, fdt_node, "data-offset");
-		len = fdt_getprop_u32(fdt, fdt_node, "data-size");
-		debug("FIT: Selected '%s'\n", name);
-
-		return len;
-	}
-
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-	printf("No matching DT out of these options:\n");
-	for (node = fdt_first_subnode(fdt, conf);
-	     node >= 0;
-	     node = fdt_next_subnode(fdt, node)) {
-		name = fdt_getprop(fdt, node, "description", &len);
-		printf("   %s\n", name);
-	}
-#endif
-
-	return -ENOENT;
-}
-
 static int get_aligned_image_offset(struct spl_load_info *info, int offset)
 {
 	/*
@@ -218,7 +144,7 @@  int spl_load_simple_fit(struct spl_image_info *spl_image,
 	memcpy(dst, src, data_size);
 
 	/* Figure out which device tree the board wants to use */
-	fdt_len = spl_fit_select_fdt(fit, images, &fdt_offset);
+	fdt_len = fit_select_fdt(fit, images, &fdt_offset);
 	if (fdt_len < 0)
 		return fdt_len;
 
diff --git a/include/image.h b/include/image.h
index 1e686b7..bb8d699 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;
@@ -1274,6 +1275,13 @@  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)
+
+ulong fdt_getprop_u32(const void *fdt, int node, const char *prop);
+int fit_select_fdt(const void *fdt, int images, int *fdt_offsetp);
+
+#endif
+
 /**
  * Mapping of image types to function handlers to be invoked on the associated
  * loaded images