create_boot_directory

import_from_depot [depot_user]/src/[base_src] \
                  [depot_user]/pkg/[drivers_interactive_pkg] \
                  [depot_user]/pkg/fonts_fs \
                  [depot_user]/pkg/backdrop \
                  [depot_user]/src/dynamic_rom \
                  [depot_user]/src/report_rom \
                  [depot_user]/src/fs_rom \
                  [depot_user]/src/fs_report \
                  [depot_user]/src/nitpicker \
                  [depot_user]/src/init \
                  [depot_user]/src/libc \
                  [depot_user]/src/wm \
                  [depot_user]/src/themed_decorator \
                  [depot_user]/src/nic_router \
                  [depot_user]/src/gui_fb \
                  [depot_user]/src/gui_fader \
                  [depot_user]/src/libpng \
                  [depot_user]/src/zlib \
                  [depot_user]/src/menu_view \
                  [depot_user]/src/fs_query \
                  [depot_user]/src/rom_filter \
                  [depot_user]/src/terminal \
                  [depot_user]/src/posix \
                  [depot_user]/src/vfs_block \
                  [depot_user]/src/part_block \
                  [depot_user]/src/rump \
                  [depot_user]/src/ncurses \
                  [depot_user]/src/usb_block_drv \
                  [depot_user]/src/bash-minimal \
                  [depot_user]/src/vim-minimal \
                  [depot_user]/src/coreutils-minimal \
                  [depot_user]/src/fs_utils \
                  [depot_user]/src/vfs_pipe \
                  [depot_user]/src/vfs_import \
                  [depot_user]/src/stdin2out \
                  [depot_user]/src/gpt_write \
                  [depot_user]/src/text_area \
                  [depot_user]/src/sandbox \
                  [depot_user]/src/window_layouter

install_config {
<config>
	<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"/>
	</parent-provides>

	<resource name="RAM" preserve="2M"/>

	<default-route>
		<any-service> <parent/> <any-child/> </any-service>
	</default-route>
	<default caps="100"/>

	<start name="timer">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Timer"/> </provides>
	</start>

	<start name="drivers" caps="1500">
		<resource name="RAM" quantum="64M" constrain_phys="yes"/>
		<binary name="init"/>
		<route>
			<service name="ROM" label="config"> <parent label="drivers.config"/> </service>
			<service name="Timer"> <child name="timer"/> </service>
			<any-service> <parent/> </any-service>
		</route>
		<provides>
			<service name="Input"/> <service name="Framebuffer"/>
		</provides>
	</start>

	<start name="report_rom">
		<binary name="report_rom"/>
		<resource name="RAM" quantum="2M"/>
		<provides> <service name="Report"/> <service name="ROM"/> </provides>
		<config verbose="no">
			<policy label="leitzentrale -> manager -> nitpicker_hover"
			        report="nitpicker -> hover"/>
			<policy label="leitzentrale -> manager -> displays"
			        report="nitpicker -> displays"/>
			<policy label="clipboard" report="clipboard"/>
		</config>
	</start>

	<start name="nitpicker">
		<resource name="RAM" quantum="4M"/>
		<provides><service name="Gui"/></provides>
		<config focus="rom">
			<report hover="yes" displays="yes"/>
			<background color="#000000"/>
			<domain name="pointer" layer="1" content="client" label="no" origin="pointer" />
			<domain name="default" layer="3" content="client" label="no" hover="always" />

			<policy label_prefix="pointer" domain="pointer"/>
			<default-policy domain="default"/>
		</config>
		<route>
			<service name="Report"> <child name="report_rom"/> </service>
			<any-service> <parent/> <any-child/></any-service>
		</route>
	</start>

	<start name="pointer">
		<resource name="RAM" quantum="1M"/>
		<route>
			<service name="Gui"> <child name="nitpicker" /> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>

	<start name="config_fs">
		<binary name="vfs"/>
		<resource name="RAM" quantum="4M"/>
		<provides> <service name="File_system"/> </provides>
		<config>
			<vfs>
				<ram/>
				<import>
					<dir name="managed">
						<rom name="fonts" label="fonts.config"/>
						<inline name="runtime"><config/></inline>
						<inline name="depot_query"><query/></inline>
					</dir>
					<inline name="deploy"></inline>
				</import>
			</vfs>
			<default-policy root="/" writeable="yes"/>
		</config>
	</start>

	<start name="config_rom">
		<resource name="RAM" quantum="1M"/>
		<binary name="fs_rom"/>
		<provides> <service name="ROM"/> </provides>
		<config/>
		<route>
			<service name="File_system"> <child name="config_fs"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="report_fs">
		<binary name="vfs"/>
		<resource name="RAM" quantum="4M"/>
		<provides> <service name="File_system"/> </provides>
		<config>
			<vfs>
				<ram/>
				<import>
					<inline name="log">See the core log for messages.</inline>
				</import>
			</vfs>
			<policy label="ro" root="/"/>
			<default-policy root="/" writeable="yes"/>
		</config>
	</start>

	<start name="fs_report">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Report"/> </provides>
		<config> <vfs> <fs/> </vfs> </config>
		<route>
			<service name="File_system"> <child name="report_fs"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="report_fs_rom">
		<resource name="RAM" quantum="1M"/>
		<binary name="fs_rom"/>
		<provides> <service name="ROM"/> </provides>
		<config/>
		<route>
			<service name="File_system"> <child name="report_fs"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="leitzentrale_config">
		<binary name="rom_filter"/>
		<resource name="RAM" quantum="1M"/>
		<provides><service name="ROM"/></provides>
		<route>
			<service name="ROM" label="config">
				<parent label="leitzentrale.config"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="usb_active_config_rom">
		<binary name="dynamic_rom"/>
		<resource name="RAM" quantum="4M"/>
		<provides> <service name="ROM"/> </provides>
		<config>
			<rom name="usb_active_config">
				<sleep milliseconds="500000" />
				<inline description="USB storage present">
					<config>
						<raw> <policy label_suffix="usb-1-2" class="storage"/> </raw>
					</config>
				</inline>
				<sleep milliseconds="500000" />
				<inline description="USB storage absent">
					<config/>
				</inline>
				<sleep milliseconds="500000" />
			</rom>
		</config>
	</start>

	<start name="ahci-1" ld="no">
		<binary name="lx_block"/>
		<resource name="RAM" quantum="2M"/>
		<provides> <service name="Block"/> </provides>
		<config file="ahci-1.img" block_size="512" writeable="yes"/>
	</start>

	<start name="ahci-2">
		<binary name="vfs_block"/>
		<resource name="RAM" quantum="10M"/>
		<provides> <service name="Block"/> </provides>
		<config>
			<vfs>
				<ram/>
				<import>
					<zero name="block_file" size="8M"/>
				</import>
			</vfs>
			<default-policy file="/block_file" block_size="512"
			                writeable="yes"/>
		</config>
	</start>

	<start name="leitzentrale" caps="2300">
		<binary name="init"/>
		<resource name="RAM" quantum="122M"/>
		<provides>
			<service name="Gui"/>
			<service name="File_system"/>
			<service name="Report"/>
			<service name="ROM"/>
		</provides>
		<route>
			<service name="ROM" label="config">
				<child name="leitzentrale_config"/> </service>
			<service name="ROM" label_prefix="manager -> config -> ">
				<child name="config_rom"/> </service>
			<service name="Gui"> <child name="nitpicker"/> </service>
			<service name="Timer"> <child name="timer"/> </service>
			<service name="File_system" label="config">
				<child name="config_fs" label="rw"/> </service>
			<service name="File_system" label="report">
				<child name="report_fs" label="ro"/> </service>
			<service name="Report"> <child name="fs_report"/> </service>
			<service name="ROM" label_last="drivers/block_devices">
				<parent label="block_devices"/> </service>
			<service name="ROM" label_last="drivers/usb_active_config">
				<child name="usb_active_config_rom" label="usb_active_config"/> </service>
			<service name="ROM" label_last="runtime/state">
				<child name="report_fs_rom" label="runtime/state"/> </service>
			<service name="ROM" label_last="deploy">
				<child name="config_rom"/> </service>
			<service name="ROM" label_last="managed/fonts">
				<child name="config_rom" label="managed/fonts"/> </service>
			<service name="ROM" label_prefix="manager -> report">
				<child name="report_fs_rom"/> </service>
			<service name="ROM" label="manager -> nitpicker_hover">
				<child name="report_rom"/> </service>
			<service name="ROM" label="manager -> displays">
				<child name="report_rom"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="runtime" caps="50000">
		<binary name="init"/>
		<resource name="RAM" quantum="1G"/>
		<route>
			<service name="ROM" label="config">
				<child name="config_rom" label="managed/runtime"/> </service>
			<service name="ROM" label_prefix="config -> ">
				<child name="config_rom"/> </service>
			<service name="ROM" label_prefix="leitzentrale ->">
				<child name="leitzentrale"/> </service>
			<service name="ROM" label="inspect -> clipboard">
				<child name="report_rom" label="clipboard"/> </service>
			<service name="ROM" label="editor -> clipboard">
				<child name="report_rom" label="clipboard"/> </service>
			<service name="ROM" label_last="cached_fs_rom"> <!-- for Linux -->
				<parent label="fs_rom"/> </service>
			<service name="Report" label="inspect -> clipboard">
				<child name="report_rom" label="clipboard"/> </service>
			<service name="Report" label="editor -> clipboard">
				<child name="report_rom" label="clipboard"/> </service>
			<service name="File_system" label="config">
				<child name="config_fs" label="rw"/> </service>
			<service name="File_system" label="report">
				<child name="report_fs" label="ro"/> </service>
			<service name="File_system" label="leitzentrale -> fonts">
				<child name="leitzentrale" label="fonts"/> </service>
			<service name="Block" label_last="ahci-1"> <child name="ahci-1"/> </service>
			<service name="Block" label_last="ahci-2"> <child name="ahci-2"/> </service>
			<service name="Block"> <child name="drivers"/> </service>
			<service name="Gui" label_prefix="leitzentrale">
				<child name="leitzentrale"/> </service>
			<service name="Gui"> <child name="nitpicker"/> </service>
			<service name="Timer"> <child name="timer"/> </service>
			<service name="Report" label_prefix="leitzentrale ->">
				<child name="leitzentrale"/> </service>
			<service name="Report"> <child name="fs_report"/> </service>
			<service name="Report"> <child name="fs_report"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

</config>}

file copy -force [genode_dir]/repos/gems/run/sculpt/fonts.config          [run_dir]/genode/
file copy -force [genode_dir]/repos/gems/run/sculpt/leitzentrale.config   [run_dir]/genode/
file copy -force [genode_dir]/repos/gems/run/sculpt/vimrc                 [run_dir]/genode/
file copy -force [genode_dir]/repos/gems/src/app/backdrop/genode_logo.png [run_dir]/genode/
file copy -force [genode_dir]/repos/gems/run/sculpt/drop_shadow.png       [run_dir]/genode/

proc install_rom_module { name content } {
	set fd [open [run_dir]/genode/$name w]
	puts $fd $content
	close $fd
}

# generate disk image with GPT partition table
proc ahci_1_img { } { return "bin/ahci-1.img" }

catch { exec dd if=/dev/zero of=[ahci_1_img] bs=1M count=10 }
exec parted -a none -s [ahci_1_img] -- mklabel gpt \
                                       mkpart BOOT   fat32  256s 1023s \
                                       mkpart GRUB   fat32 1024s 1279s \
                                       mkpart GENODE ext2  1280s 3700s

install_rom_module focus         {<focus label="leitzentrale -> manager -> fader -> "/>}
install_rom_module leitzentrale  {<leitzentrale enabled="yes"/>}
install_rom_module reset         {<reset enabled="no"/>}
install_rom_module README        {nothing to read here}
install_rom_module VERSION       {unknown version}
install_rom_module platform_info {<empty/>}

install_rom_module block_devices {
<block_devices>
	<device label="ahci-1" block_count="123" block_size="1024" model="Model"/>
	<device label="ahci-2" block_count="123" block_size="1024" model="Broken"/>
</block_devices>}

install_rom_module usb_active_config {
<config>
	<raw> <policy label_suffix="usb-1-2" class="storage"/> </raw>
</config>}

build { server/lx_block app/menu_view app/sculpt_manager }

build_boot_image { lx_block menu_view sculpt_manager ahci-1.img }

run_genode_until forever

