mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-10 09:17:00 +02:00
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>
This commit is contained in:
parent
66ebb10b0f
commit
fa94f8eec3
@ -49,3 +49,15 @@ config TI_COMMON_CMD_OPTIONS
|
|||||||
imply CMD_SPI
|
imply CMD_SPI
|
||||||
imply CMD_TIME
|
imply CMD_TIME
|
||||||
imply CMD_USB if USB
|
imply CMD_USB if USB
|
||||||
|
|
||||||
|
config TI_FDT_FOLDER_PATH
|
||||||
|
string "Location of Folder path where dtb is present"
|
||||||
|
default "ti/davinci" if ARCH_DAVINCI
|
||||||
|
default "ti/keystone" if ARCH_KEYSTONE
|
||||||
|
default "ti/omap" if ARCH_OMAP2PLUS
|
||||||
|
default "ti" if ARCH_K3
|
||||||
|
depends on ARCH_DAVINCI || ARCH_KEYSTONE || ARCH_OMAP2PLUS || ARCH_K3
|
||||||
|
help
|
||||||
|
Folder path for kernel device tree default.
|
||||||
|
This is used along with fdtfile path to locate the kernel
|
||||||
|
device tree blob.
|
||||||
|
@ -3,3 +3,4 @@
|
|||||||
|
|
||||||
obj-${CONFIG_TI_I2C_BOARD_DETECT} += board_detect.o
|
obj-${CONFIG_TI_I2C_BOARD_DETECT} += board_detect.o
|
||||||
obj-${CONFIG_CMD_EXTENSION} += cape_detect.o
|
obj-${CONFIG_CMD_EXTENSION} += cape_detect.o
|
||||||
|
obj-${CONFIG_OF_LIBFDT} += fdt_ops.o
|
||||||
|
64
board/ti/common/fdt_ops.c
Normal file
64
board/ti/common/fdt_ops.c
Normal file
@ -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");
|
||||||
|
}
|
42
board/ti/common/fdt_ops.h
Normal file
42
board/ti/common/fdt_ops.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
/*
|
||||||
|
* Library to support common device tree manipulation for TI EVMs
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FDT_OPS_H
|
||||||
|
#define __FDT_OPS_H
|
||||||
|
|
||||||
|
#define TI_BOARD_NAME_MAX 20
|
||||||
|
#define TI_FDT_FILE_MAX 200
|
||||||
|
|
||||||
|
/**
|
||||||
|
* struct ti_fdt_map - mapping of device tree blob name to board name
|
||||||
|
* @board_name: board_name up to TI_BOARD_NAME_MAX long
|
||||||
|
* @fdt_file_name: device tree blob name as described by kernel
|
||||||
|
*/
|
||||||
|
struct ti_fdt_map {
|
||||||
|
const char *board_name;
|
||||||
|
char *fdt_file_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ti_set_fdt_env - Find the correct device tree file name based on the
|
||||||
|
* board name and set 'fdtfile' env variable with correct folder
|
||||||
|
* structure appropriate to the architecture and Linux kernel's
|
||||||
|
* 'make install_dtbs' conventions. This function is invoked typically
|
||||||
|
* as part of board_late_init.
|
||||||
|
*
|
||||||
|
* fdt name is picked by:
|
||||||
|
* a) If a board name match is found, use the match
|
||||||
|
* b) If not, CONFIG_DEFAULT_FDT_FILE (Boot OS device tree) if that is defined
|
||||||
|
* and not null
|
||||||
|
* c) If not, Use CONFIG_DEFAULT_DEVICE_TREE (DT control for bootloader)
|
||||||
|
*
|
||||||
|
* @board_name: match to search with (max of TI_BOARD_NAME_MAX chars)
|
||||||
|
* @fdt_map: NULL terminated array of device tree file name matches.
|
||||||
|
*/
|
||||||
|
void ti_set_fdt_env(const char *board_name, struct ti_fdt_map *fdt_map);
|
||||||
|
|
||||||
|
#endif /* __FDT_OPS_H */
|
Loading…
Reference in New Issue
Block a user