scripts/dtc/libfdt/fdt_rw.c
Source file repositories/reference/linux-study-clean/scripts/dtc/libfdt/fdt_rw.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/dtc/libfdt/fdt_rw.c- Extension
.c- Size
- 12589 bytes
- Lines
- 513
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
libfdt_env.hfdt.hlibfdt.hlibfdt_internal.h
Detected Declarations
function Copyrightfunction fdt_downgrade_versionfunction fdt_rw_probe_function fdt_data_size_function fdt_splice_function fdt_splice_mem_rsv_function fdt_splice_struct_function fdt_del_last_string_function fdt_splice_string_function fdt_find_add_string_function fdt_add_mem_rsvfunction fdt_del_mem_rsvfunction fdt_resize_property_function fdt_add_property_function fdt_set_namefunction fdt_setprop_placeholder_namelenfunction fdt_setprop_namelenfunction fdt_appendpropfunction fdt_delpropfunction fdt_add_subnode_namelenfunction fdt_add_subnodefunction fdt_del_nodefunction fdt_packblocks_function fdt_open_intofunction fdt_pack
Annotated Snippet
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
/*
* libfdt - Flat Device Tree manipulation
* Copyright (C) 2006 David Gibson, IBM Corporation.
*/
#include "libfdt_env.h"
#include <fdt.h>
#include <libfdt.h>
#include "libfdt_internal.h"
static int fdt_blocks_misordered_(const void *fdt,
int mem_rsv_size, int struct_size)
{
return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8))
|| (fdt_off_dt_struct(fdt) <
(fdt_off_mem_rsvmap(fdt) + mem_rsv_size))
|| (fdt_off_dt_strings(fdt) <
(fdt_off_dt_struct(fdt) + struct_size))
|| (fdt_totalsize(fdt) <
(fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)));
}
static void fdt_downgrade_version(void *fdt)
{
if (!can_assume(LATEST) && fdt_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);
}
static int fdt_rw_probe_(void *fdt)
{
if (can_assume(VALID_DTB))
return 0;
FDT_RO_PROBE(fdt);
if (!can_assume(LATEST) && fdt_version(fdt) < 17)
return -FDT_ERR_BADVERSION;
if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry),
fdt_size_dt_struct(fdt)))
return -FDT_ERR_BADLAYOUT;
fdt_downgrade_version(fdt);
return 0;
}
#define FDT_RW_PROBE(fdt) \
{ \
int err_; \
if ((err_ = fdt_rw_probe_(fdt)) != 0) \
return err_; \
}
static inline unsigned int fdt_data_size_(void *fdt)
{
return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
}
static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen)
{
char *p = splicepoint;
unsigned int dsize = fdt_data_size_(fdt);
size_t soff = p - (char *)fdt;
if ((oldlen < 0) || (soff + oldlen < soff) || (soff + oldlen > dsize))
return -FDT_ERR_BADOFFSET;
if ((p < (char *)fdt) || (dsize + newlen < (unsigned)oldlen))
return -FDT_ERR_BADOFFSET;
if (dsize - oldlen + newlen > fdt_totalsize(fdt))
return -FDT_ERR_NOSPACE;
memmove(p + newlen, p + oldlen, ((char *)fdt + dsize) - (p + oldlen));
return 0;
}
static int fdt_splice_mem_rsv_(void *fdt, struct fdt_reserve_entry *p,
int oldn, int newn)
{
int delta = (newn - oldn) * sizeof(*p);
int err;
err = fdt_splice_(fdt, p, oldn * sizeof(*p), newn * sizeof(*p));
if (err)
return err;
fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta);
fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);
return 0;
}
static int fdt_splice_struct_(void *fdt, void *p,
int oldlen, int newlen)
{
Annotation
- Immediate include surface: `libfdt_env.h`, `fdt.h`, `libfdt.h`, `libfdt_internal.h`.
- Detected declarations: `function Copyright`, `function fdt_downgrade_version`, `function fdt_rw_probe_`, `function fdt_data_size_`, `function fdt_splice_`, `function fdt_splice_mem_rsv_`, `function fdt_splice_struct_`, `function fdt_del_last_string_`, `function fdt_splice_string_`, `function fdt_find_add_string_`.
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.