xref: /rk3399_rockchip-uboot/arch/arm/lib/bootm-fdt.c (revision 01b8c4d110abb0dcbe36dc5b6b10d93b2b8e2667)
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 #include <bidram.h>
26 
27 DECLARE_GLOBAL_DATA_PTR;
28 
29 #ifdef CONFIG_FMAN_ENET
30 __weak int fdt_update_ethernet_dt(void *blob)
31 {
32 	return 0;
33 }
34 #endif
35 
36 __weak int board_fdt_fixup(void *blob)
37 {
38 	return 0;
39 }
40 
41 int arch_fixup_fdt(void *blob)
42 {
43 	int ret = 0;
44 
45 	ret = board_fdt_fixup(blob);
46 	if (ret)
47 		return ret;
48 
49 #if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_OF_LIBFDT)
50 	bd_t *bd = gd->bd;
51 	int bank;
52 	u64 start[CONFIG_NR_DRAM_BANKS];
53 	u64 size[CONFIG_NR_DRAM_BANKS];
54 
55 #ifdef CONFIG_BIDRAM
56 	bidram_fixup();
57 #endif
58 	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
59 		start[bank] = bd->bi_dram[bank].start;
60 		size[bank] = bd->bi_dram[bank].size;
61 		if (size[bank] == 0)
62 			continue;
63 		printf("Adding bank: 0x%08llx - 0x%08llx (size: 0x%08llx)\n",
64 		       start[bank], start[bank] + size[bank], size[bank]);
65 
66 #ifdef CONFIG_ARMV7_NONSEC
67 		ret = armv7_apply_memory_carveout(&start[bank], &size[bank]);
68 		if (ret)
69 			return ret;
70 #endif
71 	}
72 
73 #ifdef CONFIG_OF_LIBFDT
74 	ret = fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
75 	if (ret)
76 		return ret;
77 #endif
78 
79 #ifdef CONFIG_ARMV8_SPIN_TABLE
80 	ret = spin_table_update_dt(blob);
81 	if (ret)
82 		return ret;
83 #endif
84 
85 #if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV8_PSCI) || \
86 	defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
87 	ret = psci_update_dt(blob);
88 	if (ret)
89 		return ret;
90 #endif
91 #endif
92 
93 #ifdef CONFIG_FMAN_ENET
94 	ret = fdt_update_ethernet_dt(blob);
95 	if (ret)
96 		return ret;
97 #endif
98 	return 0;
99 }
100