diff --git a/Makefile b/Makefile index 348e536d0f..a1d1df3b22 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ SHELL := /bin/bash build_dir := build +arch ?= $(shell dpkg --print-architecture 2>/dev/null || echo amd64) + .PHONY: all all: @echo "Make what specifically?" @@ -13,8 +15,8 @@ all: .PHONY: checkiso .ONESHELL: checkiso: - if [ ! -f build/live-image-amd64.hybrid.iso ]; then - echo "Could not find build/live-image-amd64.hybrid.iso" + if [ ! -f build/live-image-$(arch).hybrid.iso ]; then + echo "Could not find build/live-image-$(arch).hybrid.iso" exit 1 fi @@ -31,7 +33,7 @@ test-no-interfaces: checkiso .PHONY: test-no-interfaces-no-vpp .ONESHELL: test-no-interfaces-no-vpp: checkiso - scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp build/live-image-amd64.hybrid.iso + scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp --arch $(arch) build/live-image-$(arch).hybrid.iso .PHONY: test-interfaces .ONESHELL: diff --git a/data/build-flavors/generic-arm64.toml b/data/build-flavors/generic-arm64.toml new file mode 100644 index 0000000000..d621891aef --- /dev/null +++ b/data/build-flavors/generic-arm64.toml @@ -0,0 +1,74 @@ +# Generic (aka "universal") ISO image + +image_format = "iso" + +[[includes_chroot]] + path = "opt/vyatta/etc/config.boot.default" + data = ''' +interfaces { + loopback lo { + } +} +service { + ntp { + allow-client { + address "127.0.0.0/8" + address "169.254.0.0/16" + address "10.0.0.0/8" + address "172.16.0.0/12" + address "192.168.0.0/16" + address "::1/128" + address "fe80::/10" + address "fc00::/7" + } + server time1.vyos.net { + } + server time2.vyos.net { + } + server time3.vyos.net { + } + } +} +system { + config-management { + commit-revisions "100" + } + console { + device ttyAMA0 { + speed "115200" + } + } + host-name "vyos" + login { + operator-group default { + command-policy { + allow "*" + } + } + user vyos { + authentication { + encrypted-password "$6$QxPS.uk6mfo$9QBSo8u1FkH16gMyAVhus6fU3LOzvLR9Z9.82m3tiHFAxTtIkhaZSWssSgzt4v4dGAL8rhVQxTg0oAG9/q11h/" + plaintext-password "" + } + } + } + option { + reboot-on-upgrade-failure 5 + } + syslog { + local { + facility all { + level "info" + } + facility local7 { + level "debug" + } + } + } +} +''' + +[boot_settings] + console_type = "ttyAMA" + console_num = '0' + console_speed = "115200" diff --git a/docker-vyos/Dockerfile b/docker-vyos/Dockerfile index 3fff371b1f..61214c2516 100644 --- a/docker-vyos/Dockerfile +++ b/docker-vyos/Dockerfile @@ -64,7 +64,10 @@ RUN bash /tmp/vyos_install_stage_02.sh # Tune system for VyOS COPY [ "docker-vyos/vyos_install_common.sh", "docker-vyos/vyos_install_stage_03.sh", "/tmp/" ] # Copy default config -COPY tools/container/config.boot.default /opt/vyatta/etc/ +# Detect architecture and copy the corresponding config file +RUN ARCH=$(dpkg --print-architecture 2>/dev/null || echo amd64) && \ + echo "Detected architecture: $ARCH" && \ + cp tools/container/config.boot.$ARCH /opt/vyatta/etc/config.boot.default RUN bash /tmp/vyos_install_stage_03.sh diff --git a/scripts/check-qemu-install b/scripts/check-qemu-install index 6482d13149..b140835569 100755 --- a/scripts/check-qemu-install +++ b/scripts/check-qemu-install @@ -54,6 +54,20 @@ now = datetime.now() tpm_folder = '/tmp/vyos_tpm_test' qemu_name = 'VyOS-QEMU' +# Map QEMU arch +QEMU_CONFIG = { + "amd64": { + "bin": "qemu-system-x86_64", + "machine": "pc", + "bios": "/usr/share/OVMF/OVMF_CODE.fd", + }, + "arm64": { + "bin": "qemu-system-aarch64", + "machine": "virt", + "bios": "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd", + }, +} + # getch.py KEY_F2 = chr(27) + chr(91) + chr(49) + chr(50) + chr(126) KEY_F10 = chr(27) + chr(91) + chr(50) + chr(49) + chr(126) @@ -96,6 +110,7 @@ parser.add_argument('--sbtest', help='Execute Secure Boot tests', parser.add_argument('--qemu-cmd', help='Only generate QEMU launch command', action='store_true', default=False) parser.add_argument('--cpu', help='Set QEMU CPU', type=int, default=2) +parser.add_argument('--cpu-type', help='Set QEMU CPU type', type=str, default='host') parser.add_argument('--memory', help='Set QEMU memory', type=int, default=4) parser.add_argument('--vyconf', help='Execute testsuite with vyconfd', action='store_true', default=False) @@ -103,6 +118,7 @@ parser.add_argument('--no-vpp', help='Execute testsuite without VPP tests', action='store_true', default=False) parser.add_argument('--huge-page-size', help='Huge page size (e.g., 2M, 1G)', type=str) parser.add_argument('--huge-page-count', help='Number of huge pages to allocate', type=int) +parser.add_argument('--arch', help='Architecture') args = parser.parse_args() @@ -145,18 +161,31 @@ OVMF_VARS_TMP = args.disk.replace('.img', '.efivars') if args.sbtest: shutil.copy('/usr/share/OVMF/OVMF_VARS_4M.ms.fd', OVMF_VARS_TMP) + +def _kvm_exists(): + return os.path.exists("/dev/kvm") + + def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False, vnc_enabled=False, secure_boot=False): uefi = "" uuid = "f48b60b2-e6ad-49ef-9d09-4245d0585e52" - machine = 'pc' + arch = getattr(args, 'arch', 'amd64') + qemu_arch_config = QEMU_CONFIG.get(arch, QEMU_CONFIG["amd64"]) + qemu_bin = qemu_arch_config['bin'] + bios = qemu_arch_config['bios'] + cpu_type = args.cpu_type + machine = qemu_arch_config['machine'] + accel = ',accel=kvm' if _kvm_exists() else '' + enable_kvm = '-enable-kvm' if _kvm_exists() else '' vga = '-vga none' vnc = '' + if vnc_enabled: vga = '-vga virtio' vnc = '-vnc :0' if enable_uefi: - uefi = '-bios /usr/share/OVMF/OVMF_CODE.fd' + uefi = f'-bios {bios}' name = f'{name}-UEFI' if secure_boot: @@ -170,26 +199,25 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False cdrom = "" if iso_img: - cdrom = f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on' \ - f' -device ahci,id=achi0' \ - f' -device ide-cd,bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=10' + cdrom = ( + f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on' + f' -device scsi-cd,bus=scsi0.0,drive=drive-cd1,id=cd1,bootindex=10' + ) # RFC7042 section 2.1.2 MAC addresses used for documentation macbase = '00:00:5E:00:53' - cmd = f'qemu-system-x86_64 \ + cmd = f'{qemu_bin} \ -name "{name}" \ -smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \ - -cpu host \ - -machine {machine},accel=kvm \ + -cpu {cpu_type} \ + -machine {machine}{accel} \ {uefi} \ -m {args.memory}G \ -vga none \ -nographic \ {vga} {vnc}\ -uuid {uuid} \ - -cpu host \ - {cdrom} \ - -enable-kvm \ + {enable_kvm} \ -monitor unix:/tmp/qemu-monitor-socket-{disk_img},server,nowait \ -netdev user,id=n0,net=192.0.2.0/24,dhcpstart=192.0.2.101,dns=192.0.2.10 -device virtio-net-pci,netdev=n0,mac={macbase}:00,romfile="",host_mtu=1500 \ -netdev user,id=n1 -device virtio-net-pci,netdev=n1,mac={macbase}:01,romfile="",host_mtu=1500 \ @@ -200,6 +228,7 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False -netdev user,id=n6 -device virtio-net-pci,netdev=n6,mac={macbase}:06,romfile="" \ -netdev user,id=n7 -device virtio-net-pci,netdev=n7,mac={macbase}:07,romfile="" \ -device virtio-scsi-pci,id=scsi0 \ + {cdrom} \ -drive format=raw,file={disk_img},if=none,media=disk,id=drive-hd1,readonly=off \ -device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=1' @@ -282,7 +311,8 @@ if not os.path.isfile(args.iso): if not os.path.exists('/dev/kvm'): log.error('KVM not enabled on host, proceeding with software emulation') - sys.exit(1) + # Some arm platforms do not have kvm, for example Mac arm devices + # sys.exit(1) # Creating diskimage!! diskname_raid = None diff --git a/tools/container/config.boot.default.amd64 b/tools/container/config.boot.default.amd64 new file mode 100644 index 0000000000..c07544d3e9 --- /dev/null +++ b/tools/container/config.boot.default.amd64 @@ -0,0 +1,39 @@ +system { + host-name vyos + login { + user vyos { + authentication { + encrypted-password "*" + plaintext-password "" + } + } + } + syslog { + local { + facility all { + level info + } + facility protocols { + level debug + } + } + } + ntp { + server "time1.vyos.net" + server "time2.vyos.net" + server "time3.vyos.net" + } + console { + device ttyS0 { + speed 115200 + } + } + config-management { + commit-revisions 100 + } +} + +interfaces { + loopback lo { + } +} diff --git a/tools/container/config.boot.default.arm64 b/tools/container/config.boot.default.arm64 new file mode 100644 index 0000000000..460b46ba78 --- /dev/null +++ b/tools/container/config.boot.default.arm64 @@ -0,0 +1,39 @@ +system { + host-name vyos + login { + user vyos { + authentication { + encrypted-password "*" + plaintext-password "" + } + } + } + syslog { + local { + facility all { + level info + } + facility protocols { + level debug + } + } + } + ntp { + server "time1.vyos.net" + server "time2.vyos.net" + server "time3.vyos.net" + } + console { + device ttyAMA0 { + speed 115200 + } + } + config-management { + commit-revisions 100 + } +} + +interfaces { + loopback lo { + } +}