create_boot_directory


import_from_depot [depot_user]/src/[base_src] \
                  [depot_user]/src/acpi_drv \
                  [depot_user]/src/ahci_drv \
                  [depot_user]/src/init \
                  [depot_user]/src/libc \
                  [depot_user]/src/ncurses \
                  [depot_user]/src/platform_drv \
                  [depot_user]/src/posix \
                  [depot_user]/src/report_rom \
                  [depot_user]/src/stdcxx \
                  [depot_user]/src/vfs


build { app/sgdisk }

set config {
	<config verbose="yes">
		<parent-provides>
			<service name="CPU"/>
			<service name="IO_MEM"/>
			<service name="IO_PORT"/>
			<service name="IRQ"/>
			<service name="LOG"/>
			<service name="PD"/>
			<service name="RM"/>
			<service name="ROM"/>
		</parent-provides>

		<start name="timer" caps="100">
			<resource name="RAM" quantum="10M"/>
			<provides>
				<service name="Timer"/>
			</provides>
			<route>
				<any-service> <parent/> <any-child/> </any-service>
			</route>
		</start>

		<start name="report_rom" caps="300">
			<resource name="RAM" quantum="2M"/>
			<provides>
				<service name="Report"/>
				<service name="ROM"/>
			</provides>
			<config verbose="yes">
				<policy label="platform_drv -> acpi" report="acpi_drv -> acpi"/>
			</config>
			<route>
				<any-service> <parent/> <any-child/> </any-service>
			</route>
		</start>

		<start name="acpi_drv" caps="300">
			<resource name="RAM" quantum="4M"/>
			<route>
				<any-service> <parent/> <any-child/> </any-service>
			</route>
		</start>

		<start name="platform_drv" caps="200">
			<resource name="RAM" quantum="3M" constrain_phys="yes"/>
			<provides>
				<service name="Platform"/>
				<service name="Acpi"/>
			</provides>
			<config>
				<policy label_prefix="ahci_drv"> <pci class="AHCI"/> </policy>
			</config>
			<route>
				<service name="ROM" label="acpi"> <child name="report_rom"/> </service>
				<any-service> <parent/> <any-child/> </any-service>
			</route>
		</start>

		<start name="ahci_drv" caps="100">
			<resource name="RAM" quantum="10M"/>
			<provides>
				<service name="Block"/>
			</provides>
			<config>
				<default-policy device="0" writeable="yes"/>
			</config>
			<route>
				<any-service> <parent/> <any-child/> </any-service>
			</route>
		</start>

		<start name="sgdisk" caps="100">
			<resource name="RAM" quantum="8M"/>
			<config>
				<libc stdout="/dev/log" stderr="/dev/log"/>
				<vfs>
					<dir name="dev">
						<block name="block"/>
						<inline name="rtc">2000-01-01 00:00</inline>
						<log/>
					</dir>
				</vfs>
				<arg value="sgdisk"/>
				<arg value="--new=1:2048:10239"/>
				<arg value="--change-name=1:boot"/>
				<arg value="--new=2:10240:28671"/>
				<arg value="--change-name=2:root"/>
				<arg value="--new=3:28672:40926"/>
				<arg value="--change-name=3:stuff"/>
				<arg value="-p"/>
				<arg value="/dev/block"/>
			</config>
			<route>
				<any-service> <parent/> <any-child/> </any-service>
			</route>
		</start>

	</config>
}

install_config $config


build_boot_image {
	sgdisk
	libuuid.lib.so
	popt.lib.so
}


# Create empty image file!
set image_file "bin/image.raw"
set image_size 20
eval "exec -ignorestderr dd if=/dev/zero of=$image_file bs=1M count=$image_size"


append qemu_args " -nographic -device ahci,id=ahci "
append qemu_args " -drive id=disk,file=$image_file,format=raw,if=none -device ide-hd,drive=disk,bus=ahci.0 -boot d "


run_genode_until ".*child \"sgdisk\" exited.*\n" 20
