run: modularize run tool

This commit is contained in:
Josef Söntgen
2015-01-08 22:08:48 +01:00
committed by Christian Helmuth
parent febca1b827
commit c706b1c0a7
36 changed files with 2152 additions and 1969 deletions

49
tool/run/image/disk Normal file
View File

@@ -0,0 +1,49 @@
##
# Create disk image with contents of the run directory
#
# \param --image-disk-size disk size in MiB
#
source [genode_dir]/tool/run/iso.inc
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 ""} } {
requires_installation_of parted
requires_installation_of resize2fs
requires_installation_of fallocate
set grub_img "[genode_dir]/tool/grub2-head.img"
set disk_img "[run_dir].img"
set part1_img "[run_dir]-part1.img"
set run_size [expr [regsub {\s.*} [exec du -sm [run_dir]] {}] + 4]
if {[image_disk_size] > 0} {
set disk_size [image_disk_size]
} else {
set disk_size $run_size
}
set part1_size [expr $disk_size - 1]MiB
# extract and resize partition image
exec dd if=$grub_img of=$part1_img bs=1M skip=1 2>/dev/null
exec fallocate -l $part1_size $part1_img
exec resize2fs $part1_img 2>/dev/null
# populate partition with binaries
exec [genode_dir]/tool/rump -F ext2fs -p [run_dir] $part1_img
# merge final image from GRUB2 head and partition
exec dd if=$grub_img of=$disk_img status=noxfer bs=1M count=1 2>/dev/null
exec dd if=$part1_img of=$disk_img status=noxfer bs=1M seek=1 2>/dev/null
exec parted -s $disk_img -- rm 1 mkpart primary 2048s -1s set 1 boot on
exec rm -f $part1_img
puts "Created image file $disk_img ($disk_size MiB)"
}

20
tool/run/image/iso Normal file
View File

@@ -0,0 +1,20 @@
source [genode_dir]/tool/run/iso.inc
##
# Create ISO image with the content of the run directory
#
proc run_image { {unused ""} } {
puts "creating ISO image..."
exec rm -f "[run_dir].iso"
#
# The 'create_iso' writes diagnostics to stderr, which are interpreted as
# execution failure by expect unless '-ignorestderr' is set on 'exec'.
#
if {[catch {exec -ignorestderr [genode_dir]/tool/create_iso iso ISO=[run_dir]} ]} {
puts stderr "Error: ISO image creation failed"
exit -5
}
}

47
tool/run/image/uboot Normal file
View File

@@ -0,0 +1,47 @@
##
# Build U-boot bootloader specific uImage
#
# \param --image-uboot-no-gzip do not gzip the uImage
#
##
# Check if the uImage should be gzipped
#
proc image_uboot_use_no_gzip { } { return [get_cmd_switch --image-uboot-no-gzip] }
##
# Build U-boot bootloader specific uImage
#
# \param elf_img ELF binary to build uImage from
#
proc run_image {elf_img} {
# parse ELF entrypoint and load address
set entrypoint [exec [cross_dev_prefix]readelf -h $elf_img | \
grep "Entry point address: " | \
sed -e "s/.*Entry point address: *//"]
set load_addr [exec [cross_dev_prefix]readelf -l $elf_img | \
grep -m 1 "LOAD"]
set load_addr [lindex [regexp -inline -all -- {\S+} $load_addr] 3]
set bin_img "[run_dir]/image.bin"
exec [cross_dev_prefix]objcopy -O binary $elf_img $bin_img
set use_gzip [expr ![image_uboot_use_no_gzip]]
set compress_type none
set bin_ext ""
# compress ELF
if $use_gzip {
exec gzip --best --force $bin_img
set bin_ext .gz
set compress_type gzip
}
# create uImage
set uboot_img [run_dir]/uImage
exec mkimage -A arm -O linux -T kernel -C $compress_type -a $load_addr \
-e $entrypoint -d $bin_img$bin_ext $uboot_img
exec rm -rf $bin_img$bin_ext
}