* refs/heads/tmp-20ddb25 Linux 4.4.116 ftrace: Remove incorrect setting of glob search field mn10300/misalignment: Use SIGSEGV SEGV_MAPERR to report a failed user copy ovl: fix failure to fsync lower dir ACPI: sbshc: remove raw pointer from printk() message nvme: Fix managing degraded controllers btrfs: Handle btrfs_set_extent_delalloc failure in fixup worker pktcdvd: Fix pkt_setup_dev() error path EDAC, octeon: Fix an uninitialized variable warning xtensa: fix futex_atomic_cmpxchg_inatomic alpha: fix reboot on Avanti platform alpha: fix crash if pthread_create races with signal delivery signal/sh: Ensure si_signo is initialized in do_divide_error signal/openrisc: Fix do_unaligned_access to send the proper signal Bluetooth: btusb: Restore QCA Rome suspend/resume fix with a "rewritten" version Revert "Bluetooth: btusb: fix QCA Rome suspend/resume" Bluetooth: btsdio: Do not bind to non-removable BCM43341 HID: quirks: Fix keyboard + touchpad on Toshiba Click Mini not working kernel/async.c: revert "async: simplify lowest_in_progress()" media: cxusb, dib0700: ignore XC2028_I2C_FLUSH media: ts2020: avoid integer overflows on 32 bit machines watchdog: imx2_wdt: restore previous timeout after suspend+resume KVM: nVMX: Fix races when sending nested PI while dest enters/leaves L2 arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls crypto: caam - fix endless loop when DECO acquire fails media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic media: v4l2-compat-ioctl32.c: don't copy back the result for certain errors media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32 media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha media: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32 media: v4l2-compat-ioctl32.c: avoid sizeof(type) media: v4l2-compat-ioctl32.c: move 'helper' functions to __get/put_v4l2_format32 media: v4l2-compat-ioctl32.c: fix the indentation media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF vb2: V4L2_BUF_FLAG_DONE is set after DQBUF media: v4l2-ioctl.c: don't copy back the result for -ENOTTY nsfs: mark dentry with DCACHE_RCUACCESS crypto: poly1305 - remove ->setkey() method crypto: cryptd - pass through absence of ->setkey() crypto: hash - introduce crypto_hash_alg_has_setkey() ahci: Add Intel Cannon Lake PCH-H PCI ID ahci: Add PCI ids for Intel Bay Trail, Cherry Trail and Apollo Lake AHCI ahci: Annotate PCI ids for mobile Intel chipsets as such kernfs: fix regression in kernfs_fop_write caused by wrong type NFS: reject request for id_legacy key without auxdata NFS: commit direct writes even if they fail partially NFS: Add a cond_resched() to nfs_commit_release_pages() nfs/pnfs: fix nfs_direct_req ref leak when i/o falls back to the mds ubi: block: Fix locking for idr_alloc/idr_remove mtd: nand: sunxi: Fix ECC strength choice mtd: nand: Fix nand_do_read_oob() return value mtd: nand: brcmnand: Disable prefetch by default mtd: cfi: convert inline functions to macros media: dvb-usb-v2: lmedm04: move ts2020 attach to dm04_lme2510_tuner media: dvb-usb-v2: lmedm04: Improve logic checking of warm start dccp: CVE-2017-8824: use-after-free in DCCP code sched/rt: Up the root domain ref count when passing it around via IPIs sched/rt: Use container_of() to get root domain in rto_push_irq_work_func() usb: gadget: uvc: Missing files for configfs interface posix-timer: Properly check sigevent->sigev_notify netfilter: nf_queue: Make the queue_handler pernet kaiser: fix compile error without vsyscall x86/kaiser: fix build error with KASAN && !FUNCTION_GRAPH_TRACER dmaengine: dmatest: fix container_of member in dmatest_callback CIFS: zero sensitive data when freeing cifs: Fix autonegotiate security settings mismatch cifs: Fix missing put_xid in cifs_file_strict_mmap powerpc/pseries: include linux/types.h in asm/hvcall.h x86/microcode: Do the family check first x86/microcode/AMD: Do not load when running on a hypervisor crypto: tcrypt - fix S/G table for test_aead_speed() don't put symlink bodies in pagecache into highmem KEYS: encrypted: fix buffer overread in valid_master_desc() media: soc_camera: soc_scale_crop: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE vhost_net: stop device during reset owner tcp: release sk_frag.page in tcp_disconnect r8169: fix RTL8168EP take too long to complete driver initialization. qlcnic: fix deadlock bug net: igmp: add a missing rcu locking section ip6mr: fix stale iterator x86/asm: Fix inline asm call constraints for GCC 4.4 drm: rcar-du: Fix race condition when disabling planes at CRTC stop drm: rcar-du: Use the VBK interrupt for vblank events ASoC: rsnd: avoid duplicate free_irq() ASoC: rsnd: don't call free_irq() on Parent SSI ASoC: simple-card: Fix misleading error message net: cdc_ncm: initialize drvflags before usage usbip: fix 3eee23c3ec14 tcp_socket address still in the status file usbip: vhci_hcd: clear just the USB_PORT_STAT_POWER bit ASoC: pcm512x: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE powerpc/64s: Allow control of RFI flush via debugfs powerpc/64s: Wire up cpu_show_meltdown() powerpc/powernv: Check device-tree for RFI flush settings powerpc/pseries: Query hypervisor for RFI flush settings powerpc/64s: Support disabling RFI flush with no_rfi_flush and nopti powerpc/64s: Add support for RFI flush of L1-D cache powerpc/64s: Convert slb_miss_common to use RFI_TO_USER/KERNEL powerpc/64: Convert the syscall exit path to use RFI_TO_USER/KERNEL powerpc/64: Convert fast_exception_return to use RFI_TO_USER/KERNEL powerpc/64s: Simple RFI macro conversions powerpc/64: Add macros for annotating the destination of rfid/hrfid powerpc/pseries: Add H_GET_CPU_CHARACTERISTICS flags & wrapper powerpc: Simplify module TOC handling powerpc: Fix VSX enabling/flushing to also test MSR_FP and MSR_VEC powerpc/64: Fix flush_(d|i)cache_range() called from modules powerpc/bpf/jit: Disable classic BPF JIT on ppc64le BACKPORT: xfrm: Fix return value check of copy_sec_ctx. time: Fix ktime_get_raw() incorrect base accumulation sched/fair: prevent possible infinite loop in sched_group_energy UPSTREAM: MIPS: Fix build of compressed image ANDROID: qtaguid: Fix the UAF probelm with tag_ref_tree UPSTREAM: ANDROID: binder: remove waitqueue when thread exits. UPSTREAM: arm64/efi: Make strnlen() available to the EFI namespace UPSTREAM: ARM: boot: Add an implementation of strnlen for libfdt ANDROID: MIPS: Add ranchu[32r5|32r6|64]_defconfig FROMLIST: tty: goldfish: Enable 'earlycon' only if built-in FROMLIST: MIPS: ranchu: Add Ranchu as a new generic-based board FROMLIST: MIPS: Add noexec=on|off kernel parameter FROMLIST: MIPS: CPC: Map registers using DT in mips_cpc_default_phys_base() FROMLIST: dt-bindings: Document mti,mips-cpc binding FROMLIST: MIPS: math-emu: Mark fall throughs in switch statements with a comment FROMLIST: MIPS: math-emu: Avoid multiple assignment FROMLIST: MIPS: math-emu: Avoid an assignment within if statement condition FROMLIST: MIPS: math-emu: Declare function srl128() as static FROMLIST: MIPS: math-emu: Avoid definition duplication for macro DPXMULT() FROMLIST: MIPS: math-emu: Remove an unnecessary header inclusion UPSTREAM: scripts/dtc: Update to upstream version 0931cea3ba20 UPSTREAM: scripts/dtc: dt_to_config - kernel config options for a devicetree UPSTREAM: scripts/dtc: Update to upstream version 53bf130b1cdd UPSTREAM: scripts/dtc: Update to upstream commit b06e55c88b9b UPSTREAM: scripts/dtc: dtx_diff - add info to error message UPSTREAM: dtc: create tool to diff device trees UPSTREAM: config: android-base: disable CONFIG_NFSD and CONFIG_NFS_FS UPSTREAM: config: android-base: add CGROUP_BPF UPSTREAM: config: android-base: add CONFIG_MODULES option UPSTREAM: config: android-base: add CONFIG_IKCONFIG option UPSTREAM: config: android-base: disable CONFIG_USELIB and CONFIG_FHANDLE UPSTREAM: config: android-base: enable hardened usercopy and kernel ASLR UPSTREAM: config: android: enable CONFIG_SECCOMP UPSTREAM: config: android: set SELinux as default security mode UPSTREAM: config: android: move device mapper options to recommended UPSTREAM: config/android: Remove CONFIG_IPV6_PRIVACY UPSTREAM: config: add android config fragments BACKPORT: MIPS: generic: Add a MAINTAINERS entry BACKPORT: irqchip/irq-goldfish-pic: Add Goldfish PIC driver UPSTREAM: dt-bindings/goldfish-pic: Add device tree binding for Goldfish PIC driver UPSTREAM: MIPS: Allow storing pgd in C0_CONTEXT for MIPSr6 UPSTREAM: MIPS: CPS: Handle spurious VP starts more gracefully UPSTREAM: MIPS: CPS: Handle cores not powering down more gracefully UPSTREAM: MIPS: CPS: Prevent multi-core with dcache aliasing UPSTREAM: MIPS: CPS: Select CONFIG_SYS_SUPPORTS_SCHED_SMT for MIPSr6 UPSTREAM: MIPS: CM: WARN on attempt to lock invalid VP, not BUG UPSTREAM: MIPS: CM: Avoid per-core locking with CM3 & higher UPSTREAM: MIPS: smp-cps: Avoid BUG() when offlining pre-r6 CPUs UPSTREAM: MIPS: smp-cps: Add support for CPU hotplug of MIPSr6 processors UPSTREAM: MIPS: generic: Bump default NR_CPUS to 16 UPSTREAM: MIPS: pm-cps: Change FSB workaround to CPU blacklist UPSTREAM: MIPS: Fix early CM probing UPSTREAM: MIPS: smp-cps: Stop printing EJTAG exceptions to UART UPSTREAM: MIPS: smp-cps: Add nothreads kernel parameter UPSTREAM: MIPS: smp-cps: Support MIPSr6 Virtual Processors UPSTREAM: MIPS: smp-cps: Skip core setup if coherent UPSTREAM: MIPS: smp-cps: Pull boot config retrieval out of mips_cps_boot_vpes UPSTREAM: MIPS: smp-cps: Pull cache init into a function UPSTREAM: MIPS: smp-cps: Ensure our VP ident calculation is correct UPSTREAM: irqchip: mips-gic: Provide VP ID accessor UPSTREAM: irqchip: mips-gic: Use HW IDs for VPE_OTHER_ADDR UPSTREAM: MIPS: CM: Fix mips_cm_max_vp_width for UP kernels UPSTREAM: MIPS: CM: Add CM GCR_BEV_BASE accessors UPSTREAM: MIPS: CPC: Add start, stop and running CM3 CPC registers UPSTREAM: MIPS: pm-cps: Avoid offset overflow on MIPSr6 UPSTREAM: MIPS: traps: Make sure secondary cores have a sane ebase register UPSTREAM: MIPS: Detect MIPSr6 Virtual Processor support UPSTREAM: Documentation: Add device tree binding for Goldfish FB driver UPSTREAM: MIPS: math-emu: Use preferred flavor of unsigned integer declarations UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.D: Fix accuracy (64-bit case) UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.S: Fix accuracy (32-bit case) UPSTREAM: MIPS: Update Goldfish RTC driver maintainer email address UPSTREAM: MIPS: Update RINT emulation maintainer email address UPSTREAM: MIPS: math-emu: do not use bools for arithmetic UPSTREAM: rtc: goldfish: Add RTC driver for Android emulator BACKPORT: dt-bindings: Add device tree binding for Goldfish RTC driver UPSTREAM: tty: goldfish: Implement support for kernel 'earlycon' parameter UPSTREAM: tty: goldfish: Use streaming DMA for r/w operations on Ranchu platforms UPSTREAM: tty: goldfish: Refactor constants to better reflect their nature UPSTREAM: MIPS: math-emu: Add FP emu debugfs stats for individual instructions UPSTREAM: MIPS: math-emu: Add FP emu debugfs clear functionality UPSTREAM: MIPS: math-emu: Add FP emu debugfs statistics for branches BACKPORT: MIPS: math-emu: CLASS.D: Zero bits 32-63 of the result BACKPORT: MIPS: math-emu: RINT.<D|S>: Fix several problems by reimplementation UPSTREAM: MIPS: math-emu: CMP.Sxxx.<D|S>: Prevent occurrences of SIGILL crashes UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Clean up "maddf_flags" enumeration UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix some cases of zero inputs UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix some cases of infinite inputs UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation UPSTREAM: tty: goldfish: Fix a parameter of a call to free_irq UPSTREAM: MIPS: VDSO: Fix clobber lists in fallback code paths UPSTREAM: MIPS: VDSO: Fix a mismatch between comment and preprocessor constant UPSTREAM: MIPS: VDSO: Add implementation of gettimeofday() fallback UPSTREAM: MIPS: VDSO: Add implementation of clock_gettime() fallback UPSTREAM: MIPS: VDSO: Fix conversions in do_monotonic()/do_monotonic_coarse() UPSTREAM: MIPS: unaligned: Add DSP lwx & lhx missaligned access support UPSTREAM: MIPS: build: Fix "-modd-spreg" switch usage when compiling for mips32r6 UPSTREAM: MIPS: cmdline: Add support for 'memmap' parameter UPSTREAM: MIPS: math-emu: Handle zero accumulator case in MADDF and MSUBF separately UPSTREAM: MIPS: Support per-device DMA coherence UPSTREAM: MIPS: dma-default: Don't check hw_coherentio if device is non-coherent UPSTREAM: MIPS: Sanitise coherentio semantics UPSTREAM: MIPS: CPC: Provide default mips_cpc_default_phys_base to ignore CPC UPSTREAM: MIPS: generic: Introduce generic DT-based board support UPSTREAM: MIPS: Support generating Flattened Image Trees (.itb) UPSTREAM: MIPS: Allow emulation for unaligned [LS]DXC1 instructions UPSTREAM: MIPS: math-emu: Fix BC1EQZ and BC1NEZ condition handling UPSTREAM: MIPS: r2-on-r6-emu: Clear BLTZALL and BGEZALL debugfs counters UPSTREAM: MIPS: r2-on-r6-emu: Fix BLEZL and BGTZL identification UPSTREAM: MIPS: remove aliasing alignment if HW has antialising support BACKPORT: MIPS: store the appended dtb address in a variable UPSTREAM: MIPS: Fix FCSR Cause bit handling for correct SIGFPE issue UPSTREAM: MIPS: kernel: Audit and remove any unnecessary uses of module.h UPSTREAM: MIPS: c-r4k: Fix sigtramp SMP call to use kmap UPSTREAM: MIPS: c-r4k: Fix protected_writeback_scache_line for EVA UPSTREAM: MIPS: Spelling fix lets -> let's UPSTREAM: MIPS: R6: Fix typo UPSTREAM: MIPS: traps: Correct the SIGTRAP debug ABI in `do_watch' and `do_trap_or_bp' UPSTREAM: MIPS: inst.h: Rename cbcond{0,1}_op to pop{1,3}0_op UPSTREAM: MIPS: inst.h: Rename b{eq,ne}zcji[al]c_op to pop{6,7}6_op UPSTREAM: MIPS: math-emu: Fix m{add,sub}.s shifts UPSTREAM: MIPS: inst: Declare fsel_op for sel.fmt instruction UPSTREAM: MIPS: math-emu: Fix code indentation UPSTREAM: MIPS: math-emu: Fix bit-width in ieee754dp_{mul, maddf, msubf} comments UPSTREAM: MIPS: math-emu: Add z argument macros UPSTREAM: MIPS: math-emu: Unify ieee754dp_m{add,sub}f UPSTREAM: MIPS: math-emu: Unify ieee754sp_m{add,sub}f UPSTREAM: MIPS: math-emu: Emulate MIPSr6 sel.fmt instruction UPSTREAM: MIPS: math-emu: Fix BC1{EQ,NE}Z emulation UPSTREAM: MIPS: math-emu: Always propagate sNaN payload in quieting UPSTREAM: MIPS: Fix misspellings in comments. UPSTREAM: MIPS: math-emu: Add IEEE Std 754-2008 NaN encoding emulation UPSTREAM: MIPS: math-emu: Add IEEE Std 754-2008 ABS.fmt and NEG.fmt emulation UPSTREAM: MIPS: non-exec stack & heap when non-exec PT_GNU_STACK is present UPSTREAM: MIPS: Add IEEE Std 754 conformance mode selection UPSTREAM: MIPS: Determine the presence of IEEE Std 754-2008 features UPSTREAM: MIPS: Define the legacy-NaN and 2008-NaN features UPSTREAM: MIPS: ELF: Interpret the NAN2008 file header flag UPSTREAM: ELF: Also pass any interpreter's file header to `arch_check_elf' UPSTREAM: MIPS: Use a union to access the ELF file header UPSTREAM: MIPS: Fix delay slot emulation count in debugfs BACKPORT: exit_thread: accept a task parameter to be exited UPSTREAM: mn10300: let exit_fpu accept a task UPSTREAM: MIPS: Use per-mm page to execute branch delay slot instructions BACKPORT: s390: get rid of exit_thread() BACKPORT: exit_thread: remove empty bodies UPSTREAM: MIPS: Make flush_thread UPSTREAM: MIPS: Properly disable FPU in start_thread() UPSTREAM: MIPS: Select CONFIG_HANDLE_DOMAIN_IRQ and make it work. UPSTREAM: MIPS: math-emu: Fix typo UPSTREAM: MIPS: math-emu: dsemul: Remove an unused bit in ADDIUPC emulation UPSTREAM: MIPS: math-emu: dsemul: Reduce `get_isa16_mode' clutter UPSTREAM: MIPS: math-emu: dsemul: Correct description of the emulation frame UPSTREAM: MIPS: math-emu: Correct the emulation of microMIPS ADDIUPC instruction UPSTREAM: MIPS: math-emu: Make microMIPS branch delay slot emulation work UPSTREAM: MIPS: math-emu: dsemul: Fix ill formatting of microMIPS part UPSTREAM: MIPS: math-emu: Correctly handle NOP emulation Conflicts: drivers/irqchip/Kconfig drivers/irqchip/Makefile drivers/media/v4l2-core/v4l2-compat-ioctl32.c Change-Id: I98374358ab24ce80dba3afa2f4562c71f45b7aab Signed-off-by: Srinivasarao P <spathi@codeaurora.org>
490 lines
13 KiB
C
490 lines
13 KiB
C
/*
|
|
* libfdt - Flat Device Tree manipulation
|
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
|
*
|
|
* libfdt is dual licensed: you can use it either under the terms of
|
|
* the GPL, or the BSD license, at your option.
|
|
*
|
|
* a) This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this library; if not, write to the Free
|
|
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
* MA 02110-1301 USA
|
|
*
|
|
* Alternatively,
|
|
*
|
|
* b) Redistribution and use in source and binary forms, with or
|
|
* without modification, are permitted provided that the following
|
|
* conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer in the documentation and/or other materials
|
|
* provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
#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 int _fdt_rw_check_header(void *fdt)
|
|
{
|
|
FDT_CHECK_HEADER(fdt);
|
|
|
|
if (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;
|
|
if (fdt_version(fdt) > 17)
|
|
fdt_set_version(fdt, 17);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#define FDT_RW_CHECK_HEADER(fdt) \
|
|
{ \
|
|
int __err; \
|
|
if ((__err = _fdt_rw_check_header(fdt)) != 0) \
|
|
return __err; \
|
|
}
|
|
|
|
static inline 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;
|
|
char *end = (char *)fdt + _fdt_data_size(fdt);
|
|
|
|
if (((p + oldlen) < p) || ((p + oldlen) > end))
|
|
return -FDT_ERR_BADOFFSET;
|
|
if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt))
|
|
return -FDT_ERR_BADOFFSET;
|
|
if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
|
|
return -FDT_ERR_NOSPACE;
|
|
memmove(p + newlen, p + oldlen, end - 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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
static int _fdt_find_add_string(void *fdt, const char *s)
|
|
{
|
|
char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
|
|
const char *p;
|
|
char *new;
|
|
int len = strlen(s) + 1;
|
|
int err;
|
|
|
|
p = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s);
|
|
if (p)
|
|
/* found it */
|
|
return (p - strtab);
|
|
|
|
new = strtab + fdt_size_dt_strings(fdt);
|
|
err = _fdt_splice_string(fdt, len);
|
|
if (err)
|
|
return err;
|
|
|
|
memcpy(new, s, len);
|
|
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_CHECK_HEADER(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_CHECK_HEADER(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 len, struct fdt_property **prop)
|
|
{
|
|
int oldlen;
|
|
int err;
|
|
|
|
*prop = fdt_get_property_w(fdt, nodeoffset, name, &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 len, struct fdt_property **prop)
|
|
{
|
|
int proplen;
|
|
int nextoffset;
|
|
int namestroff;
|
|
int err;
|
|
|
|
if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)
|
|
return nextoffset;
|
|
|
|
namestroff = _fdt_find_add_string(fdt, name);
|
|
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)
|
|
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_CHECK_HEADER(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(void *fdt, int nodeoffset, const char *name,
|
|
const void *val, int len)
|
|
{
|
|
struct fdt_property *prop;
|
|
int err;
|
|
|
|
FDT_RW_CHECK_HEADER(fdt);
|
|
|
|
err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop);
|
|
if (err == -FDT_ERR_NOTFOUND)
|
|
err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
|
|
if (err)
|
|
return err;
|
|
|
|
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_CHECK_HEADER(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, 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_CHECK_HEADER(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_CHECK_HEADER(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 */
|
|
fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
|
|
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_CHECK_HEADER(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)
|
|
{
|
|
uint32_t 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),
|
|
fdt_size_dt_strings(old));
|
|
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_CHECK_HEADER(fdt);
|
|
|
|
mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
|
|
* sizeof(struct fdt_reserve_entry);
|
|
|
|
if (fdt_version(fdt) >= 17) {
|
|
struct_size = fdt_size_dt_struct(fdt);
|
|
} else {
|
|
struct_size = 0;
|
|
while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)
|
|
;
|
|
if (struct_size < 0)
|
|
return struct_size;
|
|
}
|
|
|
|
if (!_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);
|
|
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_CHECK_HEADER(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_set_totalsize(fdt, _fdt_data_size(fdt));
|
|
|
|
return 0;
|
|
}
|