initial push

This commit is contained in:
Bernd Mueller
2026-06-17 13:44:30 +02:00
commit adfd70813f
372 changed files with 146450 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
.deps
Makefile.in
Makefile
libbdmabstraction.a
*.o

View File

@@ -0,0 +1,70 @@
#ifndef BDMDriver_Included_M
#define BDMDriver_Included_M
/* @#Copyright (c) 2000, Brett Wuth. */
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: BDMDriver.h
* Purpose: Control which Linux BDM driver is used.
* Author: Brett Wuth
* Created: 2000-03-27
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: +1 403 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* HISTORY:
* $Log: BDMDriver.h,v $
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.1 2003/06/03 15:42:03 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.2 2000/04/20 04:56:22 wuth
* GPL. Abstract flash interface.
*
* Revision 1.1 2000/03/28 20:24:41 wuth
* Break out flash code into separate executable. Make run under Chris Johns BDM driver.
*
* @#[BasedOnTemplate: template.h version 2]
*/
#define BDMDriverFiedler_M (1)
#define BDMDriverJohns_M (2)
#define BDMDriverVersion_M BDMDriverJohns_M
#if BDMDriverVersion_M == BDMDriverFiedler_M
#include <bdmcf.h>
#define _COMPILING_
# include <bdmops.h>
#undef _COMPILING_
#elif BDMDriverVersion_M == BDMDriverJohns_M
#include <BDMlib.h>
#else
# error "BDMDriverVersion_M not set to known value"
#endif
#endif /* BDMDriver_Included_M */
/*** Emacs configuration ***/
/* Local Variables: */
/* mode:C */
/* End: */
/*EOF*/

View File

@@ -0,0 +1,323 @@
/* @#Copyright:
* Copyright (c) 1999, Rolf Fiedler.
* Copyright (c) 1999-2000, Brett Wuth.
*/
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: BDMFlash.c
* Purpose: Flash Driver through BDM
* Author: Rolf Fiedler, Brett Wuth
* Created: 2000-03-27
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: +1 403 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* HISTORY:
* $Log: BDMFlash.c,v $
* Revision 1.2 2005/10/24 01:37:25 cjohns
* Fixed includes for building in Windows with MinGW.
*
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.2 2003/07/04 22:33:01 codewiz
* Applied SST block-erase patch.
*
* Revision 1.1 2003/06/03 15:42:04 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.5 2000/08/03 06:29:18 wuth
* MultiProject Sync; Support Micron-style flash; Report flash model
*
* Revision 1.4 2000/07/25 13:51:09 wuth
* Working sector erase. Better error reports.
*
* Revision 1.3 2000/07/14 18:38:55 wuth
* Flash error status; Fix sector erase support; Command line sector erase
*
* Revision 1.2 2000/04/20 04:56:23 wuth
* GPL. Abstract flash interface.
*
* Revision 1.1 2000/03/28 20:24:41 wuth
* Break out flash code into separate executable. Make run under Chris Johns BDM driver.
*
* Based on revision Wuth1 of bdm-fiedler/debug/bdm_abstraction/bdmops.c.
* @#[BasedOnTemplate: template.c version 2]
*/
#include <BDMFlash.h>
#include <assert.h>
#include <BDMTargetAddress.h>
#include <Debug.h>
#include <Flash.h>
#include <stdio.h>
#include <stdlib.h> /* size_t */
#if defined (__WIN32__) && !defined (__CYGWIN__)
#include <winsock.h>
#else
#include <netinet/in.h> /* ntohl, ntohl */
#endif
typedef struct BDMFlash_s
{
int Device; /* file descriptor of BDM device */
unsigned long Base; /* start of flash in BDM's address space */
} BDMFlash_t;
static
FlashError_t
BDMFlashByteRead( void *UserData, unsigned long Location, unsigned char /*out*/ *Byte )
{
BDMFlash_t *BDMFlash = (BDMFlash_t *)UserData;
int Val;
if ((Val = BDMTargetByteRead( BDMFlash->Device, BDMFlash->Base + Location )) < 0)
return (FlashErrorReadAccess_c);
*Byte = (unsigned char) Val;
return (FlashErrorOkay_c);
}
static
FlashError_t
BDMFlashWordRead( void *UserData, unsigned long Location, unsigned short /*out*/ *Word )
{
BDMFlash_t *BDMFlash = (BDMFlash_t *)UserData;
int Val;
if ((Val = BDMTargetWordRead( BDMFlash->Device, BDMFlash->Base + Location )) < 0)
return (FlashErrorReadAccess_c);
*Word = (unsigned short) Val;
return (FlashErrorOkay_c);
}
#if 0 /*BDMTargetLongRead not yet implemented*/
static
FlashError_t
BDMFlashLongRead( void *UserData, unsigned long Location, unsigned long /*out*/ *Long )
{
BDMFlash_t *BDMFlash = (BDMFlash_t *)UserData;
long Val;
if ((Val = BDMTargetLongRead( BDMFlash->Device, BDMFlash->Base + Location )) < 0)
return (FlashErrorRead_c);
*Long = hlton( (unsigned long) Val );
return (FlashErrorOkay_c);
}
#endif
static
FlashError_t
BDMFlashByteWrite( void *UserData, unsigned long Location, unsigned char Byte )
{
BDMFlash_t *BDMFlash = (BDMFlash_t *)UserData;
if (BDMTargetByteWrite( BDMFlash->Device, BDMFlash->Base + Location, Byte ) != 0)
return (FlashErrorWriteAccess_c);
return (FlashErrorOkay_c);
}
static
FlashError_t
BDMFlashWordWrite( void *UserData, unsigned long Location, unsigned short Word )
{
BDMFlash_t *BDMFlash = (BDMFlash_t *)UserData;
if (BDMTargetWordWrite( BDMFlash->Device, BDMFlash->Base + Location, Word ) != 0)
return (FlashErrorWriteAccess_c);
return (FlashErrorOkay_c);
}
static
FlashError_t
BDMFlashLongWrite( void *UserData, unsigned long Location, unsigned long Long )
{
BDMFlash_t *BDMFlash = (BDMFlash_t *)UserData;
if (BDMTargetLongWrite( BDMFlash->Device, BDMFlash->Base + Location, Long ) != 0)
return (FlashErrorWriteAccess_c);
return (FlashErrorOkay_c);
}
static
FlashError_t
BDMFlashElementRead( void *UserData,
unsigned long Location,
unsigned int BytesWide, /* what type of read */
void /*out*/ *Element )
{
FlashError_t Error;
switch (BytesWide)
{
case 1:
Error = BDMFlashByteRead( UserData, Location, Element );
break;
case 2:
Error = BDMFlashWordRead( UserData, Location, Element );
/* BDM functions give us the number in host-order, but we want
* to pass it up in network order because that's the byte order
* that the data was originally in as seen under 68K
* architecture */
*(unsigned short *)Element = htons( *(unsigned short *)Element );
break;
case 4: /* not yet implemented */
default:
return (FlashErrorWidth_c);
}
return (Error);
}
static
FlashError_t
BDMFlashElementWrite( void *UserData,
unsigned long Location,
unsigned int BytesWide, /* what type of write */
void const *Element )
{
FlashError_t Error;
switch (BytesWide)
{
case 1:
Error = BDMFlashByteWrite( UserData, Location, *(unsigned char *)Element );
break;
case 2:
/* We want the value to be written in the same sequence as we
* receive it. The writer (the ColdFire/BDM core) uses network
* order. Therefore the byte order we're receiving it is also
* network order. The BDM functions take values in host order.
* Therefore we need to convert from network order to host
* order. */
Error = BDMFlashWordWrite( UserData, Location, ntohs( *(unsigned short *)Element ) );
break;
case 4:
Error = BDMFlashLongWrite( UserData, Location, ntohl( *(unsigned long *)Element ) );
break;
default:
return (FlashErrorWidth_c);
}
return (Error);
}
static Flash_t Flash;
static BDMFlash_t BDMFlash;
/* configure for arrangement of flash */
FlashError_t
BDMFlashConfigSet( int fd,
unsigned int Base,
unsigned int Chips,
unsigned int Bytes )
{
FlashError_t Error;
PRINTD( "Base = %u, Chips = %u, Bytes = %u\n", Base, Chips, Bytes );
BDMFlash.Device = fd;
BDMFlash.Base = Base;
Error = FlashInit( &Flash,
&BDMFlash,
BDMFlashElementRead,
BDMFlashElementWrite,
Bytes,
1, /* BDM in Big-Endian */
Chips );
return (Error);
}
/* store into flash */
FlashError_t
BDMFlashWrite( unsigned int addr, unsigned char *mem, size_t count)
{
return (FlashWrite( &Flash,
addr,
mem,
count ));
}
/* erase flash */
FlashError_t
BDMFlashErase( void )
{
return (FlashErase( &Flash ));
}
FlashError_t
BDMFlashProbe( FlashStyle_t /*out*/ *Style )
{
*Style = Flash.Style;
return (FlashErrorOkay_c);
}
/* erase flash, addr is base of a sector of a byte-wide flash */
FlashError_t
BDMFlashEraseSector( unsigned int addr )
{
return (FlashEraseSector( &Flash,
addr /* base of sector of byte-wide flash */ ));
}
/* erase flash, addr is base of a block of a byte-wide flash */
FlashError_t
BDMFlashEraseBlock( unsigned int addr )
{
return (FlashEraseBlock( &Flash,
addr /* base of sector of byte-wide flash */ ));
}
FlashError_t
BDMFlashIDRead( FlashID_t /*out*/ *ID )
{
return (FlashIDRead( &Flash, ID ));
}
FlashError_t
BDMFlashDetect( FlashInfo_t const * /*out*/ *FlashInfo )
{
return (FlashDetect( &Flash, FlashInfo ));
}
/*EOF*/

View File

@@ -0,0 +1,117 @@
#ifndef BDMFlash_Included_M
#define BDMFlash_Included_M
/* @#Copyright (c) 2000, Brett Wuth. */
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: BDMFlash.h
* Purpose: Flash Driver through BDM
* Author: Brett Wuth
* Created: 2000-03-27
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: +1 403 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* HISTORY:
* $Log: BDMFlash.h,v $
* Revision 1.2 2008/06/16 12:57:49 cjohns
* 2008-06-16 Chris Johns <cjohns@users.sourceforge.net>
*
* * packages/.cvsignore, packages/gpl.txt, packages/m68k-bdm.nsi:
* New.
*
* * flashlib/elf-utils.h: Add elf_handle_init decl.
*
* * utils/Makefile.am: Add warnings flags.
*
* * bdmabstraction/BDMFlash.h, utils/bdmctrl.c, utils/bdmflash.c:
* Fix warnings.
*
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.2 2003/07/04 22:33:01 codewiz
* Applied SST block-erase patch.
*
* Revision 1.1 2003/06/03 15:42:04 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.5 2000/08/03 06:29:18 wuth
* MultiProject Sync; Support Micron-style flash; Report flash model
*
* Revision 1.4 2000/07/25 13:51:09 wuth
* Working sector erase. Better error reports.
*
* Revision 1.3 2000/07/14 18:38:55 wuth
* Flash error status; Fix sector erase support; Command line sector erase
*
* Revision 1.2 2000/04/20 04:56:23 wuth
* GPL. Abstract flash interface.
*
* Revision 1.1 2000/03/28 20:24:41 wuth
* Break out flash code into separate executable. Make run under Chris Johns BDM driver.
*
* @#[BasedOnTemplate: template.h version 2]
*/
#include <Flash.h>
#include <stdlib.h> /* size_t */
#include <BDMTargetAddress.h>
/* configure for arrangement of flash */
FlashError_t
BDMFlashConfigSet( int fd,
unsigned int Base,
unsigned int Chips,
unsigned int Bytes );
/* store into flash */
FlashError_t
BDMFlashWrite( unsigned int addr, unsigned char *mem, size_t count);
/* erase flash */
FlashError_t
BDMFlashErase( void );
FlashError_t
BDMFlashProbe( FlashStyle_t /*out*/ *Style );
/* erase flash, addr is base of a sector of a byte-wide flash */
FlashError_t
BDMFlashEraseSector( unsigned int addr );
/* erase flash, addr is base of a block of a byte-wide flash */
FlashError_t
BDMFlashEraseBlock( unsigned int addr );
FlashError_t
BDMFlashIDRead( FlashID_t /*out*/ *ID );
FlashError_t
BDMFlashDetect( FlashInfo_t const * /*out*/ *FlashInfo );
#endif /* BDMFlash_Included_M */
/*** Emacs configuration ***/
/* Local Variables: */
/* mode:C */
/* End: */
/*EOF*/

View File

@@ -0,0 +1,411 @@
/* @#Copyright:
* Copyright (c) 1997, Rolf Fiedler.
* Copyright (c) 1999-2000, Brett Wuth.
*/
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: BDMTargetAddress.c
* Purpose: Abstract manipulation of target address space through BDM.
* Author: Rolf Fiedler, Brett Wuth
* Created: 2000-03-27
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: +1 403 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* HISTORY:
* $Log: BDMTargetAddress.c,v $
* Revision 1.3 2008/06/16 00:01:21 cjohns
* 2008-06-08 Chris Johns <cjohns@users.sourceforge.net>
*
* * libelf/COPYING.LIB, libelf/ChangeLog, libelf/INSTALL,
* libelf/MANIFEST, libelf/Makefile.in, libelf/README,
* libelf/VERSION, libelf/acconfig.h, libelf/aclocal.m4,
* libelf/config.guess, libelf/config.h.in, libelf/config.sub,
* libelf/configure, libelf/configure.in, libelf/install-sh,
* libelf/libelf.pc.in, libelf/mkinstalldirs, libelf/stamp-h.in,
* libelf/lib/32.fsize.c, libelf/lib/32.getehdr.c,
* libelf/lib/32.getphdr.c, libelf/lib/32.getshdr.c,
* libelf/lib/32.newehdr.c, libelf/lib/32.newphdr.c,
* libelf/lib/32.xlatetof.c, libelf/lib/64.xlatetof.c,
* libelf/lib/Makefile.in, libelf/lib/Makefile.w32,
* libelf/lib/assert.c, libelf/lib/begin.c, libelf/lib/build.bat,
* libelf/lib/byteswap.h, libelf/lib/checksum.c, libelf/lib/cntl.c,
* libelf/lib/config.h.w32, libelf/lib/cook.c, libelf/lib/data.c,
* libelf/lib/elf_repl.h, libelf/lib/end.c, libelf/lib/errmsg.c,
* libelf/lib/errno.c, libelf/lib/errors.h, libelf/lib/ext_types.h,
* libelf/lib/fill.c, libelf/lib/flag.c, libelf/lib/gelf.h,
* libelf/lib/gelfehdr.c, libelf/lib/gelfphdr.c,
* libelf/lib/gelfshdr.c, libelf/lib/gelftrans.c,
* libelf/lib/getarhdr.c, libelf/lib/getarsym.c,
* libelf/lib/getbase.c, libelf/lib/getdata.c, libelf/lib/getident.c,
* libelf/lib/getscn.c, libelf/lib/hash.c, libelf/lib/input.c,
* libelf/lib/kind.c, libelf/lib/libelf.def, libelf/lib/libelf.h,
* libelf/lib/memset.c, libelf/lib/ndxscn.c, libelf/lib/newdata.c,
* libelf/lib/newscn.c, libelf/lib/next.c, libelf/lib/nextscn.c,
* libelf/lib/nlist.c, libelf/lib/nlist.h, libelf/lib/opt.delscn.c,
* libelf/lib/private.h, libelf/lib/rand.c, libelf/lib/rawdata.c,
* libelf/lib/rawfile.c, libelf/lib/strptr.c, libelf/lib/swap64.c,
* libelf/lib/sys_elf.h.in, libelf/lib/sys_elf.h.w32,
* libelf/lib/update.c, libelf/lib/verdef.h,
* libelf/lib/verdef_32_tof.c, libelf/lib/verdef_32_tom.c,
* libelf/lib/verdef_64_tof.c, libelf/lib/verdef_64_tom.c,
* libelf/lib/verneed.h, libelf/lib/version.c, libelf/lib/x.elfext.c,
* libelf/lib/x.movscn.c, libelf/lib/x.remscn.c,
* libelf/po/Makefile.in, libelf/po/de.gmo, libelf/po/de.msg,
* libelf/po/de.po, libelf/po/gmo2msg.c, libelf/po/libelf.pot,
* libelf/po/stamp-po: Merge libelf into the BDM package.
*
* * configure.ac, utils/Makefile.am, utils/bdmctrl.c,
* flashlib/Makefile.am, flashlib/bdmfilt.c, flashlib/bdmfilt.h,
* flashlib/bdmflash.c, flashlib/bdmflash.h, flashlib/flash29.c,
* flashlib/flash_filter.c, flashlib/flash_filter.h: Remove all BFD
* references and change to ELF file support.
*
* * flashlib/elf-utils.c, flashlib/elf-utils.h: New.
*
* * driver/bdm.h, driver/bdm-tblcf.c: Add the TBLCF interface
* number.
*
* * bdmabstraction/BDMTargetAddress.c: Add a long write call.
*
* * gdbserver/Makefile.am: Fix the XML to C regen rule.
*
* 2008-06-08 Matthew Riek <matthew.riek@ibiscomputer.com.au>
*
* * flashlib/flashcfm.c, flashlib/flashcfm.h,
* flashlib/compile_flashcfm, utils/mcf52235.test.
*
* Revision 1.2 2005/10/24 01:37:25 cjohns
* Fixed includes for building in Windows with MinGW.
*
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.1 2003/06/03 15:42:04 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.4 2000/09/19 00:28:29 wuth
* cleanly use Fiedler's bdm driver; bdm_mon detects flash errors
*
* Revision 1.3 2000/07/25 13:51:09 wuth
* Working sector erase. Better error reports.
*
* Revision 1.2 2000/04/20 04:56:23 wuth
* GPL. Abstract flash interface.
*
* Revision 1.1 2000/03/28 20:24:41 wuth
* Break out flash code into separate executable. Make run under Chris Johns BDM driver.
*
* Based on revision Wuth1 of bdm-fiedler/debug/bdm_abstraction/bdmops.c.
* @#[BasedOnTemplate: template.c version 2]
*/
#include <BDMTargetAddress.h>
#include <assert.h>
#include <BDMDriver.h>
#include <Debug.h>
#include <stdio.h>
#define PRINTDTRACE() PRINTD( __FILE__ "(%d)\n", __LINE__ )
/* Write byte into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetByteWrite( int fd, unsigned int addr, unsigned char byte )
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long word[5];
unsigned long poll;
int ret;
word[0]=BDM_WRITE_CMD | BDM_SIZE_BYTE;
word[1]=(addr>>16);
word[2]=addr & 0xffff;
word[3]=byte;
word[4]=BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(word[4]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(word[4]==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
poll=word[4];
while(poll==BDM_NOTREADY) {
poll = BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(poll==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
}
return 0;
#else
int Ret = bdmWriteByte( addr, byte );
if (Ret)
PRINTDTRACE();
return (Ret);
#endif
}
/* Write word into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetWordWrite( int fd, unsigned int addr, unsigned short word )
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long words[5];
unsigned long poll;
int ret;
words[0]=BDM_WRITE_CMD | BDM_SIZE_WORD;
words[1]=(addr>>16);
words[2]=addr & 0xffff;
words[3]=word;
words[4]=BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(words), (unsigned long)&words);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(words[4]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(words[4]==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
poll=words[4];
while(poll==BDM_NOTREADY) {
poll = BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(poll==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
}
return 0;
#else
int Ret = bdmWriteWord( addr, word );
if (Ret)
PRINTDTRACE();
return (Ret);
#endif
}
/* Write long into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetLongWrite( int fd, unsigned int addr, unsigned long Long )
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
assert( 0 ); /* not implemented */
#else
int Ret = bdmWriteLongWord( addr, Long );
if (Ret)
PRINTDTRACE();
return (Ret);
#endif
return (-1);
}
/* Read byte into target address space through BDM */
int /* <0 if error, else byte */
BDMTargetByteRead( int fd, unsigned int addr )
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long word[4];
unsigned long poll;
int ret;
word[0]=BDM_READ_CMD | BDM_SIZE_BYTE;
word[1]=(addr>>16) & 0xffff;
word[2]=addr & 0xffff;
word[3]=BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(word[3]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(word[3]==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
poll=word[3];
while(poll==BDM_NOTREADY) {
poll = BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(poll==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
}
return poll & 0xff;
#else
unsigned char Byte;
if (bdmReadByte( addr, &Byte ) != 0)
{
PRINTDTRACE();
return (-1);
}
return Byte;
#endif
}
/* Read word into target address space through BDM */
int /* <0 if error, else word */
BDMTargetWordRead( int fd, unsigned int addr )
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long words[4];
unsigned long poll;
int ret;
words[0]=BDM_READ_CMD | BDM_SIZE_WORD;
words[1]=(addr>>16) & 0xffff;
words[2]=addr & 0xffff;
words[3]=BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(words), (unsigned long)&words);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(words[3]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(words[3]==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
poll=words[3];
while(poll==BDM_NOTREADY) {
poll = BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(ret<0)
{
PRINTDTRACE();
return ret;
}
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
PRINTDTRACE();
return BDM_FAULT_BERR;
}
if(poll==BDM_ILLEGAL)
{
PRINTDTRACE();
return BDM_FAULT_NVC;
}
}
return poll & 0xffff;
#else
unsigned short Word;
if (bdmReadWord( addr, &Word ) != 0)
{
PRINTDTRACE();
return (-1);
}
return (Word);
#endif
}
/*EOF*/

View File

@@ -0,0 +1,75 @@
#ifndef BDMTargetAddress_Included_M
#define BDMTargetAddress_Included_M
/* @#Copyright (c) 2000, Brett Wuth. */
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: BDMTargetAddress.h
* Purpose: Abstract manipulation of target address space through BDM.
* Author: Brett Wuth
* Created: 2000-03-27
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: +1 403 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* HISTORY:
* $Log: BDMTargetAddress.h,v $
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.1 2003/06/03 15:42:04 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.2 2000/04/20 04:56:23 wuth
* GPL. Abstract flash interface.
*
* Revision 1.1 2000/03/28 20:24:41 wuth
* Break out flash code into separate executable. Make run under Chris Johns BDM driver.
*
* @#[BasedOnTemplate: template.h version 2]
*/
/* Write byte into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetByteWrite( int fd, unsigned int addr, unsigned char byte );
/* Write word into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetWordWrite( int fd, unsigned int addr, unsigned short word );
/* Write long into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetLongWrite( int fd, unsigned int addr, unsigned long Long );
/* Read byte into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetByteRead( int fd, unsigned int addr );
/* Read word into target address space through BDM */
int /* 0 if success, or error code */
BDMTargetWordRead( int fd, unsigned int addr );
#endif /* BDMTargetAddress_Included_M */
/*** Emacs configuration ***/
/* Local Variables: */
/* mode:C */
/* End: */
/*EOF*/

View File

@@ -0,0 +1,64 @@
#ifndef Debug_Included_M
#define Debug_Included_M
/* @#Copyright (c) 2000, Brett Wuth. */
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: Debug.h
* Purpose:
* Author: Brett Wuth
* Created:
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: +1 403 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* HISTORY:
* $Log: Debug.h,v $
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.1 2003/06/03 15:42:04 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.2 2000/04/20 04:56:23 wuth
* GPL. Abstract flash interface.
*
* Revision 1.1 2000/03/28 20:24:41 wuth
* Break out flash code into separate executable. Make run under Chris Johns BDM driver.
*
* @#[BasedOnTemplate: template.h version 2]
*/
#include <stdio.h>
/* #define DEBUG */
#ifdef DEBUG
#define PRINTD(args...) printf(##args)
#else
#define PRINTD(args...)
#endif
#endif /* Debug_Included_M */
/*** Emacs configuration ***/
/* Local Variables: */
/* mode:C */
/* End: */
/*EOF*/

1586
m68k/bdmabstraction/Flash.c Normal file

File diff suppressed because it is too large Load Diff

258
m68k/bdmabstraction/Flash.h Normal file
View File

@@ -0,0 +1,258 @@
#ifndef Flash_Included_M
#define Flash_Included_M
/* @#Copyright:
* Copyright (c) 1999, Rolf Fiedler.
* Copyright (c) 1999-2000, Brett Wuth.
*/
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: Flash.h
* Purpose: Algorithm for manipulating flash independent of access
* method.
* Author: Brett Wuth
* Created: 2000-04-15
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: (403) 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* #@[MultiProject:
* MultiProject@castrov.cuug.ab.ca Flash Flash.h
* MultiProject@castrov.cuug.ab.ca CVSROOT=:ext:wuth@hulk.adomo.com:/home/cvs linux-development/bdm-fiedler debug/bdm_abstraction/Flash.h
* MultiProject@castrov.cuug.ab.ca CVSROOT=:ext:wuth@hulk.adomo.com:/home/cvs linux-development/ThinClientFlashWrite Flash.h
*
* This file is shared among multiple projects. The normal way to so
* is to create a separate project and have this project depend on it,
* perhaps linking to a library. But for whatever reason this project
* requires the file to be included with it.
*
* To keep your copy of this file in sync with the other copies add
* your e-mail address, the project name and file path to the list
* above. E-mail a copy of the file to the first address in the list
* now and whenever there are changes.]
*
* HISTORY:
* $Log: Flash.h,v $
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.2 2003/07/04 22:33:01 codewiz
* Applied SST block-erase patch.
*
* Revision 1.1 2003/06/03 15:42:04 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.4 2000/08/03 06:29:18 wuth
* MultiProject Sync; Support Micron-style flash; Report flash model
*
* Revision 1.3 2000/07/25 13:51:09 wuth
* Working sector erase. Better error reports.
*
* Revision 1.2 2000/07/14 18:38:55 wuth
* Flash error status; Fix sector erase support; Command line sector erase
*
* Revision 1.1 2000/04/20 04:56:23 wuth
* GPL. Abstract flash interface.
*
* @#[BasedOnTemplate: template.h version 2]
*/
#include <stdlib.h> /* size_t */
typedef enum FlashError_en {
FlashErrorOkay_c, /* no error */
FlashErrorReadAccess_c, /* can't read flash */
FlashErrorWriteAccess_c, /* can't write to flash */
FlashErrorTimeOut_c, /* flash's internal program timed out */
FlashErrorEraseFail_c, /* flash's internal erase program failed */
FlashErrorWriteFail_c, /* flash's internal write program failed */
FlashErrorProtected_c, /* flash is protected from modification */
/* flash produced contents that are unexpected */
FlashErrorUnexpected_c,
/* the specified width of the flash is invalid or not supported */
FlashErrorWidth_c,
/* the style of flash is not supported */
FlashErrorStyle_c,
FlashErrorCount_c /* number of Flash Errors */
} FlashError_t;
extern char const *FlashErrorDescriptionEnglish[FlashErrorCount_c];
typedef enum FlashStyle_en {
FlashStyleUndefined_c,
FlashStyleAMD_c,
FlashStyleMicron_c,
FlashStyleCount_c /* number of Flash Styles */
} FlashStyle_t;
extern char const *FlashStyleName[FlashStyleCount_c];
typedef unsigned short FlashID_t;
typedef enum FlashManufacturer_en {
FlashManufacturerAMD_c = 0x01,
FlashManufacturerFujitsu_c = 0x04,
FlashManufacturerSGSThomson_c = 0x20,
FlashManufacturerAtmel_c = 0x1F,
FlashManufacturerMicron_c = 0x89,
FlashManufacturerTexasInstruments_c = 0x97,
FlashManufacturerHyundai_c = 0xAD,
FlashManufacturerSST_c = 0xBF,
} FlashManufacturer_t;
char const *
FlashManufacturerName( FlashManufacturer_t Manufacturer );
typedef
FlashError_t
(*FlashElementReadFunc_t)( void *UserData,
unsigned long Location,
unsigned int BytesWide, /* what type of read */
void /*out*/ *Element );
typedef
FlashError_t
(*FlashElementWriteFunc_t)( void *UserData,
unsigned long Location,
unsigned int BytesWide, /* what type of write */
void const *Element );
/* Parameters passed to flash routines.
* This is object-based coding to reduce the proliferation
* of arguments passed to each function.
*/
typedef struct Flash_s {
/* Pointer to data which is used by generic Read and Write
* functions. The actual data is of a type specific to the
* particular functions defined. */
void *UserData;
/* Generic function read a single element out of the array of
* interlaced flash chips. The size of an element is defined by
* ChipWidthBytes. */
FlashElementReadFunc_t Read;
/* Generic function read a single element out of the array of
* interlaced flash chips. The size of an element is defined by
* ChipWidthBytes. */
FlashElementWriteFunc_t Write;
/* The number of bytes written or read in a single access */
unsigned int ChipWidthBytes;
/* Whether the hardware accessing the flash is big-endian or
* little-endian. This is not necessarily the endianness of the CPU
* on which this code is executing, because the generic Read and
* Write functions may fetch the data through some other machine.
* Such happens when an Intel-based computer manipulates the flash
* through a BDM cable connected to a Motorola CPU. The flash
* provides status information on the least significant bits. */
int/*Bool*/ BigEndian;
/* The number of flash chips of the same type which are interleaved.
* For instance, if ChipWidthBytes == 2, one chip may provide bytes
* 0, 1, 4, 5, 8, 9, etc. And another chip provides bytes 2, 3, 6,
* 7, 10, 11, etc. */
unsigned int NumParallelChips;
/* The general type of the flash. Different styles have radically
* different algorithms for burning and erasing. */
FlashStyle_t Style;
} Flash_t;
/* Initialiaze the Flash structure */
FlashError_t
FlashInit( Flash_t /*out*/ *Flash,
void *UserData,
FlashElementReadFunc_t Read,
FlashElementWriteFunc_t Write,
unsigned int ChipWidthBytes,
int/*Bool*/ BigEndian,
unsigned int NumParallelChips );
/* store into flash */
FlashError_t
FlashWrite( Flash_t const *Flash,
unsigned long Location,
void const *Data,
size_t Size /*actual rounded up by ChipWidthBytes*/ );
/* erase the whole flash */
FlashError_t
FlashErase( Flash_t const *Flash );
/* erase one sector of the flash */
FlashError_t
FlashEraseSector( Flash_t const *Flash,
unsigned long OffsetInFlash /* sector identified by offset */ );
/* erase one block of the flash */
FlashError_t
FlashEraseBlock( Flash_t const *Flash,
unsigned long OffsetInFlash /* sector identified by offset */ );
typedef struct FlashInfo_s {
FlashID_t ID;
unsigned long Size;
unsigned long loend; /* start of range of sectors all the same size */
unsigned long hiend; /* end of range of sectors all the same size */
unsigned long sec_size; /* size of sectors which are all the same size */
char const *Model;
} FlashInfo_t;
/*sets Flash->Style */
FlashError_t
FlashProbe( Flash_t *Flash );
/* leaves flash in Array Read mode */
FlashError_t
FlashIDRead( Flash_t const *Flash,
FlashID_t /*out*/ *ID );
FlashError_t
FlashDetect( Flash_t const *Flash,
FlashInfo_t const * /*out*/ *FlashInfo );
#endif /* Flash_Included_M */
/*** Emacs configuration ***/
/* Local Variables: */
/* mode:C */
/* End: */
/*EOF*/

View File

@@ -0,0 +1,29 @@
##
## $Id: Makefile.am,v 1.3 2004/01/08 20:37:25 codewiz Exp $
##
## This file is part of a free BDM package
##
## 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.
##
AM_CPPFLAGS = -I$(top_srcdir)/driver -I$(top_srcdir)/lib
noinst_LIBRARIES = libbdmabstraction.a
libbdmabstraction_a_SOURCES = \
BDMTargetAddress.c \
BDMFlash.c \
bdmops.c \
Flash.c
noinst_HEADERS = \
bdmcf.h \
BDMDriver.h \
BDMFlash.h \
bdmops.h \
BDMTargetAddress.h \
Debug.h \
Flash.h

View File

@@ -0,0 +1,435 @@
# Makefile.in generated by automake 1.10 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
subdir = bdmabstraction
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
ARFLAGS = cru
libbdmabstraction_a_AR = $(AR) $(ARFLAGS)
libbdmabstraction_a_LIBADD =
am_libbdmabstraction_a_OBJECTS = BDMTargetAddress.$(OBJEXT) \
BDMFlash.$(OBJEXT) bdmops.$(OBJEXT) Flash.$(OBJEXT)
libbdmabstraction_a_OBJECTS = $(am_libbdmabstraction_a_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libbdmabstraction_a_SOURCES)
DIST_SOURCES = $(libbdmabstraction_a_SOURCES)
HEADERS = $(noinst_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BDM_SUBDIRS = @BDM_SUBDIRS@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FLASH_PLUGIN_GCC = @FLASH_PLUGIN_GCC@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LD = @LD@
LDFLAGS = @LDFLAGS@
LEX = @LEX@
LEXLIB = @LEXLIB@
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBUSB_INCLUDE_DIR = @LIBUSB_INCLUDE_DIR@
LIBUSB_LIB_DIR = @LIBUSB_LIB_DIR@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
flash_plugin_cc = @flash_plugin_cc@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
subdirs = @subdirs@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AM_CPPFLAGS = -I$(top_srcdir)/driver -I$(top_srcdir)/lib
noinst_LIBRARIES = libbdmabstraction.a
libbdmabstraction_a_SOURCES = \
BDMTargetAddress.c \
BDMFlash.c \
bdmops.c \
Flash.c
noinst_HEADERS = \
bdmcf.h \
BDMDriver.h \
BDMFlash.h \
bdmops.h \
BDMTargetAddress.h \
Debug.h \
Flash.h
all: all-am
.SUFFIXES:
.SUFFIXES: .c .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign bdmabstraction/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign bdmabstraction/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
libbdmabstraction.a: $(libbdmabstraction_a_OBJECTS) $(libbdmabstraction_a_DEPENDENCIES)
-rm -f libbdmabstraction.a
$(libbdmabstraction_a_AR) libbdmabstraction.a $(libbdmabstraction_a_OBJECTS) $(libbdmabstraction_a_LIBADD)
$(RANLIB) libbdmabstraction.a
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BDMFlash.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BDMTargetAddress.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Flash.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bdmops.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LIBRARIES) $(HEADERS)
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-exec-am:
install-html: install-html-am
install-info: install-info-am
install-man:
install-pdf: install-pdf-am
install-ps: install-ps-am
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-noinstLIBRARIES ctags distclean distclean-compile \
distclean-generic distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-man install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
uninstall-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

274
m68k/bdmabstraction/bdmcf.h Normal file
View File

@@ -0,0 +1,274 @@
#ifndef LINUX_BDM_H
#define LINUX_BDM_H
#include <linux/ioctl.h>
/*
* $Id: bdmcf.h,v 1.1 2003/12/29 22:18:49 codewiz Exp $
*
* Linux Device Driver for P&E Microcomputer Systems Coldfire Cable
* (c) 1997 Rolf Fiedler
*
* this header file is used to interface to a kernel driver and to
* a user-mode lpt driver (using #ifdef USER_MODE)
* therefore it contains prototypes of usermode functions
*
* based on code from and using (roughly) the same API as the
*
* Linux Device Driver for Public Domain BDM Interface
* based on the PD driver package by Scott Howard, Feb 93
* ported to Linux by M.Schraut
* tested for kernel version 1.2.4
* (C) 1995 Technische Universitaet Muenchen, Lehrstuhl fuer Prozessrechner
*
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* the interface of the kernel mode driver as of June 10th, 1997
*
* there are a number of ioctl's for all non-speed-critial bdm operations
* these operations allow to reset, restart, stop, step and run the chip,
* to exchange data with the bdm interface, and to set the clocking speed
* and debug-level.
*
* the download of code and the reading back of memory are considered
* speed critical, due to the fact that download times should be minimized
* therefore these two operations are supported by the BDM fill and dump
* commands. these commands are issued automatically by read and write
* system calls on the bdm driver
*/
#define BDM_MAJOR_NUMBER 30
/* error codes */
#define BDM_FAULT_UNKNOWN -610 /*Error-definitions*/
#define BDM_FAULT_POWER -611 /* target has no power */
#define BDM_FAULT_CABLE -612 /* target is not connected */
#define BDM_FAULT_RESPONSE -613 /* NOT Ready */
#define BDM_FAULT_RESET -614 /* target is held in reset */
#define BDM_FAULT_PORT -615 /* can not gain permission to access port */
#define BDM_FAULT_BERR -616 /* access led to a bus error */
#define BDM_FAULT_NVC -617 /* no valid command */
/* Debug Levels */
#define BDM_DEBUG_NONE 0
#define BDM_DEBUG_SOME 1
#define BDM_DEBUG_ALL 2
/* supported ioctls */
#define BDM_IOCTL_TYPE 0xaa
enum BDM_IOCTLS {
BDM_INIT, /* no argument */
BDM_DEINIT, /* no argument */
BDM_RESET_CHIP, /* no argument */
BDM_RESTART_CHIP, /* no argument */
BDM_STOP_CHIP, /* no argument */
BDM_STEP_CHIP, /* no argument */
BDM_RUN_CHIP, /* no argument */
BDM_GET_STATUS, /* no argument */
BDM_XCHG_DATA, /* argument - int[], rw variable size */
BDM_DEBUG_LEVEL /* arg = level */
};
#define BDM_INIT_IOC _IO(BDM_IOCTL_TYPE,BDM_INIT)
#define BDM_DEINIT_IOC _IO(BDM_IOCTL_TYPE,BDM_DEINIT)
#define BDM_RESET_CHIP_IOC _IO(BDM_IOCTL_TYPE,BDM_RESET_CHIP)
#define BDM_RESTART_CHIP_IOC _IO(BDM_IOCTL_TYPE,BDM_RESTART_CHIP)
#define BDM_STOP_CHIP_IOC _IO(BDM_IOCTL_TYPE,BDM_STOP_CHIP)
#define BDM_STEP_CHIP_IOC _IO(BDM_IOCTL_TYPE,BDM_STEP_CHIP)
#define BDM_RUN_CHIP_IOC _IO(BDM_IOCTL_TYPE,BDM_RUN_CHIP)
#define BDM_GET_STATUS_IOC _IO(BDM_IOCTL_TYPE,BDM_GET_STATUS)
#define BDM_XCHG_DATA_IOC(size) _IOWR(BDM_IOCTL_TYPE,BDM_XCHG_DATA,size)
#define BDM_DEBUG_LEVEL_IOC _IO(BDM_IOCTL_TYPE,BDM_DEBUG_LEVEL)
/* return codes of get status (or'ed) */
#define BDM_NORETURN 0 /* no error, no ret value */
/* functional bits of ioctl BDM_GET_STATUS */
#define BDM_TARGETRESET (1<<0) /* Target reset */
#define BDM_TARGETHALT (1<<1) /* Target halt */
#define BDM_TARGETSTOPPED (1<<2) /* Target (was already) stopped */
#define BDM_TARGETPOWER (1<<3) /* Power failed */
#define BDM_TARGETNC (1<<4) /* Target not Connected */
#define BDM_FROZEN (1<<5) /* Target (was running before)stopped*/
/* it's determined by hardware from now on */
/* command codes for bdm interface */
#define BDM_RREG_CMD 0x2180
#define BDM_WREG_CMD 0x2080
#define BDM_READ_CMD 0x1900
#define BDM_WRITE_CMD 0x1800
#define BDM_DUMP_CMD 0x1d00
#define BDM_FILL_CMD 0x1c00
#define BDM_GO_CMD 0x0c00
#define BDM_NOP_CMD 0x0000
/* coldfire doesn't support BDM_RSREG_CMD/BDM_WSREG_CMD */
/* coldfire doesn't support BDM_CALL_CMD/BDM_RTS_CMD */
/* added for coldfire */
#define BDM_RCREG_CMD 0x2980
#define BDM_WCREG_CMD 0x2880
#define BDM_RDMREG_CMD 0x2d80
#define BDM_WDMREG_CMD 0x2c80
/* RCREG/WCREG */
#define BDM_REG_CACR 0x002
#define BDM_REG_ACR0 0x004
#define BDM_REG_ACR1 0x005
#define BDM_REG_VBR 0x801
#define BDM_REG_SR 0x80e
#define BDM_REG_RPC 0x80f
#define BDM_REG_RAMBAR 0xc04
#define BDM_REG_MBAR 0xc0f
/* RDMREG/WDMREG */
#define BDM_REG_CSR 0x0 /* Configuration/Status */
#define BDM_REG_RSRVD1 0x1
#define BDM_REG_RSRVD2 0x2
#define BDM_REG_RSRVD3 0x3
#define BDM_REG_RSRVD4 0x4
#define BDM_REG_RSRVD5 0x5
#define BDM_REG_AATR 0x6 /* Address ATtribute breakpoint Register */
#define BDM_REG_TDR 0x7 /* Trigger Definition Register */
#define BDM_REG_PBR 0x8 /* Pc Breakpoint Register */
#define BDM_REG_PBMR 0x9 /* Pc Breakpoint Mask Register */
#define BDM_REG_RSRVD6 0xa
#define BDM_REG_RSRVD7 0xb
#define BDM_REG_ABHR 0xc /* Address Breakpoint H Register */
#define BDM_REG_ABLR 0xd /* Address Breakpoint L Register */
#define BDM_REG_DBR 0xe /* Data Breakpoint Register */
#define BDM_REG_DBMR 0xf /* Data Breakpoint Mask Register */
/* system register for RREG/WREG */
#define BDM_REG_D0 0x0
#define BDM_REG_D1 0x1
#define BDM_REG_D2 0x2
#define BDM_REG_D3 0x3
#define BDM_REG_D4 0x4
#define BDM_REG_D5 0x5
#define BDM_REG_D6 0x6
#define BDM_REG_D7 0x7
#define BDM_REG_A0 0x8
#define BDM_REG_A1 0x9
#define BDM_REG_A2 0xa
#define BDM_REG_A3 0xb
#define BDM_REG_A4 0xc
#define BDM_REG_A5 0xd
#define BDM_REG_A6 0xe
#define BDM_REG_A7 0xf
/* op size for READ/WRITE */
#define BDM_SIZE_BYTE 0x0000
#define BDM_SIZE_WORD 0x0040
#define BDM_SIZE_LONG 0x0080
/* coldfire has trace capability */
/* processor status while trace */
#define BDM_PST_CONTINUE 0x0
#define BDM_PST_BEGIN 0x1
#define BDM_PST_RESERVED 0x2
#define BDM_PST_USERMODE 0x3
#define BDM_PST_PULSE 0x4
#define BDM_PST_BRANCH 0x5
#define BDM_PST_RESERVED2 0x6
#define BDM_PST_RTE 0x7
#define BDM_PST_DDATA1 0x8
#define BDM_PST_DDATA2 0x9
#define BDM_PST_DDATA3 0xa
#define BDM_PST_DDATA4 0xb
#define BDM_PST_EXCEPTION 0xc
#define BDM_PST_EMULATOR 0xd
#define BDM_PST_STOPPED 0xe
#define BDM_PST_HALTED 0xf
/* responses from chip */
/* bdm messages */
#define BDM_VALID 0x00000 /* not a message, but data transfer */
#define BDM_COMPLETE 0x0ffff
#define BDM_NOTREADY 0x10000
#define BDM_BERR 0x10001
#define BDM_ILLEGAL 0x1ffff
/* debug module register definitions */
/* AATR */
#define BDM_AATR_RM (1<<15) /* Read/Write mask */
#define BDM_AATR_SZM (3<<13) /* SiZe Mask */
#define BDM_AATR_TTM (3<<11) /* Transfer Type Mask */
#define BDM_AATR_TMM (7<<8) /* Transfer Modifier Mask */
#define BDM_AATR_R (1<<7) /* Read/write */
#define BDM_AATR_SZ (3<<5) /* SiZe */
#define BDM_AATR_TT (3<<3) /* Tranfer Type */
#define BDM_AATR_TM (7<<0) /* Transfer Modifier */
/* TDR */
#define BDM_TDR_TRC (3<<30) /* Trigger Response Control */
#define BDM_TDR_TRC_DATA (0<<30) /* Trigger Response Control */
#define BDM_TDR_TRC_HALT (1<<30) /* Trigger Response Control */
#define BDM_TDR_TRC_DEBG (2<<30) /* Trigger Response Control */
#define BDM_TDR_EBL2 (1<<29) /* Enable Breakpoint Level */
#define BDM_TDR_EDLW2 (1<<28) /* Enable Data BP for LongWord */
#define BDM_TDR_EDWL2 (1<<27) /* Enable Data BP for Word (Upper) */
#define BDM_TDR_EDWU2 (1<<26) /* Enable Data BP for Word (Lower) */
#define BDM_TDR_EDLL2 (1<<25) /* Enable Data BP for byte (LL) */
#define BDM_TDR_EDLM2 (1<<24) /* Enable Data BP for byte (LM) */
#define BDM_TDR_EDUM2 (1<<23) /* Enable Data BP for byte (UM) */
#define BDM_TDR_EDUU2 (1<<22) /* Enable Data BP for byte (UU) */
#define BDM_TDR_DI2 (1<<21) /* Data breakpoint invert */
#define BDM_TDR_EAI2 (1<<20) /* Enable Address breakpoint inverted */
#define BDM_TDR_EAR2 (1<<19) /* Enable Address breakpoint Range */
#define BDM_TDR_EAL2 (1<<18) /* Enable Address breakpoint Low */
#define BDM_TDR_EPC2 (1<<17) /* Enable PC breakpoint */
#define BDM_TDR_PCI2 (1<<16) /* PC breakpoint Invert */
#define BDM_TDR_EBL1 (1<<13) /* Enable Breakpoint Level */
#define BDM_TDR_EDLW1 (1<<12) /* Enable Data BP for LongWord */
#define BDM_TDR_EDWL1 (1<<11) /* Enable Data BP for Word (Upper) */
#define BDM_TDR_EDWU1 (1<<10) /* Enable Data BP for Word (Lower) */
#define BDM_TDR_EDLL1 (1<<9) /* Enable Data BP for byte (LL) */
#define BDM_TDR_EDLM1 (1<<8) /* Enable Data BP for byte (LM) */
#define BDM_TDR_EDUM1 (1<<7) /* Enable Data BP for byte (UM) */
#define BDM_TDR_EDUU1 (1<<6) /* Enable Data BP for byte (UU) */
#define BDM_TDR_DI1 (1<<5) /* Data breakpoint invert */
#define BDM_TDR_EAI1 (1<<4) /* Enable Address breakpoint inverted */
#define BDM_TDR_EAR1 (1<<3) /* Enable Address breakpoint Range */
#define BDM_TDR_EAL1 (1<<2) /* Enable Address breakpoint Low */
#define BDM_TDR_EPC1 (1<<1) /* Enable PC breakpoint */
#define BDM_TDR_PCI1 (1<<0) /* PC breakpoint Invert */
/* CSR */
#define BDM_CSR_STATUS (15<<28) /* breakpoint status */
# define BDM_CSR_STAT_NOBP 0
# define BDM_CSR_STAT_WAIT1 1
# define BDM_CSR_STAT_TRIGG1 2
# define BDM_CSR_STAT_WAIT2 5
# define BDM_CSR_STAT_TRIGG2 6
#define BDM_CSR_FOF (1<<27) /* Fault-On-Fault */
#define BDM_CSR_TRG (1<<26) /* hardware breakpoint TRiGger */
#define BDM_CSR_HALT (1<<25) /* processor HALT */
#define BDM_CSR_BKPT (1<<24) /* BreaKPoinT assert */
#define BDM_CSR_IPW (1<<16) /* Inhibit Processor Writes to dbg reg. */
#define BDM_CSR_MAP (1<<15) /* MAP processor accesses in emu mode */
#define BDM_CSR_TRC (1<<14) /* emulation mode on TRaCe exception */
#define BDM_CSR_EMU (1<<13) /* force EMUlation mode */
#define BDM_CSR_DDC (3<<11) /* Debug Data Control */
#define BDM_CSR_UHE (1<<10) /* User Halt Enable */
#define BDM_CSR_BTB (3<<8) /* Branch Target Bytes */
#define BDM_CSR_NPL (1<<6) /* NonPipelined Mode */
#define BDM_CSR_IPI (1<<5) /* Ignore Pending Interrupts */
#define BDM_CSR_SSM (1<<4) /* Single Step Mode */
#ifdef USERMODE
int bdm_open(int minor, int flags);
int bdm_ioctl(int minor, unsigned int request, unsigned long arg);
int bdm_read(int minor, unsigned char *p, int count);
int bdm_write(int minor, const unsigned char *p, int count);
void bdm_close(int minor);
#endif
#endif

View File

@@ -0,0 +1,792 @@
/* @#Copyright
* Copyright (c) 1997, Rolf Fiedler.
* Copyright (c) 1999-2000, Brett Wuth.
*/
/* @#License:
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File: bdmops.c (BDM Operations)
* Purpose:
* Author: Rolf Fiedler
* Created:
*
* Initials:
* BCW - Brett Wuth
* @#[ContactWuth:
* Phone: +1 403 627-2460
* E-mail: support@castrov.cuug.ab.ca, wuth@acm.org]
*
* this is an abstraction layer to have a general target programming interface
* so the programmer doesn't have to bother with motorola's bdm commands.
*
* applications only include bdmops.h and call the functions below
*
* HISTORY:
* $Log: bdmops.c,v $
* Revision 1.2 2005/10/24 01:37:25 cjohns
* Fixed includes for building in Windows with MinGW.
*
* Revision 1.1 2003/12/29 22:18:49 codewiz
* Move tools/bdm_abstraction to m68k/bdmabstraction and autoconfiscate.
*
* Revision 1.2 2003/07/04 22:33:01 codewiz
* Applied SST block-erase patch.
*
* Revision 1.1 2003/06/03 15:42:04 codewiz
* Import userland tools from bdm-fiedler
*
* Revision 1.6 2000/09/19 00:28:29 wuth
* cleanly use Fiedler's bdm driver; bdm_mon detects flash errors
*
* Revision 1.5 2000/07/25 13:51:09 wuth
* Working sector erase. Better error reports.
*
* Revision 1.4 2000/04/20 04:56:23 wuth
* GPL. Abstract flash interface.
*
* Revision 1.3 2000/03/28 20:24:41 wuth
* Break out flash code into separate executable. Make run under Chris Johns BDM driver.
*
* Revision 1.2 1999/07/05 22:09:50 wuth
* Abort if can't sync BDM. Work with Am29F800 flash.
* @#[BasedOnTemplate: template.c version 2]
*/
#define _COMPILING_
# include "bdmops.h"
#undef _COMPILING_
#include <assert.h>
#include "BDMDriver.h"
#include "Debug.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#if defined (__WIN32__) && !defined (__CYGWIN__)
#include <winsock.h>
#else
#include <netinet/in.h>
#endif
/*
* query status
*/
static unsigned long target_status=0;
#if BDMDriverVersion_M == BDMDriverFiedler_M
static int fd;
static void bdm_update_status(unsigned long x)
{
x &= CSR_FOF | CSR_TRG | CSR_HALT | CSR_BKPT; /* these bits ain't sticky */
target_status |= x;
}
static int bdm_read_status(void)
{
unsigned long x;
if(bdm_read_reg(REG_CSR, &x)) return -1;
bdm_update_status(x);
return 0;
}
#endif
/*
* general file handling
*/
/* open bdm-driver */
int /* <0 if error, BDMHandle otherwise */
bdm_init(const char *path)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long tdr, csr;
#ifdef USERMODE
fd=path[strlen(path)-1]-'0'; /* this is so ugly! works with /dev/bdm[0-9]*/
if(fd>3 || fd<0) return -1;
fd=bdm_open(fd, O_RDWR);
if(fd<0) return fd;
#else
fd=bdm_open(path, O_RDWR);
if(fd<0) return fd;
#endif
bdm_clear_status();
tdr = BDM_TDR_TRC_HALT; /* trigger response is halt */
if(bdm_write_reg(REG_TDR, &tdr)) return -1;
csr = BDM_CSR_UHE; /* user halt enable */
if(bdm_write_reg(REG_CSR, &csr)) return -1;
return fd;
#else
int fd=bdmOpen( path );
return (fd);
#endif
}
/* close driver */
void bdm_release(int port)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
bdm_close(fd);
#else
bdmClose();
#endif
}
/*
* bdm control functions
*/
/* bring chip to running state */
void bdm_run(void)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
bdm_ioctl(fd, BDM_RUN_CHIP_IOC, 0);
bdm_clear_status();
#else
/* not implemented */
#endif
}
/* bring chip to stopped state */
void bdm_stop(void)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
bdm_ioctl(fd, BDM_STOP_CHIP_IOC, 0);
bdm_read_status();
#else
/* not implemented */
#endif
}
/* step chip on instruction */
void bdm_step(void)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
bdm_ioctl(fd, BDM_STEP_CHIP_IOC, 0);
bdm_read_status();
#else
/* not implemented */
#endif
}
/* reset chip and hold in reset state */
void bdm_reset(void)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
bdm_ioctl(fd, BDM_RESET_CHIP_IOC, 0);
bdm_clear_status();
bdm_read_status();
#else
/* not implemented */
#endif
}
/* restart from reset to running state */
void bdm_restart(void)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
bdm_ioctl(fd, BDM_RESTART_CHIP_IOC, 0);
bdm_read_status();
#else
/* not implemented */
#endif
}
/*
* data transfer to/from target
*/
int regs_log2phys(CF_REGS which)
{
int i;
struct regs {
int logical;
int physical;
} regs[]= {
{REG_D0, BDM_REG_D0},
{REG_D1, BDM_REG_D1},
{REG_D2, BDM_REG_D2},
{REG_D3, BDM_REG_D3},
{REG_D4, BDM_REG_D4},
{REG_D5, BDM_REG_D5},
{REG_D6, BDM_REG_D6},
{REG_D7, BDM_REG_D7},
{REG_A0, BDM_REG_A0},
{REG_A1, BDM_REG_A1},
{REG_A2, BDM_REG_A2},
{REG_A3, BDM_REG_A3},
{REG_A4, BDM_REG_A4},
{REG_A5, BDM_REG_A5},
{REG_A6, BDM_REG_A6},
{REG_A7, BDM_REG_A7},
/* debug registers */
{REG_CSR, BDM_REG_CSR},
{REG_AATR, BDM_REG_AATR},
{REG_TDR, BDM_REG_TDR},
{REG_PBR, BDM_REG_PBR},
{REG_PBMR, BDM_REG_PBMR},
{REG_ABHR, BDM_REG_ABHR},
{REG_ABLR, BDM_REG_ABLR},
{REG_DBR, BDM_REG_DBR},
{REG_DBMR, BDM_REG_DBMR},
/* configuration registers */
{REG_CACR, BDM_REG_CACR},
{REG_ACR0, BDM_REG_ACR0},
{REG_ACR1, BDM_REG_ACR1},
{REG_VBR, BDM_REG_VBR},
{REG_SR, BDM_REG_SR},
{REG_RPC, BDM_REG_RPC},
{REG_RAMBAR, BDM_REG_RAMBAR},
{REG_MBAR, BDM_REG_MBAR},
{0xffff,0}
};
for(i=0; regs[i].logical!=0xffff; i++) {
if(regs[i].logical == which) return regs[i].physical;
}
return -1;
}
/* read a register from the chip */
int bdm_read_reg(CF_REGS which, unsigned long *value)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
int i;
if(which <= MAX_USER_REGS) {
unsigned long word[3];
which=regs_log2phys(which);
word[0]=BDM_RREG_CMD | which;
word[1]=BDM_NOP_CMD;
word[2]=BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(i<0)
return i;
if(word[1]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return -1;
}
*value = ((word[1] & 0xffff) << 16) | (word[2] & 0xffff);
return 0;
}
if(which <= MAX_CONFIG_REGS) {
unsigned long word[5];
which=regs_log2phys(which);
word[0]=BDM_RCREG_CMD;
word[1]=0;
word[2]=which;
word[3]=BDM_NOP_CMD;
word[4]=BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(i<0)
return i;
if(word[4]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return -1;
}
word[0]=word[4];
while(word[0]==BDM_NOTREADY) {
unsigned long poll = BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(i<0)
return i;
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return -1;
}
}
*value = ((word[3] & 0xffff) << 16) | (word[4] & 0xffff);
return 0;
}
if(which <= MAX_DEBUG_REGS) {
unsigned long word[3];
which=regs_log2phys(which);
word[0]=BDM_RDMREG_CMD | which;
word[1]=BDM_NOP_CMD;
word[2]=BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(i<0)
return i;
if(word[1]==BDM_ILLEGAL)
return -1;
*value = ((word[1] & 0xffff) << 16) | (word[2] & 0xffff);
if(which == REG_CSR) {
bdm_update_status(*value);
}
return 0;
}
return -1;
#else
/* not implemented */
return -1;
#endif
}
/* write a register in the chip */
int bdm_write_reg(CF_REGS which, unsigned long *value)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
int i;
if(which <= MAX_USER_REGS) {
unsigned long word[4];
which=regs_log2phys(which);
word[0]=BDM_WREG_CMD | which;
word[1]=(*value >> 16) & 0xffff;
word[2]=*value & 0xffff;
word[3]=BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(i<0)
return i;
if(word[1]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return -1;
}
return 0;
}
if(which <= MAX_CONFIG_REGS) {
unsigned long word[6];
which=regs_log2phys(which);
word[0]=BDM_WCREG_CMD;
word[1]=0;
word[2]=which;
word[3]=(*value >> 16) & 0xffff;
word[4]=*value & 0xffff;
word[5]=BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(i<0)
return i;
if(word[5]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return -1;
}
word[0]=word[5];
while(word[0]==BDM_NOTREADY) {
unsigned long poll = BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(i<0)
return i;
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return -1;
}
}
return 0;
}
if(which <= MAX_DEBUG_REGS) {
unsigned long word[4];
which=regs_log2phys(which);
word[0]=BDM_WDMREG_CMD | which;
word[1]=(*value >> 16) & 0xffff;
word[2]=*value & 0xffff;
word[3]=BDM_NOP_CMD;
i=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(i<0)
return i;
if(word[1]==BDM_ILLEGAL)
return -1;
return 0;
}
return -1;
#else
/* not implemented */
return -1;
#endif
}
/* read a block of memory, alignment doesn't matter anymore */
int bdm_read_mem(unsigned int addr, unsigned char *mem, int count)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long word[4], poll;
int read_bytes=0, ret;
int i;
if(!count) return 0;
/* align to long word boundary from target's point of view */
i=4-(addr&3);
for(; i>0 && count>0; i--) {
word[0]=BDM_READ_CMD | BDM_SIZE_BYTE;
word[1]=(addr>>16) & 0xffff;
word[2]=addr & 0xffff;
word[3]=BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(ret<0)
return ret;
if(word[3]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return BDM_FAULT_BERR;
}
if(word[3]==BDM_ILLEGAL)
return BDM_FAULT_NVC;
poll=word[3];
while(poll==BDM_NOTREADY) {
poll = BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(ret<0)
return ret;
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return BDM_FAULT_BERR;
}
if(poll==BDM_ILLEGAL)
return BDM_FAULT_NVC;
}
read_bytes++;
count--;
addr++;
*mem++=(unsigned char)(0xff & poll);
}
if(count>4) {
ret = bdm_read(fd, mem, count & ~3);
}
if(ret < 0) return ret;
read_bytes+=ret;
count-=ret;
addr+=ret;
mem+=ret;
while(count>0) {
word[0]=BDM_READ_CMD | BDM_SIZE_BYTE;
word[1]=(addr>>16) & 0xffff;
word[2]=addr & 0xffff;
word[3]=BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(ret<0)
return ret;
if(word[3]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return BDM_FAULT_BERR;
}
if(word[3]==BDM_ILLEGAL)
return BDM_FAULT_NVC;
poll=word[3];
while(poll==BDM_NOTREADY) {
poll = BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
if(ret<0)
return ret;
if(poll==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
unsigned long poll;
poll = BDM_NOP_CMD;
bdm_ioctl(fd, BDM_XCHG_DATA_IOC(poll), (unsigned long)&poll);
return BDM_FAULT_BERR;
}
if(poll==BDM_ILLEGAL)
return BDM_FAULT_NVC;
}
read_bytes++;
count--;
addr++;
*mem++=(unsigned char)(0xff & poll);
}
return read_bytes;
#else
/* not implemented */
return -1;
#endif
}
#if BDMDriverVersion_M == BDMDriverFiedler_M
static int perform_byte_write(int fd, unsigned int addr, unsigned char *mem)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long word[5];
int ret;
word[0]=BDM_WRITE_CMD | BDM_SIZE_BYTE;
word[1]=(addr>>16) & 0xffff;
word[2]=addr & 0xffff;
word[3]=*mem;
word[4]=BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word), (unsigned long)&word);
if(ret<0) {
PRINTD("error in bdm_ioctl (0x%08x): %d\n", addr, ret);
return ret;
}
if(word[4]==BDM_BERR) {
/* get BDM_NOT_READY after BERR */
PRINTD("bus error in bdm_ioctl (0x%08x): %d\n", addr, ret);
return BDM_FAULT_BERR;
}
if(word[4]==BDM_ILLEGAL) {
/* get BDM_NOT_READY after ILLEGAL */
PRINTD("illegal cmd in bdm_ioctl (0x%08x): %d\n", addr, ret);
return BDM_FAULT_NVC;
}
while(1) {
word[4] = BDM_NOP_CMD;
ret=bdm_ioctl(fd, BDM_XCHG_DATA_IOC(word[4]), (unsigned long)&word[4]);
if(ret<0) {
PRINTD("error in bdm_ioctl poll (0x%08x): %d\n", addr, ret);
return ret;
}
switch(word[4]) {
case BDM_BERR:
/* get BDM_NOT_READY after BERR */
PRINTD("bus error in bdm_ioctl poll (0x%08x): %d\n", addr, ret);
return BDM_FAULT_BERR;
case BDM_ILLEGAL:
PRINTD("illegal cmd in bdm_ioctl poll (0x%08x): %d\n", addr, ret);
return BDM_FAULT_NVC;
case BDM_COMPLETE:
return 0; /* we've done it ! */
case BDM_NOTREADY:
break;
default:
PRINTD("undefined reponse from target (0x%08x): %d\n", addr, ret);
return BDM_FAULT_BERR;
}
}
#else
/* not implemented */
return -1;
#endif
}
#endif
/* write a block of memory, alignment doesn't matter anymore */
int bdm_write_mem(unsigned int addr, unsigned char *mem, int count)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
int written=0, ret;
int i;
if(!count) return 0;
PRINTD("entering write_mem...");
/* align to long word boundary from target's point of view */
i=4-(addr&3); /* perform at least one write to set address */
for(; i && count; i--) {
PRINTD("alignment loop and AATR setup: %d\n", i);
ret=perform_byte_write(fd, addr, mem);
if(ret<0) return ret;
mem++;
written++;
count--;
addr++;
}
if(count>4) {
ret = bdm_write(fd, mem, count & ~3);
}
if(ret < 0) {
PRINTD("error in bdm_write: %d\n", ret);
return ret;
}
written+=ret;
count-=ret;
addr+=ret;
mem+=ret;
PRINTD("write syscall wrote %d (%x) bytes.\n", ret, ret);
while(count>0) {
ret=perform_byte_write(fd, addr, mem);
if(ret<0) return ret;
mem++;
written++;
count--;
addr++;
}
PRINTD("bdm_write_mem finished, %d bytes written\n", written);
return written;
#else
/* not implemented */
return -1;
#endif
}
void bdm_clear_status(void)
{
target_status = 0;
}
int bdm_query_status(void)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long x, y /* , z */;
y=0;
x = bdm_ioctl(fd, BDM_GET_STATUS_IOC, 0);
if(x & BDM_TARGETRESET) y |= BDM_STAT_RESET;
if(x & BDM_TARGETHALT) y |= BDM_STAT_PSTHALT;
if(x & BDM_TARGETSTOPPED);
if(x & BDM_TARGETPOWER) return BDM_STAT_NOPWR;
if(x & BDM_TARGETNC) return BDM_STAT_NC;
if(bdm_read_reg(REG_CSR, &x)) return -1;
printf("CSR=%08lx\n", x);
/* z = x & 0x10; USER HALT ENABLE */
/* y = x >> 28; it's better to translate */
x |= target_status;
if(x & CSR_BKPT) y |= BDM_STAT_BKPT;
if(x & CSR_HALT) y |= BDM_STAT_HALT;
if(x & CSR_TRG) y |= BDM_STAT_TRG;
if(x & CSR_FOF) y |= BDM_STAT_FOF;
if(x & CSR_SSM) y |= BDM_STAT_SSM;
switch(x>>28) {
case CSR_STAT_WAIT1:
y |= BDM_STAT_WAIT1;
break;
case CSR_STAT_TRIG1:
y |= BDM_STAT_TRIG1;
break;
case CSR_STAT_WAIT2:
y |= BDM_STAT_WAIT2;
break;
case CSR_STAT_TRIG2:
y |= BDM_STAT_TRIG2;
break;
}
return y;
#else
/* not implemented */
return -1;
#endif
}
/*
* wait for stopped target
*/
int bdm_wait(void)
{
#if BDMDriverVersion_M == BDMDriverFiedler_M
unsigned long x;
while(1) {
usleep(100000);
x = bdm_ioctl(fd, BDM_GET_STATUS_IOC, 0);
if(x & BDM_TARGETRESET) return BDM_STAT_RESET;
if(x & BDM_TARGETHALT) return BDM_STAT_PSTHALT;
if(x & BDM_TARGETSTOPPED) return BDM_STAT_HALT;
if(x & BDM_TARGETPOWER) return BDM_STAT_NOPWR;
if(x & BDM_TARGETNC) return BDM_STAT_NC;
}
#else
/* not implemented */
return -1;
#endif
}
static unsigned long tdr = 0; /* shadow trigger definition register */
/*
* breakpoint control
*/
int bdm_set_pc_bp(unsigned long addr, unsigned long mask)
{
bdm_stop();
if(bdm_write_reg(REG_PBR, &addr)) return -1;
if(bdm_write_reg(REG_PBMR, &mask)) return -1;
tdr = (1 << 30) | (~(3<<30) & tdr); /* trigger response is halt */
tdr |= 1 << 29; /* enable second level trigger breakpoints */
tdr |= 1 << 13; /* enable first level trigger breakpoints */
tdr |= 1 << 1; /* enable PC breakpoint */
tdr &= ~1; /* clear PC breakpoint invert */
if(bdm_write_reg(REG_TDR, &tdr)) return -1;
return 0;
}
int bdm_clear_pc_bp(void)
{
bdm_stop();
tdr &= ~(1 << 1); /* disable PC breakpoint */
if(bdm_write_reg(REG_TDR, &tdr)) return -1;
return 0;
}
int bdm_set_addr_bp(unsigned long from_addr, unsigned long to_addr)
{
unsigned long tmp=0xff05;
bdm_stop();
if(bdm_write_reg(REG_ABLR, &from_addr)) return -1;
if(bdm_write_reg(REG_ABHR, &to_addr)) return -1;
if(bdm_write_reg(REG_AATR, &tmp)) return -1; /* match everything */
tdr = (1 << 30) | (~(3<<30) & tdr); /* trigger response is halt */
tdr &= ~(1 << 29); /* disable second level trigger breakpoints */
tdr |= 1 << 13; /* enable first level trigger breakpoints */
tdr = (tdr & ~(7<<2)) | (2 << 2);
/* enable address range breakpoint */
if(bdm_write_reg(REG_TDR, &tdr)) return -1;
return 0;
}
int bdm_clear_addr_bp(void)
{
bdm_stop();
tdr = (tdr & ~(7<<2)) | (0 << 2);
/* disable address range breakpoint */
if(bdm_write_reg(REG_TDR, &tdr)) return -1;
return 0;
}
int bdm_set_data_bp(unsigned long value, unsigned long mask)
{
bdm_stop();
bdm_write_reg(REG_DBR, &value);
bdm_write_reg(REG_DBMR, &mask);
tdr = (1 << 30) | (~(3<<30) & tdr); /* trigger response is halt */
tdr &= ~(1 << 29); /* disable second level trigger breakpoints */
tdr |= 1 << 13; /* enable first level trigger breakpoints */
tdr = (tdr & ~(0xff<<5)) | (0x80 << 5);
/* enable data breakpoint for long word */
if(bdm_write_reg(REG_TDR, &tdr)) return -1;
return 0;
}
int bdm_clear_data_bp(void)
{
bdm_stop();
tdr = (tdr & ~(0xff<<5)) | (0x00 << 5);
/* disable data breakpoint */
if(bdm_write_reg(REG_TDR, &tdr)) return -1;
return 0;
}

View File

@@ -0,0 +1,246 @@
#ifndef _BDMOPS_H_
#define _BDMOPS_H_
/*
* bdm abstraction for coldfire processors
*
* 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, 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
typedef enum CF_REGS {
/* user registers */
REG_D0,
REG_D1,
REG_D2,
REG_D3,
REG_D4,
REG_D5,
REG_D6,
REG_D7,
REG_A0,
REG_A1,
REG_A2,
REG_A3,
REG_A4,
REG_A5,
REG_A6,
REG_A7,
MAX_USER_REGS=REG_A7,
/* RCREG/WCREG */
REG_CACR,
REG_ACR0,
REG_ACR1,
REG_VBR,
REG_SR,
REG_RPC,
REG_RAMBAR,
REG_MBAR,
MAX_CONFIG_REGS=REG_MBAR,
/* RDMREG/WDMREG */
REG_CSR,
REG_AATR,
REG_TDR,
REG_PBR,
REG_PBMR,
REG_ABHR,
REG_ABLR,
REG_DBR,
REG_DBMR,
MAX_DEBUG_REGS=REG_DBMR,
MAX_REGS
} CF_REGS;
#ifdef REG_NAMES
struct reg_names {
CF_REGS id;
const char name[8];
} reg_names[]={
/* user registers */
{ REG_D0, "D0"},
{ REG_D1, "D1"},
{ REG_D2, "D2"},
{ REG_D3, "D3"},
{ REG_D4, "D4"},
{ REG_D5, "D5"},
{ REG_D6, "D6"},
{ REG_D7, "D7"},
{ REG_A0, "A0"},
{ REG_A1, "A1"},
{ REG_A2, "A2"},
{ REG_A3, "A3"},
{ REG_A4, "A4"},
{ REG_A5, "A5"},
{ REG_A6, "A6"},
{ REG_A7, "A7"},
/* RCREG/WCREG */
{ REG_CACR, "CACR"},
{ REG_ACR0, "ACR0"},
{ REG_ACR1, "ACR1"},
{ REG_VBR, "VBR"},
{ REG_SR, "SR"},
{ REG_RPC, "RPC"},
{ REG_RAMBAR, "RAMBAR"},
{ REG_MBAR, "MBAR"},
/* RDMREG/WDMREG */
{ REG_CSR, "CSR"},
{ REG_AATR, "AATR"},
{ REG_TDR, "TDR"},
{ REG_PBR, "PBR"},
{ REG_PBMR, "PBMR"},
{ REG_ABHR, "ABHR"},
{ REG_ABLR, "ABLR"},
{ REG_DBR, "DBR"},
{ REG_DBMR, "DBMR"},
{ 0xffff, ""}
};
#endif
/* debug module register definitions */
/* AATR */
#define AATR_RM (1<<15) /* Read/Write mask */
#define AATR_SZM (3<<13) /* SiZe Mask */
#define AATR_TTM (3<<11) /* Transfer Type Mask */
#define AATR_TMM (7<<8) /* Transfer Modifier Mask */
#define AATR_R (1<<7) /* Read/write */
#define AATR_SZ (3<<5) /* SiZe */
#define AATR_TT (3<<3) /* Tranfer Type */
#define AATR_TM (7<<0) /* Transfer Modifier */
/* TDR */
#define TDR_TRC (3<<30) /* Trigger Response Control */
#define TDR_EBL2 (1<<29) /* Enable Breakpoint Level */
#define TDR_EDLW2 (1<<28) /* Enable Data BP for LongWord */
#define TDR_EDWL2 (1<<27) /* Enable Data BP for Word (Upper) */
#define TDR_EDWU2 (1<<26) /* Enable Data BP for Word (Lower) */
#define TDR_EDLL2 (1<<25) /* Enable Data BP for byte (LL) */
#define TDR_EDLM2 (1<<24) /* Enable Data BP for byte (LM) */
#define TDR_EDUM2 (1<<23) /* Enable Data BP for byte (UM) */
#define TDR_EDUU2 (1<<22) /* Enable Data BP for byte (UU) */
#define TDR_DI2 (1<<21) /* Data breakpoint invert */
#define TDR_EAI2 (1<<20) /* Enable Address breakpoint inverted */
#define TDR_EAR2 (1<<19) /* Enable Address breakpoint Range */
#define TDR_EAL2 (1<<18) /* Enable Address breakpoint Low */
#define TDR_EPC2 (1<<17) /* Enable PC breakpoint */
#define TDR_PCI2 (1<<16) /* PC breakpoint Invert */
#define TDR_EBL1 (1<<13) /* Enable Breakpoint Level */
#define TDR_EDLW1 (1<<12) /* Enable Data BP for LongWord */
#define TDR_EDWL1 (1<<11) /* Enable Data BP for Word (Upper) */
#define TDR_EDWU1 (1<<10) /* Enable Data BP for Word (Lower) */
#define TDR_EDLL1 (1<<9) /* Enable Data BP for byte (LL) */
#define TDR_EDLM1 (1<<8) /* Enable Data BP for byte (LM) */
#define TDR_EDUM1 (1<<7) /* Enable Data BP for byte (UM) */
#define TDR_EDUU1 (1<<6) /* Enable Data BP for byte (UU) */
#define TDR_DI1 (1<<5) /* Data breakpoint invert */
#define TDR_EAI1 (1<<4) /* Enable Address breakpoint inverted */
#define TDR_EAR1 (1<<3) /* Enable Address breakpoint Range */
#define TDR_EAL1 (1<<2) /* Enable Address breakpoint Low */
#define TDR_EPC1 (1<<1) /* Enable PC breakpoint */
#define TDR_PCI1 (1<<0) /* PC breakpoint Invert */
/* CSR */
#define CSR_STATUS (15<<28) /* breakpoint status */
# define CSR_STAT_NOBP 0
# define CSR_STAT_WAIT1 1
# define CSR_STAT_TRIG1 2
# define CSR_STAT_WAIT2 5
# define CSR_STAT_TRIG2 6
#define CSR_FOF (1<<27) /* Fault-On-Fault */
#define CSR_TRG (1<<26) /* hardware breakpoint TRiGger */
#define CSR_HALT (1<<25) /* processor HALT */
#define CSR_BKPT (1<<24) /* BreaKPoinT assert */
#define CSR_IPW (1<<16) /* Inhibit Processor Writes to dbg reg. */
#define CSR_MAP (1<<15) /* MAP processor accesses in emu mode */
#define CSR_TRC (1<<14) /* emulation mode on TRaCe exception */
#define CSR_EMU (1<<13) /* force EMUlation mode */
#define CSR_DDC (3<<11) /* Debug Data Control */
#define CSR_UHE (1<<10) /* User Halt Enable */
#define CSR_BTB (3<<8) /* Branch Target Bytes */
#define CSR_NPL (1<<6) /* NonPipelined Mode */
#define CSR_IPI (1<<5) /* Ignore Pending Interrupts */
#define CSR_SSM (1<<4) /* Single Step Mode */
/*
* this is an abstraction layer to have a general target programming interface
* so the programmer doesn't have to bother with motorola's bdm commands.
*
* applications only include bdmops.h and call the functions below
*/
/* open bdm-driver */
int /* <0 if error, BDMHandle otherwise */
bdm_init(const char *path);
/* close driver */
void bdm_release(int port);
/* bring chip to running state */
void bdm_run(void);
/* bring chip to stopped state */
void bdm_stop(void);
/* step chip on instruction */
void bdm_step(void);
/* reset chip and hold in reset state */
void bdm_reset(void);
/* restart from reset to running state */
void bdm_restart(void);
/* read a register from the chip */
int bdm_read_reg(CF_REGS which, unsigned long *value);
/* write a register in the chip */
int bdm_write_reg(CF_REGS which, unsigned long *value);
/* read a block of memory, alignment doesn't matter anymore */
int bdm_read_mem(unsigned int addr, unsigned char *mem, int count);
/* write a block of memory, alignment doesn't matter anymore */
int bdm_write_mem(unsigned int addr, unsigned char *mem, int count);
/* set program counter break point */
int bdm_set_pc_bp(unsigned long addr, unsigned long mask);
int bdm_clear_pc_bp(void);
/* set program counter break point */
int bdm_set_addr_bp(unsigned long from_addr, unsigned long to_addr);
int bdm_clear_addr_bp(void);
/* set program counter break point */
int bdm_set_data_bp(unsigned long value, unsigned long mask);
int bdm_clear_daat_bp(void);
/* bdm query status */
void bdm_clear_status(void);
int bdm_query_status(void);
#define BDM_STAT_BKPT (1<<0)
#define BDM_STAT_HALT (1<<1)
#define BDM_STAT_TRG (1<<2)
#define BDM_STAT_FOF (1<<3)
#define BDM_STAT_SSM (1<<4)
#define BDM_STAT_WAIT1 (1<<5)
#define BDM_STAT_TRIG1 (1<<6)
#define BDM_STAT_WAIT2 (1<<7)
#define BDM_STAT_TRIG2 (1<<8)
#define BDM_STAT_RESET (1<<9)
#define BDM_STAT_NOPWR (1<<10)
#define BDM_STAT_PSTHALT (1<<11)
#define BDM_STAT_NC (1<<12)
/* bdm wait for stopped target */
int bdm_wait(void);
#ifdef _COMPILING_
# ifdef USERMODE
int bdm_open(int minor, int flags);
int bdm_ioctl(int minor, unsigned int request, unsigned long arg);
int bdm_read(int minor, unsigned char *p, int count);
int bdm_write(int minor, const unsigned char *p, int count);
void bdm_close(int minor);
# else
# define bdm_open open
# define bdm_ioctl ioctl
# define bdm_read read
# define bdm_write write
# define bdm_close close
# endif
#endif
#endif