diff options
Diffstat (limited to 'apps/main.c')
-rw-r--r-- | apps/main.c | 102 |
1 files changed, 42 insertions, 60 deletions
diff --git a/apps/main.c b/apps/main.c index 6c6f0d6aba..9098180fb8 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -19,11 +19,12 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "config.h" | 21 | #include "config.h" |
22 | #include "system.h" | ||
22 | 23 | ||
23 | #include "gcc_extensions.h" | 24 | #include "gcc_extensions.h" |
24 | #include "storage.h" | 25 | #include "storage.h" |
25 | #include "disk.h" | 26 | #include "disk.h" |
26 | #include "fat.h" | 27 | #include "file_internal.h" |
27 | #include "lcd.h" | 28 | #include "lcd.h" |
28 | #include "rtc.h" | 29 | #include "rtc.h" |
29 | #include "debug.h" | 30 | #include "debug.h" |
@@ -34,7 +35,6 @@ | |||
34 | #include "filetypes.h" | 35 | #include "filetypes.h" |
35 | #include "panic.h" | 36 | #include "panic.h" |
36 | #include "menu.h" | 37 | #include "menu.h" |
37 | #include "system.h" | ||
38 | #include "usb.h" | 38 | #include "usb.h" |
39 | #include "powermgmt.h" | 39 | #include "powermgmt.h" |
40 | #include "adc.h" | 40 | #include "adc.h" |
@@ -203,80 +203,53 @@ int main(void) | |||
203 | root_menu(); | 203 | root_menu(); |
204 | } | 204 | } |
205 | 205 | ||
206 | static int init_dircache(bool preinit) INIT_ATTR; | ||
207 | static int init_dircache(bool preinit) | ||
208 | { | ||
209 | #ifdef HAVE_DIRCACHE | 206 | #ifdef HAVE_DIRCACHE |
210 | int result = 0; | 207 | static int INIT_ATTR init_dircache(bool preinit) |
211 | bool clear = false; | 208 | { |
212 | |||
213 | if (preinit) | 209 | if (preinit) |
214 | dircache_init(); | 210 | dircache_init(MAX(global_status.dircache_size, 0)); |
215 | 211 | ||
216 | if (!global_settings.dircache) | 212 | if (!global_settings.dircache) |
217 | return 0; | 213 | return -1; |
214 | |||
215 | int result = -1; | ||
218 | 216 | ||
219 | # ifdef HAVE_EEPROM_SETTINGS | 217 | #ifdef HAVE_EEPROM_SETTINGS |
220 | if (firmware_settings.initialized && firmware_settings.disk_clean | 218 | if (firmware_settings.initialized && |
221 | && preinit) | 219 | firmware_settings.disk_clean && |
220 | preinit) | ||
222 | { | 221 | { |
223 | result = dircache_load(); | 222 | result = dircache_load(); |
224 | |||
225 | if (result < 0) | 223 | if (result < 0) |
226 | { | ||
227 | firmware_settings.disk_clean = false; | 224 | firmware_settings.disk_clean = false; |
228 | if (global_status.dircache_size <= 0) | ||
229 | { | ||
230 | /* This will be in default language, settings are not | ||
231 | applied yet. Not really any easy way to fix that. */ | ||
232 | splash(0, str(LANG_SCANNING_DISK)); | ||
233 | clear = true; | ||
234 | } | ||
235 | |||
236 | dircache_build(global_status.dircache_size); | ||
237 | } | ||
238 | } | 225 | } |
239 | else | 226 | else |
240 | # endif | 227 | #endif /* HAVE_EEPROM_SETTINGS */ |
228 | if (!preinit) | ||
241 | { | 229 | { |
242 | if (preinit) | 230 | result = dircache_enable(); |
243 | return -1; | 231 | if (result != 0) |
244 | |||
245 | if (!dircache_is_enabled() | ||
246 | && !dircache_is_initializing()) | ||
247 | { | 232 | { |
248 | if (global_status.dircache_size <= 0) | 233 | if (result > 0) |
249 | { | 234 | { |
235 | /* Print "Scanning disk..." to the display. */ | ||
250 | splash(0, str(LANG_SCANNING_DISK)); | 236 | splash(0, str(LANG_SCANNING_DISK)); |
251 | clear = true; | 237 | dircache_wait(); |
238 | backlight_on(); | ||
239 | show_logo(); | ||
252 | } | 240 | } |
253 | result = dircache_build(global_status.dircache_size); | ||
254 | } | ||
255 | 241 | ||
256 | if (result < 0) | 242 | struct dircache_info info; |
257 | { | 243 | dircache_get_info(&info); |
258 | /* Initialization of dircache failed. Manual action is | 244 | global_status.dircache_size = info.size; |
259 | * necessary to enable dircache again. | 245 | status_save(); |
260 | */ | ||
261 | splashf(0, "Dircache failed, disabled. Result: %d", result); | ||
262 | global_settings.dircache = false; | ||
263 | } | 246 | } |
264 | } | 247 | /* else don't wait or already enabled by load */ |
265 | |||
266 | if (clear) | ||
267 | { | ||
268 | backlight_on(); | ||
269 | show_logo(); | ||
270 | global_status.dircache_size = dircache_get_cache_size(); | ||
271 | status_save(); | ||
272 | } | 248 | } |
273 | 249 | ||
274 | return result; | 250 | return result; |
275 | #else | ||
276 | (void)preinit; | ||
277 | return 0; | ||
278 | #endif | ||
279 | } | 251 | } |
252 | #endif /* HAVE_DIRCACHE */ | ||
280 | 253 | ||
281 | #ifdef HAVE_TAGCACHE | 254 | #ifdef HAVE_TAGCACHE |
282 | static void init_tagcache(void) INIT_ATTR; | 255 | static void init_tagcache(void) INIT_ATTR; |
@@ -363,6 +336,7 @@ static void init(void) | |||
363 | button_init(); | 336 | button_init(); |
364 | powermgmt_init(); | 337 | powermgmt_init(); |
365 | backlight_init(); | 338 | backlight_init(); |
339 | unicode_init(); | ||
366 | #ifdef SIMULATOR | 340 | #ifdef SIMULATOR |
367 | sim_tasks_init(); | 341 | sim_tasks_init(); |
368 | #endif | 342 | #endif |
@@ -392,8 +366,10 @@ static void init(void) | |||
392 | settings_reset(); | 366 | settings_reset(); |
393 | settings_load(SETTINGS_ALL); | 367 | settings_load(SETTINGS_ALL); |
394 | settings_apply(true); | 368 | settings_apply(true); |
369 | #ifdef HAVE_DIRCACHE | ||
395 | init_dircache(true); | 370 | init_dircache(true); |
396 | init_dircache(false); | 371 | init_dircache(false); |
372 | #endif | ||
397 | #ifdef HAVE_TAGCACHE | 373 | #ifdef HAVE_TAGCACHE |
398 | init_tagcache(); | 374 | init_tagcache(); |
399 | #endif | 375 | #endif |
@@ -429,6 +405,8 @@ static void init(void) | |||
429 | 405 | ||
430 | #else | 406 | #else |
431 | 407 | ||
408 | #include "errno.h" | ||
409 | |||
432 | static void init(void) INIT_ATTR; | 410 | static void init(void) INIT_ATTR; |
433 | static void init(void) | 411 | static void init(void) |
434 | { | 412 | { |
@@ -443,6 +421,9 @@ static void init(void) | |||
443 | core_allocator_init(); | 421 | core_allocator_init(); |
444 | kernel_init(); | 422 | kernel_init(); |
445 | 423 | ||
424 | /* early early early! */ | ||
425 | filesystem_init(); | ||
426 | |||
446 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 427 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
447 | set_cpu_frequency(CPUFREQ_NORMAL); | 428 | set_cpu_frequency(CPUFREQ_NORMAL); |
448 | #ifdef CPU_COLDFIRE | 429 | #ifdef CPU_COLDFIRE |
@@ -462,6 +443,7 @@ static void init(void) | |||
462 | /* current_tick should be ticking by now */ | 443 | /* current_tick should be ticking by now */ |
463 | CHART("ticking"); | 444 | CHART("ticking"); |
464 | 445 | ||
446 | unicode_init(); | ||
465 | lcd_init(); | 447 | lcd_init(); |
466 | #ifdef HAVE_REMOTE_LCD | 448 | #ifdef HAVE_REMOTE_LCD |
467 | lcd_remote_init(); | 449 | lcd_remote_init(); |
@@ -558,8 +540,6 @@ static void init(void) | |||
558 | } | 540 | } |
559 | #endif | 541 | #endif |
560 | 542 | ||
561 | |||
562 | disk_init_subsystem(); | ||
563 | CHART(">storage_init"); | 543 | CHART(">storage_init"); |
564 | rc = storage_init(); | 544 | rc = storage_init(); |
565 | CHART("<storage_init"); | 545 | CHART("<storage_init"); |
@@ -661,22 +641,24 @@ static void init(void) | |||
661 | CHART("<settings_load(ALL)"); | 641 | CHART("<settings_load(ALL)"); |
662 | } | 642 | } |
663 | 643 | ||
644 | #ifdef HAVE_DIRCACHE | ||
664 | CHART(">init_dircache(true)"); | 645 | CHART(">init_dircache(true)"); |
665 | rc = init_dircache(true); | 646 | rc = init_dircache(true); |
666 | CHART("<init_dircache(true)"); | 647 | CHART("<init_dircache(true)"); |
667 | if (rc < 0) | ||
668 | { | ||
669 | #ifdef HAVE_TAGCACHE | 648 | #ifdef HAVE_TAGCACHE |
649 | if (rc < 0) | ||
670 | remove(TAGCACHE_STATEFILE); | 650 | remove(TAGCACHE_STATEFILE); |
671 | #endif | 651 | #endif /* HAVE_TAGCACHE */ |
672 | } | 652 | #endif /* HAVE_DIRCACHE */ |
673 | 653 | ||
674 | CHART(">settings_apply(true)"); | 654 | CHART(">settings_apply(true)"); |
675 | settings_apply(true); | 655 | settings_apply(true); |
676 | CHART("<settings_apply(true)"); | 656 | CHART("<settings_apply(true)"); |
657 | #ifdef HAVE_DIRCACHE | ||
677 | CHART(">init_dircache(false)"); | 658 | CHART(">init_dircache(false)"); |
678 | init_dircache(false); | 659 | init_dircache(false); |
679 | CHART("<init_dircache(false)"); | 660 | CHART("<init_dircache(false)"); |
661 | #endif | ||
680 | #ifdef HAVE_TAGCACHE | 662 | #ifdef HAVE_TAGCACHE |
681 | CHART(">init_tagcache"); | 663 | CHART(">init_tagcache"); |
682 | init_tagcache(); | 664 | init_tagcache(); |