EMAC- Preface
Most of the black magic outlined in the file is no longer required
thanks to the Cold-Boot distribution available here.
Cold-Boot does not require a pre-loader, or flashing itself from a RAM copy on any such
weirdness.
Nevertheless, this document is included for historical reasons, and because it does give some useful documentation on using U-Boot.

-NZG 


U-Boot for Motorola Coldfire M5272C3 and M5282EVB
=================================================



Introduction
------------

U-Boot is a bootloader originaly invented for PowerPC
based microcontrollers but has been also ported to
ARM and MIPS platforms. This document describes
howto get u-boot up and running for Motorola Coldfire.

U-Boot offers the following key features:

o Command line interface
o Environment variables
o Flash write access
o TFTP download via Ethernet to RAM
o Download over the serial line
o Bootp/DHCP protocol for auto-configuration
o Scripting facilities
o Booting compressed kernels
o Booting kernel from a JFFS2 partition



Status
------

In the current incarnation of the Coldfire version
of the U-Boot loader, there is only support for the
Motorola M5272C3 and M5282EVB evaluation boards. It
works out quite good for me, but YMMV.



GDB-BDM Installation
--------------------

In order to be able to deploy U-Boot on your board, you
first need to get the BDM interface cable working
with gdb. Download gdb and the bdm patch and place
them into a convenient loacation:

  export ARCHIVE=/tmp/downloads
  install -d $ARCHIVE
  wget -c ftp://ftp.gnu.org/gnu/gdb/gdb-5.2.1.tar.gz
  wget -c ftp://www.cybertec.com.au/pub/bdm/src/gdb-5.2.1.patch
  wget -c ftp://www.cybertec.com.au/pub/bdm/src/gdb-bdm-20020210.tar.gz
  cp gdb-5.2.1.tar.gz $ARCHIVE
  cp gdb-5.2.1.patch $ARCHIVE
  cp gdb-bdm-20020210.tar.gz $ARCHIVE

Unpack and patch gdb:

  cd /usr/local/src/
  tar -xzf $ARCHIVE/gdb-5.2.1.tar.gz
  cd gdb-5.2.1/
  patch -p1 < $ARCHIVE/gdb-5.2.1.patch

Install the kernel driver for the BDM interface

  cd /usr/local/src/
  tar -xzf $ARCHIVE/gdb-bdm-20020210.tar.gz
  cd gdb-bdm-20020210/driver/linux/
  make
  install -d /lib/modules/`uname -r`/misc/
  cp linux-bdm.o /lib/modules/`uname -r`/misc/bdm.o
  depmod -a

Create the device BDM node and add an appropriate entry to
the module configuration files:

  mknod /dev/bdmcf0 c 34 4
  chmod a+rw /dev/bdmcf0
  echo "alias char-major-34 bdm" >> /etc/modules.conf

Please note that if you are using an M5282EVB, then you need
to modify the gdb-bdm-20020210/driver/bdm.c in line 1230:

  0xc04,    /* BDM_REG_RAMBAR   */

Change this line to:

  0xc05,    /* BDM_REG_RAMBAR   */

Background: RAMBAR is used for the internal flash of the
MCF5282 and a new register was invented for the
periperials associated with a different register number.

Finally compile and install the bdm enhanced gdb:

cd /usr/local/src/gdb-bdm-20020210
../gdb-5.2.1/configure --target=m68k-bdm-elf
make
strip -g gdb/gdb
cp gdb/gdb /usr/local/bin/m68k-bdm-elf-gdb



Compilation and Installation
----------------------------

Compilatino and Installation are very similar for M5272C3 and
M5282EVB, but to make things easier to understand, there
are seperate chapters for each of the boards.



Compilation and Installation for Motorola M5272C3
------------------------------------------------

It is assumed that you have an uClinux m68k-elf toolchain in
order to be able to cross compile the bootloader.

1) Download U-Boot and the patch for Coldfire:

  export ARCHIVE=/tmp/downloads
  install -d $ARCHIVE
  wget -c http://twtelecom.dl.sourceforge.net/sourceforge/u-boot/u-boot-0.4.0.tar.bz2
  wget -c http://www.uclinux.org/~bkuhn/Platforms/Coldfire/tarifa/20030707/patch-u-boot-0.4.0-mcf-20030707.bz2
  cp u-boot-0.4.0.tar.bz2 $ARCHIVE
  cp patch-u-boot-0.4.0-mcf-20030707.bz2 $ARCHIVE

2) Unpack the sources and apply the patch

  tar -xjf $ARCHIVE/u-boot-0.4.0.tar.bz2
  cd u-boot-0.4.0/
  bunzip2 -cd $ARCHIVE/patch-u-boot-0.4.0-mcf-20030707.bz2 | patch -p1

3) Configure for Motorola Coldfire MCF5272C3 evaluation board

  make M5272C3_config

4) Compile U-Boot

  make

5) Compile the pre-loader and generate a flashable image

  cd pre/coldfire/M5272C3/loader
  make
  cp loader.bin /tftpboot

6) Compile a board initialization file for the BDM interface

  cd ../../../../utils/coldfire/M5272C3/bdm/boardinit
  make

7) Load U-Boot to target RAM through the BDM cable

  cd ..
  sh load

The following output should appear on the shell:

  GNU gdb 5.2.1
  Copyright 2002 Free Software Foundation, Inc.
  GDB is free software, covered by the GNU General Public License, and you are
  welcome to change it and/or distribute copies of it under certain conditions.
  Type "show copying" to see the conditions.
  There is absolutely no warranty for GDB.  Type "show warranty" for details.
  This GDB was configured as "--host=i686-pc-linux-gnu --target=m68k-bdm-elf"...
   Coldfire debug module version is 0 (5206(e))

  Program received signal SIGTRAP, Trace/breakpoint trap.
  0x200004a4 in ?? ()
  1: x/i $pc  0x200004a4: halt

and after a few seconds, U-Boot should come up on the seriel
console (19200,8,N,1):

  U-Boot 0.4.0 (Jul  3 2003 - 19:55:38)

  CPU:   MOTOROLA Coldfire MCF5272
  Board: MOTOROLA MCF5272C3 Evaluation Board
  DRAM:   4 MB
  FLASH:  2 MB
  *** Warning - bad CRC, using default environment

  MCF5272C3>

8. Just to be sure, delete the whole flash:

  protect off ffe00000 ffffffff
  erase ffe00000 ffffffff

If unsure what should actually happen, here is a sample
console output:

  MCF5272C3> protect off ffe00000 ffffffff
  Un-Protected 11 sectors
  MCF5272C3> erase ffe00000 ffffffff
  Erase Flash from 0xffe00000 to 0xffffffff
  Erasing sector  0 ... ok.
  Erasing sector  1 ... ok.
  Erasing sector  2 ... ok.
  ...
  Erasing sector 10 ... ok.
  Erased 11 sectors
  MCF5272C3>


When the flash has been erased, re-invoke U-Boot through
the BDM cable: goto the shell where you have have
"sh load", press "CTRL+C", type 'q' and 'Enter'. Re-start
U-Boot bye typing "sh load" again.

9. Configure U-Boot and install the bootloader

Type the following commands on the seriel console:

  setenv ethaddr 00:cf:52:72:c3:01
  setenv ipaddr 192.168.1.60
  setenv serverip 192.168.1.1
  tftp 20000 /tftpboot/loader.bin
  protect off ffe00000 ffe3ffff
  erase ffe00000 ffe3ffff
  cp.b 20000 ffe00000 10000
  saveenv

If unsure what should actually happen, here is a sample
console output:

  MCF5272C3> setenv ethaddr 00:cf:52:72:c3:01
  MCF5272C3> setenv ipaddr 192.168.1.60
  MCF5272C3> setenv serverip 192.168.1.1
  MCF5272C3> tftp 20000 /tftpboot/loader.bin
  TFTP from server 192.168.1.1; our IP address is 192.168.1.60
  Filename '/tftpboot/loader.bin'.
  Load address: 0x20000
  Loading: #############
  done
  Bytes transferred = 65536 (10000 hex)
  MCF5272C3> protect off ffe00000 ffffffff
  Un-Protected 11 sectors
  MCF5272C3> cp.b 20000 ffe00000 10000
  Copy to Flash... done
  MCF5272C3> saveenv
  Saving Environment to Flash...
  Un-Protected 1 sectors
  Erasing Flash...
  Erasing sector  1 ... ok.
  Erased 1 sectors
  Writing to Flash... done
  Protected 1 sectors
  MCF5272C3>


Congratulations, you are done!

Here are some additional environment variables that allows
you to boot Linux via NFSroot:

  setenv bootcmd tftp 20000 /tftpboot/image.bin \; go 20000
  setenv bootargs root=/dev/nfs rw ip=192.168.1.60:192.168.1.1::::eth0:off
  setenv bootdelay 2
  setenv ptable env,2,4:kernel,c0,40:filesystem,100,100
  saveenv



Compilation and Insatllation for Motorola M5272EVB
--------------------------------------------------

It is assumed that you have an uClinux m68k-elf toolchain in
order to be able to cross compile the bootloader.

1) Download U-Boot and the patch for Coldfire:

  export ARCHIVE=/tmp/downloads
  install -d $ARCHIVE
  wget -c http://twtelecom.dl.sourceforge.net/sourceforge/u-boot/u-boot-0.4.0.tar.bz2
  wget -c http://www.uclinux.org/~bkuhn/Platforms/Coldfire/tarifa/20030707/patch-u-boot-0.4.0-mcf-20030707.bz2
  cp u-boot-0.4.0.tar.bz2 $ARCHIVE
  cp patch-u-boot-0.4.0-mcf-20030707.bz2 $ARCHIVE

2) Unpack the sources and apply the patch

  tar -xjf $ARCHIVE/u-boot-0.4.0.tar.bz2
  bunzip2 -cd $ARCHIVE/patch-u-boot-0.4.0-mcf-20030707.bz2 | patch -p1

3) Configure for Motorola Coldfire M5272EVB evaluation board

  make M5282EVB_config

4) Compile U-Boot

  make

5) Compile the pre-loader and generate a flashable image

  cd pre/coldfire/M5282EVB/loader
  make
  cp loader.bin /tftpboot

6) Compile a board initialization file for the BDM interface

  cd ../../../../utils/coldfire/M5282EVB/bdm/boardinit
  make

7) Load U-Boot to target RAM through the BDM cable

  cd ..
  sh load

The following output should appear on the shell:

  GNU gdb 5.2.1
  Copyright 2002 Free Software Foundation, Inc.
  GDB is free software, covered by the GNU General Public License, and you are
  welcome to change it and/or distribute copies of it under certain conditions.
  Type "show copying" to see the conditions.
  There is absolutely no warranty for GDB.  Type "show warranty" for details.
  This GDB was configured as "--host=i686-pc-linux-gnu --target=m68k-bdm-elf"...
   Coldfire debug module version is 0 (5206(e))

  Program received signal SIGTRAP, Trace/breakpoint trap.
  0x200004a4 in ?? ()
  1: x/i $pc  0x200004a4: halt

and after a few seconds, U-Boot should come up on the seriel
console (19200,8,N,1):

  U-Boot 0.4.0 (Jul  7 2003 - 02:20:28)

  CPU:   MOTOROLA Coldfire MCF5282
  Board: MOTOROLA M5272EVB Evaluation Board
  DRAM:  16 MB
  FLASH:  2 MB
  *** Warning - bad CRC, using default environment

  M5282EVB>

8. Just to be sure, delete the whole flash:

  protect off ffe00000 ffffffff
  erase ffe00000 ffffffff

If unsure what should actually happen, here is a sample
console output:

  M5282EVB> protect off ffe00000 ffffffff
  Un-Protected 35 sectors
  M5282EVB> erase ffe00000 ffffffff
  Erase Flash from 0xffe00000 to 0xffffffff
  Erasing sector  0 ... ok.
  Erasing sector  1 ... ok.
  Erasing sector  2 ... ok.
  ...
  Erasing sector 34 ... ok
  Erased 35 sectors
  M5282EVB>

When the flash has been erased, re-invoke U-Boot through
the BDM cable: goto the shell where you have have
"sh load", press "CTRL+C", type 'q' and 'Enter'. Re-start
U-Boot bye typing "sh load" again.

9. Configure U-Boot and install the bootloader

Type the following commands on the seriel console:

  setenv ethaddr 00:cf:52:82:eb:01
  setenv ipaddr 192.168.1.60
  setenv serverip 192.168.1.1
  tftp 10000 /tftpboot/loader.bin
  protect off ffe00000 ffe0ffff
  erase ffe00000 ffe0ffff
  cp.b 10000 ffe00000 10000
  saveenv

If unsure what should actually happen, here is a sample
console output:

  M5282EVB> setenv ethaddr 00:cf:52:82:eb:01
  M5282EVB> setenv ipaddr 192.168.1.60
  M5282EVB> setenv serverip 192.168.1.1
  M5282EVB> tftp 10000 /tftpboot/loader.bin
  TFTP from server 192.168.1.1; our IP address is 192.168.1.60
  Filename '/tftpboot/loader.bin'.
  Load address: 0x10000
  Loading: #############
  done
  Bytes transferred = 65536 (10000 hex)
  M5282EVB> protect off ffe00000 ffe0ffff
  Un-Protected 4 sectors
  M5282EVB> erase ffe00000 ffe0ffff
  Erase Flash from 0xffe00000 to 0xffe0ffff
  Erasing sector  0 ... ok.
  Erasing sector  1 ... ok.
  Erasing sector  2 ... ok.
  Erasing sector  3 ... ok.
  Erased 4 sectors
  M5282EVB> cp.b 10000 ffe00000 10000
  Copy to Flash... done
  M5282EVB> saveenv
  Saving Environment to Flash...
  Un-Protected 1 sectors
  Erasing Flash...
  Erasing sector  1 ... ok.
  Erased 1 sectors
  Writing to Flash... done
  Protected 1 sectors
  M5282EVB>



TFTP downloading and starting a linux kernel image
--------------------------------------------------

First, copy an appropriate kernel+romfs image to /tftpboot
on your development host. Then download and start the
image. Note that the default download loaction is 0x20000
to be compliant with the start address of the current uClinux
kernel that is optimized for the dBUG bootloader.

Use the "loadaddr" environment variable to override this
setting. The filename is determined by the "bootfile"
environment variable. Both, location and filename can
also be given on the command line

  MCF5272C3> tftp 20000 image.bin

Or just type "tftp" if "bootfile" is set properly. The response
from the bootloader should look like this:

  TFTP from server 192.168.1.1; our IP address is 192.168.1.9
  Filename 'image.bin'.
  Load address: 0x20000
  Loading: #################################################################

#################################################################

#################################################################
           #################################################
  done
  Bytes transferred = 1247760 (130a10 hex)

Now start the image:

  MCF5272C3> go 20000



Flashing a kernel image
-----------------------

First, you have to generate a "pkg"-file that U-Boot
can understand. This pkg file consists of the (compressed)
image and a prepended header containing information such
as load and start addresses. The tool to generate such
a file is "mkimage" and can be found in u-boot/0.4.0/tools
after compilation of the ppcboot image.
Copy mkimge to i.e. /usr/local/bin or to somewhere else
in your executable search path, and then perform the
following commands:

  cd /tftpboot
  gzip image.bin
  mkimage -O linux -T kernel -C gzip -a 0x20000 -e 0x20000 \
    -d image.bin.gz image.pkg
  gunzip image.bin.gz

The output of mkimage should look like this:

   Image Name:
   Created:      Sat May 25 15:52:13 2002
   Image Type:   PowerPC Linux Kernel Image (gzip compressed)
   Data Size:    547665 Bytes = 534.83 kB = 0.52 MB
   Load Address: 0x00020000
   Entry Point:  0x00020000

Don't be bothered that "Image Type" tells "PowerPC Linux Kernel Image" :-)

Now download the package and flash it:

  MCF5272C3> tftp 20000 image.pkg
    [ ARP broadcast 1
      TFTP from server 192.168.1.1; our IP address is 192.168.1.9
      Filename 'image.pkg'.
      Load address: 0x20000
      Loading: ##############################################################
               ##########################################
      done
      Bytes transferred = 547729 (85b91 hex) ]
  MCF5272C3> erase ffe40000 ffefffff
    [ Erase Flash from 0xffe40000 to 0xffefffff
      Erasing sector  4 ... ok.
      Erasing sector  5 ... ok.
      Erasing sector  6 ... ok.
      Erased 3 sectors ]
  MCF5272C3> cp.b 20000 ffe40000 $(filesize)
    [ Copy to Flash... done ]

You may now try out the "iminfo" command to get some information
about the flashed package:

  MCF5272C3> iminfo ffe40000

The output should look like this:

## Checking Image at ffe40000 ...
   Image Name:
   Image Type:   PowerPC Linux Kernel Image (gzip compressed)
   Data Size:    547665 Bytes = 534 kB = 0 MB
   Load Address: 00020000
   Entry Point:  00020000
   Verifying Checksum ... OK

Start the image with the "bootm" command:

  MCF5272C3> bootm ffe40000

In order to make the image auto-bootable, you will have
to set two more environment variables:

  MCF5272C3> setenv bootcmd bootm ffe40000
  MCF5272C3> setenv bootdelay 3
  MCF5272C3> saveenv

WARNING: if "bootdelay" is not set or set to "0", then
the system will start immediatly after reset and the
user won't have a chance to interrupt the boot process.

To recover from that situation, you will have to compile
ppcboot with CFG_ENV_ADDR set to i.e. 0xffe40000
(refer to include/config_M5272C3.h), so that
ppcboot won't find the valid environment variables
suitable for autoboot. After downloading the bootloader,
using the BDM interface cable, erase the flash block containing
the environment variables:

  MCF5272C3> protect off ffe04000 ffe05fff
  MCF5272C3> erase ffe04000 ffe05fff

After reset, the bootloader should be again accessable
by the user



User Address Range
------------------

The user may access the SDRAM ranging from 0x400 to 0x37ffff
for his/her own application. The area below 0x400 (1 KiB) is
reserved for exception vectors and the last 512 KiB are
reserved for U-Boot.

Once a kernel image has been started, the it certainly may feel
free to use the whole 4 MiB. You espcialy don't have to modify
any dBUG compliant images to limit them to 3.5 MiB.
The last 512 KiB are only reserved for U-Boot during
it's operation, i.e. it's not allowed to do something like
this:

  tftp 380000 image.bin

This, for instance, would corrupt the ethernet send/receive
buffers.

  tftp 0 kernel.bin

May work, but if an exception happens during download, then
the system may not recover from it.

The Flash may be accessed from 0xffe40000 to 0xffffffff.
However, the bootloader only needs 64 KiB, but the address
range from 0xffe10000 to 0xffe3ffff cannot be accessed without
affecting the bootloader stored in flash (see section
"Memory Layout (Flash)" below for more details).

In order to save 196 KiB of flash memory, you may attach the pkg file
to the ppcboot binary and store the whole thing at once, i.e.:

  cd /tftpboot
  cat loader.bin image.pkg > flash.img

On the target, type:

  MCF5272C3> protect off ffe00000 ffe3ffff
  MCF5272C3> tftp 20000 flash.img
  MCF5272C3> erase ffe00000 ffefffff
  MCF5272C3> cp.b 20000 ffe00000 $(filesize)
  MCF5272C3> setenv bootcmd bootm ffe10000
  MCF5272C3> setenv bootdelay 3
  MCF5272C3> saveenv

WARNING: This method affects the bootloader stored
in flash. If you have a power outage (or other
problems) during flashing, then you may need a
BDM interface cable to recover the system
(Type "bdm/load" in the ppcboot toplevel
directory after compiling the sources to download
the U-Boot loader).



Memory Layout
-------------

There are Two memory layouts: one for the first stage
bootlader (COLILO) and one for the second stage bootloader
(U-Boot).

COLILO operation mode
Exception Vectors       0x00000000 - 0x000003ff
Data, BSS and Heap      0x00000400 - 0x000fffff
Unused                  0x00100000 - 0x0037ffff
U-Boot                  0x00380000 - 0x003fffff
Stack  (Built-in SRAM)  0x20000000 - 0x20003fff
Code                    0xffe00000 - 0xffe04000
Reserved                0xffe10000 - 0xffffffff

U-Boot operation mode
Exception Vectors       0x00000000 - 0x000003ff
User RAM                0x00000400 - 0x0037ffff
Ethernet Buffers        0x00380000 - 0x00384000
Stack                   0x00384000 - 0x003bffff
Code, Data, BSS         0x003e0000 - 0x003fffff
COLILO                  0xffe00000 - 0xffe04000
Environment variables   0xffe04000 - 0xffe05fff
U-Boot                  0xffe06000 - 0xffe0ffff
Reserved                0xffe10000 - 0xffe3ffff
User Flash              0xffe40000 - 0xffffffff

Unforntuatly, the AM29PL160CB provided on the MCF5272C3 evaluation
board has a very bad flash block arrangement with respect to
U-Boot and Linux: although U-Boot fits into 64 KiB, you
will always need 256 KiB, because U-Boot overlaps flash
blocks 2 and 3 (flash blocks 0 to 3 sizes: 16/8/8/224 KiB).

One trick certainly would be to prepend a U-Boot image to
the kernel that is stored starting at flash block 3
(see section "User Address Ranges" above for more details).



Recovering dBUG
---------------

If you don't like U-Boot, you may recover dBUG with the
following command sequence on U-Boot:

  MCF5272C3> protect off ffe00000 ffe3ffff
  MCF5272C3> erase ffe00000 ffe3ffff
  MCF5272C3> tftp 20000 dBUG.bin
  MCF5272C3> cp.b 20000 ffe00000 $(filesize)

An appropriate dBUG binary suitable for the MCF5272C3 Evaluation
Board may be found at:
http://home.t-online.de/home/Bernhard_Kuhn/uclinux/Platforms/Coldfire/tarifa/20011119/images/boot_cramfs/dBUG/



(No) Warranty
-------------

I certainly cannot provide any warranties. Although this
document was put together with best intensions, i cannot
be held responsible for any demage (physicaly or mentaly)
that may result by following the instructions given above.



Thanks
------

Many thanks to Wolfgang Denk for providing and maintaining
U-Boot.

Bernhard Kuhn, Senior Software Engineerer, Metrowerks.

Mon Jul  7 03:22:07 CEST 2003
