# 
# start.txt - this file controls how u-boot starts when read
#             from media like CF, MMC, etc
 
# first load the root_config.txt file
# this file defines the device and fstype of the root file system
# and specifies whether we will be programing the on-board flash
# or booting from some other media
txt_file=root_config.txt
run execute_txt_file

# load the tty_config.txt file (normally not needed)
# this file usually controls which serial port is the console
txt_file=tty_config.txt
run execute_txt_file

# load the hw_config.txt file
# this file can be used to set hw registers to specific values
# it is most often used to setup the framebuffer geometry
txt_file=hw_config.txt
run execute_txt_file && run hw_config

# load the install_config.txt file
# this file can be used to pass parameters to the Debian installer
# when doing a fresh install of Debian. Otherwise, it is not needed.
txt_file=install_config.txt
run execute_txt_file

# check for envars that should be set by default
# or from the files loaded above
test -n ${tty_args}  || echo "Warning missing tty_args."
test -n ${root_args} || echo "Warning missing root_args."
test -n ${mtd_args}  || echo "Warning missing mtd_args."

# combine all the kernel command line arguments into
# a single envar: bootargs
setenv bootargs ${tty_args} ${root_args} ${mtd_args} ${install_args}
echo "Using bootargs: " $bootargs

# copy images to on-board flash 
if test -n ${images_to_flash}
then
  echo ${images_to_flash}
  for image in ${images_to_flash}
  do
    echo ${image}
    load_file=${image}
    echo ${load_file}
    load_buffer=scratch_buffer
    echo ${load_buffer}
    flash_partition=${image}
    echo ${flash_partition}
    run load_flash
  done
  saveenv

fi

# copy images to dram in preparation to boot
if test -n ${images_to_dram}
then
  echo ${images_to_dram}
  for image in ${images_to_dram}
  do 
    echo ${image}
    load_file=${image}
    load_buffer=${image}_buffer
    if test ${image} = ramdisk.gz || test ${image} = initrd.gz
    then
      echo Putting ramdisk.gz in initrd location
      load_buffer=initrd
    fi
    run load_dram
  done
fi

# after this file is executed, the system will be booted