diff --git a/build b/build index 68357f5..74b81d1 100755 --- a/build +++ b/build @@ -4,6 +4,7 @@ import multiprocessing import os import pathlib import shlex +import shutil import subprocess import sys import re @@ -90,8 +91,6 @@ def main(args, extra_args=None): path_relative_to_buildroot(os.path.join(common.root_dir, 'rootfs_overlay'))), 'BR2_ROOTFS_POST_BUILD_SCRIPT="{}"'.format( path_relative_to_buildroot(os.path.join(common.root_dir, 'rootfs_post_build_script'))), - 'BR2_ROOTFS_POST_IMAGE_SCRIPT="{}"'.format( - path_relative_to_buildroot(os.path.join(common.root_dir, 'rootfs_post_image_script'))), 'BR2_ROOTFS_USERS_TABLES="{}"'.format( path_relative_to_buildroot(os.path.join(common.root_dir, 'user_table'))), ]) @@ -181,20 +180,16 @@ def main(args, extra_args=None): common.mkdir() - ## Manage Linux kernel and QEMU variants. - #symlink_buildroot_variant() ( - # custom_dir="$1" - # variant_dir="$2" - # if [ -h "$custom_dir" ]; then - # rm "$custom_dir" - # elif [ -d "$custom_dir" ]; then - # # Migration for existing builds. - # mv "$custom_dir" "$variant_dir" - # fi - # mkdir -p "$variant_dir" - # ln -s "$variant_dir" "$custom_dir" - #) - #symlink_buildroot_variant "$common_linux_build_dir" "$common_linux_variant_dir" + # Manage Linux kernel and QEMU variants. + def symlink_buildroot_variant(custom_dir, variant_dir): + if os.path.islink(custom_dir): + os.unlink(custom_dir) + elif os.path.isdir(custom_dir): + # Migration for existing builds. + shutil.move(custom_dir, variant_dir) + os.makedirs(variant_dir, exist_ok=True) + os.symlink(variant_dir, custom_dir) + symlink_buildroot_variant(common.linux_build_dir, common.linux_variant_dir) ## Manage gem5 variants. #if "$common_gem5"; then @@ -203,7 +198,7 @@ def main(args, extra_args=None): # fi #fi - return common.run_cmd( + assert common.run_cmd( [ 'make', 'O={}'.format(common.buildroot_out_dir), @@ -215,7 +210,20 @@ def main(args, extra_args=None): out_file=os.path.join(common.out_arch_dir, 'buildroot.log'), delete_env=['LD_LIBRARY_PATH'], cwd=common.buildroot_dir, - ) + ) == 0 + + # Create the qcow2 from ext2. + assert common.run_cmd([ + common.qemu_img_executable, + '-T', 'pr_manager_run,file=/dev/null', + 'convert', + '-f', 'raw', + '-O', 'qcow2', + common.ext2_file, + common.qcow2_file, + ]) == 0 + + return 0 def get_argparse(): parser = common.get_argparse(argparse_args={'description':'Run Linux on an emulator'}) diff --git a/common.py b/common.py index 887a181..646a593 100644 --- a/common.py +++ b/common.py @@ -299,6 +299,7 @@ def setup(parser, **extra_args): this.vmlinux = os.path.join(this.linux_variant_dir, "vmlinux") this.qemu_build_dir = os.path.join(this.common_dir, 'qemu', args.qemu_build_id) this.qemu_executable = os.path.join(this.qemu_build_dir, '{}-softmmu'.format(args.arch), 'qemu-system-{}'.format(args.arch)) + this.qemu_img_executable = os.path.join(this.qemu_build_dir, 'qemu-img') this.qemu_guest_build_dir = os.path.join(this.build_dir, 'qemu-custom') this.host_dir = os.path.join(this.buildroot_out_dir, 'host') this.host_bin_dir = os.path.join(this.host_dir, 'usr', 'bin') diff --git a/rootfs_post_image_script b/rootfs_post_image_script deleted file mode 100755 index 4f28436..0000000 --- a/rootfs_post_image_script +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -images_dir="$1" -cd "$images_dir" -f=rootfs.ext2 -exe="${HOST_DIR}/bin/qemu-img" -if [ -f "$exe" ] && [ -f "$f" ]; then - # TODO why does qemu-img produce traces? - # http://lists.nongnu.org/archive/html/qemu-discuss/2018-04/msg00019.html - "$exe" -T "pr_manager_run,file=/dev/null" convert -f raw -O qcow2 "$f" "${f}.qcow2" -fi