if test ${devnum} -eq 1; then
	echo "Booting from SD"
	setenv linux_mmcdev 1
else
	echo "Booting from eMMC"
	setenv linux_mmcdev 0
fi

# If we have at least 2 partitions, then the 1st one is /boot, and / is #2
if part size mmc ${devnum} 2 none; then
	setenv rootpart 2
else
	setenv rootpart 1
	setenv bootdir "/boot"
fi

setenv bootargs loglevel=4 rw rootwait console=tty0

if test -e mmc ${devnum}:1 encrypted.scr; then
	load mmc ${devnum}:1 ${loadaddr} encrypted.scr
	source ${loadaddr}
else
	setenv bootargs ${bootargs} root=/dev/mmcblk${linux_mmcdev}p${rootpart}
fi

echo "Loading kernel..."
load mmc ${devnum}:1 ${ramdisk_addr_r} ${bootdir}/vmlinuz-linux-pinetab2

echo "Uncompressing kernel..."
unzip ${ramdisk_addr_r} ${kernel_addr_r}

echo "Loading initramfs..."
load mmc ${devnum}:1 ${ramdisk_addr_r} ${bootdir}/initramfs-linux-pinetab2.img
setenv ramdisk_size ${filesize}

echo "Loading dtb..."
load mmc ${devnum}:1 ${fdt_addr_r} ${bootdir}/dtbs/${fdtfile}

echo "Booting..."
booti ${kernel_addr_r} ${ramdisk_addr_r}:${ramdisk_size} ${fdt_addr_r}
