summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-10-16 02:39:56 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-10-16 02:39:56 +0800
commit8cace3f05003c6cb4d38c36890055f03151c2ad4 (patch)
treeaa739deaac0266f17c4e91b333957501cb1ea2e9 /scripts
parent3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee (diff)
downloadlume-8cace3f05003c6cb4d38c36890055f03151c2ad4.tar.gz
lume-8cace3f05003c6cb4d38c36890055f03151c2ad4.tar.xz
Remove old code
Signed-off-by: Richard Qin <richard.qin.x@gmail.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Kbuild.include159
-rw-r--r--scripts/Kconfig.mk205
-rw-r--r--scripts/build/Build.mk10
-rwxr-xr-xscripts/build/archive.sh10
-rwxr-xr-xscripts/build/check-kernel-elf.sh47
-rw-r--r--scripts/build/environments/host.mk8
-rw-r--r--scripts/build/environments/kernel.mk28
-rw-r--r--scripts/build/environments/phys.mk12
-rwxr-xr-xscripts/build/generate-asm-offsets.sh25
-rwxr-xr-xscripts/build/generate-autoconf.sh29
-rwxr-xr-xscripts/build/generate-initramfs.sh12
-rwxr-xr-xscripts/build/link-kernel.sh10
-rwxr-xr-xscripts/build/probe-toolchain.sh72
-rw-r--r--scripts/build/probes/libc_headers.c10
-rw-r--r--scripts/build/probes/libc_headers.cc12
-rw-r--r--scripts/build/probes/libcxx.cc16
-rwxr-xr-xscripts/build/run-if-changed.sh45
-rw-r--r--scripts/build/targets.mk81
-rw-r--r--scripts/build/tests/host_library.cc8
-rw-r--r--scripts/build/tests/host_test.cc7
-rw-r--r--scripts/build/tests/phys_library.cc5
-rw-r--r--scripts/build/toolchain.mk130
-rwxr-xr-xscripts/build/write-compdb.py26
-rw-r--r--scripts/dtc/libfdt/fdt.c347
-rw-r--r--scripts/dtc/libfdt/fdt.h66
-rw-r--r--scripts/dtc/libfdt/fdt_addresses.c101
-rw-r--r--scripts/dtc/libfdt/fdt_empty_tree.c38
-rw-r--r--scripts/dtc/libfdt/fdt_overlay.c1101
-rw-r--r--scripts/dtc/libfdt/fdt_ro.c888
-rw-r--r--scripts/dtc/libfdt/fdt_rw.c512
-rw-r--r--scripts/dtc/libfdt/fdt_strerror.c60
-rw-r--r--scripts/dtc/libfdt/fdt_sw.c384
-rw-r--r--scripts/dtc/libfdt/fdt_wip.c94
-rw-r--r--scripts/dtc/libfdt/libfdt.h2540
-rw-r--r--scripts/dtc/libfdt/libfdt_env.h69
-rw-r--r--scripts/dtc/libfdt/libfdt_internal.h202
-rw-r--r--scripts/extract-asm-offsets.sed18
-rwxr-xr-xscripts/gen_initramfs.sh250
38 files changed, 0 insertions, 7637 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
deleted file mode 100644
index 611499d..0000000
--- a/scripts/Kbuild.include
+++ /dev/null
@@ -1,159 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (C) 2026 Richard Qin
-#
-# scripts/Kbuild.include — shared Make helpers for LumeOS.
-#
-# Mirrors a small, useful subset of Linux's scripts/Kbuild.include.
-# Provides:
-#
-# - Q / KBUILD_VERBOSE : `make V=1` shows full commands,
-# default V=0 prints a one-line summary
-# - $(call cmd,<name>) : echo a quiet summary, then run cmd_<name>
-# - $(call if_changed,<name>) : rebuild when inputs or the command change.
-#
-# Naming convention adopted from Linux: each command has both a
-# `quiet_cmd_<name>` (single-line summary) and a `cmd_<name>` (full
-# command line). $(quiet) selects which prefix to display:
-# V=0 -> quiet := quiet_ -> echoes " CC foo.c"
-# V=1 -> quiet := -> echoes the full $(CC) $(CFLAGS) ...
-# ----------------------------------------------------------------------
-
-# --- Verbosity ---------------------------------------------------------
-# Override at the command line: `make V=1`. Default V=0 = quiet.
-KBUILD_VERBOSE ?= $(V)
-KBUILD_VERBOSE ?= 0
-
-ifeq ($(KBUILD_VERBOSE),1)
- Q :=
- quiet :=
-else
- Q := @
- quiet := quiet_
-endif
-
-# --- echo-cmd / cmd / if_changed ---------------------------------------
-#
-# echo-cmd prints the recipe's one-line summary (when quiet) or its full
-# command line (when verbose). Implementation uses $($(quiet)cmd_<name>)
-# so the right form is picked up automatically.
-#
-# cmd is the workhorse: print summary, then execute the real command.
-echo-cmd = $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';)
-
-cmd = @$(echo-cmd) $(cmd_$(1))
-
-# Record a checksum of the exact argv next to each output. FORCE makes Make
-# reconsider the action; run-if-changed executes it only for a changed input or
-# command signature.
-if_changed = @scripts/build/run-if-changed.sh \
- $(dir $@).$(notdir $@).cmd $@ '$($(quiet)cmd_$(1))' $^ -- $(cmd_$(1))
-
-# --- Standard quiet_cmd_* / cmd_* templates ---------------------------
-#
-# Subdir Makefiles and the top-level Makefile can reference these by
-# name via $(call cmd,<name>). Add new pairs here as new recipe shapes
-# show up (e.g., cmd_lz / cmd_gz / cmd_zstd for compressed Image targets).
-
- quiet_cmd_cc_o_c = CC $(PRIVATE_SOURCE)
- cmd_cc_o_c = $(CC) $(CFLAGS_LIBC) $(PRIVATE_INCLUDES) $(PRIVATE_DEFINES) $(PRIVATE_CFLAGS) -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_cxx_o_cc = CXX $(PRIVATE_SOURCE)
- cmd_cxx_o_cc = $(CXX) $(CXXFLAGS) $(PRIVATE_INCLUDES) $(PRIVATE_DEFINES) $(PRIVATE_CXXFLAGS) -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_as_o_S = AS $(PRIVATE_SOURCE)
- cmd_as_o_S = $(CC) $(ASFLAGS) $(PRIVATE_INCLUDES) $(PRIVATE_DEFINES) $(PRIVATE_ASFLAGS) -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_cc_s_c = CC -S $<
- cmd_cc_s_c = $(CC) $(CFLAGS_LIBC) -S $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_gen_asm_offsets = GEN $@
- cmd_gen_asm_offsets = scripts/build/generate-asm-offsets.sh $@ \
- $(ASM_OFFSETS_S) $(ASM_OFFSETS_SED) $(ASM_OFFSETS_C)
-
- quiet_cmd_autoconf = GEN $@
- cmd_autoconf = scripts/build/generate-autoconf.sh $@ \
- CONFIG_NR_CPUS $(CONFIG_NR_CPUS) value \
- CONFIG_HZ $(CONFIG_HZ) value \
- CONFIG_NR_PRIORITIES $(CONFIG_NR_PRIORITIES) value \
- CONFIG_DEFAULT_PRIORITY $(CONFIG_DEFAULT_PRIORITY) value \
- CONFIG_IDLE_PRIORITY $(CONFIG_IDLE_PRIORITY) value \
- CONFIG_DEFAULT_TIMESLICE $(CONFIG_DEFAULT_TIMESLICE) value \
- CONFIG_PAGE_SIZE $(CONFIG_PAGE_SIZE) value \
- CONFIG_MAX_ORDER $(CONFIG_MAX_ORDER) value \
- CONFIG_KERNEL_STACK_SIZE $(CONFIG_KERNEL_STACK_SIZE) value \
- CONFIG_KASLR $(CONFIG_KASLR) bool \
- CONFIG_KASLR_POLICY_ID $(CONFIG_KASLR_POLICY_ID) value \
- CONFIG_KASLR_LOG_LEVEL $(CONFIG_KASLR_LOG_LEVEL) value \
- CONFIG_STACK_CANARY $(CONFIG_STACK_CANARY) bool \
- CONFIG_DEBUG $(CONFIG_DEBUG) bool \
- CONFIG_DEBUG_LOCKS $(CONFIG_DEBUG_LOCKS) bool \
- CONFIG_SELFTEST $(CONFIG_SELFTEST) bool \
- CONFIG_KLOG $(CONFIG_KLOG) bool \
- CONFIG_KERNEL_COMPRESSED $(CONFIG_KERNEL_COMPRESSED) bool
-
- quiet_cmd_linker_script = LDS $@
- cmd_linker_script = $(CC) -E -P -x c $(INCLUDES) $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_initramfs = INITRAMFS $(INITRAMFS_SOURCE)
- cmd_initramfs = scripts/build/generate-initramfs.sh $(GEN_INIT_CPIO) \
- ./scripts/gen_initramfs.sh $@ \
- $(CONFIG_INITRAMFS_ROOT_UID) $(CONFIG_INITRAMFS_ROOT_GID) \
- $(INITRAMFS_SOURCE)
-
- quiet_cmd_initramfs_obj = AS $@ (initramfs)
- cmd_initramfs_obj = $(CC) $(ASFLAGS) \
- -DINITRAMFS_IMAGE='"$(INITRAMFS_CPIO)"' \
- -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_objcopy_bin = OBJCOPY $@
- cmd_objcopy_bin = $(OBJCOPY) -O binary $< $@
-
- quiet_cmd_archive = AR $@
- cmd_archive = scripts/build/archive.sh $@ $(AR) $(PRIVATE_ARCHIVE_OBJECTS)
-
- quiet_cmd_host_tool = HOSTCC $@
- cmd_host_tool = $(HOSTCC) $(HOSTCFLAGS) $(PRIVATE_HOST_CFLAGS) \
- -o $@ $(PRIVATE_HOST_SOURCE)
-
- quiet_cmd_host_cc_o_c = HOSTCC $(PRIVATE_SOURCE)
- cmd_host_cc_o_c = $(HOSTCC) $(HOSTCFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_host_cxx_o_cc = HOSTCXX $(PRIVATE_SOURCE)
- cmd_host_cxx_o_cc = $(HOSTCXX) $(HOSTCXXFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_host_archive = HOSTAR $@
- cmd_host_archive = scripts/build/archive.sh $@ $(HOSTAR) $(PRIVATE_ARCHIVE_OBJECTS)
-
- quiet_cmd_host_link = HOSTLD $@
- cmd_host_link = $(HOSTCXX) $(HOSTCXXFLAGS) -o $@ \
- $(PRIVATE_HOST_OBJECTS) $(PRIVATE_HOST_LIBS)
-
- quiet_cmd_toolchain_probe = PROBE toolchain
- cmd_toolchain_probe = scripts/build/probe-toolchain.sh $@ \
- $(CC) $(CXX) $(LD) $(COMPILER_FAMILY) $(TARGET_TRIPLE) \
- '$(GCC_TOOLCHAIN)' '$(GCC_SYSROOT)' \
- '$(KTL_INCLUDE)' '$(KTL_AFTER_INCLUDE)' \
- '$(KERNEL_LIBC_INCLUDE)' '$(KERNEL_LIBC_AFTER_INCLUDE)' \
- '$(LIBCXX_INCLUDE)' '$(COMPILER_RESOURCE_INCLUDE)'
-
- quiet_cmd_phys_cc_o_c = PHYSCC $(PRIVATE_SOURCE)
- cmd_phys_cc_o_c = $(CC) $(PHYS_CFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_phys_cxx_o_cc = PHYSCXX $(PRIVATE_SOURCE)
- cmd_phys_cxx_o_cc = $(CXX) $(PHYS_CXXFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_phys_as_o_S = PHYSAS $(PRIVATE_SOURCE)
- cmd_phys_as_o_S = $(CC) $(PHYS_ASFLAGS) -MMD -MP -c $(PRIVATE_SOURCE) -o $@
-
- quiet_cmd_link_vmlume = LD $@
- cmd_link_vmlume = scripts/build/link-kernel.sh $@ $(SIZE) \
- $(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ \
- $(KERNEL_LINK_INPUTS) $(INITRAMFS_OBJ)
-
-# Objcopy with custom flags via per-target OBJCOPYFLAGS variable —
-# used by the .pi.o post-processing rule (--prefix-symbols=__pi_ etc.).
- quiet_cmd_objcopy = OBJCOPY $@
- cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $< $@
-
- quiet_cmd_ld_kernel = LD $@
- cmd_ld_kernel = $(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ $^
diff --git a/scripts/Kconfig.mk b/scripts/Kconfig.mk
deleted file mode 100644
index 3db7a2f..0000000
--- a/scripts/Kconfig.mk
+++ /dev/null
@@ -1,205 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (C) 2026 Richard Qin
-#
-# scripts/Kconfig.mk — Kernel Configuration Infrastructure
-#
-# This file is the heart of the LumeOS build-time configuration system.
-# It mirrors the role of Linux's Kconfig + auto.conf pipeline:
-#
-# 1. Developer edits `$(O)/.config` (or runs `make O=... defconfig`)
-# 2. This file reads that configuration and applies missing defaults,
-# validates constraints, and exports two things:
-# a) KCPPFLAGS — a set of -DCONFIG_xxx=value flags for the compiler
-# b) $(BUILD)/generated/autoconf.h — the same values as C #defines
-#
-# Design Principles (matching Linux conventions):
-# - Every CONFIG_ symbol has a default defined HERE, so an empty output
-# directory still builds a sane kernel.
-# - Boolean options use 'y' / 'n'. Numeric options are plain integers.
-# - The generated autoconf.h uses the exact same names so that
-# `#ifdef CONFIG_DEBUG` works identically in Makefile and C.
-# ======================================================================
-
-# ------------------------------------------------------------------
-# §1 Read user configuration (if it exists)
-# ------------------------------------------------------------------
-KCONFIG_CONFIG ?= $(BUILD)/.config
--include $(KCONFIG_CONFIG)
-
-# ------------------------------------------------------------------
-# §2 Provide defaults for every CONFIG_ symbol
-#
-# ?= means "set only if not already set (by .config or CLI)".
-# This is the single source of truth for default values.
-# ------------------------------------------------------------------
-
-# --- Platform -------------------------------------------------------
-CONFIG_ARCH ?= riscv
-
-# --- CPU / SMP ------------------------------------------------------
-CONFIG_NR_CPUS ?= 8
-
-# --- Scheduler ------------------------------------------------------
-CONFIG_HZ ?= 100
-CONFIG_NR_PRIORITIES ?= 32
-
-# --- Memory Management ----------------------------------------------
-CONFIG_PAGE_SIZE ?= 4096
-CONFIG_MAX_ORDER ?= 11
-CONFIG_KERNEL_STACK_SIZE ?= 8192
-
-# --- Security / Hardening -------------------------------------------
-CONFIG_KASLR ?= y
-CONFIG_KASLR_POLICY_ID ?= 0
-CONFIG_KASLR_LOG_LEVEL ?= 1
-CONFIG_STACK_CANARY ?= y
-CONFIG_KERNEL_COMPRESSED ?= y
-
-# --- Debug -----------------------------------------------------------
-CONFIG_DEBUG ?= y
-CONFIG_DEBUG_LOCKS ?= y
-CONFIG_SELFTEST ?= y
-CONFIG_KLOG ?= y
-
-# --- Initramfs ------------------------------------------------------
-# Source for the initramfs image. Accepted forms (auto-detected by
-# scripts/gen_initramfs.sh):
-# - a listing file (gen_init_cpio format) → built into a cpio
-# - a directory → packed recursively
-# - a *.cpio file → used as-is
-# Override on the command line or pin in .config:
-# make all CONFIG_INITRAMFS_SOURCE=/path/to/rootfs
-CONFIG_INITRAMFS_SOURCE ?= usr/default_cpio_list
-CONFIG_INITRAMFS_ROOT_UID ?= 0
-CONFIG_INITRAMFS_ROOT_GID ?= 0
-
-# ------------------------------------------------------------------
-# §3 Derived constants (computed from CONFIG_ symbols)
-#
-# These follow Linux's pattern of expressing dependent values
-# so that C code never has to do its own derivation at runtime.
-# ------------------------------------------------------------------
-
-# Default priority = middle of the range
-CONFIG_DEFAULT_PRIORITY = $(shell echo $$(( $(CONFIG_NR_PRIORITIES) / 2 )))
-
-# Idle priority = lowest = NR_PRIORITIES - 1
-CONFIG_IDLE_PRIORITY = $(shell echo $$(( $(CONFIG_NR_PRIORITIES) - 1 )))
-
-# Default time slice in ticks: 100ms worth of ticks
-# (same as Linux CFS's sysctl_sched_min_granularity default)
-CONFIG_DEFAULT_TIMESLICE = $(shell echo $$(( $(CONFIG_HZ) / 10 )))
-
-# ------------------------------------------------------------------
-# §4 Export to C/C++ via -D flags
-#
-# KCPPFLAGS is appended to CFLAGS/CXXFLAGS in the main Makefile.
-# Every CONFIG_xxx=<value> becomes -DCONFIG_xxx=<value>.
-# Boolean 'y' options become -DCONFIG_xxx=1.
-# ------------------------------------------------------------------
-KCPPFLAGS :=
-
-# Numeric options — pass through as-is
-KCPPFLAGS += -DCONFIG_NR_CPUS=$(CONFIG_NR_CPUS)
-KCPPFLAGS += -DCONFIG_HZ=$(CONFIG_HZ)
-KCPPFLAGS += -DCONFIG_NR_PRIORITIES=$(CONFIG_NR_PRIORITIES)
-KCPPFLAGS += -DCONFIG_DEFAULT_PRIORITY=$(CONFIG_DEFAULT_PRIORITY)
-KCPPFLAGS += -DCONFIG_IDLE_PRIORITY=$(CONFIG_IDLE_PRIORITY)
-KCPPFLAGS += -DCONFIG_DEFAULT_TIMESLICE=$(CONFIG_DEFAULT_TIMESLICE)
-KCPPFLAGS += -DCONFIG_PAGE_SIZE=$(CONFIG_PAGE_SIZE)
-KCPPFLAGS += -DCONFIG_MAX_ORDER=$(CONFIG_MAX_ORDER)
-KCPPFLAGS += -DCONFIG_KERNEL_STACK_SIZE=$(CONFIG_KERNEL_STACK_SIZE)
-
-# Boolean options — translate 'y' → 1
-ifeq ($(CONFIG_KASLR),y)
-KCPPFLAGS += -DCONFIG_KASLR=1
-endif
-KCPPFLAGS += -DCONFIG_KASLR_POLICY_ID=$(CONFIG_KASLR_POLICY_ID)
-KCPPFLAGS += -DCONFIG_KASLR_LOG_LEVEL=$(CONFIG_KASLR_LOG_LEVEL)
-ifeq ($(CONFIG_STACK_CANARY),y)
-KCPPFLAGS += -DCONFIG_STACK_CANARY=1
-endif
-ifeq ($(CONFIG_DEBUG),y)
-KCPPFLAGS += -DCONFIG_DEBUG=1
-endif
-ifeq ($(CONFIG_DEBUG_LOCKS),y)
-KCPPFLAGS += -DCONFIG_DEBUG_LOCKS=1
-endif
-ifeq ($(CONFIG_SELFTEST),y)
-KCPPFLAGS += -DCONFIG_SELFTEST=1
-endif
-ifeq ($(CONFIG_KLOG),y)
-KCPPFLAGS += -DCONFIG_KLOG=1
-endif
-ifeq ($(CONFIG_KERNEL_COMPRESSED),y)
-KCPPFLAGS += -DCONFIG_KERNEL_COMPRESSED=1
-endif
-
-# ------------------------------------------------------------------
-# §5 Generate autoconf.h (analogous to Linux's include/generated/autoconf.h)
-#
-# This header is auto-generated at build time so that C code can
-# #include <generated/autoconf.h> and see CONFIG_xxx macros without
-# relying on -D flags alone. This is important for IDE integration.
-# ------------------------------------------------------------------
-AUTOCONF_H := $(BUILD)/generated/autoconf.h
-
-# ------------------------------------------------------------------
-# §6 Utility targets
-# ------------------------------------------------------------------
-
-# 'make defconfig' — reset .config to the arch default
-.PHONY: defconfig savedefconfig showconfig
-
-defconfig:
- @echo " DEFCFG arch/$(CONFIG_ARCH)/defconfig → $(KCONFIG_CONFIG)"
- @mkdir -p $(dir $(KCONFIG_CONFIG))
- @cp arch/$(CONFIG_ARCH)/defconfig $(KCONFIG_CONFIG)
-
-# 'make savedefconfig' — save current effective config
-savedefconfig:
- @echo " SAVE $(KCONFIG_CONFIG)"
- @mkdir -p $(dir $(KCONFIG_CONFIG))
- @echo "# LumeOS Kernel Configuration (saved $$(date +%Y-%m-%d))" > $(KCONFIG_CONFIG)
- @echo "CONFIG_ARCH = $(CONFIG_ARCH)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_NR_CPUS = $(CONFIG_NR_CPUS)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_HZ = $(CONFIG_HZ)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_NR_PRIORITIES = $(CONFIG_NR_PRIORITIES)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_PAGE_SIZE = $(CONFIG_PAGE_SIZE)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_MAX_ORDER = $(CONFIG_MAX_ORDER)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_KERNEL_STACK_SIZE = $(CONFIG_KERNEL_STACK_SIZE)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_KASLR = $(CONFIG_KASLR)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_KASLR_POLICY_ID = $(CONFIG_KASLR_POLICY_ID)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_KASLR_LOG_LEVEL = $(CONFIG_KASLR_LOG_LEVEL)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_STACK_CANARY = $(CONFIG_STACK_CANARY)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_DEBUG = $(CONFIG_DEBUG)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_DEBUG_LOCKS = $(CONFIG_DEBUG_LOCKS)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_SELFTEST = $(CONFIG_SELFTEST)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_KLOG = $(CONFIG_KLOG)" >> $(KCONFIG_CONFIG)
- @echo "CONFIG_KERNEL_COMPRESSED = $(CONFIG_KERNEL_COMPRESSED)" >> $(KCONFIG_CONFIG)
-
-# 'make showconfig' — print effective configuration
-showconfig:
- @echo "========================================"
- @echo " LumeOS Effective Configuration"
- @echo "========================================"
- @echo " ARCH = $(CONFIG_ARCH)"
- @echo " NR_CPUS = $(CONFIG_NR_CPUS)"
- @echo " HZ = $(CONFIG_HZ)"
- @echo " NR_PRIORITIES = $(CONFIG_NR_PRIORITIES)"
- @echo " DEFAULT_PRIORITY = $(CONFIG_DEFAULT_PRIORITY)"
- @echo " IDLE_PRIORITY = $(CONFIG_IDLE_PRIORITY)"
- @echo " DEFAULT_TIMESLICE = $(CONFIG_DEFAULT_TIMESLICE)"
- @echo " PAGE_SIZE = $(CONFIG_PAGE_SIZE)"
- @echo " MAX_ORDER = $(CONFIG_MAX_ORDER)"
- @echo " KERNEL_STACK_SIZE = $(CONFIG_KERNEL_STACK_SIZE)"
- @echo " KASLR = $(CONFIG_KASLR)"
- @echo " KASLR_POLICY_ID = $(CONFIG_KASLR_POLICY_ID)"
- @echo " KASLR_LOG_LEVEL = $(CONFIG_KASLR_LOG_LEVEL)"
- @echo " STACK_CANARY = $(CONFIG_STACK_CANARY)"
- @echo " DEBUG = $(CONFIG_DEBUG)"
- @echo " DEBUG_LOCKS = $(CONFIG_DEBUG_LOCKS)"
- @echo " SELFTEST = $(CONFIG_SELFTEST)"
- @echo " KLOG = $(CONFIG_KLOG)"
- @echo " KERNEL_COMPRESSED = $(CONFIG_KERNEL_COMPRESSED)"
- @echo "========================================"
diff --git a/scripts/build/Build.mk b/scripts/build/Build.mk
deleted file mode 100644
index 0a15b38..0000000
--- a/scripts/build/Build.mk
+++ /dev/null
@@ -1,10 +0,0 @@
-targets += build/host-library-smoke build/host-test-smoke build/phys-library-smoke
-target.build/host-library-smoke.kind := host-library
-target.build/host-library-smoke.sources := scripts/build/tests/host_library.cc
-
-target.build/host-test-smoke.kind := host-test
-target.build/host-test-smoke.sources := scripts/build/tests/host_test.cc
-target.build/host-test-smoke.private-deps := build/host-library-smoke
-
-target.build/phys-library-smoke.kind := phys-library
-target.build/phys-library-smoke.sources := scripts/build/tests/phys_library.cc
diff --git a/scripts/build/archive.sh b/scripts/build/archive.sh
deleted file mode 100755
index 79f0bb9..0000000
--- a/scripts/build/archive.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-archive=$1
-ar=$2
-shift 2
-rm -f "$archive"
-"$ar" rcs "$archive" "$@"
-
diff --git a/scripts/build/check-kernel-elf.sh b/scripts/build/check-kernel-elf.sh
deleted file mode 100755
index eb92b33..0000000
--- a/scripts/build/check-kernel-elf.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-elf=$1
-readelf=$2
-nm=$3
-arch=$4
-
-case "$arch" in
- riscv) expected_machine='RISC-V' ;;
- aarch64) expected_machine='AArch64' ;;
- x86_64) expected_machine='Advanced Micro Devices X86-64' ;;
- *) echo "ELF check: unsupported architecture: $arch" >&2; exit 2 ;;
-esac
-
-machine=$($readelf -h "$elf" | sed -n 's/^[[:space:]]*Machine:[[:space:]]*//p')
-[ "$machine" = "$expected_machine" ] || {
- echo "ELF check: expected machine '$expected_machine', got '$machine'" >&2
- exit 1
-}
-
-entry=$($readelf -h "$elf" | sed -n 's/^[[:space:]]*Entry point address:[[:space:]]*//p')
-[ -n "$entry" ] && [ "$entry" != 0x0 ] || {
- echo "ELF check: kernel has no entry point" >&2
- exit 1
-}
-
-undefined=$($nm -u "$elf" || true)
-[ -z "$undefined" ] || {
- echo "ELF check: undefined symbols:" >&2
- printf '%s\n' "$undefined" >&2
- exit 1
-}
-
-if $readelf -W -l "$elf" | awk '$1 == "LOAD" && $0 ~ /W/ && $0 ~ /E/ { found=1 } END { exit !found }'; then
- echo "ELF check: writable and executable LOAD segment" >&2
- exit 1
-fi
-
-$readelf -S "$elf" | grep -q '[.]rela[.]dyn' || {
- echo "ELF check: missing relocation section .rela.dyn" >&2
- exit 1
-}
-
-echo "Kernel ELF OK: $machine, entry $entry"
-
diff --git a/scripts/build/environments/host.mk b/scripts/build/environments/host.mk
deleted file mode 100644
index 0911ad3..0000000
--- a/scripts/build/environments/host.mk
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-HOSTCC ?= cc
-HOSTCXX ?= c++
-HOSTAR ?= ar
-HOSTCFLAGS ?= -O2 -g -Wall -Wextra
-HOSTCXXFLAGS ?= $(HOSTCFLAGS) -std=c++23
-
diff --git a/scripts/build/environments/kernel.mk b/scripts/build/environments/kernel.mk
deleted file mode 100644
index 1d6c8cf..0000000
--- a/scripts/build/environments/kernel.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-WARNINGS ?= -Wall -Wextra -Wno-unused-parameter
-
-ifeq ($(BUILD_VARIANT),release)
-KERNEL_OPT_FLAGS := -O2 -g0 -DNDEBUG
-else
-KERNEL_OPT_FLAGS := -O2 -g
-endif
-
-CFLAGS := $(WARNINGS) $(KERNEL_OPT_FLAGS) \
- -ffreestanding -nostdlib \
- -mcmodel=medany -fPIE -MMD -MP \
- $(TOOLCHAIN_CFLAGS) $(KCPPFLAGS) $(INCLUDES) \
- -I$(BUILD)/generated
-
-CFLAGS_LIBC := -Iinclude/libc-shim $(CFLAGS) -std=gnu23 \
- -Wno-parentheses -Wno-sign-compare
-
-CXXFLAGS := $(CFLAGS) $(TOOLCHAIN_CXXFLAGS) -std=c++23 \
- -fno-exceptions -fno-rtti -fno-use-cxa-atexit \
- -fno-threadsafe-statics
-
-# Pre-MMU assembly must never use GOT-indirect addressing.
-ASFLAGS := $(filter-out -fPIE,$(CFLAGS)) -fno-pie
-
-LDFLAGS := -nostdlib -shared -Bsymbolic -z notext -z norelro \
- --no-dynamic-linker
diff --git a/scripts/build/environments/phys.mk b/scripts/build/environments/phys.mk
deleted file mode 100644
index 6a11c12..0000000
--- a/scripts/build/environments/phys.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-# Early physical-address execution environment. It deliberately has no heap,
-# exceptions, RTTI, thread-safe statics, or PIE/GOT assumptions.
-PHYS_CFLAGS := $(WARNINGS) -Os -g -ffreestanding -nostdlib \
- -fno-pie -fno-stack-protector $(TOOLCHAIN_CFLAGS) \
- $(KCPPFLAGS) $(INCLUDES) -I$(BUILD)/generated
-PHYS_CXXFLAGS := $(PHYS_CFLAGS) $(TOOLCHAIN_CXXFLAGS) -std=c++23 \
- -fno-exceptions -fno-rtti -fno-use-cxa-atexit \
- -fno-threadsafe-statics
-PHYS_ASFLAGS := $(PHYS_CFLAGS)
-
diff --git a/scripts/build/generate-asm-offsets.sh b/scripts/build/generate-asm-offsets.sh
deleted file mode 100755
index 4e90f94..0000000
--- a/scripts/build/generate-asm-offsets.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-output=$1
-assembly=$2
-sed_script=$3
-source=$4
-tmp="$output.tmp.$$"
-{
- echo '/* AUTO-GENERATED — DO NOT EDIT */'
- echo "/* Generated from $source */"
- echo '#ifndef _LUME_GENERATED_ASM_OFFSETS_H'
- echo '#define _LUME_GENERATED_ASM_OFFSETS_H'
- echo
- sed -n -f "$sed_script" "$assembly"
- echo
- echo '#endif /* _LUME_GENERATED_ASM_OFFSETS_H */'
-} > "$tmp"
-if [ -e "$output" ] && cmp -s "$tmp" "$output"; then
- rm -f "$tmp"
-else
- mv -f "$tmp" "$output"
-fi
-
diff --git a/scripts/build/generate-autoconf.sh b/scripts/build/generate-autoconf.sh
deleted file mode 100755
index 493d630..0000000
--- a/scripts/build/generate-autoconf.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-output=$1
-shift
-tmp="$output.tmp.$$"
-mkdir -p "$(dirname "$output")"
-{
- echo '/* AUTO-GENERATED — DO NOT EDIT */'
- echo '#pragma once'
- while [ "$#" -gt 0 ]; do
- name=$1
- value=$2
- kind=$3
- shift 3
- if [ "$kind" = bool ]; then
- [ "$value" = y ] && echo "#define $name 1"
- else
- echo "#define $name $value"
- fi
- done
-} > "$tmp"
-if [ -e "$output" ] && cmp -s "$tmp" "$output"; then
- rm -f "$tmp"
-else
- mv -f "$tmp" "$output"
-fi
-
diff --git a/scripts/build/generate-initramfs.sh b/scripts/build/generate-initramfs.sh
deleted file mode 100755
index 194e206..0000000
--- a/scripts/build/generate-initramfs.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-generator=$1
-wrapper=$2
-output=$3
-uid=$4
-gid=$5
-source=$6
-GEN_INIT_CPIO=$generator "$wrapper" -o "$output" -u "$uid" -g "$gid" "$source"
-
diff --git a/scripts/build/link-kernel.sh b/scripts/build/link-kernel.sh
deleted file mode 100755
index 31164e7..0000000
--- a/scripts/build/link-kernel.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-output=$1
-size_tool=$2
-shift 2
-"$@"
-"$size_tool" "$output"
-
diff --git a/scripts/build/probe-toolchain.sh b/scripts/build/probe-toolchain.sh
deleted file mode 100755
index 218a821..0000000
--- a/scripts/build/probe-toolchain.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-output=$1
-cc=$2
-cxx=$3
-ld=$4
-family=$5
-target=$6
-gcc_toolchain=$7
-sysroot=$8
-ktl_include=$9
-ktl_after_include=${10}
-libc_include=${11}
-libc_after_include=${12}
-libcxx_include=${13}
-compiler_resource_include=${14}
-
-set --
-if [ "$family" = clang ]; then
- set -- "$@" "--target=$target"
- [ -z "$gcc_toolchain" ] || set -- "$@" "--gcc-toolchain=$gcc_toolchain"
- [ -z "$sysroot" ] || set -- "$@" "--sysroot=$sysroot"
-fi
-
-probe() {
- language=$1
- standard=$2
- shift 2
- compiler=$cc
- [ "$language" = c++ ] && compiler=$cxx
- printf '' | "$compiler" "$@" "-std=$standard" -x "$language" \
- -fsyntax-only - >/dev/null 2>&1
-}
-
-probe_libcxx() {
- printf '%s\n' \
- '#include <ktl/array.h>' \
- '#include <ktl/atomic.h>' \
- '#include <ktl/optional.h>' \
- '#include <ktl/span.h>' \
- '#include <ktl/string_view.h>' \
- 'constexpr ktl::array<int, 2> values{1, 2};' \
- 'static_assert(values[1] == 2);' | \
- "$cxx" "$@" -std=c++23 -ffreestanding -fno-exceptions -fno-rtti \
- -nostdinc -I include -I "$ktl_include" -I "$libc_include" \
- -isystem "$compiler_resource_include" \
- -isystem "$libcxx_include" -idirafter "$ktl_after_include" \
- -idirafter "$libc_after_include" -fsyntax-only -x c++ - >/dev/null 2>&1
-}
-
-tmp="$output.tmp.$$"
-mkdir -p "$(dirname "$output")"
-{
- echo "cc=$($cc --version | head -n 1)"
- echo "cxx=$($cxx --version | head -n 1)"
- echo "ld=$($ld --version | head -n 1)"
- echo "target=$target"
- printf 'c23='; if probe c gnu23 "$@"; then echo yes; else echo no; fi
- printf 'cxx23='; if probe c++ c++23 "$@"; then echo yes; else echo no; fi
- printf 'libcxx-headers='; if probe_libcxx "$@"; then echo yes; else echo no; fi
- printf 'fno-pie='; if probe c++ c++23 "$@" -fno-pie; then echo yes; else echo no; fi
- printf 'mcmodel-medany='; if probe c++ c++23 "$@" -mcmodel=medany; then echo yes; else echo no; fi
-} > "$tmp"
-mv -f "$tmp" "$output"
-
-grep -q '^c23=yes$' "$output"
-grep -q '^cxx23=yes$' "$output"
-grep -q '^libcxx-headers=yes$' "$output"
-grep -q '^fno-pie=yes$' "$output"
-grep -q '^mcmodel-medany=yes$' "$output"
diff --git a/scripts/build/probes/libc_headers.c b/scripts/build/probes/libc_headers.c
deleted file mode 100644
index e4bdd20..0000000
--- a/scripts/build/probes/libc_headers.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#include <assert.h>
-#include <inttypes.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-_Static_assert(sizeof(uintptr_t) == sizeof(void*), "uintptr_t must hold a pointer");
diff --git a/scripts/build/probes/libc_headers.cc b/scripts/build/probes/libc_headers.cc
deleted file mode 100644
index 1085cd3..0000000
--- a/scripts/build/probes/libc_headers.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#include <assert.h>
-#include <inttypes.h>
-#include <multi-file.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string-file.h>
-#include <string.h>
-
-static_assert(sizeof(uintptr_t) == sizeof(void*));
diff --git a/scripts/build/probes/libcxx.cc b/scripts/build/probes/libcxx.cc
deleted file mode 100644
index 8237151..0000000
--- a/scripts/build/probes/libcxx.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#include <array>
-#include <atomic>
-#include <optional>
-#include <span>
-#include <string_view>
-#include <type_traits>
-
-constexpr std::array<int, 3> kValues{1, 2, 3};
-static_assert(kValues[2] == 3);
-static_assert(std::is_same_v<std::span<const int>::element_type, const int>);
-static_assert(std::string_view{"libc++"}.size() == 6);
-
-using Optional = std::optional<unsigned long>;
-using Atomic = std::atomic<unsigned long>;
diff --git a/scripts/build/run-if-changed.sh b/scripts/build/run-if-changed.sh
deleted file mode 100755
index 6cdc7c4..0000000
--- a/scripts/build/run-if-changed.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-set -eu
-
-cmdfile=$1
-output=$2
-description=$3
-shift 3
-
-rebuild=false
-if [ ! -e "$output" ] || [ ! -e "$cmdfile" ]; then
- rebuild=true
-fi
-
-while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do
- prerequisite=$1
- shift
- if [ "$prerequisite" != FORCE ] && [ -e "$prerequisite" ] && \
- [ "$prerequisite" -nt "$output" ]; then
- rebuild=true
- fi
-done
-
-[ "$#" -gt 0 ] || { echo "run-if-changed: missing --" >&2; exit 2; }
-shift
-
-signature=$(printf '%s\0' "$@" | cksum)
-old_signature=
-if [ -e "$cmdfile" ]; then
- old_signature=$(cat "$cmdfile")
-fi
-if [ "$signature" != "$old_signature" ]; then
- rebuild=true
-fi
-
-if [ "$rebuild" = true ]; then
- printf ' %s\n' "$description"
- mkdir -p "$(dirname "$output")" "$(dirname "$cmdfile")"
- "$@"
- tmp="$cmdfile.tmp.$$"
- printf '%s\n' "$signature" > "$tmp"
- mv -f "$tmp" "$cmdfile"
-fi
-
diff --git a/scripts/build/targets.mk b/scripts/build/targets.mk
deleted file mode 100644
index 1a66379..0000000
--- a/scripts/build/targets.mk
+++ /dev/null
@@ -1,81 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (C) 2026 Richard Qin
-
-# Declarative target registry for the LumeOS build.
-#
-# Build.mk files populate target.<name>.* and append the name to targets. A
-# target name is metadata, not a Make rule, so names may contain '/' and ':'.
-
-target-kinds := \
- interface-library header-library object-library source-set \
- static-library whole-archive host-library phys-library host-tool generated \
- binary-blob kernel-test host-test product
-targets :=
-generated-actions := autoconf asm-offsets linker-script initramfs
-
-empty :=
-space := $(empty) $(empty)
-comma := ,
-
-# Convert a logical target/source name into a path-safe component.
-target-key = $(subst :,_,$(subst /,_,$(1)))
-
-# Recursively collect a target and all of its dependencies. Dependency cycles
-# are rejected separately before this is evaluated for build roots.
-target-deps = $(sort $(target.$(1).deps) $(target.$(1).public-deps) \
- $(target.$(1).private-deps) $(target.$(1).interface-deps) \
- $(target.$(1).link-deps) $(target.$(1).tool-deps) \
- $(target.$(1).generated-deps) $(target.$(1).runtime-deps) \
- $(target.$(1).order-only-deps))
-target-closure = $(strip \
- $(if $(filter $(1),$(2)),$(error target dependency cycle: $(2) -> $(1))) \
- $(1) $(foreach dep,$(call target-deps,$(1)),$(call target-closure,$(dep),$(2) $(1))))
-target-link-deps = $(sort $(target.$(1).deps) $(target.$(1).public-deps) \
- $(target.$(1).private-deps) $(target.$(1).interface-deps) \
- $(target.$(1).link-deps))
-target-link-order = $(strip $(1) $(foreach dep,$(call target-link-deps,$(1)),\
- $(call target-link-order,$(dep))))
-unique-words = $(if $(strip $(1)),$(firstword $(1)) \
- $(call unique-words,$(filter-out $(firstword $(1)),$(1))))
-
-duplicate-words = $(sort $(foreach word,$(1),\
- $(if $(word 2,$(filter $(word),$(1))),$(word))))
-all-target-sources = $(foreach target,$(targets),$(target.$(target).sources))
-duplicate-target-sources = $(call duplicate-words,$(all-target-sources))
-
-define validate-target
-$(if $(filter $(target.$(1).kind),$(target-kinds)),,$(error target '$(1)' has invalid kind '$(target.$(1).kind)'))
-$(if $(filter header-library interface-library product generated binary-blob,$(target.$(1).kind)),$(if $(strip $(target.$(1).sources)),$(error target '$(1)' of kind $(target.$(1).kind) declares sources),),)
-$(if $(filter host-tool,$(target.$(1).kind)),$(if $(word 2,$(target.$(1).sources)),$(error host-tool '$(1)' currently requires exactly one source),),)
-$(foreach src,$(target.$(1).sources),$(if $(wildcard $(src)),,$(error target '$(1)' references missing source '$(src)')))
-$(foreach dep,$(call target-deps,$(1)),$(if $(filter $(dep),$(targets)),,$(error target '$(1)' references unknown dependency '$(dep)')))
-$(foreach dep,$(call target-deps,$(1)),$(if $(strip $(target.$(dep).visibility)),\
- $(if $(filter all $(1),$(target.$(dep).visibility)),,\
- $(error target '$(1)' cannot depend on '$(dep)': visibility is '$(target.$(dep).visibility)')),))
-$(if $(filter generated,$(target.$(1).kind)),$(if $(strip $(target.$(1).outputs)),,$(error generated target '$(1)' has no outputs)),)
-$(if $(filter generated,$(target.$(1).kind)),$(if $(filter $(target.$(1).action),$(generated-actions)),,$(error generated target '$(1)' has invalid action '$(target.$(1).action)')),)
-endef
-
-define validate-targets
-$(if $(strip $(targets)),,$(error no build targets were registered))
-$(if $(filter-out $(words $(sort $(targets))),$(words $(targets))),$(error duplicate build target name),)
-$(foreach target,$(targets),$(call validate-target,$(target)))
-endef
-
-# Usage requirements are deliberately separate from link inputs. Public
-# include paths and defines propagate through deps; private values apply only
-# while compiling the target itself.
-target-public-closure = $(sort $(1) $(foreach dep,$(target.$(1).public-deps) \
- $(target.$(1).deps),$(call target-public-closure,$(dep))))
-target-public-includes = $(sort $(foreach target,$(call target-public-closure,$(1)),$(target.$(target).public-includes)))
-target-public-after-includes = $(sort $(foreach target,$(call target-public-closure,$(1)),$(target.$(target).public-after-includes)))
-target-public-defines = $(sort $(foreach target,$(call target-public-closure,$(1)),$(target.$(target).public-defines)))
-
-target-usage-roots = $(sort $(1) $(target.$(1).deps) $(target.$(1).public-deps) \
- $(target.$(1).private-deps) $(target.$(1).interface-deps))
-target-compile-includes = $(sort $(target.$(1).private-includes) \
- $(foreach root,$(call target-usage-roots,$(1)),$(call target-public-includes,$(root))))
-target-compile-after-includes = $(sort $(target.$(1).private-after-includes) \
- $(foreach root,$(call target-usage-roots,$(1)),$(call target-public-after-includes,$(root))))
-target-compile-defines = $(sort $(target.$(1).private-defines) \
- $(foreach root,$(call target-usage-roots,$(1)),$(call target-public-defines,$(root))))
diff --git a/scripts/build/tests/host_library.cc b/scripts/build/tests/host_library.cc
deleted file mode 100644
index c545815..0000000
--- a/scripts/build/tests/host_library.cc
+++ /dev/null
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-namespace lume::build::test {
-
-int HostLibrarySmokeTestSymbol() { return 0; }
-
-} // namespace lume::build::test
-
diff --git a/scripts/build/tests/host_test.cc b/scripts/build/tests/host_test.cc
deleted file mode 100644
index 6b13417..0000000
--- a/scripts/build/tests/host_test.cc
+++ /dev/null
@@ -1,7 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-namespace lume::build::test {
-int HostLibrarySmokeTestSymbol();
-}
-
-int main() { return lume::build::test::HostLibrarySmokeTestSymbol(); }
diff --git a/scripts/build/tests/phys_library.cc b/scripts/build/tests/phys_library.cc
deleted file mode 100644
index 2cf1596..0000000
--- a/scripts/build/tests/phys_library.cc
+++ /dev/null
@@ -1,5 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-extern "C" unsigned long LumePhysBuildSmoke(unsigned long value) {
- return value ^ 0x4c554d45UL;
-}
diff --git a/scripts/build/toolchain.mk b/scripts/build/toolchain.mk
deleted file mode 100644
index d244981..0000000
--- a/scripts/build/toolchain.mk
+++ /dev/null
@@ -1,130 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (C) 2026 Richard Qin
-
-# Toolchain selection:
-# make GCC + GNU ld
-# make LLVM=1 Clang + GNU ld
-# make LLVM=1 LD_TYPE=lld Clang + LLD
-
-LLVM ?= 0
-LLVM_VERSION ?= 20
-LD_TYPE ?= bfd
-LLVM_BINUTILS ?= 0
-CXX_STDLIB ?= libc++
-CXX_ABI ?= lume
-COMPILER_RUNTIME ?= compiler-default
-
-# One pinned libc++ header snapshot is shared by GCC and Clang. Platform C
-# declarations and libc++ configuration come from the Zircon libc/KTL layer,
-# not from a Linux or Fuchsia userland __config_site.
-LIBCXX_ROOT ?= third_party/libcxx
-LIBCXX_INCLUDE := $(LIBCXX_ROOT)/include/c++/v1
-KTL_INCLUDE := lib/ktl/include
-KTL_AFTER_INCLUDE := lib/ktl/include-after
-KERNEL_LIBC_INCLUDE := lib/libc/include
-KERNEL_LIBC_AFTER_INCLUDE := lib/libc/include-after
-
-ifeq ($(wildcard $(LIBCXX_INCLUDE)/__config),)
-$(error missing pinned libc++ headers under '$(LIBCXX_INCLUDE)')
-endif
-ifeq ($(wildcard $(KTL_INCLUDE)/__config_site),)
-$(error missing KTL libc++ configuration under '$(KTL_INCLUDE)')
-endif
-ifneq ($(CXX_STDLIB),libc++)
-$(error unsupported CXX_STDLIB '$(CXX_STDLIB)' (LumeOS uses its pinned libc++ headers))
-endif
-
-GCC_TOOLCHAIN ?=
-CROSS_COMPILE ?=
-
-ifeq ($(ARCH),riscv)
-TARGET_TRIPLE := riscv64-unknown-linux-gnu
-ifeq ($(strip $(GCC_TOOLCHAIN)),)
-ifneq ($(wildcard /opt/riscv64-glibc/bin/riscv64-unknown-linux-gnu-g++),)
-GCC_TOOLCHAIN := /opt/riscv64-glibc
-endif
-endif
-ifeq ($(strip $(CROSS_COMPILE)),)
-ifneq ($(strip $(GCC_TOOLCHAIN)),)
-CROSS_COMPILE := $(GCC_TOOLCHAIN)/bin/$(TARGET_TRIPLE)-
-else
-CROSS_COMPILE := $(TARGET_TRIPLE)-
-endif
-endif
-else ifeq ($(ARCH),aarch64)
-TARGET_TRIPLE := aarch64-linux-gnu
-else ifeq ($(ARCH),x86_64)
-TARGET_TRIPLE := x86_64-linux-gnu
-endif
-
-ifeq ($(strip $(CROSS_COMPILE)),)
-CROSS_COMPILE := $(TARGET_TRIPLE)-
-endif
-ifeq ($(strip $(GCC_TOOLCHAIN)),)
-GCC_TOOLCHAIN := $(patsubst %/bin/,%, $(dir $(CROSS_COMPILE)))
-endif
-
-GCC_SYSROOT := $(strip $(shell $(CROSS_COMPILE)g++ -print-sysroot 2>/dev/null))
-
-CLANG_SUFFIX := $(if $(LLVM_VERSION),-$(LLVM_VERSION),)
-CLANG ?= clang$(CLANG_SUFFIX)
-CLANGXX ?= clang++$(CLANG_SUFFIX)
-LLD ?= ld.lld$(CLANG_SUFFIX)
-
-CLANG_TARGET_FLAGS := --target=$(TARGET_TRIPLE)
-ifneq ($(strip $(GCC_TOOLCHAIN)),)
-CLANG_TARGET_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
-endif
-ifneq ($(strip $(GCC_SYSROOT)),)
-CLANG_TARGET_FLAGS += --sysroot=$(GCC_SYSROOT)
-endif
-
-ifeq ($(LLVM),1)
-CC := $(CLANG)
-CXX := $(CLANGXX)
-COMPILER_FAMILY := clang
-TOOLCHAIN_CFLAGS := $(CLANG_TARGET_FLAGS)
-TOOLCHAIN_CXXFLAGS :=
-COMPILER_RESOURCE_DIR := $(strip $(shell $(CXX) $(CLANG_TARGET_FLAGS) -print-resource-dir 2>/dev/null))
-COMPILER_RESOURCE_INCLUDE := $(COMPILER_RESOURCE_DIR)/include
-ifeq ($(LD_TYPE),lld)
-LD := $(LLD)
-LINKER_FAMILY := lld
-else
-LD := $(CROSS_COMPILE)ld
-LINKER_FAMILY := bfd
-endif
-
-else
-CC := $(CROSS_COMPILE)gcc
-CXX := $(CROSS_COMPILE)g++
-LD := $(CROSS_COMPILE)ld
-COMPILER_FAMILY := gcc
-LINKER_FAMILY := bfd
-COMPILER_RESOURCE_INCLUDE := $(strip $(shell $(CXX) -print-file-name=include 2>/dev/null))
-endif
-
-ifeq ($(wildcard $(COMPILER_RESOURCE_INCLUDE)/stddef.h),)
-$(error missing compiler resource headers under '$(COMPILER_RESOURCE_INCLUDE)')
-endif
-
-# Kernel and phys code must not observe the Linux target sysroot. Supply only
-# compiler intrinsic headers explicitly; the target graph provides the kernel
-# libc and KTL layers, followed by the pinned libc++ headers for C++.
-TOOLCHAIN_CFLAGS += -nostdinc -isystem $(COMPILER_RESOURCE_INCLUDE)
-TOOLCHAIN_CXXFLAGS += -isystem $(LIBCXX_INCLUDE)
-
-ifeq ($(LLVM_BINUTILS),1)
-AR := llvm-ar$(CLANG_SUFFIX)
-NM := llvm-nm$(CLANG_SUFFIX)
-OBJCOPY := llvm-objcopy$(CLANG_SUFFIX)
-OBJDUMP := llvm-objdump$(CLANG_SUFFIX)
-READELF := llvm-readelf$(CLANG_SUFFIX)
-else
-AR := $(CROSS_COMPILE)ar
-NM := $(CROSS_COMPILE)nm
-OBJCOPY := $(CROSS_COMPILE)objcopy
-OBJDUMP := $(CROSS_COMPILE)objdump
-READELF := $(CROSS_COMPILE)readelf
-endif
-SIZE := $(CROSS_COMPILE)size
diff --git a/scripts/build/write-compdb.py b/scripts/build/write-compdb.py
deleted file mode 100755
index 9ec5a49..0000000
--- a/scripts/build/write-compdb.py
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env python3
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-import json
-import pathlib
-import sys
-
-source = pathlib.Path(sys.argv[1])
-output = pathlib.Path(sys.argv[2])
-directory = pathlib.Path.cwd()
-entries = []
-for line in source.read_text().splitlines():
- file_name, object_name, command = line.split("\t", 2)
- entries.append(
- {
- "directory": str(directory),
- "file": file_name,
- "output": object_name,
- "command": command,
- }
- )
-output.parent.mkdir(parents=True, exist_ok=True)
-temporary = output.with_suffix(output.suffix + ".tmp")
-temporary.write_text(json.dumps(entries, indent=2) + "\n")
-temporary.replace(output)
-
diff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c
deleted file mode 100644
index 56d4dcb..0000000
--- a/scripts/dtc/libfdt/fdt.c
+++ /dev/null
@@ -1,347 +0,0 @@
-// 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"
-
-/*
- * Minimal sanity check for a read-only tree. fdt_ro_probe_() checks
- * that the given buffer contains what appears to be a flattened
- * device tree with sane information in its header.
- */
-int32_t fdt_ro_probe_(const void *fdt)
-{
- uint32_t totalsize = fdt_totalsize(fdt);
-
- if (can_assume(VALID_DTB))
- return totalsize;
-
- /* The device tree must be at an 8-byte aligned address */
- if ((uintptr_t)fdt & 7)
- return -FDT_ERR_ALIGNMENT;
-
- if (fdt_magic(fdt) == FDT_MAGIC) {
- /* Complete tree */
- if (!can_assume(LATEST)) {
- if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
- return -FDT_ERR_BADVERSION;
- if (fdt_last_comp_version(fdt) >
- FDT_LAST_SUPPORTED_VERSION)
- return -FDT_ERR_BADVERSION;
- }
- } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
- /* Unfinished sequential-write blob */
- if (!can_assume(VALID_INPUT) && fdt_size_dt_struct(fdt) == 0)
- return -FDT_ERR_BADSTATE;
- } else {
- return -FDT_ERR_BADMAGIC;
- }
-
- if (totalsize < INT32_MAX)
- return totalsize;
- else
- return -FDT_ERR_TRUNCATED;
-}
-
-static int check_off_(uint32_t hdrsize, uint32_t totalsize, uint32_t off)
-{
- return (off >= hdrsize) && (off <= totalsize);
-}
-
-static int check_block_(uint32_t hdrsize, uint32_t totalsize,
- uint32_t base, uint32_t size)
-{
- if (!check_off_(hdrsize, totalsize, base))
- return 0; /* block start out of bounds */
- if ((base + size) < base)
- return 0; /* overflow */
- if (!check_off_(hdrsize, totalsize, base + size))
- return 0; /* block end out of bounds */
- return 1;
-}
-
-size_t fdt_header_size_(uint32_t version)
-{
- if (version <= 1)
- return FDT_V1_SIZE;
- else if (version <= 2)
- return FDT_V2_SIZE;
- else if (version <= 3)
- return FDT_V3_SIZE;
- else if (version <= 16)
- return FDT_V16_SIZE;
- else
- return FDT_V17_SIZE;
-}
-
-size_t fdt_header_size(const void *fdt)
-{
- return can_assume(LATEST) ? FDT_V17_SIZE :
- fdt_header_size_(fdt_version(fdt));
-}
-
-int fdt_check_header(const void *fdt)
-{
- size_t hdrsize;
-
- /* The device tree must be at an 8-byte aligned address */
- if ((uintptr_t)fdt & 7)
- return -FDT_ERR_ALIGNMENT;
-
- if (fdt_magic(fdt) != FDT_MAGIC)
- return -FDT_ERR_BADMAGIC;
- if (!can_assume(LATEST)) {
- if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
- || (fdt_last_comp_version(fdt) >
- FDT_LAST_SUPPORTED_VERSION))
- return -FDT_ERR_BADVERSION;
- if (fdt_version(fdt) < fdt_last_comp_version(fdt))
- return -FDT_ERR_BADVERSION;
- }
- hdrsize = fdt_header_size(fdt);
- if (!can_assume(VALID_DTB)) {
- if ((fdt_totalsize(fdt) < hdrsize)
- || (fdt_totalsize(fdt) > INT_MAX))
- return -FDT_ERR_TRUNCATED;
-
- /* memrsv block must be 8 byte aligned */
- if (fdt_off_mem_rsvmap(fdt) % sizeof(uint64_t))
- return -FDT_ERR_ALIGNMENT;
-
- /* Structure block must be 4 byte aligned */
- if (fdt_off_dt_struct(fdt) % FDT_TAGSIZE)
- return -FDT_ERR_ALIGNMENT;
-
- /* Bounds check memrsv block */
- if (!check_off_(hdrsize, fdt_totalsize(fdt),
- fdt_off_mem_rsvmap(fdt)))
- return -FDT_ERR_TRUNCATED;
-
- /* Bounds check structure block */
- if (!can_assume(LATEST) && fdt_version(fdt) < 17) {
- if (!check_off_(hdrsize, fdt_totalsize(fdt),
- fdt_off_dt_struct(fdt)))
- return -FDT_ERR_TRUNCATED;
- } else {
- if (!check_block_(hdrsize, fdt_totalsize(fdt),
- fdt_off_dt_struct(fdt),
- fdt_size_dt_struct(fdt)))
- return -FDT_ERR_TRUNCATED;
- }
-
- /* Bounds check strings block */
- if (!check_block_(hdrsize, fdt_totalsize(fdt),
- fdt_off_dt_strings(fdt),
- fdt_size_dt_strings(fdt)))
- return -FDT_ERR_TRUNCATED;
- }
-
- return 0;
-}
-
-const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
-{
- unsigned int uoffset = offset;
- unsigned int absoffset = offset + fdt_off_dt_struct(fdt);
-
- if (offset < 0)
- return NULL;
-
- if (!can_assume(VALID_INPUT))
- if ((absoffset < uoffset)
- || ((absoffset + len) < absoffset)
- || (absoffset + len) > fdt_totalsize(fdt))
- return NULL;
-
- if (can_assume(LATEST) || fdt_version(fdt) >= 0x11)
- if (((uoffset + len) < uoffset)
- || ((offset + len) > fdt_size_dt_struct(fdt)))
- return NULL;
-
- return fdt_offset_ptr_(fdt, offset);
-}
-
-uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
-{
- const fdt32_t *tagp, *lenp;
- uint32_t tag, len, sum;
- int offset = startoffset;
- const char *p;
-
- *nextoffset = -FDT_ERR_TRUNCATED;
- tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);
- if (!can_assume(VALID_DTB) && !tagp)
- return FDT_END; /* premature end */
- tag = fdt32_to_cpu(*tagp);
- offset += FDT_TAGSIZE;
-
- *nextoffset = -FDT_ERR_BADSTRUCTURE;
- switch (tag) {
- case FDT_BEGIN_NODE:
- /* skip name */
- do {
- p = fdt_offset_ptr(fdt, offset++, 1);
- } while (p && (*p != '\0'));
- if (!can_assume(VALID_DTB) && !p)
- return FDT_END; /* premature end */
- break;
-
- case FDT_PROP:
- lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
- if (!can_assume(VALID_DTB) && !lenp)
- return FDT_END; /* premature end */
-
- len = fdt32_to_cpu(*lenp);
- sum = len + offset;
- if (!can_assume(VALID_DTB) &&
- (INT_MAX <= sum || sum < (uint32_t) offset))
- return FDT_END; /* premature end */
-
- /* skip-name offset, length and value */
- offset += sizeof(struct fdt_property) - FDT_TAGSIZE + len;
-
- if (!can_assume(LATEST) &&
- fdt_version(fdt) < 0x10 && len >= 8 &&
- ((offset - len) % 8) != 0)
- offset += 4;
- break;
-
- case FDT_END:
- case FDT_END_NODE:
- case FDT_NOP:
- break;
-
- default:
- return FDT_END;
- }
-
- if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset))
- return FDT_END; /* premature end */
-
- *nextoffset = FDT_TAGALIGN(offset);
- return tag;
-}
-
-int fdt_check_node_offset_(const void *fdt, int offset)
-{
- if (!can_assume(VALID_INPUT)
- && ((offset < 0) || (offset % FDT_TAGSIZE)))
- return -FDT_ERR_BADOFFSET;
-
- if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)
- return -FDT_ERR_BADOFFSET;
-
- return offset;
-}
-
-int fdt_check_prop_offset_(const void *fdt, int offset)
-{
- if (!can_assume(VALID_INPUT)
- && ((offset < 0) || (offset % FDT_TAGSIZE)))
- return -FDT_ERR_BADOFFSET;
-
- if (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)
- return -FDT_ERR_BADOFFSET;
-
- return offset;
-}
-
-int fdt_next_node(const void *fdt, int offset, int *depth)
-{
- int nextoffset = 0;
- uint32_t tag;
-
- if (offset >= 0)
- if ((nextoffset = fdt_check_node_offset_(fdt, offset)) < 0)
- return nextoffset;
-
- do {
- offset = nextoffset;
- tag = fdt_next_tag(fdt, offset, &nextoffset);
-
- switch (tag) {
- case FDT_PROP:
- case FDT_NOP:
- break;
-
- case FDT_BEGIN_NODE:
- if (depth)
- (*depth)++;
- break;
-
- case FDT_END_NODE:
- if (depth && ((--(*depth)) < 0))
- return nextoffset;
- break;
-
- case FDT_END:
- if ((nextoffset >= 0)
- || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth))
- return -FDT_ERR_NOTFOUND;
- else
- return nextoffset;
- }
- } while (tag != FDT_BEGIN_NODE);
-
- return offset;
-}
-
-int fdt_first_subnode(const void *fdt, int offset)
-{
- int depth = 0;
-
- offset = fdt_next_node(fdt, offset, &depth);
- if (offset < 0 || depth != 1)
- return -FDT_ERR_NOTFOUND;
-
- return offset;
-}
-
-int fdt_next_subnode(const void *fdt, int offset)
-{
- int depth = 1;
-
- /*
- * With respect to the parent, the depth of the next subnode will be
- * the same as the last.
- */
- do {
- offset = fdt_next_node(fdt, offset, &depth);
- if (offset < 0 || depth < 1)
- return -FDT_ERR_NOTFOUND;
- } while (depth > 1);
-
- return offset;
-}
-
-const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s,
- int slen)
-{
- const char *last = strtab + tabsize - (slen + 1);
- const char *p;
-
- for (p = strtab; p <= last; p++)
- if (memcmp(p, s, slen) == 0 && p[slen] == '\0')
- return p;
- return NULL;
-}
-
-int fdt_move(const void *fdt, void *buf, int bufsize)
-{
- if (!can_assume(VALID_INPUT) && bufsize < 0)
- return -FDT_ERR_NOSPACE;
-
- FDT_RO_PROBE(fdt);
-
- if (fdt_totalsize(fdt) > (unsigned int)bufsize)
- return -FDT_ERR_NOSPACE;
-
- memmove(buf, fdt, fdt_totalsize(fdt));
- return 0;
-}
diff --git a/scripts/dtc/libfdt/fdt.h b/scripts/dtc/libfdt/fdt.h
deleted file mode 100644
index a07abfc..0000000
--- a/scripts/dtc/libfdt/fdt.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
-#ifndef FDT_H
-#define FDT_H
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- * Copyright 2012 Kim Phillips, Freescale Semiconductor.
- */
-
-#ifndef __ASSEMBLER__
-
-struct fdt_header {
- fdt32_t magic; /* magic word FDT_MAGIC */
- fdt32_t totalsize; /* total size of DT block */
- fdt32_t off_dt_struct; /* offset to structure */
- fdt32_t off_dt_strings; /* offset to strings */
- fdt32_t off_mem_rsvmap; /* offset to memory reserve map */
- fdt32_t version; /* format version */
- fdt32_t last_comp_version; /* last compatible version */
-
- /* version 2 fields below */
- fdt32_t boot_cpuid_phys; /* Which physical CPU id we're
- booting on */
- /* version 3 fields below */
- fdt32_t size_dt_strings; /* size of the strings block */
-
- /* version 17 fields below */
- fdt32_t size_dt_struct; /* size of the structure block */
-};
-
-struct fdt_reserve_entry {
- fdt64_t address;
- fdt64_t size;
-};
-
-struct fdt_node_header {
- fdt32_t tag;
- char name[];
-};
-
-struct fdt_property {
- fdt32_t tag;
- fdt32_t len;
- fdt32_t nameoff;
- char data[];
-};
-
-#endif /* !__ASSEMBLER__ */
-
-#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */
-#define FDT_TAGSIZE sizeof(fdt32_t)
-
-#define FDT_BEGIN_NODE 0x1 /* Start node: full name */
-#define FDT_END_NODE 0x2 /* End node */
-#define FDT_PROP 0x3 /* Property: name off,
- size, content */
-#define FDT_NOP 0x4 /* nop */
-#define FDT_END 0x9
-
-#define FDT_V1_SIZE (7*sizeof(fdt32_t))
-#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))
-#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
-#define FDT_V16_SIZE FDT_V3_SIZE
-#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t))
-
-#endif /* FDT_H */
diff --git a/scripts/dtc/libfdt/fdt_addresses.c b/scripts/dtc/libfdt/fdt_addresses.c
deleted file mode 100644
index c40ba09..0000000
--- a/scripts/dtc/libfdt/fdt_addresses.c
+++ /dev/null
@@ -1,101 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
- * Copyright (C) 2018 embedded brains GmbH
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
-{
- const fdt32_t *c;
- uint32_t val;
- int len;
-
- c = fdt_getprop(fdt, nodeoffset, name, &len);
- if (!c)
- return len;
-
- if (len != sizeof(*c))
- return -FDT_ERR_BADNCELLS;
-
- val = fdt32_to_cpu(*c);
- if (val > FDT_MAX_NCELLS)
- return -FDT_ERR_BADNCELLS;
-
- return (int)val;
-}
-
-int fdt_address_cells(const void *fdt, int nodeoffset)
-{
- int val;
-
- val = fdt_cells(fdt, nodeoffset, "#address-cells");
- if (val == 0)
- return -FDT_ERR_BADNCELLS;
- if (val == -FDT_ERR_NOTFOUND)
- return 2;
- return val;
-}
-
-int fdt_size_cells(const void *fdt, int nodeoffset)
-{
- int val;
-
- val = fdt_cells(fdt, nodeoffset, "#size-cells");
- if (val == -FDT_ERR_NOTFOUND)
- return 1;
- return val;
-}
-
-/* This function assumes that [address|size]_cells is 1 or 2 */
-int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
- const char *name, uint64_t addr, uint64_t size)
-{
- int addr_cells, size_cells, ret;
- uint8_t data[sizeof(fdt64_t) * 2], *prop;
-
- ret = fdt_address_cells(fdt, parent);
- if (ret < 0)
- return ret;
- addr_cells = ret;
-
- ret = fdt_size_cells(fdt, parent);
- if (ret < 0)
- return ret;
- size_cells = ret;
-
- /* check validity of address */
- prop = data;
- if (addr_cells == 1) {
- if ((addr > UINT32_MAX) || (((uint64_t) UINT32_MAX + 1 - addr) < size))
- return -FDT_ERR_BADVALUE;
-
- fdt32_st(prop, (uint32_t)addr);
- } else if (addr_cells == 2) {
- fdt64_st(prop, addr);
- } else {
- return -FDT_ERR_BADNCELLS;
- }
-
- /* check validity of size */
- prop += addr_cells * sizeof(fdt32_t);
- if (size_cells == 1) {
- if (size > UINT32_MAX)
- return -FDT_ERR_BADVALUE;
-
- fdt32_st(prop, (uint32_t)size);
- } else if (size_cells == 2) {
- fdt64_st(prop, size);
- } else {
- return -FDT_ERR_BADNCELLS;
- }
-
- return fdt_appendprop(fdt, nodeoffset, name, data,
- (addr_cells + size_cells) * sizeof(fdt32_t));
-}
diff --git a/scripts/dtc/libfdt/fdt_empty_tree.c b/scripts/dtc/libfdt/fdt_empty_tree.c
deleted file mode 100644
index 49d54d4..0000000
--- a/scripts/dtc/libfdt/fdt_empty_tree.c
+++ /dev/null
@@ -1,38 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2012 David Gibson, IBM Corporation.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-int fdt_create_empty_tree(void *buf, int bufsize)
-{
- int err;
-
- err = fdt_create(buf, bufsize);
- if (err)
- return err;
-
- err = fdt_finish_reservemap(buf);
- if (err)
- return err;
-
- err = fdt_begin_node(buf, "");
- if (err)
- return err;
-
- err = fdt_end_node(buf);
- if (err)
- return err;
-
- err = fdt_finish(buf);
- if (err)
- return err;
-
- return fdt_open_into(buf, buf, bufsize);
-}
diff --git a/scripts/dtc/libfdt/fdt_overlay.c b/scripts/dtc/libfdt/fdt_overlay.c
deleted file mode 100644
index 51a3859..0000000
--- a/scripts/dtc/libfdt/fdt_overlay.c
+++ /dev/null
@@ -1,1101 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2016 Free Electrons
- * Copyright (C) 2016 NextThing Co.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-/**
- * overlay_get_target_phandle - retrieves the target phandle of a fragment
- * @fdto: pointer to the device tree overlay blob
- * @fragment: node offset of the fragment in the overlay
- *
- * overlay_get_target_phandle() retrieves the target phandle of an
- * overlay fragment when that fragment uses a phandle (target
- * property) instead of a path (target-path property).
- *
- * returns:
- * the phandle pointed by the target property
- * 0, if the phandle was not found
- * -1, if the phandle was malformed
- */
-static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)
-{
- const fdt32_t *val;
- int len;
-
- val = fdt_getprop(fdto, fragment, "target", &len);
- if (!val)
- return 0;
-
- if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1))
- return (uint32_t)-1;
-
- return fdt32_to_cpu(*val);
-}
-
-int fdt_overlay_target_offset(const void *fdt, const void *fdto,
- int fragment_offset, char const **pathp)
-{
- uint32_t phandle;
- const char *path = NULL;
- int path_len = 0, ret;
-
- /* Try first to do a phandle based lookup */
- phandle = overlay_get_target_phandle(fdto, fragment_offset);
- if (phandle == (uint32_t)-1)
- return -FDT_ERR_BADPHANDLE;
-
- /* no phandle, try path */
- if (!phandle) {
- /* And then a path based lookup */
- path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len);
- if (path)
- ret = fdt_path_offset(fdt, path);
- else
- ret = path_len;
- } else
- ret = fdt_node_offset_by_phandle(fdt, phandle);
-
- /*
- * If we haven't found either a target or a
- * target-path property in a node that contains a
- * __overlay__ subnode (we wouldn't be called
- * otherwise), consider it a improperly written
- * overlay
- */
- if (ret < 0 && path_len == -FDT_ERR_NOTFOUND)
- ret = -FDT_ERR_BADOVERLAY;
-
- /* return on error */
- if (ret < 0)
- return ret;
-
- /* return pointer to path (if available) */
- if (pathp)
- *pathp = path ? path : NULL;
-
- return ret;
-}
-
-/**
- * overlay_phandle_add_offset - Increases a phandle by an offset
- * @fdt: Base device tree blob
- * @node: Device tree overlay blob
- * @name: Name of the property to modify (phandle or linux,phandle)
- * @delta: offset to apply
- *
- * overlay_phandle_add_offset() increments a node phandle by a given
- * offset.
- *
- * returns:
- * 0 on success.
- * Negative error code on error
- */
-static int overlay_phandle_add_offset(void *fdt, int node,
- const char *name, uint32_t delta)
-{
- fdt32_t *valp, val;
- int len;
-
- valp = fdt_getprop_w(fdt, node, name, &len);
- if (!valp)
- return len;
-
- if (len != sizeof(val))
- return -FDT_ERR_BADPHANDLE;
-
- val = fdt32_ld(valp);
- if (val + delta < val || val + delta == (uint32_t)-1)
- return -FDT_ERR_NOPHANDLES;
-
- fdt32_st(valp, val + delta);
- return 0;
-}
-
-/**
- * overlay_adjust_node_phandles - Offsets the phandles of a node
- * @fdto: Device tree overlay blob
- * @node: Offset of the node we want to adjust
- * @delta: Offset to shift the phandles of
- *
- * overlay_adjust_node_phandles() adds a constant to all the phandles
- * of a given node. This is mainly use as part of the overlay
- * application process, when we want to update all the overlay
- * phandles to not conflict with the overlays of the base device tree.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_adjust_node_phandles(void *fdto, int node,
- uint32_t delta)
-{
- int child;
- int ret;
-
- ret = overlay_phandle_add_offset(fdto, node, "phandle", delta);
- if (ret && ret != -FDT_ERR_NOTFOUND)
- return ret;
-
- ret = overlay_phandle_add_offset(fdto, node, "linux,phandle", delta);
- if (ret && ret != -FDT_ERR_NOTFOUND)
- return ret;
-
- fdt_for_each_subnode(child, fdto, node) {
- ret = overlay_adjust_node_phandles(fdto, child, delta);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_adjust_local_phandles - Adjust the phandles of a whole overlay
- * @fdto: Device tree overlay blob
- * @delta: Offset to shift the phandles of
- *
- * overlay_adjust_local_phandles() adds a constant to all the
- * phandles of an overlay. This is mainly use as part of the overlay
- * application process, when we want to update all the overlay
- * phandles to not conflict with the overlays of the base device tree.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_adjust_local_phandles(void *fdto, uint32_t delta)
-{
- /*
- * Start adjusting the phandles from the overlay root
- */
- return overlay_adjust_node_phandles(fdto, 0, delta);
-}
-
-/**
- * overlay_update_local_node_references - Adjust the overlay references
- * @fdto: Device tree overlay blob
- * @tree_node: Node offset of the node to operate on
- * @fixup_node: Node offset of the matching local fixups node
- * @delta: Offset to shift the phandles of
- *
- * overlay_update_local_nodes_references() update the phandles
- * pointing to a node within the device tree overlay by adding a
- * constant delta.
- *
- * This is mainly used as part of a device tree application process,
- * where you want the device tree overlays phandles to not conflict
- * with the ones from the base device tree before merging them.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_update_local_node_references(void *fdto,
- int tree_node,
- int fixup_node,
- uint32_t delta)
-{
- int fixup_prop;
- int fixup_child;
- int ret;
-
- fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) {
- const fdt32_t *fixup_val;
- const char *name;
- char *tree_val;
- int fixup_len;
- int tree_len;
- int i;
-
- fixup_val = fdt_getprop_by_offset(fdto, fixup_prop,
- &name, &fixup_len);
- if (!fixup_val)
- return fixup_len;
-
- if (fixup_len % sizeof(uint32_t))
- return -FDT_ERR_BADOVERLAY;
- fixup_len /= sizeof(uint32_t);
-
- tree_val = fdt_getprop_w(fdto, tree_node, name, &tree_len);
- if (!tree_val) {
- if (tree_len == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_BADOVERLAY;
-
- return tree_len;
- }
-
- for (i = 0; i < fixup_len; i++) {
- fdt32_t *refp;
-
- refp = (fdt32_t *)(tree_val + fdt32_ld_(fixup_val + i));
-
- /*
- * phandles to fixup can be unaligned, so use
- * fdt32_{ld,st}() to read/write them.
- */
- fdt32_st(refp, fdt32_ld(refp) + delta);
- }
- }
-
- fdt_for_each_subnode(fixup_child, fdto, fixup_node) {
- const char *fixup_child_name = fdt_get_name(fdto, fixup_child,
- NULL);
- int tree_child;
-
- tree_child = fdt_subnode_offset(fdto, tree_node,
- fixup_child_name);
- if (tree_child == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_BADOVERLAY;
- if (tree_child < 0)
- return tree_child;
-
- ret = overlay_update_local_node_references(fdto,
- tree_child,
- fixup_child,
- delta);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_update_local_references - Adjust the overlay references
- * @fdto: Device tree overlay blob
- * @delta: Offset to shift the phandles of
- *
- * overlay_update_local_references() update all the phandles pointing
- * to a node within the device tree overlay by adding a constant
- * delta to not conflict with the base overlay.
- *
- * This is mainly used as part of a device tree application process,
- * where you want the device tree overlays phandles to not conflict
- * with the ones from the base device tree before merging them.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_update_local_references(void *fdto, uint32_t delta)
-{
- int fixups;
-
- fixups = fdt_path_offset(fdto, "/__local_fixups__");
- if (fixups < 0) {
- /* There's no local phandles to adjust, bail out */
- if (fixups == -FDT_ERR_NOTFOUND)
- return 0;
-
- return fixups;
- }
-
- /*
- * Update our local references from the root of the tree
- */
- return overlay_update_local_node_references(fdto, 0, fixups,
- delta);
-}
-
-/**
- * overlay_fixup_one_phandle - Set an overlay phandle to the base one
- * @fdto: Device tree overlay blob
- * @symbols_off: Node offset of the symbols node in the base device tree
- * @path: Path to a node holding a phandle in the overlay
- * @path_len: number of path characters to consider
- * @name: Name of the property holding the phandle reference in the overlay
- * @name_len: number of name characters to consider
- * @poffset: Offset within the overlay property where the phandle is stored
- * @phandle: Phandle referencing the node
- *
- * overlay_fixup_one_phandle() resolves an overlay phandle pointing to
- * a node in the base device tree.
- *
- * This is part of the device tree overlay application process, when
- * you want all the phandles in the overlay to point to the actual
- * base dt nodes.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_fixup_one_phandle(void *fdto, int symbols_off,
- const char *path, uint32_t path_len,
- const char *name, uint32_t name_len,
- int poffset, uint32_t phandle)
-{
- fdt32_t phandle_prop;
- int fixup_off;
-
- if (symbols_off < 0)
- return symbols_off;
-
- fixup_off = fdt_path_offset_namelen(fdto, path, path_len);
- if (fixup_off == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_BADOVERLAY;
- if (fixup_off < 0)
- return fixup_off;
-
- phandle_prop = cpu_to_fdt32(phandle);
- return fdt_setprop_inplace_namelen_partial(fdto, fixup_off,
- name, name_len, poffset,
- &phandle_prop,
- sizeof(phandle_prop));
-}
-
-/**
- * overlay_fixup_phandle - Set an overlay phandle to the base one
- * @fdt: Base Device Tree blob
- * @fdto: Device tree overlay blob
- * @symbols_off: Node offset of the symbols node in the base device tree
- * @property: Property offset in the overlay holding the list of fixups
- *
- * overlay_fixup_phandle() resolves all the overlay phandles pointed
- * to in a __fixups__ property, and updates them to match the phandles
- * in use in the base device tree.
- *
- * This is part of the device tree overlay application process, when
- * you want all the phandles in the overlay to point to the actual
- * base dt nodes.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
- int property)
-{
- const char *value;
- const char *label;
- int len;
- const char *symbol_path;
- int prop_len;
- int symbol_off;
- uint32_t phandle;
-
- value = fdt_getprop_by_offset(fdto, property,
- &label, &len);
- if (!value) {
- if (len == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_INTERNAL;
-
- return len;
- }
-
- symbol_path = fdt_getprop(fdt, symbols_off, label, &prop_len);
- if (!symbol_path)
- return prop_len;
-
- symbol_off = fdt_path_offset(fdt, symbol_path);
- if (symbol_off < 0)
- return symbol_off;
-
- phandle = fdt_get_phandle(fdt, symbol_off);
- if (!phandle)
- return -FDT_ERR_NOTFOUND;
-
- do {
- const char *path, *name, *fixup_end;
- const char *fixup_str = value;
- uint32_t path_len, name_len;
- uint32_t fixup_len;
- const char *sep;
- char *endptr;
- int poffset, ret;
-
- fixup_end = memchr(value, '\0', len);
- if (!fixup_end)
- return -FDT_ERR_BADOVERLAY;
- fixup_len = fixup_end - fixup_str;
-
- len -= fixup_len + 1;
- value += fixup_len + 1;
-
- path = fixup_str;
- sep = memchr(fixup_str, ':', fixup_len);
- if (!sep || *sep != ':')
- return -FDT_ERR_BADOVERLAY;
-
- path_len = sep - path;
- if (path_len == (fixup_len - 1))
- return -FDT_ERR_BADOVERLAY;
-
- fixup_len -= path_len + 1;
- name = sep + 1;
- sep = memchr(name, ':', fixup_len);
- if (!sep || *sep != ':')
- return -FDT_ERR_BADOVERLAY;
-
- name_len = sep - name;
- if (!name_len)
- return -FDT_ERR_BADOVERLAY;
-
- poffset = strtoul(sep + 1, &endptr, 10);
- if ((*endptr != '\0') || (endptr <= (sep + 1)))
- return -FDT_ERR_BADOVERLAY;
-
- ret = overlay_fixup_one_phandle(fdto, symbols_off,
- path, path_len, name, name_len,
- poffset, phandle);
- if (ret)
- return ret;
- } while (len > 0);
-
- return 0;
-}
-
-/**
- * overlay_fixup_phandles - Resolve the overlay phandles to the base
- * device tree
- * @fdt: Base Device Tree blob
- * @fdto: Device tree overlay blob
- *
- * overlay_fixup_phandles() resolves all the overlay phandles pointing
- * to nodes in the base device tree.
- *
- * This is one of the steps of the device tree overlay application
- * process, when you want all the phandles in the overlay to point to
- * the actual base dt nodes.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_fixup_phandles(void *fdt, void *fdto)
-{
- int fixups_off, symbols_off;
- int property;
-
- /* We can have overlays without any fixups */
- fixups_off = fdt_path_offset(fdto, "/__fixups__");
- if (fixups_off == -FDT_ERR_NOTFOUND)
- return 0; /* nothing to do */
- if (fixups_off < 0)
- return fixups_off;
-
- /* And base DTs without symbols */
- symbols_off = fdt_path_offset(fdt, "/__symbols__");
- if ((symbols_off < 0 && (symbols_off != -FDT_ERR_NOTFOUND)))
- return symbols_off;
-
- fdt_for_each_property_offset(property, fdto, fixups_off) {
- int ret;
-
- ret = overlay_fixup_phandle(fdt, fdto, symbols_off, property);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_adjust_local_conflicting_phandle: Changes a phandle value
- * @fdto: Device tree overlay
- * @node: The node the phandle is set for
- * @fdt_phandle: The new value for the phandle
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_adjust_local_conflicting_phandle(void *fdto, int node,
- uint32_t fdt_phandle)
-{
- const fdt32_t *php;
- int len, ret;
-
- php = fdt_getprop(fdto, node, "phandle", &len);
- if (php && len == sizeof(*php)) {
- ret = fdt_setprop_inplace_u32(fdto, node, "phandle", fdt_phandle);
- if (ret)
- return ret;
- }
-
- php = fdt_getprop(fdto, node, "linux,phandle", &len);
- if (php && len == sizeof(*php)) {
- ret = fdt_setprop_inplace_u32(fdto, node, "linux,phandle", fdt_phandle);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_update_node_conflicting_references - Recursively replace phandle values
- * @fdto: Device tree overlay blob
- * @tree_node: Node to recurse into
- * @fixup_node: Node offset of the matching local fixups node
- * @fdt_phandle: Value to replace phandles with
- * @fdto_phandle: Value to be replaced
- *
- * Replaces all phandles with value @fdto_phandle by @fdt_phandle.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_update_node_conflicting_references(void *fdto, int tree_node,
- int fixup_node,
- uint32_t fdt_phandle,
- uint32_t fdto_phandle)
-{
- int fixup_prop;
- int fixup_child;
- int ret;
-
- fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) {
- const fdt32_t *fixup_val;
- const char *name;
- char *tree_val;
- int fixup_len;
- int tree_len;
- int i;
-
- fixup_val = fdt_getprop_by_offset(fdto, fixup_prop,
- &name, &fixup_len);
- if (!fixup_val)
- return fixup_len;
-
- if (fixup_len % sizeof(uint32_t))
- return -FDT_ERR_BADOVERLAY;
- fixup_len /= sizeof(uint32_t);
-
- tree_val = fdt_getprop_w(fdto, tree_node, name, &tree_len);
- if (!tree_val) {
- if (tree_len == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_BADOVERLAY;
-
- return tree_len;
- }
-
- for (i = 0; i < fixup_len; i++) {
- fdt32_t *refp;
- uint32_t valp;
-
- refp = (fdt32_t *)(tree_val + fdt32_ld_(fixup_val + i));
- valp = fdt32_ld(refp);
-
- if (valp == fdto_phandle)
- fdt32_st(refp, fdt_phandle);
- }
- }
-
- fdt_for_each_subnode(fixup_child, fdto, fixup_node) {
- const char *fixup_child_name = fdt_get_name(fdto, fixup_child, NULL);
- int tree_child;
-
- tree_child = fdt_subnode_offset(fdto, tree_node, fixup_child_name);
-
- if (tree_child == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_BADOVERLAY;
- if (tree_child < 0)
- return tree_child;
-
- ret = overlay_update_node_conflicting_references(fdto, tree_child,
- fixup_child,
- fdt_phandle,
- fdto_phandle);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_update_local_conflicting_references - Recursively replace phandle values
- * @fdto: Device tree overlay blob
- * @fdt_phandle: Value to replace phandles with
- * @fdto_phandle: Value to be replaced
- *
- * Replaces all phandles with value @fdto_phandle by @fdt_phandle.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_update_local_conflicting_references(void *fdto,
- uint32_t fdt_phandle,
- uint32_t fdto_phandle)
-{
- int fixups;
-
- fixups = fdt_path_offset(fdto, "/__local_fixups__");
- if (fixups == -FDT_ERR_NOTFOUND)
- return 0;
- if (fixups < 0)
- return fixups;
-
- return overlay_update_node_conflicting_references(fdto, 0, fixups,
- fdt_phandle,
- fdto_phandle);
-}
-
-/**
- * overlay_prevent_phandle_overwrite_node - Helper function for overlay_prevent_phandle_overwrite
- * @fdt: Base Device tree blob
- * @fdtnode: Node in fdt that is checked for an overwrite
- * @fdto: Device tree overlay blob
- * @fdtonode: Node in fdto matching @fdtnode
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_prevent_phandle_overwrite_node(void *fdt, int fdtnode,
- void *fdto, int fdtonode)
-{
- uint32_t fdt_phandle, fdto_phandle;
- int fdtochild;
-
- fdt_phandle = fdt_get_phandle(fdt, fdtnode);
- fdto_phandle = fdt_get_phandle(fdto, fdtonode);
-
- if (fdt_phandle && fdto_phandle) {
- int ret;
-
- ret = overlay_adjust_local_conflicting_phandle(fdto, fdtonode,
- fdt_phandle);
- if (ret)
- return ret;
-
- ret = overlay_update_local_conflicting_references(fdto,
- fdt_phandle,
- fdto_phandle);
- if (ret)
- return ret;
- }
-
- fdt_for_each_subnode(fdtochild, fdto, fdtonode) {
- const char *name = fdt_get_name(fdto, fdtochild, NULL);
- int fdtchild;
- int ret;
-
- fdtchild = fdt_subnode_offset(fdt, fdtnode, name);
- if (fdtchild == -FDT_ERR_NOTFOUND)
- /*
- * no further overwrites possible here as this node is
- * new
- */
- continue;
-
- ret = overlay_prevent_phandle_overwrite_node(fdt, fdtchild,
- fdto, fdtochild);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_prevent_phandle_overwrite - Fixes overlay phandles to not overwrite base phandles
- * @fdt: Base Device Tree blob
- * @fdto: Device tree overlay blob
- *
- * Checks recursively if applying fdto overwrites phandle values in the base
- * dtb. When such a phandle is found, the fdto is changed to use the fdt's
- * phandle value to not break references in the base.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_prevent_phandle_overwrite(void *fdt, void *fdto)
-{
- int fragment;
-
- fdt_for_each_subnode(fragment, fdto, 0) {
- int overlay;
- int target;
- int ret;
-
- overlay = fdt_subnode_offset(fdto, fragment, "__overlay__");
- if (overlay == -FDT_ERR_NOTFOUND)
- continue;
-
- if (overlay < 0)
- return overlay;
-
- target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL);
- if (target == -FDT_ERR_NOTFOUND)
- /*
- * The subtree doesn't exist in the base, so nothing
- * will be overwritten.
- */
- continue;
- else if (target < 0)
- return target;
-
- ret = overlay_prevent_phandle_overwrite_node(fdt, target,
- fdto, overlay);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_apply_node - Merges a node into the base device tree
- * @fdt: Base Device Tree blob
- * @target: Node offset in the base device tree to apply the fragment to
- * @fdto: Device tree overlay blob
- * @node: Node offset in the overlay holding the changes to merge
- *
- * overlay_apply_node() merges a node into a target base device tree
- * node pointed.
- *
- * This is part of the final step in the device tree overlay
- * application process, when all the phandles have been adjusted and
- * resolved and you just have to merge overlay into the base device
- * tree.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_apply_node(void *fdt, int target,
- void *fdto, int node)
-{
- int property;
- int subnode;
-
- fdt_for_each_property_offset(property, fdto, node) {
- const char *name;
- const void *prop;
- int prop_len;
- int ret;
-
- prop = fdt_getprop_by_offset(fdto, property, &name,
- &prop_len);
- if (prop_len == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_INTERNAL;
- if (prop_len < 0)
- return prop_len;
-
- ret = fdt_setprop(fdt, target, name, prop, prop_len);
- if (ret)
- return ret;
- }
-
- fdt_for_each_subnode(subnode, fdto, node) {
- const char *name = fdt_get_name(fdto, subnode, NULL);
- int nnode;
- int ret;
-
- nnode = fdt_add_subnode(fdt, target, name);
- if (nnode == -FDT_ERR_EXISTS) {
- nnode = fdt_subnode_offset(fdt, target, name);
- if (nnode == -FDT_ERR_NOTFOUND)
- return -FDT_ERR_INTERNAL;
- }
-
- if (nnode < 0)
- return nnode;
-
- ret = overlay_apply_node(fdt, nnode, fdto, subnode);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-/**
- * overlay_merge - Merge an overlay into its base device tree
- * @fdt: Base Device Tree blob
- * @fdto: Device tree overlay blob
- *
- * overlay_merge() merges an overlay into its base device tree.
- *
- * This is the next to last step in the device tree overlay application
- * process, when all the phandles have been adjusted and resolved and
- * you just have to merge overlay into the base device tree.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_merge(void *fdt, void *fdto)
-{
- int fragment;
-
- fdt_for_each_subnode(fragment, fdto, 0) {
- int overlay;
- int target;
- int ret;
-
- /*
- * Each fragments will have an __overlay__ node. If
- * they don't, it's not supposed to be merged
- */
- overlay = fdt_subnode_offset(fdto, fragment, "__overlay__");
- if (overlay == -FDT_ERR_NOTFOUND)
- continue;
-
- if (overlay < 0)
- return overlay;
-
- target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL);
- if (target < 0)
- return target;
-
- ret = overlay_apply_node(fdt, target, fdto, overlay);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-static int get_path_len(const void *fdt, int nodeoffset)
-{
- int len = 0, namelen;
- const char *name;
-
- FDT_RO_PROBE(fdt);
-
- for (;;) {
- name = fdt_get_name(fdt, nodeoffset, &namelen);
- if (!name)
- return namelen;
-
- /* root? we're done */
- if (namelen == 0)
- break;
-
- nodeoffset = fdt_parent_offset(fdt, nodeoffset);
- if (nodeoffset < 0)
- return nodeoffset;
- len += namelen + 1;
- }
-
- /* in case of root pretend it's "/" */
- if (len == 0)
- len++;
- return len;
-}
-
-/**
- * overlay_symbol_update - Update the symbols of base tree after a merge
- * @fdt: Base Device Tree blob
- * @fdto: Device tree overlay blob
- *
- * overlay_symbol_update() updates the symbols of the base tree with the
- * symbols of the applied overlay
- *
- * This is the last step in the device tree overlay application
- * process, allowing the reference of overlay symbols by subsequent
- * overlay operations.
- *
- * returns:
- * 0 on success
- * Negative error code on failure
- */
-static int overlay_symbol_update(void *fdt, void *fdto)
-{
- int root_sym, ov_sym, prop, path_len, fragment, target;
- int len, frag_name_len, ret, rel_path_len;
- const char *s, *e;
- const char *path;
- const char *name;
- const char *frag_name;
- const char *rel_path;
- const char *target_path;
- char *buf;
- void *p;
-
- ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__");
-
- /* if no overlay symbols exist no problem */
- if (ov_sym < 0)
- return 0;
-
- root_sym = fdt_subnode_offset(fdt, 0, "__symbols__");
-
- /* it no root symbols exist we should create them */
- if (root_sym == -FDT_ERR_NOTFOUND)
- root_sym = fdt_add_subnode(fdt, 0, "__symbols__");
-
- /* any error is fatal now */
- if (root_sym < 0)
- return root_sym;
-
- /* iterate over each overlay symbol */
- fdt_for_each_property_offset(prop, fdto, ov_sym) {
- path = fdt_getprop_by_offset(fdto, prop, &name, &path_len);
- if (!path)
- return path_len;
-
- /* verify it's a string property (terminated by a single \0) */
- if (path_len < 1 || memchr(path, '\0', path_len) != &path[path_len - 1])
- return -FDT_ERR_BADVALUE;
-
- /* keep end marker to avoid strlen() */
- e = path + path_len;
-
- if (*path != '/')
- return -FDT_ERR_BADVALUE;
-
- /* get fragment name first */
- s = strchr(path + 1, '/');
- if (!s) {
- /* Symbol refers to something that won't end
- * up in the target tree */
- continue;
- }
-
- frag_name = path + 1;
- frag_name_len = s - path - 1;
-
- /* verify format; safe since "s" lies in \0 terminated prop */
- len = sizeof("/__overlay__/") - 1;
- if ((e - s) > len && (memcmp(s, "/__overlay__/", len) == 0)) {
- /* /<fragment-name>/__overlay__/<relative-subnode-path> */
- rel_path = s + len;
- rel_path_len = e - rel_path - 1;
- } else if ((e - s) == len
- && (memcmp(s, "/__overlay__", len - 1) == 0)) {
- /* /<fragment-name>/__overlay__ */
- rel_path = "";
- rel_path_len = 0;
- } else {
- /* Symbol refers to something that won't end
- * up in the target tree */
- continue;
- }
-
- /* find the fragment index in which the symbol lies */
- ret = fdt_subnode_offset_namelen(fdto, 0, frag_name,
- frag_name_len);
- /* not found? */
- if (ret < 0)
- return -FDT_ERR_BADOVERLAY;
- fragment = ret;
-
- /* an __overlay__ subnode must exist */
- ret = fdt_subnode_offset(fdto, fragment, "__overlay__");
- if (ret < 0)
- return -FDT_ERR_BADOVERLAY;
-
- /* get the target of the fragment */
- ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
- if (ret < 0)
- return ret;
- target = ret;
-
- /* if we have a target path use */
- if (!target_path) {
- ret = get_path_len(fdt, target);
- if (ret < 0)
- return ret;
- len = ret;
- } else {
- len = strlen(target_path);
- }
-
- ret = fdt_setprop_placeholder(fdt, root_sym, name,
- len + (len > 1) + rel_path_len + 1, &p);
- if (ret < 0)
- return ret;
-
- if (!target_path) {
- /* again in case setprop_placeholder changed it */
- ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
- if (ret < 0)
- return ret;
- target = ret;
- }
-
- buf = p;
- if (len > 1) { /* target is not root */
- if (!target_path) {
- ret = fdt_get_path(fdt, target, buf, len + 1);
- if (ret < 0)
- return ret;
- } else
- memcpy(buf, target_path, len + 1);
-
- } else
- len--;
-
- buf[len] = '/';
- memcpy(buf + len + 1, rel_path, rel_path_len);
- buf[len + 1 + rel_path_len] = '\0';
- }
-
- return 0;
-}
-
-int fdt_overlay_apply(void *fdt, void *fdto)
-{
- uint32_t delta;
- int ret;
-
- FDT_RO_PROBE(fdt);
- FDT_RO_PROBE(fdto);
-
- ret = fdt_find_max_phandle(fdt, &delta);
- if (ret)
- goto err;
-
- /* Increase all phandles in the fdto by delta */
- ret = overlay_adjust_local_phandles(fdto, delta);
- if (ret)
- goto err;
-
- /* Adapt the phandle values in fdto to the above increase */
- ret = overlay_update_local_references(fdto, delta);
- if (ret)
- goto err;
-
- /* Update fdto's phandles using symbols from fdt */
- ret = overlay_fixup_phandles(fdt, fdto);
- if (ret)
- goto err;
-
- /* Don't overwrite phandles in fdt */
- ret = overlay_prevent_phandle_overwrite(fdt, fdto);
- if (ret)
- goto err;
-
- ret = overlay_merge(fdt, fdto);
- if (ret)
- goto err;
-
- ret = overlay_symbol_update(fdt, fdto);
- if (ret)
- goto err;
-
- /*
- * The overlay has been damaged, erase its magic.
- */
- fdt_set_magic(fdto, ~0);
-
- return 0;
-
-err:
- /*
- * The overlay might have been damaged, erase its magic.
- */
- fdt_set_magic(fdto, ~0);
-
- /*
- * The base device tree might have been damaged, erase its
- * magic.
- */
- fdt_set_magic(fdt, ~0);
-
- return ret;
-}
diff --git a/scripts/dtc/libfdt/fdt_ro.c b/scripts/dtc/libfdt/fdt_ro.c
deleted file mode 100644
index 63494fb..0000000
--- a/scripts/dtc/libfdt/fdt_ro.c
+++ /dev/null
@@ -1,888 +0,0 @@
-// 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_nodename_eq_(const void *fdt, int offset,
- const char *s, int len)
-{
- int olen;
- const char *p = fdt_get_name(fdt, offset, &olen);
-
- if (!p || olen < len)
- /* short match */
- return 0;
-
- if (memcmp(p, s, len) != 0)
- return 0;
-
- if (p[len] == '\0')
- return 1;
- else if (!memchr(s, '@', len) && (p[len] == '@'))
- return 1;
- else
- return 0;
-}
-
-const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
-{
- int32_t totalsize;
- uint32_t absoffset;
- size_t len;
- int err;
- const char *s, *n;
-
- if (can_assume(VALID_INPUT)) {
- s = (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
-
- if (lenp)
- *lenp = strlen(s);
- return s;
- }
- totalsize = fdt_ro_probe_(fdt);
- err = totalsize;
- if (totalsize < 0)
- goto fail;
-
- err = -FDT_ERR_BADOFFSET;
- absoffset = stroffset + fdt_off_dt_strings(fdt);
- if (absoffset >= (unsigned)totalsize)
- goto fail;
- len = totalsize - absoffset;
-
- if (fdt_magic(fdt) == FDT_MAGIC) {
- if (stroffset < 0)
- goto fail;
- if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
- if ((unsigned)stroffset >= fdt_size_dt_strings(fdt))
- goto fail;
- if ((fdt_size_dt_strings(fdt) - stroffset) < len)
- len = fdt_size_dt_strings(fdt) - stroffset;
- }
- } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
- unsigned int sw_stroffset = -stroffset;
-
- if ((stroffset >= 0) ||
- (sw_stroffset > fdt_size_dt_strings(fdt)))
- goto fail;
- if (sw_stroffset < len)
- len = sw_stroffset;
- } else {
- err = -FDT_ERR_INTERNAL;
- goto fail;
- }
-
- s = (const char *)fdt + absoffset;
- n = memchr(s, '\0', len);
- if (!n) {
- /* missing terminating NULL */
- err = -FDT_ERR_TRUNCATED;
- goto fail;
- }
-
- if (lenp)
- *lenp = n - s;
- return s;
-
-fail:
- if (lenp)
- *lenp = err;
- return NULL;
-}
-
-const char *fdt_string(const void *fdt, int stroffset)
-{
- return fdt_get_string(fdt, stroffset, NULL);
-}
-
-static int fdt_string_eq_(const void *fdt, int stroffset,
- const char *s, int len)
-{
- int slen;
- const char *p = fdt_get_string(fdt, stroffset, &slen);
-
- return p && (slen == len) && (memcmp(p, s, len) == 0);
-}
-
-int fdt_find_max_phandle(const void *fdt, uint32_t *phandle)
-{
- uint32_t max = 0;
- int offset = -1;
-
- while (true) {
- uint32_t value;
-
- offset = fdt_next_node(fdt, offset, NULL);
- if (offset < 0) {
- if (offset == -FDT_ERR_NOTFOUND)
- break;
-
- return offset;
- }
-
- value = fdt_get_phandle(fdt, offset);
-
- if (value > max)
- max = value;
- }
-
- if (phandle)
- *phandle = max;
-
- return 0;
-}
-
-int fdt_generate_phandle(const void *fdt, uint32_t *phandle)
-{
- uint32_t max;
- int err;
-
- err = fdt_find_max_phandle(fdt, &max);
- if (err < 0)
- return err;
-
- if (max == FDT_MAX_PHANDLE)
- return -FDT_ERR_NOPHANDLES;
-
- if (phandle)
- *phandle = max + 1;
-
- return 0;
-}
-
-static const struct fdt_reserve_entry *fdt_mem_rsv(const void *fdt, int n)
-{
- unsigned int offset = n * sizeof(struct fdt_reserve_entry);
- unsigned int absoffset = fdt_off_mem_rsvmap(fdt) + offset;
-
- if (!can_assume(VALID_INPUT)) {
- if (absoffset < fdt_off_mem_rsvmap(fdt))
- return NULL;
- if (absoffset > fdt_totalsize(fdt) -
- sizeof(struct fdt_reserve_entry))
- return NULL;
- }
- return fdt_mem_rsv_(fdt, n);
-}
-
-int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
-{
- const struct fdt_reserve_entry *re;
-
- FDT_RO_PROBE(fdt);
- re = fdt_mem_rsv(fdt, n);
- if (!can_assume(VALID_INPUT) && !re)
- return -FDT_ERR_BADOFFSET;
-
- *address = fdt64_ld_(&re->address);
- *size = fdt64_ld_(&re->size);
- return 0;
-}
-
-int fdt_num_mem_rsv(const void *fdt)
-{
- int i;
- const struct fdt_reserve_entry *re;
-
- for (i = 0; (re = fdt_mem_rsv(fdt, i)) != NULL; i++) {
- if (fdt64_ld_(&re->size) == 0)
- return i;
- }
- return -FDT_ERR_TRUNCATED;
-}
-
-static int nextprop_(const void *fdt, int offset)
-{
- uint32_t tag;
- int nextoffset;
-
- do {
- tag = fdt_next_tag(fdt, offset, &nextoffset);
-
- switch (tag) {
- case FDT_END:
- if (nextoffset >= 0)
- return -FDT_ERR_BADSTRUCTURE;
- else
- return nextoffset;
-
- case FDT_PROP:
- return offset;
- }
- offset = nextoffset;
- } while (tag == FDT_NOP);
-
- return -FDT_ERR_NOTFOUND;
-}
-
-int fdt_subnode_offset_namelen(const void *fdt, int offset,
- const char *name, int namelen)
-{
- int depth;
-
- FDT_RO_PROBE(fdt);
-
- for (depth = 0;
- (offset >= 0) && (depth >= 0);
- offset = fdt_next_node(fdt, offset, &depth))
- if ((depth == 1)
- && fdt_nodename_eq_(fdt, offset, name, namelen))
- return offset;
-
- if (depth < 0)
- return -FDT_ERR_NOTFOUND;
- return offset; /* error */
-}
-
-int fdt_subnode_offset(const void *fdt, int parentoffset,
- const char *name)
-{
- return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));
-}
-
-int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
-{
- const char *end = path + namelen;
- const char *p = path;
- int offset = 0;
-
- FDT_RO_PROBE(fdt);
-
- if (!can_assume(VALID_INPUT) && namelen <= 0)
- return -FDT_ERR_BADPATH;
-
- /* see if we have an alias */
- if (*path != '/') {
- const char *q = memchr(path, '/', end - p);
-
- if (!q)
- q = end;
-
- p = fdt_get_alias_namelen(fdt, p, q - p);
- if (!p)
- return -FDT_ERR_BADPATH;
- offset = fdt_path_offset(fdt, p);
-
- p = q;
- }
-
- while (p < end) {
- const char *q;
-
- while (*p == '/') {
- p++;
- if (p == end)
- return offset;
- }
- q = memchr(p, '/', end - p);
- if (! q)
- q = end;
-
- offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
- if (offset < 0)
- return offset;
-
- p = q;
- }
-
- return offset;
-}
-
-int fdt_path_offset(const void *fdt, const char *path)
-{
- return fdt_path_offset_namelen(fdt, path, strlen(path));
-}
-
-const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
-{
- const struct fdt_node_header *nh = fdt_offset_ptr_(fdt, nodeoffset);
- const char *nameptr;
- int err;
-
- if (!can_assume(VALID_DTB) && (((err = fdt_ro_probe_(fdt)) < 0)
- || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0)))
- goto fail;
-
- nameptr = nh->name;
-
- if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
- /*
- * For old FDT versions, match the naming conventions of V16:
- * give only the leaf name (after all /). The actual tree
- * contents are loosely checked.
- */
- const char *leaf;
- leaf = strrchr(nameptr, '/');
- if (leaf == NULL) {
- err = -FDT_ERR_BADSTRUCTURE;
- goto fail;
- }
- nameptr = leaf+1;
- }
-
- if (len)
- *len = strlen(nameptr);
-
- return nameptr;
-
- fail:
- if (len)
- *len = err;
- return NULL;
-}
-
-int fdt_first_property_offset(const void *fdt, int nodeoffset)
-{
- int offset;
-
- if ((offset = fdt_check_node_offset_(fdt, nodeoffset)) < 0)
- return offset;
-
- return nextprop_(fdt, offset);
-}
-
-int fdt_next_property_offset(const void *fdt, int offset)
-{
- if ((offset = fdt_check_prop_offset_(fdt, offset)) < 0)
- return offset;
-
- return nextprop_(fdt, offset);
-}
-
-static const struct fdt_property *fdt_get_property_by_offset_(const void *fdt,
- int offset,
- int *lenp)
-{
- int err;
- const struct fdt_property *prop;
-
- if (!can_assume(VALID_INPUT) &&
- (err = fdt_check_prop_offset_(fdt, offset)) < 0) {
- if (lenp)
- *lenp = err;
- return NULL;
- }
-
- prop = fdt_offset_ptr_(fdt, offset);
-
- if (lenp)
- *lenp = fdt32_ld_(&prop->len);
-
- return prop;
-}
-
-const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
- int offset,
- int *lenp)
-{
- /* Prior to version 16, properties may need realignment
- * and this API does not work. fdt_getprop_*() will, however. */
-
- if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
- if (lenp)
- *lenp = -FDT_ERR_BADVERSION;
- return NULL;
- }
-
- return fdt_get_property_by_offset_(fdt, offset, lenp);
-}
-
-static const struct fdt_property *fdt_get_property_namelen_(const void *fdt,
- int offset,
- const char *name,
- int namelen,
- int *lenp,
- int *poffset)
-{
- for (offset = fdt_first_property_offset(fdt, offset);
- (offset >= 0);
- (offset = fdt_next_property_offset(fdt, offset))) {
- const struct fdt_property *prop;
-
- prop = fdt_get_property_by_offset_(fdt, offset, lenp);
- if (!can_assume(LIBFDT_FLAWLESS) && !prop) {
- offset = -FDT_ERR_INTERNAL;
- break;
- }
- if (fdt_string_eq_(fdt, fdt32_ld_(&prop->nameoff),
- name, namelen)) {
- if (poffset)
- *poffset = offset;
- return prop;
- }
- }
-
- if (lenp)
- *lenp = offset;
- return NULL;
-}
-
-
-const struct fdt_property *fdt_get_property_namelen(const void *fdt,
- int offset,
- const char *name,
- int namelen, int *lenp)
-{
- /* Prior to version 16, properties may need realignment
- * and this API does not work. fdt_getprop_*() will, however. */
- if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
- if (lenp)
- *lenp = -FDT_ERR_BADVERSION;
- return NULL;
- }
-
- return fdt_get_property_namelen_(fdt, offset, name, namelen, lenp,
- NULL);
-}
-
-
-const struct fdt_property *fdt_get_property(const void *fdt,
- int nodeoffset,
- const char *name, int *lenp)
-{
- return fdt_get_property_namelen(fdt, nodeoffset, name,
- strlen(name), lenp);
-}
-
-const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
- const char *name, int namelen, int *lenp)
-{
- int poffset;
- const struct fdt_property *prop;
-
- prop = fdt_get_property_namelen_(fdt, nodeoffset, name, namelen, lenp,
- &poffset);
- if (!prop)
- return NULL;
-
- /* Handle realignment */
- if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 &&
- (poffset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8)
- return prop->data + 4;
- return prop->data;
-}
-
-const void *fdt_getprop_by_offset(const void *fdt, int offset,
- const char **namep, int *lenp)
-{
- const struct fdt_property *prop;
-
- prop = fdt_get_property_by_offset_(fdt, offset, lenp);
- if (!prop)
- return NULL;
- if (namep) {
- const char *name;
- int namelen;
-
- if (!can_assume(VALID_INPUT)) {
- name = fdt_get_string(fdt, fdt32_ld_(&prop->nameoff),
- &namelen);
- *namep = name;
- if (!name) {
- if (lenp)
- *lenp = namelen;
- return NULL;
- }
- } else {
- *namep = fdt_string(fdt, fdt32_ld_(&prop->nameoff));
- }
- }
-
- /* Handle realignment */
- if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 &&
- (offset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8)
- return prop->data + 4;
- return prop->data;
-}
-
-const void *fdt_getprop(const void *fdt, int nodeoffset,
- const char *name, int *lenp)
-{
- return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp);
-}
-
-uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
-{
- const fdt32_t *php;
- int len;
-
- /* FIXME: This is a bit sub-optimal, since we potentially scan
- * over all the properties twice. */
- php = fdt_getprop(fdt, nodeoffset, "phandle", &len);
- if (!php || (len != sizeof(*php))) {
- php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len);
- if (!php || (len != sizeof(*php)))
- return 0;
- }
-
- return fdt32_ld_(php);
-}
-
-static const void *fdt_path_getprop_namelen(const void *fdt, const char *path,
- const char *propname, int propnamelen,
- int *lenp)
-{
- int offset = fdt_path_offset(fdt, path);
-
- if (offset < 0)
- return NULL;
-
- return fdt_getprop_namelen(fdt, offset, propname, propnamelen, lenp);
-}
-
-const char *fdt_get_alias_namelen(const void *fdt,
- const char *name, int namelen)
-{
- int len;
- const char *alias;
-
- alias = fdt_path_getprop_namelen(fdt, "/aliases", name, namelen, &len);
-
- if (!can_assume(VALID_DTB) &&
- !(alias && len > 0 && alias[len - 1] == '\0' && *alias == '/'))
- return NULL;
-
- return alias;
-}
-
-const char *fdt_get_alias(const void *fdt, const char *name)
-{
- return fdt_get_alias_namelen(fdt, name, strlen(name));
-}
-
-const char *fdt_get_symbol_namelen(const void *fdt,
- const char *name, int namelen)
-{
- return fdt_path_getprop_namelen(fdt, "/__symbols__", name, namelen, NULL);
-}
-
-const char *fdt_get_symbol(const void *fdt, const char *name)
-{
- return fdt_get_symbol_namelen(fdt, name, strlen(name));
-}
-
-int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
-{
- int pdepth = 0, p = 0;
- int offset, depth, namelen;
- const char *name;
-
- FDT_RO_PROBE(fdt);
-
- if (buflen < 2)
- return -FDT_ERR_NOSPACE;
-
- for (offset = 0, depth = 0;
- (offset >= 0) && (offset <= nodeoffset);
- offset = fdt_next_node(fdt, offset, &depth)) {
- while (pdepth > depth) {
- do {
- p--;
- } while (buf[p-1] != '/');
- pdepth--;
- }
-
- if (pdepth >= depth) {
- name = fdt_get_name(fdt, offset, &namelen);
- if (!name)
- return namelen;
- if ((p + namelen + 1) <= buflen) {
- memcpy(buf + p, name, namelen);
- p += namelen;
- buf[p++] = '/';
- pdepth++;
- }
- }
-
- if (offset == nodeoffset) {
- if (pdepth < (depth + 1))
- return -FDT_ERR_NOSPACE;
-
- if (p > 1) /* special case so that root path is "/", not "" */
- p--;
- buf[p] = '\0';
- return 0;
- }
- }
-
- if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
- return -FDT_ERR_BADOFFSET;
- else if (offset == -FDT_ERR_BADOFFSET)
- return -FDT_ERR_BADSTRUCTURE;
-
- return offset; /* error from fdt_next_node() */
-}
-
-int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
- int supernodedepth, int *nodedepth)
-{
- int offset, depth;
- int supernodeoffset = -FDT_ERR_INTERNAL;
-
- FDT_RO_PROBE(fdt);
-
- if (supernodedepth < 0)
- return -FDT_ERR_NOTFOUND;
-
- for (offset = 0, depth = 0;
- (offset >= 0) && (offset <= nodeoffset);
- offset = fdt_next_node(fdt, offset, &depth)) {
- if (depth == supernodedepth)
- supernodeoffset = offset;
-
- if (offset == nodeoffset) {
- if (nodedepth)
- *nodedepth = depth;
-
- if (supernodedepth > depth)
- return -FDT_ERR_NOTFOUND;
- else
- return supernodeoffset;
- }
- }
-
- if (!can_assume(VALID_INPUT)) {
- if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
- return -FDT_ERR_BADOFFSET;
- else if (offset == -FDT_ERR_BADOFFSET)
- return -FDT_ERR_BADSTRUCTURE;
- }
-
- return offset; /* error from fdt_next_node() */
-}
-
-int fdt_node_depth(const void *fdt, int nodeoffset)
-{
- int nodedepth;
- int err;
-
- err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth);
- if (err)
- return (can_assume(LIBFDT_FLAWLESS) || err < 0) ? err :
- -FDT_ERR_INTERNAL;
- return nodedepth;
-}
-
-int fdt_parent_offset(const void *fdt, int nodeoffset)
-{
- int nodedepth = fdt_node_depth(fdt, nodeoffset);
-
- if (nodedepth < 0)
- return nodedepth;
- return fdt_supernode_atdepth_offset(fdt, nodeoffset,
- nodedepth - 1, NULL);
-}
-
-int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
- const char *propname,
- const void *propval, int proplen)
-{
- int offset;
- const void *val;
- int len;
-
- FDT_RO_PROBE(fdt);
-
- /* FIXME: The algorithm here is pretty horrible: we scan each
- * property of a node in fdt_getprop(), then if that didn't
- * find what we want, we scan over them again making our way
- * to the next node. Still it's the easiest to implement
- * approach; performance can come later. */
- for (offset = fdt_next_node(fdt, startoffset, NULL);
- offset >= 0;
- offset = fdt_next_node(fdt, offset, NULL)) {
- val = fdt_getprop(fdt, offset, propname, &len);
- if (val && (len == proplen)
- && (memcmp(val, propval, len) == 0))
- return offset;
- }
-
- return offset; /* error from fdt_next_node() */
-}
-
-int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
-{
- int offset;
-
- if ((phandle == 0) || (phandle == ~0U))
- return -FDT_ERR_BADPHANDLE;
-
- FDT_RO_PROBE(fdt);
-
- /* FIXME: The algorithm here is pretty horrible: we
- * potentially scan each property of a node in
- * fdt_get_phandle(), then if that didn't find what
- * we want, we scan over them again making our way to the next
- * node. Still it's the easiest to implement approach;
- * performance can come later. */
- for (offset = fdt_next_node(fdt, -1, NULL);
- offset >= 0;
- offset = fdt_next_node(fdt, offset, NULL)) {
- if (fdt_get_phandle(fdt, offset) == phandle)
- return offset;
- }
-
- return offset; /* error from fdt_next_node() */
-}
-
-int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
-{
- int len = strlen(str);
- const char *p;
-
- while (listlen >= len) {
- if (memcmp(str, strlist, len+1) == 0)
- return 1;
- p = memchr(strlist, '\0', listlen);
- if (!p)
- return 0; /* malformed strlist.. */
- listlen -= (p-strlist) + 1;
- strlist = p + 1;
- }
- return 0;
-}
-
-int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)
-{
- const char *list, *end;
- int length, count = 0;
-
- list = fdt_getprop(fdt, nodeoffset, property, &length);
- if (!list)
- return length;
-
- end = list + length;
-
- while (list < end) {
- length = strnlen(list, end - list) + 1;
-
- /* Abort if the last string isn't properly NUL-terminated. */
- if (list + length > end)
- return -FDT_ERR_BADVALUE;
-
- list += length;
- count++;
- }
-
- return count;
-}
-
-int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
- const char *string)
-{
- int length, len, idx = 0;
- const char *list, *end;
-
- list = fdt_getprop(fdt, nodeoffset, property, &length);
- if (!list)
- return length;
-
- len = strlen(string) + 1;
- end = list + length;
-
- while (list < end) {
- length = strnlen(list, end - list) + 1;
-
- /* Abort if the last string isn't properly NUL-terminated. */
- if (list + length > end)
- return -FDT_ERR_BADVALUE;
-
- if (length == len && memcmp(list, string, length) == 0)
- return idx;
-
- list += length;
- idx++;
- }
-
- return -FDT_ERR_NOTFOUND;
-}
-
-const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
- const char *property, int idx,
- int *lenp)
-{
- const char *list, *end;
- int length;
-
- list = fdt_getprop(fdt, nodeoffset, property, &length);
- if (!list) {
- if (lenp)
- *lenp = length;
-
- return NULL;
- }
-
- end = list + length;
-
- while (list < end) {
- length = strnlen(list, end - list) + 1;
-
- /* Abort if the last string isn't properly NUL-terminated. */
- if (list + length > end) {
- if (lenp)
- *lenp = -FDT_ERR_BADVALUE;
-
- return NULL;
- }
-
- if (idx == 0) {
- if (lenp)
- *lenp = length - 1;
-
- return list;
- }
-
- list += length;
- idx--;
- }
-
- if (lenp)
- *lenp = -FDT_ERR_NOTFOUND;
-
- return NULL;
-}
-
-int fdt_node_check_compatible(const void *fdt, int nodeoffset,
- const char *compatible)
-{
- const void *prop;
- int len;
-
- prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
- if (!prop)
- return len;
-
- return !fdt_stringlist_contains(prop, len, compatible);
-}
-
-int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
- const char *compatible)
-{
- int offset, err;
-
- FDT_RO_PROBE(fdt);
-
- /* FIXME: The algorithm here is pretty horrible: we scan each
- * property of a node in fdt_node_check_compatible(), then if
- * that didn't find what we want, we scan over them again
- * making our way to the next node. Still it's the easiest to
- * implement approach; performance can come later. */
- for (offset = fdt_next_node(fdt, startoffset, NULL);
- offset >= 0;
- offset = fdt_next_node(fdt, offset, NULL)) {
- err = fdt_node_check_compatible(fdt, offset, compatible);
- if ((err < 0) && (err != -FDT_ERR_NOTFOUND))
- return err;
- else if (err == 0)
- return offset;
- }
-
- return offset; /* error from fdt_next_node() */
-}
diff --git a/scripts/dtc/libfdt/fdt_rw.c b/scripts/dtc/libfdt/fdt_rw.c
deleted file mode 100644
index 90ea14e..0000000
--- a/scripts/dtc/libfdt/fdt_rw.c
+++ /dev/null
@@ -1,512 +0,0 @@
-// 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)
-{
- int delta = newlen - oldlen;
- int err;
-
- if ((err = fdt_splice_(fdt, p, oldlen, newlen)))
- return err;
-
- fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta);
- fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);
- return 0;
-}
-
-/* Must only be used to roll back in case of error */
-static void fdt_del_last_string_(void *fdt, const char *s)
-{
- int newlen = strlen(s) + 1;
-
- fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) - newlen);
-}
-
-static int fdt_splice_string_(void *fdt, int newlen)
-{
- void *p = (char *)fdt
- + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
- int err;
-
- if ((err = fdt_splice_(fdt, p, 0, newlen)))
- return err;
-
- fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen);
- return 0;
-}
-
-/**
- * fdt_find_add_string_() - Find or allocate a string
- *
- * @fdt: pointer to the device tree to check/adjust
- * @s: string to find/add
- * @allocated: Set to 0 if the string was found, 1 if not found and so
- * allocated. Ignored if can_assume(NO_ROLLBACK)
- * @return offset of string in the string table (whether found or added)
- */
-static int fdt_find_add_string_(void *fdt, const char *s, int slen,
- int *allocated)
-{
- char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
- const char *p;
- char *new;
- int err;
-
- if (!can_assume(NO_ROLLBACK))
- *allocated = 0;
-
- p = fdt_find_string_len_(strtab, fdt_size_dt_strings(fdt), s, slen);
- if (p)
- /* found it */
- return (p - strtab);
-
- new = strtab + fdt_size_dt_strings(fdt);
- err = fdt_splice_string_(fdt, slen + 1);
- if (err)
- return err;
-
- if (!can_assume(NO_ROLLBACK))
- *allocated = 1;
-
- memcpy(new, s, slen);
- new[slen] = '\0';
-
- return (new - strtab);
-}
-
-int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)
-{
- struct fdt_reserve_entry *re;
- int err;
-
- FDT_RW_PROBE(fdt);
-
- re = fdt_mem_rsv_w_(fdt, fdt_num_mem_rsv(fdt));
- err = fdt_splice_mem_rsv_(fdt, re, 0, 1);
- if (err)
- return err;
-
- re->address = cpu_to_fdt64(address);
- re->size = cpu_to_fdt64(size);
- return 0;
-}
-
-int fdt_del_mem_rsv(void *fdt, int n)
-{
- struct fdt_reserve_entry *re = fdt_mem_rsv_w_(fdt, n);
-
- FDT_RW_PROBE(fdt);
-
- if (n >= fdt_num_mem_rsv(fdt))
- return -FDT_ERR_NOTFOUND;
-
- return fdt_splice_mem_rsv_(fdt, re, 1, 0);
-}
-
-static int fdt_resize_property_(void *fdt, int nodeoffset,
- const char *name, int namelen,
- int len, struct fdt_property **prop)
-{
- int oldlen;
- int err;
-
- *prop = fdt_get_property_namelen_w(fdt, nodeoffset, name, namelen,
- &oldlen);
- if (!*prop)
- return oldlen;
-
- if ((err = fdt_splice_struct_(fdt, (*prop)->data, FDT_TAGALIGN(oldlen),
- FDT_TAGALIGN(len))))
- return err;
-
- (*prop)->len = cpu_to_fdt32(len);
- return 0;
-}
-
-static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,
- int namelen, int len, struct fdt_property **prop)
-{
- int proplen;
- int nextoffset;
- int namestroff;
- int err;
- int allocated;
-
- if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0)
- return nextoffset;
-
- namestroff = fdt_find_add_string_(fdt, name, namelen, &allocated);
- if (namestroff < 0)
- return namestroff;
-
- *prop = fdt_offset_ptr_w_(fdt, nextoffset);
- proplen = sizeof(**prop) + FDT_TAGALIGN(len);
-
- err = fdt_splice_struct_(fdt, *prop, 0, proplen);
- if (err) {
- /* Delete the string if we failed to add it */
- if (!can_assume(NO_ROLLBACK) && allocated)
- fdt_del_last_string_(fdt, name);
- return err;
- }
-
- (*prop)->tag = cpu_to_fdt32(FDT_PROP);
- (*prop)->nameoff = cpu_to_fdt32(namestroff);
- (*prop)->len = cpu_to_fdt32(len);
- return 0;
-}
-
-int fdt_set_name(void *fdt, int nodeoffset, const char *name)
-{
- char *namep;
- int oldlen, newlen;
- int err;
-
- FDT_RW_PROBE(fdt);
-
- namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen);
- if (!namep)
- return oldlen;
-
- newlen = strlen(name);
-
- err = fdt_splice_struct_(fdt, namep, FDT_TAGALIGN(oldlen+1),
- FDT_TAGALIGN(newlen+1));
- if (err)
- return err;
-
- memcpy(namep, name, newlen+1);
- return 0;
-}
-
-int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name,
- int namelen, int len, void **prop_data)
-{
- struct fdt_property *prop;
- int err;
-
- FDT_RW_PROBE(fdt);
-
- err = fdt_resize_property_(fdt, nodeoffset, name, namelen, len, &prop);
- if (err == -FDT_ERR_NOTFOUND)
- err = fdt_add_property_(fdt, nodeoffset, name, namelen, len,
- &prop);
- if (err)
- return err;
-
- *prop_data = prop->data;
- return 0;
-}
-
-int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name,
- int namelen, const void *val, int len)
-{
- void *prop_data;
- int err;
-
- err = fdt_setprop_placeholder_namelen(fdt, nodeoffset, name, namelen,
- len, &prop_data);
- if (err)
- return err;
-
- if (len)
- memcpy(prop_data, val, len);
- return 0;
-}
-
-int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
- const void *val, int len)
-{
- struct fdt_property *prop;
- int err, oldlen, newlen;
-
- FDT_RW_PROBE(fdt);
-
- prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
- if (prop) {
- newlen = len + oldlen;
- err = fdt_splice_struct_(fdt, prop->data,
- FDT_TAGALIGN(oldlen),
- FDT_TAGALIGN(newlen));
- if (err)
- return err;
- prop->len = cpu_to_fdt32(newlen);
- memcpy(prop->data + oldlen, val, len);
- } else {
- err = fdt_add_property_(fdt, nodeoffset, name, strlen(name),
- len, &prop);
- if (err)
- return err;
- memcpy(prop->data, val, len);
- }
- return 0;
-}
-
-int fdt_delprop(void *fdt, int nodeoffset, const char *name)
-{
- struct fdt_property *prop;
- int len, proplen;
-
- FDT_RW_PROBE(fdt);
-
- prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
- if (!prop)
- return len;
-
- proplen = sizeof(*prop) + FDT_TAGALIGN(len);
- return fdt_splice_struct_(fdt, prop, proplen, 0);
-}
-
-int fdt_add_subnode_namelen(void *fdt, int parentoffset,
- const char *name, int namelen)
-{
- struct fdt_node_header *nh;
- int offset, nextoffset;
- int nodelen;
- int err;
- uint32_t tag;
- fdt32_t *endtag;
-
- FDT_RW_PROBE(fdt);
-
- offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
- if (offset >= 0)
- return -FDT_ERR_EXISTS;
- else if (offset != -FDT_ERR_NOTFOUND)
- return offset;
-
- /* Try to place the new node after the parent's properties */
- tag = fdt_next_tag(fdt, parentoffset, &nextoffset);
- /* the fdt_subnode_offset_namelen() should ensure this never hits */
- if (!can_assume(LIBFDT_FLAWLESS) && (tag != FDT_BEGIN_NODE))
- return -FDT_ERR_INTERNAL;
- do {
- offset = nextoffset;
- tag = fdt_next_tag(fdt, offset, &nextoffset);
- } while ((tag == FDT_PROP) || (tag == FDT_NOP));
-
- nh = fdt_offset_ptr_w_(fdt, offset);
- nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE;
-
- err = fdt_splice_struct_(fdt, nh, 0, nodelen);
- if (err)
- return err;
-
- nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
- memset(nh->name, 0, FDT_TAGALIGN(namelen+1));
- memcpy(nh->name, name, namelen);
- endtag = (fdt32_t *)((char *)nh + nodelen - FDT_TAGSIZE);
- *endtag = cpu_to_fdt32(FDT_END_NODE);
-
- return offset;
-}
-
-int fdt_add_subnode(void *fdt, int parentoffset, const char *name)
-{
- return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name));
-}
-
-int fdt_del_node(void *fdt, int nodeoffset)
-{
- int endoffset;
-
- FDT_RW_PROBE(fdt);
-
- endoffset = fdt_node_end_offset_(fdt, nodeoffset);
- if (endoffset < 0)
- return endoffset;
-
- return fdt_splice_struct_(fdt, fdt_offset_ptr_w_(fdt, nodeoffset),
- endoffset - nodeoffset, 0);
-}
-
-static void fdt_packblocks_(const char *old, char *new,
- int mem_rsv_size,
- int struct_size,
- int strings_size)
-{
- int mem_rsv_off, struct_off, strings_off;
-
- mem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8);
- struct_off = mem_rsv_off + mem_rsv_size;
- strings_off = struct_off + struct_size;
-
- memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size);
- fdt_set_off_mem_rsvmap(new, mem_rsv_off);
-
- memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size);
- fdt_set_off_dt_struct(new, struct_off);
- fdt_set_size_dt_struct(new, struct_size);
-
- memmove(new + strings_off, old + fdt_off_dt_strings(old), strings_size);
- fdt_set_off_dt_strings(new, strings_off);
- fdt_set_size_dt_strings(new, fdt_size_dt_strings(old));
-}
-
-int fdt_open_into(const void *fdt, void *buf, int bufsize)
-{
- int err;
- int mem_rsv_size, struct_size;
- int newsize;
- const char *fdtstart = fdt;
- const char *fdtend = fdtstart + fdt_totalsize(fdt);
- char *tmp;
-
- FDT_RO_PROBE(fdt);
-
- mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
- * sizeof(struct fdt_reserve_entry);
-
- if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
- struct_size = fdt_size_dt_struct(fdt);
- } else if (fdt_version(fdt) == 16) {
- struct_size = 0;
- while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)
- ;
- if (struct_size < 0)
- return struct_size;
- } else {
- return -FDT_ERR_BADVERSION;
- }
-
- if (can_assume(LIBFDT_ORDER) ||
- !fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) {
- /* no further work necessary */
- err = fdt_move(fdt, buf, bufsize);
- if (err)
- return err;
- fdt_set_version(buf, 17);
- fdt_set_size_dt_struct(buf, struct_size);
- fdt_set_totalsize(buf, bufsize);
- return 0;
- }
-
- /* Need to reorder */
- newsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size
- + struct_size + fdt_size_dt_strings(fdt);
-
- if (bufsize < newsize)
- return -FDT_ERR_NOSPACE;
-
- /* First attempt to build converted tree at beginning of buffer */
- tmp = buf;
- /* But if that overlaps with the old tree... */
- if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {
- /* Try right after the old tree instead */
- tmp = (char *)(uintptr_t)fdtend;
- if ((tmp + newsize) > ((char *)buf + bufsize))
- return -FDT_ERR_NOSPACE;
- }
-
- fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size,
- fdt_size_dt_strings(fdt));
- memmove(buf, tmp, newsize);
-
- fdt_set_magic(buf, FDT_MAGIC);
- fdt_set_totalsize(buf, bufsize);
- fdt_set_version(buf, 17);
- fdt_set_last_comp_version(buf, 16);
- fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));
-
- return 0;
-}
-
-int fdt_pack(void *fdt)
-{
- int mem_rsv_size;
-
- FDT_RW_PROBE(fdt);
-
- mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
- * sizeof(struct fdt_reserve_entry);
- fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt),
- fdt_size_dt_strings(fdt));
- fdt_set_totalsize(fdt, fdt_data_size_(fdt));
-
- return 0;
-}
diff --git a/scripts/dtc/libfdt/fdt_strerror.c b/scripts/dtc/libfdt/fdt_strerror.c
deleted file mode 100644
index d852b77..0000000
--- a/scripts/dtc/libfdt/fdt_strerror.c
+++ /dev/null
@@ -1,60 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-struct fdt_errtabent {
- const char *str;
-};
-
-#define FDT_ERRTABENT(val) \
- [(val)] = { .str = #val, }
-
-static struct fdt_errtabent fdt_errtable[] = {
- FDT_ERRTABENT(FDT_ERR_NOTFOUND),
- FDT_ERRTABENT(FDT_ERR_EXISTS),
- FDT_ERRTABENT(FDT_ERR_NOSPACE),
-
- FDT_ERRTABENT(FDT_ERR_BADOFFSET),
- FDT_ERRTABENT(FDT_ERR_BADPATH),
- FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
- FDT_ERRTABENT(FDT_ERR_BADSTATE),
-
- FDT_ERRTABENT(FDT_ERR_TRUNCATED),
- FDT_ERRTABENT(FDT_ERR_BADMAGIC),
- FDT_ERRTABENT(FDT_ERR_BADVERSION),
- FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
- FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
- FDT_ERRTABENT(FDT_ERR_INTERNAL),
- FDT_ERRTABENT(FDT_ERR_BADNCELLS),
- FDT_ERRTABENT(FDT_ERR_BADVALUE),
- FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
- FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
- FDT_ERRTABENT(FDT_ERR_BADFLAGS),
- FDT_ERRTABENT(FDT_ERR_ALIGNMENT),
-};
-#define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0])))
-
-const char *fdt_strerror(int errval)
-{
- if (errval > 0)
- return "<valid offset/length>";
- else if (errval == 0)
- return "<no error>";
- else if (-errval < FDT_ERRTABSIZE) {
- const char *s = fdt_errtable[-errval].str;
-
- if (s)
- return s;
- }
-
- return "<unknown error>";
-}
diff --git a/scripts/dtc/libfdt/fdt_sw.c b/scripts/dtc/libfdt/fdt_sw.c
deleted file mode 100644
index 4c569ee..0000000
--- a/scripts/dtc/libfdt/fdt_sw.c
+++ /dev/null
@@ -1,384 +0,0 @@
-// 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_sw_probe_(void *fdt)
-{
- if (!can_assume(VALID_INPUT)) {
- if (fdt_magic(fdt) == FDT_MAGIC)
- return -FDT_ERR_BADSTATE;
- else if (fdt_magic(fdt) != FDT_SW_MAGIC)
- return -FDT_ERR_BADMAGIC;
- }
-
- return 0;
-}
-
-#define FDT_SW_PROBE(fdt) \
- { \
- int err; \
- if ((err = fdt_sw_probe_(fdt)) != 0) \
- return err; \
- }
-
-/* 'memrsv' state: Initial state after fdt_create()
- *
- * Allowed functions:
- * fdt_add_reservemap_entry()
- * fdt_finish_reservemap() [moves to 'struct' state]
- */
-static int fdt_sw_probe_memrsv_(void *fdt)
-{
- int err = fdt_sw_probe_(fdt);
- if (err)
- return err;
-
- if (!can_assume(VALID_INPUT) && fdt_off_dt_strings(fdt) != 0)
- return -FDT_ERR_BADSTATE;
- return 0;
-}
-
-#define FDT_SW_PROBE_MEMRSV(fdt) \
- { \
- int err; \
- if ((err = fdt_sw_probe_memrsv_(fdt)) != 0) \
- return err; \
- }
-
-/* 'struct' state: Enter this state after fdt_finish_reservemap()
- *
- * Allowed functions:
- * fdt_begin_node()
- * fdt_end_node()
- * fdt_property*()
- * fdt_finish() [moves to 'complete' state]
- */
-static int fdt_sw_probe_struct_(void *fdt)
-{
- int err = fdt_sw_probe_(fdt);
- if (err)
- return err;
-
- if (!can_assume(VALID_INPUT) &&
- fdt_off_dt_strings(fdt) != fdt_totalsize(fdt))
- return -FDT_ERR_BADSTATE;
- return 0;
-}
-
-#define FDT_SW_PROBE_STRUCT(fdt) \
- { \
- int err; \
- if ((err = fdt_sw_probe_struct_(fdt)) != 0) \
- return err; \
- }
-
-static inline uint32_t sw_flags(void *fdt)
-{
- /* assert: (fdt_magic(fdt) == FDT_SW_MAGIC) */
- return fdt_last_comp_version(fdt);
-}
-
-/* 'complete' state: Enter this state after fdt_finish()
- *
- * Allowed functions: none
- */
-
-static void *fdt_grab_space_(void *fdt, size_t len)
-{
- unsigned int offset = fdt_size_dt_struct(fdt);
- unsigned int spaceleft;
-
- spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)
- - fdt_size_dt_strings(fdt);
-
- if ((offset + len < offset) || (offset + len > spaceleft))
- return NULL;
-
- fdt_set_size_dt_struct(fdt, offset + len);
- return fdt_offset_ptr_w_(fdt, offset);
-}
-
-int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags)
-{
- const int hdrsize = FDT_ALIGN(sizeof(struct fdt_header),
- sizeof(struct fdt_reserve_entry));
- void *fdt = buf;
-
- if (bufsize < hdrsize)
- return -FDT_ERR_NOSPACE;
-
- if (flags & ~FDT_CREATE_FLAGS_ALL)
- return -FDT_ERR_BADFLAGS;
-
- memset(buf, 0, bufsize);
-
- /*
- * magic and last_comp_version keep intermediate state during the fdt
- * creation process, which is replaced with the proper FDT format by
- * fdt_finish().
- *
- * flags should be accessed with sw_flags().
- */
- fdt_set_magic(fdt, FDT_SW_MAGIC);
- fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);
- fdt_set_last_comp_version(fdt, flags);
-
- fdt_set_totalsize(fdt, bufsize);
-
- fdt_set_off_mem_rsvmap(fdt, hdrsize);
- fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt));
- fdt_set_off_dt_strings(fdt, 0);
-
- return 0;
-}
-
-int fdt_create(void *buf, int bufsize)
-{
- return fdt_create_with_flags(buf, bufsize, 0);
-}
-
-int fdt_resize(void *fdt, void *buf, int bufsize)
-{
- size_t headsize, tailsize;
- char *oldtail, *newtail;
-
- FDT_SW_PROBE(fdt);
-
- if (bufsize < 0)
- return -FDT_ERR_NOSPACE;
-
- headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
- tailsize = fdt_size_dt_strings(fdt);
-
- if (!can_assume(VALID_DTB) &&
- headsize + tailsize > fdt_totalsize(fdt))
- return -FDT_ERR_INTERNAL;
-
- if ((headsize + tailsize) > (unsigned)bufsize)
- return -FDT_ERR_NOSPACE;
-
- oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;
- newtail = (char *)buf + bufsize - tailsize;
-
- /* Two cases to avoid clobbering data if the old and new
- * buffers partially overlap */
- if (buf <= fdt) {
- memmove(buf, fdt, headsize);
- memmove(newtail, oldtail, tailsize);
- } else {
- memmove(newtail, oldtail, tailsize);
- memmove(buf, fdt, headsize);
- }
-
- fdt_set_totalsize(buf, bufsize);
- if (fdt_off_dt_strings(buf))
- fdt_set_off_dt_strings(buf, bufsize);
-
- return 0;
-}
-
-int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
-{
- struct fdt_reserve_entry *re;
- int offset;
-
- FDT_SW_PROBE_MEMRSV(fdt);
-
- offset = fdt_off_dt_struct(fdt);
- if ((offset + sizeof(*re)) > fdt_totalsize(fdt))
- return -FDT_ERR_NOSPACE;
-
- re = (struct fdt_reserve_entry *)((char *)fdt + offset);
- re->address = cpu_to_fdt64(addr);
- re->size = cpu_to_fdt64(size);
-
- fdt_set_off_dt_struct(fdt, offset + sizeof(*re));
-
- return 0;
-}
-
-int fdt_finish_reservemap(void *fdt)
-{
- int err = fdt_add_reservemap_entry(fdt, 0, 0);
-
- if (err)
- return err;
-
- fdt_set_off_dt_strings(fdt, fdt_totalsize(fdt));
- return 0;
-}
-
-int fdt_begin_node(void *fdt, const char *name)
-{
- struct fdt_node_header *nh;
- int namelen;
-
- FDT_SW_PROBE_STRUCT(fdt);
-
- namelen = strlen(name) + 1;
- nh = fdt_grab_space_(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen));
- if (! nh)
- return -FDT_ERR_NOSPACE;
-
- nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
- memcpy(nh->name, name, namelen);
- return 0;
-}
-
-int fdt_end_node(void *fdt)
-{
- fdt32_t *en;
-
- FDT_SW_PROBE_STRUCT(fdt);
-
- en = fdt_grab_space_(fdt, FDT_TAGSIZE);
- if (! en)
- return -FDT_ERR_NOSPACE;
-
- *en = cpu_to_fdt32(FDT_END_NODE);
- return 0;
-}
-
-static int fdt_add_string_(void *fdt, const char *s)
-{
- char *strtab = (char *)fdt + fdt_totalsize(fdt);
- unsigned int strtabsize = fdt_size_dt_strings(fdt);
- unsigned int len = strlen(s) + 1;
- unsigned int struct_top, offset;
-
- offset = strtabsize + len;
- struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
- if (fdt_totalsize(fdt) - offset < struct_top)
- return 0; /* no more room :( */
-
- memcpy(strtab - offset, s, len);
- fdt_set_size_dt_strings(fdt, strtabsize + len);
- return -offset;
-}
-
-/* Must only be used to roll back in case of error */
-static void fdt_del_last_string_(void *fdt, const char *s)
-{
- int strtabsize = fdt_size_dt_strings(fdt);
- int len = strlen(s) + 1;
-
- fdt_set_size_dt_strings(fdt, strtabsize - len);
-}
-
-static int fdt_find_add_string_(void *fdt, const char *s, int *allocated)
-{
- char *strtab = (char *)fdt + fdt_totalsize(fdt);
- int strtabsize = fdt_size_dt_strings(fdt);
- const char *p;
-
- *allocated = 0;
-
- p = fdt_find_string_(strtab - strtabsize, strtabsize, s);
- if (p)
- return p - strtab;
-
- *allocated = 1;
-
- return fdt_add_string_(fdt, s);
-}
-
-int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp)
-{
- struct fdt_property *prop;
- int nameoff;
- int allocated;
-
- FDT_SW_PROBE_STRUCT(fdt);
-
- /* String de-duplication can be slow, _NO_NAME_DEDUP skips it */
- if (sw_flags(fdt) & FDT_CREATE_FLAG_NO_NAME_DEDUP) {
- allocated = 1;
- nameoff = fdt_add_string_(fdt, name);
- } else {
- nameoff = fdt_find_add_string_(fdt, name, &allocated);
- }
- if (nameoff == 0)
- return -FDT_ERR_NOSPACE;
-
- prop = fdt_grab_space_(fdt, sizeof(*prop) + FDT_TAGALIGN(len));
- if (! prop) {
- if (allocated)
- fdt_del_last_string_(fdt, name);
- return -FDT_ERR_NOSPACE;
- }
-
- prop->tag = cpu_to_fdt32(FDT_PROP);
- prop->nameoff = cpu_to_fdt32(nameoff);
- prop->len = cpu_to_fdt32(len);
- *valp = prop->data;
- return 0;
-}
-
-int fdt_property(void *fdt, const char *name, const void *val, int len)
-{
- void *ptr;
- int ret;
-
- ret = fdt_property_placeholder(fdt, name, len, &ptr);
- if (ret)
- return ret;
- memcpy(ptr, val, len);
- return 0;
-}
-
-int fdt_finish(void *fdt)
-{
- char *p = (char *)fdt;
- fdt32_t *end;
- int oldstroffset, newstroffset;
- uint32_t tag;
- int offset, nextoffset;
-
- FDT_SW_PROBE_STRUCT(fdt);
-
- /* Add terminator */
- end = fdt_grab_space_(fdt, sizeof(*end));
- if (! end)
- return -FDT_ERR_NOSPACE;
- *end = cpu_to_fdt32(FDT_END);
-
- /* Relocate the string table */
- oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt);
- newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
- memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt));
- fdt_set_off_dt_strings(fdt, newstroffset);
-
- /* Walk the structure, correcting string offsets */
- offset = 0;
- while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) {
- if (tag == FDT_PROP) {
- struct fdt_property *prop =
- fdt_offset_ptr_w_(fdt, offset);
- int nameoff;
-
- nameoff = fdt32_to_cpu(prop->nameoff);
- nameoff += fdt_size_dt_strings(fdt);
- prop->nameoff = cpu_to_fdt32(nameoff);
- }
- offset = nextoffset;
- }
- if (nextoffset < 0)
- return nextoffset;
-
- /* Finally, adjust the header */
- fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
-
- /* And fix up fields that were keeping intermediate state. */
- fdt_set_last_comp_version(fdt, FDT_LAST_COMPATIBLE_VERSION);
- fdt_set_magic(fdt, FDT_MAGIC);
-
- return 0;
-}
diff --git a/scripts/dtc/libfdt/fdt_wip.c b/scripts/dtc/libfdt/fdt_wip.c
deleted file mode 100644
index c2d7566..0000000
--- a/scripts/dtc/libfdt/fdt_wip.c
+++ /dev/null
@@ -1,94 +0,0 @@
-// 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"
-
-int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
- const char *name, int namelen,
- uint32_t idx, const void *val,
- int len)
-{
- void *propval;
- int proplen;
-
- propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
- &proplen);
- if (!propval)
- return proplen;
-
- if ((unsigned)proplen < (len + idx))
- return -FDT_ERR_NOSPACE;
-
- memcpy((char *)propval + idx, val, len);
- return 0;
-}
-
-int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
- const void *val, int len)
-{
- const void *propval;
- int proplen;
-
- propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
- if (!propval)
- return proplen;
-
- if (proplen != len)
- return -FDT_ERR_NOSPACE;
-
- return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
- strlen(name), 0,
- val, len);
-}
-
-static void fdt_nop_region_(void *start, int len)
-{
- fdt32_t *p;
-
- for (p = start; (char *)p < ((char *)start + len); p++)
- *p = cpu_to_fdt32(FDT_NOP);
-}
-
-int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
-{
- struct fdt_property *prop;
- int len;
-
- prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
- if (!prop)
- return len;
-
- fdt_nop_region_(prop, len + sizeof(*prop));
-
- return 0;
-}
-
-int fdt_node_end_offset_(void *fdt, int offset)
-{
- int depth = 0;
-
- while ((offset >= 0) && (depth >= 0))
- offset = fdt_next_node(fdt, offset, &depth);
-
- return offset;
-}
-
-int fdt_nop_node(void *fdt, int nodeoffset)
-{
- int endoffset;
-
- endoffset = fdt_node_end_offset_(fdt, nodeoffset);
- if (endoffset < 0)
- return endoffset;
-
- fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0),
- endoffset - nodeoffset);
- return 0;
-}
diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h
deleted file mode 100644
index 81aaf7c..0000000
--- a/scripts/dtc/libfdt/libfdt.h
+++ /dev/null
@@ -1,2540 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
-#ifndef LIBFDT_H
-#define LIBFDT_H
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- */
-
-#include "libfdt_env.h"
-#include "fdt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define FDT_FIRST_SUPPORTED_VERSION 0x02
-#define FDT_LAST_COMPATIBLE_VERSION 0x10
-#define FDT_LAST_SUPPORTED_VERSION 0x11
-
-/* Error codes: informative error codes */
-#define FDT_ERR_NOTFOUND 1
- /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
-#define FDT_ERR_EXISTS 2
- /* FDT_ERR_EXISTS: Attempted to create a node or property which
- * already exists */
-#define FDT_ERR_NOSPACE 3
- /* FDT_ERR_NOSPACE: Operation needed to expand the device
- * tree, but its buffer did not have sufficient space to
- * contain the expanded tree. Use fdt_open_into() to move the
- * device tree to a buffer with more space. */
-
-/* Error codes: codes for bad parameters */
-#define FDT_ERR_BADOFFSET 4
- /* FDT_ERR_BADOFFSET: Function was passed a structure block
- * offset which is out-of-bounds, or which points to an
- * unsuitable part of the structure for the operation. */
-#define FDT_ERR_BADPATH 5
- /* FDT_ERR_BADPATH: Function was passed a badly formatted path
- * (e.g. missing a leading / for a function which requires an
- * absolute path) */
-#define FDT_ERR_BADPHANDLE 6
- /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
- * This can be caused either by an invalid phandle property
- * length, or the phandle value was either 0 or -1, which are
- * not permitted. */
-#define FDT_ERR_BADSTATE 7
- /* FDT_ERR_BADSTATE: Function was passed an incomplete device
- * tree created by the sequential-write functions, which is
- * not sufficiently complete for the requested operation. */
-
-/* Error codes: codes for bad device tree blobs */
-#define FDT_ERR_TRUNCATED 8
- /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
- * terminated (overflows, goes outside allowed bounds, or
- * isn't properly terminated). */
-#define FDT_ERR_BADMAGIC 9
- /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
- * device tree at all - it is missing the flattened device
- * tree magic number. */
-#define FDT_ERR_BADVERSION 10
- /* FDT_ERR_BADVERSION: Given device tree has a version which
- * can't be handled by the requested operation. For
- * read-write functions, this may mean that fdt_open_into() is
- * required to convert the tree to the expected version. */
-#define FDT_ERR_BADSTRUCTURE 11
- /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
- * structure block or other serious error (e.g. misnested
- * nodes, or subnodes preceding properties). */
-#define FDT_ERR_BADLAYOUT 12
- /* FDT_ERR_BADLAYOUT: For read-write functions, the given
- * device tree has it's sub-blocks in an order that the
- * function can't handle (memory reserve map, then structure,
- * then strings). Use fdt_open_into() to reorganize the tree
- * into a form suitable for the read-write operations. */
-
-/* "Can't happen" error indicating a bug in libfdt */
-#define FDT_ERR_INTERNAL 13
- /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
- * Should never be returned, if it is, it indicates a bug in
- * libfdt itself. */
-
-/* Errors in device tree content */
-#define FDT_ERR_BADNCELLS 14
- /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
- * or similar property with a bad format or value */
-
-#define FDT_ERR_BADVALUE 15
- /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
- * value. For example: a property expected to contain a string list
- * is not NUL-terminated within the length of its value. */
-
-#define FDT_ERR_BADOVERLAY 16
- /* FDT_ERR_BADOVERLAY: The device tree overlay, while
- * correctly structured, cannot be applied due to some
- * unexpected or missing value, property or node. */
-
-#define FDT_ERR_NOPHANDLES 17
- /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
- * phandle available anymore without causing an overflow */
-
-#define FDT_ERR_BADFLAGS 18
- /* FDT_ERR_BADFLAGS: The function was passed a flags field that
- * contains invalid flags or an invalid combination of flags. */
-
-#define FDT_ERR_ALIGNMENT 19
- /* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
- * aligned. */
-
-#define FDT_ERR_MAX 19
-
-/* constants */
-#define FDT_MAX_PHANDLE 0xfffffffe
- /* Valid values for phandles range from 1 to 2^32-2. */
-
-/**********************************************************************/
-/* Low-level functions (you probably don't need these) */
-/**********************************************************************/
-
-/**
- * fdt_offset_ptr - safely get a byte range within the device tree blob
- * @fdt: Pointer to the device tree blob
- * @offset: Offset within the blob to the desired byte range
- * @checklen: Required length of the byte range
- *
- * fdt_offset_ptr() returns a pointer to the byte range of length @checklen at
- * the given @offset within the device tree blob, after verifying that the byte
- * range fits entirely within the blob and does not overflow.
- *
- * returns:
- * pointer to the byte range, on success
- * NULL, if the requested range does not fit within the blob
- */
-#ifndef SWIG /* This function is not useful in Python */
-const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
-#endif
-static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
-{
- return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
-}
-
-/**
- * fdt_next_tag - get next tag in the device tree
- * @fdt: Pointer to the device tree blob
- * @offset: Offset within the blob to start searching
- * @nextoffset: Pointer to variable to store the offset of the next tag
- *
- * fdt_next_tag() returns the tag type of the next tag in the device tree
- * blob starting from the given @offset. If @nextoffset is non-NULL, it will
- * be set to the offset immediately following the tag.
- *
- * returns:
- * the tag type (FDT_BEGIN_NODE, FDT_END_NODE, FDT_PROP, FDT_NOP, FDT_END),
- * FDT_END, if offset is out of bounds
- */
-uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
-
-/*
- * External helpers to access words from a device tree blob. They're built
- * to work even with unaligned pointers on platforms (such as ARMv5) that don't
- * like unaligned loads and stores.
- */
-static inline uint16_t fdt16_ld(const fdt16_t *p)
-{
- const uint8_t *bp = (const uint8_t *)p;
-
- return ((uint16_t)bp[0] << 8) | bp[1];
-}
-
-static inline uint32_t fdt32_ld(const fdt32_t *p)
-{
- const uint8_t *bp = (const uint8_t *)p;
-
- return ((uint32_t)bp[0] << 24)
- | ((uint32_t)bp[1] << 16)
- | ((uint32_t)bp[2] << 8)
- | bp[3];
-}
-
-static inline void fdt32_st(void *property, uint32_t value)
-{
- uint8_t *bp = (uint8_t *)property;
-
- bp[0] = value >> 24;
- bp[1] = (value >> 16) & 0xff;
- bp[2] = (value >> 8) & 0xff;
- bp[3] = value & 0xff;
-}
-
-static inline uint64_t fdt64_ld(const fdt64_t *p)
-{
- const uint8_t *bp = (const uint8_t *)p;
-
- return ((uint64_t)bp[0] << 56)
- | ((uint64_t)bp[1] << 48)
- | ((uint64_t)bp[2] << 40)
- | ((uint64_t)bp[3] << 32)
- | ((uint64_t)bp[4] << 24)
- | ((uint64_t)bp[5] << 16)
- | ((uint64_t)bp[6] << 8)
- | bp[7];
-}
-
-static inline void fdt64_st(void *property, uint64_t value)
-{
- uint8_t *bp = (uint8_t *)property;
-
- bp[0] = value >> 56;
- bp[1] = (value >> 48) & 0xff;
- bp[2] = (value >> 40) & 0xff;
- bp[3] = (value >> 32) & 0xff;
- bp[4] = (value >> 24) & 0xff;
- bp[5] = (value >> 16) & 0xff;
- bp[6] = (value >> 8) & 0xff;
- bp[7] = value & 0xff;
-}
-
-/**********************************************************************/
-/* Traversal functions */
-/**********************************************************************/
-
-int fdt_next_node(const void *fdt, int offset, int *depth);
-
-/**
- * fdt_first_subnode() - get offset of first direct subnode
- * @fdt: FDT blob
- * @offset: Offset of node to check
- *
- * Return: offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
- */
-int fdt_first_subnode(const void *fdt, int offset);
-
-/**
- * fdt_next_subnode() - get offset of next direct subnode
- * @fdt: FDT blob
- * @offset: Offset of previous subnode
- *
- * After first calling fdt_first_subnode(), call this function repeatedly to
- * get direct subnodes of a parent node.
- *
- * Return: offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
- * subnodes
- */
-int fdt_next_subnode(const void *fdt, int offset);
-
-/**
- * fdt_for_each_subnode - iterate over all subnodes of a parent
- *
- * @node: child node (int, lvalue)
- * @fdt: FDT blob (const void *)
- * @parent: parent node (int)
- *
- * This is actually a wrapper around a for loop and would be used like so:
- *
- * fdt_for_each_subnode(node, fdt, parent) {
- * Use node
- * ...
- * }
- *
- * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
- * Error handling
- * }
- *
- * Note that this is implemented as a macro and @node is used as
- * iterator in the loop. The parent variable be constant or even a
- * literal.
- */
-#define fdt_for_each_subnode(node, fdt, parent) \
- for (node = fdt_first_subnode(fdt, parent); \
- node >= 0; \
- node = fdt_next_subnode(fdt, node))
-
-/**********************************************************************/
-/* General functions */
-/**********************************************************************/
-#define fdt_get_header(fdt, field) \
- (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
-#define fdt_magic(fdt) (fdt_get_header(fdt, magic))
-#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
-#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
-#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
-#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
-#define fdt_version(fdt) (fdt_get_header(fdt, version))
-#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
-#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
-#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
-#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
-
-#define fdt_set_hdr_(name) \
- static inline void fdt_set_##name(void *fdt, uint32_t val) \
- { \
- struct fdt_header *fdth = (struct fdt_header *)fdt; \
- fdth->name = cpu_to_fdt32(val); \
- }
-fdt_set_hdr_(magic)
-fdt_set_hdr_(totalsize)
-fdt_set_hdr_(off_dt_struct)
-fdt_set_hdr_(off_dt_strings)
-fdt_set_hdr_(off_mem_rsvmap)
-fdt_set_hdr_(version)
-fdt_set_hdr_(last_comp_version)
-fdt_set_hdr_(boot_cpuid_phys)
-fdt_set_hdr_(size_dt_strings)
-fdt_set_hdr_(size_dt_struct)
-#undef fdt_set_hdr_
-
-/**
- * fdt_header_size - return the size of the tree's header
- * @fdt: pointer to a flattened device tree
- *
- * Return: size of DTB header in bytes
- */
-size_t fdt_header_size(const void *fdt);
-
-/**
- * fdt_header_size_ - internal function to get header size from a version number
- * @version: device tree version number
- *
- * Return: size of DTB header in bytes
- */
-size_t fdt_header_size_(uint32_t version);
-
-/**
- * fdt_check_header - sanity check a device tree header
- * @fdt: pointer to data which might be a flattened device tree
- *
- * fdt_check_header() checks that the given buffer contains what
- * appears to be a flattened device tree, and that the header contains
- * valid information (to the extent that can be determined from the
- * header alone).
- *
- * returns:
- * 0, if the buffer appears to contain a valid device tree
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_TRUNCATED, standard meanings, as above
- */
-int fdt_check_header(const void *fdt);
-
-/**
- * fdt_move - move a device tree around in memory
- * @fdt: pointer to the device tree to move
- * @buf: pointer to memory where the device is to be moved
- * @bufsize: size of the memory space at buf
- *
- * fdt_move() relocates, if possible, the device tree blob located at
- * fdt to the buffer at buf of size bufsize. The buffer may overlap
- * with the existing device tree blob at fdt. Therefore,
- * fdt_move(fdt, fdt, fdt_totalsize(fdt))
- * should always succeed.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE, standard meanings
- */
-int fdt_move(const void *fdt, void *buf, int bufsize);
-
-/**********************************************************************/
-/* Read-only functions */
-/**********************************************************************/
-
-/**
- * fdt_check_full - check device tree validity
- * @fdt: pointer to the device tree blob
- * @bufsize: size of the buffer containing the device tree
- *
- * fdt_check_full() checks that the given buffer contains a valid
- * flattened device tree and that the tree structure is internally
- * consistent. This is a more thorough check than fdt_check_header().
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_check_full(const void *fdt, size_t bufsize);
-
-/**
- * fdt_get_string - retrieve a string from the strings block of a device tree
- * @fdt: pointer to the device tree blob
- * @stroffset: offset of the string within the strings block (native endian)
- * @lenp: optional pointer to return the string's length
- *
- * fdt_get_string() retrieves a pointer to a single string from the
- * strings block of the device tree blob at fdt, and optionally also
- * returns the string's length in *lenp.
- *
- * returns:
- * a pointer to the string, on success
- * NULL, if stroffset is out of bounds, or doesn't point to a valid string
- */
-const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
-
-/**
- * fdt_string - retrieve a string from the strings block of a device tree
- * @fdt: pointer to the device tree blob
- * @stroffset: offset of the string within the strings block (native endian)
- *
- * fdt_string() retrieves a pointer to a single string from the
- * strings block of the device tree blob at fdt.
- *
- * returns:
- * a pointer to the string, on success
- * NULL, if stroffset is out of bounds, or doesn't point to a valid string
- */
-const char *fdt_string(const void *fdt, int stroffset);
-
-/**
- * fdt_find_max_phandle - find and return the highest phandle in a tree
- * @fdt: pointer to the device tree blob
- * @phandle: return location for the highest phandle value found in the tree
- *
- * fdt_find_max_phandle() finds the highest phandle value in the given device
- * tree. The value returned in @phandle is only valid if the function returns
- * success.
- *
- * returns:
- * 0 on success or a negative error code on failure
- */
-int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
-
-/**
- * fdt_get_max_phandle - retrieves the highest phandle in a tree
- * @fdt: pointer to the device tree blob
- *
- * fdt_get_max_phandle retrieves the highest phandle in the given
- * device tree. This will ignore badly formatted phandles, or phandles
- * with a value of 0 or -1.
- *
- * This function is deprecated in favour of fdt_find_max_phandle().
- *
- * returns:
- * the highest phandle on success
- * 0, if no phandle was found in the device tree
- * -1, if an error occurred
- */
-static inline uint32_t fdt_get_max_phandle(const void *fdt)
-{
- uint32_t phandle;
- int err;
-
- err = fdt_find_max_phandle(fdt, &phandle);
- if (err < 0)
- return (uint32_t)-1;
-
- return phandle;
-}
-
-/**
- * fdt_generate_phandle - return a new, unused phandle for a device tree blob
- * @fdt: pointer to the device tree blob
- * @phandle: return location for the new phandle
- *
- * Walks the device tree blob and looks for the highest phandle value. On
- * success, the new, unused phandle value (one higher than the previously
- * highest phandle value in the device tree blob) will be returned in the
- * @phandle parameter.
- *
- * Return: 0 on success or a negative error-code on failure
- */
-int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
-
-/**
- * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
- * @fdt: pointer to the device tree blob
- *
- * Returns the number of entries in the device tree blob's memory
- * reservation map. This does not include the terminating 0,0 entry
- * or any other (0,0) entries reserved for expansion.
- *
- * returns:
- * the number of entries
- */
-int fdt_num_mem_rsv(const void *fdt);
-
-/**
- * fdt_get_mem_rsv - retrieve one memory reserve map entry
- * @fdt: pointer to the device tree blob
- * @n: index of reserve map entry
- * @address: pointer to 64-bit variable to hold the start address
- * @size: pointer to 64-bit variable to hold the size of the entry
- *
- * On success, @address and @size will contain the address and size of
- * the n-th reserve map entry from the device tree blob, in
- * native-endian format.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE, standard meanings
- */
-int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
-
-/**
- * fdt_subnode_offset_namelen - find a subnode based on substring
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to locate
- * @namelen: number of characters of name to consider
- *
- * Identical to fdt_subnode_offset(), but only examine the first
- * namelen characters of name for matching the subnode name. This is
- * useful for finding subnodes based on a portion of a larger string,
- * such as a full path.
- *
- * Return: offset of the subnode or -FDT_ERR_NOTFOUND if name not found.
- */
-#ifndef SWIG /* Not available in Python */
-int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
- const char *name, int namelen);
-#endif
-/**
- * fdt_subnode_offset - find a subnode of a given node
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to locate
- *
- * fdt_subnode_offset() finds a subnode of the node at structure block
- * offset parentoffset with the given name. name may include a unit
- * address, in which case fdt_subnode_offset() will find the subnode
- * with that unit address, or the unit address may be omitted, in
- * which case fdt_subnode_offset() will find an arbitrary subnode
- * whose name excluding unit address matches the given name.
- *
- * returns:
- * structure block offset of the requested subnode (>=0), on success
- * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
- * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
- * tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
-
-/**
- * fdt_path_offset_namelen - find a tree node by its full path
- * @fdt: pointer to the device tree blob
- * @path: full path of the node to locate
- * @namelen: number of characters of path to consider
- *
- * Identical to fdt_path_offset(), but only consider the first namelen
- * characters of path as the path name.
- *
- * Return: offset of the node or negative libfdt error value otherwise
- */
-#ifndef SWIG /* Not available in Python */
-int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
-#endif
-
-/**
- * fdt_path_offset - find a tree node by its full path
- * @fdt: pointer to the device tree blob
- * @path: full path of the node to locate
- *
- * fdt_path_offset() finds a node of a given path in the device tree.
- * Each path component may omit the unit address portion, but the
- * results of this are undefined if any such path component is
- * ambiguous (that is if there are multiple nodes at the relevant
- * level matching the given component, differentiated only by unit
- * address).
- *
- * If the path is not absolute (i.e. does not begin with '/'), the
- * first component is treated as an alias. That is, the property by
- * that name is looked up in the /aliases node, and the value of that
- * property used in place of that first component.
- *
- * For example, for this small fragment
- *
- * / {
- * aliases {
- * i2c2 = &foo; // RHS compiles to "/soc@0/i2c@30a40000/eeprom@52"
- * };
- * soc@0 {
- * foo: i2c@30a40000 {
- * bar: eeprom@52 {
- * };
- * };
- * };
- * };
- *
- * these would be equivalent:
- *
- * /soc@0/i2c@30a40000/eeprom@52
- * i2c2/eeprom@52
- *
- * returns:
- * structure block offset of the node with the requested path (>=0), on
- * success
- * -FDT_ERR_BADPATH, given path does not begin with '/' and the first
- * component is not a valid alias
- * -FDT_ERR_NOTFOUND, if the requested node does not exist
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_path_offset(const void *fdt, const char *path);
-
-/**
- * fdt_get_name - retrieve the name of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of the starting node
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_get_name() retrieves the name (including unit address) of the
- * device tree node at structure block offset nodeoffset. If lenp is
- * non-NULL, the length of this name is also returned, in the integer
- * pointed to by lenp.
- *
- * returns:
- * pointer to the node's name, on success
- * If lenp is non-NULL, *lenp contains the length of that name
- * (>=0)
- * NULL, on error
- * if lenp is non-NULL *lenp contains an error code (<0):
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
- * tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE, standard meanings
- */
-const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
-
-/**
- * fdt_first_property_offset - find the offset of a node's first property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of a node
- *
- * fdt_first_property_offset() finds the first property of the node at
- * the given structure block offset.
- *
- * returns:
- * structure block offset of the property (>=0), on success
- * -FDT_ERR_NOTFOUND, if the requested node has no properties
- * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_first_property_offset(const void *fdt, int nodeoffset);
-
-/**
- * fdt_next_property_offset - step through a node's properties
- * @fdt: pointer to the device tree blob
- * @offset: structure block offset of a property
- *
- * fdt_next_property_offset() finds the property immediately after the
- * one at the given structure block offset. This will be a property
- * of the same node as the given property.
- *
- * returns:
- * structure block offset of the next property (>=0), on success
- * -FDT_ERR_NOTFOUND, if the given property is the last in its node
- * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_next_property_offset(const void *fdt, int offset);
-
-/**
- * fdt_for_each_property_offset - iterate over all properties of a node
- *
- * @property: property offset (int, lvalue)
- * @fdt: FDT blob (const void *)
- * @node: node offset (int)
- *
- * This is actually a wrapper around a for loop and would be used like so:
- *
- * fdt_for_each_property_offset(property, fdt, node) {
- * Use property
- * ...
- * }
- *
- * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) {
- * Error handling
- * }
- *
- * Note that this is implemented as a macro and property is used as
- * iterator in the loop. The node variable can be constant or even a
- * literal.
- */
-#define fdt_for_each_property_offset(property, fdt, node) \
- for (property = fdt_first_property_offset(fdt, node); \
- property >= 0; \
- property = fdt_next_property_offset(fdt, property))
-
-/**
- * fdt_get_property_by_offset - retrieve the property at a given offset
- * @fdt: pointer to the device tree blob
- * @offset: offset of the property to retrieve
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_get_property_by_offset() retrieves a pointer to the
- * fdt_property structure within the device tree blob at the given
- * offset. If lenp is non-NULL, the length of the property value is
- * also returned, in the integer pointed to by lenp.
- *
- * Note that this code only works on device tree versions >= 16. fdt_getprop()
- * works on all versions.
- *
- * returns:
- * pointer to the structure representing the property
- * if lenp is non-NULL, *lenp contains the length of the property
- * value (>=0)
- * NULL, on error
- * if lenp is non-NULL, *lenp contains an error code (<0):
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
- int offset,
- int *lenp);
-static inline struct fdt_property *fdt_get_property_by_offset_w(void *fdt,
- int offset,
- int *lenp)
-{
- return (struct fdt_property *)(uintptr_t)
- fdt_get_property_by_offset(fdt, offset, lenp);
-}
-
-/**
- * fdt_get_property_namelen - find a property based on substring
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @namelen: number of characters of name to consider
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * Identical to fdt_get_property(), but only examine the first namelen
- * characters of name for matching the property name.
- *
- * Return: pointer to the structure representing the property, or NULL
- * if not found
- */
-#ifndef SWIG /* Not available in Python */
-const struct fdt_property *fdt_get_property_namelen(const void *fdt,
- int nodeoffset,
- const char *name,
- int namelen, int *lenp);
-static inline struct fdt_property *
-fdt_get_property_namelen_w(void *fdt, int nodeoffset, const char *name,
- int namelen, int *lenp)
-{
- return (struct fdt_property *)(uintptr_t)fdt_get_property_namelen(
- fdt, nodeoffset, name, namelen, lenp);
-}
-#endif
-
-/**
- * fdt_get_property - find a given property in a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_get_property() retrieves a pointer to the fdt_property
- * structure within the device tree blob corresponding to the property
- * named 'name' of the node at offset nodeoffset. If lenp is
- * non-NULL, the length of the property value is also returned, in the
- * integer pointed to by lenp.
- *
- * returns:
- * pointer to the structure representing the property
- * if lenp is non-NULL, *lenp contains the length of the property
- * value (>=0)
- * NULL, on error
- * if lenp is non-NULL, *lenp contains an error code (<0):
- * -FDT_ERR_NOTFOUND, node does not have named property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
- * tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
- const char *name, int *lenp);
-static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
- const char *name,
- int *lenp)
-{
- return (struct fdt_property *)(uintptr_t)
- fdt_get_property(fdt, nodeoffset, name, lenp);
-}
-
-/**
- * fdt_getprop_by_offset - retrieve the value of a property at a given offset
- * @fdt: pointer to the device tree blob
- * @offset: offset of the property to read
- * @namep: pointer to a string variable (will be overwritten) or NULL
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_getprop_by_offset() retrieves a pointer to the value of the
- * property at structure block offset 'offset' (this will be a pointer
- * to within the device blob itself, not a copy of the value). If
- * lenp is non-NULL, the length of the property value is also
- * returned, in the integer pointed to by lenp. If namep is non-NULL,
- * the property's name will also be returned in the char * pointed to
- * by namep (this will be a pointer to within the device tree's string
- * block, not a new copy of the name).
- *
- * returns:
- * pointer to the property's value
- * if lenp is non-NULL, *lenp contains the length of the property
- * value (>=0)
- * if namep is non-NULL *namep contains a pointer to the property
- * name.
- * NULL, on error
- * if lenp is non-NULL, *lenp contains an error code (<0):
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-#ifndef SWIG /* This function is not useful in Python */
-const void *fdt_getprop_by_offset(const void *fdt, int offset,
- const char **namep, int *lenp);
-#endif
-
-/**
- * fdt_getprop_namelen - get property value based on substring
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @namelen: number of characters of name to consider
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * Identical to fdt_getprop(), but only examine the first namelen
- * characters of name for matching the property name.
- *
- * Return: pointer to the property's value or NULL on error
- */
-#ifndef SWIG /* Not available in Python */
-const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
- const char *name, int namelen, int *lenp);
-static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
- const char *name, int namelen,
- int *lenp)
-{
- return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
- namelen, lenp);
-}
-#endif
-
-/**
- * fdt_getprop - retrieve the value of a given property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_getprop() retrieves a pointer to the value of the property
- * named @name of the node at offset @nodeoffset (this will be a
- * pointer to within the device blob itself, not a copy of the value).
- * If @lenp is non-NULL, the length of the property value is also
- * returned, in the integer pointed to by @lenp.
- *
- * returns:
- * pointer to the property's value
- * if lenp is non-NULL, *lenp contains the length of the property
- * value (>=0)
- * NULL, on error
- * if lenp is non-NULL, *lenp contains an error code (<0):
- * -FDT_ERR_NOTFOUND, node does not have named property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
- * tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-const void *fdt_getprop(const void *fdt, int nodeoffset,
- const char *name, int *lenp);
-static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
- const char *name, int *lenp)
-{
- return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
-}
-
-/**
- * fdt_get_phandle - retrieve the phandle of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of the node
- *
- * fdt_get_phandle() retrieves the phandle of the device tree node at
- * structure block offset nodeoffset.
- *
- * returns:
- * the phandle of the node at nodeoffset, on success (!= 0, != -1)
- * 0, if the node has no phandle, or another error occurs
- */
-uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
-
-/**
- * fdt_get_alias_namelen - get alias based on substring
- * @fdt: pointer to the device tree blob
- * @name: name of the alias to look up
- * @namelen: number of characters of name to consider
- *
- * Identical to fdt_get_alias(), but only examine the first @namelen
- * characters of @name for matching the alias name.
- *
- * Return: a pointer to the expansion of the alias named @name, if it exists,
- * NULL otherwise
- */
-#ifndef SWIG /* Not available in Python */
-const char *fdt_get_alias_namelen(const void *fdt,
- const char *name, int namelen);
-#endif
-
-/**
- * fdt_get_alias - retrieve the path referenced by a given alias
- * @fdt: pointer to the device tree blob
- * @name: name of the alias to look up
- *
- * fdt_get_alias() retrieves the value of a given alias. That is, the
- * value of the property named @name in the node /aliases.
- *
- * returns:
- * a pointer to the expansion of the alias named 'name', if it exists
- * NULL, if the given alias or the /aliases node does not exist
- */
-const char *fdt_get_alias(const void *fdt, const char *name);
-
-/**
- * fdt_get_symbol_namelen - get symbol based on substring
- * @fdt: pointer to the device tree blob
- * @name: name of the symbol to look up
- * @namelen: number of characters of name to consider
- *
- * Identical to fdt_get_symbol(), but only examine the first @namelen
- * characters of @name for matching the symbol name.
- *
- * Return: a pointer to the expansion of the symbol named @name, if it exists,
- * NULL otherwise
- */
-#ifndef SWIG /* Not available in Python */
-const char *fdt_get_symbol_namelen(const void *fdt,
- const char *name, int namelen);
-#endif
-
-/**
- * fdt_get_symbol - retrieve the path referenced by a given symbol
- * @fdt: pointer to the device tree blob
- * @name: name of the symbol to look up
- *
- * fdt_get_symbol() retrieves the value of a given symbol. That is,
- * the value of the property named @name in the node
- * /__symbols__. Such a node exists only for a device tree blob that
- * has been compiled with the -@ dtc option. Each property corresponds
- * to a label appearing in the device tree source, with the name of
- * the property being the label and the value being the full path of
- * the node it is attached to.
- *
- * returns:
- * a pointer to the expansion of the symbol named 'name', if it exists
- * NULL, if the given symbol or the /__symbols__ node does not exist
- */
-const char *fdt_get_symbol(const void *fdt, const char *name);
-
-/**
- * fdt_get_path - determine the full path of a node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose path to find
- * @buf: character buffer to contain the returned path (will be overwritten)
- * @buflen: size of the character buffer at buf
- *
- * fdt_get_path() computes the full path of the node at offset
- * nodeoffset, and records that path in the buffer at buf.
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset.
- *
- * returns:
- * 0, on success
- * buf contains the absolute path of the node at
- * nodeoffset, as a NUL-terminated string.
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
- * characters and will not fit in the given buffer.
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
-
-/**
- * fdt_supernode_atdepth_offset - find a specific ancestor of a node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose parent to find
- * @supernodedepth: depth of the ancestor to find
- * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_supernode_atdepth_offset() finds an ancestor of the given node
- * at a specific depth from the root (where the root itself has depth
- * 0, its immediate subnodes depth 1 and so forth). So
- * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
- * will always return 0, the offset of the root node. If the node at
- * nodeoffset has depth D, then:
- * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
- * will return nodeoffset itself.
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset.
- *
- * returns:
- * structure block offset of the node at node offset's ancestor
- * of depth supernodedepth (>=0), on success
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
- * nodeoffset
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
- int supernodedepth, int *nodedepth);
-
-/**
- * fdt_node_depth - find the depth of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose parent to find
- *
- * fdt_node_depth() finds the depth of a given node. The root node
- * has depth 0, its immediate subnodes depth 1 and so forth.
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset.
- *
- * returns:
- * depth of the node at nodeoffset (>=0), on success
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_depth(const void *fdt, int nodeoffset);
-
-/**
- * fdt_parent_offset - find the parent of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose parent to find
- *
- * fdt_parent_offset() locates the parent node of a given node (that
- * is, it finds the offset of the node which contains the node at
- * nodeoffset as a subnode).
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset, *twice*.
- *
- * returns:
- * structure block offset of the parent of the node at nodeoffset
- * (>=0), on success
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_parent_offset(const void *fdt, int nodeoffset);
-
-/**
- * fdt_node_offset_by_prop_value - find nodes with a given property value
- * @fdt: pointer to the device tree blob
- * @startoffset: only find nodes after this offset
- * @propname: property name to check
- * @propval: property value to search for
- * @proplen: length of the value in propval
- *
- * fdt_node_offset_by_prop_value() returns the offset of the first
- * node after startoffset, which has a property named propname whose
- * value is of length proplen and has value equal to propval; or if
- * startoffset is -1, the very first such node in the tree.
- *
- * To iterate through all nodes matching the criterion, the following
- * idiom can be used:
- * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
- * propval, proplen);
- * while (offset != -FDT_ERR_NOTFOUND) {
- * // other code here
- * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
- * propval, proplen);
- * }
- *
- * Note the -1 in the first call to the function, if 0 is used here
- * instead, the function will never locate the root node, even if it
- * matches the criterion.
- *
- * returns:
- * structure block offset of the located node (>= 0, >startoffset),
- * on success
- * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
- * tree after startoffset
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
- const char *propname,
- const void *propval, int proplen);
-
-/**
- * fdt_node_offset_by_phandle - find the node with a given phandle
- * @fdt: pointer to the device tree blob
- * @phandle: phandle value
- *
- * fdt_node_offset_by_phandle() returns the offset of the node
- * which has the given phandle value. If there is more than one node
- * in the tree with the given phandle (an invalid tree), results are
- * undefined.
- *
- * returns:
- * structure block offset of the located node (>= 0), on success
- * -FDT_ERR_NOTFOUND, no node with that phandle exists
- * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
-
-/**
- * fdt_node_check_compatible - check a node's compatible property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of a tree node
- * @compatible: string to match against
- *
- * fdt_node_check_compatible() returns 0 if the given node contains a
- * @compatible property with the given string as one of its elements,
- * it returns non-zero otherwise, or on error.
- *
- * returns:
- * 0, if the node has a 'compatible' property listing the given string
- * 1, if the node has a 'compatible' property, but it does not list
- * the given string
- * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
- * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_check_compatible(const void *fdt, int nodeoffset,
- const char *compatible);
-
-/**
- * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
- * @fdt: pointer to the device tree blob
- * @startoffset: only find nodes after this offset
- * @compatible: 'compatible' string to match against
- *
- * fdt_node_offset_by_compatible() returns the offset of the first
- * node after startoffset, which has a 'compatible' property which
- * lists the given compatible string; or if startoffset is -1, the
- * very first such node in the tree.
- *
- * To iterate through all nodes matching the criterion, the following
- * idiom can be used:
- * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
- * while (offset != -FDT_ERR_NOTFOUND) {
- * // other code here
- * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
- * }
- *
- * Note the -1 in the first call to the function, if 0 is used here
- * instead, the function will never locate the root node, even if it
- * matches the criterion.
- *
- * returns:
- * structure block offset of the located node (>= 0, >startoffset),
- * on success
- * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
- * tree after startoffset
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
- const char *compatible);
-
-/**
- * fdt_stringlist_contains - check a string list property for a string
- * @strlist: Property containing a list of strings to check
- * @listlen: Length of property
- * @str: String to search for
- *
- * This is a utility function provided for convenience. The list contains
- * one or more strings, each terminated by \0, as is found in a device tree
- * "compatible" property.
- *
- * Return: 1 if the string is found in the list, 0 not found, or invalid list
- */
-int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
-
-/**
- * fdt_stringlist_count - count the number of strings in a string list
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of a tree node
- * @property: name of the property containing the string list
- *
- * Return:
- * the number of strings in the given property
- * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
- * -FDT_ERR_NOTFOUND if the property does not exist
- */
-int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
-
-/**
- * fdt_stringlist_search - find a string in a string list and return its index
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of a tree node
- * @property: name of the property containing the string list
- * @string: string to look up in the string list
- *
- * Note that it is possible for this function to succeed on property values
- * that are not NUL-terminated. That's because the function will stop after
- * finding the first occurrence of @string. This can for example happen with
- * small-valued cell properties, such as #address-cells, when searching for
- * the empty string.
- *
- * return:
- * the index of the string in the list of strings
- * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
- * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
- * the given string
- */
-int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
- const char *string);
-
-/**
- * fdt_stringlist_get() - obtain the string at a given index in a string list
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of a tree node
- * @property: name of the property containing the string list
- * @index: index of the string to return
- * @lenp: return location for the string length or an error code on failure
- *
- * Note that this will successfully extract strings from properties with
- * non-NUL-terminated values. For example on small-valued cell properties
- * this function will return the empty string.
- *
- * If non-NULL, the length of the string (on success) or a negative error-code
- * (on failure) will be stored in the integer pointer to by lenp.
- *
- * Return:
- * A pointer to the string at the given index in the string list or NULL on
- * failure. On success the length of the string will be stored in the memory
- * location pointed to by the lenp parameter, if non-NULL. On failure one of
- * the following negative error codes will be returned in the lenp parameter
- * (if non-NULL):
- * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
- * -FDT_ERR_NOTFOUND if the property does not exist
- */
-const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
- const char *property, int index,
- int *lenp);
-
-/**********************************************************************/
-/* Read-only functions (addressing related) */
-/**********************************************************************/
-
-/**
- * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
- *
- * This is the maximum value for #address-cells, #size-cells and
- * similar properties that will be processed by libfdt. IEE1275
- * requires that OF implementations handle values up to 4.
- * Implementations may support larger values, but in practice higher
- * values aren't used.
- */
-#define FDT_MAX_NCELLS 4
-
-/**
- * fdt_address_cells - retrieve address size for a bus represented in the tree
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node to find the address size for
- *
- * When the node has a valid #address-cells property, returns its value.
- *
- * returns:
- * 0 <= n < FDT_MAX_NCELLS, on success
- * 2, if the node has no #address-cells property
- * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
- * #address-cells property
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_address_cells(const void *fdt, int nodeoffset);
-
-/**
- * fdt_size_cells - retrieve address range size for a bus represented in the
- * tree
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node to find the address range size for
- *
- * When the node has a valid #size-cells property, returns its value.
- *
- * returns:
- * 0 <= n < FDT_MAX_NCELLS, on success
- * 1, if the node has no #size-cells property
- * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
- * #size-cells property
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_size_cells(const void *fdt, int nodeoffset);
-
-
-/**********************************************************************/
-/* Write-in-place functions */
-/**********************************************************************/
-
-/**
- * fdt_setprop_inplace_namelen_partial - change a property's value,
- * but not its size
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @namelen: number of characters of name to consider
- * @idx: index of the property to change in the array
- * @val: pointer to data to replace the property value with
- * @len: length of the property value
- *
- * Identical to fdt_setprop_inplace(), but modifies the given property
- * starting from the given index, and using only the first characters
- * of the name. It is useful when you want to manipulate only one value of
- * an array and you have a string that doesn't end with \0.
- *
- * Return: 0 on success, negative libfdt error value otherwise
- */
-#ifndef SWIG /* Not available in Python */
-int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
- const char *name, int namelen,
- uint32_t idx, const void *val,
- int len);
-#endif
-
-/**
- * fdt_setprop_inplace - change a property's value, but not its size
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: pointer to data to replace the property value with
- * @len: length of the property value
- *
- * fdt_setprop_inplace() replaces the value of a given property with
- * the data in val, of length len. This function cannot change the
- * size of a property, and so will only work if len is equal to the
- * current length of the property.
- *
- * This function will alter only the bytes in the blob which contain
- * the given property value, and will not alter or move any other part
- * of the tree.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
- * -FDT_ERR_NOTFOUND, node does not have the named property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-#ifndef SWIG /* Not available in Python */
-int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
- const void *val, int len);
-#endif
-
-/**
- * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value to replace the property with
- *
- * fdt_setprop_inplace_u32() replaces the value of a given property
- * with the 32-bit integer value in val, converting val to big-endian
- * if necessary. This function cannot change the size of a property,
- * and so will only work if the property already exists and has length
- * 4.
- *
- * This function will alter only the bytes in the blob which contain
- * the given property value, and will not alter or move any other part
- * of the tree.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
- * -FDT_ERR_NOTFOUND, node does not have the named property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
- const char *name, uint32_t val)
-{
- fdt32_t tmp = cpu_to_fdt32(val);
- return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
-}
-
-/**
- * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 64-bit integer value to replace the property with
- *
- * fdt_setprop_inplace_u64() replaces the value of a given property
- * with the 64-bit integer value in val, converting val to big-endian
- * if necessary. This function cannot change the size of a property,
- * and so will only work if the property already exists and has length
- * 8.
- *
- * This function will alter only the bytes in the blob which contain
- * the given property value, and will not alter or move any other part
- * of the tree.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
- * -FDT_ERR_NOTFOUND, node does not have the named property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
- const char *name, uint64_t val)
-{
- fdt64_t tmp = cpu_to_fdt64(val);
- return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
-}
-
-/**
- * fdt_setprop_inplace_cell - change the value of a single-cell property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node containing the property
- * @name: name of the property to change the value of
- * @val: new value of the 32-bit cell
- *
- * This is an alternative name for fdt_setprop_inplace_u32()
- * Return: 0 on success, negative libfdt error number otherwise.
- */
-static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
- const char *name, uint32_t val)
-{
- return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
-}
-
-/**
- * fdt_nop_property - replace a property with nop tags
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to nop
- * @name: name of the property to nop
- *
- * fdt_nop_property() will replace a given property's representation
- * in the blob with FDT_NOP tags, effectively removing it from the
- * tree.
- *
- * This function will alter only the bytes in the blob which contain
- * the property, and will not alter or move any other part of the
- * tree.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOTFOUND, node does not have the named property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
-
-/**
- * fdt_nop_node - replace a node (subtree) with nop tags
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node to nop
- *
- * fdt_nop_node() will replace a given node's representation in the
- * blob, including all its subnodes, if any, with FDT_NOP tags,
- * effectively removing it from the tree.
- *
- * This function will alter only the bytes in the blob which contain
- * the node and its properties and subnodes, and will not alter or
- * move any other part of the tree.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_nop_node(void *fdt, int nodeoffset);
-
-/**********************************************************************/
-/* Sequential write functions */
-/**********************************************************************/
-
-/* fdt_create_with_flags flags */
-#define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
- /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
- * names in the fdt. This can result in faster creation times, but
- * a larger fdt. */
-
-#define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
-
-/**
- * fdt_create_with_flags - begin creation of a new fdt
- * @buf: pointer to memory allocated where fdt will be created
- * @bufsize: size of the memory space at fdt
- * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
- *
- * fdt_create_with_flags() begins the process of creating a new fdt with
- * the sequential write interface.
- *
- * fdt creation process must end with fdt_finish() to produce a valid fdt.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
- * -FDT_ERR_BADFLAGS, flags is not valid
- */
-int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
-
-/**
- * fdt_create - begin creation of a new fdt
- * @buf: pointer to memory allocated where fdt will be created
- * @bufsize: size of the memory space at fdt
- *
- * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
- */
-int fdt_create(void *buf, int bufsize);
-
-/**
- * fdt_resize - move and resize a device tree in sequential write state
- * @fdt: Pointer to the device tree to resize
- * @buf: Buffer where resized tree should be placed
- * @bufsize: Size of the buffer at @buf
- *
- * fdt_resize() moves the device tree blob from @fdt to @buf and
- * resizes it to fit in the new buffer size.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if @bufsize is too small
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE, standard meanings
- */
-int fdt_resize(void *fdt, void *buf, int bufsize);
-
-/**
- * fdt_add_reservemap_entry - add an entry to the memory reserve map
- * @fdt: Pointer to the device tree blob
- * @addr: Start address of the reserve map entry
- * @size: Size of the reserved region
- *
- * fdt_add_reservemap_entry() adds a memory reserve map entry to the
- * device tree blob during the sequential write process. This function
- * can only be called after fdt_create() and before fdt_finish_reservemap().
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if there is insufficient space in the blob
- * -FDT_ERR_BADSTATE, if not in the correct sequential write state
- */
-int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
-
-/**
- * fdt_finish_reservemap - complete the memory reserve map
- * @fdt: Pointer to the device tree blob
- *
- * fdt_finish_reservemap() completes the memory reserve map section
- * of the device tree blob during sequential write. After calling this
- * function, no more reserve map entries can be added and the blob
- * moves to the structure creation phase.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADSTATE, if not in the correct sequential write state
- */
-int fdt_finish_reservemap(void *fdt);
-
-/**
- * fdt_begin_node - start creation of a new node
- * @fdt: Pointer to the device tree blob
- * @name: Name of the node to create
- *
- * fdt_begin_node() starts the creation of a new node with the given
- * @name during sequential write. After calling this function, properties
- * can be added with fdt_property() and subnodes can be created with
- * additional fdt_begin_node() calls. The node must be completed with
- * fdt_end_node().
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if there is insufficient space in the blob
- * -FDT_ERR_BADSTATE, if not in the correct sequential write state
- */
-int fdt_begin_node(void *fdt, const char *name);
-
-/**
- * fdt_property - add a property to the current node
- * @fdt: Pointer to the device tree blob
- * @name: Name of the property to add
- * @val: Pointer to the property value
- * @len: Length of the property value in bytes
- *
- * fdt_property() adds a property with the given @name and value to
- * the current node during sequential write. This function can only
- * be called between fdt_begin_node() and fdt_end_node().
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if there is insufficient space in the blob
- * -FDT_ERR_BADSTATE, if not currently within a node
- */
-int fdt_property(void *fdt, const char *name, const void *val, int len);
-static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
-{
- fdt32_t tmp = cpu_to_fdt32(val);
- return fdt_property(fdt, name, &tmp, sizeof(tmp));
-}
-static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
-{
- fdt64_t tmp = cpu_to_fdt64(val);
- return fdt_property(fdt, name, &tmp, sizeof(tmp));
-}
-
-#ifndef SWIG /* Not available in Python */
-static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
-{
- return fdt_property_u32(fdt, name, val);
-}
-#endif
-
-/**
- * fdt_property_placeholder - add a new property and return a ptr to its value
- *
- * @fdt: pointer to the device tree blob
- * @name: name of property to add
- * @len: length of property value in bytes
- * @valp: returns a pointer to where the value should be placed
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_NOSPACE, standard meanings
- */
-int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
-
-#define fdt_property_string(fdt, name, str) \
- fdt_property(fdt, name, str, strlen(str)+1)
-
-/**
- * fdt_end_node - complete the current node
- * @fdt: Pointer to the device tree blob
- *
- * fdt_end_node() completes the current node during sequential write. This
- * function must be called to close each node started with
- * fdt_begin_node(). After calling this function, no more properties or subnodes
- * can be added to the node.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADSTATE, if not currently within a node
- */
-int fdt_end_node(void *fdt);
-
-/**
- * fdt_finish - complete device tree creation
- * @fdt: Pointer to the device tree blob
- *
- * fdt_finish() completes the device tree creation process started with
- * fdt_create(). This function finalizes the device tree blob and makes it ready
- * for use. After calling this function, the blob is complete and can be used
- * with libfdt read-only and read-write functions, but not with sequential write
- * functions.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADSTATE, if the sequential write process is incomplete
- */
-int fdt_finish(void *fdt);
-
-/**********************************************************************/
-/* Read-write functions */
-/**********************************************************************/
-
-/**
- * fdt_create_empty_tree - create an empty device tree
- * @buf: Buffer where the empty tree should be created
- * @bufsize: Size of the buffer at @buf
- *
- * fdt_create_empty_tree() creates a minimal empty device tree blob
- * in the given buffer. The tree contains only a root node with no
- * properties or subnodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if @bufsize is too small for even an empty tree
- */
-int fdt_create_empty_tree(void *buf, int bufsize);
-
-/**
- * fdt_open_into - move a device tree into a new buffer and make editable
- * @fdt: Pointer to the device tree to move
- * @buf: Buffer where the editable tree should be placed
- * @bufsize: Size of the buffer at @buf
- *
- * fdt_open_into() moves and reorganizes the device tree blob from @fdt
- * into @buf, converting it to a format suitable for read-write operations.
- * The new buffer should allow space for modifications.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, if @bufsize is too small
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_open_into(const void *fdt, void *buf, int bufsize);
-
-/**
- * fdt_pack - pack a device tree blob
- * @fdt: Pointer to the device tree blob
- *
- * fdt_pack() reorganizes the device tree blob to eliminate any free space
- * and pack it into the minimum possible size. This is useful after making
- * modifications that might have left gaps in the blob.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT, standard meanings
- */
-int fdt_pack(void *fdt);
-
-/**
- * fdt_add_mem_rsv - add one memory reserve map entry
- * @fdt: pointer to the device tree blob
- * @address: 64-bit start address of the reserve map entry
- * @size: 64-bit size of the reserved region
- *
- * Adds a reserve map entry to the given blob reserving a region at
- * address address of length size.
- *
- * This function will insert data into the reserve map and will
- * therefore change the indexes of some entries in the table.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new reservation entry
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
-
-/**
- * fdt_del_mem_rsv - remove a memory reserve map entry
- * @fdt: pointer to the device tree blob
- * @n: entry to remove
- *
- * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
- * the blob.
- *
- * This function will delete data from the reservation table and will
- * therefore change the indexes of some entries in the table.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
- * are less than n+1 reserve map entries)
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_del_mem_rsv(void *fdt, int n);
-
-/**
- * fdt_set_name - change the name of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of a node
- * @name: name to give the node
- *
- * fdt_set_name() replaces the name (including unit address, if any)
- * of the given node with the given string. NOTE: this function can't
- * efficiently check if the new name is unique amongst the given
- * node's siblings; results are undefined if this function is invoked
- * with a name equal to one of the given node's siblings.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
- * to contain the new name
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE, standard meanings
- */
-int fdt_set_name(void *fdt, int nodeoffset, const char *name);
-
-/**
- * fdt_setprop_namelen - create or change a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @namelen: length of the name
- * @val: pointer to data to set the property value to
- * @len: length of the property value
- *
- * fdt_setprop_namelen() sets the value of the named property in the given
- * node to the given value and length, creating the property if it
- * does not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name,
- int namelen, const void *val, int len);
-
-/**
- * fdt_setprop - create or change a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: pointer to data to set the property value to
- * @len: length of the property value
- *
- * fdt_setprop() sets the value of the named property in the given
- * node to the given value and length, creating the property if it
- * does not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop(void *fdt, int nodeoffset, const char *name,
- const void *val, int len)
-{
- return fdt_setprop_namelen(fdt, nodeoffset, name, strlen(name), val,
- len);
-}
-
-/**
- * fdt_setprop_placeholder_namelen - allocate space for a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @namelen: length of the name
- * @len: length of the property value
- * @prop_data: return pointer to property data
- *
- * fdt_setprop_placeholder_namelen() allocates the named property in the given node.
- * If the property exists it is resized. In either case a pointer to the
- * property data is returned.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name,
- int namelen, int len, void **prop_data);
-
-/**
- * fdt_setprop_placeholder - allocate space for a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @len: length of the property value
- * @prop_data: return pointer to property data
- *
- * fdt_setprop_placeholder() allocates the named property in the given node.
- * If the property exists it is resized. In either case a pointer to the
- * property data is returned.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_placeholder(void *fdt, int nodeoffset,
- const char *name, int len,
- void **prop_data)
-{
- return fdt_setprop_placeholder_namelen(fdt, nodeoffset, name,
- strlen(name), len, prop_data);
-}
-
-/**
- * fdt_setprop_u32 - set a property to a 32-bit integer
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value for the property (native endian)
- *
- * fdt_setprop_u32() sets the value of the named property in the given
- * node to the given 32-bit integer value (converting to big-endian if
- * necessary), or creates a new property with that value if it does
- * not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
- uint32_t val)
-{
- fdt32_t tmp = cpu_to_fdt32(val);
- return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
-}
-
-/**
- * fdt_setprop_u64 - set a property to a 64-bit integer
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 64-bit integer value for the property (native endian)
- *
- * fdt_setprop_u64() sets the value of the named property in the given
- * node to the given 64-bit integer value (converting to big-endian if
- * necessary), or creates a new property with that value if it does
- * not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
- uint64_t val)
-{
- fdt64_t tmp = cpu_to_fdt64(val);
- return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
-}
-
-/**
- * fdt_setprop_cell - set a property to a single cell value
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value for the property (native endian)
- *
- * This is an alternative name for fdt_setprop_u32()
- *
- * Return: 0 on success, negative libfdt error value otherwise.
- */
-static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
- uint32_t val)
-{
- return fdt_setprop_u32(fdt, nodeoffset, name, val);
-}
-
-/**
- * fdt_setprop_string - set a property to a string value
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @str: string value for the property
- *
- * fdt_setprop_string() sets the value of the named property in the
- * given node to the given string value (using the length of the
- * string to determine the new length of the property), or creates a
- * new property with that value if it does not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-#define fdt_setprop_string(fdt, nodeoffset, name, str) \
- fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
-
-/**
- * fdt_setprop_namelen_string - set a property to a string value
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @namelen: number of characters of name to consider
- * @str: string value for the property
- *
- * fdt_setprop_namelen_string() sets the value of the named property in the
- * given node to the given string value (using the length of the
- * string to determine the new length of the property), or creates a
- * new property with that value if it does not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-#define fdt_setprop_namelen_string(fdt, nodeoffset, name, namelen, str) \
- fdt_setprop_namelen((fdt), (nodeoffset), (name), (namelen), (str), \
- strlen(str) + 1)
-
-/**
- * fdt_setprop_empty - set a property to an empty value
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- *
- * fdt_setprop_empty() sets the value of the named property in the
- * given node to an empty (zero length) value, or creates a new empty
- * property if it does not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-#define fdt_setprop_empty(fdt, nodeoffset, name) \
- fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
-
-/**
- * fdt_appendprop - append to or create a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to append to
- * @val: pointer to data to append to the property value
- * @len: length of the data to append to the property value
- *
- * fdt_appendprop() appends the value to the named property in the
- * given node, creating the property if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
- const void *val, int len);
-
-/**
- * fdt_appendprop_u32 - append a 32-bit integer value to a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value to append to the property (native endian)
- *
- * fdt_appendprop_u32() appends the given 32-bit integer value
- * (converting to big-endian if necessary) to the value of the named
- * property in the given node, or creates a new property with that
- * value if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
- const char *name, uint32_t val)
-{
- fdt32_t tmp = cpu_to_fdt32(val);
- return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
-}
-
-/**
- * fdt_appendprop_u64 - append a 64-bit integer value to a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 64-bit integer value to append to the property (native endian)
- *
- * fdt_appendprop_u64() appends the given 64-bit integer value
- * (converting to big-endian if necessary) to the value of the named
- * property in the given node, or creates a new property with that
- * value if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
- const char *name, uint64_t val)
-{
- fdt64_t tmp = cpu_to_fdt64(val);
- return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
-}
-
-/**
- * fdt_appendprop_cell - append a single cell value to a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value to append to the property (native endian)
- *
- * This is an alternative name for fdt_appendprop_u32()
- *
- * Return: 0 on success, negative libfdt error value otherwise.
- */
-static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
- const char *name, uint32_t val)
-{
- return fdt_appendprop_u32(fdt, nodeoffset, name, val);
-}
-
-/**
- * fdt_appendprop_string - append a string to a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @str: string value to append to the property
- *
- * fdt_appendprop_string() appends the given string to the value of
- * the named property in the given node, or creates a new property
- * with that value if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain the new property value
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
- fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
-
-/**
- * fdt_appendprop_addrrange - append a address range property
- * @fdt: pointer to the device tree blob
- * @parent: offset of the parent node
- * @nodeoffset: offset of the node to add a property at
- * @name: name of property
- * @addr: start address of a given range
- * @size: size of a given range
- *
- * fdt_appendprop_addrrange() appends an address range value (start
- * address and size) to the value of the named property in the given
- * node, or creates a new property with that value if it does not
- * already exist.
- *
- * Cell sizes are determined by parent's #address-cells and #size-cells.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
- * #address-cells property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
- * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- * contain a new property
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
- const char *name, uint64_t addr, uint64_t size);
-
-/**
- * fdt_delprop - delete a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to nop
- * @name: name of the property to nop
- *
- * fdt_delprop() will delete the given property.
- *
- * This function will delete data from the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOTFOUND, node does not have the named property
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_delprop(void *fdt, int nodeoffset, const char *name);
-
-/**
- * fdt_add_subnode_namelen - creates a new node based on substring
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to create
- * @namelen: number of characters of name to consider
- *
- * Identical to fdt_add_subnode(), but use only the first @namelen
- * characters of @name as the name of the new node. This is useful for
- * creating subnodes based on a portion of a larger string, such as a
- * full path.
- *
- * Return: structure block offset of the created subnode (>=0),
- * negative libfdt error value otherwise
- */
-#ifndef SWIG /* Not available in Python */
-int fdt_add_subnode_namelen(void *fdt, int parentoffset,
- const char *name, int namelen);
-#endif
-
-/**
- * fdt_add_subnode - creates a new node
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to locate
- *
- * fdt_add_subnode() creates a new node as a subnode of the node at
- * structure block offset parentoffset, with the given name (which
- * should include the unit address, if any).
- *
- * This function will insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * structure block offset of the created subnode (>=0), on success
- * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
- * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
- * tag
- * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
- * the given name
- * -FDT_ERR_NOSPACE, if there is insufficient free space in the
- * blob to contain the new node
- * -FDT_ERR_NOSPACE
- * -FDT_ERR_BADLAYOUT
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
-
-/**
- * fdt_del_node - delete a node (subtree)
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node to nop
- *
- * fdt_del_node() will remove the given node, including all its
- * subnodes if any, from the blob.
- *
- * This function will delete data from the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_del_node(void *fdt, int nodeoffset);
-
-/**
- * fdt_overlay_apply - Applies a DT overlay on a base DT
- * @fdt: pointer to the base device tree blob
- * @fdto: pointer to the device tree overlay blob
- *
- * fdt_overlay_apply() will apply the given device tree overlay on the
- * given base device tree.
- *
- * Expect the base device tree to be modified, even if the function
- * returns an error.
- *
- * returns:
- * 0, on success
- * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
- * -FDT_ERR_NOTFOUND, the overlay points to some nonexistent nodes or
- * properties in the base DT
- * -FDT_ERR_BADPHANDLE,
- * -FDT_ERR_BADOVERLAY,
- * -FDT_ERR_NOPHANDLES,
- * -FDT_ERR_INTERNAL,
- * -FDT_ERR_BADLAYOUT,
- * -FDT_ERR_BADMAGIC,
- * -FDT_ERR_BADOFFSET,
- * -FDT_ERR_BADPATH,
- * -FDT_ERR_BADVERSION,
- * -FDT_ERR_BADSTRUCTURE,
- * -FDT_ERR_BADSTATE,
- * -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_overlay_apply(void *fdt, void *fdto);
-
-/**
- * fdt_overlay_target_offset - retrieves the offset of a fragment's target
- * @fdt: Base device tree blob
- * @fdto: Device tree overlay blob
- * @fragment_offset: node offset of the fragment in the overlay
- * @pathp: pointer which receives the path of the target (or NULL)
- *
- * fdt_overlay_target_offset() retrieves the target offset in the base
- * device tree of a fragment, no matter how the actual targeting is
- * done (through a phandle or a path)
- *
- * returns:
- * the targeted node offset in the base device tree
- * Negative error code on error
- */
-int fdt_overlay_target_offset(const void *fdt, const void *fdto,
- int fragment_offset, char const **pathp);
-
-/**********************************************************************/
-/* Debugging / informational functions */
-/**********************************************************************/
-
-/**
- * fdt_strerror - return string description of error code
- * @errval: Error code returned by a libfdt function
- *
- * fdt_strerror() returns a string description of the error code passed
- * in @errval.
- *
- * returns:
- * pointer to a string describing the error code
- */
-const char *fdt_strerror(int errval);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LIBFDT_H */
diff --git a/scripts/dtc/libfdt/libfdt_env.h b/scripts/dtc/libfdt/libfdt_env.h
deleted file mode 100644
index 5580b48..0000000
--- a/scripts/dtc/libfdt/libfdt_env.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
-#ifndef LIBFDT_ENV_H
-#define LIBFDT_ENV_H
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- * Copyright 2012 Kim Phillips, Freescale Semiconductor.
- */
-
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-#ifdef __CHECKER__
-#define FDT_FORCE __attribute__((force))
-#define FDT_BITWISE __attribute__((bitwise))
-#else
-#define FDT_FORCE
-#define FDT_BITWISE
-#endif
-
-typedef uint16_t FDT_BITWISE fdt16_t;
-typedef uint32_t FDT_BITWISE fdt32_t;
-typedef uint64_t FDT_BITWISE fdt64_t;
-
-#define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n])
-#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))
-#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \
- (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))
-#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \
- (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \
- (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \
- (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))
-
-static inline uint16_t fdt16_to_cpu(fdt16_t x)
-{
- return (FDT_FORCE uint16_t)CPU_TO_FDT16(x);
-}
-static inline fdt16_t cpu_to_fdt16(uint16_t x)
-{
- return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x);
-}
-
-static inline uint32_t fdt32_to_cpu(fdt32_t x)
-{
- return (FDT_FORCE uint32_t)CPU_TO_FDT32(x);
-}
-static inline fdt32_t cpu_to_fdt32(uint32_t x)
-{
- return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x);
-}
-
-static inline uint64_t fdt64_to_cpu(fdt64_t x)
-{
- return (FDT_FORCE uint64_t)CPU_TO_FDT64(x);
-}
-static inline fdt64_t cpu_to_fdt64(uint64_t x)
-{
- return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x);
-}
-#undef CPU_TO_FDT64
-#undef CPU_TO_FDT32
-#undef CPU_TO_FDT16
-#undef EXTRACT_BYTE
-
-#endif /* LIBFDT_ENV_H */
diff --git a/scripts/dtc/libfdt/libfdt_internal.h b/scripts/dtc/libfdt/libfdt_internal.h
deleted file mode 100644
index 0e103ca..0000000
--- a/scripts/dtc/libfdt/libfdt_internal.h
+++ /dev/null
@@ -1,202 +0,0 @@
-/* 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) \
- { \
- if (!can_assume(VALID_DTB)) { \
- 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_PERFECT.
- */
-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 */
diff --git a/scripts/extract-asm-offsets.sed b/scripts/extract-asm-offsets.sed
deleted file mode 100644
index c97ec2c..0000000
--- a/scripts/extract-asm-offsets.sed
+++ /dev/null
@@ -1,18 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Extract `->SYM val COMMENT` markers emitted by inline asm in
-# asm-offsets.c into proper `#define SYM val /* COMMENT */` lines.
-# 1:1 with Linux scripts/Makefile.lib `sed-offsets`.
-#
-# Input : assembly source produced by `gcc -S asm-offsets.c` —
-# inline asm emits lines like
-# .ascii "->KERNEL_MAP_VIRT_ADDR 0 offsetof(...)"
-# Output : header fragment for include/generated/asm-offsets.h
-#
-# Step 1 unwraps the `.ascii "..."` directive so the actual payload
-# (starting with `->`) is exposed. Steps 2-4 then rewrite into a
-# proper #define.
-s:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:
-/^->/{s:->#\(.*\):/* \1 */:;
- s:^->\([^ ]*\) [\$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:;
- s:->::;
- p;}
diff --git a/scripts/gen_initramfs.sh b/scripts/gen_initramfs.sh
deleted file mode 100755
index 8ad0cd7..0000000
--- a/scripts/gen_initramfs.sh
+++ /dev/null
@@ -1,250 +0,0 @@
-#!/bin/sh
-# Copyright (C) Martin Schlemmer <azarah@nosferatu.za.org>
-# Copyright (C) 2006 Sam Ravnborg <sam@ravnborg.org>
-#
-# Released under the terms of the GNU GPL
-#
-# Generate a cpio packed initramfs. It uses gen_init_cpio to generate
-# the cpio archive.
-# This script assumes that gen_init_cpio is located in usr/ directory
-
-# error out on errors
-set -e
-
-usage() {
-cat << EOF
-Usage:
-$0 [-o <file>] [-l <dep_list>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
- -o <file> Create initramfs file named <file> by using gen_init_cpio
- -l <dep_list> Create dependency list named <dep_list>
- -u <uid> User ID to map to user ID 0 (root).
- <uid> is only meaningful if <cpio_source> is a
- directory. "squash" forces all files to uid 0.
- -g <gid> Group ID to map to group ID 0 (root).
- <gid> is only meaningful if <cpio_source> is a
- directory. "squash" forces all files to gid 0.
- -d <date> Use date for all file mtime values
- <cpio_source> File list or directory for cpio archive.
- If <cpio_source> is a .cpio file it will be used
- as direct input to initramfs.
-
-All options except -o and -l may be repeated and are interpreted
-sequentially and immediately. -u and -g states are preserved across
-<cpio_source> options so an explicit "-u 0 -g 0" is required
-to reset the root/group mapping.
-EOF
-}
-
-# awk style field access
-# $1 - field number; rest is argument string
-field() {
- shift $1 ; echo $1
-}
-
-filetype() {
- local argv1="$1"
-
- # symlink test must come before file test
- if [ -L "${argv1}" ]; then
- echo "slink"
- elif [ -f "${argv1}" ]; then
- echo "file"
- elif [ -d "${argv1}" ]; then
- echo "dir"
- elif [ -b "${argv1}" -o -c "${argv1}" ]; then
- echo "nod"
- elif [ -p "${argv1}" ]; then
- echo "pipe"
- elif [ -S "${argv1}" ]; then
- echo "sock"
- else
- echo "invalid"
- fi
- return 0
-}
-
-print_mtime() {
- local my_mtime="0"
-
- if [ -e "$1" ]; then
- my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1)
- fi
-
- echo "# Last modified: ${my_mtime}" >> $cpio_list
- echo "" >> $cpio_list
-}
-
-list_parse() {
- if [ -z "$dep_list" -o -L "$1" ]; then
- return
- fi
- echo "$1" | sed 's/:/\\:/g; s/$/ \\/' >> $dep_list
-}
-
-# for each file print a line in following format
-# <filetype> <name> <path to file> <octal mode> <uid> <gid>
-# for links, devices etc the format differs. See gen_init_cpio for details
-parse() {
- local location="$1"
- local name="/${location#${srcdir}}"
- # change '//' into '/'
- name=$(echo "$name" | sed -e 's://*:/:g')
- local mode="$2"
- local uid="$3"
- local gid="$4"
- local ftype=$(filetype "${location}")
- # remap uid/gid to 0 if necessary
- [ "$root_uid" = "squash" ] && uid=0 || [ "$uid" -eq "$root_uid" ] && uid=0
- [ "$root_gid" = "squash" ] && gid=0 || [ "$gid" -eq "$root_gid" ] && gid=0
- local str="${mode} ${uid} ${gid}"
-
- [ "${ftype}" = "invalid" ] && return 0
- [ "${location}" = "${srcdir}" ] && return 0
-
- case "${ftype}" in
- "file")
- str="${ftype} ${name} ${location} ${str}"
- ;;
- "nod")
- local dev="`LC_ALL=C ls -l "${location}"`"
- local maj=`field 5 ${dev}`
- local min=`field 6 ${dev}`
- maj=${maj%,}
-
- [ -b "${location}" ] && dev="b" || dev="c"
-
- str="${ftype} ${name} ${str} ${dev} ${maj} ${min}"
- ;;
- "slink")
- local target=`readlink "${location}"`
- str="${ftype} ${name} ${target} ${str}"
- ;;
- *)
- str="${ftype} ${name} ${str}"
- ;;
- esac
-
- echo "${str}" >> $cpio_list
-
- return 0
-}
-
-unknown_option() {
- printf "ERROR: unknown option \"$arg\"\n" >&2
- printf "If the filename validly begins with '-', " >&2
- printf "then it must be prefixed\n" >&2
- printf "by './' so that it won't be interpreted as an option." >&2
- printf "\n" >&2
- usage >&2
- exit 1
-}
-
-header() {
- printf "\n#####################\n# $1\n" >> $cpio_list
-}
-
-# process one directory (incl sub-directories)
-dir_filelist() {
- header "$1"
-
- srcdir=$(echo "$1" | sed -e 's://*:/:g')
- dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LC_ALL=C sort)
-
- # If $dirlist is only one line, then the directory is empty
- if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then
- print_mtime "$1"
-
- echo "${dirlist}" | \
- while read x; do
- list_parse $x
- parse $x
- done
- fi
-}
-
-input_file() {
- source="$1"
- if [ -f "$1" ]; then
- # If a regular file is specified, assume it is in
- # gen_init_cpio format
- header "$1"
- print_mtime "$1" >> $cpio_list
- cat "$1" >> $cpio_list
- if [ -n "$dep_list" ]; then
- echo "$1 \\" >> $dep_list
- cat "$1" | while read type dir file perm ; do
- if [ "$type" = "file" ]; then
- echo "$file \\" >> $dep_list
- fi
- done
- fi
- elif [ -d "$1" ]; then
- # If a directory is specified then add all files in it to fs
- dir_filelist "$1"
- else
- echo " ${prog}: Cannot open '$1'" >&2
- exit 1
- fi
-}
-
-prog=$0
-root_uid=0
-root_gid=0
-dep_list=
-timestamp=
-cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)
-# gen_init_cpio writes to stdout by default
-output=""
-
-trap "rm -f $cpio_list" EXIT
-
-while [ $# -gt 0 ]; do
- arg="$1"
- shift
- case "$arg" in
- "-l") # files included in initramfs - used by kbuild
- dep_list="$1"
- echo "deps_initramfs := \\" > $dep_list
- shift
- ;;
- "-o") # generate cpio image named $1
- output="-o $1"
- shift
- ;;
- "-u") # map $1 to uid=0 (root)
- root_uid="$1"
- [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0)
- shift
- ;;
- "-g") # map $1 to gid=0 (root)
- root_gid="$1"
- [ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0)
- shift
- ;;
- "-d") # date for file mtimes
- timestamp="$(date -d"$1" +%s || :)"
- if test -n "$timestamp"; then
- timestamp="-t $timestamp"
- fi
- shift
- ;;
- "-h")
- usage
- exit 0
- ;;
- *)
- case "$arg" in
- "-"*)
- unknown_option
- ;;
- *) # input file/dir - process it
- input_file "$arg"
- ;;
- esac
- ;;
- esac
-done
-
-# If output_file is set we will generate cpio archive
-# we are careful to delete tmp files
-"${GEN_INIT_CPIO:-usr/gen_init_cpio}" $output $timestamp $cpio_list