# erases NAND, flashes bootstrap and u-boot
# Set the rootPath to the location of the release files.
# Set the releaseDir to the specific directory of this release.

#set rootPath "Z:\\Products\\MTCDT-Conduit\\AEP\\Production\\TestMasFlashDirectory\\"
# set rootPath "\\\\Nasserver1\\TestRoom Programs\\EXTERNAL\\MRFLASH\\MASFLASH\\MTCDT\\MTCDT-x-210A\\"
# set rootPath "\\\\Nasserver1\\PROMS\\RELEASE\\MTCDT-x-210A\\"
#set releaseDir "AEP-1_7_0-dev1"
#set rootFilePath 	"$rootPath$releaseDir"

set bootstrapFile	"C:\\RomBOOT-mtcap-mlinux-5.2.7\\at91bootstrap-mtcap.bin"
set ubootFile		"C:\\RomBOOT-mtcap-mlinux-5.2.7\\u-boot-mtcap-2016.09.01-m3.bin"
set uimageFile		"C:\\RomBOOT-mtcap-mlinux-5.2.7\\uImage--4.9.87-r11.2-mtcap-20200612183133.bin"
set rootfsFile		"C:\\RomBOOT-mtcap-mlinux-5.2.7\\mlinux-mtcap-commissioning-image-mtcap-20200612183543.rootfs.jffs2"

## NandFlash Mapping
set ubootAddr		0x00040000
set ubootEnv1Addr	0x000C0000
set ubootEnv2Addr	0x00160000
set uimageAddr		0x00200000
set rootfsAddr		0x01800000

puts "-I- === Initialize the NAND access ==="
NANDFLASH::Init

puts "-I- === Enable PMECC OS Parameters ==="
# 4-bit ECC
NANDFLASH::NandHeaderValue HEADER 0xc0902405

puts "-I- === Erase entire NAND flash==="
NANDFLASH::EraseAll

puts "-I- === Load the bootstrap in the first sector ==="
NANDFLASH::SendBootFilePmeccCmd $bootstrapFile

puts "-I- === Load the u-boot image ==="
send_file {NandFlash} "$ubootFile" $ubootAddr 0

# jjg - no longer needed since U-boot reads eeprom for ethernet mac addr
#puts "-I- === Load u-boot env1 ==="
#send_file {NandFlash} "$ubootEnv1File" $ubootEnv1Addr 0
#puts "-I- === Load u-boot env2 ==="
#send_file {NandFlash} "$ubootEnv2File" $ubootEnv2Addr 0

puts "-I- === Loading uImage ==="
send_file {NandFlash} "$uimageFile" $uimageAddr 0

# Need to enable Trimffs before writing rootfs or PMECC errors will
# result.
NANDFLASH::NandSetTrimffs 1

puts "-I- === Loading rootfs ==="
send_file {NandFlash} "$rootfsFile" $rootfsAddr 0

puts "-I- === DONE. ==="
