Sunday, August 31, 2008

Low cost Jtag for beagle

In the quest for a proper debug tool.. printfs have been my friend so far.. but printfs cannot help in many cases optimally.. JTAG is the right solution for such cases. keesj and I have been independently working on getting openocd working with flyswatter.
http://elinux.org/BeagleBoardJTAG is the starting point in this quest! join us, provide your thoughts etc..

[Update: Sept 3, 2008:
1. keesj has mailed an excellent report to the beagleboard list on his progress on the JTAG saga. Read about it here (excellent job Kees :) ).
2. As pointed by keesj, tincan tools have the adapter on the product page]

Today, the thought has been in creating a jtag debugger convertor - given that "ARM standard" and "TI standard" are not 1-1!

Note: Tincan tools is planning on making a more professional connector than "mine" and most probably will work.. one thing I can say for sure.. OMAP still works after plugging this in.. and I can probe the chip ID from openocd we are still way off from getting openocd working..

keesj had an adapter which does the translation. here is how it ought to look:
==>

Now, I dont have the above connector, so I set about creating my own:
step 1: connectors and my setup as per this:

step 2: created a connectivity of the same as per this:


NOTE: I screwed up the EMU0,1 wiring to pull up instead of down in the above picture.. my"rev0.2" fixes it ;)..

Thanks to keesj: (sample openocd.cfg):
#Basic configuration
#default port 4444
telnet_port 4444

#interface

interface ft2232
ft2232_device_desc "Flyswatter"
ft2232_layout "flyswatter"
ft2232_vid_pid 0x0403 0x6010
jtag_speed 1

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
jtag_device 6 0x1 0x0 0x0

target arm926ejs little 0 arm926ejs

#
# trst == test rest is part of the jtag optional specs and allows the jtag state machine
# to be reset to an initial state
#
# srst ==system reset?
#
reset_config trst_and_srst
Building openOCD: http://openfacts.berlios.de/index-en.phtml?title=Building_OpenOCD
I did it with libftdi using ubuntu, as the binaries of the closed source ftdi driver is x32 bit :(
nmenon@coyote:~/Src/opensource/openocd/trunk$ sudo ./src/openocd -f ../keesj/jtag-3530.cfg
Open On-Chip Debugger 1.0 (2008-09-01-16:50) svn:977
$URL: svn://svn.berlios.de/openocd/trunk/src/openocd.c $
jtag_speed: 1
Info: JTAG device found: 0x0b7ae02f (Manufacturer: 0x017, Part: 0xb7ae, Version: 0x0)
Error: unknown EmbeddedICE version (comms ctrl: 0x00000000)
Warning:no gdb port specified, using default port 3333
Warning:no tcl port specified, using default port 6666
telnet localhost 4444
> halt
timed out while waiting for target halted
Runtime error, file "command.c", line 436:
> scan_chain
0: idcode: 0x0b7ae02f ir length 6, ir capture 0x1, ir mask 0x0, current instruction 0xc
Not too good, as keesj points here, we probably need to give tapid commands before things start working..

[Update: Sept 3, 2008:
as keesj mentions:

SCANINIT t1:w1000:t0:w1000: ;toggle TRST,
SCANINIT ch10:w1000: ;clock TCK with TMS high and wait
SCANINIT i6=07:d8=89:i6=02: ;connect and select router
SCANINIT d32=81000080: ;IP control: KeepPowered
SCANINIT d32=a3002048: ;TAP3: DebugConnect, ForcePower, ForceActive
SCANINIT d32=81000081: ;IP control: KeepPowered, SysReset
SCANINIT d32=a3002148: ;enable TAP3
SCANINIT cl10:i10=ffff ;clock 10 times in RTI, scan bypass

In openocd this would translate to the following sequence.

irscan 0 7
drscan 0 8 0X89
irscan 0 2
drscan 0 32 0xA3002108
......
irscan 0 0x3F
sleep 10
jtag_device 4 0x1 0x0 0xe

A final frontier remains: EMU0,1 -> unlocking it's mysteries..]

Thursday, August 28, 2008

omap u-boot-utilities released!!

Finally, it is out.. nothing great as of each of the tools.. but these are handy little blokes to have around.. see the announce here
Links to the project sites:
* Source Code hosting: Git Hub
http://github.com/nmenon/omap-u-boot-utils/
* Binaries, Defect tracking and Documentation: code.google.com -
http://code.google.com/p/omap-u-boot-utils/

pserial history:
They started off coz, I wanted something to work on windows and Linux equally well and I had nothing on hand.. the first app I ever wrote in this thread of thought was the perl script here. Now, perl is good but it can turn ugly too- esp for a new guy poking around.. hence wanted a pserial with a c version. While, doing that with windows, I set myself some weird targets:
a) I will not use cygwin or vmware -> I wanted folks to use the exes without worrying about where the lib files should be got from!
b) It will provide the user apis to be as similar as possible.
I ended up with MingW compiler for windows, and the usual gcc for linux.

pusb history:
Incidently around the same time Dirk and I had a interesting few days getting usb apps working -> which we both did in our own ways. Dirk's code is accessible here. I must say, we had been thinking about this w.r.t doing a custom driver + app.. but libusb seems to have done it all before.. The only hickup was getting Win32 version of it functional.

ucmd history:
Many days later while trying to download I hated having to switch windows between hyperterm and pserial command window, and decided to be lazy and write a ucmd -> something to send commands to uboot!

ukermit history:
This has an interesting story of me getting tired of using ckermit and hyperterminal and finally deciding to write my own kermit application custom to u-boot which I could run from command line in windows and linux. Note: This does not mean u-boot wont work with standard apps.. Mine is just one which you can tweak around (like the -d option) for u-boot!

That is long short story of how all of these started... anyways.. So have fun and send your patches if you like things and could fix things up -> esp the irritating usb2serial convertor and pserial issue!!

Monday, August 11, 2008

some thoughts on writing boot code for omap

This following post is based on a reply I send to Vishal Bhoj, thought I'd share with all..
In general before starting, I suggest one does read the TRM and Data Manual pretty well.
If you are starting from scratch, it may not be quick to get things running on OMAP,but the basics are same no matter which OMAP you do take.. Unfortunately, I don't think I could start explaining the entire OMAP architecture even if I wanted to.. :( I am not saying it is an herculean task doing a boot code, but it is challenging and is a good way to start really know OMAP's potential. The question was related to UART and character LCD on SDP2430/3430, and the following is a very very brief overview of what to think of as a starter..

Some basic Fundamentals:

OMAP is a SOC (System On Chip) -containing ARM, DSP and other peripherals.
ARM has a memory mapped interface to it's peripherals it can talk to.
UART is one such peripheral,
character LCD on SDP2430 on the other hand is emulated over FPGA on the board. So, you need to look at how to talk to FPGA from ARM.

Now, every peripheral has a few basic stuff:
a) Basic clocks: Interface clock -> clock to enable register access, functional clock -> clock for it's functionality.
b) Another generic stuff is called pin muxing -> OMAP has hundreds of peripherals with tons of possible pins flowing out.. so the logic is simplified by muxing multiple pins to a single pin out and OMAP allows configuration of which pin you want in what mode.

Note: the above is the bare minimum stuff you need to take care, there
may be more per peripheral.

So when you boot up you need to get your clocks right(to make the module functional) and also the pin muxing right if you intend to talk to the world outside OMAP. Now every peripheral has it's own internal methodology of programming and operation.. + you may have specific needs
of power and timing -> esp when you speak with the peripherals outside of OMAP. Remember OMAP is designed to talk to as many things as possible, so you'd need to configure things as per the device you want to.. usually one-size-fits all is not optimal esp in the embedded
world.. so you'd need to tweak timings..

You also need to remember what you need to do when your code gets control - esp while you boot up. what things are active and can cause a reset(e.g. watchdogs), where are you booting from -> sram, NOR, NAND, sdram etc.. things are bit different and constraints different for a
boot code..

If you intend to write boot code, you need to understand the hardware pretty well.. it usually a mite tougher to write a boot code from scratch compared to writing a simple driver once everything is setup and you just need to call apis to get things done..

So, U-Boot, X-Loader might be good places to look at, but dont stop there.. you could write your own boot loader.. or even port something like grub, lilo or anything out there.. doing it is fun.. but getting it to work and be stable gives an even high level of exhilaration..

happy hunting.. Remember in boot code, most things are logical.. so knowing the hardware as well as your code is of equal importance :)...

Saturday, August 02, 2008

How to make a bootable MMC card on Linux for BeagleBoard (using gparted)

H/w I have:
a) Beagle board rev A5
b) a 512Meg Micro SD card with adapter
c) USB2Serial convertor (my laptop docking station has a PCI UART, but I hardly ever use docking stations)
d) card reader
Objective use the UI tools in Linux as much as possible to boot mmc card on beagleboard.

Step 1:
getting to know the usb sd/mmc card reader device:
plugin the reader and run dmesg
E.g.:
[50306.414076] sd 6:0:0:0: [sdb] 254208 512-byte hardware sectors (130 MB)
[50306.419071] sd 6:0:0:0: [sdb] Write Protect is off
[50306.419080] sd 6:0:0:0: [sdb] Mode Sense: 03 00 00 00
[50306.419084] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[50306.431052] sd 6:0:0:0: [sdb] 254208 512-byte hardware sectors (130 MB)
[50306.436051] sd 6:0:0:0: [sdb] Write Protect is off
[50306.436059] sd 6:0:0:0: [sdb] Mode Sense: 03 00 00 00
[50306.436063] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[50306.436071] sdb:
[50306.442153] sd 6:0:0:0: [sdb] Attached SCSI removable disk
[50306.442235] sd 6:0:0:0: Attached scsi generic sg1 type 0
See here for more instructions on using fdisk
-> here are my own instructions (Ubuntu 8.04)
Step 2: Formating the mmc card
a) Stop HAL from autodetecting drives..
sudo /etc/init.d/hal stop
b) Run gparted
sudo gparted /dev/sdb
c) Delete all partitions present

































d) create the minimum FAT32 partition (primary partition)











e) create the rest of the disk for ext3fs (primary partition)











f) apply the changes
g) Set the FAT32 partition as bootable:
select manage flags for the FAT32 partition

select bootable option:


apply and quit from gparted.
h) restart the hal
sudo /etc/init.d/hal start
sudo /etc/init.d/hal restart


(At this point, you can replug your mmc card without it being auto detected ;)...
Step 3:Copy the images
a) run mount command to see the partitions:
mount

/dev/sdb2 on /media/disk-1 type ext3 (rw,nosuid,nodev,uhelper=hal)
/dev/sdb1 on /media/disk-2 type vfat (rw,nosuid,nodev,uhelper=hal,shortname=mixed,uid=1000,utf8,umask=077,flush)

b) mount the partitions and copy the following to FAT32 partition:
MLO, uImage, u-boot.bin (See here and here for more versions)
c) unmount the filesystem on the PC. put the card in the board
d) boot up and you should see x-loader followed by u-boot coming up.

Boot args: for Linux to boot out of mmc card and continue using the filesystem in mmc partition 2,
setenv bootargs "console=ttyS2,115200n8 noinitrd root=/dev/mmcblk0p1 rootfstype=ext2 rw rootdelay=1 nohz=off"
setenv bootcmd 'mmcinit; fatload mmc 0 0x80300000 uImage;bootm 0x80300000'
saveenv


NOTE: I dont trust the bootargs completely.. any one with proper values.. please comment in.. there are two variants here:
a) partition number mmcblk0p1 or the equal based on udev etc..
b) partition type - ext2/ext3 etc..