Dangerous Prototypes

Dangerous Prototypes => Bus Pirate Support => OpenOCD JTAG => Topic started by: gonemad on April 21, 2011, 10:32:24 pm

Title: buspirate.cfg?
Post by: gonemad on April 21, 2011, 10:32:24 pm
The fog is slowly beginning to dissipate...

About the router SW/HW, that is a forum by itself. See any threads on OpenWRT. I don't think I need to specify this at the moment, as it would distract from the basic and current problems. But I can tell you it is a Broadcom 6348 SoC with what seem to be a standard 14 pin MIPS JTAG...

Quote
Have you tried to follow any of the OpenOCD examples and perform a chain scan? Have you tried to connect to the Bus Pirate via OpenOCD? I think the functionality you want is there in the main firmware.

This is exactly what I'd like to do! But I just can't find a working procedure. However, I have successfully compiled OpenOCD for Cygwin on WinVista, given some of the instructions on the Michal Demin page and others. Here are the results:

Code: [Select]
$ ./bootstrap
$ ./configure --enable-buspirate --enable-maintainer-mode --disable-werror --disable-shared --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=/cygdrive/c/myusr/ftd2xx
$ make && make install
$ which openocd.exe

/usr/local/bin/openocd.exe

$ openocd.exe --help

Open On-Chip Debugger 0.5.0-dev-00858-g3c6af51-dirty (2011-04-21-20:38)
Licensed under GNU GPL v2
For bug reports, read
        --------------------------------------------------
Open On-Chip Debugger
Licensed under GNU GPL v2
--help      | -h      display this help
--version    | -v      display OpenOCD version
--file      | -f      use configuration file <name>
--search    | -s      dir to search for config files and scripts
--debug      | -d      set debug level <0-3>
--log_output | -l      redirect log output to file <name>
--command    | -c      run <command>

But then the instructions are talking about copying the content of the /usr/local/share/openocd/scripts/interface/buspirate.cfg file and change it to my needs. Although not saying anything how to determine these. So now what??
Title: Re: buspirate.cfg?
Post by: ian on April 22, 2011, 08:20:39 am
I'm sorry, I don't see the instructions you're refering to.

On robots page here:
http://michaldemin.wordpress.com/2010/0 ... d-openocd/ (http://michaldemin.wordpress.com/2010/02/27/how-to-buspirate-and-openocd/)

It looks like there are 2 steps.

Step 1. Setup the interface profile:
Quote
Next step is creating the correct configuration file. The confiuration file contains interface specification and target specification.
The interface is buspirate, of course. If defaults are Ok, you can just use

source [find interface/buspirate.cfg]

More advance way is to copy the content of the buspirate.cfg file and change it to needs.

interface buspirate
buspirate_port /dev/ttyUSB0
buspirate_speed normal # or fast
#buspirate_vreg 0 # or 1
#buspirate_mode normal # or open-drain
#buspirate_pullup 0 # or 1

These commands should be self explanatory. Fast speed mode switches the UART speed to 1Mbit upon connecting to BP, some BP revisions might not work, if this happens please report!

Check the /interface/ folder in your OpenOCD directory, there should be an existing  buspirate.cfg. You need to edit it to suit your needs. It should work with defaults, but you'll probably need to edit this line to match your serial port:

Code: [Select]
buspirate_port /dev/ttyUSB0

It the file is not there, create a new text file and add these contents:

Code: [Select]
interface buspirate
buspirate_port /dev/ttyUSB0
buspirate_speed normal # or fast
#buspirate_vreg 0 # or 1
#buspirate_mode normal # or open-drain
#buspirate_pullup 0 # or 1

Now when you run OpenOCD and specify the buspirate.cfg with -f, it should connect:

Code: [Select]
openocd -f buspirate.cfg 

2. Add a target configuration:

This defines the chips on your router and how to interact with them.

Quote
Next you need to add your target configuration. I use STM32 cpu.

source [find target/stm32.cfg]

This tells OpenOCD what TAPs are on the JTAG chain, and OpenOCD scans if the IDs match.
After you are done with the configuration file, save it, and run openocd in the same directory. If there is no fatal error, OpenOCD listens on 4444 port. Use telnet to connect to it, you will get simple console to send commands to OpenOCD.

This is where you'll need the support of the Open-Wrt community, or someone who knows that is on your router. Probably it is a JTAG chain involving a few flash chips, and ARM, and maybe a few other odds and ends. This needs to be defined in the target configuration file. I highly recommend you figure out the configuration for your router before trying either step, it might not be available.

When all is ready you can try to run OpenOCD. Specify both the interface and target configuration files:
Code: [Select]
openocd -f buspirate.cfg -f sam7x256.cfg

Now open Telnet to localhost:444 and you can interact with the OpenOCD interface.

The OpenOCD documentation, which covers configuration files, use, and more, is here:
http://openocd.berlios.de/doc/html/index.html (http://openocd.berlios.de/doc/html/index.html)
Title: Re: buspirate.cfg?
Post by: gonemad on April 23, 2011, 02:16:59 am
Hi,
After editing and experimenting with the buspireate.cfg file, I finally got a little bit more on the way, but then everything failed with the same error as in this post:  viewtopic.php?f=27&t=1702#p19292 (http://dangerousprototypes.com/forum/viewtopic.php?f=27&t=1702#p19292)

So now I am stuck again...

In the meantime I'll respond to your post:
Quote
I'm sorry, I don't see the instructions you're refering to.
They were:
http://forum.sparkfun.com/viewtopic.php?t=11221 (http://forum.sparkfun.com/viewtopic.php?t=11221)
http://piconomic.co.za/fwlib/_b_u_i_l_d ... o_c_d.html (http://piconomic.co.za/fwlib/_b_u_i_l_d___o_p_e_n_o_c_d.html)

Here's my buspireate.cfg file:
Code: [Select]
interface buspirate
buspirate_port /dev/com13
buspirate_speed normal
reset_config srst_only

In fact I have some comments about the OpenOCD & the buspirate.cfg files:

1) "#" Comments after .cfg commands are not working/allowed ??
Because of this you may wanna update this page: http://dangerousprototypes.com/docs/Bus ... or_OpenOCD (http://dangerousprototypes.com/docs/Bus_Pirate_JTAG_connections_for_OpenOCD)

2) OpenOCD configuration files should now declare "transports",
  which is not currently present in "buspirate.cfg". (See adapter.c:171)
  (Adding a "transport select jtag" line to the .cfg file crashes OpenOCD.)

openocd/src/jtag/adapter.c:
Code: [Select]
168         if (!jtag_interface->transports)
169                LOG_WARNING("Adapter driver '%s' did not declare "
170                        "which transports it allows; assuming "
171                        "legacy JTAG-only", jtag_interface->name);
172                retval = allow_transports(CMD_CTX,
173                                        jtag_interface->transports
174                                                ? : jtag_only);
175                        if (ERROR_OK != retval)
176                                return retval;

3) There is at least one spelling error in the info messages in the "buspirate.c" file:
  "Error: Buspirate error. Is is binary//OpenOCD support enabled?"

In fact this is the error I now keep on getting, as referred to in the top thread link.

4) There often seem to be some problems with the "reset_config srst_only" line...

The line that I use for testing (not actually connecting to anything) is this:
Code: [Select]
openocd.exe -f bitpirate.cfg -f stm32.cfg

However, I am curious as to which target chip to use for a MIPS based Broadcom 6348 ?
In the OpenOCD documentation they say they support a mips_m4k, but I can't find it/load it...
http://openocd.berlios.de/doc/html/CPU- ... figuration (http://openocd.berlios.de/doc/html/CPU-Configuration.html#CPU-Configuration)

So how can I find out how to add that board to this target list, if it is not already there/supported?

In addition it has the following:
Flash: 29LV320CBTC-90G, 32Mbit
SDRAM: Winbond W9812G6GH-6 (2Mx4x16 bits)
Title: Re: buspirate.cfg?
Post by: ian on April 23, 2011, 08:51:12 am
Hi gonemad,

Thanks for the update. I'm glad you're making some progress.

Thanks for the tip on #, I updated the wiki page with a note. Have the comments been removed from the examples included in the development version you compiled?

I think it is ok to let OpenOCD default to legacy transport. Especially if declaring a transport crashes it.

We've had similar reports of OpenOCD not responding in the v5.10 release. Please try this version compiled by the author of OpenOCD support. Many people have success with it:
viewtopic.php?f=27&t=1702#p17536 (http://dangerousprototypes.com/forum/viewtopic.php?f=27&t=1702#p17536)

I'm sure the OpenOCD project would be happy to accept your patches for spelling mistakes. The best way to contact them is through their mailing list.

Quote
However, I am curious as to which target chip to use for a MIPS based Broadcom 6348 ?
In the OpenOCD documentation they say they support a mips_m4k, but I can't find it/load it...
http://openocd.berlios.de/doc/html/CPU- (http://openocd.berlios.de/doc/html/CPU-) ... figuration

So how can I find out how to add that board to this target list, if it is not already there/supported?

In addition it has the following:
Flash: 29LV320CBTC-90G, 32Mbit
SDRAM: Winbond W9812G6GH-6 (2Mx4x16 bits)

Where there any example configuration files in the version you got? I have only used pre-compiled windows versions in the past, and they always included a bunch of examples. Maybe you can find a complete release and get the missing examples. I do remember that the manual referred to many config files that were no longer included in the release.

The OpenOCD manual chapter before the one you link is tap declarations, I believe that is what you need to setup, but I'm not sure:
http://openocd.berlios.de/doc/html/TAP- ... eclaration (http://openocd.berlios.de/doc/html/TAP-Declaration.html#TAP-Declaration)
I won't be able to help you with this, I've only done simple stuff with OpenOCD. The OpenOCD mailing list and open-wrt forum can probably help you out though.
Title: Re: buspirate.cfg?
Post by: gonemad on April 23, 2011, 10:26:35 pm
Hi! Just to clarify:
Quote
Thanks for the tip on #, I updated the wiki page with a note. Have the comments been removed from the examples included in the development version you compiled?

You CAN have "#" comments after a configuration line, iff you terminate the line with a " ;" (notice the space), otherwise OpenOCD thinks that "# blah bla" is part of the configuration.

"buspirate_pullup 0 # Pullup disabled"              ==> NOT OK!
"buspirate_pullup 0 ;# Pullup disabled"            ==> OK!
"buspirate_pullup 0; # Pullup disabled"            ==> probably OK!
"#buspirate_pullup blah blah # Pullup disabled" ==> OK!

Quote
Where there any example configuration files in the version you got? I have only used pre-compiled windows versions in the past, and they always included a bunch of examples.

Could you elaborate?
I'm really clueless here, there are tons of files around.
/openocd/contrib/  --> just one "example.cfg"
/openocd/scripts/ --> board, chip, cpld, cpu, interface,target,test subdirectories...

Where should I post what I have so far (regarding BP/OpenOCD and windows)? Perhaps I start a new thread, so I can update/edit my post as my progress move along.
Title: Re: buspirate.cfg?
Post by: robots on April 25, 2011, 08:26:34 am
Hi

Can you try this ?

viewtopic.php?f=27&t=1702#p17536 (http://dangerousprototypes.com/forum/viewtopic.php?f=27&t=1702#p17536)

It is different firmware, (which actually works), and simpler configuration file ;)
Title: Re: buspirate.cfg?
Post by: ian on April 25, 2011, 08:51:23 am
>>/openocd/scripts/ --> board, chip, cpld, cpu, interface,target,test subdirectories...

This sounds good, but I don't know. I've only done simple stuff with OpenOCD, I don't know how to setup a profile for a new board.
Title: Re: buspirate.cfg?
Post by: gonemad on April 25, 2011, 09:07:43 pm
@ Robots:  Thanks! Seem to work, see results here: viewtopic.php?f=27&t=1702&p=21004#p21004 (http://dangerousprototypes.com/forum/viewtopic.php?f=27&t=1702&p=21004#p21004)

But I need a OpenOCD config file for the only board I have, which is a Broadcom 63xx based one... Or is it possible to successfully send the chain scan command (or others) to the board, without having to specify a target config file?
Title: Re: buspirate.cfg?
Post by: robots on April 26, 2011, 12:08:24 am
openocd will try to auto-detect the chain when run without any target specified (you need to keep the interface definition)

But i am not sure about  the results :). Is your cpu supported by openocd ?

It seems that broadcom 63xx is mips, so you might have some luck debugging the cpu. But i don't think you will be able to access the flash, unless it is explicitly supported by openocd.
Title: Re: buspirate.cfg?
Post by: gonemad on April 26, 2011, 08:48:28 pm
Quote
But i am not sure about the results :). Is your cpu supported by openocd ?

Well, that is my question. I'm sure it is supported in principle, since you should be able to create the appropriate scripts for any jtag'able device. In addition, other people have managed to use other Broadcom devices with OpenOCD, but I have not found any one script for the chips set in question, which is BCM63xx.
And like you already mentioned, it is MIPS based, and MIPS are in fact one of the "supported" chips, according to OpenOCD manual, although I (and others) have not been able to find this "support".

(I'm really starting to dislike that term "support". It seems it can mean just about anything, but most of the time nothing! ;)
Title: Re: buspirate.cfg?
Post by: robots on April 26, 2011, 09:12:11 pm
you need to understand that even if it is mips, the cpu can have different address mapping, different memory controllers and other peripherals different from other mips cpu's.

Best would be to ask in the openocd mailing list or check urjtag (that seems to have broadcom support)

Urjtag does not support buspirate
Title: Re: buspirate.cfg?
Post by: gonemad on April 27, 2011, 01:43:00 am
Yes, I know that. But since I am not able to find the relevant target config files, I'm hoping to find something or some that are similar enough to the BCM6348. And according to:
http://www.linux-mips.org/wiki/Broadcom_SOCs (http://www.linux-mips.org/wiki/Broadcom_SOCs)
This chip is very similar to BCM3348,6358,6368.  So if I can find any OpenOCD target files for any of these, it should be a lot easier to make one for my own chip.

I have also tried to find any BSDL files for these, in vain. Perhaps my google skills are not up to date?

Yes, I have all(?) UrJTAG configuration (?) files from the "data" directory, for both: 6348 and 6358.

Here's 6348:
Code: [Select]
register	BR		 1
register BSR 480
register DIR 32
register EJIMPCODE 32
register EJADDRESS 32
register EJDATA 32
register EJCONTROL 32
register EJALL 96

instruction length 5

instruction BYPASS 11111 BR
instruction SAMPLE/PRELOAD 00010 BSR
instruction IDCODE 00001 DIR
instruction EJTAG_IMPCODE 00011 EJIMPCODE
instruction EJTAG_ADDRESS 01000 EJADDRESS
instruction EJTAG_DATA 01001 EJDATA
instruction EJTAG_CONTROL 01010 EJCONTROL
instruction EJTAG_ALL 01011 EJALL
instruction EJTAGBOOT 01100 BR
instruction NORMALBOOT 01101 BR

As you can see this is very short and boring, so I cannot see how you can use this info. Any ideas?
(I have a pending question on OpenOCD forum, but it has to be accepted by moderator first, who seem to have been eaten by a giant Easter chicken.)

PS. I am not intending to do any advanced JTAG analysis, I just would like to perform a chain scan, reading some chip/board binary info and possibly erase/reflash NVRAM. So do I still need a complete set of target config file(s)?
Title: Re: buspirate.cfg?
Post by: robots on April 27, 2011, 12:58:56 pm
have a look at openocd targer config files. These are very different from bsdl files and urjtag configs.

To scan chain run openocd without target defined. It will preform scan (which may or may not work).

Find similar target in openocd and try to use that config file. You might need to change the IDcode of the chip. (OpenOCD will tell you when it is wrong)

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01882127160session_write_close ( )...(null):0
20.01912258752ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01912259528Database_MySQL->query( ).../DatabaseHandler.php:119
40.06332398264Database_MySQL->error( ).../Db-mysql.class.php:273