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#include <common.h>
32#include <asm/ppc4xx.h>
33#include <asm/processor.h>
34
35#undef DEBUG
36#ifdef DEBUG
37#define DEBUGF(x...) printf(x)
38#else
39#define DEBUGF(x...)
40#endif
41
42
43
44
45#include "../common/flash.c"
46
47
48
49
50static ulong flash_get_size(vu_long * addr, flash_info_t * info);
51static void flash_get_offsets(ulong base, flash_info_t * info);
52
53unsigned long flash_init(void)
54{
55 unsigned long size_b0, size_b1;
56 int i;
57 uint pbcr;
58 unsigned long base_b0, base_b1;
59
60
61 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
62 flash_info[i].flash_id = FLASH_UNKNOWN;
63 }
64
65
66
67 size_b0 =
68 flash_get_size((vu_long *) FLASH_BASE0_PRELIM, &flash_info[0]);
69
70 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
71 printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
72 size_b0, size_b0 << 20);
73 }
74
75
76 if (CONFIG_SYS_MAX_FLASH_BANKS == 1) {
77
78 flash_get_offsets(FLASH_BASE0_PRELIM, &flash_info[0]);
79
80
81 (void)flash_protect(FLAG_PROTECT_SET,
82 CONFIG_SYS_MONITOR_BASE,
83 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
84 &flash_info[0]);
85#ifdef CONFIG_ENV_IS_IN_FLASH
86 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
87 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
88 &flash_info[0]);
89 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
90 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
91 &flash_info[0]);
92#endif
93
94 size_b1 = 0;
95 flash_info[0].size = size_b0;
96 } else {
97
98 size_b1 =
99 flash_get_size((vu_long *) FLASH_BASE1_PRELIM,
100 &flash_info[1]);
101
102
103
104 if (size_b1) {
105 mtdcr(EBC0_CFGADDR, PB0CR);
106 pbcr = mfdcr(EBC0_CFGDATA);
107 mtdcr(EBC0_CFGADDR, PB0CR);
108 base_b1 = -size_b1;
109 pbcr =
110 (pbcr & 0x0001ffff) | base_b1 |
111 (((size_b1 / 1024 / 1024) - 1) << 17);
112 mtdcr(EBC0_CFGDATA, pbcr);
113
114 }
115
116 if (size_b0) {
117 mtdcr(EBC0_CFGADDR, PB1CR);
118 pbcr = mfdcr(EBC0_CFGDATA);
119 mtdcr(EBC0_CFGADDR, PB1CR);
120 base_b0 = base_b1 - size_b0;
121 pbcr =
122 (pbcr & 0x0001ffff) | base_b0 |
123 (((size_b0 / 1024 / 1024) - 1) << 17);
124 mtdcr(EBC0_CFGDATA, pbcr);
125
126 }
127
128 size_b0 = flash_get_size((vu_long *) base_b0, &flash_info[0]);
129
130 flash_get_offsets(base_b0, &flash_info[0]);
131
132
133 (void)flash_protect(FLAG_PROTECT_SET,
134 base_b0 + size_b0 - monitor_flash_len,
135 base_b0 + size_b0 - 1, &flash_info[0]);
136
137 if (size_b1) {
138
139 size_b1 =
140 flash_get_size((vu_long *) base_b1, &flash_info[1]);
141
142 flash_get_offsets(base_b1, &flash_info[1]);
143
144
145 (void)flash_protect(FLAG_PROTECT_SET,
146 base_b1 + size_b1 -
147 monitor_flash_len,
148 base_b1 + size_b1 - 1,
149 &flash_info[1]);
150
151 (void)flash_protect(FLAG_PROTECT_CLEAR,
152 base_b0 + size_b0 -
153 monitor_flash_len,
154 base_b0 + size_b0 - 1,
155 &flash_info[0]);
156 } else {
157 flash_info[1].flash_id = FLASH_UNKNOWN;
158 flash_info[1].sector_count = -1;
159 }
160
161 flash_info[0].size = size_b0;
162 flash_info[1].size = size_b1;
163 }
164 return (size_b0 + size_b1);
165}
166
167
168static void flash_get_offsets(ulong base, flash_info_t * info)
169{
170 int i;
171
172
173 if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
174 (info->flash_id == FLASH_AM040)) {
175 for (i = 0; i < info->sector_count; i++)
176 info->start[i] = base + (i * 0x00010000);
177 } else {
178 if (info->flash_id & FLASH_BTYPE) {
179
180 info->start[0] = base + 0x00000000;
181 info->start[1] = base + 0x00004000;
182 info->start[2] = base + 0x00006000;
183 info->start[3] = base + 0x00008000;
184 for (i = 4; i < info->sector_count; i++) {
185 info->start[i] =
186 base + (i * 0x00010000) - 0x00030000;
187 }
188 } else {
189
190 i = info->sector_count - 1;
191 info->start[i--] = base + info->size - 0x00004000;
192 info->start[i--] = base + info->size - 0x00006000;
193 info->start[i--] = base + info->size - 0x00008000;
194 for (; i >= 0; i--) {
195 info->start[i] = base + i * 0x00010000;
196 }
197 }
198 }
199}
200