blob: 8a3300993ed39f0186dd804e6fb810921d199cb3 [file] [log] [blame]
Nishanth Menon9a9f6472024-02-12 13:47:17 -06001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Library to support FDT file operations which are common
4 *
5 * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
6 */
7
8#include <env.h>
Raymond Mao24da8312024-05-16 14:11:52 -07009#include <stdio.h>
Nishanth Menon9a9f6472024-02-12 13:47:17 -060010#include "fdt_ops.h"
11
12void ti_set_fdt_env(const char *board_name, struct ti_fdt_map *fdt_map)
13{
14 char *fdt_file_name = NULL;
15 char fdtfile[TI_FDT_FILE_MAX];
16
17 if (board_name) {
18 while (fdt_map) {
19 /* Check for NULL terminator in the list */
20 if (!fdt_map->board_name)
21 break;
22 if (!strncmp(fdt_map->board_name, board_name, TI_BOARD_NAME_MAX)) {
23 fdt_file_name = fdt_map->fdt_file_name;
24 break;
25 }
26 fdt_map++;
27 }
28 }
29
30 /* match not found OR null board_name */
31 if (!fdt_file_name) {
32 /*
33 * Prioritize CONFIG_DEFAULT_FDT_FILE - if that is not defined,
34 * or is empty, then use CONFIG_DEFAULT_DEVICE_TREE
35 */
36#ifdef CONFIG_DEFAULT_FDT_FILE
37 if (strlen(CONFIG_DEFAULT_FDT_FILE)) {
38 snprintf(fdtfile, sizeof(fdtfile), "%s/%s",
39 CONFIG_TI_FDT_FOLDER_PATH, CONFIG_DEFAULT_FDT_FILE);
40 } else
41#endif
42 {
43 snprintf(fdtfile, sizeof(fdtfile), "%s/%s.dtb",
44 CONFIG_TI_FDT_FOLDER_PATH, CONFIG_DEFAULT_DEVICE_TREE);
45 }
46 } else {
47 snprintf(fdtfile, sizeof(fdtfile), "%s/%s", CONFIG_TI_FDT_FOLDER_PATH,
48 fdt_file_name);
49 }
50
51 env_set("fdtfile", fdtfile);
52
53 /*
54 * XXX: DEPRECATION WARNING: 2 u-boot versions (2024.10).
55 *
56 * Maintain compatibility with downstream scripts that may be using
57 * name_fdt
58 */
59 if (board_name)
60 env_set("name_fdt", fdtfile);
61 /* Also set the findfdt legacy script to warn users to stop using this */
62 env_set("findfdt",
63 "echo WARN: fdtfile already set. Stop using findfdt in script");
64}