xref: /openbmc/u-boot/arch/arm/lib/bootm-fdt.c (revision 78a88f79)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013, Google Inc.
4  *
5  * Copyright (C) 2011
6  * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
7  *  - Added prep subcommand support
8  *  - Reorganized source - modeled after powerpc version
9  *
10  * (C) Copyright 2002
11  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12  * Marius Groeger <mgroeger@sysgo.de>
13  *
14  * Copyright (C) 2001  Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
15  */
16 
17 #include <common.h>
18 #include <fdt_support.h>
19 #ifdef CONFIG_ARMV7_NONSEC
20 #include <asm/armv7.h>
21 #endif
22 #include <asm/psci.h>
23 #include <asm/spin_table.h>
24 
25 DECLARE_GLOBAL_DATA_PTR;
26 
27 #ifdef CONFIG_FMAN_ENET
28 __weak int fdt_update_ethernet_dt(void *blob)
29 {
30 	return 0;
31 }
32 #endif
33 
34 int arch_fixup_fdt(void *blob)
35 {
36 	__maybe_unused int ret = 0;
37 #if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_OF_LIBFDT)
38 	bd_t *bd = gd->bd;
39 	int bank;
40 	u64 start[CONFIG_NR_DRAM_BANKS];
41 	u64 size[CONFIG_NR_DRAM_BANKS];
42 
43 	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
44 		start[bank] = bd->bi_dram[bank].start;
45 		size[bank] = bd->bi_dram[bank].size;
46 #ifdef CONFIG_ARMV7_NONSEC
47 		ret = armv7_apply_memory_carveout(&start[bank], &size[bank]);
48 		if (ret)
49 			return ret;
50 #endif
51 	}
52 
53 #ifdef CONFIG_OF_LIBFDT
54 	ret = fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
55 	if (ret)
56 		return ret;
57 #endif
58 
59 #ifdef CONFIG_ARMV8_SPIN_TABLE
60 	ret = spin_table_update_dt(blob);
61 	if (ret)
62 		return ret;
63 #endif
64 
65 #if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV8_PSCI) || \
66 	defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
67 	ret = psci_update_dt(blob);
68 	if (ret)
69 		return ret;
70 #endif
71 #endif
72 
73 #ifdef CONFIG_FMAN_ENET
74 	ret = fdt_update_ethernet_dt(blob);
75 	if (ret)
76 		return ret;
77 #endif
78 	return 0;
79 }
80