summaryrefslogtreecommitdiff
path: root/board/ti/common/fdt_ops.c
diff options
context:
space:
mode:
authorNishanth Menon <nm@ti.com>2024-02-12 13:47:17 -0600
committerTom Rini <trini@konsulko.com>2024-02-20 17:57:40 -0500
commitfa94f8eec367f89f1036249e7bdbaf7b0fc28e64 (patch)
treee1748ebb50a589fe5b1c3eb13c44b991b6ae69bd /board/ti/common/fdt_ops.c
parent66ebb10b0f7ef870a98adbe2c35fa3e54761ee05 (diff)
board: ti: common: Introduce a common fdt ops library
Introduce a common fdt operations library for basic device tree operations that are common between various boards. The first library to introduce here is the capability to set up fdtfile as a standard variable as part of board identification rather than depend on scripted ifdeffery. Reviewed-by: Jonathan Humphreys <j-humphreys@ti.com> Reviewed-by: Roger Quadros <rogerq@kernel.org> Signed-off-by: Nishanth Menon <nm@ti.com>
Diffstat (limited to 'board/ti/common/fdt_ops.c')
-rw-r--r--board/ti/common/fdt_ops.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/board/ti/common/fdt_ops.c b/board/ti/common/fdt_ops.c
new file mode 100644
index 00000000000..eb917be9e0d
--- /dev/null
+++ b/board/ti/common/fdt_ops.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Library to support FDT file operations which are common
+ *
+ * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include <env.h>
+#include <vsprintf.h>
+#include "fdt_ops.h"
+
+void ti_set_fdt_env(const char *board_name, struct ti_fdt_map *fdt_map)
+{
+ char *fdt_file_name = NULL;
+ char fdtfile[TI_FDT_FILE_MAX];
+
+ if (board_name) {
+ while (fdt_map) {
+ /* Check for NULL terminator in the list */
+ if (!fdt_map->board_name)
+ break;
+ if (!strncmp(fdt_map->board_name, board_name, TI_BOARD_NAME_MAX)) {
+ fdt_file_name = fdt_map->fdt_file_name;
+ break;
+ }
+ fdt_map++;
+ }
+ }
+
+ /* match not found OR null board_name */
+ if (!fdt_file_name) {
+ /*
+ * Prioritize CONFIG_DEFAULT_FDT_FILE - if that is not defined,
+ * or is empty, then use CONFIG_DEFAULT_DEVICE_TREE
+ */
+#ifdef CONFIG_DEFAULT_FDT_FILE
+ if (strlen(CONFIG_DEFAULT_FDT_FILE)) {
+ snprintf(fdtfile, sizeof(fdtfile), "%s/%s",
+ CONFIG_TI_FDT_FOLDER_PATH, CONFIG_DEFAULT_FDT_FILE);
+ } else
+#endif
+ {
+ snprintf(fdtfile, sizeof(fdtfile), "%s/%s.dtb",
+ CONFIG_TI_FDT_FOLDER_PATH, CONFIG_DEFAULT_DEVICE_TREE);
+ }
+ } else {
+ snprintf(fdtfile, sizeof(fdtfile), "%s/%s", CONFIG_TI_FDT_FOLDER_PATH,
+ fdt_file_name);
+ }
+
+ env_set("fdtfile", fdtfile);
+
+ /*
+ * XXX: DEPRECATION WARNING: 2 u-boot versions (2024.10).
+ *
+ * Maintain compatibility with downstream scripts that may be using
+ * name_fdt
+ */
+ if (board_name)
+ env_set("name_fdt", fdtfile);
+ /* Also set the findfdt legacy script to warn users to stop using this */
+ env_set("findfdt",
+ "echo WARN: fdtfile already set. Stop using findfdt in script");
+}