blob: fd06b318f3d30a1992192abbff543bf492e6bfa5 [file] [log] [blame]
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01001/*
2 * U-boot - flash.c Flash driver for PSD4256GV
3 *
Aubrey Lidfeeab22007-04-05 18:28:34 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01005 * This file is based on BF533EzFlash.c originally written by Analog Devices, Inc.
6 *
7 * (C) Copyright 2000-2004
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010011 */
12
Aubrey Li8440bb12007-03-12 00:25:14 +080013#include <asm/io.h>
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010014#include "flash-defines.h"
15
Mike Frysinger65ba1ab2008-10-11 20:30:28 -040016int AFP_NumSectors = 40;
17long AFP_SectorSize1 = 0x10000;
18int AFP_SectorSize2 = 0x4000;
19
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010020void flash_reset(void)
21{
22 reset_flash();
23}
24
Aubrey.Li3f0606a2007-03-09 13:38:44 +080025unsigned long flash_get_size(ulong baseaddr, flash_info_t * info, int bank_flag)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010026{
27 int id = 0, i = 0;
28 static int FlagDev = 1;
29
30 id = get_codes();
Aubrey.Li3f0606a2007-03-09 13:38:44 +080031 if (FlagDev) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010032#ifdef DEBUG
33 printf("Device ID of the Flash is %x\n", id);
34#endif
35 FlagDev = 0;
36 }
37 info->flash_id = id;
38
39 switch (bank_flag) {
40 case 0:
41 for (i = PriFlashABegin; i < SecFlashABegin; i++)
42 info->start[i] = (baseaddr + (i * AFP_SectorSize1));
43 info->size = 0x200000;
44 info->sector_count = 32;
45 break;
46 case 1:
47 info->start[0] = baseaddr + SecFlashASec1Off;
48 info->start[1] = baseaddr + SecFlashASec2Off;
49 info->start[2] = baseaddr + SecFlashASec3Off;
50 info->start[3] = baseaddr + SecFlashASec4Off;
51 info->size = 0x10000;
52 info->sector_count = 4;
53 break;
54 case 2:
55 info->start[0] = baseaddr + SecFlashBSec1Off;
56 info->start[1] = baseaddr + SecFlashBSec2Off;
57 info->start[2] = baseaddr + SecFlashBSec3Off;
58 info->start[3] = baseaddr + SecFlashBSec4Off;
59 info->size = 0x10000;
60 info->sector_count = 4;
61 break;
62 }
63 return (info->size);
64}
65
66unsigned long flash_init(void)
67{
68 unsigned long size_b0, size_b1, size_b2;
69 int i;
70
71 size_b0 = size_b1 = size_b2 = 0;
72#ifdef DEBUG
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020073 printf("Flash Memory Start 0x%x\n", CONFIG_SYS_FLASH_BASE);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010074 printf("Memory Map for the Flash\n");
75 printf("0x20000000 - 0x200FFFFF Flash A Primary (1MB)\n");
76 printf("0x20100000 - 0x201FFFFF Flash B Primary (1MB)\n");
77 printf("0x20200000 - 0x2020FFFF Flash A Secondary (64KB)\n");
78 printf("0x20280000 - 0x2028FFFF Flash B Secondary (64KB)\n");
79 printf("Please type command flinfo for information on Sectors \n");
80#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020081 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010082 flash_info[i].flash_id = FLASH_UNKNOWN;
83 }
84
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020085 size_b0 = flash_get_size(CONFIG_SYS_FLASH0_BASE, &flash_info[0], 0);
86 size_b1 = flash_get_size(CONFIG_SYS_FLASH0_BASE, &flash_info[1], 1);
87 size_b2 = flash_get_size(CONFIG_SYS_FLASH0_BASE, &flash_info[2], 2);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010088
89 if (flash_info[0].flash_id == FLASH_UNKNOWN || size_b0 == 0) {
90 printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
Aubrey.Li3f0606a2007-03-09 13:38:44 +080091 size_b0, size_b0 >> 20);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010092 }
93
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020094 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH0_BASE,
Aubrey.Li3f0606a2007-03-09 13:38:44 +080095 (flash_info[0].start[2] - 1), &flash_info[0]);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010096
97 return (size_b0 + size_b1 + size_b2);
98}
99
100void flash_print_info(flash_info_t * info)
101{
102 int i;
103
104 if (info->flash_id == FLASH_UNKNOWN) {
105 printf("missing or unknown FLASH type\n");
106 return;
107 }
108
109 switch (info->flash_id) {
110 case FLASH_PSD4256GV:
111 printf("ST Microelectronics ");
112 break;
113 default:
Mike Frysingerfe033ad2008-10-12 06:02:55 -0400114 printf("Unknown Vendor: (0x%08lX) ", info->flash_id);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100115 break;
116 }
117 for (i = 0; i < info->sector_count; ++i) {
118 if ((i % 5) == 0)
119 printf("\n ");
120 printf(" %08lX%s",
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800121 info->start[i], info->protect[i] ? " (RO)" : " ");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100122 }
123 printf("\n");
124 return;
125}
126
127int flash_erase(flash_info_t * info, int s_first, int s_last)
128{
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800129 int cnt = 0, i;
130 int prot, sect;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100131
132 prot = 0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100133 for (sect = s_first; sect <= s_last; ++sect) {
134 if (info->protect[sect])
135 prot++;
136 }
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100137
138 if (prot)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800139 printf("- Warning: %d protected sectors will not be erased!\n",
140 prot);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100141 else
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800142 printf("\n");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100143
144 cnt = s_last - s_first + 1;
145
146 if (cnt == FLASH_TOT_SECT) {
147 printf("Erasing flash, Please Wait \n");
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800148 if (erase_flash() < 0) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100149 printf("Erasing flash failed \n");
150 return FLASH_FAIL;
151 }
152 } else {
153 printf("Erasing Flash locations, Please Wait\n");
154 for (i = s_first; i <= s_last; i++) {
155 if (info->protect[i] == 0) { /* not protected */
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800156 if (erase_block_flash(i, info->start[i]) < 0) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100157 printf("Error Sector erasing \n");
158 return FLASH_FAIL;
159 }
160 }
161 }
162 }
163 return FLASH_SUCCESS;
164}
165
166int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt)
167{
168 int ret;
Aubrey Lidfeeab22007-04-05 18:28:34 +0800169 int d;
170 if (addr % 2) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200171 read_flash(addr - 1 - CONFIG_SYS_FLASH_BASE, &d);
Aubrey Lidfeeab22007-04-05 18:28:34 +0800172 d = (int)((d & 0x00FF) | (*src++ << 8));
173 ret = write_data(addr - 1, 2, (uchar *) & d);
174 if (ret == FLASH_FAIL)
175 return ERR_NOT_ERASED;
176 ret = write_data(addr + 1, cnt - 1, src);
177 } else
178 ret = write_data(addr, cnt, src);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800179 if (ret == FLASH_FAIL)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100180 return ERR_NOT_ERASED;
181 return FLASH_SUCCESS;
182}
183
Aubrey Lidfeeab22007-04-05 18:28:34 +0800184int write_data(long lStart, long lCount, uchar * pnData)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100185{
186 long i = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200187 unsigned long ulOffset = lStart - CONFIG_SYS_FLASH_BASE;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100188 int d;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100189 int nSector = 0;
Aubrey Lidfeeab22007-04-05 18:28:34 +0800190 int flag = 0;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100191
Aubrey Lidfeeab22007-04-05 18:28:34 +0800192 if (lCount % 2) {
193 flag = 1;
194 lCount = lCount - 1;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100195 }
Aubrey Lidfeeab22007-04-05 18:28:34 +0800196
197 for (i = 0; i < lCount - 1; i += 2, ulOffset += 2) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100198 get_sector_number(ulOffset, &nSector);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800199 read_flash(ulOffset, &d);
200 if (d != 0xffff) {
201 printf
Mike Frysingerfe033ad2008-10-12 06:02:55 -0400202 ("Flash not erased at offset 0x%lx Please erase to reprogram\n",
Aubrey Lidfeeab22007-04-05 18:28:34 +0800203 ulOffset);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100204 return FLASH_FAIL;
205 }
206 unlock_flash(ulOffset);
Aubrey Lidfeeab22007-04-05 18:28:34 +0800207 d = (int)(pnData[i] | pnData[i + 1] << 8);
208 write_flash(ulOffset, d);
209 if (poll_toggle_bit(ulOffset) < 0) {
210 printf("Error programming the flash \n");
211 return FLASH_FAIL;
212 }
213 if ((i > 0) && (!(i % AFP_SectorSize2)))
214 printf(".");
215 }
216 if (flag) {
217 get_sector_number(ulOffset, &nSector);
218 read_flash(ulOffset, &d);
219 if (d != 0xffff) {
220 printf
Mike Frysingerfe033ad2008-10-12 06:02:55 -0400221 ("Flash not erased at offset 0x%lx Please erase to reprogram\n",
Aubrey Lidfeeab22007-04-05 18:28:34 +0800222 ulOffset);
223 return FLASH_FAIL;
224 }
225 unlock_flash(ulOffset);
226 d = (int)(pnData[i] | (d & 0xFF00));
227 write_flash(ulOffset, d);
228 if (poll_toggle_bit(ulOffset) < 0) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100229 printf("Error programming the flash \n");
230 return FLASH_FAIL;
231 }
232 }
233 return FLASH_SUCCESS;
234}
235
236int read_data(long ulStart, long lCount, long lStride, int *pnData)
237{
238 long i = 0;
239 int j = 0;
240 long ulOffset = ulStart;
241 int iShift = 0;
242 int iNumWords = 2;
243 int nLeftover = lCount % 4;
244 int nHi, nLow;
245 int nSector = 0;
246
247 for (i = 0; (i < lCount / 4) && (i < BUFFER_SIZE); i++) {
248 for (iShift = 0, j = 0; j < iNumWords; j += 2) {
249 if ((ulOffset >= INVALIDLOCNSTART)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800250 && (ulOffset < INVALIDLOCNEND))
251 return FLASH_FAIL;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100252
253 get_sector_number(ulOffset, &nSector);
254 read_flash(ulOffset, &nLow);
255 ulOffset += (lStride * 2);
256 read_flash(ulOffset, &nHi);
257 ulOffset += (lStride * 2);
258 pnData[i] = (nHi << 16) | nLow;
259 }
260 }
261 if (nLeftover > 0) {
262 if ((ulOffset >= INVALIDLOCNSTART)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800263 && (ulOffset < INVALIDLOCNEND))
264 return FLASH_FAIL;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100265
266 get_sector_number(ulOffset, &nSector);
267 read_flash(ulOffset, &pnData[i]);
268 }
269 return FLASH_SUCCESS;
270}
271
272int write_flash(long nOffset, int nValue)
273{
274 long addr;
275
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200276 addr = (CONFIG_SYS_FLASH_BASE + nOffset);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500277 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800278 *(unsigned volatile short *)addr = nValue;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500279 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800280 if (poll_toggle_bit(nOffset) < 0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100281 return FLASH_FAIL;
282 return FLASH_SUCCESS;
283}
284
285int read_flash(long nOffset, int *pnValue)
286{
287 int nValue = 0x0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200288 long addr = (CONFIG_SYS_FLASH_BASE + nOffset);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100289
290 if (nOffset != 0x2)
291 reset_flash();
Mike Frysingerd4d77302008-02-04 19:26:55 -0500292 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800293 nValue = *(volatile unsigned short *)addr;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500294 SSYNC();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100295 *pnValue = nValue;
York Sun472d5462013-04-01 11:29:11 -0700296 return true;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100297}
298
299int poll_toggle_bit(long lOffset)
300{
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800301 unsigned int u1, u2;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100302 unsigned long timeout = 0xFFFFFFFF;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800303 volatile unsigned long *FB =
304 (volatile unsigned long *)(0x20000000 + lOffset);
305 while (1) {
306 if (timeout < 0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100307 break;
308 u1 = *(volatile unsigned short *)FB;
309 u2 = *(volatile unsigned short *)FB;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800310 if ((u1 & 0x0040) == (u2 & 0x0040))
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100311 return FLASH_SUCCESS;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800312 if ((u2 & 0x0020) == 0x0000)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100313 continue;
314 u1 = *(volatile unsigned short *)FB;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800315 if ((u2 & 0x0040) == (u1 & 0x0040))
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100316 return FLASH_SUCCESS;
317 else {
318 reset_flash();
319 return FLASH_FAIL;
320 }
321 timeout--;
322 }
323 printf("Time out occured \n");
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800324 if (timeout < 0)
325 return FLASH_FAIL;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100326}
327
328void reset_flash(void)
329{
330 write_flash(WRITESEQ1, RESET_VAL);
331 /* Wait for 10 micro seconds */
332 udelay(10);
333}
334
335int erase_flash(void)
336{
337 write_flash(WRITESEQ1, WRITEDATA1);
338 write_flash(WRITESEQ2, WRITEDATA2);
339 write_flash(WRITESEQ3, WRITEDATA3);
340 write_flash(WRITESEQ4, WRITEDATA4);
341 write_flash(WRITESEQ5, WRITEDATA5);
342 write_flash(WRITESEQ6, WRITEDATA6);
343
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800344 if (poll_toggle_bit(0x0000) < 0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100345 return FLASH_FAIL;
346
347 write_flash(SecFlashAOff + WRITESEQ1, WRITEDATA1);
348 write_flash(SecFlashAOff + WRITESEQ2, WRITEDATA2);
349 write_flash(SecFlashAOff + WRITESEQ3, WRITEDATA3);
350 write_flash(SecFlashAOff + WRITESEQ4, WRITEDATA4);
351 write_flash(SecFlashAOff + WRITESEQ5, WRITEDATA5);
352 write_flash(SecFlashAOff + WRITESEQ6, WRITEDATA6);
353
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800354 if (poll_toggle_bit(SecFlashASec1Off) < 0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100355 return FLASH_FAIL;
356
357 write_flash(PriFlashBOff + WRITESEQ1, WRITEDATA1);
358 write_flash(PriFlashBOff + WRITESEQ2, WRITEDATA2);
359 write_flash(PriFlashBOff + WRITESEQ3, WRITEDATA3);
360 write_flash(PriFlashBOff + WRITESEQ4, WRITEDATA4);
361 write_flash(PriFlashBOff + WRITESEQ5, WRITEDATA5);
362 write_flash(PriFlashBOff + WRITESEQ6, WRITEDATA6);
363
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800364 if (poll_toggle_bit(PriFlashBOff) < 0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100365 return FLASH_FAIL;
366
367 write_flash(SecFlashBOff + WRITESEQ1, WRITEDATA1);
368 write_flash(SecFlashBOff + WRITESEQ2, WRITEDATA2);
369 write_flash(SecFlashBOff + WRITESEQ3, WRITEDATA3);
370 write_flash(SecFlashBOff + WRITESEQ4, WRITEDATA4);
371 write_flash(SecFlashBOff + WRITESEQ5, WRITEDATA5);
372 write_flash(SecFlashBOff + WRITESEQ6, WRITEDATA6);
373
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800374 if (poll_toggle_bit(SecFlashBOff) < 0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100375 return FLASH_FAIL;
376
377 return FLASH_SUCCESS;
378}
379
380int erase_block_flash(int nBlock, unsigned long address)
381{
382 long ulSectorOff = 0x0;
383
384 if ((nBlock < 0) || (nBlock > AFP_NumSectors))
York Sun472d5462013-04-01 11:29:11 -0700385 return false;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100386
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200387 ulSectorOff = (address - CONFIG_SYS_FLASH_BASE);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100388
389 write_flash((WRITESEQ1 | ulSectorOff), WRITEDATA1);
390 write_flash((WRITESEQ2 | ulSectorOff), WRITEDATA2);
391 write_flash((WRITESEQ3 | ulSectorOff), WRITEDATA3);
392 write_flash((WRITESEQ4 | ulSectorOff), WRITEDATA4);
393 write_flash((WRITESEQ5 | ulSectorOff), WRITEDATA5);
394
395 write_flash(ulSectorOff, BlockEraseVal);
396
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800397 if (poll_toggle_bit(ulSectorOff) < 0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100398 return FLASH_FAIL;
399
400 return FLASH_SUCCESS;
401}
402
403void unlock_flash(long ulOffset)
404{
405 unsigned long ulOffsetAddr = ulOffset;
406 ulOffsetAddr &= 0xFFFF0000;
407
408 write_flash((WRITESEQ1 | ulOffsetAddr), UNLOCKDATA1);
409 write_flash((WRITESEQ2 | ulOffsetAddr), UNLOCKDATA2);
410 write_flash((WRITESEQ3 | ulOffsetAddr), UNLOCKDATA3);
411}
412
413int get_codes()
414{
415 int dev_id = 0;
416
417 write_flash(WRITESEQ1, GETCODEDATA1);
418 write_flash(WRITESEQ2, GETCODEDATA2);
419 write_flash(WRITESEQ3, GETCODEDATA3);
420
421 read_flash(0x0002, &dev_id);
422 dev_id &= 0x00FF;
423
424 reset_flash();
425
426 return dev_id;
427}
428
429void get_sector_number(long ulOffset, int *pnSector)
430{
431 int nSector = 0;
432
433 if (ulOffset >= SecFlashAOff) {
434 if ((ulOffset < SecFlashASec1Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800435 && (ulOffset < SecFlashASec2Off)) {
436 nSector = SECT32;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100437 } else if ((ulOffset >= SecFlashASec2Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800438 && (ulOffset < SecFlashASec3Off)) {
439 nSector = SECT33;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100440 } else if ((ulOffset >= SecFlashASec3Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800441 && (ulOffset < SecFlashASec4Off)) {
442 nSector = SECT34;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100443 } else if ((ulOffset >= SecFlashASec4Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800444 && (ulOffset < SecFlashAEndOff)) {
445 nSector = SECT35;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100446 }
447 } else if (ulOffset >= SecFlashBOff) {
448 if ((ulOffset < SecFlashBSec1Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800449 && (ulOffset < SecFlashBSec2Off)) {
450 nSector = SECT36;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100451 }
452 if ((ulOffset < SecFlashBSec2Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800453 && (ulOffset < SecFlashBSec3Off)) {
454 nSector = SECT37;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100455 }
456 if ((ulOffset < SecFlashBSec3Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800457 && (ulOffset < SecFlashBSec4Off)) {
458 nSector = SECT38;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100459 }
460 if ((ulOffset < SecFlashBSec4Off)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800461 && (ulOffset < SecFlashBEndOff)) {
462 nSector = SECT39;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100463 }
464 } else if ((ulOffset >= PriFlashAOff) && (ulOffset < SecFlashAOff)) {
465 nSector = ulOffset & 0xffff0000;
466 nSector = ulOffset >> 16;
467 nSector = nSector & 0x000ff;
468 }
469
470 if ((nSector >= 0) && (nSector < AFP_NumSectors)) {
471 *pnSector = nSector;
472 }
473}