aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgermeier <germeier>2002-09-03 10:22:24 +0000
committergermeier <germeier>2002-09-03 10:22:24 +0000
commit803c62b42c74886315856b9d9c6e2954c97f3ea8 (patch)
tree4656818e21a086a7ab2bfba30c4418199e714637
parente3021e217748a48295856259cf418f6754569579 (diff)
downloadmpiosh-803c62b42c74886315856b9d9c6e2954c97f3ea8.tar.gz
mpiosh-803c62b42c74886315856b9d9c6e2954c97f3ea8.tar.bz2
mpiosh-803c62b42c74886315856b9d9c6e2954c97f3ea8.zip
"small" cleanups to libmpio before starting major structural changes
-rw-r--r--ChangeLog4
-rw-r--r--libmpio/directory.c5
-rw-r--r--libmpio/fat.c96
-rw-r--r--libmpio/io.c500
-rw-r--r--libmpio/io.h12
-rw-r--r--libmpio/mpio.c93
-rw-r--r--libmpio/smartmedia.c27
7 files changed, 414 insertions, 323 deletions
diff --git a/ChangeLog b/ChangeLog
index 60a82ba..495cc67 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2002-09-03 Markus Germeier <mager@tzi.de>
+
+ * libmpio/*: various "little" code cleanups
+
2002-09-01 Andreas Buesching <crunchy@tzi.de>
* mpio_tool/mpiosh.c: add commands lcd and ldir
diff --git a/libmpio/directory.c b/libmpio/directory.c
index b14dd6d..0344c1c 100644
--- a/libmpio/directory.c
+++ b/libmpio/directory.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: directory.c,v 1.1 2002/08/28 16:10:51 salmoon Exp $
+ * $Id: directory.c,v 1.2 2002/09/03 10:22:24 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -251,8 +251,7 @@ mpio_rootdir_read (mpio_t *m, mpio_mem_t mem)
if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
for (i = 0; i < DIR_NUM; i++) {
- if (mpio_io_sector_read(m, mem,
- (sm->dir_offset + i), sm->size, 0, recvbuff))
+ if (mpio_io_sector_read(m, mem, (sm->dir_offset + i), recvbuff))
return 1;
memcpy(sm->dir + (i * SECTOR_SIZE), recvbuff, SECTOR_SIZE);
diff --git a/libmpio/fat.c b/libmpio/fat.c
index c978b2b..900d75f 100644
--- a/libmpio/fat.c
+++ b/libmpio/fat.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: fat.c,v 1.1 2002/08/28 16:10:51 salmoon Exp $
+ * $Id: fat.c,v 1.2 2002/09/03 10:22:24 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -36,34 +36,40 @@ mpio_bootblocks_read (mpio_t *m, mpio_mem_t mem)
BYTE *pe; /* partition entry */
BYTE *bpb; /* BIOS Parameter Block */
- mpio_smartmedia_t *sm;
+ mpio_smartmedia_t *sm=0;
int sector, head, cylinder, total_sector;
long temp;
+ /* this should not be needed for internal memory, but ... */
if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
+ if (!sm)
+ return 1;
/* TODO: check a few things more, just to be sure */
/* read CIS (just in case it might me usefull) */
/* fixed @ offset 0x20 */
- if (mpio_io_sector_read(m, mem, 0x20, sm->size, 0, sm->cis)) {
- debug("error reading CIS\n");
- return 1;
- }
+ if (mpio_io_sector_read(m, mem, 0x20, sm->cis))
+ {
+ debug("error reading CIS\n");
+ return 1;
+ }
/* read MBR */
/* fixed @ offset 0x40 */
- if (mpio_io_sector_read(m, mem, 0x40, sm->size, 0, sm->mbr)) {
- debug("error reading MBR\n");
- return 1;
- }
+ if (mpio_io_sector_read(m, mem, 0x40, sm->mbr))
+ {
+ debug("error reading MBR\n");
+ return 1;
+ }
- if ((sm->mbr[0x1fe] != 0x55) || (sm->mbr[0x1ff] != 0xaa)) {
- debug("This is not the MBR!\n");
- return 1;
- }
+ if ((sm->mbr[0x1fe] != 0x55) || (sm->mbr[0x1ff] != 0xaa))
+ {
+ debug("This is not the MBR!\n");
+ return 1;
+ }
/* always use the first partition */
/* we probably don't need to support others */
@@ -77,18 +83,23 @@ mpio_bootblocks_read (mpio_t *m, mpio_mem_t mem)
sm->geo.NumSector + sector - 1 + OFFSET_MBR;
/* read PBR */
- if (mpio_io_sector_read(m, mem, sm->pbr_offset, sm->size, 0, sm->pbr))
+ if (mpio_io_sector_read(m, mem, sm->pbr_offset, sm->pbr))
+ {
+ debug("error reading PBR\n");
return 1;
+ }
- if ((sm->pbr[0x1fe] != 0x55) || (sm->pbr[0x1ff] != 0xaa)) {
- debug("This is not the PBR!\n");
- return 1;
- }
+ if ((sm->pbr[0x1fe] != 0x55) || (sm->pbr[0x1ff] != 0xaa))
+ {
+ debug("This is not the PBR!\n");
+ return 1;
+ }
- if (strncmp((sm->pbr+0x36),"FAT", 3) != 0) {
- debug("Did not find an FAT signature, *not* good!, aborting!\n");
- exit (1);
- }
+ if (strncmp((sm->pbr+0x36),"FAT", 3) != 0)
+ {
+ debug("Did not find an FAT signature, *not* good!, aborting!\n");
+ exit (1);
+ }
bpb = sm->pbr + 0x0b;
@@ -101,9 +112,11 @@ mpio_bootblocks_read (mpio_t *m, mpio_mem_t mem)
/* 128 MB need 2 Bytes instead of 1.5 */
if (sm->size != 128)
- temp = ((total_sector / 0x20 * 0x03 / 0x02 / 0x200) + 0x01);
- else
- temp = ((total_sector / 0x20 * 0x02 / 0x200) + 0x01);
+ {
+ temp = ((total_sector / 0x20 * 0x03 / 0x02 / 0x200) + 0x01);
+ } else {
+ temp = ((total_sector / 0x20 * 0x02 / 0x200) + 0x01);
+ }
sm->max_cluster = (total_sector / BLOCK_SECTORS);
debugn(2,"max_cluster: %d\n", sm->max_cluster);
@@ -123,19 +136,22 @@ mpio_fat_read (mpio_t *m, mpio_mem_t mem)
BYTE recvbuff[SECTOR_SIZE];
int i;
- if (mem == MPIO_INTERNAL_MEM) {
- sm = &m->internal;
- if (mpio_io_spare_read(m, mem, 0, (sm->size / sm->chips), 0, sm->fat,
- (sm->fat_size * SECTOR_SIZE)))
- return 1;
- return 0;
- }
+ if (mem == MPIO_INTERNAL_MEM)
+ {
+ sm = &m->internal;
+ if (mpio_io_spare_read(m, mem, 0, (sm->size / sm->chips), 0, sm->fat,
+ (sm->fat_size * SECTOR_SIZE)))
+ return 1;
+ return 0;
+ }
if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
+
+ if (!sm)
+ return 1;
for (i = 0; i < sm->fat_size; i++) {
- if (mpio_io_sector_read(m, mem, (sm->fat_offset + i),
- sm->size, 0, recvbuff))
+ if (mpio_io_sector_read(m, mem, (sm->fat_offset + i), recvbuff))
return 1;
memcpy(sm->fat + (i * SECTOR_SIZE), recvbuff, SECTOR_SIZE);
@@ -393,20 +409,20 @@ mpio_fat_write(mpio_t *m, mpio_mem_t mem)
}
if (i == 0x40)
- mpio_io_sector_write(m, mem, 0x40, sm->size, 0, sm->mbr);
+ mpio_io_sector_write(m, mem, 0x40, sm->mbr);
if ((i > 0x40) && (i < sm->pbr_offset))
- mpio_io_sector_write(m, mem, i, sm->size, 0, dummy);
+ mpio_io_sector_write(m, mem, i, dummy);
if (i == sm->pbr_offset)
- mpio_io_sector_write(m, mem, sm->pbr_offset, sm->size, 0, sm->pbr);
+ mpio_io_sector_write(m, mem, sm->pbr_offset, sm->pbr);
if ((i >= sm->fat_offset) && (i < (sm->fat_offset + (2 * sm->fat_size))))
- mpio_io_sector_write(m, mem, i, sm->size, 0,
+ mpio_io_sector_write(m, mem, i,
(sm->fat + SECTOR_SIZE *
((i - sm->fat_offset) % sm->fat_size)));
if (i>=sm->dir_offset)
- mpio_io_sector_write(m, mem, i, sm->size, 0,
+ mpio_io_sector_write(m, mem, i,
(sm->dir + (i - sm->dir_offset) * SECTOR_SIZE));
}
diff --git a/libmpio/io.c b/libmpio/io.c
index 1e49a27..01af3bc 100644
--- a/libmpio/io.c
+++ b/libmpio/io.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.c,v 1.1 2002/08/28 16:10:50 salmoon Exp $
+ * $Id: io.c,v 1.2 2002/09/03 10:22:24 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -56,18 +56,20 @@ WORD index2blockaddress(WORD ba)
low = (ba * 2) & 0xff;
c = high;
- while (c) {
- if (c & 0x01)
- p ^= 1;
- c /= 2;
- }
+ while (c)
+ {
+ if (c & 0x01)
+ p ^= 1;
+ c /= 2;
+ }
c = low;
- while (c) {
- if (c & 0x01)
- p ^= 0x01;
- c /= 2;
- }
+ while (c)
+ {
+ if (c & 0x01)
+ p ^= 0x01;
+ c /= 2;
+ }
addr = (high * 0x100) + low + p;
@@ -86,15 +88,15 @@ WORD index2blockaddress(WORD ba)
* cmd: commando code
* mem: internal/external
* index: sector/block
- * small: FAT with less or equal 32MB
+ * size: size of used memory chip
* wsize: write size, only for PUT_BLOCK
- *
+ * buffer: output buffer of command packet
*
*/
int
mpio_io_set_cmdpacket(mpio_cmd_t cmd, mpio_mem_t mem, DWORD index,
- BYTE small, BYTE wsize, BYTE *buffer)
+ BYTE size, BYTE wsize, BYTE *buffer)
{
/* clear cmdpacket*/
@@ -108,15 +110,16 @@ mpio_io_set_cmdpacket(mpio_cmd_t cmd, mpio_mem_t mem, DWORD index,
* to address sectors or blocks.
* The highest byte has to be 0xff in that case!
*/
- if (small <= 32) {
- *(buffer + 0x05) = 0xff;
- } else {
- *(buffer + 0x05) = (BYTE) (index >> 16);
- }
- *(buffer + 0x06) = wsize; /* is this always 0x48 in case of a write ?? */
+ if (size <= 32)
+ {
+ *(buffer + 0x05) = 0xff;
+ } else {
+ *(buffer + 0x05) = (BYTE) (index >> 16);
+ }
+ /* is this always 0x48 in case of a block write ?? */
+ *(buffer + 0x06) = wsize;
memcpy((buffer + 0x3b), "jykim", 5);
-
return (0);
}
@@ -217,20 +220,22 @@ mpio_io_version_read(mpio_t *m, BYTE *buffer)
nwrite = mpio_io_bulk_write (m->fd, cmdpacket, 0x40);
- if (nwrite != CMD_SIZE) {
- debug ("Failed to send command.\n\n");
- close (m->fd);
- return 0;
- }
+ if (nwrite != CMD_SIZE)
+ {
+ debug ("Failed to send command.\n\n");
+ close (m->fd);
+ return 0;
+ }
/* Receive packet from MPIO */
nread = mpio_io_bulk_read (m->fd, status, 0x40);
- if (nread == -1 || nread != 0x40) {
+ if (nread == -1 || nread != 0x40)
+ {
debug ("Failed to read Sector.\n%x\n",nread);
- close (m->fd);
- return 0;
- }
+ close (m->fd);
+ return 0;
+ }
debugn (5, "<<< MPIO\n");
hexdump (status, 0x40);
@@ -246,49 +251,70 @@ mpio_io_version_read(mpio_t *m, BYTE *buffer)
* parameter:
*
* m: mpio context
- * area: MPIO_{INTERNAL,EXTERNAL}_MEM
+ * mem: MPIO_{INTERNAL,EXTERNAL}_MEM
* index: index number of sector to read
- * small: size of memory chip to read from
- * wsize: dummy
* output: return buffer (has to be SECTOR_SIZE)
*
*/
+
+/* right now we assume we only want to read single sectors from
+ * the _first_ internal memory chip
+ */
+
int
-mpio_io_sector_read(mpio_t *m, BYTE area, DWORD index, BYTE small,
- BYTE wsize, BYTE *output)
+mpio_io_sector_read(mpio_t *m, BYTE mem, DWORD index, BYTE *output)
{
+ mpio_smartmedia_t *sm;
+
int nwrite, nread;
BYTE cmdpacket[CMD_SIZE], recvbuff[SECTOR_TRANS];
- mpio_io_set_cmdpacket (GET_SECTOR, area, index, small, wsize, cmdpacket);
+ 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);
+ }
+
+ mpio_io_set_cmdpacket (GET_SECTOR, mem, index, sm->size, 0, cmdpacket);
debugn (5, "\n>>> MPIO\n");
hexdump (cmdpacket, sizeof(cmdpacket));
nwrite = mpio_io_bulk_write (m->fd, cmdpacket, 0x40);
- if(nwrite != CMD_SIZE) {
- debug ("\nFailed to send command.\n\n");
- close (m->fd);
- return 1;
- }
+ if(nwrite != CMD_SIZE)
+ {
+ debug ("\nFailed to send command.\n\n");
+ close (m->fd);
+ return 1;
+ }
/* Receive packet from MPIO */
nread = mpio_io_bulk_read (m->fd, recvbuff, SECTOR_TRANS);
- if(nread != SECTOR_TRANS) {
- debug ("\nFailed to read Sector.\n%x\n", nread);
- close (m->fd);
- return 1;
- }
+ if(nread != SECTOR_TRANS)
+ {
+ debug ("\nFailed to read Sector.\n%x\n", nread);
+ close (m->fd);
+ return 1;
+ }
/* check ECC Area information */
- if (area==MPIO_EXTERNAL_MEM) {
- mpio_ecc_256_check (recvbuff,
- (recvbuff + SECTOR_SIZE + 13));
- mpio_ecc_256_check ((recvbuff + (SECTOR_SIZE / 2)),
- (recvbuff + SECTOR_SIZE + 8));
- }
+ if (mem==MPIO_EXTERNAL_MEM)
+ {
+ mpio_ecc_256_check (recvbuff,
+ (recvbuff + SECTOR_SIZE + 13));
+ mpio_ecc_256_check ((recvbuff + (SECTOR_SIZE / 2)),
+ (recvbuff + SECTOR_SIZE + 8));
+ }
+
+ if (mem==MPIO_INTERNAL_MEM)
+ {
+ debugn(2, "WARNING, code for internal FAT entry (in ECC area)"
+ " not yet in place!!\n");
+ }
debugn (5, "\n<<< MPIO\n");
hexdump (recvbuff, SECTOR_TRANS);
@@ -304,60 +330,82 @@ mpio_io_sector_read(mpio_t *m, BYTE area, DWORD index, BYTE small,
* parameter:
*
* m: mpio context
- * area: MPIO_{INTERNAL,EXTERNAL}_MEM
+ * mem: MPIO_{INTERNAL,EXTERNAL}_MEM
* index: index number of sector to read
- * small: size of memory chip to read from
- * wsize: dummy
* input: data buffer (has to be SECTOR_SIZE)
*
*/
+
+/* right now we assume we only want to write single sectors from
+ * the _first_ internal memory chip
+ */
+
int
-mpio_io_sector_write(mpio_t *m, BYTE area, DWORD index, BYTE small,
- BYTE wsize, BYTE *input)
+mpio_io_sector_write(mpio_t *m, BYTE mem, DWORD index, BYTE *input)
{
- DWORD block_address, ba;
int nwrite;
+ mpio_smartmedia_t *sm;
+ DWORD block_address, ba;
BYTE cmdpacket[CMD_SIZE], sendbuff[SECTOR_TRANS];
- mpio_io_set_cmdpacket(PUT_SECTOR, area, index, small, wsize, cmdpacket);
+ 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);
+ }
+
+ mpio_io_set_cmdpacket(PUT_SECTOR, mem, index, sm->size, 0, cmdpacket);
debugn (5, "\n>>> MPIO\n");
hexdump (cmdpacket, sizeof(cmdpacket));
nwrite = mpio_io_bulk_write(m->fd, cmdpacket, 0x40);
- if(nwrite != CMD_SIZE) {
- debug ("\nFailed to send command.\n\n");
- close (m->fd);
- return 1;
- }
+ if(nwrite != CMD_SIZE)
+ {
+ debug ("\nFailed to send command.\n\n");
+ close (m->fd);
+ return 1;
+ }
memset(sendbuff, 0, SECTOR_TRANS);
memset(sendbuff + SECTOR_SIZE, 0xff, 0x10);
memcpy(sendbuff, input, SECTOR_SIZE);
- if (index<0x40) {
- block_address=0;
- } else {
- ba= (index /0x20) - 2;
- debugn(2, "foobar: %4x\n", ba);
- block_address= index2blockaddress(ba);
- debugn(2, "foobar: %4x\n", block_address);
- }
-
- /* generate ECC information for spare area ! */
- mpio_ecc_256_gen(sendbuff,
- sendbuff + SECTOR_SIZE + 0x0d);
- mpio_ecc_256_gen(sendbuff + (SECTOR_SIZE / 2),
- sendbuff + SECTOR_SIZE + 0x08);
+ if (index<0x40)
+ {
+ block_address=0;
+ } else {
+ ba= (index /0x20) - 2;
+ debugn(2, "foobar: %4x\n", ba);
+ block_address= index2blockaddress(ba);
+ debugn(2, "foobar: %4x\n", block_address);
+ }
- ba = (block_address / 0x100) & 0xff;
- sendbuff[SECTOR_SIZE + 0x06] = ba;
- sendbuff[SECTOR_SIZE + 0x0b] = ba;
+ if (mem==MPIO_EXTERNAL_MEM)
+ {
+ /* generate ECC information for spare area ! */
+ mpio_ecc_256_gen(sendbuff,
+ sendbuff + SECTOR_SIZE + 0x0d);
+ mpio_ecc_256_gen(sendbuff + (SECTOR_SIZE / 2),
+ sendbuff + SECTOR_SIZE + 0x08);
+
+ ba = (block_address / 0x100) & 0xff;
+ sendbuff[SECTOR_SIZE + 0x06] = ba;
+ sendbuff[SECTOR_SIZE + 0x0b] = ba;
+
+ ba = block_address & 0xff;
+ sendbuff[SECTOR_SIZE + 0x07] = ba;
+ sendbuff[SECTOR_SIZE + 0x0c] = ba;
+ }
- ba = block_address & 0xff;
- sendbuff[SECTOR_SIZE + 0x07] = ba;
- sendbuff[SECTOR_SIZE + 0x0c] = ba;
+ if (mem==MPIO_INTERNAL_MEM)
+ {
+ debug("WARNING, code for internal FAT entry (in ECC area)"
+ " not yet in place!!\n");
+ }
debugn (5, "\n>>> MPIO\n");
hexdump(sendbuff, SECTOR_TRANS);
@@ -365,11 +413,12 @@ mpio_io_sector_write(mpio_t *m, BYTE area, DWORD index, BYTE small,
/* write sector MPIO */
nwrite = mpio_io_bulk_write(m->fd, sendbuff, SECTOR_TRANS);
- if(nwrite != SECTOR_TRANS) {
- debug ("\nFailed to read Sector.\n%x\n", nwrite);
- close (m->fd);
- return 1;
- }
+ if(nwrite != SECTOR_TRANS)
+ {
+ debug ("\nFailed to read Sector.\n%x\n", nwrite);
+ close (m->fd);
+ return 1;
+ }
return 0;
}
@@ -378,76 +427,84 @@ mpio_io_sector_write(mpio_t *m, BYTE area, DWORD index, BYTE small,
* read/write of blocks
*/
int
-mpio_io_block_read(mpio_t *m, BYTE area, DWORD index, BYTE small,
- BYTE wsize, BYTE *output)
+mpio_io_block_read(mpio_t *m, BYTE area, DWORD index, BYTE size, BYTE *output)
{
int i=0;
int nwrite, nread;
DWORD rarea=0;
BYTE cmdpacket[CMD_SIZE], recvbuff[BLOCK_TRANS];
- if (area == MPIO_INTERNAL_MEM) {
- rarea = index / 0x1000000;
- index &= 0xffffff;
- }
- if (area == MPIO_EXTERNAL_MEM) {
- rarea = area;
- }
+ if (area == MPIO_INTERNAL_MEM)
+ {
+ rarea = index / 0x1000000;
+ index &= 0xffffff;
+ }
+ if (area == MPIO_EXTERNAL_MEM)
+ {
+ rarea = area;
+ }
index *= BLOCK_SECTORS;
- mpio_io_set_cmdpacket(GET_BLOCK, rarea, index, small, wsize, cmdpacket);
+ mpio_io_set_cmdpacket(GET_BLOCK, rarea, index, size, 0, cmdpacket);
debugn(5, "\n>>> MPIO\n");
hexdump(cmdpacket, sizeof(cmdpacket));
nwrite = mpio_io_bulk_write(m->fd, cmdpacket, CMD_SIZE);
- if(nwrite != CMD_SIZE) {
- debug ("\nFailed to send command.\n\n");
- close (m->fd);
- return 1;
- }
+ if(nwrite != CMD_SIZE)
+ {
+ debug ("\nFailed to send command.\n\n");
+ close (m->fd);
+ return 1;
+ }
/* Receive packet from MPIO */
nread = mpio_io_bulk_read(m->fd, recvbuff, BLOCK_TRANS);
- if(nread != BLOCK_TRANS) {
- debug ("\nFailed to read Block.\n%x\n",nread);
- close (m->fd);
- return 1;
- }
+ if(nread != BLOCK_TRANS)
+ {
+ debug ("\nFailed to read Block.\n%x\n",nread);
+ close (m->fd);
+ return 1;
+ }
debugn(5, "\n<<< MPIO\n");
hexdump(recvbuff, BLOCK_TRANS);
- for (i = 0; i < BLOCK_SECTORS; i++) {
- /* check ECC Area information */
- if (area==MPIO_EXTERNAL_MEM) {
- mpio_ecc_256_check ((recvbuff + (i * SECTOR_TRANS)),
- ((recvbuff + (i * SECTOR_TRANS) + SECTOR_SIZE + 13)));
- mpio_ecc_256_check ((recvbuff + (i * SECTOR_TRANS) + (SECTOR_SIZE / 2)),
- ((recvbuff + (i * SECTOR_TRANS) + SECTOR_SIZE + 8)));
+ for (i = 0; i < BLOCK_SECTORS; i++)
+ {
+ /* check ECC Area information */
+ if (area==MPIO_EXTERNAL_MEM) {
+ mpio_ecc_256_check ((recvbuff + (i * SECTOR_TRANS)),
+ ((recvbuff +(i * SECTOR_TRANS) + SECTOR_SIZE +13)));
+
+ mpio_ecc_256_check ((recvbuff + (i * SECTOR_TRANS) + (SECTOR_SIZE / 2)),
+ ((recvbuff +(i * SECTOR_TRANS) + SECTOR_SIZE + 8)));
+
+ }
+
+ memcpy(output + (i * SECTOR_SIZE),
+ recvbuff + (i * SECTOR_TRANS),
+ SECTOR_SIZE);
}
-
- memcpy(output + (i * SECTOR_SIZE),
- recvbuff + (i * SECTOR_TRANS),
- SECTOR_SIZE);
- }
return 0;
}
/* Read spare is only usefull for the internal memory,
- * the FAT lies there.
- *
- * For external SmartMedia cards we get and write the
- * informatione during {read,write}_{sector,block}
+ * the FAT lies there. It is updated during the
+ * mpio_io_{sector,block}_{read,write} operations.
+ *
+ * For external SmartMedia cards we have a "seperate" FAT
+ * which is read and updated just like on a regular floppy
+ * disc or hard drive.
*
*/
int
-mpio_io_spare_read(mpio_t *m, BYTE area, DWORD index, BYTE small,
+mpio_io_spare_read(mpio_t *m, BYTE area, DWORD index, BYTE size,
BYTE wsize, BYTE *output, int toread)
{
int i;
@@ -463,71 +520,75 @@ mpio_io_spare_read(mpio_t *m, BYTE area, DWORD index, BYTE small,
chips = m->internal.chips;
- for (chip = 1; chip <= chips; chip++) {
- mpio_io_set_cmdpacket(GET_SPARE_AREA, chip, index, small,
- wsize, cmdpacket);
- debugn(5, "\n>>> MPIO\n");
- hexdump(cmdpacket, sizeof(cmdpacket));
-
- nwrite = mpio_io_bulk_write(m->fd, cmdpacket, CMD_SIZE);
-
- if(nwrite != CMD_SIZE) {
- debug ("\nFailed to send command.\n\n");
- close (m->fd);
- return 1;
- }
-
- /* Receive packet from MPIO */
- for (i = 0; i < (toread / chips / CMD_SIZE); i++) {
+ for (chip = 1; chip <= chips; chip++)
+ {
+ mpio_io_set_cmdpacket(GET_SPARE_AREA, chip, index, size,
+ wsize, cmdpacket);
+ debugn(5, "\n>>> MPIO\n");
+ hexdump(cmdpacket, sizeof(cmdpacket));
- nread = mpio_io_bulk_read (m->fd,
- output + (i * CMD_SIZE) +
- (toread / chips * (chip - 1)),
- CMD_SIZE);
+ nwrite = mpio_io_bulk_write(m->fd, cmdpacket, CMD_SIZE);
- if(nread != CMD_SIZE) {
- debug ("\nFailed to read Block.\n%x\n",nread);
+ if(nwrite != CMD_SIZE) {
+ debug ("\nFailed to send command.\n\n");
close (m->fd);
return 1;
}
- debugn(5, "\n<<< MPIO\n");
- hexdump(output + (i * CMD_SIZE) + (toread / chips * (chip - 1)),
- CMD_SIZE);
+
+ /* Receive packet from MPIO */
+ for (i = 0; i < (toread / chips / CMD_SIZE); i++)
+ {
+ nread = mpio_io_bulk_read (m->fd,
+ output + (i * CMD_SIZE) +
+ (toread / chips * (chip - 1)),
+ CMD_SIZE);
+
+ if(nread != CMD_SIZE)
+ {
+ debug ("\nFailed to read Block.\n%x\n",nread);
+ close (m->fd);
+ return 1;
+ }
+ debugn(5, "\n<<< MPIO\n");
+ hexdump(output + (i * CMD_SIZE) + (toread / chips * (chip - 1)),
+ CMD_SIZE);
+ }
}
- }
-
+
return 0;
}
int
-mpio_io_block_delete(mpio_t *m, BYTE mem, DWORD index, BYTE small)
+mpio_io_block_delete(mpio_t *m, BYTE mem, DWORD index, BYTE size)
{
int nwrite, nread;
BYTE cmdpacket[CMD_SIZE], status[CMD_SIZE];
/* Send command packet to MPIO */
- mpio_io_set_cmdpacket(DEL_BLOCK, mem, index, small, 0, cmdpacket);
+ mpio_io_set_cmdpacket(DEL_BLOCK, mem, index, size, 0, cmdpacket);
debugn (5, ">>> MPIO\n");
hexdump (cmdpacket, sizeof(cmdpacket));
nwrite = mpio_io_bulk_write(m->fd, cmdpacket, 0x40);
- if (nwrite != CMD_SIZE) {
- debug ("Failed to send command.\n\n");
- close (m->fd);
- return 0;
- }
+ if (nwrite != CMD_SIZE)
+ {
+ debug ("Failed to send command.\n\n");
+ close (m->fd);
+ return 0;
+ }
/* Receive packet from MPIO */
nread = mpio_io_bulk_read (m->fd, status, CMD_SIZE);
- if ((nread == -1) || (nread != CMD_SIZE)) {
+ if ((nread == -1) || (nread != CMD_SIZE))
+ {
debug ("Failed to read Sector.\n%x\n",nread);
- close (m->fd);
- return 0;
- }
+ close (m->fd);
+ return 0;
+ }
if (status[0] != 0xc0) debug ("error formatting Block %04x\n", index);
debugn(5, "<<< MPIO\n");
@@ -537,8 +598,7 @@ mpio_io_block_delete(mpio_t *m, BYTE mem, DWORD index, BYTE small)
}
int
-mpio_io_block_write(mpio_t *m, BYTE area, DWORD index, BYTE small,
- BYTE wsize, BYTE *data)
+mpio_io_block_write(mpio_t *m, BYTE area, DWORD index, BYTE size, BYTE *data)
{
int i = 0;
int nwrite;
@@ -546,73 +606,83 @@ mpio_io_block_write(mpio_t *m, BYTE area, DWORD index, BYTE small,
DWORD rarea = 0;
BYTE cmdpacket[CMD_SIZE], sendbuff[BLOCK_TRANS];
- if (area == MPIO_INTERNAL_MEM) {
- rarea = index / 0x1000000;
- index &= 0xffffff;
- }
- if (area == MPIO_EXTERNAL_MEM) {
- rarea = area;
- }
+ if (area == MPIO_INTERNAL_MEM)
+ {
+ rarea = index / 0x1000000;
+ index &= 0xffffff;
+ }
+ if (area == MPIO_EXTERNAL_MEM)
+ {
+ rarea = area;
+ }
index *= BLOCK_SECTORS;
/* build block for transfer to MPIO */
- for (i = 0; i < BLOCK_SECTORS; i++) {
- memcpy(sendbuff + (i * SECTOR_TRANS),
- data + (i * SECTOR_SIZE),
- SECTOR_SIZE);
- memset(sendbuff + (i * SECTOR_TRANS) + SECTOR_SIZE,
- 0xff, CMD_SIZE);
- /* fill in block information */
- if (index < 0x40) {
- block_address = 0;
- } else {
- ba = (index / 0x20) - 2;
-/* debugn(2, "foobar: %4x\n", ba); */
- block_address = index2blockaddress(ba);
-/* debugn(2, "foobar: %4x\n", block_address); */
- }
-
- ba = (block_address / 0x100) & 0xff;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x06] = ba;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0b] = ba;
-
- ba = block_address & 0xff;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x07] = ba;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0c] = ba;
-
- /* generate ECC Area information */
- if (area == MPIO_EXTERNAL_MEM) {
- mpio_ecc_256_gen ((sendbuff + (i * SECTOR_TRANS)),
- ((sendbuff + (i * SECTOR_TRANS) + SECTOR_SIZE + 13)));
- mpio_ecc_256_gen ((sendbuff + (i * SECTOR_TRANS) + (SECTOR_SIZE / 2)),
- ((sendbuff + (i * SECTOR_TRANS) + SECTOR_SIZE + 8)));
- }
+ for (i = 0; i < BLOCK_SECTORS; i++)
+ {
+ memcpy(sendbuff + (i * SECTOR_TRANS),
+ data + (i * SECTOR_SIZE),
+ SECTOR_SIZE);
+ memset(sendbuff + (i * SECTOR_TRANS) + SECTOR_SIZE,
+ 0xff, CMD_SIZE);
+ /* fill in block information */
+ if (index < 0x40)
+ {
+ block_address = 0;
+ } else {
+ ba = (index / 0x20) - 2;
+ /* debugn(2, "foobar: %4x\n", ba); */
+ block_address = index2blockaddress(ba);
+ /* debugn(2, "foobar: %4x\n", block_address); */
+ }
+
+ ba = (block_address / 0x100) & 0xff;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x06] = ba;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0b] = ba;
+
+ ba = block_address & 0xff;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x07] = ba;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0c] = ba;
+
+ /* generate ECC Area information */
+ if (area == MPIO_EXTERNAL_MEM)
+ {
+ mpio_ecc_256_gen ((sendbuff + (i * SECTOR_TRANS)),
+ ((sendbuff + (i * SECTOR_TRANS)
+ + SECTOR_SIZE + 13)));
+ mpio_ecc_256_gen ((sendbuff + (i * SECTOR_TRANS)
+ + (SECTOR_SIZE / 2)),
+ ((sendbuff + (i * SECTOR_TRANS)
+ + SECTOR_SIZE + 8)));
+ }
}
- mpio_io_set_cmdpacket(PUT_BLOCK, rarea, index, small, wsize, cmdpacket);
+ mpio_io_set_cmdpacket(PUT_BLOCK, rarea, index, size, 0x48 , cmdpacket);
debugn(5, "\n>>> MPIO\n");
hexdump(cmdpacket, sizeof(cmdpacket));
nwrite = mpio_io_bulk_write(m->fd, cmdpacket, CMD_SIZE);
- if(nwrite != CMD_SIZE) {
- debug ("\nFailed to send command.\n\n");
- close (m->fd);
- return 1;
- }
+ if(nwrite != CMD_SIZE)
+ {
+ debug ("\nFailed to send command.\n\n");
+ close (m->fd);
+ return 1;
+ }
/* send packet to MPIO */
debugn(5, "\n<<< MPIO\n");
hexdump(sendbuff, BLOCK_TRANS);
nwrite = mpio_io_bulk_write (m->fd, sendbuff, BLOCK_TRANS);
- if(nwrite != BLOCK_TRANS) {
- debug ("\nFailed to read Block.\n%x\n",nwrite);
- close (m->fd);
- return 1;
- }
+ if(nwrite != BLOCK_TRANS)
+ {
+ debug ("\nFailed to read Block.\n%x\n",nwrite);
+ close (m->fd);
+ return 1;
+ }
return 0;
}
diff --git a/libmpio/io.h b/libmpio/io.h
index d682967..bf0960f 100644
--- a/libmpio/io.h
+++ b/libmpio/io.h
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.h,v 1.1 2002/08/28 16:10:51 salmoon Exp $
+ * $Id: io.h,v 1.2 2002/09/03 10:22:24 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -34,7 +34,7 @@
#include "defs.h"
/* real I/O */
-int mpio_io_set_cmdpacket(mpio_cmd_t, mpio_mem_t,
+int mpio_io_set_cmdpacket(mpio_cmd_t, mpio_mem_t,
DWORD, BYTE, BYTE, BYTE *);
int mpio_io_bulk_read(int, BYTE *, int);
@@ -44,12 +44,12 @@ int mpio_io_bulk_write(int, BYTE *, int);
int mpio_io_version_read(mpio_t *, BYTE *);
/* */
-int mpio_io_sector_read(mpio_t *, BYTE, DWORD, BYTE, BYTE, BYTE *);
-int mpio_io_sector_write(mpio_t *, BYTE, DWORD, BYTE, BYTE, BYTE *);
+int mpio_io_sector_read(mpio_t *, BYTE, DWORD, BYTE *);
+int mpio_io_sector_write(mpio_t *, BYTE, DWORD, BYTE *);
/* */
-int mpio_io_block_read(mpio_t *, BYTE, DWORD, BYTE, BYTE, BYTE *);
-int mpio_io_block_write(mpio_t *, BYTE, DWORD, BYTE, BYTE, BYTE *);
+int mpio_io_block_read(mpio_t *, BYTE, DWORD, BYTE, BYTE *);
+int mpio_io_block_write(mpio_t *, BYTE, DWORD, BYTE, BYTE *);
int mpio_io_block_delete(mpio_t *, BYTE, DWORD, BYTE);
/* */
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index ce16963..c9d67a6 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.1 2002/08/28 16:10:50 salmoon Exp $
+ * $Id: mpio.c,v 1.2 2002/09/03 10:22:24 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -48,43 +48,47 @@ void mpio_init_external(mpio_t *);
void
mpio_init_internal(mpio_t *m)
{
- BYTE i_offset = 0x18;
+ mpio_smartmedia_t *sm = &(m->internal);
+ BYTE i_offset = 0x18;
+
/* init main memory parameters */
- m->internal.manufacturer = m->version[i_offset];
- m->internal.id = m->version[i_offset+1];
- m->internal.size = mpio_id2mem(m->internal.id);
- m->internal.max_cluster = m->internal.size/16*1024;
- m->internal.chips = 1;
+ sm->manufacturer = m->version[i_offset];
+ sm->id = m->version[i_offset+1];
+ sm->size = mpio_id2mem(sm->id);
+ sm->max_cluster = sm->size/16*1024;
+ sm->chips = 1;
/* look for a second installed memory chip */
if (mpio_id_valid(m->version[i_offset+2]))
{
- if(mpio_id2mem(m->internal.id) != mpio_id2mem(m->version[i_offset+3]))
+ if(mpio_id2mem(sm->id) != mpio_id2mem(m->version[i_offset+3]))
{
printf("Found a MPIO with two chips with different size!");
printf("I'm utterly confused and aborting now, sorry!");
printf("Please report this to: mpio-devel@lists.sourceforge.net\n");
exit(1);
}
- m->internal.size = 2 * mpio_id2mem(m->internal.id);
- m->internal.chips = 2;
+ sm->size = 2 * mpio_id2mem(sm->id);
+ sm->chips = 2;
}
-
- mpio_id2geo(m->internal.id, &m->internal.geo);
+
+ /* this probably is not needed, but anyways ... */
+ mpio_id2geo(sm->id, &sm->geo);
/* read FAT information from spare area */
- m->internal.fat_size=m->internal.size*2;
- m->internal.fat=malloc(m->internal.fat_size*SECTOR_SIZE);
+ sm->fat_size=sm->size*2; /* the *2 is need here! */
+ sm->fat=malloc(sm->fat_size*SECTOR_SIZE);
mpio_fat_read(m, MPIO_INTERNAL_MEM);
/* Read directory from internal memory */
- m->internal.dir_offset=0;
+ sm->dir_offset=0;
mpio_rootdir_read(m, MPIO_INTERNAL_MEM);
}
void
mpio_init_external(mpio_t *m)
{
+ mpio_smartmedia_t *sm=&(m->external);
BYTE e_offset=0x20;
/* heuristic to find the right offset for the external memory */
@@ -93,36 +97,35 @@ mpio_init_external(mpio_t *m)
if (mpio_id_valid(m->version[e_offset]))
{
- m->external.manufacturer=m->version[e_offset];
- m->external.id=m->version[e_offset+1];
+ sm->manufacturer=m->version[e_offset];
+ sm->id=m->version[e_offset+1];
} else {
- m->external.manufacturer=0;
- m->external.id=0;
+ sm->manufacturer=0;
+ sm->id=0;
}
- if (m->external.id!=0) {
+ /* init memory parameters if external memory is found */
+ if (sm->id!=0)
+ {
+ /* Read things from external memory (if available) */
+ sm->size = mpio_id2mem(sm->id);
+ sm->chips = 1; /* external is always _one_ chip !! */
- m->external.fat=0;
- /* Read things from external memory (if available) */
- m->external.size = mpio_id2mem(m->external.id);
- m->external.chips = 1; /* external is always _one_ chip !! */
- mpio_id2geo(m->external.id, &m->external.geo);
-
- if (m->external.size < 16) {
- printf("Sorry, I don't believe this software works with "
- "SmartMedia Cards less than 16MB\n"
- "Proceed with care and send any findings to: "
- "mpio-devel@lists.sourceforge.net\n");
+ mpio_id2geo(sm->id, &sm->geo);
+
+ if (sm->size < 16)
+ {
+ debug("Sorry, I don't believe this software works with "
+ "SmartMedia Cards less than 16MB\n"
+ "Proceed with care and send any findings to: "
+ "mpio-devel@lists.sourceforge.net\n");
+ }
+
+ mpio_bootblocks_read(m, MPIO_EXTERNAL_MEM);
+ sm->fat = malloc(SECTOR_SIZE*sm->fat_size);
+ mpio_fat_read(m, MPIO_EXTERNAL_MEM);
+ mpio_rootdir_read(m, MPIO_EXTERNAL_MEM);
}
-
- mpio_bootblocks_read(m, MPIO_EXTERNAL_MEM);
- m->external.fat = malloc(SECTOR_SIZE*m->external.fat_size);
- mpio_fat_read(m, MPIO_EXTERNAL_MEM);
- mpio_rootdir_read(m, MPIO_EXTERNAL_MEM);
- }
-
-
-
}
mpio_t *
@@ -388,7 +391,7 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename,
}
mpio_io_block_read(m, mem, realsector + (data_offset / BLOCK_SECTORS),
- sm->size, 0, block);
+ sm->size, block);
if (filesize > BLOCK_SIZE) {
towrite = BLOCK_SIZE;
@@ -423,7 +426,7 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename,
mpio_io_block_read(m, mem,
(realsector + (data_offset / BLOCK_SECTORS)),
- sm->size, 0, block);
+ sm->size, block);
if (filesize > BLOCK_SIZE) {
towrite=BLOCK_SIZE;
} else {
@@ -559,7 +562,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
mpio_io_block_delete(m, mem, ((realsector*BLOCK_SECTORS) + data_offset),
sm->size);
mpio_io_block_write(m, mem, realsector + (data_offset/BLOCK_SECTORS),
- sm->size, 0x48, block);
+ sm->size, block);
filesize -= toread;
@@ -614,8 +617,8 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem,
/* format CIS area */
mpio_io_block_delete(m, mem, 0x20, sm->size);
- mpio_io_sector_write(m, mem, 0x20, sm->size, 0, sm->cis);
- mpio_io_sector_write(m, mem, 0x21, sm->size, 0, sm->cis);
+ mpio_io_sector_write(m, mem, 0x20, sm->cis);
+ mpio_io_sector_write(m, mem, 0x21, sm->cis);
mpio_fat_clear(m, mem);
mpio_rootdir_clear(m, mem);
diff --git a/libmpio/smartmedia.c b/libmpio/smartmedia.c
index 64e89b1..fc8c286 100644
--- a/libmpio/smartmedia.c
+++ b/libmpio/smartmedia.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: smartmedia.c,v 1.1 2002/08/28 16:10:51 salmoon Exp $
+ * $Id: smartmedia.c,v 1.2 2002/09/03 10:22:24 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -104,13 +104,14 @@ mpio_id2manufacturer(BYTE id)
BYTE
mpio_id_valid(BYTE id)
{
- switch(id) {
- case 0xec: /* Samsung */
- case 0x98: /* Toshiba */
- return 1;
- default:
- ;
- }
+ switch(id)
+ {
+ case 0xec: /* Samsung */
+ case 0x98: /* Toshiba */
+ return 1;
+ default:
+ ;
+ }
return 0;
}
@@ -118,7 +119,8 @@ mpio_id_valid(BYTE id)
void
mpio_id2geo(BYTE id, mpio_disk_phy_t *geo)
{
- switch(id) {
+ switch(id)
+ {
case 0xea:
*geo = MPIO_DISK_GEO_002;
break;
@@ -144,10 +146,7 @@ mpio_id2geo(BYTE id, mpio_disk_phy_t *geo)
default:
debug("This should never happen!\n");
exit (1);
- }
-
+ }
+
return;
}
-
-
-