summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/main.c6
-rw-r--r--apps/settings.c38
-rw-r--r--apps/settings.h1
3 files changed, 39 insertions, 6 deletions
diff --git a/apps/main.c b/apps/main.c
index 1a163ebd72..38bbd71177 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -79,6 +79,7 @@ void init(void)
79 font_init(); 79 font_init();
80 show_logo(); 80 show_logo();
81 settings_reset(); 81 settings_reset();
82 settings_calc_config_sector();
82 settings_load(SETTINGS_ALL); 83 settings_load(SETTINGS_ALL);
83 settings_apply(); 84 settings_apply();
84 sleep(HZ/2); 85 sleep(HZ/2);
@@ -224,11 +225,12 @@ void init(void)
224 } 225 }
225 } 226 }
226 227
228 settings_calc_config_sector();
227 settings_load(SETTINGS_ALL); 229 settings_load(SETTINGS_ALL);
228 settings_apply(); 230 settings_apply();
229 231
230 status_init(); 232 status_init();
231 playlist_init(); 233 playlist_init();
232 tree_init(); 234 tree_init();
233 235
234 /* No buffer allocation (see buffer.c) may take place after the call to 236 /* No buffer allocation (see buffer.c) may take place after the call to
diff --git a/apps/settings.c b/apps/settings.c
index 708a38b678..bb8deb0cb4 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -82,6 +82,7 @@ const char rec_base_directory[] = REC_BASE_DIR;
82#endif 82#endif
83 83
84long lasttime = 0; 84long lasttime = 0;
85static int config_sector = 0; /* mark uninitialized */
85static unsigned char config_block[CONFIG_BLOCK_SIZE]; 86static unsigned char config_block[CONFIG_BLOCK_SIZE];
86 87
87 88
@@ -481,8 +482,8 @@ static int save_config_buffer( void )
481 482
482#endif 483#endif
483 484
484 if (fat_startsector() != 0) 485 if (config_sector != 0)
485 ata_delayed_write( 61, config_block); 486 ata_delayed_write( config_sector, config_block);
486 else 487 else
487 return -1; 488 return -1;
488 489
@@ -502,8 +503,8 @@ static int load_config_buffer(int which)
502 503
503 if (which & SETTINGS_HD) 504 if (which & SETTINGS_HD)
504 { 505 {
505 if (fat_startsector() != 0) { 506 if (config_sector != 0) {
506 ata_read_sectors( 61, 1, config_block); 507 ata_read_sectors( config_sector, 1, config_block);
507 508
508 /* calculate the checksum, check it and the header */ 509 /* calculate the checksum, check it and the header */
509 chksum = calculate_config_checksum(config_block); 510 chksum = calculate_config_checksum(config_block);
@@ -601,6 +602,35 @@ static void save_bit_table(const struct bit_entry* p_table, int count, int bitst
601 curr_bit); /* = position after last element */ 602 curr_bit); /* = position after last element */
602} 603}
603 604
605/*
606 * figure out the config sector from the partition table and the
607 * mounted file system
608 */
609void settings_calc_config_sector(void)
610{
611#ifdef SIMULATOR
612 config_sector = 61;
613#else
614 int i, partition_start;
615 int sector = 0;
616
617 if (fat_startsector != 0) /* There is a partition table */
618 {
619 sector = 61;
620 for (i = 0; i < 4; i++)
621 {
622 partition_start = disk_partinfo(i)->start;
623 if (partition_start != 0 && (partition_start - 2) < sector)
624 sector = partition_start - 2;
625 }
626 if (sector < 0)
627 sector = 0;
628 }
629
630 splash(HZ, true, "CfgSec: %d", sector);
631 config_sector = sector;
632#endif
633}
604 634
605/* 635/*
606 * persist all runtime user settings to disk or RTC RAM 636 * persist all runtime user settings to disk or RTC RAM
diff --git a/apps/settings.h b/apps/settings.h
index 0af466c5f7..aa408ea2cc 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -281,6 +281,7 @@ struct opt_items {
281 281
282/* prototypes */ 282/* prototypes */
283 283
284void settings_calc_config_sector(void);
284int settings_save(void); 285int settings_save(void);
285void settings_load(int which); 286void settings_load(int which);
286void settings_reset(void); 287void settings_reset(void);