summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <[email protected]>2023-12-14 21:19:11 -0700
committerTom Rini <[email protected]>2024-04-10 17:04:25 -0600
commit8ed730f7204c72694b2214335a000207fcaf7e68 (patch)
treede0e19bac79fb9af569afa53aa2e284712fa394b
parent03a4a6d5bc9823576571bba5826d85f3b3c3a523 (diff)
pxe: Move calculation of FDT file into a function
This code undertakes a separate task from the main logic of label_run_boot() so move it into its own function. Signed-off-by: Simon Glass <[email protected]>
-rw-r--r--boot/pxe_utils.c112
1 files changed, 64 insertions, 48 deletions
diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index a6aee68bb79..a34f4410e07 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -470,6 +470,68 @@ skip_overlay:
#endif
/**
+ * calc_fdt_fname() - Figure out the filename to use for the FDT
+ *
+ * Determine the path to the FDT filename, based on the "fdtfile" environment
+ * variable. Use <soc>-<board>.dtb as a fallback
+ *
+ * @fdtdir: Directory to use for the FDT file
+ * Return: allocated filename (including directory), or NULL if out of memory
+ */
+static char *calc_fdt_fname(const char *fdtdir)
+{
+ char *fdtfile;
+ char *f1, *f2, *f3, *f4, *slash;
+ int len;
+
+ f1 = env_get("fdtfile");
+ if (f1) {
+ f2 = "";
+ f3 = "";
+ f4 = "";
+ } else {
+ /*
+ * For complex cases where this code doesn't generate the
+ * correct filename, the board code should set $fdtfile during
+ * early boot, or the boot scripts should set $fdtfile before
+ * invoking "pxe" or "sysboot".
+ */
+ f1 = env_get("soc");
+ f2 = "-";
+ f3 = env_get("board");
+ f4 = ".dtb";
+ if (!f1) {
+ f1 = "";
+ f2 = "";
+ }
+ if (!f3) {
+ f2 = "";
+ f3 = "";
+ }
+ }
+
+ len = strlen(fdtdir);
+ if (!len)
+ slash = "./";
+ else if (fdtdir[len - 1] != '/')
+ slash = "/";
+ else
+ slash = "";
+
+ len = strlen(fdtdir) + strlen(slash) + strlen(f1) + strlen(f2) +
+ strlen(f3) + strlen(f4) + 1;
+ fdtfile = malloc(len);
+ if (!fdtfile) {
+ printf("malloc fail (FDT filename)\n");
+ return NULL;
+ }
+
+ snprintf(fdtfile, len, "%s%s%s%s%s%s", fdtdir, slash, f1, f2, f3, f4);
+
+ return fdtfile;
+}
+
+/**
* label_run_boot() - Run the correct boot procedure
*
* fdt usage is optional:
@@ -525,55 +587,9 @@ static int label_run_boot(struct pxe_context *ctx, struct pxe_label *label,
if (label->fdt) {
fdtfile = label->fdt;
} else if (label->fdtdir) {
- char *f1, *f2, *f3, *f4, *slash;
- int len;
-
- f1 = env_get("fdtfile");
- if (f1) {
- f2 = "";
- f3 = "";
- f4 = "";
- } else {
- /*
- * For complex cases where this code doesn't
- * generate the correct filename, the board
- * code should set $fdtfile during early boot,
- * or the boot scripts should set $fdtfile
- * before invoking "pxe" or "sysboot".
- */
- f1 = env_get("soc");
- f2 = "-";
- f3 = env_get("board");
- f4 = ".dtb";
- if (!f1) {
- f1 = "";
- f2 = "";
- }
- if (!f3) {
- f2 = "";
- f3 = "";
- }
- }
-
- len = strlen(label->fdtdir);
- if (!len)
- slash = "./";
- else if (label->fdtdir[len - 1] != '/')
- slash = "/";
- else
- slash = "";
-
- len = strlen(label->fdtdir) + strlen(slash) +
- strlen(f1) + strlen(f2) + strlen(f3) +
- strlen(f4) + 1;
- fdtfilefree = malloc(len);
- if (!fdtfilefree) {
- printf("malloc fail (FDT filename)\n");
+ fdtfilefree = calc_fdt_fname(label->fdtdir);
+ if (!fdtfilefree)
return -ENOMEM;
- }
-
- snprintf(fdtfilefree, len, "%s%s%s%s%s%s",
- label->fdtdir, slash, f1, f2, f3, f4);
fdtfile = fdtfilefree;
}