blob: ebddf6a7dbcc5f5c48a018127ae0e29b8d7f12e3 [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 Rini654eb082024-04-30 07:35:32 -06008#include <config.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <linux/libfdt.h>
Marek Vasutefdedcb2023-01-12 18:58:40 +010011#include <asm/arch/sys_proto.h>
Patrick Delaunay98276112020-03-18 09:22:50 +010012#include <asm/sections.h>
13#include <asm/system.h>
14
15/*
Patrick Delaunay98276112020-03-18 09:22:50 +010016 * Use the saved FDT address provided by TF-A at boot time (NT_FW_CONFIG =
17 * Non Trusted Firmware configuration file) when the pointer is valid
18 */
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030019void *board_fdt_blob_setup(int *err)
Patrick Delaunay98276112020-03-18 09:22:50 +010020{
Marek Vasutefdedcb2023-01-12 18:58:40 +010021 unsigned long nt_fw_dtb = get_stm32mp_bl2_dtb();
22
Patrick Delaunayba779402020-11-06 19:01:29 +010023 log_debug("%s: nt_fw_dtb=%lx\n", __func__, nt_fw_dtb);
Patrick Delaunay98276112020-03-18 09:22:50 +010024
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030025 *err = 0;
Patrick Delaunay98276112020-03-18 09:22:50 +010026 /* use external device tree only if address is valid */
27 if (nt_fw_dtb >= STM32_DDR_BASE) {
28 if (fdt_magic(nt_fw_dtb) == FDT_MAGIC)
29 return (void *)nt_fw_dtb;
Patrick Delaunayba779402020-11-06 19:01:29 +010030 log_debug("%s: DTB not found.\n", __func__);
Patrick Delaunay98276112020-03-18 09:22:50 +010031 }
Shiji Yangeff11fa2023-08-03 09:47:17 +080032 log_debug("%s: fall back to builtin DTB, %p\n", __func__, _end);
Patrick Delaunay98276112020-03-18 09:22:50 +010033
Shiji Yangeff11fa2023-08-03 09:47:17 +080034 return (void *)_end;
Patrick Delaunay98276112020-03-18 09:22:50 +010035}