1 /* 2 * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 #include <common/debug.h> 7 #include <common/fdt_fixup.h> 8 #include <common/fdt_wrappers.h> 9 #include <libfdt.h> 10 #include <platform_def.h> 11 12 #include <plat_fdt.h> 13 #include <plat_xfer_list.h> 14 15 #define FIT_CONFS_PATH "/configurations" 16 17 static bool is_fit_image(void *dtb) 18 { 19 int64_t confs_noffset = 0; 20 bool status = true; 21 22 confs_noffset = fdt_path_offset(dtb, FIT_CONFS_PATH); 23 24 /* confs_noffset is only present on FIT image */ 25 if (confs_noffset < 0) { 26 status = false; 27 } 28 29 return status; 30 } 31 32 int32_t is_valid_dtb(void *fdt) 33 { 34 int32_t ret = 0; 35 36 ret = fdt_check_header(fdt); 37 if (ret != 0) { 38 ERROR("Can't read DT at %p\n", fdt); 39 goto error; 40 } 41 42 ret = fdt_open_into(fdt, fdt, XILINX_OF_BOARD_DTB_MAX_SIZE); 43 if (ret < 0) { 44 ERROR("Invalid Device Tree at %p: error %d\n", fdt, ret); 45 goto error; 46 } 47 48 if (is_fit_image(fdt)) { 49 WARN("FIT image detected, TF-A will not update DTB for DDR address space\n"); 50 ret = -FDT_ERR_NOTFOUND; 51 } 52 error: 53 return ret; 54 } 55 56 /* TODO: Reserve TFA memory in DT through custom TL entry */ 57 void prepare_dtb(void) 58 { 59 60 } 61 62 uintptr_t plat_retrieve_dt_addr(void) 63 { 64 void *dtb = NULL; 65 66 dtb = transfer_list_retrieve_dt_address(); 67 if (dtb == NULL) { 68 WARN("TL header or DT entry is invalid\n"); 69 } 70 71 return (uintptr_t)dtb; 72 } 73