echo "Trying to boot Linux from device ${target}";

if test ${target} = "mmc0"; then
	if test -e ${devtype} ${devnum}:${distro_bootpart} /${bootfile}; then
		echo "Found kernel in mmc0";		
		mmc rescan;
		fatload ${devtype} ${devnum}:${distro_bootpart} ${loadaddr} ${bootfile};
		setenv bootargs "earlycon panic=-1 root=${mmcroot} rw rootwait";		
		bootm ${loadaddr}#board-${board_id};
		exit;
	fi
fi

if test ${target} = "qspi"; then
	mtdparts;
	ubi part root;
	ubi readvol ${loadaddr} kernel;
	ubi detach;
	setenv bootargs "earlycon panic=-1 ubi.mtd=1 root=ubi0:rootfs rootfstype=ubifs rw rootwait";
	bootm ${loadaddr}#board-${board_id};
fi

if test ${target} = "nand"; then
	setenv mtdids "nor0=nor0,nand0=ffb90000.nand.0";
	setenv mtdparts "mtdparts=nor0:66m(u-boot),190m(qspi_root);ffb90000.nand.0:2m(u-boot),-(root)";
	env select UBI;
	saveenv;
	mtdparts;
	ubi part root;
	ubi readvol ${loadaddr} kernel;
	ubi detach;
	setenv bootargs "earlycon panic=-1 root=${nandroot} rw rootwait rootfstype=ubifs ubi.mtd=1";
	bootm ${loadaddr}#board-${board_id};
fi
