2015-01-08 21:08:48 +00:00
|
|
|
##
|
|
|
|
# Create disk image with contents of the run directory
|
|
|
|
#
|
|
|
|
# \param --image-disk-size disk size in MiB
|
|
|
|
#
|
|
|
|
|
2018-04-13 21:46:24 +00:00
|
|
|
source [genode_dir]/tool/run/grub2.inc
|
2015-01-08 21:08:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc image_disk_size { } { return [get_cmd_arg --image-disk-size 0] }
|
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
# Create disk image with the content of the run directory
|
|
|
|
#
|
|
|
|
proc run_image { {unused ""} } {
|
|
|
|
|
2018-06-19 17:55:04 +00:00
|
|
|
set sgdisk [installed_command sgdisk]
|
2018-04-13 21:46:24 +00:00
|
|
|
|
|
|
|
# make copy of template grub2 header image
|
|
|
|
exec cp [get_grub2_dir]/boot/grub2-head.img [run_dir].header
|
|
|
|
|
|
|
|
# remove template partition
|
2018-06-19 17:55:04 +00:00
|
|
|
exec $sgdisk --delete=3 [run_dir].header
|
2018-04-13 21:46:24 +00:00
|
|
|
|
|
|
|
# calculate size of grub2 header and the size of Genode scenario
|
|
|
|
set size_header [expr [regsub {\s.*} [exec du -b [run_dir].header] {}]]
|
|
|
|
set size_run [expr [regsub {\s.*} [exec du -skL [run_dir]] {}]]
|
2015-01-08 21:08:48 +00:00
|
|
|
|
|
|
|
if {[image_disk_size] > 0} {
|
2018-12-09 15:31:12 +00:00
|
|
|
set disk_size_kb [expr [image_disk_size] * 1024]
|
2015-01-08 21:08:48 +00:00
|
|
|
} else {
|
2018-05-22 22:43:43 +00:00
|
|
|
set disk_size_kb [expr ($size_run + 512) / 32 * 32]
|
2018-04-13 21:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# setup partition with content
|
|
|
|
exec dd if=/dev/zero of=[run_dir].partition bs=1k count=$disk_size_kb 2>/dev/null
|
2018-06-19 17:55:04 +00:00
|
|
|
exec [installed_command mkfs.ext2] -L GENODE -q -T default [run_dir].partition
|
2018-04-13 21:46:24 +00:00
|
|
|
|
|
|
|
# copy content to disk image
|
|
|
|
foreach file [exec find [run_dir]] {
|
|
|
|
set filename [string replace $file 0 [string length [run_dir]] ""]
|
|
|
|
if {[string length $filename] == 0} {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[file isdirectory $file]} {
|
2018-06-19 17:55:04 +00:00
|
|
|
exec [installed_command e2mkdir] [run_dir].partition:$filename
|
2018-04-13 21:46:24 +00:00
|
|
|
} else {
|
2018-06-19 17:55:04 +00:00
|
|
|
exec [installed_command e2cp] $file [run_dir].partition:$filename
|
2018-04-13 21:46:24 +00:00
|
|
|
}
|
2015-01-08 21:08:48 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:46:24 +00:00
|
|
|
# calculate start/end sector of content partition
|
|
|
|
set first_sector [expr $size_header / 512]
|
|
|
|
set last_sector [expr ((($size_header + ($disk_size_kb * 1024)) / 512) - 1)]
|
|
|
|
|
|
|
|
# add free space for the backup gpt at the end of disk
|
2018-06-19 17:55:04 +00:00
|
|
|
set sector_backup [exec $sgdisk --info=1 [run_dir].header]
|
2018-06-11 17:08:13 +00:00
|
|
|
set sector_backup [regexp -all -line -inline {First sector: ([0-9]+)} $sector_backup]
|
|
|
|
set sector_backup [lindex $sector_backup 1]
|
2015-01-08 21:08:48 +00:00
|
|
|
|
2018-04-13 21:46:24 +00:00
|
|
|
exec dd if=/dev/zero of=[run_dir].empty bs=512 count=$sector_backup 2>/dev/null
|
2015-01-08 21:08:48 +00:00
|
|
|
|
|
|
|
# merge final image from GRUB2 head and partition
|
2018-04-13 21:46:24 +00:00
|
|
|
exec cat [run_dir].header [run_dir].partition [run_dir].empty > [run_dir].img
|
2015-01-08 21:08:48 +00:00
|
|
|
|
2018-04-13 21:46:24 +00:00
|
|
|
# cleanup
|
|
|
|
exec rm [run_dir].empty
|
|
|
|
exec rm [run_dir].header
|
|
|
|
exec rm [run_dir].partition
|
2015-01-08 21:08:48 +00:00
|
|
|
|
2018-06-11 17:08:13 +00:00
|
|
|
# move backup GPT to the end of the disk
|
2018-06-19 17:55:04 +00:00
|
|
|
exec $sgdisk --move-second-header [run_dir].img
|
2018-06-11 17:08:13 +00:00
|
|
|
|
2018-04-13 21:46:24 +00:00
|
|
|
# create partition table entry pointing to the content
|
2018-06-19 17:55:04 +00:00
|
|
|
exec $sgdisk --new=3:$first_sector:$last_sector [run_dir].img
|
|
|
|
exec $sgdisk --change-name=3:GENODE [run_dir].img
|
2018-05-15 12:35:04 +00:00
|
|
|
|
|
|
|
# create hybrid MBR
|
2018-06-19 17:55:04 +00:00
|
|
|
exec $sgdisk --hybrid [run_dir].img
|
2018-05-15 12:35:04 +00:00
|
|
|
|
2018-04-13 21:46:24 +00:00
|
|
|
set size_image [expr [regsub {\s.*} [exec du -sk [run_dir].img] {}]]
|
|
|
|
puts "Created image file [run_dir].img (${size_image}kiB)"
|
2015-01-08 21:08:48 +00:00
|
|
|
}
|