===============================================================================
Instructions for development and using SIMPC8313
-------------------------------------------------------------------------------

U-boot is the bootloader.  U-boot is not an operating system, but rather a monitor.  When the board is powered on, u-boot brings the board up and performs certain specific tasks similar to a BIOS.  Building any code for the SIMPC8313 is done using the cross compile toolchain provided by Denx software engineering.  Follow the instructions below to install the ELDK (Embedded Linux Development Kit).

===============================================================================
INSTALLING ELDK (on PC)
-------------------------------------------------------------------------------
In an internet browser window, navigate to ftp://ftp.denx.de/pub/eldk/
Select the most current version of the ELDK ~4.2
Select ppc-linux-x86
Select iso
Select ppc_*_freescale.iso
Save the file to your machine
Select ppc_*-src.iso
Save the file to your machine
(Inside terminal window)
cd /your/dowload/location
mount -o loop /your/dowload/location/ppc_*_freescale.iso /your/mount/location
cd /your/mount/location
./install -d /opt/eldk ppc_6xx

connecting to the board and transferring files while u-boot is running on the MPC is accomplished through tftp.  Your PC will be the tftp server and u-boot will act as the client making requests of the server.  Below are the instructions for installing the TFTP server on your Linux box.

===============================================================================
INSTALLING TFTP SERVER (on PC)
-------------------------------------------------------------------------------
yum install tftp-server ('yum' is for Fedora, 'apt-get' is for Ubunutu)
vi /etc/xinet.d/tftp
service tftp
{
	protocol = udp
	port = 69
	socket_type = dgram
	wait = yes
	user = nobody
	server = /usr/sbin/in.tftpd
	server_args = /tftpboot
	disable = no
}
/sbin/service xinetd start
mkdir /tftpboot
*****Don't forget to check the linux security firewall
make sure that your PC IP address is set to 10.196.31.85
The MPC IP address is set to 10.196.31.84

Now that the ELDK is successfully installed you can now build U-boot.  Follow the instructions below to download and compile U-boot.

===============================================================================
BUILDING U-BOOT
-------------------------------------------------------------------------------
Navigate to ftp://ftp.denx.de/pub/u-boot/
Select u-boot-latest.tar.bz2
	NOTE: The latest u-boot version that includes SI-MPC code is sourced from
	"git://git.denx.de/u-boot-mpc83xx.git"
Extract files to a directory of your choosing
PATH=$PATH:/opt/eldk/usr/bin
cd /your/u-boot/path
export CROSS_COMPILE=ppc_6xx-
make SIMPC8313_**_config
make
cp u-boot-nand.bin /tftpboot/

Use one of two methods to burn U-boot to the NAND flash.  If the board has a working version of U-boot running, you can simply use the tftp command in U-boot.
(In u-boot)
tftp 100000 u-boot-nand.bin

after the file has transfered, run the following commands to burn the new version of U-boot into the NAND flash.

(erase only U-boot image and leave environment variables undisturbed.  Do this if you are making changes to the current U-boot version on the board)
nand erase 0 80000
or
(erase U-boot image and all environment variables.  Do this if you are updating to a new version of U-boot or you wish to erase the environment variables).
nand erase 0 200000

then write the image to the NAND flash.

(filesize should be rounded up to the nearest 0x800.  So a file size of 61ef0 should be rounded up to 62000.  The size of the file will be told to you during the tftp tranfer.)
nand write 100000 0 filesize

at this point your current u-boot will still be running, but your new u-boot will be in NAND and will boot the next time the SIMPC is reset or powered on.  Type reset or toggle power button.
reset

If after loading a new version of u-boot to NAND there are issues and it is not possible to burn another version of u-boot to the board, you will need to use the supplied driver and sample application to reburn u-boot.

After u-boot has been successfully installed you can proceed with building the Linux kernel, dtb (device tree blob), and filesystem.

Note:
1. The PHY address is 0x8 by default, but may also be 0x0.  Be sure to set the following #defines inside the \include\configs\SIMPC8313.H file:
#define TSEC1_PHY_ADDR	0x0

2. The environment settings under the "#define CONFIG_EXTRA_ENV_SETTINGS" section may also be included:
"ethaddr=00:E0:0C:00:95:01\0"
"ipaddr=10.196.31.84\0"
"serverip=10.196.31.85\0"


===============================================================================
BUILDING THE KERNEL
-------------------------------------------------------------------------------
NOTE: Latest valid kernel version is 2.6.33
S(Server_E):\Develop\_binaries\_Latest_Working\Sample and Samplib\mpc_C67x\bsp_downloads\linux-2.6.33.tar.gz
Unpackage and move to an appropriate directory

simpc8313_defconfig_usbhost
simpc8313_defconfig_usbgadget
should be placed in arch/powerpc/configs/83xx in order to compile the Linux kernel in this configuration.

simpc8313.dts
should be place in arch/powerpc/boot/dts, but can be placed and compiled anywhere.
To build as usbhost comment out (//) line 172 - 'dr_mode = "peripheral";'
Defaults as usbgadget.

PATH=$PATH:/opt/eldk/usr/bin
export ARCH=powerpc CROSS_COMPILE=ppc_6xx- KBUILD_OUTPUT=/home/si/build/kernel/<kernel_version>
make 83xx/simpc8313_defconfig
make
cp /home/si/build/kernel/<kernel_version>/arch/powerpc/boot/uImage /tftpboot/linux-<kernel_version>

(In u-boot)
tftp 100000 linux-<kernel_version>
nand erase kernel 400000
(filesize can be determined again by stats given at the end of a successful tftp transfer and should be rounded up to the nearest 0x800)
nand write 100000 kernel filesize

The kernel will not be able to boot appropriately without the associated dtb file.  Below are the instructions for building the dtb.

===============================================================================
BUILDING THE DTB
-------------------------------------------------------------------------------
Navigate to http://www.jdl.com/software/
Download latest dtc application and install

cd /home/si/develop/dtc-v1.1.0
./dtc -I dts -O dtb -o simpc8313_<kernel-version>.dtb -S 0x2000 /home/si/develop/linux-2.6.27/arch/powerpc/boot/dts/simpc8313.dts
cp simpc8313_<kernel-version>.dtb /tftpboot/

(In u-boot)
tftp 100000 simpc8313_<kernel-version>.dtb
nand erase 7e0000 20000
nand write 100000 7e0000 2000

Instructions for building the JFFS2 FS are incomplete at this time.

===============================================================================
BUILDING THE JFFS2 FS
-------------------------------------------------------------------------------
Manual Configuration
-------------------------------------------------------------------------------
PATH=$PATH:/opt/eldk/usr/bin
cd /opt/eldk/ppc_6xx/images
mkdir /root/Desktop/temp/rootfs/
gzip -d -c -v ramdisk_image.gz >/root/Desktop/temp/rootfs/ramdisk_image
cd /root/Desktop/temp/rootfs/
mount -o loop ramdisk_image /root/Desktop/temp_mount/
cd /root/Desktop/temp_mount
tar -zc --exclude='dev/*' -f /home/si/build/rootfs/rootfs.tar.gz *
tar -zcf /home/si/build/rootfs/devices.tar.gz dev/
umount /root/Desktop/temp_mount
<add/remove packages/files/directories>
mkfs.jffs2 -r rootfs -n --pad -s 0x800 -e 0x20000 -b -D rootfs/rootfs_devices.tab -o simpc_lp.jffs2
or
mkfs.jffs2 -r rootfs -n --pad -s 0x200 -e 0x4000 -b -D rootfs/rootfs_devices.tab -o simpc_sp.jffs2
tar -zcf rootfs.tar.gz rootfs/*

-------------------------------------------------------------------------------
RFSB (Root File System Builder) Configuration
-------------------------------------------------------------------------------
Currently git must be installed and used to download the rfsb.  There is not a standalone website that houses the lastest stable version of the source code.

git clone git://git.denx.de/rfsb.git

PATH=$PATH:/opt/eldk/usr/bin:/opt/eldk/bin
export CROSS_COMPILE=ppc_6xx-
cp rfsb.config rfsb/.config
cp root_devices.tab rfsb/config/
cp inittab rfsb/custom/rootfs/etc/
cp passwd rfsb/custom/rootfs/etc/
cp rc.sh rfsb/custom/rootfs/etc/
mkdir rfsb/custom/rootfs/home
mkdir rfsb/custom/rootfs/home/si
mkdir rfsb/custom/rootfs/home/si/bin
mkdir rfsb/custom/rootfs/home/si/doc
mkdir rfsb/custom/rootfs/home/si/dsp
mkdir rfsb/custom/rootfs/home/si/tmp
mkdir rfsb/custom/rootfs/home/si/usr
Copy all of the following files to rfsb/custom/rootfs/home/si/bin:
	fpgalock
	fsl_usb2_udc.ko
	g_ether.ko
	g_serial.ko
	g_zero.ko
	mod66xx.bit
	mpc_top_12e.bit
	mpc_sisample.out
	mpc_siserver_net.out
	mpc_siserver_usb.out
	mpc_top.bit
	simpc.ko
	sisample.out
	siserver_net.out
	siserver_usb.out
cp c6711mpcini.out rfsb/custom/rootfs/home/si/dsp
cd rfsb
make menuconfig
make

Resultant image file will be found at rfsb/build/images.
NOTE:
'cpio: etc/security/opasswd: Cannot open: Permission denied'

errors like this can be solved by 'chmod +r /opt/eldk/ppc_6xx/etc/security/opasswd'

===============================================================================
ADDING PACKAGES TO FILE SYSTEM (when not using RFSB)
-------------------------------------------------------------------------------
PATH=/opt/eldk/usr/ppc-linux/bin:$PATH:/opt/eldk/usr/bin:/opt/eldk/bin
export CROSS_COMPILE=ppc_6xx-
mount -o loop /your/dowload/location/ppc_*-src.iso /mnt/temp
ppc_6xx-rpm -iv /mnt/temp/target/SRPMS/<package>.src.rpm
ppc_6xx-rpmbuild -ba /opt/eldk/usr/src/denx/SPECS/<package>.spec
<add appropriate files to filesystem location - varies for packages>

List of packages added to the file system (possibly more)
libpthread
libcap
libcom_err
libgcc
libssl
libstdc++
libz
busybox (reconfigured):
	addgroup
	adduser
vsftpd
telnetd


*******************************************************************************
REGARDING BOARD STARTUP
*******************************************************************************
Starting with a bare board there are a few steps which must be taken in order to have the board be in normal working order.  The first of these is to boot the board inside of the PCI as an agent using one of the hardcoded reset configuration source options.  SI recommends S2 have the value 0x80 or from left to right 0b10000000.  Once S2 has been set appropriately you can then plug the SIMPC8313 card into the PCI bus and start the PC.  Please take caution as the board has been known to start certain PCs upon insertion into the PCI bus.  To guard against this you can switch off the power supply on your PC while inserting the board into the PCI bus.

Once the PC has finished its boot process you can start the sample application.  The sample application should recognize that the boot sequencer has not been initialized.  The application should then configure an appropriate boot sequencer in the I2C located at (I2C bus) address 0x50.  Once this is finished the board must be restarted in order for written values to take effect.

After restarting the board and restarting the sample application all should run as "normal".  In order to appropriately use the NAND options you must first bitload the FPGA.  After the FPGA has been successfully bitloaded you can write u-boot to the NAND flash.  First, erase the u-boot region of the flash with option '5'.  The erase size on the first time should be the entire u-boot range (0x0 - 0x200000).  After you have erased the flash you can program u-boot into the NAND using option '6'.

After u-boot has been burned into the NAND flash the board should be able to operate in the stand alone (host) mode.

===============================================================================
U-boot ENV setup
-------------------------------------------------------------------------------
If not already set up, within U-boot perform the following steps:
setenv ethaddr 00:E0:0C:00:95:01
setenv ipaddr 10.196.31.84
setenv serverip 10.196.31.85
saveenv

===============================================================================
BUILDING THE HOST DRIVER (Linux)
-------------------------------------------------------------------------------
cd /home/si/sidev/siddk/siddk_mpc/drivers/linux/0206
make

===============================================================================
BUILDING THE EMBEDDED DRIVER (Linux only (?))
-------------------------------------------------------------------------------
cd /home/si/sidev/siddk/siddk_mpc/drivers/linux/mpc_embedded
PATH=$PATH:/opt/eldk/usr/bin
**also you need to have a configured kernel located at /home/si/build/kernel/2_6
make

===============================================================================
BUILDING SAMPLE (Linux)
-------------------------------------------------------------------------------
cd /home/si/sidev/siddk/siddk_mpc/apps/sample/linux
make

===============================================================================
GIT DEVELOPMENT (Linux)
-------------------------------------------------------------------------------
yum install git-core git-email (for Fedora, in Ubuntu use Ubuntu Software Center)
cd /home/si/develop/
git clone git://www.denx.de/git/u-boot.git u-boot/
cd u-boot
#####optional#####
git branch next				#create remote 'next' branch
git checkout next			#switch to next branch
git pull origin next			#pull remote 'next' branch
###end optional###
git branch simpc			#Create branch called simpc from current branch
git checkout simpc			#Switch to simpc branch
gedit foo.c				#Make all changes here
git diff				#To verify changes against master branch
git add foo.c				#Apply changes to current branch
git commit -m "Subject for email format" -m "Message describing changes made" -s foo.c
git status				#To verify you are still in the simpc branch
git format-patch --subject-prefix="PATCH v2][foo" master	#Create patch of changes against master branch
git send-email --to u-boot@lists.denx.de 0001-Some-Patch-File.patch
		    linuxppc-dev@ozlabs.org
		    netdev@vger.kernel.org
		    eldk@lists.denx.de

git reset HEAD <file>			#unstages a file for committing
git reset --soft HEAD^ 			#Goes back one commit
git reset --soft HEAD~ (?)

*******************************************************************************
git clone git://www.denx.de/git/u-boot.git u-boot/
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
git clone git://git.denx.de/linux-2.6-denx.git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/romieu/netdev-2.6.git ???
git clone git://git.denx.de/u-boot-nand-flash.git
git clone git://git.denx.de/u-boot-mpc83xx.git
git clone git://git.denx.de/rfsb.git

-------------------------------------------------------------------------------
git config --global user.name "Your Name"
git config --global user.email "some.email@address.com"
git config --global sendemail.smtpserver some.smtp.server.com
git config --global sendemail.aliasfiletype mailrc
git config --global sendemail.smtpuser "some.email@address.com"
git config --global sendemail.smtpssl true
*******************************************************************************

Notes:

1) Add revision/version numbers that pertain to the instructions.
2) 
