system: vm: Add arm64 support.

* gnu/build/vm.scm (load-in-linux-vm): Add target-arm64? argument and use it
to pass correct arguments to qemu.
* gnu/system/vm.scm (expression->derivation-in-linux-vm): Pass the new
target-arm64? argument added above. Do not add ESP partition on all ARM
targets. Do not pass grub-efi package to initialize-hard-disk on ARM targets.
This commit is contained in:
Mathieu Othacehe 2019-08-20 18:00:40 +02:00
parent 8ac892c99c
commit fd02b831ba
No known key found for this signature in database
GPG key ID: 8354763531769CA6
2 changed files with 22 additions and 12 deletions

View file

@ -82,6 +82,7 @@ (define* (load-in-linux-vm builder
make-disk-image? make-disk-image?
single-file-output? single-file-output?
target-arm32? target-arm32?
target-aarch64?
(disk-image-size (* 100 (expt 2 20))) (disk-image-size (* 100 (expt 2 20)))
(disk-image-format "qcow2") (disk-image-format "qcow2")
(references-graphs '())) (references-graphs '()))
@ -97,10 +98,14 @@ (define* (load-in-linux-vm builder
REFERENCES-GRAPHS can specify a list of reference-graph files as produced by REFERENCES-GRAPHS can specify a list of reference-graph files as produced by
the #:references-graphs parameter of 'derivation'." the #:references-graphs parameter of 'derivation'."
(define target-arm? (or target-arm32? target-aarch64?))
(define arch-specific-flags (define arch-specific-flags
`(;; On ARM, a machine has to be specified. Use "virt" machine to avoid `(;; On ARM, a machine has to be specified. Use "virt" machine to avoid
;; hardware limits imposed by other machines. ;; hardware limits imposed by other machines.
,@(if target-arm32? '("-M" "virt") '()) ,@(if target-arm?
'("-M" "virt")
'())
;; On ARM32, if the kernel is built without LPAE support, ECAM conflicts ;; On ARM32, if the kernel is built without LPAE support, ECAM conflicts
;; with VIRT_PCIE_MMIO causing PCI devices not to show up. Disable ;; with VIRT_PCIE_MMIO causing PCI devices not to show up. Disable
@ -112,9 +117,9 @@ (define arch-specific-flags
;; Only enable kvm if we see /dev/kvm exists. This allows users without ;; Only enable kvm if we see /dev/kvm exists. This allows users without
;; hardware virtualization to still use these commands. KVM support is ;; hardware virtualization to still use these commands. KVM support is
;; still buggy on some ARM32 boards. Do not use it even if available. ;; still buggy on some ARM boards. Do not use it even if available.
,@(if (and (file-exists? "/dev/kvm") ,@(if (and (file-exists? "/dev/kvm")
(not target-arm32?)) (not target-arm?))
'("-enable-kvm") '("-enable-kvm")
'()) '())
@ -125,11 +130,11 @@ (define arch-specific-flags
;; The serial port name differs between emulated ;; The serial port name differs between emulated
;; architectures/machines. ;; architectures/machines.
" console=" " console="
(if target-arm32? "ttyAMA0" "ttyS0")) (if target-arm? "ttyAMA0" "ttyS0"))
;; NIC is not supported on ARM "virt" machine, so use a user mode ;; NIC is not supported on ARM "virt" machine, so use a user mode
;; network stack instead. ;; network stack instead.
,@(if target-arm32? ,@(if target-arm?
'("-device" "virtio-net-pci,netdev=mynet" '("-device" "virtio-net-pci,netdev=mynet"
"-netdev" "user,id=mynet") "-netdev" "user,id=mynet")
'("-net" "nic,model=virtio")))) '("-net" "nic,model=virtio"))))
@ -153,7 +158,9 @@ (define arch-specific-flags
(_ #f)) (_ #f))
(apply invoke qemu "-nographic" "-no-reboot" (apply invoke qemu "-nographic" "-no-reboot"
"-smp" (number->string (parallel-job-count)) ;; CPU "max" behaves as "host" when KVM is enabled, and like a system
;; CPU with the maximum possible feature set otherwise.
"-cpu" "max"
"-m" (number->string memory-size) "-m" (number->string memory-size)
"-object" "rng-random,filename=/dev/urandom,id=guixsd-vm-rng" "-object" "rng-random,filename=/dev/urandom,id=guixsd-vm-rng"
"-device" "virtio-rng-pci,rng=guixsd-vm-rng" "-device" "virtio-rng-pci,rng=guixsd-vm-rng"

View file

@ -235,10 +235,12 @@ (define builder
#:memory-size #$memory-size #:memory-size #$memory-size
#:make-disk-image? #$make-disk-image? #:make-disk-image? #$make-disk-image?
#:single-file-output? #$single-file-output? #:single-file-output? #$single-file-output?
;; FIXME: target-arm32? may not operate on ;; FIXME: target-arm32? and
;; the right system/target values. Rewrite ;; target-aarch64? may not operate on the
;; right system/target values. Rewrite
;; using let-system when available. ;; using let-system when available.
#:target-arm32? #$(target-arm32?) #:target-arm32? #$(target-arm32?)
#:target-aarch64? #$(target-aarch64?)
#:disk-image-format #$disk-image-format #:disk-image-format #$disk-image-format
#:disk-image-size size #:disk-image-size size
#:references-graphs graphs)))))) #:references-graphs graphs))))))
@ -452,10 +454,10 @@ (define schema
;; bootloaders if we are not targeting ARM because UEFI ;; bootloaders if we are not targeting ARM because UEFI
;; support in U-Boot is experimental. ;; support in U-Boot is experimental.
;; ;;
;; FIXME: target-arm32? may be not operate on the right ;; FIXME: target-arm? may be not operate on the right
;; system/target values. Rewrite using let-system when ;; system/target values. Rewrite using let-system when
;; available. ;; available.
(if #$(target-arm32?) (if #$(target-arm?)
'() '()
(list (partition (list (partition
;; The standalone grub image is about 10MiB, but ;; The standalone grub image is about 10MiB, but
@ -466,10 +468,11 @@ (define schema
;; when mounting. The actual FAT-ness is based ;; when mounting. The actual FAT-ness is based
;; on file system size (16 in this case). ;; on file system size (16 in this case).
(file-system "vfat") (file-system "vfat")
(flags '(esp)))))))) (flags '(esp)))))))
(grub-efi #$(and (not (target-arm?)) grub-efi)))
(initialize-hard-disk "/dev/vda" (initialize-hard-disk "/dev/vda"
#:partitions partitions #:partitions partitions
#:grub-efi #$grub-efi #:grub-efi grub-efi
#:bootloader-package #:bootloader-package
#$(bootloader-package bootloader) #$(bootloader-package bootloader)
#:bootcfg #$bootcfg-drv #:bootcfg #$bootcfg-drv