blob: 2d058edc41960974cf42416732800289a118f82b [file] [log] [blame]
Patrick Delaunay98276112020-03-18 09:22:50 +01001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2/*
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
4 */
5
Patrick Delaunayba779402020-11-06 19:01:29 +01006#define LOG_CATEGORY LOGC_ARCH
7
Tom Rinidec7ea02024-05-20 13:35:03 -06008#include <config.h>
Simon Glass94086b22024-11-02 11:49:42 -06009#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <linux/libfdt.h>
Marek Vasutefdedcb2023-01-12 18:58:40 +010012#include <asm/arch/sys_proto.h>
Patrick Delaunay98276112020-03-18 09:22:50 +010013#include <asm/sections.h>
14#include <asm/system.h>
15
16/*
Patrick Delaunay98276112020-03-18 09:22:50 +010017 * Use the saved FDT address provided by TF-A at boot time (NT_FW_CONFIG =
18 * Non Trusted Firmware configuration file) when the pointer is valid
19 */
Simon Glass94086b22024-11-02 11:49:42 -060020int board_fdt_blob_setup(void **fdtp)
Patrick Delaunay98276112020-03-18 09:22:50 +010021{
Marek Vasutefdedcb2023-01-12 18:58:40 +010022 unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
23
Patrick Delaunayba779402020-11-06 19:01:29 +010024 log_debug("%s: nt_fw_dtb=%lx\n", __func__, nt_fw_dtb);
Patrick Delaunay98276112020-03-18 09:22:50 +010025
26 /* use external device tree only if address is valid */
Simon Glass94086b22024-11-02 11:49:42 -060027 if (nt_fw_dtb < STM32_DDR_BASE ||
28 fdt_magic(nt_fw_dtb) != FDT_MAGIC) {
29 log_debug("DTB not found.\n");
30 log_debug("fall back to builtin DTB, %p\n", _end);
31
32 return -EEXIST;
Patrick Delaunay98276112020-03-18 09:22:50 +010033 }
Simon Glass94086b22024-11-02 11:49:42 -060034
35 *fdtp = (void *)nt_fw_dtb;
Patrick Delaunay98276112020-03-18 09:22:50 +010036
Simon Glass94086b22024-11-02 11:49:42 -060037 return 0;
Patrick Delaunay98276112020-03-18 09:22:50 +010038}