===========================================================================
####COPYRIGHTBEGIN####

-------------------------------------------
The contents of this file are subject to the Cygnus eCos Public License
Version 1.0 (the "License"); you may not use this file except in
compliance with the License.  You may obtain a copy of the License at
http://sourceware.cygnus.com/ecos

Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the
License for the specific language governing rights and limitations under
the License.

The Original Code is eCos - Embedded Cygnus Operating System, released
September 30, 1998.

The Initial Developer of the Original Code is Cygnus.  Portions created
by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions.  All Rights Reserved.
-------------------------------------------

####COPYRIGHTEND####
===========================================================================

1999-01-05, revised 1999-03-11

How to build and install the GDB module on the AEB-1
====================================================

Overview
--------

The ARM AEB-1 comes with tools in ROM.  These include a simple FLASH
management tool and the Angel (R) monitor.  eCos for the ARM AEB-1
comes with GDB stubs suitable for programming into the onboard FLASH.
GDB is the preferred debug environment for eCos, but Angel must be
used to initially install the GDB stubs.

Once this bootstrapping is done, you can use GDB to load and debug
programs on the AEB-1 board.

The following steps will have you:

* talk to the AEB-1 board with a terminal emulator (or a real
  terminal!)

* enable ARM's Angel ROM monitor

* use GDB with Angel to download a configuration of eCos with GDB
  stubs which will act as a ROM monitor

* talk to the AEB-1 with a terminal emulator again, and tell it to
  write the new module to flash

* tell the board to use this new monitor, and then hook GDB up to it
  for real debugging

Talking to the board
--------------------

Connect a terminal or computer's serial port to the ARM AEB-1.  On a
PC with a 9-pin serial port, you can use the cable shipped by ARM with
no modification.

Set the terminal or terminal emulator to 9600N1 (9600 baud, no parity,
1 stop bit).

Reset the board by pressing the little reset button on the top.  You
will see the following text:

	ARM Evaluation Board Boot Monitor 0.01 (19 APR 1998)
	Press ENTER within 2 seconds to stop autoboot

Press ENTER quickly, and you will get the boot prompt:

	Boot:


Downloading the GDB stubs
-------------------------

Run the angel monitor by typing the following at the Boot: prompt:

    Boot: plugin angel
    Boot: angel

Then exit the terminal emulator and start up gdb with the GDB module:

    $ arm-elf-gdb -nw loaders/arm-aeb/gdb_module.img
    (gdb) set remotebaud 9600
    (gdb) target rdi s=<YOUR SERIAL PORT>

On Windows, the serial port could be com1, com2, etc.  On a UNIX or
Linux system, the serial port would be /dev/cua0 or /dev/cua1.
Examples are:

    (gdb) target rdi s=com1
    (gdb) target rdi s=/dev/cua0

Finally, load the GDB stubs image:

    (gdb) load
    Loading section .rom_vectors, size 0x44 lma 0xc000
    Loading section .text, size 0x3544 lma 0xc044
    Loading section .rodata, size 0x164 lma 0xf588
    Loading section .data, size 0x110 lma 0xf6ec
    Start address 0xc044 , load size 14332
    Transfer rate: 12739 bits/sec.

(Note that the sizes may not exactly match the ones you see on your
system.)

Once the loading is done, quit GDB:

    (gdb) quit


Activating the GDB stubs
------------------------

Connect a terminal emulator to the board again, reset the board, and
type enter within two seconds to get the Boot: prompt.  This is the
same thing you did at the beginning of this procedure.

Commit the GDB stubs module to flash:

	Boot: flashwrite 4018000 C000 8000

Verify that the eCos/"GDB stubs" module is now added in the list of
modules in the board:

	Boot: rommodules

You should see the following output:

	Header   Base     Limit
	04000004 04000000 040034a8 BootStrap       1.00 (14 Aug 1998) 
	04003a74 04003800 04003bc0 Production Test 1.00 (13 Aug 1998) 
	0400e4f4 04004000 0400e60f Angel           1.02 (12 MAY 1998) 
	0401ac00 04018000 0401aed8 eCos            1.2  (26 Feb 1999) GDB stubs

Now make the eCos/"GDB stubs" module be the default monitor:

	Boot: plugin eCos


Running and debugging an application
------------------------------------

Configure eCos from scratch for the ARM AEB-1 platform, and build your
application.  Remember that the AEB-1 board only has 128K of RAM.

Exit from the terminal emulator (you will not need it anymore for
normal operations), and run gdb:

    $ arm-elf-gdb -nw executable
    (gdb) set remotebaud 38400
    (gdb) target remote <YOUR SERIAL PORT>
    (gdb) load

You can now run your program in the usual way under GDB'S control

Notice that the GDB stub runs at 38400 baud.


Building the GDB stubs
----------------------

We provide the GDB stubs image in the directory
loaders/arm-aeb/gdb_module.img, but here are instructions on how to
rebuild them if you should ever need to.

1. Configure a minimal eCos system with all packages except 'infra'
   disabled.  If you are doing manual configuration, you can do so
   with

   tcl /work2/ecc/ecc/pkgconf.tcl                                         \
      --target=arm --platform=aeb --startup=stubs                         \
      --disable CYGPKG_KERNEL --disable CYGPKG_UITRON                     \
      --disable CYGPKG_LIBC --disable CYGPKG_LIBM                         \
      --disable CYGPKG_ERROR --disable CYGPKG_IO                          \
      --disable CYGPKG_IO_SERIAL --disable CYGPKG_DEVICES_WALLCLOCK       \
      --disable CYGPKG_DEVICES_WATCHDOG

   and if you are using the Configuration Tool GUI, you can select the
   ARM AEB platform, with GDB stubs startup, and enable the HAL and
   INFRA packages and disable all other packages.

2. Edit <hal/hal.h> to enable GDB:
    #define  CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
    #undef   CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
    #undef   CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT

   you can use the following patch:

--- pkgconf/hal.h~      Wed Mar 10 13:08:58 1999
+++ pkgconf/hal.h       Thu Mar 11 15:53:16 1999
@@ -356,9 +356,9 @@
 
    }}CFG_DATA */
 
-#undef   CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
+#define  CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
 #undef   CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
-#define  CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
+#undef   CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
 
 /*
  * NOTE:


3. make misc

The gdb_module.img file will be built in the directory
hal/arm/aeb/current/misc


Alternate way of loading the initial stubs
------------------------------------------

Using the AEB-1 module tool, install the GDB stubs from the provided
".UU" file.

>>> This is an annotated 'terminal' session with the AEB-1 monitor:

ARM Evaluation Board Boot Monitor 0.01 (19 APR 1998)
Press ENTER within 2 seconds to stop autoboot
Boot: help
Module is BootStrap       1.00 (14 Aug 1998)

Help is available on:
  Help          Modules       ROMModules    UnPlug        PlugIn
  Kill          SetEnv        UnSetEnv      PrintEnv      DownLoad
  Go            GoS           Boot          PC            FlashWrite
  FlashLoad     FlashErase

Boot: download c000
Ready to download. Use 'transmit' option on terminal emulator to download file.

 ... at this point, I told my terminal emulator (minicom) to download the ASCII file
     gdb_module.img.UU (probably needs a different name on Win/NT)
     I had to enter ^D when the download was complete to get the monitor to come back.

Loaded file gdb_module.img.raw at address 0000c000, size = 13905

Boot: flashwrite 4018000 c000 4000

  As above, this command actually programs the FLASH.

Boot: rommodules
Header   Base     Limit
04000004 04000000 040034a8 BootStrap       1.00 (14 Aug 1998)
04003a74 04003800 04003bc0 Production Test 1.00 (13 Aug 1998)
0400e4f4 04004000 0400e60f Angel           1.02 (12 MAY 1998)
0401b608 04018000 0401b844 eCos            1.2  (26 Feb 1999) GDB stubs

  This verifies that the eCos GDB stubs are available in FLASH.

Boot: plugin ecos

  This makes the eCos GDB stubs the default "monitor."  When reset the
  AEB-1 will start the GDB stubs, after the initial 2 second escape
  period.
