blob: 13322e34d606763bab6eacf45a863f33eb23114e [file] [log] [blame]
Patrick Delaunay4ac34522020-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 Delaunayeb653ac2020-11-06 19:01:29 +01006#define LOG_CATEGORY LOGC_ARCH
7
Patrick Delaunay4ac34522020-03-18 09:22:50 +01008#include <common.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Patrick Delaunay4ac34522020-03-18 09:22:50 +010010#include <asm/sections.h>
11#include <asm/system.h>
12
13/*
14 * Force data-section, as .bss will not be valid
15 * when save_boot_params is invoked.
16 */
17static unsigned long nt_fw_dtb __section(".data");
18
19/*
20 * Save the FDT address provided by TF-A in r2 at boot time
21 * This function is called from start.S
22 */
23void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
24 unsigned long r3)
25{
26 nt_fw_dtb = r2;
27
28 save_boot_params_ret();
29}
30
31/*
32 * Use the saved FDT address provided by TF-A at boot time (NT_FW_CONFIG =
33 * Non Trusted Firmware configuration file) when the pointer is valid
34 */
35void *board_fdt_blob_setup(void)
36{
Patrick Delaunayeb653ac2020-11-06 19:01:29 +010037 log_debug("%s: nt_fw_dtb=%lx\n", __func__, nt_fw_dtb);
Patrick Delaunay4ac34522020-03-18 09:22:50 +010038
39 /* use external device tree only if address is valid */
40 if (nt_fw_dtb >= STM32_DDR_BASE) {
41 if (fdt_magic(nt_fw_dtb) == FDT_MAGIC)
42 return (void *)nt_fw_dtb;
Patrick Delaunayeb653ac2020-11-06 19:01:29 +010043 log_debug("%s: DTB not found.\n", __func__);
Patrick Delaunay4ac34522020-03-18 09:22:50 +010044 }
Patrick Delaunayeb653ac2020-11-06 19:01:29 +010045 log_debug("%s: fall back to builtin DTB, %p\n", __func__, &_end);
Patrick Delaunay4ac34522020-03-18 09:22:50 +010046
47 return (void *)&_end;
48}