# boot script for BeagleBone Black

# BeagleBone white uses a different .dtb file, and flash-kernel is
# currently unable to support multiple .dtb files.
if test "${board_name}" = "A335BONE"
then
  echo "BeagleBone white detected, unsupported platform."
  echo "Exiting in 10 seconds..."
  sleep 10
  exit
fi

if test "${devtype}" = ""
then
  setenv device mmc
else
  # use device provided by distro_bootcmd
  setenv device "${devtype}"
fi

if test "${devnum}" = ""
then
  setenv partition ${bootpart}
elif test "${distro_bootpart}" = ""
then
  # use partition provided by bootpart
  setenv partition ${devnum}:${bootpart}
else
  # use partition provided by distro_bootpart
  setenv partition ${devnum}:${distro_bootpart}
fi

setenv bootargs @@LINUX_KERNEL_CMDLINE_DEFAULTS@@ ${bootargs} @@LINUX_KERNEL_CMDLINE@@

if test "${prefix}" = ""
then
  setenv image_locations '/boot/ /'
else
  # use prefix provided by distro_bootcmd
  setenv image_locations "${prefix}"
fi

if test -z "${fk_kvers}"; then
   setenv fk_kvers '@@KERNEL_VERSION@@'
fi

if test -n "${fdtfile}"; then
   setenv fdtpath dtbs/${fk_kvers}/${fdtfile}
else
   setenv fdtpath dtb-${fk_kvers}
fi

for pathprefix in ${image_locations}
do
  load ${device} ${partition} ${loadaddr} ${pathprefix}vmlinuz-${fk_kvers} \
  && load ${device} ${partition} ${fdtaddr} ${pathprefix}${fdtpath} \
  && load ${device} ${partition} ${rdaddr} ${pathprefix}initrd.img-${fk_kvers} \
  && echo "Booting Debian ${fk_kvers} from ${device} ${partition}..." \
  && bootz ${loadaddr} ${rdaddr}:${filesize} ${fdtaddr}
done
