aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgermeier <germeier>2004-05-30 16:28:51 +0000
committergermeier <germeier>2004-05-30 16:28:51 +0000
commitce23b1180a4e5a97971a2dda64bc6706338e45e6 (patch)
tree5cc0aed86eeb7440f74e9907761616bcf9e0c233
parent9e7e6f1129f91f888e4049e5d7acd8b0472efeb5 (diff)
downloadmpiosh-ce23b1180a4e5a97971a2dda64bc6706338e45e6.tar.gz
mpiosh-ce23b1180a4e5a97971a2dda64bc6706338e45e6.tar.bz2
mpiosh-ce23b1180a4e5a97971a2dda64bc6706338e45e6.zip
added Roberts MMC code (step 1)
-rw-r--r--ChangeLog5
-rw-r--r--libmpio/Makefile.am2
-rw-r--r--libmpio/defs.h12
-rw-r--r--libmpio/src/fat.c16
-rw-r--r--libmpio/src/mmc.c101
-rw-r--r--libmpio/src/mmc.h49
-rw-r--r--libmpio/src/mpio.c83
7 files changed, 236 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 273d71d..1b01259 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
2004-05-30 Markus Germeier <mager@tzi.de>
+ * added Roberts MMC code (step 1)
+ * fixed a FAT bug he found on the way
+ * Thanks and kudos to Robert!
+
+2004-05-30 Markus Germeier <mager@tzi.de>
* changed version to 0.7.1-pre2
2004-04-24 Markus Germeier <mager@tzi.de>
diff --git a/libmpio/Makefile.am b/libmpio/Makefile.am
index 2f2c5ca..2b55f7f 100644
--- a/libmpio/Makefile.am
+++ b/libmpio/Makefile.am
@@ -9,6 +9,7 @@ libmpio_la_SOURCES= \
src/io.c \
src/debug.c \
src/smartmedia.c \
+ src/mmc.c \
src/directory.c \
src/fat.c \
src/ecc.c \
@@ -27,6 +28,7 @@ noinst_HEADERS= \
debug.h \
src/io.h \
src/smartmedia.h \
+ src/mmc.h \
src/directory.h \
src/fat.h \
src/ecc.h \
diff --git a/libmpio/defs.h b/libmpio/defs.h
index c7880c0..645a16c 100644
--- a/libmpio/defs.h
+++ b/libmpio/defs.h
@@ -1,5 +1,5 @@
/*
- * $Id: defs.h,v 1.34 2004/04/23 19:21:07 germeier Exp $
+ * $Id: defs.h,v 1.35 2004/05/30 16:28:51 germeier Exp $
*
* libmpio - a library for accessing Digit@lways MPIO players
* Copyright (C) 2002, 2003 Markus Germeier
@@ -65,6 +65,10 @@ typedef enum { GET_VERSION = 0x01,
GET_SECTOR = 0x06,
GET_SPARE_AREA = 0x07,
PUT_BLOCK = 0x08,
+ MMC_GET_BLOCK = 0x11,
+ MMC_GET_BIG_BLOCK= 0x12,
+ MMC_WRITE_SECTOR = 0x18,
+ MMC_WRITE_CLUSTER= 0x19,
PUT_MEGABLOCK = 0x30,
MODIFY_FIRMWARE = 0xa0 } mpio_cmd_t;
@@ -265,6 +269,12 @@ typedef struct {
/* special "features" */
BYTE recursive_directory;
+ /* OK sue me, we can also handle the MMCs with this */
+ BYTE mmc; /* Added for external MMC memory modules */
+ int mmc_sector_size; /* Bytes/sector */
+ BYTE mmc_cluster_size; /* Sectors/Cluster */
+ int mmc_addressing_offset; /* Offset used in addressing - varies for mmc chip size */
+
} mpio_smartmedia_t;
/* health status of a memory "card" */
diff --git a/libmpio/src/fat.c b/libmpio/src/fat.c
index 4a166fe..aab6b83 100644
--- a/libmpio/src/fat.c
+++ b/libmpio/src/fat.c
@@ -1,5 +1,5 @@
/*
- * $Id: fat.c,v 1.5 2003/10/19 21:06:35 germeier Exp $
+ * $Id: fat.c,v 1.6 2004/05/30 16:28:52 germeier Exp $
*
* libmpio - a library for accessing Digit@lways MPIO players
* Copyright (C) 2002, 2003 Markus Germeier
@@ -211,11 +211,11 @@ mpio_pbr_eval(mpio_smartmedia_t *sm)
*(sm->pbr+0x20));
/* 128 MB need 2 Bytes instead of 1.5 */
- if (sm->size != 128)
+ if (sm->size >= 128)
{
- temp = ((total_sector / 0x20 * 0x03 / 0x02 / 0x200) + 0x01);
- } else {
temp = ((total_sector / 0x20 * 0x02 / 0x200) + 0x01);
+ } else {
+ temp = ((total_sector / 0x20 * 0x03 / 0x02 / 0x200) + 0x01);
}
sm->fat_offset = sm->pbr_offset + 0x01;
@@ -541,7 +541,7 @@ mpio_fatentry_read(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f )
}
- if (sm->size == 128) {
+ if (sm->size >= 128) {
/* 2 Byte per entry */
e = f->entry * 2;
v = sm->fat[e + 1] * 0x100 + sm->fat[e];
@@ -578,7 +578,7 @@ mpio_fatentry_write(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f, WORD value)
if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
- if (sm->size == 128)
+ if (sm->size >= 128)
{
/* 2 Byte per entry */
e = f->entry * 2;
@@ -753,7 +753,7 @@ mpio_fatentry_next_entry(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f)
sm = &m->external;
f->entry = value;
- if (sm->size==128)
+ if (sm->size>=128)
{
endvalue = 0xfff8;
} else {
@@ -791,7 +791,7 @@ mpio_fat_clear(mpio_t *m, mpio_mem_t mem)
sm->fat[1] = 0xff;
sm->fat[2] = 0xff;
/* for FAT 16 */
- if (sm->size == 128)
+ if (sm->size >= 128)
sm->fat[3] = 0xff;
}
diff --git a/libmpio/src/mmc.c b/libmpio/src/mmc.c
new file mode 100644
index 0000000..10907d7
--- /dev/null
+++ b/libmpio/src/mmc.c
@@ -0,0 +1,101 @@
+/*
+ * $Id: mmc.c,v 1.1 2004/05/30 16:28:52 germeier Exp $
+ *
+ * libmpio - a library for accessing Digit@lways MPIO players
+ * Copyright (C) 2004 Robert Kellington, Markus Germeier
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc.,g 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mmc.h"
+#include "debug.h"
+
+/*
+ This routine attempts to detect when mmc module is present and set some variables according to
+ that size. If adding a new memory module do the following changes:
+ 1. Add the appropriate switch below (size and geo need to be set).
+ 2. Add the new module size and array data into the routines mmc_mpio_mbr_gen and mmc_mpio_pbr_gen for the memory
+ formating.
+ That should be all
+*/
+BYTE mpio_mmc_detect_memory(mpio_t *m, mpio_mem_t mem)
+{
+ mpio_smartmedia_t *sm=0;
+ int size;
+
+ /* just in case we encounter a player with an internel mmc memory */
+ if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
+ if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
+ if (!sm)
+ {
+ debug("error in memory selection, aborting\n");
+ exit (-1);
+ }
+
+ /*looking for likely markers*/
+ /*
+ if((m->version[0x28] == 0x32) && (m->version[0x3a] == 0x01) && (m->version[0x3b] == 0x01) &&
+ (m->version[0x30] == 0xff) && (m->version[0x31] == 0xcf))
+ */
+ if((m->version[0x39] == 0x01) && (m->version[0x3b] == 0x01) && (m->version[0x20] == 0xff) && (m->version[0x21] == 0xff) &&
+ (m->version[0x22] == 0xff) && (m->version[0x23] == 0xff) && (m->version[0x24] == 0xff) && (m->version[0x25] == 0xff))
+ {
+ switch(m->version[0x26])
+ {
+ case 0x0e: /* 16 Mb */
+ /*NOTE: This size needs formating to be added and testing*/
+ sm->size = 16;
+ sm->geo = MPIO_DISK_GEO_016;
+ break;
+ case 0x1e: /* 32 Mb */
+ sm->size = 32;
+ sm->geo = MPIO_DISK_GEO_032;
+ break;
+ case 0x3b: /* 64 Mb */
+ sm->size = 64;
+ sm->geo = MPIO_DISK_GEO_064;
+ break;
+ case 0x78: /* 128 Mb */
+ sm->size = 128;
+ sm->geo = MPIO_DISK_GEO_128;
+ break;
+ case 0xf1: /* 256 Mb */
+ sm->size = 256;
+ sm->geo = MPIO_DISK_GEO_256;
+ break;
+ default:
+ debug("Found MMC memory markers but didn't recognize size\n");
+ sm->mmc = 0;
+ sm->size = 0;
+ return 0;
+ }
+ sm->mmc = 1;
+ sm->chips = 1;
+ sm->version = 0;
+ sm->id = 0x78; /* Assigning my random id */
+
+ debug("Found MMC memory and all is OK so far\n");
+
+ return 1;
+ }
+
+ debug("Not recognized MMC memory\n");
+
+ return 0;
+}
diff --git a/libmpio/src/mmc.h b/libmpio/src/mmc.h
new file mode 100644
index 0000000..300b78e
--- /dev/null
+++ b/libmpio/src/mmc.h
@@ -0,0 +1,49 @@
+/*
+ * $Id: mmc.h,v 1.1 2004/05/30 16:28:52 germeier Exp $
+ *
+ * libmpio - a library for accessing Digit@lways MPIO players
+ * Copyright (C) 2004 Robert Kellington, Markus Germeier
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc.,g 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _MPIO_MMC_H_
+#define _MPIO_MMC_H_
+
+#include "defs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern mpio_disk_phy_t MPIO_DISK_GEO_001;
+extern mpio_disk_phy_t MPIO_DISK_GEO_002;
+extern mpio_disk_phy_t MPIO_DISK_GEO_004;
+extern mpio_disk_phy_t MPIO_DISK_GEO_008;
+extern mpio_disk_phy_t MPIO_DISK_GEO_016;
+extern mpio_disk_phy_t MPIO_DISK_GEO_032;
+extern mpio_disk_phy_t MPIO_DISK_GEO_064;
+extern mpio_disk_phy_t MPIO_DISK_GEO_128;
+extern mpio_disk_phy_t MPIO_DISK_GEO_256;
+
+/* get our configuration for MMC cards right */
+BYTE mpio_mmc_detect_memory(mpio_t *m, mpio_mem_t mem);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MPIO_MMC_H_ */
diff --git a/libmpio/src/mpio.c b/libmpio/src/mpio.c
index 229644e..60e89d5 100644
--- a/libmpio/src/mpio.c
+++ b/libmpio/src/mpio.c
@@ -1,5 +1,5 @@
/*
- * $Id: mpio.c,v 1.15 2004/04/24 16:09:58 germeier Exp $
+ * $Id: mpio.c,v 1.16 2004/05/30 16:28:52 germeier Exp $
*
* libmpio - a library for accessing Digit@lways MPIO players
* Copyright (C) 2002-2004 Markus Germeier
@@ -160,6 +160,7 @@ mpio_init_internal(mpio_t *m)
BYTE i_offset = 0x18;
/* init main memory parameters */
+ sm->mmc = 0;
sm->manufacturer = m->version[i_offset];
sm->id = m->version[i_offset + 1];
sm->chips = 1;
@@ -249,14 +250,40 @@ mpio_init_external(mpio_t *m)
mpio_smartmedia_t *sm = &(m->external);
BYTE e_offset = 0x20;
+ /* these players have a MMC/SD slot */
+ if ((m->model != MPIO_MODEL_VP_02) &&
+ (m->model != MPIO_MODEL_FL100)) {
+ debugn(0, "Trying to detect external MMC. This is work in progress. BEWARE!!\n");
+ debugn(0, "Please report your findings to mpio-devel@lists.sourceforge.net\n");
+ debugn(0, "and include the following information block\n");
+ hexdumpn(0, m->version, 64);
+
+ mpio_mmc_detect_memory(m, sm);
+
+ if (sm->size) {
+ debugn(0, "You are lucky! ;-) I found a %d MB MMC card.\n", sm->size);
+ debugn(0, "disabling memory, because low-level routines \n"
+ "are not integrated, yet. Please stay tuned.\n");
+ sm->size = 0;
+ } else {
+ debugn(0, "I'm sorry, I did not detect a MMC card.\n"
+ "If you think I should have, please report this to the mpio-devel list.\n");
+ }
+
+ return;
+ } else {
+ sm->mmc=0;
+ sm->manufacturer = 0;
+ sm->id = 0;
+ sm->chips = 0;
+ sm->size = 0;
+ }
+
/* heuristic to find the right offset for the external memory */
while((e_offset < 0x3a) && !(mpio_id_valid(m->version[e_offset])))
e_offset++;
- if ((mpio_id_valid(m->version[e_offset])) &&
- (m->model != MPIO_MODEL_VP_02) &&
- (m->model != MPIO_MODEL_FL100)) /* ignore external memory ATM until
- we know how to support it! */
+ if ((mpio_id_valid(m->version[e_offset])))
{
sm->manufacturer = m->version[e_offset];
sm->id = m->version[e_offset + 1];
@@ -417,11 +444,11 @@ mpio_init(mpio_callback_init_t progress_callback)
mpio_init_external(new_mpio);
/* read FAT/spare area */
- if (new_mpio->internal.id)
+ if (new_mpio->internal.size)
mpio_fat_read(new_mpio, MPIO_INTERNAL_MEM, progress_callback);
/* read the spare area (for block mapping) */
- if (new_mpio->external.id)
+ if (new_mpio->external.size)
{
sm = &new_mpio->external;
mpio_io_spare_read(new_mpio, MPIO_EXTERNAL_MEM, 0,
@@ -523,28 +550,38 @@ mpio_get_info(mpio_t *m, mpio_info_t *info)
m->firmware.day, m->firmware.month, m->firmware.year);
snprintf(info->model, max, "%s", mpio_model_name[m->model]);
- if (!m->internal.id)
+ if (!m->internal.size)
{
snprintf(info->mem_internal, max, "not available");
} else {
- if (m->internal.chips == 1)
- {
- snprintf(info->mem_internal, max, "%3dMB (%s)",
- mpio_id2mem(m->internal.id),
- mpio_id2manufacturer(m->internal.manufacturer));
- } else {
- snprintf(info->mem_internal, max, "%3dMB (%s) - %d chips",
- mpio_id2mem(m->internal.id)*m->internal.chips,
- mpio_id2manufacturer(m->internal.manufacturer),
- m->internal.chips);
- }
+ if (m->internal.mmc) {
+ snprintf(info->mem_internal, max, "%3dMB (MMC)",
+ m->internal.size);
+ } else {
+ if (m->internal.chips == 1)
+ {
+ snprintf(info->mem_internal, max, "%3dMB (%s)",
+ mpio_id2mem(m->internal.id),
+ mpio_id2manufacturer(m->internal.manufacturer));
+ } else {
+ snprintf(info->mem_internal, max, "%3dMB (%s) - %d chips",
+ mpio_id2mem(m->internal.id)*m->internal.chips,
+ mpio_id2manufacturer(m->internal.manufacturer),
+ m->internal.chips);
+ }
+ }
}
- if (m->external.id)
+ if (m->external.size)
{
- snprintf(info->mem_external, max, "%3dMB (%s)",
- mpio_id2mem(m->external.id),
- mpio_id2manufacturer(m->external.manufacturer));
+ if (m->external.mmc) {
+ snprintf(info->mem_external, max, "%3dMB (MMC)",
+ m->external.size);
+ } else {
+ snprintf(info->mem_external, max, "%3dMB (%s)",
+ mpio_id2mem(m->external.id),
+ mpio_id2manufacturer(m->external.manufacturer));
+ }
} else {
snprintf(info->mem_external, max, "not available");
}