freemyipod r255 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r254‎ | r255 | r256 >
Date:21:20, 4 November 2010
Author:theseven
Status:new
Tags:
Comment:
noteboot: Add some more timeouts to the NAND driver to make bank detection work correctly
Modified paths:
  • /noteboot/ftlstub/nand.c (modified) (history)

Diff [purge]

Index: noteboot/ftlstub/nand.c
@@ -93,22 +93,31 @@
9494 return 0;
9595 }
9696
97 -static void nand_wait_cmddone(void)
 97+static uint32_t nand_wait_cmddone(void)
9898 {
99 - while ((FMCSTAT & FMCSTAT_CMDDONE) == 0);
 99+ uint32_t timeout = USEC_TIMER + 20000;
 100+ while ((FMCSTAT & FMCSTAT_CMDDONE) == 0)
 101+ if (TIME_AFTER(USEC_TIMER, timeout)) return 1;
100102 FMCSTAT = FMCSTAT_CMDDONE;
 103+ return 0;
101104 }
102105
103 -static void nand_wait_addrdone(void)
 106+static uint32_t nand_wait_addrdone(void)
104107 {
105 - while ((FMCSTAT & FMCSTAT_ADDRDONE) == 0);
 108+ uint32_t timeout = USEC_TIMER + 20000;
 109+ while ((FMCSTAT & FMCSTAT_ADDRDONE) == 0)
 110+ if (TIME_AFTER(USEC_TIMER, timeout)) return 1;
106111 FMCSTAT = FMCSTAT_ADDRDONE;
 112+ return 0;
107113 }
108114
109 -static void nand_wait_chip_ready(uint32_t bank)
 115+static uint32_t nand_wait_chip_ready(uint32_t bank)
110116 {
111 - while ((FMCSTAT & (FMCSTAT_BANK0READY << bank)) == 0);
 117+ uint32_t timeout = USEC_TIMER + 20000;
 118+ while ((FMCSTAT & (FMCSTAT_BANK0READY << bank)) == 0)
 119+ if (TIME_AFTER(USEC_TIMER, timeout)) return 1;
112120 FMCSTAT = (FMCSTAT_BANK0READY << bank);
 121+ return 0;
113122 }
114123
115124 static void nand_set_fmctrl0(uint32_t bank, uint32_t flags)
@@ -136,7 +145,7 @@
137146 {
138147 nand_set_fmctrl0(bank, 0);
139148 if (nand_send_cmd(NAND_CMD_RESET)) return 1;
140 - nand_wait_chip_ready(bank);
 149+ if (nand_wait_chip_ready(bank)) return 1;
141150 FMCTRL1 = FMCTRL1_CLEARRFIFO | FMCTRL1_CLEARWFIFO;
142151 sleep(1000);
143152 return 0;
@@ -212,10 +221,10 @@
213222 FMANUM = 0;
214223 FMADDR0 = 0;
215224 FMCTRL1 = FMCTRL1_DOTRANSADDR;
216 - nand_wait_cmddone();
 225+ if (nand_wait_cmddone()) return 0xFFFFFFFF;
217226 FMDNUM = 4;
218227 FMCTRL1 = FMCTRL1_DOREADDATA;
219 - nand_wait_addrdone();
 228+ if (nand_wait_addrdone()) return 0xFFFFFFFF;
220229 result = FMFIFO;
221230 FMCTRL1 = FMCTRL1_CLEARRFIFO;
222231 return result;
@@ -285,12 +294,12 @@
286295 if (j == NAND_DEVICEINFOTABLE_ENTRIES) break;
287296 else if (nand_deviceinfotable[j].id == type)
288297 {
 298+ nand_tunk1 = nand_deviceinfotable[j].tunk1;
 299+ nand_twp = nand_deviceinfotable[j].twp;
289300 nand_type[i] = j;
290301 break;
291302 }
292303 }
293304 }
294 - nand_tunk1 = nand_deviceinfotable[nand_type[0]].tunk1;
295 - nand_twp = nand_deviceinfotable[nand_type[0]].twp;
296305 return 0;
297306 }