assert_spec foc

#
# Build
#
set build_components {
	core
	init
	drivers/timer
	drivers/framebuffer
	server/nic_bridge
	server/nitpicker
	server/nit_fb
	server/terminal
	server/terminal_log
	l4linux
}

lappend_if [have_spec     x86] build_components drivers/nic
lappend_if [have_spec     pci] build_components drivers/pci
lappend_if [have_spec     ps2] build_components drivers/input/ps2
lappend_if [have_spec lan9118] build_components drivers/nic
lappend_if [have_spec     usb] build_components drivers/usb

build $build_components
create_boot_directory

#
# Config
#
set config  {
<config>
	<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> }

append_if [have_spec pci] config {
	<start name="pci_drv">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="PCI"/></provides>
	</start>}

append_if [have_spec vesa] config {
	<start name="fb_drv">
		<binary name="vesa_drv"/>
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Framebuffer"/></provides>
	</start> }

append_if [have_spec pl11x] config {
	<start name="fb_drv">
		<binary name="pl11x_drv"/>
		<resource name="RAM" quantum="2M"/>
		<provides><service name="Framebuffer"/></provides>
	</start> }

append_if [have_spec omap4] config {
	<start name="fb_drv">
		<binary name="omap4_fb_drv"/>
		<resource name="RAM" quantum="4M"/>
		<provides><service name="Framebuffer"/></provides>
	</start>}

append_if [have_spec ps2] config {
	<start name="input_drv">
		<binary name="ps2_drv"/>
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Input"/></provides>
	</start>}

append_if [expr ![have_spec ps2] && [have_spec usb]] config {
	<start name="input_drv">
		<binary name="usb_drv"/>
		<resource name="RAM" quantum="3M"/>
		<provides><service name="Input"/></provides>
		<config> <hid/> </config>
	</start> }

append_if [have_spec x86] config {
	<start name="nic_drv">
		<resource name="RAM" quantum="2M"/>
		<provides><service name="Nic"/></provides>
	</start>}

append_if [have_spec lan9118] config {
	<start name="nic_drv">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Nic"/></provides>
	</start> }

append config {
<!--
	<start name="nic_bridge">
		<resource name="RAM" quantum="2M"/>
		<provides><service name="Nic"/></provides>
		<route>
			<service name="Nic"> <child name="nic_drv"/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
-->
	<start name="nitpicker">
		<resource name="RAM" quantum="2M"/>
		<provides><service name="Nitpicker"/></provides>
		<route>
			<service name="Input">       <child name="input_drv"/> </service>
			<service name="Framebuffer"> <child name="fb_drv"/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
	<start name="linux.1">
		<binary name="nit_fb"/>
		<resource name="RAM" quantum="4M"/>
		<provides>
			<service name="Framebuffer"/>
			<service name="Input"/>
		</provides>
		<config xpos="1" ypos="0" width="510" height="382" refresh_rate="25"/>
	</start>
	<start name="linux.2">
		<binary name="nit_fb"/>
		<resource name="RAM" quantum="4M"/>
		<provides>
			<service name="Framebuffer"/>
			<service name="Input"/>
		</provides>
		<config xpos="513" ypos="0" width="510" height="382" refresh_rate="25"/>
	</start>
	<start name="log">
		<binary name="nit_fb"/>
		<resource name="RAM" quantum="4M"/>
		<provides>
			<service name="Framebuffer"/>
			<service name="Input"/>
		</provides>
		<config xpos="1" ypos="385" width="1022" height="376" refresh_rate="25"/>
	</start>
	<start name="log_term">
		<binary name="terminal"/>
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Terminal"/></provides>
		<route>
			<service name="Input">       <child name="log"/> </service>
			<service name="Framebuffer"> <child name="log"/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
	<start name="terminal_log">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="LOG"/></provides>
	</start>
	<start name="vmlinux.1">
		<binary name="l4linux"/>
		<resource name="RAM" quantum="96M"/>
		<config args="mem=54M l4x_rd=initrd.gz"/>
		<route>
			<service name="Input">       <child name="linux.1"/> </service>
			<service name="Framebuffer"> <child name="linux.1"/> </service>
			<!-- <service name="Nic">         <child name="nic_bridge"/> </service> -->
			<service name="LOG">         <child name="terminal_log"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>
	<start name="vmlinux.2">
		<binary name="l4linux"/>
		<resource name="RAM" quantum="96M"/>
		<config args="mem=54M l4x_rd=initrd.gz"/>
		<route>
			<service name="Input">       <child name="linux.2"/> </service>
			<service name="Framebuffer"> <child name="linux.2"/> </service>
			<!-- <service name="Nic">         <child name="nic_bridge"/> </service> -->
			<service name="LOG">         <child name="terminal_log"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>
</config>}

install_config $config

#
# Boot modules
#
set boot_modules {
	core
	init
	timer
	nic_bridge
	nitpicker
	nit_fb
	terminal
	terminal_log
	l4linux
	initrd.gz
}
lappend_if [have_spec     pci] boot_modules pci_drv
lappend_if [have_spec     ps2] boot_modules ps2_drv
lappend_if [have_spec   pl11x] boot_modules pl11x_drv
lappend_if [have_spec    vesa] boot_modules vesa_drv
lappend_if [have_spec     x86] boot_modules nic_drv
lappend_if [have_spec lan9118] boot_modules nic_drv
lappend_if [have_spec   omap4] boot_modules omap4_fb_drv
lappend_if [have_spec   usb]   boot_modules usb_drv

if {[have_spec x86]} {
	set uri "https://github.com/downloads/skalk/genode/busybox-initrd-x86-20120618.gz"
} elseif {[have_spec arm]} {
	set uri "https://github.com/downloads/skalk/genode/busybox-initrd-arm-20120618.gz"
}
if {![file exists bin/initrd.gz]} {
	puts "Download initramfs ..."
	exec >& /dev/null wget -c -O bin/initrd.gz $uri
}

build_boot_image  [join $boot_modules " "]

#
# Qemu
#
append qemu_args " -m 256 "
append qemu_args " -serial mon:stdio "
append_if [have_spec     x86] qemu_args " -net nic,model=e1000 -net user "
append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 -net user "

#
# Execute test case
#
run_genode_until forever