]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: move distro_efi_get_fdt_name()
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 26 Apr 2024 14:13:18 +0000 (16:13 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 10 Jun 2024 09:43:36 +0000 (11:43 +0200)
Move distro_efi_get_fdt_name() to a separate C module
and rename it to efi_get_distro_fdt_name().

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
boot/bootmeth_efi.c
include/efi_loader.h
lib/efi_loader/Makefile
lib/efi_loader/efi_fdt.c [new file with mode: 0644]

index c7035c0d0c4e2fed5a0eeae63fdf8ffd40e54905..5a4c125835a3be45e51160ca06c4706b3b3d6a01 100644 (file)
@@ -143,62 +143,6 @@ static int distro_efi_check(struct udevice *dev, struct bootflow_iter *iter)
        return 0;
 }
 
-/**
- * distro_efi_get_fdt_name() - Get the filename for reading the .dtb file
- *
- * @fname: Place to put filename
- * @size: Max size of filename
- * @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
- */
-static int distro_efi_get_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;
-       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;
-}
-
 /*
  * distro_efi_try_bootflow_files() - Check that files are present
  *
@@ -240,7 +184,7 @@ static int distro_efi_try_bootflow_files(struct udevice *dev,
        ret = -ENOENT;
        *fname = '\0';
        for (seq = 0; ret == -ENOENT; seq++) {
-               ret = distro_efi_get_fdt_name(fname, sizeof(fname), seq);
+               ret = efi_get_distro_fdt_name(fname, sizeof(fname), seq);
                if (ret == -EALREADY)
                        bflow->flags = BOOTFLOWF_USE_PRIOR_FDT;
                if (!ret) {
@@ -339,7 +283,7 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
        sprintf(file_addr, "%lx", fdt_addr);
 
        /* We only allow the first prefix with PXE */
-       ret = distro_efi_get_fdt_name(fname, sizeof(fname), 0);
+       ret = efi_get_distro_fdt_name(fname, sizeof(fname), 0);
        if (ret)
                return log_msg_ret("nam", ret);
 
index 1236eecff0f7ef68597e7363a0434db1239f770b..1b4bc987a2373505ae245263254d876bfa139d7d 100644 (file)
@@ -1199,4 +1199,6 @@ efi_status_t efi_load_option_dp_join(struct efi_device_path **dp,
                                     struct efi_device_path *initrd_dp,
                                     struct efi_device_path *fdt_dp);
 
+int efi_get_distro_fdt_name(char *fname, int size, int seq);
+
 #endif /* _EFI_LOADER_H */
index 034e366967f05feb7ba0a635c3be69d9bcdd60dd..2af6f2066b586b28460c006fee95d426a0d3f875 100644 (file)
@@ -59,6 +59,7 @@ obj-y += efi_device_path.o
 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
 obj-$(CONFIG_EFI_DEVICE_PATH_UTIL) += efi_device_path_utilities.o
 obj-y += efi_dt_fixup.o
+obj-y += efi_fdt.o
 obj-y += efi_file.o
 obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o
 obj-y += efi_image_loader.o
diff --git a/lib/efi_loader/efi_fdt.c b/lib/efi_loader/efi_fdt.c
new file mode 100644 (file)
index 0000000..0edf0c1
--- /dev/null
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for distro boot via EFI
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <efi_loader.h>
+#include <env.h>
+#include <errno.h>
+#include <log.h>
+#include <string.h>
+#include <vsprintf.h>
+
+/**
+ * distro_efi_get_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;
+       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;
+}