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

5
m68k/tblcf/.cvsignore Normal file
View File

@@ -0,0 +1,5 @@
.deps
Makefile
Makefile.in
bdmgdbserver
bdmgdbserver.exe

60
m68k/tblcf/Makefile.am Normal file
View File

@@ -0,0 +1,60 @@
##
## $Id: Makefile.am,v 1.1 2008/03/06 10:35:40 cjohns 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$(srcdir)/../driver -I$(srcdir)/../lib
AM_CFLAGS = -Wall -g
if LIBUSB_PATH
AM_CPPFLAGS += -I@LIBUSB_INCLUDE_DIR@
AM_LDFLAGS = -L@LIBUSB_LIB_DIR@
endif
if WIN32
LIBS += -l wsock32
endif
bin_PROGRAMS = tblcf-show tblcf-boot tblcf-unsec
tblcf_show_SOURCES = \
tblcf-show.c \
log.c
tblcf_show_LDADD = \
$(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a
tblcf_boot_SOURCES = \
tblcf_bt.c \
log_cmdline.c \
srec.c
tblcf_boot_LDADD = \
$(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a \
$(top_builddir)/tblcf/libtblcf.a
tblcf_unsec_SOURCES = \
tblcf_unsec.c \
log_cmdline.c
tblcf_unsec_LDADD = \
$(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a
lib_LIBRARIES = libtblcf.a
include_HEADERS = \
tblcf.h
libtblcf_a_SOURCES = \
tblcf.c \
tblcf_usb.c \
log.c

574
m68k/tblcf/Makefile.in Normal file
View File

@@ -0,0 +1,574 @@
# 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@
@LIBUSB_PATH_TRUE@am__append_1 = -I@LIBUSB_INCLUDE_DIR@
@WIN32_TRUE@am__append_2 = -l wsock32
bin_PROGRAMS = tblcf-show$(EXEEXT) tblcf-boot$(EXEEXT) \
tblcf-unsec$(EXEEXT)
subdir = tblcf
DIST_COMMON = $(include_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 =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
"$(DESTDIR)$(includedir)"
libLIBRARIES_INSTALL = $(INSTALL_DATA)
LIBRARIES = $(lib_LIBRARIES)
ARFLAGS = cru
libtblcf_a_AR = $(AR) $(ARFLAGS)
libtblcf_a_LIBADD =
am_libtblcf_a_OBJECTS = tblcf.$(OBJEXT) tblcf_usb.$(OBJEXT) \
log.$(OBJEXT)
libtblcf_a_OBJECTS = $(am_libtblcf_a_OBJECTS)
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_tblcf_boot_OBJECTS = tblcf_bt.$(OBJEXT) log_cmdline.$(OBJEXT) \
srec.$(OBJEXT)
tblcf_boot_OBJECTS = $(am_tblcf_boot_OBJECTS)
tblcf_boot_DEPENDENCIES = $(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a $(top_builddir)/tblcf/libtblcf.a
am_tblcf_show_OBJECTS = tblcf-show.$(OBJEXT) log.$(OBJEXT)
tblcf_show_OBJECTS = $(am_tblcf_show_OBJECTS)
tblcf_show_DEPENDENCIES = $(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a
am_tblcf_unsec_OBJECTS = tblcf_unsec.$(OBJEXT) log_cmdline.$(OBJEXT)
tblcf_unsec_OBJECTS = $(am_tblcf_unsec_OBJECTS)
tblcf_unsec_DEPENDENCIES = $(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a
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 = $(libtblcf_a_SOURCES) $(tblcf_boot_SOURCES) \
$(tblcf_show_SOURCES) $(tblcf_unsec_SOURCES)
DIST_SOURCES = $(libtblcf_a_SOURCES) $(tblcf_boot_SOURCES) \
$(tblcf_show_SOURCES) $(tblcf_unsec_SOURCES)
includeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(include_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@ $(am__append_2)
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$(srcdir)/../driver -I$(srcdir)/../lib $(am__append_1)
AM_CFLAGS = -Wall -g
@LIBUSB_PATH_TRUE@AM_LDFLAGS = -L@LIBUSB_LIB_DIR@
tblcf_show_SOURCES = \
tblcf-show.c \
log.c
tblcf_show_LDADD = \
$(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a
tblcf_boot_SOURCES = \
tblcf_bt.c \
log_cmdline.c \
srec.c
tblcf_boot_LDADD = \
$(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a \
$(top_builddir)/tblcf/libtblcf.a
tblcf_unsec_SOURCES = \
tblcf_unsec.c \
log_cmdline.c
tblcf_unsec_LDADD = \
$(top_builddir)/tblcf/libtblcf.a \
$(top_builddir)/lib/libBDM.a
lib_LIBRARIES = libtblcf.a
include_HEADERS = \
tblcf.h
libtblcf_a_SOURCES = \
tblcf.c \
tblcf_usb.c \
log.c
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 tblcf/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign tblcf/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
install-libLIBRARIES: $(lib_LIBRARIES)
@$(NORMAL_INSTALL)
test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
@list='$(lib_LIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f=$(am__strip_dir) \
echo " $(libLIBRARIES_INSTALL) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
$(libLIBRARIES_INSTALL) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
else :; fi; \
done
@$(POST_INSTALL)
@list='$(lib_LIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
p=$(am__strip_dir) \
echo " $(RANLIB) '$(DESTDIR)$(libdir)/$$p'"; \
$(RANLIB) "$(DESTDIR)$(libdir)/$$p"; \
else :; fi; \
done
uninstall-libLIBRARIES:
@$(NORMAL_UNINSTALL)
@list='$(lib_LIBRARIES)'; for p in $$list; do \
p=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(libdir)/$$p'"; \
rm -f "$(DESTDIR)$(libdir)/$$p"; \
done
clean-libLIBRARIES:
-test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
libtblcf.a: $(libtblcf_a_OBJECTS) $(libtblcf_a_DEPENDENCIES)
-rm -f libtblcf.a
$(libtblcf_a_AR) libtblcf.a $(libtblcf_a_OBJECTS) $(libtblcf_a_LIBADD)
$(RANLIB) libtblcf.a
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
tblcf-boot$(EXEEXT): $(tblcf_boot_OBJECTS) $(tblcf_boot_DEPENDENCIES)
@rm -f tblcf-boot$(EXEEXT)
$(LINK) $(tblcf_boot_OBJECTS) $(tblcf_boot_LDADD) $(LIBS)
tblcf-show$(EXEEXT): $(tblcf_show_OBJECTS) $(tblcf_show_DEPENDENCIES)
@rm -f tblcf-show$(EXEEXT)
$(LINK) $(tblcf_show_OBJECTS) $(tblcf_show_LDADD) $(LIBS)
tblcf-unsec$(EXEEXT): $(tblcf_unsec_OBJECTS) $(tblcf_unsec_DEPENDENCIES)
@rm -f tblcf-unsec$(EXEEXT)
$(LINK) $(tblcf_unsec_OBJECTS) $(tblcf_unsec_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log_cmdline.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/srec.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tblcf-show.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tblcf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tblcf_bt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tblcf_unsec.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tblcf_usb.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) '$<'`
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
@list='$(include_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
$(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(include_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
rm -f "$(DESTDIR)$(includedir)/$$f"; \
done
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) $(PROGRAMS) $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
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-binPROGRAMS clean-generic clean-libLIBRARIES \
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-includeHEADERS
install-dvi: install-dvi-am
install-exec-am: install-binPROGRAMS install-libLIBRARIES
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: uninstall-binPROGRAMS uninstall-includeHEADERS \
uninstall-libLIBRARIES
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic clean-libLIBRARIES ctags distclean \
distclean-compile distclean-generic distclean-tags distdir dvi \
dvi-am html html-am info info-am install install-am \
install-binPROGRAMS install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-includeHEADERS install-info \
install-info-am install-libLIBRARIES 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 uninstall-binPROGRAMS uninstall-includeHEADERS \
uninstall-libLIBRARIES
# 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:

81
m68k/tblcf/commands.h Normal file
View File

@@ -0,0 +1,81 @@
/* command format:
1 byte : command number (see below)
n bytes: command parameters (data)
data format:
all 16-bit and 32-bit data is transferred in big endian, i.e. MSB on lower address (first) and LSB on higher address (next)
data must be converted properly on intel machines (PCs)
*/
/* cable status bit fields */
#define RESET_DETECTED_MASK 0x0001
#define RSTO_STATE_MASK 0x0002
/* target types */
#define TARGET_TYPE_CF_BDM 0
#define TARGET_TYPE_JTAG 1
/* if command fails, the device responds with command code CMD_FAILED */
/* if command succeeds, the device responds with the same command number followed by any results as appropriate */
#define MAX_DATA_SIZE 127 /* maximum command parameter/result block size in bytes; this is to make sure that response of READ_BLOCK plus the command status fit into 16 frames exactly */
/* System related commands */
#define CMD_FAILED 1 /* command execution failed (incorrect parameters, target not responding, etc.) */
#define CMD_UNKNOWN 2 /* unknown command */
/* TurboBdmLightCF related commands */
#define CMD_GET_VER 10 /* returns 16 bit HW/SW version number, (major & minor revision in BCD in each byte - HW in MSB, SW in LSB; intel endianism) */
#define CMD_GET_LAST_STATUS 11 /* returns status of the previous command */
#define CMD_SET_BOOT 12 /* request bootloader firmware upgrade on next power-up, parameters: 'B','O','O','T', returns: none */
#define CMD_GET_STACK_SIZE 13 /* parameters: none, returns 16-bit stack size required by the application (so far into the execution) */
/* BDM/debugging related commands */
#define CMD_SET_TARGET 20 /* set target, 8bit parameter: 00=ColdFire(default), 01=JTAG */
#define CMD_RESET 21 /* 8bit parameter: 0=reset to BDM Mode, 1=reset to Normal mode */
#define CMD_GET_STATUS 22 /* returns 16bit status word: bit0 - target was reset since last execution of this command (this bit is cleared after reading), bit1 - current state of the RSTO pin, big endian! */
#define CMD_HALT 23 /* stop the CPU and bring it into BDM mode */
#define CMD_GO 24 /* start code execution from current PC address */
#define CMD_STEP 25 /* perform single step */
#define CMD_RESYNCHRONIZE 26 /* resynchronize communication with the target (in case of noise, etc.) */
#define CMD_ASSERT_TA 27 /* parameter: 8-bit number of 10us ticks - duration of the TA assertion */
/* CPU related commands */
#define CMD_READ_MEM8 30 /* parameter 32bit address, returns 8bit value read from address */
#define CMD_READ_MEM16 31 /* parameter 32bit address, returns 16bit value read from address */
#define CMD_READ_MEM32 32 /* parameter 32bit address, returns 32bit value read from address */
#define CMD_READ_MEMBLOCK8 33 /* parameter 32bit address, returns block of 8bit values read from the address and onwards */
#define CMD_READ_MEMBLOCK16 34 /* parameter 32bit address, returns block of 16bit values read from the address and onwards */
#define CMD_READ_MEMBLOCK32 35 /* parameter 32bit address, returns block of 32bit values read from the address and onwards */
#define CMD_WRITE_MEM8 36 /* parameter 32bit address & an 8-bit value to be written to the address */
#define CMD_WRITE_MEM16 37 /* parameter 32bit address & a 16-bit value to be written to the address */
#define CMD_WRITE_MEM32 38 /* parameter 32bit address & a 32-bit value to be written to the address */
#define CMD_WRITE_MEMBLOCK8 39 /* parameter 32bit address & a block of 8-bit values to be written from the address */
#define CMD_WRITE_MEMBLOCK16 40 /* parameter 32bit address & a block of 16-bit values to be written from the address */
#define CMD_WRITE_MEMBLOCK32 41 /* parameter 32bit address & a block of 32-bit values to be written from the address */
#define CMD_READ_REG 42 /* parameter 8-bit register number to read, returns 32-bit register contents */
#define CMD_WRITE_REG 43 /* parameter 8-bit register number to write & the 32-bit register contents to be written */
#define CMD_READ_CREG 44 /* parameter 16-bit register address, returns 32-bit control register contents */
#define CMD_WRITE_CREG 45 /* parameter 16-bit register address & the 32-bit control register contents to be written */
#define CMD_READ_DREG 46 /* parameter 8-bit register number to read, returns 32-bit debug module register contents */
#define CMD_WRITE_DREG 47 /* parameter 8-bit register number to write & the 32-bit debug module register contents to be written */
/* JTAG commands */
#define CMD_JTAG_GOTORESET 80 /* no parameters, takes the TAP to TEST-LOGIC-RESET state, re-select the JTAG target to take TAP back to RUN-TEST/IDLE */
#define CMD_JTAG_GOTOSHIFT 81 /* parameters 8-bit path option; path option ==0 : go to SHIFT-DR, !=0 : go to SHIFT-IR (requires the tap to be in RUN-TEST/IDLE) */
#define CMD_JTAG_WRITE 82 /* parameters 8-bit exit option, 8-bit count of bits to shift in, and the data to be shifted in (shifted in LSB (last byte) first, unused bits (if any) are in the MSB (first) byte; exit option ==0 : stay in SHIFT-xx, !=0 : go to RUN-TEST/IDLE when finished */
#define CMD_JTAG_READ 83 /* parameters 8-bit exit option, 8-bit count of bits to shift out; exit option ==0 : stay in SHIFT-xx, !=0 : go to RUN-TEST/IDLE when finished, returns the data read out of the device (first bit in LSB of the last byte in the buffer) */
/* Comments:
*/

43
m68k/tblcf/log.c Normal file
View File

@@ -0,0 +1,43 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
Changed to support the BDM project.
Chris Johns (cjohns@user.sourgeforge.net)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include "log.h"
void tblcf_print_dump(unsigned char *data, unsigned int size) {
static char buf[256];
char *p = buf;
unsigned int i=0;
while(size--) {
p += sprintf(p,"%02X ",*(data++));
if (((++i)%32)==0) {
tblcf_print("%s\n", buf);
p = buf;
}
else if (((i)%8)==0) {
p = strcat (p, " ");
}
}
if (((i)%32)!=0) tblcf_print("%s\n", buf);
}

3
m68k/tblcf/log.h Normal file
View File

@@ -0,0 +1,3 @@
#define tblcf_print bdmPrint
void bdmPrint(const char *format, ...);
void tblcf_print_dump(unsigned char *data, unsigned int size);

135
m68k/tblcf/log_cmdline.c Normal file
View File

@@ -0,0 +1,135 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include "log_cmdline.h"
static int log=0;
#ifdef DETAILED_LOG_CAPABILITY
static int dbg_level=0;
#endif
FILE *log_file;
/* prints messages on stdout and into log file */
int print_screen(const char *format, ...) {
va_list list;
int i;
va_start(list, format);
i=vprintf(format, list);
if (log) vfprintf(log_file, format, list);
fflush(log_file);
va_end(list);
return(i);
}
#ifdef DETAILED_LOG_CAPABILITY
/* prints messages on stdout and into log file if level < dbg_level level */
void print_screen_level(unsigned char msg_level, const char *format, ...) {
va_list list;
if (dbg_level<msg_level) return;
va_start(list, format);
vprintf(format, list);
if (log) {
fprintf(log_file, "%04.3f: ",1.0*GetTickCount()/1000);
vfprintf(log_file, format, list);
fflush(log_file);
}
va_end(list);
return;
}
/* same as print_screen_level, but takes va_list instead of ... */
void vprint_screen_level(unsigned char msg_level, const char *format, va_list list) {
if (dbg_level<msg_level) return;
vprintf(format, list);
if (log) {
fprintf(log_file, "%04.3f: ",1.0*GetTickCount()/1000);
vfprintf(log_file, format, list);
fflush(log_file);
}
return;
}
/* prints last system error in human readable form */
void print_last_error_level(unsigned char msg_level, int error) {
char buffer[100];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,error,0,buffer,sizeof(buffer),0);
print_screen_level(msg_level," %s",buffer);
}
/* sets debugging level */
void set_dbg_level(int new_dbg_level) {
dbg_level=new_dbg_level;
}
/* prints data in hex format */
void print_dump_level(unsigned char msg_level, unsigned char *data, unsigned int size) {
unsigned int i=0;
if (dbg_level<msg_level) return;
while(size--) {
printf("%02X ",*data);
if (log) fprintf(log_file, "%02X ",*data);
data++;
if (((++i)%16)==0) {
printf("\n");
if ((log)&&((i%32)==0)) fprintf(log_file,"\n");
}
if ((i%8)==0) {
if ((i%16)!=0) printf(" ");
if ((log)&&((i%32)!=0)) fprintf(log_file," ");
}
}
if ((i%32)!=0) {
if ((i%16)!=0) printf("\n");
if (log) fprintf(log_file,"\n");
}
fflush(log_file);
}
#endif
/* opens log file */
int open_log(char *path) {
time_t timer;
log_file=fopen(path,"wb");
if (log_file==NULL) {
printf("Cannot open log file \"%s\"\n",path);
return(-1);
}
if (atexit(close_log)) {
printf("Error registering atexit function: %s\n",path);
return(-2);
}
printf("Log file: %s\n",path);
log=1;
time(&timer);
print_screen("Timestamp: %s\r", ctime(&timer));
return(0);
}
/* closes log file */
void close_log(void) {
if (log) {
fprintf(log_file, "Closing the log file\n");
fclose(log_file);
}
}

35
m68k/tblcf/log_cmdline.h Normal file
View File

@@ -0,0 +1,35 @@
int print_screen(const char *format, ...);
int open_log(char *path);
void close_log(void);
#ifdef DETAILED_LOG_CAPABILITY
void print_screen_level(unsigned char msg_level, const char *format, ...);
void set_dbg_level(int new_dbg_level);
void print_last_error_level(unsigned char msg_level,int error);
void print_dump_level(unsigned char msg_level, unsigned char *data, unsigned int size);
void vprint_screen_level(unsigned char msg_level, const char *format, va_list list);
#else
#define print_screen_level(...)
#define set_dbg_level(new_dbg_level)
#define print_last_error_level(msg_level,error)
#define print_dump_level(msg_level, data, size)
#define vprint_screen_level(msg_level, format, list)
#endif
/* debugging levels:
0 - basic messages, start-up, shutdown...
10 - connection/disconnection of debugger
20 - commands
30 - commands & their parameters, results
40 - detailed execution of commands
50 - details including TCP/IP
*/
#define TCP_LOG_LEVEL_HIGH 10
#define CMD_LOG_LEVEL_HIGH 20
#define CMD_LOG_LEVEL_LOW 30
#define CMD_LOG_LEVEL_DETAILED 40
#define TCP_LOG_LEVEL_LOW 50

118
m68k/tblcf/srec.c Normal file
View File

@@ -0,0 +1,118 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include "log_cmdline.h"
#include "srec.h"
#include "tblcf_hwdesc.h"
#include "tblcf_bt.h"
/* converts BCD number to unsigned integer value */
unsigned int hex2dec(char *bcd) {
unsigned int i,result;
int charvalue;
result=0;
for (i=0;i<2;i++) {
charvalue=*bcd-'0';
if (charvalue>9) charvalue-='A'-'0'-10;
if (charvalue>15) charvalue-='a'-'A';
if ((charvalue>15) || (charvalue<0)) {
printf("Hex2dec conversion error: %c\r\n",*bcd);
return (0);
}
bcd++;
result*=16;
result+=charvalue;
}
return (result);
}
/* extract address and data from each line */
/* returns 0 on success and -1 on error */
/* checksum is not verified */
char s_line_process(char *line) {
int i;
unsigned int address;
switch (line[1]) {
case '0':
/* S0 - header */
for (i=0;i<((strlen(line)-8-2)/2);i++) line[i]=hex2dec(line+8+i*2); /* convert the string to readable text */
line[i]=0; /* terminate the string */
print_screen("S-rec: \"%s\"\r\n",line);
return(0);
case '1':
/* S1 */
address = 256*hex2dec(line+4) + hex2dec(line+6);
if ((address>=TBLCF_FLASH_START)&&(address<=TBLCF_FLASH_END)) {
/* application code */
for (i=0;i<((strlen(line)-8-2)/2);i++) {
if ((address+i)>TBLCF_FLASH_END) {
print_screen("S-rec address (0x%04X) outside of expected range\r\n",address+i);
return(-1);
}
function_descriptor.flash_data[address-TBLCF_FLASH_START+i]=hex2dec(line+8+i*2);
}
return(0);
} else if ((address>=TBLCF_FLASH_BOOT_START)&&(address<=TBLCF_FLASH_BOOT_END)) {
/* boot sector code */
for (i=0;i<((strlen(line)-8-2)/2);i++) {
if ((address+i)>TBLCF_FLASH_BOOT_END) {
print_screen("S-rec address (0x%04X) outside of expected range\r\n",address+i);
return(-1);
}
function_descriptor.boot_sector_data[address-TBLCF_FLASH_BOOT_START+i]=hex2dec(line+8+i*2);
}
return(0);
}
/* address outside of expected range */
print_screen("S-rec address (0x%04X) outside of expected range\r\n",address);
return(-1);
case '9':
/* S9 - end record */
case '8':
/* S8 - end record */
return(0);
default:
print_screen("Unknown S-rec line: %s \r\n",line);
return(-1);
}
}
/* main S-rec routine which opens the file and reads it line by line */
/* returns 0 on success and !=0 on error */
char s_rec_process(void) {
FILE *input;
char line[MAX_LINE_LENGTH+1];
input=fopen(function_descriptor.s_rec_filename,"r");
if (input==NULL) {
print_screen("Cannot open file \"%s\"\r\n",function_descriptor.s_rec_filename);
return(-1);
}
while (!feof(input)) {
if (fgets(line,MAX_LINE_LENGTH,input)==0) continue; /* ignore blank lines */
if (line[0]=='S') {
if (s_line_process(line)) return(1); /* error while processing the line? */
}
}
fclose(input);
return(0);
}

4
m68k/tblcf/srec.h Normal file
View File

@@ -0,0 +1,4 @@
#define MAX_LINE_LENGTH 500 /* max possible length of S-rec line */
char s_rec_process(void);

70
m68k/tblcf/tblcf-show.c Normal file
View File

@@ -0,0 +1,70 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2008 Chris Johns
Chris Johns (cjohns@user.sourgeforge.net)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "BDMlib.h"
#include "tblcf.h"
#include "tblcf_usb.h"
int
main (int argc, char *argv[])
{
extern char *optarg;
extern int optind, optopt;
int devs;
int i;
int c;
int debug = 0;
char name[128];
printf ("TBLCF Turbo BDM Light ColdFire Show\n\n");
while ((c = getopt(argc, argv, "d:")) != -1)
{
switch (c)
{
case 'd':
debug = strtoul (optarg, 0, 0);
break;
case '?':
fprintf (stderr, "Unrecognized option: -%c\n", optopt);
exit (1);
break;
}
}
bdmSetDebugFlag (debug);
devs = tblcf_init();
printf ("Found %i device(s)\n", devs);
for (i = 0; i < devs; i++)
{
tblcf_usb_dev_name (i, name, sizeof (name));
printf (" %2d: %s\n", i + 1, name);
}
return 0;
}

778
m68k/tblcf/tblcf.c Normal file
View File

@@ -0,0 +1,778 @@
/*
Turbo BDM Light ColdFire - interface DLL
Copyright (C) 2006 Daniel Malik
Changed to support the BDM project.
Chris Johns (cjohns@user.sourgeforge.net)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "log.h"
#include "version.h"
#include "tblcf.h"
#include "tblcf_usb.h"
#include "tblcf_hwdesc.h"
#include "commands.h"
/* define symbol "LOG" during compilation to produce a log file tblcf_dll.log */
static unsigned char usb_data[MAX_DATA_SIZE+2];
/* returns version of the DLL in BCD format */
unsigned char tblcf_version(void) {
return(TBLCF_DLL_VERSION);
}
/* initialises USB and returns number of devices found */
unsigned char tblcf_init(void) {
unsigned char i;
tblcf_usb_init();
tblcf_usb_find_devices(TBLCF_PID); /* look for devices on all USB busses */
i=tblcf_usb_cnt();
tblcf_print("TBDML_INIT: Usb initialised, found %d device(s)\r\n",i);
return(i); /* count the devices found and return the number */
}
/* opens a device with given number name */
/* returns device number on success and -1 on error */
int tblcf_open(const char *device) {
tblcf_print("TBLCF_OPEN: Trying to open device %s\r\n", device);
return(tblcf_usb_open(device));
}
/* closes currently open device */
void tblcf_close(int dev) {
tblcf_print("TBLCF_CLOSE: Trying to close the device\r\n");
tblcf_usb_close(dev);
}
/* gets version of the interface (HW and SW) in BCD format */
unsigned int tblcf_get_version(int dev) {
usb_data[0]=3; /* get 3 bytes */
usb_data[1]=CMD_GET_VER;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_GET_VERSION: Reported cable version (0x%02X) - %02X.%02X (HW.SW)\r\n",
usb_data[0],usb_data[2],usb_data[1]);
return((*((unsigned int *)(usb_data+1)))&0xffff);
}
/* returns status of the last command: 0 on sucess and non-zero on failure */
unsigned char tblcf_get_last_sts_value(int dev) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_GET_LAST_STATUS;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_GET_LAST_STATUS: Reported last command status 0x%02X\r\n",usb_data[0]);
return usb_data[0];
}
/* returns status of the last command: 0 on sucess and non-zero on failure */
unsigned char tblcf_get_last_sts(int dev) {
unsigned char status = tblcf_get_last_sts_value(dev);
if ((status==CMD_FAILED)||(status==CMD_UNKNOWN)) return(1); else return(0);
}
/* requests bootloader execution on next power-up */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_request_boot(int dev) {
usb_data[0]=1; /* return 1 byte */
usb_data[1]=CMD_SET_BOOT;
usb_data[2]='B';
usb_data[3]='O';
usb_data[4]='O';
usb_data[5]='T';
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_REQUEST_BOOT: Requested bootloader on next power-up (0x%02X)\r\n",usb_data[0]);
return(!(usb_data[0]==CMD_SET_BOOT));
}
/* sets target MCU type */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_set_target_type(int dev, target_type_e target_type) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_SET_TARGET;
usb_data[2]=target_type;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_SET_TARGET_TYPE: Set target type 0x%02X (0x%02X)\r\n",usb_data[2],usb_data[0]);
return(!(usb_data[0]==CMD_SET_TARGET));
}
/* resets the target to normal or BDM mode */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_target_reset(int dev, target_mode_e target_mode) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_RESET;
usb_data[2]=target_mode;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_TARGET_RESET: Target reset into mode 0x%02X (0x%02X)\r\n",usb_data[2],usb_data[0]);
return(!(usb_data[0]==CMD_RESET));
}
/* fills user supplied structure with current state of the BDM communication channel */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_bdm_sts(int dev, bdmcf_status_t *bdmcf_status) {
usb_data[0]=3; /* get 3 bytes */
usb_data[1]=CMD_GET_STATUS;
tblcf_usb_recv_ep0(dev, usb_data);
if (usb_data[0]!=CMD_GET_STATUS) return(1);
bdmcf_status->reset_state = ((usb_data[1]*256+usb_data[2])&RSTO_STATE_MASK)?RSTO_INACTIVE:RSTO_ACTIVE;
bdmcf_status->reset_detection =
((usb_data[1]*256+usb_data[2])&RESET_DETECTED_MASK)?RESET_DETECTED:RESET_NOT_DETECTED;
tblcf_print("TBLCF_BDM_STATUS: Reported communication status 0x%04X (0x%02X)\r\n",
(usb_data[1]*256+usb_data[2]),usb_data[0]);
return(0);
}
/* brings the target into BDM mode */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_target_halt(int dev) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_HALT;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_TARGET_HALT: (0x%02X)\r\n",usb_data[0]);
return(!(usb_data[0]==CMD_HALT));
}
/* starts target execution from current PC address */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_target_go(int dev) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_GO;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_TARGET_GO: (0x%02X)\r\n",usb_data[0]);
return(!(usb_data[0]==CMD_GO));
}
/* steps over a single target instruction */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_target_step(int dev) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_STEP;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_TARGET_STEP: (0x%02X)\r\n",usb_data[0]);
return(!(usb_data[0]==CMD_STEP));
}
/* resynchronizes communication with the target (in case of noise, etc.) */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_resynchronize(int dev) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_RESYNCHRONIZE;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_RESYNCHRONIZE: (0x%02X)\r\n",usb_data[0]);
return(!(usb_data[0]==CMD_RESYNCHRONIZE));
}
/* asserts the TA signal for the specified time (in 10us ticks) */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_assert_ta(int dev, unsigned char duration_10us) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_ASSERT_TA;
usb_data[2]=duration_10us;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_ASSERT_TA: duration %d us (0x%02X)\r\n",(int)10*usb_data[2],usb_data[0]);
return(!(usb_data[0]==CMD_ASSERT_TA));
}
/* reads control register at the specified address and writes its contents into the supplied buffer */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_creg(int dev, unsigned int address, unsigned long int * result) {
usb_data[0]=5; /* get 5 bytes */
usb_data[1]=CMD_READ_CREG;
usb_data[2]=(address>>8)&0xff; /* address in big endian */
usb_data[3]=address&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
*result = (((unsigned long int)usb_data[1])<<24)+(usb_data[2]<<16)+(usb_data[3]<<8)+usb_data[4]; /* result is in big endian */
tblcf_print("TBLCF_READ_CREG: Read control register from address 0x%04X, result: 0x%08lX (0x%02X)\r\n",address,*result,usb_data[0]);
return(!(usb_data[0]==CMD_READ_CREG));
}
/* writes control register at the specified address */
void tblcf_write_creg(int dev, unsigned int address, unsigned long int value) {
usb_data[0]=7; /* send 7 bytes */
usb_data[1]=CMD_WRITE_CREG;
usb_data[2]=(address>>8)&0xff; /* address in big endian */
usb_data[3]=address&0xff;
usb_data[4]=(value>>24)&0xff;
usb_data[5]=(value>>16)&0xff;
usb_data[6]=(value>>8)&0xff;
usb_data[7]=(value)&0xff;
tblcf_print("TBLCF_WRITE_CREG: Write control register at address 0x%04X with 0x%08lX\r\n",address,value);
tblcf_usb_send_ep0(dev, usb_data);
}
/* reads the specified debug register and writes its contents into the supplied buffer */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_dreg(int dev, unsigned char dreg_index, unsigned long int * result) {
usb_data[0]=5; /* get 5 bytes */
usb_data[1]=CMD_READ_DREG;
usb_data[2]=dreg_index;
tblcf_usb_recv_ep0(dev, usb_data);
*result = (((unsigned long int)usb_data[1])<<24)+(usb_data[2]<<16)+(usb_data[3]<<8)+usb_data[4]; /* result is in big endian */
tblcf_print("TBLCF_READ_DREG: Read debug register #0x%02X, result: 0x%08lX (0x%02X)\r\n",
dreg_index,*result,usb_data[0]);
return(!(usb_data[0]==CMD_READ_DREG));
}
/* writes specified debug register */
void tblcf_write_dreg(int dev, unsigned char dreg_index, unsigned long int value) {
usb_data[0]=6; /* send 6 bytes */
usb_data[1]=CMD_WRITE_DREG;
usb_data[2]=dreg_index&0xff;
usb_data[3]=(value>>24)&0xff;
usb_data[4]=(value>>16)&0xff;
usb_data[5]=(value>>8)&0xff;
usb_data[6]=(value)&0xff;
tblcf_print("TBLCF_WRITE_DREG: Write debug register #0x%02X with 0x%08lX\r\n",dreg_index,value);
tblcf_usb_send_ep0(dev, usb_data);
}
/* reads the specified register and writes its contents into the supplied buffer */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_reg(int dev, unsigned char reg_index, unsigned long int * result) {
usb_data[0]=5; /* get 5 bytes */
usb_data[1]=CMD_READ_REG;
usb_data[2]=reg_index;
tblcf_usb_recv_ep0(dev, usb_data);
*result = (((unsigned long int)usb_data[1])<<24)+(usb_data[2]<<16)+(usb_data[3]<<8)+usb_data[4]; /* result is in big endian */
tblcf_print("TBLCF_READ_REG: Read register #0x%02X, result: 0x%08lX (0x%02X)\r\n",
reg_index,*result,usb_data[0]);
return(!(usb_data[0]==CMD_READ_REG));
}
/* writes specified register */
void tblcf_write_reg(int dev, unsigned char reg_index, unsigned long int value) {
usb_data[0]=6; /* send 6 bytes */
usb_data[1]=CMD_WRITE_REG;
usb_data[2]=reg_index&0xff;
usb_data[3]=(value>>24)&0xff;
usb_data[4]=(value>>16)&0xff;
usb_data[5]=(value>>8)&0xff;
usb_data[6]=(value)&0xff;
tblcf_print("TBLCF_WRITE_REG: Write register #0x%02X with 0x%08lX\r\n",reg_index,value);
tblcf_usb_send_ep0(dev, usb_data);
}
/* reads byte from the specified address */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_mem8(int dev, unsigned long int address, unsigned char * result) {
usb_data[0]=2; /* get 2 bytes */
usb_data[1]=CMD_READ_MEM8;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
*result = usb_data[1];
tblcf_print("TBLCF_READ_MEM8: Read byte from address 0x%08lX, result: 0x%02X (0x%02X)\r\n",
address,*result,usb_data[0]);
return(!(usb_data[0]==CMD_READ_MEM8));
}
/* reads word from the specified address */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_mem16(int dev, unsigned long int address, unsigned int * result) {
usb_data[0]=3; /* get 3 bytes */
usb_data[1]=CMD_READ_MEM16;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
*result = ((unsigned int)usb_data[1]<<8)+usb_data[2];
tblcf_print("TBLCF_READ_MEM16: Read word from address 0x%08lX, result: 0x%04X (0x%02X)\r\n",
address,*result,usb_data[0]);
return(!(usb_data[0]==CMD_READ_MEM16));
}
/* reads long word from the specified address */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_mem32(int dev, unsigned long int address, unsigned long int * result) {
usb_data[0]=5; /* get 5 bytes */
usb_data[1]=CMD_READ_MEM32;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
*result = (((unsigned long int)usb_data[1])<<24)+(usb_data[2]<<16)+(usb_data[3]<<8)+usb_data[4];
tblcf_print("TBLCF_READ_MEM32: Read long word from address 0x%08lX, result: 0x%08lX (0x%02X)\r\n",address,*result,usb_data[0]);
return(!(usb_data[0]==CMD_READ_MEM32));
}
/* writes byte at the specified address */
void tblcf_write_mem8(int dev, unsigned long int address, unsigned char value) {
usb_data[0]=6; /* send 6 bytes */
usb_data[1]=CMD_WRITE_MEM8;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
usb_data[6]=(value)&0xff;
tblcf_print("TBLCF_WRITE_MEM8: Write byte 0x%02X to address 0x%08lX\r\n",value,address);
tblcf_usb_send_ep0(dev, usb_data);
}
/* writes word at the specified address */
void tblcf_write_mem16(int dev, unsigned long int address, unsigned int value) {
usb_data[0]=7; /* send 7 bytes */
usb_data[1]=CMD_WRITE_MEM16;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
usb_data[6]=(value>>8)&0xff;
usb_data[7]=(value)&0xff;
tblcf_print("TBLCF_WRITE_MEM16: Write word 0x%04X to address 0x%08lX\r\n",value,address);
tblcf_usb_send_ep0(dev, usb_data);
}
/* writes long word at the specified address */
void tblcf_write_mem32(int dev, unsigned long int address, unsigned long int value) {
usb_data[0]=9; /* send 9 bytes */
usb_data[1]=CMD_WRITE_MEM32;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
usb_data[6]=(value>>24)&0xff;
usb_data[7]=(value>>16)&0xff;
usb_data[8]=(value>>8)&0xff;
usb_data[9]=(value)&0xff;
tblcf_print("TBLCF_WRITE_MEM32: Write long word 0x%08lX to address 0x%08lX\r\n",value,address);
tblcf_usb_send_ep0(dev, usb_data);
}
/* reads the requested number of bytes from target memory from the supplied address and stores results into the user supplied buffer */
/* uses byte accesses only */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_block8(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer) {
int i;
tblcf_print("TBLCF_READ_BLOCK8: Read 0x%08lX byte(s) from address 0x%08lX:\r\n",bytecount,address);
while (bytecount>=MAX_DATA_SIZE) {
usb_data[0]=MAX_DATA_SIZE+1; /* receive block of maximum size */
usb_data[1]=CMD_READ_MEMBLOCK8;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_READ_BLOCK8: Block read, size 0x%02X (0x%02X):\r\n",MAX_DATA_SIZE,usb_data[0]);
tblcf_print_dump(usb_data+1, MAX_DATA_SIZE);
if (usb_data[0]!=CMD_READ_MEMBLOCK8) return(1);
for (i=0;i<MAX_DATA_SIZE;i++) *(buffer++)=usb_data[1+i]; /* copy results */
bytecount-=MAX_DATA_SIZE;
address+=MAX_DATA_SIZE;
}
if (bytecount) {
usb_data[0]=bytecount+1;
usb_data[1]=CMD_READ_MEMBLOCK8;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_READ_BLOCK8: Block read, size 0x%02X (0x%02X):\r\n",bytecount,usb_data[0]);
tblcf_print_dump(usb_data+1, bytecount);
if (usb_data[0]!=CMD_READ_MEMBLOCK8) return(1);
for (i=0;i<bytecount;i++) *(buffer++)=usb_data[1+i]; /* copy results */
}
return(0);
}
/* reads the requested number of bytes from target memory from the supplied address and stores results into the user supplied buffer */
/* uses word accesses */
/* if the address is odd a byte read is performed to make it even before performing the word reads */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_block16(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer) {
int i;
tblcf_print("TBLCF_READ_BLOCK16: Read 0x%08lX byte(s) from address 0x%08lX:\r\n",bytecount,address);
if (address&0x01) {
tblcf_print("TBLCF_READ_BLOCK16: Address is odd, performing 1 byte read\r\n");
if (tblcf_read_mem8(dev, address, buffer)) return(1);
bytecount--;
address++;
buffer++;
}
while (bytecount>=(MAX_DATA_SIZE&0xfffe)) {
usb_data[0]=(MAX_DATA_SIZE&0xfffe)+1; /* receive block of maximum size */
usb_data[1]=CMD_READ_MEMBLOCK16;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_READ_BLOCK16: Block read, size 0x%02X (0x%02X):\r\n",MAX_DATA_SIZE&0xfffe,usb_data[0]);
tblcf_print_dump(usb_data+1, MAX_DATA_SIZE&0xfffe);
for (i=0;i<(MAX_DATA_SIZE&0xfffe);i++) *(buffer++)=usb_data[1+i]; /* copy results */
bytecount-=(MAX_DATA_SIZE&0xfffe);
address+=(MAX_DATA_SIZE&0xfffe);
if (usb_data[0]!=CMD_READ_MEMBLOCK16) return(1);
}
if (bytecount) {
usb_data[0]=bytecount+1;
if ((bytecount&0x01)==1) usb_data[0]++; /* increase the number of bytes to return to a whole number of words */
usb_data[1]=CMD_READ_MEMBLOCK16;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_READ_BLOCK16: Block read, size 0x%02X (0x%02X):\r\n",bytecount,usb_data[0]);
tblcf_print_dump(usb_data+1, bytecount);
if (usb_data[0]!=CMD_READ_MEMBLOCK16) return(1);
for (i=0;i<bytecount;i++) *(buffer++)=usb_data[1+i]; /* copy results */
}
return(0);
}
/* reads the requested number of bytes from target memory from the supplied address and stores results into the user supplied buffer */
/* uses long word accesses */
/* if the address is not aligned byte/word reads are performed to align it */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_read_block32(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer) {
int i;
tblcf_print("TBLCF_READ_BLOCK32: Read 0x%08lX byte(s) from address 0x%08lX:\r\n",bytecount,address);
if (address&0x01) {
tblcf_print("TBLCF_READ_BLOCK32: Address is odd, performing 1 byte read\r\n");
if (tblcf_read_mem8(dev, address, buffer)) return(1);
bytecount--;
address++;
buffer++;
}
if (address&0x02) {
tblcf_print("TBLCF_READ_BLOCK32: Address is not aligned, performing 1 word read\r\n");
if (tblcf_read_mem16(dev, address, (unsigned int*) buffer)) return(1);
bytecount-=2;
address+=2;
buffer+=2;
}
while (bytecount>=(MAX_DATA_SIZE&0xfffc)) {
usb_data[0]=(MAX_DATA_SIZE&0xfffc)+1; /* receive block of maximum size */
usb_data[1]=CMD_READ_MEMBLOCK32;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_READ_BLOCK32: Block read, size 0x%02X (0x%02X):\r\n",MAX_DATA_SIZE&0xfffc,usb_data[0]);
tblcf_print_dump(usb_data+1, MAX_DATA_SIZE&0xfffc);
for (i=0;i<(MAX_DATA_SIZE&0xfffc);i++) *(buffer++)=usb_data[1+i]; /* copy results */
bytecount-=(MAX_DATA_SIZE&0xfffc);
address+=(MAX_DATA_SIZE&0xfffc);
if (usb_data[0]!=CMD_READ_MEMBLOCK32) return(1);
}
if (bytecount) {
usb_data[0]=bytecount+1;
usb_data[0]+=((4-(bytecount&0x03))&0x03); /* increase the number of bytes to make it a multiple of 4 */
usb_data[1]=CMD_READ_MEMBLOCK32;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_READ_BLOCK32: Block read, size 0x%02X (0x%02X):\r\n",bytecount,usb_data[0]);
tblcf_print_dump(usb_data+1, bytecount);
if (usb_data[0]!=CMD_READ_MEMBLOCK32) return(1);
for (i=0;i<bytecount;i++) *(buffer++)=usb_data[1+i]; /* copy results */
}
return(0);
}
/* writes the requested number of bytes to target memory from the supplied address */
/* uses byte accesses only */
/* returns 0 on success and non-zero on failure (must be compiled with WRITE_BLOCK_CHECK, otherwise always returns 0) */
unsigned char tblcf_write_block8(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer) {
int i;
tblcf_print("TBLCF_WRITE_BLOCK8: Write 0x%08lX byte(s) to address 0x%08lX:\r\n",bytecount,address);
while (bytecount>=MAX_DATA_SIZE) {
usb_data[0]=MAX_DATA_SIZE+5; /* write block of maximum size */
usb_data[1]=CMD_WRITE_MEMBLOCK8;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
for (i=0;i<MAX_DATA_SIZE;i++) usb_data[6+i]=*(buffer++); /* copy data */
tblcf_print("TBLCF_WRITE_BLOCK8: Block write, size 0x%02X:\r\n",MAX_DATA_SIZE);
tblcf_print_dump(usb_data+6, MAX_DATA_SIZE);
tblcf_usb_send_ep0(dev, usb_data);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
bytecount-=MAX_DATA_SIZE;
address+=MAX_DATA_SIZE;
}
if (bytecount) {
usb_data[0]=bytecount+5;
usb_data[1]=CMD_WRITE_MEMBLOCK8;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
for (i=0;i<bytecount;i++) usb_data[6+i]=*(buffer++); /* copy data */
tblcf_print("TBLCF_WRITE_BLOCK8: Block write, size 0x%02X:\r\n",bytecount);
tblcf_print_dump(usb_data+6, bytecount);
tblcf_usb_send_ep0(dev, usb_data);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
}
return(0);
}
/* writes the requested number of bytes to target memory at the supplied address */
/* uses word accesses */
/* if the address is odd a byte write is performed to make it even before performing the word writes */
/* if there is an odd byte at the end of the block it is written using a byte write */
/* returns 0 on success and non-zero on failure (must be compiled with WRITE_BLOCK_CHECK, otherwise always returns 0) */
unsigned char tblcf_write_block16(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer) {
int i;
tblcf_print("TBLCF_WRITE_BLOCK16: Write 0x%08lX byte(s) from address 0x%08lX:\r\n",bytecount,address);
if (address&0x01) {
tblcf_print("TBLCF_WRITE_BLOCK16: Address is odd, performing 1 byte write\r\n");
tblcf_write_mem8(dev, address, *buffer);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
bytecount--;
address++;
buffer++;
}
while (bytecount>=(MAX_DATA_SIZE&0xfffe)) {
usb_data[0]=(MAX_DATA_SIZE&0xfffe)+5; /* send block of maximum size */
usb_data[1]=CMD_WRITE_MEMBLOCK16;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
for (i=0;i<(MAX_DATA_SIZE&0xfffe);i++) usb_data[6+i]=*(buffer++); /* copy data */
tblcf_print("TBLCF_WRITE_BLOCK16: Block write, size 0x%02X:\r\n",MAX_DATA_SIZE&0xfffe);
tblcf_print_dump(usb_data+6, MAX_DATA_SIZE&0xfffe);
tblcf_usb_send_ep0(dev, usb_data);
bytecount-=(MAX_DATA_SIZE&0xfffe);
address+=(MAX_DATA_SIZE&0xfffe);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
}
if (bytecount>=2) {
usb_data[0]=bytecount+5;
if ((bytecount&0x01)==1) usb_data[0]--; /* decrease the number of bytes to write a whole number of words */
usb_data[1]=CMD_WRITE_MEMBLOCK16;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
for (i=0;i<(bytecount&0xfffe);i++) usb_data[6+i]=*(buffer++); /* copy data */
tblcf_print("TBLCF_WRITE_BLOCK16: Block write, size 0x%02X:\r\n",(bytecount&0xfffe));
tblcf_print_dump(usb_data+6, (bytecount&0xfffe));
tblcf_usb_send_ep0(dev, usb_data);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
address+=(bytecount&0xfffe);
bytecount&=0x01;
}
if (bytecount) { /* leftover byte */
tblcf_print("TBLCF_WRITE_BLOCK16: Misaligned byte at the end of the block, performing 1 byte write\r\n");
tblcf_write_mem8(dev, address, *buffer);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
}
return(0);
}
/* writes the requested number of bytes to target memory at the supplied address */
/* uses long word accesses */
/* if the address is not aligned byte/word writes are performed */
/* if there are odd bytes at the end of the block they is written using byte/word writes */
/* returns 0 on success and non-zero on failure (must be compiled with WRITE_BLOCK_CHECK, otherwise always returns 0) */
unsigned char tblcf_write_block32(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer) {
int i;
tblcf_print("TBLCF_WRITE_BLOCK32: Write 0x%08lX byte(s) at address 0x%08lX:\r\n",bytecount,address);
if (address&0x01) {
tblcf_print("TBLCF_WRITE_BLOCK32: Address is odd, performing 1 byte write\r\n");
tblcf_write_mem8(dev, address, *buffer);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
bytecount--;
address++;
buffer++;
}
if (address&0x02) {
tblcf_print("TBLCF_WRITE_BLOCK32: Address is not aligned, performing 1 word write\r\n");
tblcf_write_mem16(dev, address, (*(buffer+0))*256+*(buffer+1));
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
bytecount-=2;
address+=2;
buffer+=2;
}
while (bytecount>=(MAX_DATA_SIZE&0xfffc)) {
usb_data[0]=(MAX_DATA_SIZE&0xfffc)+5; /* send block of maximum size */
usb_data[1]=CMD_WRITE_MEMBLOCK32;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
for (i=0;i<(MAX_DATA_SIZE&0xfffc);i++) usb_data[6+i]=*(buffer++); /* copy data */
tblcf_print("TBLCF_WRITE_BLOCK32: Block write, size 0x%02X:\r\n",MAX_DATA_SIZE&0xfffc);
tblcf_print_dump(usb_data+6, MAX_DATA_SIZE&0xfffc);
tblcf_usb_send_ep0(dev, usb_data);
bytecount-=(MAX_DATA_SIZE&0xfffc);
address+=(MAX_DATA_SIZE&0xfffc);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
}
if (bytecount>=4) {
usb_data[0]=bytecount+5;
usb_data[0]-=(bytecount&0x03); /* decrease the number of bytes to write a whole number of long words */
usb_data[1]=CMD_WRITE_MEMBLOCK32;
usb_data[2]=(address>>24)&0xff;
usb_data[3]=(address>>16)&0xff;
usb_data[4]=(address>>8)&0xff;
usb_data[5]=(address)&0xff;
for (i=0;i<(bytecount&0xfffc);i++) usb_data[6+i]=*(buffer++); /* copy data */
tblcf_print("TBLCF_WRITE_BLOCK32: Block write, size 0x%02X:\r\n",(bytecount&0xfffc));
tblcf_print_dump(usb_data+6, (bytecount&0xfffc));
tblcf_usb_send_ep0(dev, usb_data);
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
address+=(bytecount&0xfffc);
bytecount&=0x03;
}
if (bytecount>=2) { /* leftover word */
tblcf_print("TBLCF_WRITE_BLOCK32: Misaligned word at the end of the block, performing 1 word write\r\n");
tblcf_write_mem16(dev, address, (*(buffer+0))*256+*(buffer+1));
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
address+=2;
bytecount-=2;
buffer+=2;
}
if (bytecount) { /* leftover byte */
tblcf_print("TBLCF_WRITE_BLOCK32: Misaligned byte at the end of the block, performing 1 byte write\r\n");
tblcf_write_mem8(dev, address, *(buffer));
#ifdef WRITE_BLOCK_CHECK
if (tblcf_get_last_sts(dev)) return(1);
#endif
}
return(0);
}
/* JTAG - go from RUN-TEST/IDLE to SHIFT-DR or SHIFT-IR state */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_jtag_sel_shift(int dev, unsigned char mode) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_JTAG_GOTOSHIFT;
usb_data[2]=mode;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_JTAG_SEL_SHIFT: SHIFT-%cR\r\n",mode?'I':'D');
return(!(usb_data[0]==CMD_JTAG_GOTOSHIFT));
}
/* JTAG - go from RUN-TEST/IDLE to TEST-LOGIC-RESET state */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_jtag_sel_reset(int dev) {
usb_data[0]=1; /* get 1 byte */
usb_data[1]=CMD_JTAG_GOTORESET;
tblcf_usb_recv_ep0(dev, usb_data);
tblcf_print("TBLCF_JTAG_SEL_RESET\r\n");
return(!(usb_data[0]==CMD_JTAG_GOTORESET));
}
/* JTAG - write data */
/* parameter exit: ==0 : stay in SHIFT-xx, !=0 : go to RUN-TEST/IDLE when done */
/* data: shifted in LSB (last byte) first, unused bits (if any) are in the MSB (first) byte */
void tblcf_jtag_write(int dev, unsigned char bit_count, unsigned char exit, unsigned char *buffer) {
int i;
usb_data[0]=(bit_count>>3)+((bit_count&0x07)!=0)+3; /* send all data bits & 3 more bytes */
usb_data[1]=CMD_JTAG_WRITE;
usb_data[2]=exit;
usb_data[3]=bit_count;
for (i=0;i<((bit_count>>3)+1);i++) usb_data[4+i]=*(buffer+i); /* copy data */
tblcf_usb_send_ep0(dev, usb_data);
tblcf_print("TBLCF_JTAG_WRITE: %d bits (%sexit to RUN-TEST/IDLE)\r\n",bit_count,exit?"":"NO ");
tblcf_print_dump(usb_data+4,(bit_count>>3)+((bit_count&0x07)!=0));
}
/* JTAG - read data */
/* parameter exit: ==0 : stay in SHIFT-xx, !=0 : go to RUN-TEST/IDLE when done */
/* data: shifted in LSB (last byte) first, unused bits (if any) are in the MSB (first) byte */
/* returns 0 on success and non-zero on failure */
unsigned char tblcf_jtag_read(int dev, unsigned char bit_count, unsigned char exit, unsigned char *buffer) {
int i;
usb_data[0]=(bit_count>>3)+((bit_count&0x07)!=0)+1; /* get all data bits & the status byte */
usb_data[1]=CMD_JTAG_READ;
usb_data[2]=exit;
usb_data[3]=bit_count;
tblcf_usb_recv_ep0(dev, usb_data);
for (i=0;i<((bit_count>>3)+((bit_count&0x07)!=0));i++) *(buffer+i)=usb_data[1+i]; /* copy data */
tblcf_print("TBLCF_JTAG_READ: %d bits (%sexit to RUN-TEST/IDLE)\r\n",bit_count,exit?"":"NO ");
tblcf_print_dump(usb_data+1,(bit_count>>3)+((bit_count&0x07)!=0));
return(!(usb_data[0]==CMD_JTAG_READ));
}
#if 0
BOOL LibMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved) {
char path[MAX_PATH];
char *charp;
time_t time_now;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
tblcf_usb_init(); /* initialise USB */
#ifdef LOG
GetModuleFileName(NULL,path,sizeof(path));
charp=strchr(path,'\\');
if (charp!=NULL) {
while (strchr(charp+1,'\\')) charp=strchr(charp+1,'\\'); /* find the last backslash */
strcpy(charp+1,"tblcf_dll.log");
log_file=fopen(path,"wb");
}
tblcf_print("Log file path: %s\r\n",path);
tblcf_print("Turbo BDM Light DLL v%1d.%1d. Compiled on %s, %s.\r\n",
TBLCF_DLL_VERSION/16,TBLCF_DLL_VERSION&0x0f,__DATE__,__TIME__);
time(&time_now);
tblcf_print("Log file created on: %s\r", ctime(&time_now));
#endif
break;
case DLL_PROCESS_DETACH:
#ifdef LOG
time(&time_now);
tblcf_print("End of log file: %s\r", ctime(&time_now));
fclose(log_file);
#endif
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
#endif

210
m68k/tblcf/tblcf.h Normal file
View File

@@ -0,0 +1,210 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
Changed to support the BDM project.
Chris Johns (cjohns@user.sourgeforge.net)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TBLCF_H
#define TBLCF_H
#define WRITE_BLOCK_CHECK /* Keep on. CCJ */
typedef enum { /* type of BDM target */
CF_BDM=0,
JTAG=1
} target_type_e;
typedef enum { /* type of reset action required */
BDM_MODE=0,
NORMAL_MODE=1
} target_mode_e;
typedef enum { /* target reset detection state */
RESET_NOT_DETECTED=0,
RESET_DETECTED=1
} reset_detection_e;
typedef enum { /* target reset state */
RSTO_ACTIVE=0,
RSTO_INACTIVE=1
} reset_state_e;
typedef struct { /* state of BDM communication */
reset_state_e reset_state;
reset_detection_e reset_detection;
} bdmcf_status_t;
/* returns version of the DLL in BCD format */
unsigned char tblcf_version(void);
/* initialises USB and returns number of devices found */
unsigned char tblcf_init(void);
/* opens a device with given number (0...), returns 0 on success and 1 on error */
int tblcf_open(const char *device);
/* closes currently open device */
void tblcf_close(int dev);
/* returns hardware & software version of the cable in BCD format - SW version
* in lower byte and HW version in upper byte */
unsigned int tblcf_get_version(int dev);
/* returns status of the last command: 0 on sucess and non-zero on failure */
unsigned char tblcf_get_last_sts(int dev);
/* returns status of the last command value */
unsigned char tblcf_get_last_sts_value(int dev);
/* requests bootloader execution on new power-up, returns 0 on success and
* non-zero on failure */
unsigned char tblcf_request_boot(int dev);
/* sets target MCU type; returns 0 on success and non-zero on failure */
unsigned char tblcf_set_target_type(int dev, target_type_e target_type);
/* resets the target to normal or BDM mode; returns 0 on success and non-zero
* on failure */
unsigned char tblcf_target_reset(int dev, target_mode_e target_mode);
/* fills user supplied structure with current state of the BDM communication
* channel; returns 0 on success and non-zero on failure */
unsigned char tblcf_bdm_sts(int dev, bdmcf_status_t *bdmcf_status);
/* brings the target into BDM mode; returns 0 on success and non-zero on
* failure */
unsigned char tblcf_target_halt(int dev);
/* starts target execution from current PC address; returns 0 on success and
* non-zero on failure */
unsigned char tblcf_target_go(int dev);
/* steps over a single target instruction; returns 0 on success and non-zero on
* failure */
unsigned char tblcf_target_step(int dev);
/* resynchronizes communication with the target (in case of noise, etc.);
* returns 0 on success and non-zero on failure */
unsigned char tblcf_resynchronize(int dev);
/* asserts the TA signal for the specified time (in 10us ticks); returns 0 on
* success and non-zero on failure */
unsigned char tblcf_assert_ta(int dev, unsigned char duration_10us);
/* reads control register at the specified address and writes its contents into
* the supplied buffer; returns 0 on success and non-zero on failure */
unsigned char tblcf_read_creg(int dev, unsigned int address, unsigned long int * result);
/* writes control register at the specified address; returns 0 on success and
* non-zero on failure */
void tblcf_write_creg(int dev, unsigned int address, unsigned long int value);
/* reads the specified debug register and writes its contents into the
* supplied buffer; returns 0 on success and non-zero on failure */
unsigned char tblcf_read_dreg(int dev, unsigned char dreg_index, unsigned long int * result);
/* writes specified debug register */
void tblcf_write_dreg(int dev, unsigned char dreg_index, unsigned long int value);
/* reads the specified register and writes its contents into the supplied
* buffer; returns 0 on success and non-zero on failure */
unsigned char tblcf_read_reg(int dev, unsigned char reg_index, unsigned long int * result);
/* writes specified register */
void tblcf_write_reg(int dev, unsigned char reg_index, unsigned long int value);
/* reads byte from the specified address; returns 0 on success and non-zero on
* failure */
unsigned char tblcf_read_mem8(int dev, unsigned long int address, unsigned char * result);
/* reads word from the specified address; returns 0 on success and non-zero on
* failure */
unsigned char tblcf_read_mem16(int dev, unsigned long int address, unsigned int * result);
/* reads long word from the specified address; returns 0 on success and
* non-zero on failure */
unsigned char tblcf_read_mem32(int dev, unsigned long int address, unsigned long int * result);
/* writes byte at the specified address */
void tblcf_write_mem8(int dev, unsigned long int address, unsigned char value);
/* writes word at the specified address */
void tblcf_write_mem16(int dev, unsigned long int address, unsigned int value);
/* writes long word at the specified address */
void tblcf_write_mem32(int dev, unsigned long int address, unsigned long int value);
/* reads the requested number of bytes from target memory from the supplied
* address and stores results into the user supplied buffer; uses byte accesses
* only; returns 0 on success and non-zero on failure */
unsigned char tblcf_read_block8(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer);
/* reads the requested number of bytes from target memory from the supplied
* address and stores results into the user supplied buffer; uses word
* accesses; returns 0 on success and non-zero on failure */
unsigned char tblcf_read_block16(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer);
/* reads the requested number of bytes from target memory from the supplied
* address and stores results into the user supplied buffer; uses long word
* accesses; returns 0 on success and non-zero on failure */
unsigned char tblcf_read_block32(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer);
/* writes the requested number of bytes to target memory from the supplied
* address; uses byte accesses only; returns 0 on success and non-zero on
* failure (must be compiled with WRITE_BLOCK_CHECK, otherwise always returns
* 0) */
unsigned char tblcf_write_block8(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer);
/* writes the requested number of bytes to target memory at the supplied
* address; uses word accesses; returns 0 on success and non-zero on failure
* (must be compiled with WRITE_BLOCK_CHECK, otherwise always returns 0) */
unsigned char tblcf_write_block16(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer);
/* writes the requested number of bytes to target memory at the supplied
* address; uses long word accesses; returns 0 on success and non-zero on
* failure (must be compiled with WRITE_BLOCK_CHECK, otherwise always returns
* 0) */
unsigned char tblcf_write_block32(int dev, unsigned long int address,
unsigned long int bytecount, unsigned char *buffer);
/* JTAG - go from RUN-TEST/IDLE to SHIFT-DR (mode==0) or SHIFT-IR (mode!=0)
* state */
unsigned char tblcf_jtag_sel_shift(int dev, unsigned char mode);
/* JTAG - go from RUN-TEST/IDLE to TEST-LOGIC-RESET state */
unsigned char tblcf_jtag_sel_reset(int dev);
/* JTAG - write data; parameter exit: ==0 : stay in SHIFT-xx, !=0 : go to
* RUN-TEST/IDLE when done; data: shifted in LSB (last byte) first, unused bits
* (if any) are in the MSB (first) byte */
void tblcf_jtag_write(int dev, unsigned char bit_count,
unsigned char exit, unsigned char *buffer);
/* JTAG - read data; parameter exit: ==0 : stay in SHIFT-xx, !=0 : go to
* RUN-TEST/IDLE when done; data: shifted in LSB (last byte) first, unused bits
* (if any) are in the MSB (first) byte */
unsigned char tblcf_jtag_read(int dev, unsigned char bit_count,
unsigned char exit, unsigned char *buffer);
#endif

288
m68k/tblcf/tblcf_bt.c Normal file
View File

@@ -0,0 +1,288 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include "tblcf_hwdesc.h"
#include "tblcf_usb.h"
#include "version.h"
#include "tblcf_bt.h"
#include "log_cmdline.h"
#include "srec.h"
#include "commands.h"
/*
Changes:
1.0 Initial coding
*/
function_descriptor_t function_descriptor; /* this structure describes what the program should do */
/* returns number of parameters or a negative number in case of error */
char handleoptions(int argc,char *argv[]) {
int i,notoption=0;
for (i=1; i< argc;i++) {
if (argv[i][0] == '/' || argv[i][0] == '-') {
switch (argv[i][1]) {
case 'b':
case 'B':
/* replace boot sector */
function_descriptor.replace_boot=1;
break;
case 'd':
case 'D':
/* USB device number */
{
strcpy (function_descriptor.device_name, argv[i]+2);
print_screen("Device #: %s\n",function_descriptor.device_name);
break;
}
case 'U':
case 'u':
/* request firmware upgrade */
function_descriptor.request_upgrade=1;
break;
case 'l':
case 'L':
/* -l<log file> */
open_log(argv[i]+2);
break;
default:
print_screen("Unknown option %s\n",argv[i]);
return(-1);
}
} else {
if (notoption==0) { /* the first parameter which is not an option is the S-record file */
strncpy(function_descriptor.s_rec_filename,argv[i],MAX_PATH);
}
if (notoption>=1) {
print_screen("Too many parameters!\n");
}
notoption++;
}
}
return(notoption);
}
void usage(void) {
print_screen("\nUsage:\n\nTBLCF_BT <S-record file> [<options>]\n\n");
print_screen("Options:\n\n");
print_screen("-B\t\tReplace BOOT sector\n");
print_screen("-D<n>\t\tSpecify which USB device to work with\n");
print_screen("-L<log file>\tWrite messages into a log file\n");
print_screen("-U\t\tRequest Firmware upgrade\n");
print_screen("\n");
}
int main(int argc, char *argv[]) {
int i;
unsigned int start,end; /* indexes into the array delimiting block of data to be programmed into flash */
print_screen("Turbo BDM Light ColdFire Bootloader ver %01X.%01X. Compiled on %s, %s.\n",TBLCF_BOOTLOADER_VERSION>>4,TBLCF_BOOTLOADER_VERSION&0x0f,__DATE__,__TIME__);
/* initialise function_descriptor */
function_descriptor.replace_boot=0;
function_descriptor.device_no=0;
function_descriptor.request_upgrade=0;
for (i=0;i<sizeof(function_descriptor.boot_sector_data);i++) function_descriptor.boot_sector_data[i]=0xff;
for (i=0;i<sizeof(function_descriptor.flash_data);i++) function_descriptor.flash_data[i]=0xff;
/* now handle user supplied options */
i=handleoptions(argc,argv);
if ((i != 1)&&(function_descriptor.request_upgrade==0)) { /* number of parameters is incorrect */
print_screen("Number of parameters incorrect or other error\n");
usage();
return(1);
}
tblcf_usb_init();
/* request firmware upgrade on next power up (if required by the user) */
if (function_descriptor.request_upgrade) {
unsigned char data[6];
tblcf_usb_find_devices(TBLCF_PID);
print_screen("found %d Turbo BDM Light ColdFire device(s)\n",i=tblcf_usb_cnt());
if (function_descriptor.device_no>=i) {
print_screen("Not enough devices connected to work with device #%d\n",
function_descriptor.device_no);
return(1);
}
function_descriptor.device_no = tblcf_usb_open(function_descriptor.device_name);
/* request bootloader action op next power-up */
data[0]=1; /* return 1 byte */
data[1]=CMD_SET_BOOT;
data[2]='B';
data[3]='O';
data[4]='O';
data[5]='T';
i=tblcf_usb_recv_ep0(function_descriptor.device_no, data);
tblcf_usb_close(function_descriptor.device_no);
if ((i)||(data[0]!=CMD_SET_BOOT)) {
print_screen("USB communication problem or CMD_SET_BOOT command failure\n");
return(1);
}
print_screen("HC08JB16 ICP will execute on next power-up. Disconnect and reconnect the device.\n");
return(0);
}
if (s_rec_process()) return(1); /* process the S-record file, exit in case of error */
/* now open communication with the device */
tblcf_usb_find_devices(JB16ICP_PID);
print_screen("found %d HC08JB16 ICP device(s)\n",i=tblcf_usb_cnt());
if (function_descriptor.device_no>=i) {
print_screen("Not enough devices connected to work with device #%d\n",
function_descriptor.device_no);
return(1);
}
function_descriptor.device_no = tblcf_usb_open(function_descriptor.device_name);
/* boot sector reprogramming (if requested by user) */
i=icp_verify(function_descriptor.device_no,
function_descriptor.boot_sector_data,
TBLCF_FLASH_BOOT_START, TBLCF_FLASH_BOOT_END-TBLCF_FLASH_BOOT_START+1);
if (i<0) {
print_screen("USB communication problem\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
if (function_descriptor.replace_boot) {
/* user wants to overwrite the boot sector, first check, whether it is really needed */
if (i) {
print_screen("Boot sector contents different, performing mass erase\n");
/* erase flash of the device */
i=icp_mass_erase(function_descriptor.device_no);
if (i) {
print_screen("USB communication problem or mass erase failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
print_screen("Mass erase done, programming boot sector\n");
/* program the boot sector contents */
i=icp_program(function_descriptor.device_no,
function_descriptor.boot_sector_data,
TBLCF_FLASH_BOOT_START, TBLCF_FLASH_BOOT_END-TBLCF_FLASH_BOOT_START+1);
if (i) {
print_screen("USB communication problem or programming failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
print_screen("Programming done, verifying boot sector\n");
/* verify that the contents is now correct */
i=icp_verify(function_descriptor.device_no,
function_descriptor.boot_sector_data,
TBLCF_FLASH_BOOT_START, TBLCF_FLASH_BOOT_END-TBLCF_FLASH_BOOT_START+1);
if (i) {
print_screen("USB communication problem or verification failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
print_screen("Verification done, boot sector OK. You can start breathing again.\n");
} else {
print_screen("Boot sector contents identical, -B option ignored\n");
}
} else {
/* user does not want to reprogram the boot sector */
if (i) {
print_screen("Boot sector contents differs from S-record, update required\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
}
/* flash programming */
for (i=TBLCF_FLASH_START;i<TBLCF_FLASH_END;i+=ICP_FLASH_BLOCK_SIZE) {
/* erase all flash blocks one by one */
print_screen("Erasing block at address: 0x%04X\r",i);
if (icp_block_erase(function_descriptor.device_no, i)) {
print_screen("\nUSB communication problem or block erase failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
}
print_screen("\n");
/* set the boot_state variable to erased state (0xFF 0xFF) before programming */
function_descriptor.flash_data[TBLCF_BOOT_STATE-TBLCF_FLASH_START]=TBLCF_BOOT_STATE_BLANK>>8;
function_descriptor.flash_data[TBLCF_BOOT_STATE-TBLCF_FLASH_START+1]=TBLCF_BOOT_STATE_BLANK&&0xff;
/* now do the actual programming */
/* the algorithm below will split the flash into several sections if there is at least 8 unprogrammed bytes beetwen two sections */
/* for TBLCF firmware there will typically be only 2 sections: code of the application at the beginning of flash and secondary vectors at the end */
end=TBLCF_FLASH_START;
while (1) {
/* look for first byte in non-erased state */
start=end;
while ((function_descriptor.flash_data[start-TBLCF_FLASH_START]==0xff) &&
(start<=TBLCF_FLASH_END)) start++; /* find first byte != 0xff */
if (start>TBLCF_FLASH_END) break; /* end of array */
/* now look for block of 8 bytes in erased state */
end=start;
do {
while ((function_descriptor.flash_data[end-TBLCF_FLASH_START]!=0xff) &&
(end<TBLCF_FLASH_END)) end++; /* find first byte == 0xff */
if (end<TBLCF_FLASH_END) {
i=1;
while ((function_descriptor.flash_data[end+i-TBLCF_FLASH_START]==0xff) &&
((end+i)<TBLCF_FLASH_END)&&(i<8)) i++; /* keep going for 7 more bytes (max) */
if (i<8) end+=i;
}
} while ((i<8)&&(end<TBLCF_FLASH_END));
if (end<TBLCF_FLASH_END) end--; /* go back 1 byte (it is blank anyway) */
/* program the block */
print_screen("Programming block from 0x%04X to 0x%04X\n",start,end);
i=icp_program(function_descriptor.device_no,
function_descriptor.flash_data+(start-TBLCF_FLASH_START),
start, end-start+1);
if (i) {
print_screen("USB communication problem or programming failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
/* verify the block */
print_screen("Verifying block from 0x%04X to 0x%04X ",start,end);
i=icp_verify(function_descriptor.device_no,
function_descriptor.flash_data+(start-TBLCF_FLASH_START),
start, end-start+1);
if (i) {
print_screen("\nUSB communication problem or verification failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
print_screen("- OK\n",start,end);
end++; /* increment end again */
}
/* all flash programmed and verified, program the boot_state to 0xFF 0x01 to enable the application */
print_screen("All flash programmed and verified, enabling the application\n");
function_descriptor.flash_data[TBLCF_BOOT_STATE-TBLCF_FLASH_START]=TBLCF_BOOT_STATE_APPLOK>>8;
function_descriptor.flash_data[TBLCF_BOOT_STATE-TBLCF_FLASH_START+1]=TBLCF_BOOT_STATE_APPLOK&&0xff;
i=icp_program(function_descriptor.device_no,
function_descriptor.flash_data+(TBLCF_BOOT_STATE-TBLCF_FLASH_START),
TBLCF_BOOT_STATE, 2); /* bootloader_state is 2 bytes long */
if (i) {
print_screen("USB communication problem or programming failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
/* now verify that the bootloader state is programmed correctly */
i=icp_verify(function_descriptor.device_no,
function_descriptor.flash_data+(TBLCF_BOOT_STATE-TBLCF_FLASH_START),
TBLCF_BOOT_STATE, 2);
if (i) {
print_screen("USB communication problem or bootloader state verification failure\n");
tblcf_usb_close(function_descriptor.device_no);
return(1);
}
print_screen("Flash programming complete, disconnect & reconnect the device\n");
tblcf_usb_close(function_descriptor.device_no);
return(0);
}

47
m68k/tblcf/tblcf_bt.h Normal file
View File

@@ -0,0 +1,47 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
Changed to support the BDM project.
Chris Johns (cjohns@user.sourgeforge.net)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TBLCF_BT_H
#define TBLCF_BT_H
#ifndef MAX_PATH
#define MAX_PATH 512
#endif
typedef struct {
/* filename of the S-record file */
char s_rec_filename[MAX_PATH];
/* 0=do not replace boot secotr, 1= mass erase part and replace the boot
* secotor */
char replace_boot;
/* data to be programmed into the boot sector */
unsigned char boot_sector_data[TBLCF_FLASH_BOOT_END-TBLCF_FLASH_BOOT_START+1];
/* data to be programmed into the application flash */
unsigned char flash_data[TBLCF_FLASH_END-TBLCF_FLASH_START+1];
char device_name[128];
unsigned char device_no;
char request_upgrade;
} function_descriptor_t;
extern function_descriptor_t function_descriptor;
#endif

18
m68k/tblcf/tblcf_hwdesc.h Normal file
View File

@@ -0,0 +1,18 @@
/* this file specifies propierties according to which the hardware can be identified */
#define TBLCF_PID 0x1001
#define JB16ICP_PID 0xFF02
#define TBLCF_VID 0x0425
#define TIMEOUT 1000 /* ussual timeout for device operations */
/* addresses of parts of flash for bootloader operation */
#define TBLCF_FLASH_BOOT_START 0xFFD0
#define TBLCF_FLASH_BOOT_END 0xFFFF
#define TBLCF_FLASH_START 0xBA00
#define TBLCF_FLASH_END 0xF9FF
#define TBLCF_BOOT_STATE 0xF9CE /* address of 2 byte bootloader state */
#define TBLCF_BOOT_STATE_BLANK 0xFFFF /* value to be initially programmed in */
#define TBLCF_BOOT_STATE_APPLOK 0xFF01 /* value to be programmed in after flash contents has been verified */

131
m68k/tblcf/tblcf_unsec.c Normal file
View File

@@ -0,0 +1,131 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "version.h"
#include "log_cmdline.h"
#include "tblcf.h"
char device_name[128];
int device_no=0;
unsigned char unsec_instr[4];
unsigned int unsec_instruction_len;
unsigned char flash_clock_divisor;
/* returns number of parameters or a negative number in case of error */
char handleoptions(int argc,char *argv[]) {
int i,notoption=0;
for (i=1; i< argc;i++) {
if (argv[i][0] == '/' || argv[i][0] == '-') {
switch (argv[i][1]) {
case 'd':
case 'D':
/* USB device number */
{
strcpy (device_name, argv[i]+2);
print_screen("Device #: %s\n",device_name);
break;
}
case 'l':
case 'L':
/* -l<log file> */
open_log(argv[i]+2);
break;
default:
print_screen("Unknown option %s\n",argv[i]);
return(-1);
}
} else {
if (notoption==0) {
unsigned long int unsec_instruction;
sscanf(argv[i],"%lX",&unsec_instruction);
print_screen("Unsecure instruction: 0x%lX\n",unsec_instruction);
unsec_instr[0]=unsec_instruction&0xff;
unsec_instr[1]=(unsec_instruction>>8)&0xff;
unsec_instr[2]=(unsec_instruction>>16)&0xff;
unsec_instr[3]=(unsec_instruction>>24)&0xff;
} else if (notoption==1) {
sscanf(argv[i],"%d",&unsec_instruction_len);
print_screen("Instruction length: %d\n",unsec_instruction_len);
} else if (notoption==2) {
unsigned int flash_clock_div;
sscanf(argv[i],"%X",&flash_clock_div);
flash_clock_divisor = flash_clock_div&0xff;
print_screen("Flash clock divisor: 0x%X\n",flash_clock_divisor);
} else {
print_screen("Too many parameters!\n");
}
notoption++;
}
}
return(notoption);
}
void usage(void) {
print_screen("\nUsage:\n\nTBLCF_UNSEC [<options>] <LR_INSTR> <LEN> <CLKDIV>\n\n");
print_screen("<LR_INSTR>\tLOCKOUT_RECOVERY JTAG instruction in hexadecimal\n");
print_screen("<LEN>\t\tLength of the unsecure instruction in decimal\n");
print_screen("<CLKDIV>\tFlash clock divisor in hexadecimal\n\n");
print_screen("Options:\n\n");
print_screen("-D<n>\t\tSpecify which USB device to work with\n");
print_screen("-L<log file>\tWrite messages into a log file\n\n");
}
int main(int argc, char *argv[]) {
int i;
unsigned char idcode[4]={0,0,0,1}; /* IDCODE instruction */
unsigned char part_id[4];
print_screen("Turbo BDM Light ColdFire Unsecure Utility ver %01X.%01X.\nCompiled on %s, %s.\n",TBLCF_UNSEC_VERSION>>4,TBLCF_UNSEC_VERSION&0x0f,__DATE__,__TIME__);
print_screen("TBLCF DLL version: %02X\n",tblcf_version());
/* handle user supplied options */
i=handleoptions(argc,argv);
if (i != 3) { /* number of parameters is incorrect */
print_screen("Number of parameters incorrect\n");
usage();
return(1);
}
print_screen("found %d Turbo BDM Light ColdFire device(s)\n",i=tblcf_init());
if (device_no>=i) {
print_screen("Not enough devices connected to work with device #%d\n",device_no);
return(1);
}
device_no = tblcf_open(device_name);
tblcf_set_target_type(device_no, JTAG); /* select JTAG target */
tblcf_jtag_sel_shift(device_no, 1); /* select instruction path */
tblcf_jtag_write(device_no,
unsec_instruction_len,1,idcode+4-((unsec_instruction_len-1)>>3)); /* shift the IDCODE instruction in */
tblcf_jtag_sel_shift(device_no, 0); /* select data path */
tblcf_jtag_read(device_no, 32,1,part_id); /* get the ID */
printf("Part ID: %02X%02X%02X%02X\n",part_id[0],part_id[1],part_id[2],part_id[3]);
tblcf_jtag_sel_shift(device_no, 1); /* select instruction path */
tblcf_jtag_write(device_no, unsec_instruction_len,1,unsec_instr); /* shift the LOCKOUT_RECOVERY instruction in */
tblcf_jtag_sel_shift(device_no, 0); /* select data path */
tblcf_jtag_write(device_no, 7,1,&flash_clock_divisor); /* shift the flash clk div in */
tblcf_jtag_sel_reset(device_no); /* go to TEST-LOGIC-RESET */
usleep(300 * 1000); /* wait to make sure the flash is mass erased before exiting */
tblcf_close(device_no);
printf("Done.\n");
return(0);
}

458
m68k/tblcf/tblcf_usb.c Normal file
View File

@@ -0,0 +1,458 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
Changed to support the BDM project.
Chris Johns (cjohns@user.sourgeforge.net)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "log.h"
#include "tblcf_usb.h"
#include "tblcf_hwdesc.h"
#include "usb.h"
/*
* Manage the USB devices we have connected.
*/
typedef struct tblcf_usb_dev_s {
struct usb_bus *bus;
struct usb_device *device;
usb_dev_handle *handle;
char *name;
} tblcf_usb_dev;
/*
* The lits of devices.
*/
static tblcf_usb_dev *usb_devs;
static int usb_dev_count;
/* provides low level USB functions which talk to the hardware */
/* initialisation */
void tblcf_usb_init(void) {
usb_init(); /* init LIBUSB */
usb_set_debug(0); /* set debug level to minimum */
}
/* find all TBLCF devices attached to the computer */
void tblcf_usb_find_devices(unsigned short int product_id) {
struct usb_bus *libusb_bus;
struct usb_device *libusb_dev;
if (usb_devs) return;
usb_dev_count = 0;
usb_find_busses(); /* enumerate all busses */
usb_find_devices(); /* enumerate all devices */
/* scan through all busses then devices counting the number found */
for (libusb_bus = usb_get_busses(); libusb_bus; libusb_bus = libusb_bus->next) {
/* scan through all devices */
for (libusb_dev = libusb_bus->devices; libusb_dev; libusb_dev = libusb_dev->next) {
if ((libusb_dev->descriptor.idVendor==TBLCF_VID) &&
(libusb_dev->descriptor.idProduct==product_id)) {
/* found a device */
usb_dev_count++;
}
}
}
usb_devs = calloc (usb_dev_count, sizeof (tblcf_usb_dev));
if (!usb_devs) return;
usb_dev_count = 0;
/* scan through all busses and devices adding each one */
for (libusb_bus = usb_get_busses(); libusb_bus; libusb_bus = libusb_bus->next) {
/* scan through all devices */
for (libusb_dev = libusb_bus->devices; libusb_dev; libusb_dev = libusb_dev->next) {
if ((libusb_dev->descriptor.idVendor==TBLCF_VID) &&
(libusb_dev->descriptor.idProduct==product_id)) {
/* found a device */
usb_devs[usb_dev_count].bus = libusb_bus;
usb_devs[usb_dev_count].device = libusb_dev;
usb_devs[usb_dev_count].name = malloc (strlen (libusb_bus->dirname) +
strlen (libusb_dev->filename) + 2);
if (!usb_devs[usb_dev_count].name)
usb_devs[usb_dev_count].name = "no memory for name";
else {
strcpy (usb_devs[usb_dev_count].name, libusb_bus->dirname);
strcat (usb_devs[usb_dev_count].name, "-");
strcat (usb_devs[usb_dev_count].name, libusb_dev->filename);
}
usb_dev_count++;
}
}
}
}
/* returns number of attached TBDML devices */
unsigned int tblcf_usb_cnt(void) {
return usb_dev_count;
}
/* returns number of attached TBDML devices */
void tblcf_usb_dev_name(int dev, char *name, int namelen) {
if (usb_devs && (dev < tblcf_usb_cnt ()))
strncpy (name, usb_devs[dev].name, namelen - 1);
else
strncpy (name, "invalid device", namelen - 1);
name[namelen - 1] = '\0';
}
int tblcf_usb_dev_open(int dev) {
return (dev < tblcf_usb_cnt ()) && usb_devs[dev].handle;
}
/* open connection to device enumerated by tblcf_usb_find_devices */
/* returns the device number on success and -1 on error */
int tblcf_usb_open(const char *device) {
int dev;
for (dev = 0; dev < usb_dev_count; dev++)
if (strcmp (device, usb_devs[dev].name) == 0)
break;
if (dev == usb_dev_count) {
tblcf_print("USB Device '%s' not found\n", device);
return -1;
}
if (usb_devs[dev].handle) {
tblcf_print("USB Device '%s' alread open\n", device);
return -1;
}
usb_devs[dev].handle = usb_open(usb_devs[dev].device);
if (usb_devs[dev].handle==NULL) return -1;
tblcf_print("USB Device open\n");
/* TBLCF has only one valid configuration */
if (usb_set_configuration(usb_devs[dev].handle,1)) return -1;
tblcf_print("USB Configuration set\n");
/* TBLCF has only 1 interface */
if (usb_claim_interface(usb_devs[dev].handle,0)) return -1;
tblcf_print("USB Interface claimed\n");
return dev;
}
/* closes connection to the currently open device */
void tblcf_usb_close(int dev) {
if (tblcf_usb_dev_open(dev)) {
/* release the interface */
usb_release_interface(usb_devs[dev].handle,0);
tblcf_print("USB Interface released\n");
/* close the device */
usb_close(usb_devs[dev].handle);
tblcf_print("USB Device closed\n");
/* indicate that no device is open */
usb_devs[dev].handle=NULL;
}
}
/* Message data format:
1 byte: size of cmd+data
1 byte: cmd
(size-1) bytes: data
*/
/* sends a message to the TBDML device over EP0 */
/* returns 0 on success and 1 on error */
/* since the EP0 transfer is unidirectional in this case, data returned by the
* device must be read separately */
unsigned char tblcf_usb_send_ep0(int dev, unsigned char * data) {
unsigned char * count = data; /* data count is the first byte of the message */
int i;
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("USB EP0 send: device not open\n");
return(1);
}
tblcf_print("USB EP0 send:\n");
tblcf_print_dump(data,(*count)+1);
i=usb_control_msg(usb_devs[dev].handle, 0x40, *(data+1), (*(data+2))+256*(*(data+3)),
(*(data+4))+256*(*(data+5)), (char*) data+6,
((*count)>5)?((*count)-5):0, TIMEOUT);
if (i<0) return(1); else return(0);
}
/* sends a message to the TBDML device over EP0 which instruct the device to
* exec command and return data */
/* returns 0 on success and 1 on error */
/* data count in the message is number of bytes EXPECTED/REQUIRED from the device */
/* the device will get the cmd number and 4 following data bytes */
unsigned char tblcf_usb_recv_ep0(int dev, unsigned char * data) {
unsigned char count = *data; /* data count is the first byte of the message */
int i;
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("USB EP0 receive request: device not open\n");
return(1);
}
tblcf_print("USB EP0 receive request:\n");
tblcf_print_dump(data,6);
i=usb_control_msg(usb_devs[dev].handle, 0xC0, *(data+1), (*(data+2))+256*(*(data+3)),
(*(data+4))+256*(*(data+5)), (char*) data, count, TIMEOUT);
tblcf_print("USB EP0 receive:\n");
tblcf_print_dump(data,count);
if (i<0) return(1); else return(0);
}
/* sends a message to the TBDML device over EP2 */
/* returns 0 on success and 1 on error */
/* data the device wants to return need to be read out in separate recv transaction */
unsigned char tblcf_usb_send_ep2(int dev, unsigned char *data) {
unsigned char * count = data; /* data count is the first byte of the message */
int i;
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("USB EP2 send: device not open\n");
return(1);
}
tblcf_print("USB EP2 send:\n");
tblcf_print_dump(data,(*count)+1);
i=usb_bulk_write(usb_devs[dev].handle, 0x02, (char*) data, (*count)+1, TIMEOUT);
if (i<0) return(1); else return(0);
}
/* receives data from EP2 */
/* returns 0 on success and 1 on error */
/* data count in the message is number of bytes EXPECTED/REQUIRED from the device */
unsigned char tblcf_usb_recv_ep2(int dev, unsigned char * data) {
unsigned char count = *data; /* data count is the first byte of the message */
int i;
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("USB EP2 receive request: device not open\n");
return(1);
}
tblcf_print("USB EP2 receive request:\n");
tblcf_print_dump(data,6);
i=usb_bulk_read(usb_devs[dev].handle, 0x82, (char*) data, count, TIMEOUT);
tblcf_print("USB EP2 receive (%d byte(s)):\n",i);
tblcf_print_dump(data,count);
if (i<0) return(1); else return(0);
}
/* routines to interact with the ICP code on JB16 */
/* programs given number of bytes into flash of the device from given address */
/* returns 0 on succes, -1 on USB error and 1 on compare error */
char icp_program(int dev, unsigned char * data, unsigned int address, unsigned int count) {
int i;
unsigned char result;
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("ICP program: device not open\n");
return(-1);
}
while (count>ICP_MAX_PACKET_SIZE) {
tblcf_print("ICP program %d byte from address 0x%04X:\n",ICP_MAX_PACKET_SIZE,address);
tblcf_print_dump(data,ICP_MAX_PACKET_SIZE);
i=usb_control_msg(usb_devs[dev].handle, 0x40, ICP_PROGRAM, address,
address+ICP_MAX_PACKET_SIZE-1, (char*) data, ICP_MAX_PACKET_SIZE, TIMEOUT);
if (i<0) {
tblcf_print("ICP program: request failed\n");
return(-1);
}
usleep(10 * 1000 * 1000); /* give the part plenty of time to do the programming */
do {
i=usb_control_msg(usb_devs[dev].handle, 0xC0, ICP_GET_RESULT,
0, 0, (char*) &result, 1, TIMEOUT);
if (i<0) {
tblcf_print("ICP program: get result request failed\n");
return(-1);
}
} while (result==ICP_RESULT_BUSY); /* keep checking the result while busy */
if (result!=ICP_RESULT_OK) {
tblcf_print("ICP programming error (%02X)\n",result);
return(1);
}
count-=ICP_MAX_PACKET_SIZE;
address+=ICP_MAX_PACKET_SIZE;
data+=ICP_MAX_PACKET_SIZE;
}
if (count) {
tblcf_print("ICP program %d byte(s) from address 0x%04X:\n",count,address);
tblcf_print_dump(data,count);
i=usb_control_msg(usb_devs[dev].handle, 0x40, ICP_PROGRAM, address, address+count-1,
(char*) data, count, TIMEOUT);
if (i<0) {
tblcf_print("ICP program: request failed\n");
return(-1);
}
usleep(10 * 1000 * 1000); /* give the part plenty of time to do the programming */
do {
i=usb_control_msg(usb_devs[dev].handle, 0xC0, ICP_GET_RESULT,
0, 0, (char*) &result, 1, TIMEOUT);
if (i<0) {
tblcf_print("ICP program: get result request failed\n");
return(-1);
}
} while (result==ICP_RESULT_BUSY); /* keep checking the result while busy */
if (result!=ICP_RESULT_OK) {
tblcf_print("ICP programming error (%02X)\n",result);
return(1);
}
}
return(0);
}
/* performs mass erase of device flash */
/* returns 0 on success , -1 on USB error and 1 on operation error */
char icp_mass_erase(int dev) {
int i;
unsigned char result;
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("ICP mass erase: device not open\n");
return(-1);
}
tblcf_print("ICP mass erase\n");
i=usb_control_msg(usb_devs[dev].handle, 0x40, ICP_MASS_ERASE, 0, 0, NULL, 0, TIMEOUT);
if (i<0) {
tblcf_print("ICP mass erase request failed\n");
return(-1);
}
/* wait 250ms (time of mass erase) + lots of extra to make sure the operation
* is finished by the time new traffic apears on the USB bus */
usleep(400 * 1000);
do {
i=usb_control_msg(usb_devs[dev].handle, 0xC0, ICP_GET_RESULT,
0, 0, (char*) &result, 1, TIMEOUT);
if (i<0) {
tblcf_print("ICP mass erase: get result request failed\n");
return(-1);
}
} while (result==ICP_RESULT_BUSY); /* keep checking the result while busy */
if (result!=ICP_RESULT_OK) {
tblcf_print("ICP mass erase error (0x%02X)\n",result);
return(1);
}
return(0);
}
/* performs block erase on block containing given address */
/* returns 0 on success, -1 on USB error and 1 on operation error */
char icp_block_erase(int dev, unsigned int address) {
int i;
unsigned char result;
unsigned char blank_test_array[ICP_FLASH_BLOCK_SIZE];
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("ICP block erase: device not open\n");
return(-1);
}
/* make sure the address is only 16 bit and align it to the closest lower
* block boundary */
address&=(65536-ICP_FLASH_BLOCK_SIZE);
tblcf_print("ICP block erase\n");
for (i=0;i<ICP_FLASH_BLOCK_SIZE;i++) blank_test_array[i]=0xff;
i=icp_verify(dev, blank_test_array, address, ICP_FLASH_BLOCK_SIZE);
if (i<0) {
tblcf_print("ICP block erase: verify request failed\n");
return(-1);
}
if (i==0) return(0); /* block is already erased */
/* sector is not blank, must perform block erase */
tblcf_print("ICP block erase: block not empty, erasing...\n");
i=usb_control_msg(usb_devs[dev].handle, 0x40, ICP_BLOCK_ERASE,
address, address+ICP_FLASH_BLOCK_SIZE-1, NULL, 0, TIMEOUT);
if (i<0) {
tblcf_print("ICP block erase request failed\n");
return(-1);
}
/* wait 10ms (time of block erase) + lots of extra to make sure the operation
* is finished by the time new traffic apears on the USB bus */
usleep(30 * 1000);
do {
i=usb_control_msg(usb_devs[dev].handle, 0xC0, ICP_GET_RESULT,
0, 0, (char*) &result, 1, TIMEOUT);
if (i<0) {
tblcf_print("ICP block erase: get result request failed\n");
return(-1);
}
} while (result==ICP_RESULT_BUSY); /* keep checking the result while busy */
if (result!=ICP_RESULT_OK) {
tblcf_print("ICP block erase error (0x%02X)\n",result);
return(1);
}
return(0);
}
/* verifies given number of bytes against contents of flash of the device from given address */
/* returns 0 on succesful compare, -1 on USB error and 1 on compare error */
char icp_verify(int dev, unsigned char * data, unsigned int address, unsigned int count) {
int i;
unsigned char result;
if (!tblcf_usb_dev_open(dev)) {
tblcf_print("ICP verify: device not open\n");
return(-1);
}
while (count>ICP_MAX_PACKET_SIZE) {
tblcf_print("ICP verify %d bytes from address 0x%04X:\n",ICP_MAX_PACKET_SIZE,address);
tblcf_print_dump(data,ICP_MAX_PACKET_SIZE);
i=usb_control_msg(usb_devs[dev].handle, 0x40, ICP_VERIFY,
address, address+ICP_MAX_PACKET_SIZE-1, (char*) data,
ICP_MAX_PACKET_SIZE, TIMEOUT);
if (i<0) {
tblcf_print("ICP verify request failed\n");
return(-1);
}
/* wait to make sure the operation is finished by the time new traffic
* apears on the USB bus */
usleep(5 * 1000);
do {
i=usb_control_msg(usb_devs[dev].handle, 0xC0, ICP_GET_RESULT,
0, 0, (char*) &result, 1, TIMEOUT);
if (i<0) {
tblcf_print("ICP verify: get result request failed\n");
return(-1);
}
} while (result==ICP_RESULT_BUSY); /* keep checking the result while busy */
if (result!=ICP_RESULT_OK) {
tblcf_print("ICP verification error\n");
return(1);
}
count-=ICP_MAX_PACKET_SIZE;
address+=ICP_MAX_PACKET_SIZE;
data+=ICP_MAX_PACKET_SIZE;
}
if (count) {
tblcf_print("ICP verify %d byte(s) from address 0x%04X:\n",count,address);
tblcf_print_dump(data,count);
i=usb_control_msg(usb_devs[dev].handle, 0x40, ICP_VERIFY,
address, address+count-1, (char*) data, count, TIMEOUT);
if (i<0) {
tblcf_print("ICP verify request failed\n");
return(-1);
}
/* wait to make sure the operation is finished by the time new traffic
* apears on the USB bus */
usleep(5 * 1000);
do {
i=usb_control_msg(usb_devs[dev].handle, 0xC0, ICP_GET_RESULT,
0, 0, (char*) &result, 1, TIMEOUT);
if (i<0) {
tblcf_print("ICP verify: get result request failed\n");
return(-1);
}
} while (result==ICP_RESULT_BUSY); /* keep checking the result while busy */
if (result!=ICP_RESULT_OK) {
tblcf_print("ICP verification error\n");
return(1);
}
}
return(0);
}

56
m68k/tblcf/tblcf_usb.h Normal file
View File

@@ -0,0 +1,56 @@
/*
Turbo BDM Light ColdFire
Copyright (C) 2006 Daniel Malik
Changed to support the BDM project.
Chris Johns (cjohns@user.sourgeforge.net)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TBLCF_USB_H
#define TBLCF_USB_H
void tblcf_usb_init(void);
void tblcf_usb_find_devices(unsigned short int product_id);
unsigned int tblcf_usb_cnt(void);
void tblcf_usb_dev_name(int dev, char *name, int namelen);
int tblcf_usb_dev_open(int dev);
int tblcf_usb_open(const char *device);
void tblcf_usb_close(int dev);
unsigned char tblcf_usb_send_ep0(int dev, unsigned char * data);
unsigned char tblcf_usb_recv_ep0(int dev, unsigned char * data);
unsigned char tblcf_usb_send_ep2(int dev, unsigned char * data);
unsigned char tblcf_usb_recv_ep2(int dev, unsigned char * data);
/* in circuit programming */
#define ICP_MAX_PACKET_SIZE 64
#define ICP_VERIFY 0x87
#define ICP_MASS_ERASE 0x83
#define ICP_BLOCK_ERASE 0x82
#define ICP_GET_RESULT 0x8F
#define ICP_RESULT_OK 0x01
#define ICP_RESULT_BUSY 0x02
#define ICP_RESULT_FAIL 0x04
#define ICP_PROGRAM 0x81
#define ICP_FLASH_BLOCK_SIZE 512 /* must be power of 2 */
char icp_verify(int dev, unsigned char * data, unsigned int address, unsigned int count);
char icp_program(int dev, unsigned char * data, unsigned int address, unsigned int count);
char icp_mass_erase(int dev);
char icp_block_erase(int dev, unsigned int address);
#endif

47
m68k/tblcf/version.h Normal file
View File

@@ -0,0 +1,47 @@
#define TBLCF_DLL_VERSION 0x10 /* version of the DLL in BCD */
/* Changes:
1.0 01/04/2006 initial coding
*/
#define TBLCF_BOOTLOADER_VERSION 0x10 /* version of the bootloader application in BCD */
/* Changes:
1.0 10/03/2006 initial coding
*/
#define TBLCF_CCS_VERSION 0x10 /* version of the CCS application in BCD */
#define TBLCF_CCS_SERVER_VERSION 0x040D /* version reported to CCSAPI */
/* Changes:
1.0 15/04/2006 initial coding
*/
#define TBLCF_GDI_VERSION 0x13 /* version of the GDI DLL */
/* Changes:
1.0 29/04/2006 initial coding
1.1 19/06/2006 changed return value in case of target stopped to DI_WAIT_UNKNOWN
removed reset to BDM mode executed during start-up of the GDI interface ("ResetHalt" in the debugger cfg file can be used instead)
1.2 22/06/2006 added conditional resynchronization into each call of GetStatus
added conditional compilation for returnning errors, the debugger is able to attach to a running target if no errors are returned
1.3 22/06/2006 added conditional default values for memory and register reads
*/
#define TBLCF_UNSEC_VERSION 0x10 /* version of the unsecure utility */
/* Changes:
1.0 11/05/2006 initial coding
*/