1*6fa8e72eSAndre Przywara /* 2*6fa8e72eSAndre Przywara * Copyright (c) 2021, ARM Limited. All rights reserved. 3*6fa8e72eSAndre Przywara * 4*6fa8e72eSAndre Przywara * SPDX-License-Identifier: BSD-3-Clause 5*6fa8e72eSAndre Przywara */ 6*6fa8e72eSAndre Przywara 7*6fa8e72eSAndre Przywara #include <libfdt.h> 8*6fa8e72eSAndre Przywara 9*6fa8e72eSAndre Przywara #include <common/debug.h> 10*6fa8e72eSAndre Przywara #include <common/fdt_fixup.h> 11*6fa8e72eSAndre Przywara #include <common/fdt_wrappers.h> 12*6fa8e72eSAndre Przywara 13*6fa8e72eSAndre Przywara #include <sunxi_private.h> 14*6fa8e72eSAndre Przywara 15*6fa8e72eSAndre Przywara void sunxi_prepare_dtb(void *fdt) 16*6fa8e72eSAndre Przywara { 17*6fa8e72eSAndre Przywara int ret; 18*6fa8e72eSAndre Przywara 19*6fa8e72eSAndre Przywara if (fdt == NULL || fdt_check_header(fdt) != 0) { 20*6fa8e72eSAndre Przywara return; 21*6fa8e72eSAndre Przywara } 22*6fa8e72eSAndre Przywara 23*6fa8e72eSAndre Przywara ret = fdt_open_into(fdt, fdt, 0x10000); 24*6fa8e72eSAndre Przywara if (ret < 0) { 25*6fa8e72eSAndre Przywara ERROR("Preparing devicetree at %p: error %d\n", fdt, ret); 26*6fa8e72eSAndre Przywara return; 27*6fa8e72eSAndre Przywara } 28*6fa8e72eSAndre Przywara 29*6fa8e72eSAndre Przywara #ifdef SUNXI_BL31_IN_DRAM 30*6fa8e72eSAndre Przywara /* Reserve memory used by Trusted Firmware. */ 31*6fa8e72eSAndre Przywara if (fdt_add_reserved_memory(fdt, "tf-a@40000000", BL31_BASE, 32*6fa8e72eSAndre Przywara BL31_LIMIT - BL31_BASE)) { 33*6fa8e72eSAndre Przywara WARN("Failed to add reserved memory nodes to DT.\n"); 34*6fa8e72eSAndre Przywara return; 35*6fa8e72eSAndre Przywara } 36*6fa8e72eSAndre Przywara #endif 37*6fa8e72eSAndre Przywara 38*6fa8e72eSAndre Przywara ret = fdt_pack(fdt); 39*6fa8e72eSAndre Przywara if (ret < 0) { 40*6fa8e72eSAndre Przywara ERROR("Failed to pack devicetree at %p: error %d\n", 41*6fa8e72eSAndre Przywara fdt, ret); 42*6fa8e72eSAndre Przywara } else { 43*6fa8e72eSAndre Przywara clean_dcache_range((uintptr_t)fdt, fdt_blob_size(fdt)); 44*6fa8e72eSAndre Przywara INFO("Changed devicetree.\n"); 45*6fa8e72eSAndre Przywara } 46*6fa8e72eSAndre Przywara } 47