linux/scripts/dtc/libfdt/libfdt_internal.h
Rob Herring (Arm) c072d2b495 scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c
This adds the following commits from upstream:

52f07dcca47c dtc: Add informative error for stray identifier
9cabae6b0351 checks: Fix detection of 'i2c-bus' node
605dc044c3fe New helper to add markers
7da5d106c740 fdtput: Fix documentation about existing nodes
53c63dd421d7 dtdiff: Use input format dtb for dtbo files
84d9dd2fcbc8 dtc: Add data_insert_data function
97011d1f4e98 meson: use override_find_program/override_dependency
b841391bbd08 srcpos: Define srcpos_free
e0b7749c26a9 Add alloc_marker
ecb21febfdd3 meson: port python bindings to build natively via meson and meson-python
7ebfcac8520e Makefile: deprecate in favor of Meson
f4c53f4ebf78 Use __ASSEMBLER__ instead of __ASSEMBLY__
205fbef17b7b Fix some typos
da85f91931e5 Remove duplicated words in documentation and comments
dd1b3e532d22 meson: support building libfdt without static library
1ccd232709d4 meson: don't build test programs by default
ce1d8588880a tests: When building .so from -O asm output mark as non-executable stack
915daadbb62d Start with empty __local_fixups__ and __fixups__ nodes
4ea851f5a44d Let get_subnode() not return deleted nodes
175d2a564c47 Use build_root_node() instead of open-coding it
18f4f305fdd7 build: fix -Dtools=false build
267efc7d4694 checks: Warn about missing #address-cells for interrupt parents
755db115355b libfdt: Add fdt_setprop_namelen_string()
bdca8612009e libfdt: Add fdt_setprop_namelen()
0f69cedc08fc libfdt_internal: fdt_find_string_len_()
56b2b30c5bd0 libfdt: add fdt_get_property_namelen_w()
1e8c5f60e127 Add clang-format config
6f183c7d9246 checks: Relax avoid_unnecessary_addr_size check to allow child ranges properties
66c7d0e6f4f3 tests/sw_tree1.c: fix unitialized saveptr
9a969f3b70b0 pylibfdt/libfdt.i: fix backwards compatibility of return values
4292b072a23a .github/workflows: update ubuntu runner to supported version
1c745a9bd169 libfdt: Remove fdt parameter from overlay_fixup_one_phandle
b3bbee6b1242 libfdt: Move the SBOM authors section
d1656730abfb Add a SBOM file in CycloneDX format
b75515af4576 libfdt: Remove extra semi-colons outside functions
2d10aa2afe35 Bump version to v1.7.2
48795c82bdb6 pylibfdt: Don't emit warnings from swig generate C code
838f11e830e3 fdtoverlay: provide better error message for missing `/__symbols__`
d1e2384185c5 pylibfdt/libfdt.i: Use SWIG_AppendOutput
18aa49a9f68d Escape spaces in depfile with backslashes.
f9968fa06921 libfdt.h: whitespace consistency fixups
9b5f65fb3d8d libfdt.h: typo and consistency fixes
99031e3a4a6e Bump version to v1.7.1
3d5e376925fd setup: Move setting of srcdir down to the bottom
e277553b9880 setup: Collect top-level code together
7e5a88984081 setup: Move version and full_description into a function
78b6a85c113b Tidy up some pylint warnings
3501d373f0a2 Require Python 3

The added include of string.h in libfdt_internal.h breaks the kernel
overriding libfdt_env.h with its own string functions, so it is dropped.
An upstream fix is pending.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2025-08-11 08:08:51 -05:00

200 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 */