
#
# settings
#
set interpose_part_blk 0

assert_spec foc
assert_spec exynos5

#
# build
#
set build_components {
	core
	init
	drivers/timer
	drivers/uart
	drivers/ahci
	drivers/platform
	l4linux
}

lappend_if $interpose_part_blk build_components server/part_blk

build $build_components
create_boot_directory

#
# genode config
#
set config  {
<config prio_levels="2">
	<parent-provides>
		<service name="ROM"/>
		<service name="RAM"/>
		<service name="IRQ"/>
		<service name="IO_MEM"/>
		<service name="IO_PORT"/>
		<service name="CAP"/>
		<service name="PD"/>
		<service name="RM"/>
		<service name="CPU"/>
		<service name="LOG"/>
		<service name="SIGNAL"/>
	</parent-provides>
	<default-route>
		<any-service><parent/><any-child/></any-service>
	</default-route>
	<start name="timer">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Timer"/></provides>
	</start>
	<start name="kdb_uart_drv">
		<resource name="RAM" quantum="1M"/>
		<provides>
			<service name="Terminal"/>
			<service name="Uart"/>
		</provides>
		<config><policy label="l4linux" uart="0" detect_size="yes"/></config>
	</start>
	<start name="ahci">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Block"/></provides>
	</start>
	<start name="platform_drv">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Regulator"/></provides>
	</start> }

append_if $interpose_part_blk config {
	<start name="part_blk">
		<resource name="RAM" quantum="10M" />
		<provides><service name="Block" /></provides>
		<route>
			<service name="Block"><child name="ahci" /></service>
			<any-service><parent/><any-child/></any-service>
		</route>
		<config>
			<policy label="l4linux -> sda" partition="0"/>
		</config>
	</start> }

append config {
	<start name="l4linux">
		<resource name="RAM" quantum="200M"/>
		<config args="mem=100M console=ttyS0 l4x_rd=initrd.gz l4x_cpus=2 l4x_cpus_map=0,1">
			<block label="sda" />
		</config> }

append_if $interpose_part_blk config {
		<route>
			<service name="Block"><child name="part_blk" /></service>
			<any-service><parent/><any-child/></any-service>
		</route> }

append config {
	</start>
</config> }

install_config $config

#
# boot modules
#
set boot_modules {
	core
	init
	timer
	kdb_uart_drv
	l4linux
	initrd.gz
	ahci
	platform_drv }

lappend_if $interpose_part_blk boot_modules part_blk

set uri "http://genode.org/files/l4linux/initrd-ahci-bench.gz"
if {![file exists bin/initrd.gz]} {
	puts "Download initramfs ..."
	exec >& /dev/null wget -c -O bin/initrd.gz $uri
}
exec >& /dev/null wget -O bin/initrd.gz.md5 $uri.md5
cd bin
exec md5sum -c initrd.gz.md5
cd ..

set fiasco_serial_esc_arg ""

build_boot_image  [join $boot_modules " "]

#
# qemu
#
append qemu_args " -m 512 -nographic "

#
# execute test
#
run_genode_until forever

