xref: /openbmc/qemu/tests/vm/ubuntu.aarch64 (revision 47f71f89)
113336606SRobert Foley#!/usr/bin/env python3
213336606SRobert Foley#
313336606SRobert Foley# Ubuntu aarch64 image
413336606SRobert Foley#
513336606SRobert Foley# Copyright 2020 Linaro
613336606SRobert Foley#
713336606SRobert Foley# Authors:
813336606SRobert Foley#  Robert Foley <robert.foley@linaro.org>
913336606SRobert Foley#  Originally based on ubuntu.i386 Fam Zheng <famz@redhat.com>
1013336606SRobert Foley#
1113336606SRobert Foley# This code is licensed under the GPL version 2 or later.  See
1213336606SRobert Foley# the COPYING file in the top-level directory.
1313336606SRobert Foley#
1413336606SRobert Foley
1513336606SRobert Foleyimport sys
1613336606SRobert Foleyimport basevm
1713336606SRobert Foleyimport aarch64vm
1813336606SRobert Foleyimport ubuntuvm
1913336606SRobert Foley
2013336606SRobert FoleyDEFAULT_CONFIG = {
2113336606SRobert Foley    'cpu'          : "cortex-a57",
2213336606SRobert Foley    'machine'      : "virt,gic-version=3",
2313336606SRobert Foley    'install_cmds' : "apt-get update,"\
2413336606SRobert Foley                     "apt-get build-dep -y --arch-only qemu,"\
25345d7053SPaolo Bonzini                     "apt-get install -y libfdt-dev pkg-config language-pack-en ninja-build",
2613336606SRobert Foley    # We increase beyond the default time since during boot
2713336606SRobert Foley    # it can take some time (many seconds) to log into the VM
2813336606SRobert Foley    # especially using softmmu.
2913336606SRobert Foley    'ssh_timeout'  : 60,
3013336606SRobert Foley}
3113336606SRobert Foley
3213336606SRobert Foleyclass UbuntuAarch64VM(ubuntuvm.UbuntuVM):
3313336606SRobert Foley    name = "ubuntu.aarch64"
3413336606SRobert Foley    arch = "aarch64"
35*47f71f89SJohn Snow    # NOTE: The Ubuntu 20.04 cloud images are periodically updated. The
36*47f71f89SJohn Snow    # fixed image chosen below is the latest release at time of
37*47f71f89SJohn Snow    # writing. Using a rolling latest instead would mean that the SHA
38*47f71f89SJohn Snow    # would be incorrect at an indeterminate point in the future.
39*47f71f89SJohn Snow    image_name = "focal-server-cloudimg-arm64.img"
40*47f71f89SJohn Snow    image_link = "https://cloud-images.ubuntu.com/focal/20220615/" + image_name
41*47f71f89SJohn Snow    image_sha256="95a027336e197debe88c92ff2e554598e23c409139e1e750b71b3b820b514832"
4213336606SRobert Foley    BUILD_SCRIPT = """
4313336606SRobert Foley        set -e;
4413336606SRobert Foley        cd $(mktemp -d);
4513336606SRobert Foley        sudo chmod a+r /dev/vdb;
4613336606SRobert Foley        tar --checkpoint=.10 -xf /dev/vdb;
4713336606SRobert Foley        ./configure {configure_opts};
4813336606SRobert Foley        make --output-sync {target} -j{jobs} {verbose};
4913336606SRobert Foley    """
5013336606SRobert Foley    def boot(self, img, extra_args=None):
5113336606SRobert Foley        aarch64vm.create_flash_images(self._tmpdir, self._efi_aarch64)
5213336606SRobert Foley        default_args = aarch64vm.get_pflash_args(self._tmpdir)
5313336606SRobert Foley        if extra_args:
5413336606SRobert Foley            extra_args.extend(default_args)
5513336606SRobert Foley        else:
5613336606SRobert Foley            extra_args = default_args
5713336606SRobert Foley        # We always add these performance tweaks
5813336606SRobert Foley        # because without them, we boot so slowly that we
5913336606SRobert Foley        # can time out finding the boot efi device.
6013336606SRobert Foley        if '-smp' not in extra_args and \
6113336606SRobert Foley           '-smp' not in self._config['extra_args'] and \
6213336606SRobert Foley           '-smp' not in self._args:
6313336606SRobert Foley            # Only add if not already there to give caller option to change it.
6413336606SRobert Foley            extra_args.extend(["-smp", "8"])
6513336606SRobert Foley
6613336606SRobert Foley        # We have overridden boot() since aarch64 has additional parameters.
6713336606SRobert Foley        # Call down to the base class method.
6813336606SRobert Foley        super(UbuntuAarch64VM, self).boot(img, extra_args=extra_args)
6913336606SRobert Foley
7013336606SRobert Foleyif __name__ == "__main__":
7113336606SRobert Foley    defaults = aarch64vm.get_config_defaults(UbuntuAarch64VM, DEFAULT_CONFIG)
7213336606SRobert Foley    sys.exit(basevm.main(UbuntuAarch64VM, defaults))
73