summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
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 0000000000..9572f115e5
--- /dev/null
+++ b/firmware/common/disk.c
@@ -0,0 +1,74 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "ata.h"
20#include "debug.h"
21#include "disk.h"
22
23/* Partition table entry layout:
24 -----------------------
25 0: 0x80 - active
26 1: starting head
27 2: starting sector
28 3: starting cylinder
29 4: partition type
30 5: end head
31 6: end sector
32 7: end cylinder
33 8-11: starting sector (LBA)
34 12-15: nr of sectors in partition
35*/
36
37#define BYTES2INT32(array,pos) \
38 (array[pos] | (array[pos+1] << 8 ) | \
39 (array[pos+2] << 16 ) | (array[pos+3] << 24 ))
40
41struct partinfo part[8];
42
43int disk_init(void)
44{
45 int i;
46 unsigned char sector[512];
47
48 ata_read_sectors(0,1,&sector);
49
50 /* check that the boot sector is initialized */
51 if ( (sector[510] != 0x55) ||
52 (sector[511] != 0xaa)) {
53 DEBUGF("Bad boot sector signature\n");
54 return -1;
55 }
56
57 /* parse partitions */
58 for ( i=0; i<4; i++ ) {
59 unsigned char* ptr = sector + 0x1be + 16*i;
60 part[i].type = ptr[4];
61 part[i].start = BYTES2INT32(ptr, 8);
62 part[i].size = BYTES2INT32(ptr, 12);
63
64 DEBUGF("Part%d: Type %02x, start: %08x size: %08x\n",
65 i,part[i].type,part[i].start,part[i].size);
66
67 /* extended? */
68 if ( part[i].type == 5 ) {
69 /* not handled yet */
70 }
71 }
72
73 return 0;
74}
diff --git a/firmware/common/disk.h b/firmware/common/disk.h
new file mode 100644
index 0000000000..1e95c73c6b
--- /dev/null
+++ b/firmware/common/disk.h
@@ -0,0 +1,32 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _DISK_H_
20#define _DISK_H_
21
22struct partinfo {
23 unsigned long start; /* first sector (LBA) */
24 unsigned long size; /* number of sectors */
25 unsigned char type;
26};
27
28extern struct partinfo part[8];
29
30int disk_init(void);
31
32#endif