mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-05-04 20:26:13 +02:00
Synchronize local copy of DTC with Linux 6.17 . This includes the
following picked and squashed commits from Linux kernel. The squash
was necessary, since the DTC here contains changes which were also
part of DTC in Linux alraedy, and the squash helped resolve those
without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7 # scripts/dtc: consolidate include path options in Makefile
b5b3d9b63b0ee # scripts/dtc: Add yamltree.c to dtc sources
7d97a76f226d6 # scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4
ea6f243be74e5 # scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d145
02d435d4eccd8 # scripts/dtc: Update to upstream version v1.5.0-23-g87963ee20693
6e321b7637396 # scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e73
9f19ec91a7a35 # scripts/dtc: dtx_diff - add color output support
8287d642f38d1 # scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a
4c52deef9225d # scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"
5d3827e1452ed # scripts/dtc: Remove unused makefile fragments
40dd266887654 # scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff9
8d4cf6b6acb59 # scripts/dtc: use pkg-config to include <yaml.h> in non-standard path
b9bf9ace5ae90 # scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c
69a883b6f5ac0 # scripts/dtc: dtx_diff - make help text formatting consistent
8f829108b8aed # scripts/dtc: only append to HOST_EXTRACFLAGS instead of overwriting
b39b4342ac495 # scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea121
93c6424c486b3 # scripts: dtc: Fetch fdtoverlay.c from external DTC project
0dd574a1d75c3 # scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9
ec38b5df8a231 # scripts: dtc: Build fdtoverlay tool
a0c8c431411f5 # scripts: dtc: Remove the unused fdtdump.c file
e7dc653d4e890 # scripts/dtc: Add missing fdtoverlay to gitignore
d2bf5d2e3f09c # scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8
a60878f5532d0 # scripts/dtc: dtx_diff: remove broken example from help text
8b739d8658a9b # scripts/dtc: Call pkg-config POSIXly correct
b6eeafa67df00 # scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61
f96cc4c787588 # scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e
09ab9c092ef2b # scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43
ded8a5a498f2d # scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429
ee6ff6fca7e71 # scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c
This also includes forward port of U-Boot commit
e8c2d25845c7 ("libfdt: Revert 6dcb8ba4 from upstream libfdt")
to avoid binary size growth.
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
201 lines
6.5 KiB
C
201 lines
6.5 KiB
C
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
|
#ifndef LIBFDT_INTERNAL_H
|
|
#define LIBFDT_INTERNAL_H
|
|
/*
|
|
* libfdt - Flat Device Tree manipulation
|
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
|
*/
|
|
#include <fdt.h>
|
|
|
|
#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
|
#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))
|
|
|
|
int32_t fdt_ro_probe_(const void *fdt);
|
|
#define FDT_RO_PROBE(fdt) \
|
|
{ \
|
|
int32_t totalsize_; \
|
|
if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \
|
|
return totalsize_; \
|
|
}
|
|
|
|
int fdt_check_node_offset_(const void *fdt, int offset);
|
|
int fdt_check_prop_offset_(const void *fdt, int offset);
|
|
|
|
const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s,
|
|
int s_len);
|
|
static inline const char *fdt_find_string_(const char *strtab, int tabsize,
|
|
const char *s)
|
|
{
|
|
return fdt_find_string_len_(strtab, tabsize, s, strlen(s));
|
|
}
|
|
|
|
int fdt_node_end_offset_(void *fdt, int nodeoffset);
|
|
|
|
static inline const void *fdt_offset_ptr_(const void *fdt, int offset)
|
|
{
|
|
return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
|
|
}
|
|
|
|
static inline void *fdt_offset_ptr_w_(void *fdt, int offset)
|
|
{
|
|
return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset);
|
|
}
|
|
|
|
static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n)
|
|
{
|
|
const struct fdt_reserve_entry *rsv_table =
|
|
(const struct fdt_reserve_entry *)
|
|
((const char *)fdt + fdt_off_mem_rsvmap(fdt));
|
|
|
|
return rsv_table + n;
|
|
}
|
|
static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n)
|
|
{
|
|
return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n);
|
|
}
|
|
|
|
/*
|
|
* Internal helpers to access structural elements of the device tree
|
|
* blob (rather than for example reading integers from within property
|
|
* values). We assume that we are either given a naturally aligned
|
|
* address for the platform or if we are not, we are on a platform
|
|
* where unaligned memory reads will be handled in a graceful manner.
|
|
* If not the external helpers fdtXX_ld() from libfdt.h can be used
|
|
* instead.
|
|
*/
|
|
static inline uint32_t fdt32_ld_(const fdt32_t *p)
|
|
{
|
|
return fdt32_to_cpu(*p);
|
|
}
|
|
|
|
static inline uint64_t fdt64_ld_(const fdt64_t *p)
|
|
{
|
|
return fdt64_to_cpu(*p);
|
|
}
|
|
|
|
#define FDT_SW_MAGIC (~FDT_MAGIC)
|
|
|
|
/**********************************************************************/
|
|
/* Checking controls */
|
|
/**********************************************************************/
|
|
|
|
#ifndef FDT_ASSUME_MASK
|
|
#define FDT_ASSUME_MASK 0
|
|
#endif
|
|
|
|
/*
|
|
* Defines assumptions which can be enabled. Each of these can be enabled
|
|
* individually. For maximum safety, don't enable any assumptions!
|
|
*
|
|
* For minimal code size and no safety, use ASSUME_PERFECT at your own risk.
|
|
* You should have another method of validating the device tree, such as a
|
|
* signature or hash check before using libfdt.
|
|
*
|
|
* For situations where security is not a concern it may be safe to enable
|
|
* ASSUME_SANE.
|
|
*/
|
|
enum {
|
|
/*
|
|
* This does essentially no checks. Only the latest device-tree
|
|
* version is correctly handled. Inconsistencies or errors in the device
|
|
* tree may cause undefined behaviour or crashes. Invalid parameters
|
|
* passed to libfdt may do the same.
|
|
*
|
|
* If an error occurs when modifying the tree it may leave the tree in
|
|
* an intermediate (but valid) state. As an example, adding a property
|
|
* where there is insufficient space may result in the property name
|
|
* being added to the string table even though the property itself is
|
|
* not added to the struct section.
|
|
*
|
|
* Only use this if you have a fully validated device tree with
|
|
* the latest supported version and wish to minimise code size.
|
|
*/
|
|
ASSUME_PERFECT = 0xff,
|
|
|
|
/*
|
|
* This assumes that the device tree is sane. i.e. header metadata
|
|
* and basic hierarchy are correct.
|
|
*
|
|
* With this assumption enabled, normal device trees produced by libfdt
|
|
* and the compiler should be handled safely. Malicious device trees and
|
|
* complete garbage may cause libfdt to behave badly or crash. Truncated
|
|
* device trees (e.g. those only partially loaded) can also cause
|
|
* problems.
|
|
*
|
|
* Note: Only checks that relate exclusively to the device tree itself
|
|
* (not the parameters passed to libfdt) are disabled by this
|
|
* assumption. This includes checking headers, tags and the like.
|
|
*/
|
|
ASSUME_VALID_DTB = 1 << 0,
|
|
|
|
/*
|
|
* This builds on ASSUME_VALID_DTB and further assumes that libfdt
|
|
* functions are called with valid parameters, i.e. not trigger
|
|
* FDT_ERR_BADOFFSET or offsets that are out of bounds. It disables any
|
|
* extensive checking of parameters and the device tree, making various
|
|
* assumptions about correctness.
|
|
*
|
|
* It doesn't make sense to enable this assumption unless
|
|
* ASSUME_VALID_DTB is also enabled.
|
|
*/
|
|
ASSUME_VALID_INPUT = 1 << 1,
|
|
|
|
/*
|
|
* This disables checks for device-tree version and removes all code
|
|
* which handles older versions.
|
|
*
|
|
* Only enable this if you know you have a device tree with the latest
|
|
* version.
|
|
*/
|
|
ASSUME_LATEST = 1 << 2,
|
|
|
|
/*
|
|
* This assumes that it is OK for a failed addition to the device tree,
|
|
* due to lack of space or some other problem, to skip any rollback
|
|
* steps (such as dropping the property name from the string table).
|
|
* This is safe to enable in most circumstances, even though it may
|
|
* leave the tree in a sub-optimal state.
|
|
*/
|
|
ASSUME_NO_ROLLBACK = 1 << 3,
|
|
|
|
/*
|
|
* This assumes that the device tree components appear in a 'convenient'
|
|
* order, i.e. the memory reservation block first, then the structure
|
|
* block and finally the string block.
|
|
*
|
|
* This order is not specified by the device-tree specification,
|
|
* but is expected by libfdt. The device-tree compiler always created
|
|
* device trees with this order.
|
|
*
|
|
* This assumption disables a check in fdt_open_into() and removes the
|
|
* ability to fix the problem there. This is safe if you know that the
|
|
* device tree is correctly ordered. See fdt_blocks_misordered_().
|
|
*/
|
|
ASSUME_LIBFDT_ORDER = 1 << 4,
|
|
|
|
/*
|
|
* This assumes that libfdt itself does not have any internal bugs. It
|
|
* drops certain checks that should never be needed unless libfdt has an
|
|
* undiscovered bug.
|
|
*
|
|
* This can generally be considered safe to enable.
|
|
*/
|
|
ASSUME_LIBFDT_FLAWLESS = 1 << 5,
|
|
};
|
|
|
|
/**
|
|
* can_assume_() - check if a particular assumption is enabled
|
|
*
|
|
* @mask: Mask to check (ASSUME_...)
|
|
* @return true if that assumption is enabled, else false
|
|
*/
|
|
static inline bool can_assume_(int mask)
|
|
{
|
|
return FDT_ASSUME_MASK & mask;
|
|
}
|
|
|
|
/** helper macros for checking assumptions */
|
|
#define can_assume(_assume) can_assume_(ASSUME_ ## _assume)
|
|
|
|
#endif /* LIBFDT_INTERNAL_H */
|