?? mtkdump.cpp
字號:
// **********************************************************************
//
// MTK MT13x9 Memory Dumper
//
// For reading/writing memory from Mediatek MT13x9 chip based
// players.
//
// **********************************************************************
//
// Copyright (C) 2006 MaBreaker
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.
//
// **********************************************************************
#ifndef __BORLANDC__
// #define _DEBUG
#endif
#define THREAD
#include <stdio.h>
#include <windows.h> // Port definitions
#ifdef THREAD
// #define __MT__ // Multi threading
#include <process.h> // _beginthread, _endthread
/*
#ifdef __cplusplus
extern "C" {
#endif
unsigned long _beginthread(void (__closure *)(void *), unsigned, void*);
//unsigned long _beginthread(void (*)(void *), unsigned, void*);
void _endthread(void);
#ifdef __cplusplus
}
#endif
*/
#endif
#include "MTKDump.h"
#include "Mediatek.h"
#include "Print.h"
//#include "ComDef.h"
//#include "ComMain.h"
void Testi(void *)
{
printf("Testi");
Sleep(5000);
}
// **********************************************************************
// Main Options
bool bDumpRead; // /r : Read mode
bool bDumpWrite; // /w : Write mode
int iDumpAddress; // /a : Target address
uchar bDumpTargetMem; // /m : Target memory
// Read options
int iDumpLength; // /l : Output / File length
uchar bDumpHexText; // /t : Output hex ediot look text file
// Port Options
uchar bDumpPort; // /c : Com port
ulong ulDumpBaud; // /b : Baud rate
uchar bDumpDataBit; // /d : Databits
char cDumpParity; // /p : Parity
uchar bDumpStopBit; // /s : Stopbits
// Common
uchar bDumpRetry; // /R : Reply count
uchar bDumpDelay; // /D : Delay value
// **********************************************************************
#define mStopBit(Byte) (double)(1 + Byte * 0.5)
#define mParity(Byte) ctabParity[Byte]
const char ctabParity[6] = "NOEMS";
// **********************************************************************
// PRINT USAGE TEXT
// **********************************************************************
void Usage(char *ptrProg)
{
fprintf(stderr, "Dump / Write MT13x9 Player memory to a file, according to the options.\n\n");
fprintf(stderr, "USAGE : %s /r /m=<mem> /a=<address> [option] Outfile.bin\n", ptrProg);
fprintf(stderr, " %s /w /m=<mem> /a=<address> [option] Patch.bin\n", ptrProg);
fprintf(stderr, "\nOptions : \n");
fprintf(stderr, " /h This help\n");
fprintf(stderr, " /r Read from memory\n");
fprintf(stderr, " /w Write to memory\n");
fprintf(stderr, " /a=LONG Target address\n");
fprintf(stderr, " /m=BYTE Target memory\n");
fprintf(stderr, " 1 = FLASH\n");
fprintf(stderr, " 2 = XDATA\n");
fprintf(stderr, " 3 = IDATA\n");
fprintf(stderr, " 4 = RISC RAM\n");
fprintf(stderr, " 5 = DRAM\n");
fprintf(stderr, " 6 = EEPROM\n");
fprintf(stderr, "\nRead Options : \n");
fprintf(stderr, " /l=LONG Dump length (not for write)\n");
fprintf(stderr, " /t Output hex ediot look text file\n");
fprintf(stderr, "\nPort Options : \n");
fprintf(stderr, " /c=BYTE Com port (default 1)\n");
fprintf(stderr, " /b=LONG Baud rate (default 115200)\n");
fprintf(stderr, " (56700,115200)\n");
fprintf(stderr, " /d=BYTE Databits (default 8)\n");
fprintf(stderr, " (5,6,7,8)\n");
fprintf(stderr, " /p=CHAR Parity (default N)\n");
fprintf(stderr, " N = None\n");
fprintf(stderr, " O = Odd\n");
fprintf(stderr, " E = Even\n");
fprintf(stderr, " M = Mark\n");
fprintf(stderr, " S = Space\n");
fprintf(stderr, " /s=BYTE Stopbits (default 1)\n");
fprintf(stderr, " 1 = One\n");
fprintf(stderr, " 15 = 1.5 bits\n");
fprintf(stderr, " 2 = Two\n");
fprintf(stderr, " /n=BYTE Reply count (default 3)\n");
fprintf(stderr, " /i=BYTE Delay value (default 10)\n");
fprintf(stderr, "\nThis will read 32 bytes from RISC RAM address 0x1234");
fprintf(stderr, "to Outfile.bin. Using COM port 2\n\n");
fprintf(stderr, "EXAMPLE : %s /r /m=2 /a=0x1234 /l=32 /c=2 Outfile.bin\n", ptrProg);
fprintf(stderr, "\nThis will patch 256 bytes of DRAM address 0x337C00");
fprintf(stderr, "with Infile.bin. Using COM port 5\n\n");
fprintf(stderr, "EXAMPLE : %s /w /m=3 /a=0x337C00 /l=0x100 /c=5 Outfile.bin\n", ptrProg);
}
// **********************************************************************
// INIT DEFAULT SETTINGS
// **********************************************************************
void Init()
{
// Main Options
bDumpRead = false;
bDumpWrite = false;
iDumpAddress = -1;
bDumpTargetMem = TARGET_NULL;
// Read options
iDumpLength = -1;
bDumpHexText = false;
// Port Options
bDumpPort = 1;
ulDumpBaud = CBR_115200;
bDumpDataBit = 8;
cDumpParity = NOPARITY; // 'N';
bDumpStopBit = ONESTOPBIT;
bDumpRetry = 3;
bDumpDelay = 10;
}
// **********************************************************************
// PARSE COMMANDLINE
// **********************************************************************
// returns the index of the first argument that is not an option; i.e.
// does not start with a dash or a slash
int HandleOptions(int argc,char *argv[])
{
int i, firstnonoption=-1;
bool bRedef = false;
for (i=1; i< argc;i++)
{
if (argv[i][0] == '/' || argv[i][0] == '-')
{
switch (argv[i][1])
{
/* An argument -? means help is requested */
case '?':
case 'h':
case 'H':
case 'r':
case 'R':
case 'w':
case 'W':
case 't':
case 'T':
if(strlen (argv[i]) > 2) //[2] != '\0')
{
fprintf(stderr,"Bad option %s\n",argv[i]);
exit(EXIT_FAILURE);
}
break;
case 'a':
case 'A':
case 'm':
case 'M':
case 'l':
case 'L':
case 'c':
case 'C':
case 'b':
case 'B':
case 'd':
case 'D':
case 'p':
case 'P':
case 's':
case 'S':
case 'i':
case 'I':
case 'n':
case 'N':
if((argv[i][2] != '=') || (strlen(argv[i]) < 4))
{
fprintf(stderr,"Bad option %s\n",argv[i]);
exit(EXIT_FAILURE);
}
break;
default:
fprintf(stderr,"Unknown option %s\n",argv[i]);
exit(EXIT_FAILURE);
}
switch (argv[i][1])
{
/* An argument -? means help is requested */
case '?':
case 'h':
case 'H':
Usage(argv[0]);
exit(EXIT_FAILURE);
// Read
case 'r':
case 'R':
if(bDumpWrite == true)
{
fprintf(stderr,"Both Read and Write defined. Remove other of these.\n");
exit(EXIT_FAILURE);
}
bDumpRead = true;
break;
// Write
case 'w':
case 'W':
if(bDumpWrite == true)
{
bRedef = true;
break;
}
if(bDumpRead == true)
{
fprintf(stderr,"Both Read and Write defined. Remove other of these.\n");
exit(EXIT_FAILURE);
}
bDumpRead = true;
break;
// Address
case 'a':
case 'A':
if(iDumpAddress != -1)
{
bRedef = true;
break;
}
iDumpAddress = strtol(argv[i]+3, NULL, 0);
break;
// Target memory
case 'm':
case 'M':
if(bDumpTargetMem != 0)
{
bRedef = true;
break;
}
bDumpTargetMem = (uchar) strtol(argv[i]+3, NULL, 0);
switch(bDumpTargetMem)
{
case 1 :
bDumpTargetMem = TARGET_FLASH;
break;
case 2 :
bDumpTargetMem = TARGET_XDATA;
break;
case 3 :
bDumpTargetMem = TARGET_IDATA;
break;
case 4 :
bDumpTargetMem = TARGET_RISC_RAM;
break;
case 5 :
bDumpTargetMem = TARGET_DRAM_LONG;
break;
case 6 :
bDumpTargetMem = TARGET_EEPROM;
break;
default :
fprintf(stderr,"Unknow target mem value %d\n", bDumpTargetMem);
exit(EXIT_FAILURE);
}
break;
case 'l':
case 'L':
if(iDumpLength != -1)
{
bRedef = true;
break;
}
iDumpLength = strtol(argv[i]+3, NULL, 0);
break;
// Hex Text
case 't':
case 'T':
if(bDumpHexText == true)
{
bRedef = true;
break;
}
bDumpHexText = true;
break;
// Com port nro
case 'c':
case 'C':
bDumpPort = (uchar) strtol(argv[i]+3, NULL, 0);
break;
// Com port baud rate
case 'b':
case 'B':
ulDumpBaud = (ulong) strtol(argv[i]+3, NULL, 0);
switch(ulDumpBaud)
{
case CBR_57600:
case CBR_115200:
break;
default:
fprintf(stderr,"Bad baud rate %s\n",argv[i]);
exit(EXIT_FAILURE);
}
break;
// Com port databit count
case 'd':
case 'D':
bDumpDataBit = (uchar) strtol(argv[i]+3, NULL, 0);
if((bDumpDataBit < 5) || (bDumpDataBit > 8))
{
fprintf(stderr,"Bad databit count %s\n",argv[i]);
exit(EXIT_FAILURE);
}
break;
// Com port parity
case 'p':
case 'P':
cDumpParity = argv[i][3];
switch(cDumpParity)
{
case 'N':
cDumpParity = NOPARITY;
break;
case 'M':
cDumpParity = MARKPARITY;
break;
case 'S':
cDumpParity = SPACEPARITY;
break;
case 'E':
cDumpParity = EVENPARITY;
break;
case 'O':
cDumpParity = ODDPARITY;
break;
default:
fprintf(stderr,"Bad parity setting %s\n",argv[i]);
exit(EXIT_FAILURE);
}
break;
// Com port stopbit count
case 's':
case 'S':
bDumpStopBit = (uchar) strtol(argv[i]+3, NULL, 0);
switch(bDumpStopBit)
{
case 1:
bDumpStopBit = ONESTOPBIT;
break;
case 15:
bDumpStopBit = ONE5STOPBITS;
break;
case 2:
bDumpStopBit = TWOSTOPBITS;
break;
default:
fprintf(stderr,"Bad stop bit count %s\n",argv[i]);
exit(EXIT_FAILURE);
}
break;
// Common reply
case 'i':
case 'I':
bDumpRetry = (uchar) strtol(argv[i]+3, NULL, 0);
if(bDumpRetry > 100)
{
fprintf(stderr,"Bad reply value %s\n",argv[i]);
exit(EXIT_FAILURE);
}
break;
// Common delay
case 'n':
case 'N':
bDumpDelay = (uchar) strtol(argv[i]+3, NULL, 0);
break;
default:
fprintf(stderr,"Unknown option %s\n",argv[i]);
break;
}
}
else
{
if(firstnonoption == -1)
firstnonoption = i;
}
if(bRedef == true)
{
fprintf(stderr,"Option %s is defined already.\n", argv[i]);
exit(EXIT_FAILURE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -