freemyipod r66 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r65‎ | r66 | r67 >
Date:22:33, 9 August 2010
Author:theseven
Status:new
Tags:
Comment:
Fix initialisation and backport some improvements from Rockbox.
Modified paths:
  • /embios/trunk/init.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/ftl.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/nand.c (modified) (history)
  • /embios/trunk/usb/synopsysotg.c (modified) (history)

Diff [purge]

Index: embios/trunk/init.c
@@ -34,21 +34,35 @@
3535 #include "usb/usb.h"
3636
3737 static const char welcomestring[] INITCONST_ATTR = "emBIOS v" VERSION " r" VERSION_SVN "\n\n";
 38+static const char initthreadname[] INITCONST_ATTR = "Initialisation thread";
 39+static uint32_t initstack[0x400] INITBSS_ATTR;
3840
39 -void init() INITCODE_ATTR;
40 -void init()
 41+void initthread() INITCODE_ATTR;
 42+void initthread()
4143 {
42 - scheduler_init();
43 - console_init();
44 - lcd_init();
45 - lcdconsole_init();
46 - interrupt_init();
4744 cputs(1, welcomestring);
4845 i2c_init();
4946 power_init();
5047 usb_init();
 48+ DEBUGF("Initializing storage drivers...");
5149 storage_init();
 50+ DEBUGF("Initializing storage subsystem...");
5251 disk_init_subsystem();
 52+ DEBUGF("Reading partition tables...");
5353 disk_init();
 54+ DEBUGF("Mounting partitions...");
5455 disk_mount_all();
55 -}
\ No newline at end of file
 56+ DEBUGF("Finished initialisation sequence");
 57+}
 58+
 59+void init() INITCODE_ATTR;
 60+void init()
 61+{
 62+ scheduler_init();
 63+ console_init();
 64+ lcd_init();
 65+ lcdconsole_init();
 66+ interrupt_init();
 67+ thread_create(initthreadname, initthread, initstack,
 68+ sizeof(initstack), USER_THREAD, 127, true);
 69+}
Index: embios/trunk/target/ipodnano2g/nand.c
@@ -78,15 +78,15 @@
7979 {0xA555D520, 8192, 3872, 0x80, 7, 2, 1, 2, 1}
8080 };
8181
82 -uint8_t nand_tunk1[4];
83 -uint8_t nand_twp[4];
84 -uint8_t nand_tunk2[4];
85 -uint8_t nand_tunk3[4];
86 -int nand_type[4];
87 -int nand_powered = 0;
88 -int nand_interleaved = 0;
89 -int nand_cached = 0;
90 -long nand_last_activity_value = -1;
 82+static uint8_t nand_tunk1[4];
 83+static uint8_t nand_twp[4];
 84+static uint8_t nand_tunk2[4];
 85+static uint8_t nand_tunk3[4];
 86+static int nand_type[4];
 87+static int nand_powered = 0;
 88+static int nand_interleaved = 0;
 89+static int nand_cached = 0;
 90+static long nand_last_activity_value = -1;
9191 static uint32_t nand_stack[0x80];
9292
9393 static struct mutex nand_mtx;
@@ -100,7 +100,7 @@
101101 static uint8_t nand_ecc[0x30] CACHEALIGN_ATTR;
102102
103103
104 -uint32_t nand_unlock(uint32_t rc)
 104+static uint32_t nand_unlock(uint32_t rc)
105105 {
106106 nand_last_activity_value = USEC_TIMER;
107107 mutex_unlock(&nand_mtx);
@@ -107,13 +107,13 @@
108108 return rc;
109109 }
110110
111 -uint32_t ecc_unlock(uint32_t rc)
 111+static uint32_t ecc_unlock(uint32_t rc)
112112 {
113113 mutex_unlock(&ecc_mtx);
114114 return rc;
115115 }
116116
117 -uint32_t nand_timeout(uint32_t timeout)
 117+static uint32_t nand_timeout(long timeout)
118118 {
119119 if (TIME_AFTER(USEC_TIMER, timeout)) return 1;
120120 else
@@ -123,7 +123,7 @@
124124 }
125125 }
126126
127 -uint32_t nand_wait_rbbdone(void)
 127+static uint32_t nand_wait_rbbdone(void)
128128 {
129129 uint32_t timeout = USEC_TIMER + 20000;
130130 while (!(FMCSTAT & FMCSTAT_RBBDONE))
@@ -132,7 +132,7 @@
133133 return 0;
134134 }
135135
136 -uint32_t nand_wait_cmddone(void)
 136+static uint32_t nand_wait_cmddone(void)
137137 {
138138 uint32_t timeout = USEC_TIMER + 20000;
139139 while (!(FMCSTAT & FMCSTAT_CMDDONE))
@@ -141,7 +141,7 @@
142142 return 0;
143143 }
144144
145 -uint32_t nand_wait_addrdone(void)
 145+static uint32_t nand_wait_addrdone(void)
146146 {
147147 uint32_t timeout = USEC_TIMER + 20000;
148148 while (!(FMCSTAT & FMCSTAT_ADDRDONE))
@@ -150,7 +150,7 @@
151151 return 0;
152152 }
153153
154 -uint32_t nand_wait_chip_ready(uint32_t bank)
 154+static uint32_t nand_wait_chip_ready(uint32_t bank)
155155 {
156156 uint32_t timeout = USEC_TIMER + 20000;
157157 while (!(FMCSTAT & (FMCSTAT_BANK0READY << bank)))
@@ -159,19 +159,19 @@
160160 return 0;
161161 }
162162
163 -void nand_set_fmctrl0(uint32_t bank, uint32_t flags)
 163+static void nand_set_fmctrl0(uint32_t bank, uint32_t flags)
164164 {
165165 FMCTRL0 = (nand_tunk1[bank] << 16) | (nand_twp[bank] << 12)
166166 | (1 << 11) | 1 | (1 << (bank + 1)) | flags;
167167 }
168168
169 -uint32_t nand_send_cmd(uint32_t cmd)
 169+static uint32_t nand_send_cmd(uint32_t cmd)
170170 {
171171 FMCMD = cmd;
172172 return nand_wait_rbbdone();
173173 }
174174
175 -uint32_t nand_send_address(uint32_t page, uint32_t offset)
 175+static uint32_t nand_send_address(uint32_t page, uint32_t offset)
176176 {
177177 FMANUM = 4;
178178 FMADDR0 = (page << 16) | offset;
@@ -190,7 +190,7 @@
191191 return 0;
192192 }
193193
194 -uint32_t nand_wait_status_ready(uint32_t bank)
 194+static uint32_t nand_wait_status_ready(uint32_t bank)
195195 {
196196 uint32_t timeout = USEC_TIMER + 20000;
197197 nand_set_fmctrl0(bank, 0);
@@ -211,8 +211,8 @@
212212 return nand_send_cmd(NAND_CMD_READ);
213213 }
214214
215 -void nand_transfer_data_start(uint32_t bank, uint32_t direction,
216 - void* buffer, uint32_t size)
 215+static void nand_transfer_data_start(uint32_t bank, uint32_t direction,
 216+ void* buffer, uint32_t size)
217217 {
218218 nand_set_fmctrl0(bank, FMCTRL0_ENABLEDMA);
219219 FMDNUM = size - 1;
@@ -229,7 +229,7 @@
230230 DMACOM3 = 4;
231231 }
232232
233 -uint32_t nand_transfer_data_collect(uint32_t direction)
 233+static uint32_t nand_transfer_data_collect(uint32_t direction)
234234 {
235235 uint32_t timeout = USEC_TIMER + 20000;
236236 while ((DMAALLST & DMAALLST_DMABUSY3))
@@ -241,8 +241,8 @@
242242 return 0;
243243 }
244244
245 -uint32_t nand_transfer_data(uint32_t bank, uint32_t direction,
246 - void* buffer, uint32_t size)
 245+static uint32_t nand_transfer_data(uint32_t bank, uint32_t direction,
 246+ void* buffer, uint32_t size)
247247 {
248248 nand_transfer_data_start(bank, direction, buffer, size);
249249 uint32_t rc = nand_transfer_data_collect(direction);
@@ -249,7 +249,8 @@
250250 return rc;
251251 }
252252
253 -void ecc_start(uint32_t size, void* databuffer, void* sparebuffer, uint32_t type)
 253+static void ecc_start(uint32_t size, void* databuffer, void* sparebuffer,
 254+ uint32_t type)
254255 {
255256 mutex_lock(&ecc_mtx, TIMEOUT_BLOCK);
256257 ECC_INT_CLR = 1;
@@ -261,7 +262,7 @@
262263 ECC_CTRL = type;
263264 }
264265
265 -uint32_t ecc_collect(void)
 266+static uint32_t ecc_collect(void)
266267 {
267268 uint32_t timeout = USEC_TIMER + 20000;
268269 while (!(SRCPND & INTMSK_ECC))
@@ -272,7 +273,7 @@
273274 return ecc_unlock(ECC_RESULT);
274275 }
275276
276 -uint32_t ecc_decode(uint32_t size, void* databuffer, void* sparebuffer)
 277+static uint32_t ecc_decode(uint32_t size, void* databuffer, void* sparebuffer)
277278 {
278279 ecc_start(size, databuffer, sparebuffer, ECCCTRL_STARTDECODING);
279280 uint32_t rc = ecc_collect();
@@ -279,7 +280,7 @@
280281 return rc;
281282 }
282283
283 -uint32_t ecc_encode(uint32_t size, void* databuffer, void* sparebuffer)
 284+static uint32_t ecc_encode(uint32_t size, void* databuffer, void* sparebuffer)
284285 {
285286 ecc_start(size, databuffer, sparebuffer, ECCCTRL_STARTENCODING);
286287 ecc_collect();
@@ -286,7 +287,7 @@
287288 return 0;
288289 }
289290
290 -uint32_t nand_check_empty(uint8_t* buffer)
 291+static uint32_t nand_check_empty(uint8_t* buffer)
291292 {
292293 uint32_t i, count;
293294 count = 0;
@@ -295,7 +296,7 @@
296297 return 0;
297298 }
298299
299 -uint32_t nand_get_chip_type(uint32_t bank)
 300+static uint32_t nand_get_chip_type(uint32_t bank)
300301 {
301302 mutex_lock(&nand_mtx, TIMEOUT_BLOCK);
302303 uint32_t result;
@@ -431,8 +432,9 @@
432433 return nand_unlock(rc);
433434 }
434435
435 -uint32_t nand_write_page_int(uint32_t bank, uint32_t page, void* databuffer,
436 - void* sparebuffer, uint32_t doecc, uint32_t wait)
 436+static uint32_t nand_write_page_int(uint32_t bank, uint32_t page,
 437+ void* databuffer, void* sparebuffer,
 438+ uint32_t doecc, uint32_t wait)
437439 {
438440 uint8_t* data = nand_data;
439441 uint8_t* spare = nand_spare;
@@ -658,7 +660,7 @@
659661 return nand_wait_status_ready(bank);
660662 }
661663
662 -uint32_t nand_block_erase_fast(uint32_t page)
 664+static uint32_t nand_block_erase_fast(uint32_t page)
663665 {
664666 uint32_t i, rc = 0;
665667 mutex_lock(&nand_mtx, TIMEOUT_BLOCK);
Index: embios/trunk/target/ipodnano2g/ftl.c
@@ -362,54 +362,54 @@
363363 uint32_t ftl_banks;
364364
365365 /* Block map, used vor pBlock to vBlock mapping */
366 -uint16_t ftl_map[0x2000];
 366+static uint16_t ftl_map[0x2000];
367367
368368 /* VFL context for each bank */
369 -struct ftl_vfl_cxt_type ftl_vfl_cxt[4];
 369+static struct ftl_vfl_cxt_type ftl_vfl_cxt[4];
370370
371371 /* FTL context */
372 -struct ftl_cxt_type ftl_cxt;
 372+static struct ftl_cxt_type ftl_cxt;
373373
374374 /* Temporary data buffers for internal use by the FTL */
375 -uint8_t ftl_buffer[0x800] CACHEALIGN_ATTR;
 375+static uint8_t ftl_buffer[0x800] CACHEALIGN_ATTR;
376376
377377 /* Temporary spare byte buffer for internal use by the FTL */
378 -union ftl_spare_data_type ftl_sparebuffer[FTL_WRITESPARE_SIZE] CACHEALIGN_ATTR;
 378+static union ftl_spare_data_type ftl_sparebuffer[FTL_WRITESPARE_SIZE] CACHEALIGN_ATTR;
379379
380380
381381 #ifndef FTL_READONLY
382382
383383 /* Lowlevel BBT for each bank */
384 -uint8_t ftl_bbt[4][0x410];
 384+static uint8_t ftl_bbt[4][0x410];
385385
386386 /* Erase counters for the vBlocks */
387 -uint16_t ftl_erasectr[0x2000];
 387+static uint16_t ftl_erasectr[0x2000];
388388
389389 /* Used by ftl_log */
390 -uint16_t ftl_offsets[0x11][0x200];
 390+static uint16_t ftl_offsets[0x11][0x200];
391391
392392 /* Structs keeping record of scattered page blocks */
393 -struct ftl_log_type ftl_log[0x11];
 393+static struct ftl_log_type ftl_log[0x11];
394394
395395 /* Global cross-bank update sequence number of the VFL context */
396 -uint32_t ftl_vfl_usn;
 396+static uint32_t ftl_vfl_usn;
397397
398398 /* Keeps track (temporarily) of troublesome blocks */
399 -struct ftl_trouble_type ftl_troublelog[5];
 399+static struct ftl_trouble_type ftl_troublelog[5];
400400
401401 /* Counts erase counter page changes, after 100 of them the affected
402402 page will be committed to the flash. */
403 -uint8_t ftl_erasectr_dirt[8];
 403+static uint8_t ftl_erasectr_dirt[8];
404404
405405 /* Buffer needed for copying pages around while moving or committing blocks.
406406 This can't be shared with ftl_buffer, because this one could be overwritten
407407 during the copying operation in order to e.g. commit a CXT. */
408 -uint8_t ftl_copybuffer[FTL_COPYBUF_SIZE][0x800] CACHEALIGN_ATTR;
409 -union ftl_spare_data_type ftl_copyspare[FTL_COPYBUF_SIZE] CACHEALIGN_ATTR;
 408+static uint8_t ftl_copybuffer[FTL_COPYBUF_SIZE][0x800] CACHEALIGN_ATTR;
 409+static union ftl_spare_data_type ftl_copyspare[FTL_COPYBUF_SIZE] CACHEALIGN_ATTR;
410410
411411 /* Needed to store the old scattered page offsets in order to be able to roll
412412 back if something fails while compacting a scattered page block. */
413 -uint16_t ftl_offsets_backup[0x200] CACHEALIGN_ATTR;
 413+static uint16_t ftl_offsets_backup[0x200] CACHEALIGN_ATTR;
414414
415415 #endif
416416
@@ -420,7 +420,7 @@
421421
422422 /* Finds a device info page for the specified bank and returns its number.
423423 Used to check if one is present, and to read the lowlevel BBT. */
424 -uint32_t ftl_find_devinfo(uint32_t bank)
 424+static uint32_t ftl_find_devinfo(uint32_t bank)
425425 {
426426 /* Scan the last 10% of the flash for device info pages */
427427 uint32_t lowestBlock = ftl_nand_type->blocks
@@ -444,7 +444,7 @@
445445
446446
447447 /* Checks if all banks have proper device info pages */
448 -uint32_t ftl_has_devinfo(void)
 448+static uint32_t ftl_has_devinfo(void)
449449 {
450450 uint32_t i;
451451 for (i = 0; i < ftl_banks; i++) if (ftl_find_devinfo(i) == 0) return 0;
@@ -454,7 +454,7 @@
455455
456456 /* Loads the lowlevel BBT for a bank to the specified buffer.
457457 This is based on some cryptic disassembly and not fully understood yet. */
458 -uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt)
 458+static uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt)
459459 {
460460 uint32_t i, j;
461461 uint32_t pagebase, page = ftl_find_devinfo(bank), page2;
@@ -488,8 +488,8 @@
489489
490490
491491 /* Calculates the checksums for the VFL context page of the specified bank */
492 -void ftl_vfl_calculate_checksum(uint32_t bank,
493 - uint32_t* checksum1, uint32_t* checksum2)
 492+static void ftl_vfl_calculate_checksum(uint32_t bank,
 493+ uint32_t* checksum1, uint32_t* checksum2)
494494 {
495495 uint32_t i;
496496 *checksum1 = 0xAABBCCDD;
@@ -504,7 +504,7 @@
505505
506506 /* Checks if the checksums of the VFL context
507507 of the specified bank are correct */
508 -uint32_t ftl_vfl_verify_checksum(uint32_t bank)
 508+static uint32_t ftl_vfl_verify_checksum(uint32_t bank)
509509 {
510510 uint32_t checksum1, checksum2;
511511 ftl_vfl_calculate_checksum(bank, &checksum1, &checksum2);
@@ -519,7 +519,7 @@
520520
521521 #ifndef FTL_READONLY
522522 /* Updates the checksums of the VFL context of the specified bank */
523 -void ftl_vfl_update_checksum(uint32_t bank)
 523+static void ftl_vfl_update_checksum(uint32_t bank)
524524 {
525525 ftl_vfl_calculate_checksum(bank, &ftl_vfl_cxt[bank].checksum1,
526526 &ftl_vfl_cxt[bank].checksum2);
@@ -530,7 +530,7 @@
531531 #ifndef FTL_READONLY
532532 /* Writes 8 copies of the VFL context of the specified bank to flash,
533533 and succeeds if at least 4 can be read back properly. */
534 -uint32_t ftl_vfl_store_cxt(uint32_t bank)
 534+static uint32_t ftl_vfl_store_cxt(uint32_t bank)
535535 {
536536 uint32_t i;
537537 ftl_vfl_cxt[bank].updatecount--;
@@ -574,7 +574,7 @@
575575 #ifndef FTL_READONLY
576576 /* Commits the VFL context of the specified bank to flash,
577577 retries until it works or all available pages have been tried */
578 -uint32_t ftl_vfl_commit_cxt(uint32_t bank)
 578+static uint32_t ftl_vfl_commit_cxt(uint32_t bank)
579579 {
580580 DEBUGF("FTL: VFL: Committing context on bank %d", bank);
581581 if (ftl_vfl_cxt[bank].nextcxtpage + 8 <= ftl_nand_type->pagesperblock)
@@ -604,7 +604,7 @@
605605 /* Returns a pointer to the most recently updated VFL context,
606606 used to find out the current FTL context vBlock numbers
607607 (planetbeing's "maxthing") */
608 -struct ftl_vfl_cxt_type* ftl_vfl_get_newest_cxt(void)
 608+static struct ftl_vfl_cxt_type* ftl_vfl_get_newest_cxt(void)
609609 {
610610 uint32_t i, maxusn;
611611 struct ftl_vfl_cxt_type* cxt = (struct ftl_vfl_cxt_type*)0;
@@ -621,7 +621,7 @@
622622
623623 /* Checks if the specified pBlock is marked bad in the supplied lowlevel BBT.
624624 Only used while mounting the VFL. */
625 -uint32_t ftl_is_good_block(uint8_t* bbt, uint32_t block)
 625+static uint32_t ftl_is_good_block(uint8_t* bbt, uint32_t block)
626626 {
627627 if ((bbt[block >> 3] & (1 << (block & 7))) == 0) return 0;
628628 else return 1;
@@ -629,7 +629,7 @@
630630
631631
632632 /* Checks if the specified vBlock could be remapped */
633 -uint32_t ftl_vfl_is_good_block(uint32_t bank, uint32_t block)
 633+static uint32_t ftl_vfl_is_good_block(uint32_t bank, uint32_t block)
634634 {
635635 uint8_t bbtentry = ftl_vfl_cxt[bank].bbt[block >> 6];
636636 if ((bbtentry & (1 << ((7 - (block >> 3)) & 7))) == 0) return 0;
@@ -640,7 +640,7 @@
641641 #ifndef FTL_READONLY
642642 /* Sets or unsets the bad bit of the specified vBlock
643643 in the specified bank's VFL context */
644 -void ftl_vfl_set_good_block(uint32_t bank, uint32_t block, uint32_t isgood)
 644+static void ftl_vfl_set_good_block(uint32_t bank, uint32_t block, uint32_t isgood)
645645 {
646646 uint8_t bit = (1 << ((7 - (block >> 3)) & 7));
647647 if (isgood == 1) ftl_vfl_cxt[bank].bbt[block >> 6] |= bit;
@@ -650,9 +650,9 @@
651651
652652
653653 /* Tries to read a VFL context from the specified bank, pBlock and page */
654 -uint32_t ftl_vfl_read_page(uint32_t bank, uint32_t block,
655 - uint32_t startpage, void* databuffer,
656 - union ftl_spare_data_type* sparebuffer)
 654+static uint32_t ftl_vfl_read_page(uint32_t bank, uint32_t block,
 655+ uint32_t startpage, void* databuffer,
 656+ union ftl_spare_data_type* sparebuffer)
657657 {
658658 uint32_t i;
659659 for (i = 0; i < 8; i++)
@@ -670,7 +670,7 @@
671671
672672
673673 /* Translates a bank and vBlock to a pBlock, following remaps */
674 -uint32_t ftl_vfl_get_physical_block(uint32_t bank, uint32_t block)
 674+static uint32_t ftl_vfl_get_physical_block(uint32_t bank, uint32_t block)
675675 {
676676 if (ftl_vfl_is_good_block(bank, block) == 1) return block;
677677
@@ -689,7 +689,7 @@
690690
691691 #ifndef FTL_READONLY
692692 /* Checks if remapping is scheduled for the specified bank and vBlock */
693 -uint32_t ftl_vfl_check_remap_scheduled(uint32_t bank, uint32_t block)
 693+static uint32_t ftl_vfl_check_remap_scheduled(uint32_t bank, uint32_t block)
694694 {
695695 uint32_t i;
696696 for (i = 0x333; i > 0 && i > ftl_vfl_cxt[bank].scheduledstart; i--)
@@ -701,7 +701,7 @@
702702
703703 #ifndef FTL_READONLY
704704 /* Schedules remapping for the specified bank and vBlock */
705 -void ftl_vfl_schedule_block_for_remap(uint32_t bank, uint32_t block)
 705+static void ftl_vfl_schedule_block_for_remap(uint32_t bank, uint32_t block)
706706 {
707707 if (ftl_vfl_check_remap_scheduled(bank, block) == 1) return;
708708 panicf(PANIC_FATAL, "FTL: Scheduling bank %u block %u for remap!",
@@ -717,7 +717,7 @@
718718 #ifndef FTL_READONLY
719719 /* Removes the specified bank and vBlock combination
720720 from the remap scheduled list */
721 -void ftl_vfl_mark_remap_done(uint32_t bank, uint32_t block)
 721+static void ftl_vfl_mark_remap_done(uint32_t bank, uint32_t block)
722722 {
723723 uint32_t i;
724724 uint32_t start = ftl_vfl_cxt[bank].scheduledstart;
@@ -738,7 +738,7 @@
739739 /* Logs that there is trouble for the specified vBlock on the specified bank.
740740 The vBlock will be scheduled for remap
741741 if there is too much trouble with it. */
742 -void ftl_vfl_log_trouble(uint32_t bank, uint32_t vblock)
 742+static void ftl_vfl_log_trouble(uint32_t bank, uint32_t vblock)
743743 {
744744 uint32_t i;
745745 for (i = 0; i < 5; i++)
@@ -767,7 +767,7 @@
768768
769769 #ifndef FTL_READONLY
770770 /* Logs a successful erase for the specified vBlock on the specified bank */
771 -void ftl_vfl_log_success(uint32_t bank, uint32_t vblock)
 771+static void ftl_vfl_log_success(uint32_t bank, uint32_t vblock)
772772 {
773773 uint32_t i;
774774 for (i = 0; i < 5; i++)
@@ -787,7 +787,7 @@
788788 not caring about data in there.
789789 If it worked, it will return the new pBlock number,
790790 if not (no more spare blocks available), it will return zero. */
791 -uint32_t ftl_vfl_remap_block(uint32_t bank, uint32_t block)
 791+static uint32_t ftl_vfl_remap_block(uint32_t bank, uint32_t block)
792792 {
793793 uint32_t i;
794794 uint32_t newblock = 0, newidx;
@@ -818,8 +818,8 @@
819819
820820
821821 /* Reads the specified vPage, dealing with all kinds of trouble */
822 -uint32_t ftl_vfl_read(uint32_t vpage, void* buffer, void* sparebuffer,
823 - uint32_t checkempty, uint32_t remaponfail)
 822+static uint32_t ftl_vfl_read(uint32_t vpage, void* buffer, void* sparebuffer,
 823+ uint32_t checkempty, uint32_t remaponfail)
824824 {
825825 #ifdef VFL_TRACE
826826 DEBUGF("FTL: VFL: Reading page %d", vpage);
@@ -866,8 +866,8 @@
867867
868868
869869 /* Multi-bank version of ftl_vfl_read, will read ftl_banks pages in parallel */
870 -uint32_t ftl_vfl_read_fast(uint32_t vpage, void* buffer, void* sparebuffer,
871 - uint32_t checkempty, uint32_t remaponfail)
 870+static uint32_t ftl_vfl_read_fast(uint32_t vpage, void* buffer, void* sparebuffer,
 871+ uint32_t checkempty, uint32_t remaponfail)
872872 {
873873 #ifdef VFL_TRACE
874874 DEBUGF("FTL: VFL: Fast reading page %d on all banks", vpage);
@@ -942,8 +942,8 @@
943943
944944 #ifndef FTL_READONLY
945945 /* Writes the specified vPage, dealing with all kinds of trouble */
946 -uint32_t ftl_vfl_write(uint32_t vpage, uint32_t count,
947 - void* buffer, void* sparebuffer)
 946+static uint32_t ftl_vfl_write(uint32_t vpage, uint32_t count,
 947+ void* buffer, void* sparebuffer)
948948 {
949949 uint32_t i, j;
950950 #ifdef VFL_TRACE
@@ -1019,7 +1019,7 @@
10201020
10211021
10221022 /* Mounts the VFL on all banks */
1023 -uint32_t ftl_vfl_open(void)
 1023+static uint32_t ftl_vfl_open(void)
10241024 {
10251025 uint32_t i, j, k;
10261026 uint32_t minusn, vflcxtidx, last;
@@ -1112,7 +1112,7 @@
11131113
11141114
11151115 /* Mounts the actual FTL */
1116 -uint32_t ftl_open(void)
 1116+static uint32_t ftl_open(void)
11171117 {
11181118 uint32_t i;
11191119 uint32_t ret;
@@ -1264,7 +1264,7 @@
12651265 #ifndef FTL_READONLY
12661266 /* Returns a pointer to the ftl_log entry for the specified vBlock,
12671267 or null, if there is none */
1268 -struct ftl_log_type* ftl_get_log_entry(uint32_t block)
 1268+static struct ftl_log_type* ftl_get_log_entry(uint32_t block)
12691269 {
12701270 uint32_t i;
12711271 for (i = 0; i < 0x11; i++)
@@ -1365,7 +1365,7 @@
13661366 #ifndef FTL_READONLY
13671367 /* Performs a vBlock erase, dealing with hardware,
13681368 remapping and all kinds of trouble */
1369 -uint32_t ftl_erase_block_internal(uint32_t block)
 1369+static uint32_t ftl_erase_block_internal(uint32_t block)
13701370 {
13711371 uint32_t i, j;
13721372 block = block + ftl_nand_type->blocks
@@ -1409,7 +1409,7 @@
14101410
14111411 #ifndef FTL_READONLY
14121412 /* Highlevel vBlock erase, that increments the erase counter for the block */
1413 -uint32_t ftl_erase_block(uint32_t block)
 1413+static uint32_t ftl_erase_block(uint32_t block)
14141414 {
14151415 ftl_erasectr[block]++;
14161416 if (ftl_erasectr_dirt[block >> 10] == 100) ftl_cxt.erasedirty = 1;
@@ -1422,7 +1422,7 @@
14231423 #ifndef FTL_READONLY
14241424 /* Allocates a block from the pool,
14251425 returning its vBlock number, or 0xFFFFFFFF on error */
1426 -uint32_t ftl_allocate_pool_block(void)
 1426+static uint32_t ftl_allocate_pool_block(void)
14271427 {
14281428 uint32_t i;
14291429 uint32_t erasectr = 0xFFFFFFFF, bestidx = 0xFFFFFFFF, block;
@@ -1456,7 +1456,7 @@
14571457
14581458 #ifndef FTL_READONLY
14591459 /* Releases a vBlock back into the pool */
1460 -void ftl_release_pool_block(uint32_t block)
 1460+static void ftl_release_pool_block(uint32_t block)
14611461 {
14621462 if (block >= (uint32_t)ftl_nand_type->userblocks + 0x17)
14631463 panicf(PANIC_FATAL, "FTL: Tried to release block %u", (unsigned)block);
@@ -1470,7 +1470,7 @@
14711471 #ifndef FTL_READONLY
14721472 /* Commits the location of the FTL context blocks
14731473 to a semi-randomly chosen VFL context */
1474 -uint32_t ftl_store_ctrl_block_list(void)
 1474+static uint32_t ftl_store_ctrl_block_list(void)
14751475 {
14761476 uint32_t i;
14771477 for (i = 0; i < ftl_banks; i++)
@@ -1483,7 +1483,7 @@
14841484 #ifndef FTL_READONLY
14851485 /* Saves the n-th erase counter page to the flash,
14861486 because it is too dirty or needs to be moved. */
1487 -uint32_t ftl_save_erasectr_page(uint32_t index)
 1487+static uint32_t ftl_save_erasectr_page(uint32_t index)
14881488 {
14891489 memset(&ftl_sparebuffer[0], 0xFF, 0x40);
14901490 ftl_sparebuffer[0].meta.usn = ftl_cxt.usn;
@@ -1509,7 +1509,7 @@
15101510 #ifndef FTL_READONLY
15111511 /* Increments ftl_cxt.ftlctrlpage to the next available FTL context page,
15121512 allocating a new context block if neccessary. */
1513 -uint32_t ftl_next_ctrl_pool_page(void)
 1513+static uint32_t ftl_next_ctrl_pool_page(void)
15141514 {
15151515 uint32_t i;
15161516 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
@@ -1548,8 +1548,8 @@
15491549
15501550 #ifndef FTL_READONLY
15511551 /* Copies a vPage from one location to another */
1552 -uint32_t ftl_copy_page(uint32_t source, uint32_t destination,
1553 - uint32_t lpn, uint32_t type)
 1552+static uint32_t ftl_copy_page(uint32_t source, uint32_t destination,
 1553+ uint32_t lpn, uint32_t type)
15541554 {
15551555 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
15561556 uint32_t rc = ftl_vfl_read(source, ftl_copybuffer[0],
@@ -1569,7 +1569,7 @@
15701570
15711571 #ifndef FTL_READONLY
15721572 /* Copies a pBlock to a vBlock */
1573 -uint32_t ftl_copy_block(uint32_t source, uint32_t destination)
 1573+static uint32_t ftl_copy_block(uint32_t source, uint32_t destination)
15741574 {
15751575 uint32_t i, j;
15761576 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
@@ -1611,7 +1611,7 @@
16121612
16131613 #ifndef FTL_READONLY
16141614 /* Clears ftl_log.issequential, if something violating that is written. */
1615 -void ftl_check_still_sequential(struct ftl_log_type* entry, uint32_t page)
 1615+static void ftl_check_still_sequential(struct ftl_log_type* entry, uint32_t page)
16161616 {
16171617 if (entry->pagesused != entry->pagescurrent
16181618 || entry->pageoffsets[page] != page)
@@ -1628,7 +1628,7 @@
16291629 space again. This is usually done when a scattered page block is being
16301630 removed because it is full, but less than half of the pages in there are
16311631 still in use and rest is just filled with old crap. */
1632 -uint32_t ftl_compact_scattered(struct ftl_log_type* entry)
 1632+static uint32_t ftl_compact_scattered(struct ftl_log_type* entry)
16331633 {
16341634 uint32_t i, j;
16351635 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
@@ -1684,7 +1684,7 @@
16851685
16861686 #ifndef FTL_READONLY
16871687 /* Commits an ftl_log entry to proper blocks, no matter what's in there. */
1688 -uint32_t ftl_commit_scattered(struct ftl_log_type* entry)
 1688+static uint32_t ftl_commit_scattered(struct ftl_log_type* entry)
16891689 {
16901690 uint32_t i;
16911691 uint32_t error;
@@ -1712,7 +1712,7 @@
17131713 sequentially until now, in order to be able to save a block erase by
17141714 committing it without needing to copy it again.
17151715 If this fails for whichever reason, it will be committed the usual way. */
1716 -uint32_t ftl_commit_sequential(struct ftl_log_type* entry)
 1716+static uint32_t ftl_commit_sequential(struct ftl_log_type* entry)
17171717 {
17181718 uint32_t i;
17191719 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
@@ -1758,7 +1758,7 @@
17591759 /* If a log entry is supplied, its scattered page block will be removed in
17601760 whatever way seems most appropriate. Else, the oldest scattered page block
17611761 will be freed by committing it. */
1762 -uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry)
 1762+static uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry)
17631763 {
17641764 uint32_t i;
17651765 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
@@ -1794,7 +1794,7 @@
17951795
17961796 #ifndef FTL_READONLY
17971797 /* Initialize a log entry to the values for an empty scattered page block */
1798 -void ftl_init_log_entry(struct ftl_log_type* entry)
 1798+static void ftl_init_log_entry(struct ftl_log_type* entry)
17991799 {
18001800 entry->issequential = 1;
18011801 entry->pagescurrent = 0;
@@ -1807,7 +1807,7 @@
18081808 #ifndef FTL_READONLY
18091809 /* Allocates a log entry for the specified vBlock,
18101810 first making space, if neccessary. */
1811 -struct ftl_log_type* ftl_allocate_log_entry(uint32_t block)
 1811+static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block)
18121812 {
18131813 uint32_t i;
18141814 struct ftl_log_type* entry = ftl_get_log_entry(block);
@@ -1848,7 +1848,7 @@
18491849
18501850 #ifndef FTL_READONLY
18511851 /* Commits the FTL block map, erase counters, and context to flash */
1852 -uint32_t ftl_commit_cxt(void)
 1852+static uint32_t ftl_commit_cxt(void)
18531853 {
18541854 uint32_t i;
18551855 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
@@ -1892,7 +1892,7 @@
18931893 /* Swaps the most and least worn block on the flash,
18941894 to better distribute wear. It will refuse to do anything
18951895 if the wear spread is lower than 5 erases. */
1896 -uint32_t ftl_swap_blocks(void)
 1896+static uint32_t ftl_swap_blocks(void)
18971897 {
18981898 uint32_t i;
18991899 uint32_t min = 0xFFFFFFFF, max = 0, maxidx = 0x14;
@@ -2118,6 +2118,8 @@
21192119 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
21202120 if (ftl_cxt.clean_flag == 1) return 0;
21212121
 2122+ mutex_lock(&ftl_mtx, TIMEOUT_BLOCK);
 2123+
21222124 #ifdef FTL_TRACE
21232125 DEBUGF("FTL: Syncing");
21242126 #endif
Index: embios/trunk/usb/synopsysotg.c
@@ -51,7 +51,7 @@
5252 return (DSTS & 2) == 0 ? 1 : 0;
5353 }
5454
55 -void reset_endpoints(int reinit)
 55+static void reset_endpoints(int reinit)
5656 {
5757 unsigned int i;
5858 for (i = 0; i < sizeof(endpoints)/sizeof(struct ep_type); i++)
@@ -257,7 +257,7 @@
258258 DCFG = (DCFG & ~0x7F0) | (address << 4);
259259 }
260260
261 -void ep_send(int ep, const void *ptr, int length)
 261+static void ep_send(int ep, const void *ptr, int length)
262262 {
263263 endpoints[ep].busy = true;
264264 endpoints[ep].size = length;
@@ -273,13 +273,12 @@
274274 {
275275 DIEPTSIZ(ep) = length | (packets << 19);
276276 DIEPDMA(ep) = (uint32_t)ptr;
277 -// if (length > 64) panicf(PANIC_FATAL, "%08X %08X %08X\n%08X %08X %08X", ptr, length | (packets << 19), DIEPCTL(ep), DIEPDMA(ep), DIEPTSIZ(ep), DIEPINT(ep));
278277 }
279278 clean_dcache();
280279 DIEPCTL(ep) |= 0x84000000; /* EPx OUT ENABLE CLEARNAK */
281280 }
282281
283 -void ep_recv(int ep, void *ptr, int length)
 282+static void ep_recv(int ep, void *ptr, int length)
284283 {
285284 endpoints[ep].busy = true;
286285 endpoints[ep].size = length;