blob: 194d538a427f2ac76202fff8378cf3a12c7129d7 [file] [log] [blame]
Maheedhar Bollapalli73365f42024-12-04 04:12:53 +00001/*
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>
Harrison Mutaia3c6a072025-05-27 10:39:02 +000013#ifdef TRANSFER_LIST
Maheedhar Bollapalli73365f42024-12-04 04:12:53 +000014#include <plat_xfer_list.h>
Harrison Mutaia3c6a072025-05-27 10:39:02 +000015#endif
Maheedhar Bollapalli73365f42024-12-04 04:12:53 +000016
17#define FIT_CONFS_PATH "/configurations"
18
19static bool is_fit_image(void *dtb)
20{
21 int64_t confs_noffset = 0;
22 bool status = true;
23
24 confs_noffset = fdt_path_offset(dtb, FIT_CONFS_PATH);
25
26 /* confs_noffset is only present on FIT image */
27 if (confs_noffset < 0) {
28 status = false;
29 }
30
31 return status;
32}
33
34int32_t is_valid_dtb(void *fdt)
35{
36 int32_t ret = 0;
37
38 ret = fdt_check_header(fdt);
39 if (ret != 0) {
40 ERROR("Can't read DT at %p\n", fdt);
41 goto error;
42 }
43
44 ret = fdt_open_into(fdt, fdt, XILINX_OF_BOARD_DTB_MAX_SIZE);
45 if (ret < 0) {
46 ERROR("Invalid Device Tree at %p: error %d\n", fdt, ret);
47 goto error;
48 }
49
50 if (is_fit_image(fdt)) {
51 WARN("FIT image detected, TF-A will not update DTB for DDR address space\n");
52 ret = -FDT_ERR_NOTFOUND;
53 }
54error:
55 return ret;
56}
57
58/* TODO: Reserve TFA memory in DT through custom TL entry */
59void prepare_dtb(void)
60{
61
62}
63
64uintptr_t plat_retrieve_dt_addr(void)
65{
66 void *dtb = NULL;
67
68 dtb = transfer_list_retrieve_dt_address();
69 if (dtb == NULL) {
70 WARN("TL header or DT entry is invalid\n");
71 }
72
73 return (uintptr_t)dtb;
74}