summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-05-03 11:59:53 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-05-03 11:59:53 +0000
commitc7f7934e8f74be4b98abe83c2f6a2593fd294cf0 (patch)
treecdebbde186e8db107472c5a7b0775f050e7f4560 /firmware/common
parent86a59ecdf6e6bf3e45938c0ca305b892777b28e0 (diff)
downloadrockbox-c7f7934e8f74be4b98abe83c2f6a2593fd294cf0.zip
rockbox-c7f7934e8f74be4b98abe83c2f6a2593fd294cf0.tar.gz
rockbox-c7f7934e8f74be4b98abe83c2f6a2593fd294cf0.tar.bz2
rockbox-c7f7934e8f74be4b98abe83c2f6a2593fd294cf0.tar.xz
Added disk/partition handling
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@405 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/disk.c74
-rw-r--r--firmware/common/disk.h32
2 files changed, 106 insertions, 0 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
new file mode 100644
index 0000000..9572f11
--- /dev/null
+++ b/firmware/common/disk.c
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Björn Stenberg
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "ata.h"
+#include "debug.h"
+#include "disk.h"
+
+/* Partition table entry layout:
+ -----------------------
+ 0: 0x80 - active
+ 1: starting head
+ 2: starting sector
+ 3: starting cylinder
+ 4: partition type
+ 5: end head
+ 6: end sector
+ 7: end cylinder
+ 8-11: starting sector (LBA)
+ 12-15: nr of sectors in partition
+*/
+
+#define BYTES2INT32(array,pos) \
+ (array[pos] | (array[pos+1] << 8 ) | \
+ (array[pos+2] << 16 ) | (array[pos+3] << 24 ))
+
+struct partinfo part[8];
+
+int disk_init(void)
+{
+ int i;
+ unsigned char sector[512];
+
+ ata_read_sectors(0,1,&sector);
+
+ /* check that the boot sector is initialized */
+ if ( (sector[510] != 0x55) ||
+ (sector[511] != 0xaa)) {
+ DEBUGF("Bad boot sector signature\n");
+ return -1;
+ }
+
+ /* parse partitions */
+ for ( i=0; i<4; i++ ) {
+ unsigned char* ptr = sector + 0x1be + 16*i;
+ part[i].type = ptr[4];
+ part[i].start = BYTES2INT32(ptr, 8);
+ part[i].size = BYTES2INT32(ptr, 12);
+
+ DEBUGF("Part%d: Type %02x, start: %08x size: %08x\n",
+ i,part[i].type,part[i].start,part[i].size);
+
+ /* extended? */
+ if ( part[i].type == 5 ) {
+ /* not handled yet */
+ }
+ }
+
+ return 0;
+}
diff --git a/firmware/common/disk.h b/firmware/common/disk.h
new file mode 100644
index 0000000..1e95c73
--- /dev/null
+++ b/firmware/common/disk.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Björn Stenberg
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _DISK_H_
+#define _DISK_H_
+
+struct partinfo {
+ unsigned long start; /* first sector (LBA) */
+ unsigned long size; /* number of sectors */
+ unsigned char type;
+};
+
+extern struct partinfo part[8];
+
+int disk_init(void);
+
+#endif