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