summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Hohensohn <hohensoh@rockbox.org>2004-12-29 22:10:24 +0000
committerJörg Hohensohn <hohensoh@rockbox.org>2004-12-29 22:10:24 +0000
commit1a5962f2be995b669f2cc3a49be33b3ecd8dede0 (patch)
treedd9f407265826fa02ed08cc12f9fd54a093e4ad8
parent5c631a1222c81bb075ec241621aa3626bd44c31a (diff)
downloadrockbox-1a5962f2be995b669f2cc3a49be33b3ecd8dede0.tar.gz
rockbox-1a5962f2be995b669f2cc3a49be33b3ecd8dede0.zip
Shared mounting code, also more general. It will mount multiple HD partitions, too, once HAVE_MULTIVOLUME is enabled.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5518 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/main.c48
-rw-r--r--firmware/common/disk.c51
-rw-r--r--firmware/export/disk.h1
-rw-r--r--firmware/usb.c35
4 files changed, 57 insertions, 78 deletions
diff --git a/apps/main.c b/apps/main.c
index 572e0a3114..fece06a587 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -156,7 +156,6 @@ void init(void)
156void init(void) 156void init(void)
157{ 157{
158 int rc, i; 158 int rc, i;
159 struct partinfo* pinfo;
160 /* if nobody initialized ATA before, I consider this a cold start */ 159 /* if nobody initialized ATA before, I consider this a cold start */
161 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ 160 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
162 161
@@ -240,12 +239,12 @@ void init(void)
240 usb_start_monitoring(); 239 usb_start_monitoring();
241 240
242 /* FixMe: the same kind of mounting happens in usb.c, share the code. */ 241 /* FixMe: the same kind of mounting happens in usb.c, share the code. */
243 pinfo = disk_init(IF_MV(0)); 242 rc = disk_mount_all();
244 if (!pinfo) 243 if (rc<=0)
245 { 244 {
246 lcd_clear_display(); 245 lcd_clear_display();
247 lcd_puts(0, 0, "No partition"); 246 lcd_puts(0, 0, "No partition");
248 lcd_puts(0, 1, "table."); 247 lcd_puts(0, 1, "found.");
249#ifdef HAVE_LCD_BITMAP 248#ifdef HAVE_LCD_BITMAP
250 lcd_puts(0, 2, "Insert USB cable"); 249 lcd_puts(0, 2, "Insert USB cable");
251 lcd_puts(0, 3, "and fix it."); 250 lcd_puts(0, 3, "and fix it.");
@@ -256,47 +255,6 @@ void init(void)
256 system_reboot(); 255 system_reboot();
257 } 256 }
258 257
259 fat_init();
260 for ( i=0; i<4; i++ ) {
261 if (!fat_mount(IF_MV2(0,) IF_MV2(0,) pinfo[i].start))
262 break; /* only one partition gets mounted as of now */
263 }
264
265 if ( i==4 ) {
266 DEBUGF("No partition found, trying to mount sector 0.\n");
267 rc = fat_mount(IF_MV2(0,) IF_MV2(0,) 0);
268 if(rc) {
269 lcd_clear_display();
270 lcd_puts(0,0,"No FAT32");
271 lcd_puts(0,1,"partition!");
272 lcd_update();
273 sleep(HZ);
274 /* Don't leave until we have been in USB mode */
275 while(!dbg_partitions());
276
277 /* The USB thread will panic if the drive still can't be mounted */
278 }
279 }
280#ifdef HAVE_MULTIVOLUME
281 /* mount partition on the optional volume */
282#ifdef HAVE_MMC
283 if (mmc_detect()) /* for Ondio, only if card detected */
284#endif
285 {
286 pinfo = disk_init(1);
287 if (pinfo)
288 {
289 for ( i=0; i<4; i++ ) {
290 if (!fat_mount(1, 1, pinfo[i].start))
291 break; /* only one partition gets mounted as of now */
292 }
293
294 if ( i==4 ) {
295 rc = fat_mount(1, 1, 0);
296 }
297 }
298 }
299#endif /* #ifdef HAVE_MULTIVOLUME */
300 settings_calc_config_sector(); 258 settings_calc_config_sector();
301 settings_load(SETTINGS_ALL); 259 settings_load(SETTINGS_ALL);
302 settings_apply(); 260 settings_apply();
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index cfe15984f9..aa42f0793f 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -19,6 +19,10 @@
19#include <stdio.h> 19#include <stdio.h>
20#include "ata.h" 20#include "ata.h"
21#include "debug.h" 21#include "debug.h"
22#include "fat.h"
23#ifdef HAVE_MMC
24#include "ata_mmc.h"
25#endif
22#include "disk.h" 26#include "disk.h"
23 27
24/* Partition table entry layout: 28/* Partition table entry layout:
@@ -39,7 +43,7 @@
39 (array[pos] | (array[pos+1] << 8 ) | \ 43 (array[pos] | (array[pos+1] << 8 ) | \
40 (array[pos+2] << 16 ) | (array[pos+3] << 24 )) 44 (array[pos+2] << 16 ) | (array[pos+3] << 24 ))
41 45
42static struct partinfo part[8]; 46static struct partinfo part[8]; /* space for 4 partitions on 2 drives */
43 47
44struct partinfo* disk_init(IF_MV_NONVOID(int drive)) 48struct partinfo* disk_init(IF_MV_NONVOID(int drive))
45{ 49{
@@ -89,3 +93,48 @@ struct partinfo* disk_partinfo(int partition)
89 return &part[partition]; 93 return &part[partition];
90} 94}
91 95
96int disk_mount_all(void)
97{
98 struct partinfo* pinfo;
99 int i,j;
100 int mounted = 0;
101 bool found;
102 int drives = 1;
103#ifdef HAVE_MMC
104 if (mmc_detect()) /* for Ondio, only if card detected */
105 {
106 drives = 2; /* in such case we have two drives to try */
107 }
108#endif
109
110 fat_init(); /* reset all mounted partitions */
111 for (j=0; j<drives; j++)
112 {
113 found = false; /* reset partition-on-drive flag */
114 pinfo = disk_init(IF_MV(j));
115 if (pinfo == NULL)
116 {
117 continue;
118 }
119 for (i=0; mounted<NUM_VOLUMES && i<4; i++)
120 {
121 if (!fat_mount(IF_MV2(mounted,) IF_MV2(j,) pinfo[i].start))
122 {
123 mounted++;
124 found = true; /* at least one valid entry */
125 }
126 }
127
128 if (!found && mounted<NUM_VOLUMES) /* none of the 4 entries worked? */
129 { /* try "superfloppy" mode */
130 DEBUGF("No partition found, trying to mount sector 0.\n");
131 if (!fat_mount(IF_MV2(mounted,) IF_MV2(j,) 0))
132 {
133 mounted++;
134 }
135 }
136 }
137
138 return mounted;
139}
140
diff --git a/firmware/export/disk.h b/firmware/export/disk.h
index 70b73c6547..e8525d1f75 100644
--- a/firmware/export/disk.h
+++ b/firmware/export/disk.h
@@ -34,5 +34,6 @@ struct partinfo {
34/* returns a pointer to an array of 8 partinfo structs */ 34/* returns a pointer to an array of 8 partinfo structs */
35struct partinfo* disk_init(IF_MV_NONVOID(int volume)); 35struct partinfo* disk_init(IF_MV_NONVOID(int volume));
36struct partinfo* disk_partinfo(int partition); 36struct partinfo* disk_partinfo(int partition);
37int disk_mount_all(void); /* returns the # of successful mounts */
37 38
38#endif 39#endif
diff --git a/firmware/usb.c b/firmware/usb.c
index ab8e080c45..7060ccfe23 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -122,7 +122,6 @@ static void usb_enable(bool on)
122static void usb_slave_mode(bool on) 122static void usb_slave_mode(bool on)
123{ 123{
124 int rc; 124 int rc;
125 struct partinfo* pinfo;
126 125
127 if(on) 126 if(on)
128 { 127 {
@@ -135,7 +134,6 @@ static void usb_slave_mode(bool on)
135 } 134 }
136 else 135 else
137 { 136 {
138 int i;
139 DEBUGF("Leaving USB slave mode\n"); 137 DEBUGF("Leaving USB slave mode\n");
140 138
141 /* Let the ISDx00 settle */ 139 /* Let the ISDx00 settle */
@@ -146,6 +144,7 @@ static void usb_slave_mode(bool on)
146 rc = ata_init(); 144 rc = ata_init();
147 if(rc) 145 if(rc)
148 { 146 {
147 /* fixme: can we remove this? (already such in main.c) */
149 char str[32]; 148 char str[32];
150 lcd_clear_display(); 149 lcd_clear_display();
151 snprintf(str, 31, "ATA error: %d", rc); 150 snprintf(str, 31, "ATA error: %d", rc);
@@ -157,38 +156,10 @@ static void usb_slave_mode(bool on)
157 panicf("ata: %d",rc); 156 panicf("ata: %d",rc);
158 } 157 }
159 158
160 pinfo = disk_init(IF_MV(0)); 159 rc = disk_mount_all();
161 if (!pinfo) 160 if (rc <= 0) /* no partition */
162 panicf("disk: NULL");
163
164 fat_init();
165 for ( i=0; i<4; i++ ) {
166 rc = fat_mount(IF_MV2(0,) IF_MV2(0,) pinfo[i].start);
167 if (!rc)
168 break; /* only one partition gets mounted as of now */
169 }
170 if (i==4)
171 panicf("mount: %d",rc); 161 panicf("mount: %d",rc);
172#ifdef HAVE_MULTIVOLUME
173 /* mount partition on the optional volume */
174#ifdef HAVE_MMC
175 if (mmc_detect()) /* for Ondio, only if card detected */
176#endif
177 {
178 pinfo = disk_init(1);
179 if (pinfo)
180 {
181 for ( i=0; i<4; i++ ) {
182 if (!fat_mount(1, 1, pinfo[i].start))
183 break; /* only one partition gets mounted as of now */
184 }
185 162
186 if ( i==4 ) {
187 rc = fat_mount(1, 1, 0);
188 }
189 }
190 }
191#endif /* #ifdef HAVE_MULTIVOLUME */
192 } 163 }
193} 164}
194 165