setenv bootargs ''

setenv initrd_high 0xffffffff
	
a_base=0x70000000
a_script=0x70800000
a_zImage=0x70800000
a_fdt=0x73000000
a_ramdisk=0x73800000
a_initrd=0x73a00000
a_reset_cause_marker=0x70000080
a_reset_cause=0x70000084
dtbname=imx53-qsb.dtb

if itest.s x${console} == x ; then
	console=ttymxc0
fi

if itest.s x${dtype} == x ; then
	dtype=mmc
fi

if itest.s x${rfspart} == x ; then
	rfspart=1
fi

if itest.s x${disk} == x ; then
	disk=0
fi

if load ${dtype} ${disk}:1 ${a_script} uEnv.txt ; then
    env import -t ${a_script} ${filesize}
fi

if itest.s x == x${bootdir} ; then
	bootdir=/boot/
fi

if itest.s x${bootpart} == x ; then
	bootpart=1
fi


if load ${dtype} ${disk}:${bootpart} ${a_fdt} ${bootdir}dtbs/${dtbname} ; then
	fdt addr ${a_fdt}
	setenv fdt_high 0xffffffff
else
	echo "!!!! Error loading ${bootdir}dtbs/${dtbname}";
	exit;
fi

fdt resize
if itest.s "x" != "x${cmd_custom}" ; then
	run cmd_custom
fi

## HDMI ##
if itest.s "xoff" == "x$fb_hdmi" ; then
	setenv bootargs $bootargs video=HDMI-A-1:d
else
	if itest.s "x" != "x$force_edid" ; then
		echo "------ forcing EDID to /lib/firmware/$force_edid"
		setenv bootargs $bootargs drm_kms_helper.edid_firmware=$force_edid
	fi
fi

## LVDS ##
if itest.s "xoff" == "x$fb_lvds" ; then
	setenv bootargs $bootargs video=LVDS-1:d
elif itest.s "xhannstar7" == "x$fb_lvds" ; then
	fdt set /panel-lvds0 compatible "hannstar,hsd070pww1"
elif itest.s "xtm070jdhg30" == "x$fb_lvds" ; then
	fdt set /panel-lvds0 compatible "tianma,tm070jdhg30"
elif itest.s "xdt070btft" == "x$fb_lvds" ; then
	fdt set /panel-lvds0 compatible "innolux,zj070na-01p"
fi

if itest.s "xoff" == "x$fb_lvds2" ; then
	setenv bootargs $bootargs video=LVDS-2:d
elif itest.s "xhannstar7" == "x$fb_lvds2" ; then
	fdt set /panel-lvds1 compatible "hannstar,hsd070pww1"
elif itest.s "xtm070jdhg30" == "x$fb_lvds2" ; then
	fdt set /panel-lvds1 compatible "tianma,tm070jdhg30"
elif itest.s "xdt070btft" == "x$fb_lvds2" ; then
	fdt set /panel-lvds1 compatible "innolux,zj070na-01p"
fi

## LCD ##
if itest.s "xoff" == "x$fb_lcd" ; then
	setenv bootargs $bootargs video=VGA-1:d
fi

if itest.s x${rfspart} == x ; then
	rfspart=1
fi

if itest.s "x" == "x${root}"; then
	part uuid ${dtype} ${disk}:${rfspart} uuid
	if itest.s "x" != "x${uuid}"; then
		root=PARTUUID=${uuid}
	elif test "sata" = "${dtype}" || test "usb" = "${dtype}" ; then
		root=/dev/sda${rfspart}
	else
		root=/dev/mmcblk${disk}p${rfspart}
	fi
fi

if itest.s "x" == "x$cma" ; then
	cma=256M
fi

if itest.s "x" == "x$vmalloc" ; then
	vmalloc=400M
fi

if itest.s "x" != "x$show_fdt" ; then
	fdt print /
fi

if itest.s "x" != "x$show_env" ; then
	printenv
fi

setenv bootargs "$bootargs console=${console},115200 vmalloc=${vmalloc}"
setenv bootargs "$bootargs cma=${cma} consoleblank=0 root=${root} rootwait"

if itest.s "x" != "x${loglevel}" ; then
	setenv bootargs ${bootargs} loglevel=${loglevel}
fi

if itest *${a_reset_cause_marker} == 12345678 ; then
	setexpr.l reset_cause *${a_reset_cause}
	setenv bootargs $bootargs reset_cause=0x${reset_cause}
fi

if load ${dtype} ${disk}:${bootpart} ${a_zImage} ${bootdir}zImage; then
	bootz ${a_zImage} - ${a_fdt}
fi
echo "Error loading kernel image"