Move efi_get_distro_fdt_name() into lib/efi so it can be used from the
app.

Signed-off-by: Simon Glass <s...@chromium.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schucha...@canonical.com>
---

 lib/efi/basename.c       | 62 +++++++++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_fdt.c | 63 ----------------------------------------
 2 files changed, 62 insertions(+), 63 deletions(-)

diff --git a/lib/efi/basename.c b/lib/efi/basename.c
index a01cdf1f5fa..b747dffad1d 100644
--- a/lib/efi/basename.c
+++ b/lib/efi/basename.c
@@ -89,3 +89,65 @@ int efi_get_pxe_arch(void)
 
        return -EINVAL;
 }
+
+/**
+ * efi_get_distro_fdt_name() - get the filename for reading the .dtb file
+ *
+ * @fname:     buffer for filename
+ * @size:      buffer size
+ * @seq:       sequence number, to cycle through options (0=first)
+ *
+ * Returns:
+ * 0 on success,
+ * -ENOENT if the "fdtfile" env var does not exist,
+ * -EINVAL if there are no more options,
+ * -EALREADY if the control FDT should be used
+ */
+int efi_get_distro_fdt_name(char *fname, int size, int seq)
+{
+       const char *fdt_fname;
+       const char *prefix;
+
+       /* select the prefix */
+       switch (seq) {
+       case 0:
+               /* this is the default */
+               prefix = "/dtb";
+               break;
+       case 1:
+               prefix = "";
+               break;
+       case 2:
+               prefix = "/dtb/current";
+               break;
+       case 3:
+               prefix = "/dtbs";
+               break;
+       default:
+               return log_msg_ret("pref", -EINVAL);
+       }
+
+       fdt_fname = env_get("fdtfile");
+       if (fdt_fname) {
+               snprintf(fname, size, "%s/%s", prefix, fdt_fname);
+               log_debug("Using device tree: %s\n", fname);
+       } else if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE)) {
+               strcpy(fname, "<prior>");
+               return log_msg_ret("pref", -EALREADY);
+       /* Use this fallback only for 32-bit ARM */
+       } else if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_ARM64)) {
+               const char *soc = env_get("soc");
+               const char *board = env_get("board");
+               const char *boardver = env_get("boardver");
+
+               /* cf the code in label_boot() which seems very complex */
+               snprintf(fname, size, "%s/%s%s%s%s.dtb", prefix,
+                        soc ? soc : "", soc ? "-" : "", board ? board : "",
+                        boardver ? boardver : "");
+               log_debug("Using default device tree: %s\n", fname);
+       } else {
+               return log_msg_ret("env", -ENOENT);
+       }
+
+       return 0;
+}
diff --git a/lib/efi_loader/efi_fdt.c b/lib/efi_loader/efi_fdt.c
index bfaa9cfc207..bd7cf454471 100644
--- a/lib/efi_loader/efi_fdt.c
+++ b/lib/efi_loader/efi_fdt.c
@@ -11,73 +11,10 @@
 #include <efi_device_path.h>
 #include <efi_loader.h>
 #include <env.h>
-#include <errno.h>
 #include <log.h>
 #include <string.h>
 #include <vsprintf.h>
 
-/**
- * efi_get_distro_fdt_name() - get the filename for reading the .dtb file
- *
- * @fname:     buffer for filename
- * @size:      buffer size
- * @seq:       sequence number, to cycle through options (0=first)
- *
- * Returns:
- * 0 on success,
- * -ENOENT if the "fdtfile" env var does not exist,
- * -EINVAL if there are no more options,
- * -EALREADY if the control FDT should be used
- */
-int efi_get_distro_fdt_name(char *fname, int size, int seq)
-{
-       const char *fdt_fname;
-       const char *prefix;
-
-       /* select the prefix */
-       switch (seq) {
-       case 0:
-               /* this is the default */
-               prefix = "/dtb";
-               break;
-       case 1:
-               prefix = "";
-               break;
-       case 2:
-               prefix = "/dtb/current";
-               break;
-       case 3:
-               prefix = "/dtbs";
-               break;
-       default:
-               return log_msg_ret("pref", -EINVAL);
-       }
-
-       fdt_fname = env_get("fdtfile");
-       if (fdt_fname) {
-               snprintf(fname, size, "%s/%s", prefix, fdt_fname);
-               log_debug("Using device tree: %s\n", fname);
-       } else if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE)) {
-               strcpy(fname, "<prior>");
-               return log_msg_ret("pref", -EALREADY);
-       /* Use this fallback only for 32-bit ARM */
-       } else if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_ARM64)) {
-               const char *soc = env_get("soc");
-               const char *board = env_get("board");
-               const char *boardver = env_get("boardver");
-
-               /* cf the code in label_boot() which seems very complex */
-               snprintf(fname, size, "%s/%s%s%s%s.dtb", prefix,
-                        soc ? soc : "", soc ? "-" : "", board ? board : "",
-                        boardver ? boardver : "");
-               log_debug("Using default device tree: %s\n", fname);
-       } else {
-               return log_msg_ret("env", -ENOENT);
-       }
-
-       return 0;
-}
-
 /**
  * efi_load_distro_fdt() - load distro device-tree
  *
-- 
2.43.0

Reply via email to