#
# \brief  Virtual-machine monitor demo
# \author Stefan Kalkowski
# \author Martin Stein
# \date   2012-06-25
#

assert_spec hw

if {![have_board imx53_qsb_tz]} {

	puts "\n Run script is not supported on this platform. \n"
	exit 0
}

build { core init server/tz_vmm }

create_boot_directory

# compose config
install_config {
<config verbose="yes">

	<parent-provides>
		<service name="ROM"/>
		<service name="IRQ"/>
		<service name="IO_MEM"/>
		<service name="IO_PORT"/>
		<service name="PD"/>
		<service name="RM"/>
		<service name="CPU"/>
		<service name="LOG"/>
		<service name="VM"/>
	</parent-provides>
	<default-route>
		<any-service><any-child/><parent/></any-service>
	</default-route>
	<default caps="100"/>

	<start name="imx53_qsb_tz_vmm">
		<resource name="RAM" quantum="10M"/>
	</start>

</config> }

# download and add linux
cd bin
set linux_uri "http://genode.org/files/images/imx53_qsb/linux_trustzone.bin"
if {![file exists linux]} {
	puts "Download linux binary ..."
	exec >& /dev/null wget -c -O linux $linux_uri
}
exec >& /dev/null wget -O linux.md5 $linux_uri.md5
exec md5sum -c linux.md5

# download and add initrd
set initrd_uri  "http://genode.org/files/images/imx53_qsb/initrd.gz"
if {![file exists initrd.gz]} {
	puts "Download initramfs ..."
	exec >& /dev/null wget -c -O initrd.gz $initrd_uri
}
exec >& /dev/null wget -O initrd.gz.md5 $initrd_uri.md5
exec md5sum -c initrd.gz.md5
cd ..

build_boot_image { core ld.lib.so init linux imx53_qsb_tz_vmm initrd.gz }

# execute and wait for console
run_genode_until {.*\/ #.*} 220
set serial_id [output_spawn_id]

# wait for network to settle down
send -i $serial_id "sleep 5\n"

# test network
send -i $serial_id "ping 1.1.1.1\n"
run_genode_until "64 bytes from 1.1.1.1:.*\n" 30 $serial_id