1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#include <common.h>
35#include <asm/ppc4xx.h>
36#include <asm/processor.h>
37#include <asm/io.h>
38
39#undef DEBUG
40#ifdef DEBUG
41#define DEBUGF(x...) printf(x)
42#else
43#define DEBUGF(x...)
44#endif
45
46#define BOOT_SMALL_FLASH 32
47#define FLASH_ONBD_N 2
48#define FLASH_SRAM_SEL 1
49
50#define BOOT_SMALL_FLASH_VAL 4
51#define FLASH_ONBD_N_VAL 2
52#define FLASH_SRAM_SEL_VAL 1
53
54static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
55 {0xffc00000, 0xffe00000, 0xff880000},
56 {0xffc00000, 0xffe00000, 0xff800000},
57 {0xffc00000, 0xffe00000, 0x00000000},
58 {0xffc00000, 0xffe00000, 0x00000000},
59 {0xff800000, 0xffa00000, 0xfff80000},
60 {0xff800000, 0xffa00000, 0xfff00000},
61 {0xffc00000, 0xffe00000, 0x00000000},
62 {0xffc00000, 0xffe00000, 0x00000000}
63};
64
65
66
67
68#include "../common/flash.c"
69
70
71
72
73static ulong flash_get_size(vu_long * addr, flash_info_t * info);
74
75
76
77
78u32 flash_get_bank_size(int cs, int idx)
79{
80 u8 reg = in_8((void *)CONFIG_SYS_FPGA_BASE);
81
82 if ((reg & BOOT_SMALL_FLASH) && !(reg & FLASH_ONBD_N)) {
83
84
85
86
87 if (cs == 0)
88 return flash_info[2].size;
89 if (cs == 2)
90 return flash_info[0].size + flash_info[1].size;
91 } else {
92
93
94
95
96 if (cs == 0)
97 return flash_info[0].size + flash_info[1].size;
98 if (cs == 2)
99 return flash_info[2].size;
100 }
101
102 return 0;
103}
104
105unsigned long flash_init(void)
106{
107 unsigned long total_b = 0;
108 unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
109 unsigned char *fpga_base = (unsigned char *)CONFIG_SYS_FPGA_BASE;
110 unsigned char switch_status;
111 unsigned short index = 0;
112 int i;
113
114
115 switch_status = *fpga_base;
116
117
118 if (switch_status & BOOT_SMALL_FLASH) {
119 index += BOOT_SMALL_FLASH_VAL;
120 }
121 if (switch_status & FLASH_ONBD_N) {
122 index += FLASH_ONBD_N_VAL;
123 }
124 if (switch_status & FLASH_SRAM_SEL) {
125 index += FLASH_SRAM_SEL_VAL;
126 }
127
128 DEBUGF("\n");
129 DEBUGF("FLASH: Index: %d\n", index);
130
131
132 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
133 flash_info[i].flash_id = FLASH_UNKNOWN;
134 flash_info[i].sector_count = -1;
135 flash_info[i].size = 0;
136
137
138 if (flash_addr_table[index][i] == 0) {
139 continue;
140 }
141
142
143 size_b[i] = flash_get_size((vu_long *)
144 flash_addr_table[index][i],
145 &flash_info[i]);
146 flash_info[i].size = size_b[i];
147 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
148 printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
149 i, size_b[i], size_b[i] << 20);
150 flash_info[i].sector_count = -1;
151 flash_info[i].size = 0;
152 }
153
154
155 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
156 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
157 &flash_info[2]);
158#ifdef CONFIG_ENV_IS_IN_FLASH
159 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
160 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
161 &flash_info[2]);
162 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
163 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
164 &flash_info[2]);
165#endif
166
167 total_b += flash_info[i].size;
168 }
169
170 return total_b;
171}
172