[U-Boot] [PATCH v3 02/30] spl: fit: Break out some functions into a common file
Franklin S Cooper Jr
fcooper at ti.com
Wed May 24 15:42:42 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>
---
common/Makefile | 1 +
common/common_fit.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
common/spl/spl_fit.c | 76 +---------------------------------------------
3 files changed, 88 insertions(+), 75 deletions(-)
create mode 100644 common/common_fit.c
diff --git a/common/Makefile b/common/Makefile
index 14d0184..ccd8bbc 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -95,6 +95,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..a08af72
--- /dev/null
+++ b/common/common_fit.c
@@ -0,0 +1,86 @@
+/*
+ * 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 (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;
--
2.10.0
More information about the U-Boot
mailing list