aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2020-06-27 12:13:42 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-06-27 15:04:27 +0200
commitf5b2c665da983dfae9f6ac0c5661bb1416d16e31 (patch)
tree95a5f2cf72d78953b2c1bfb7083646e132dc1361 /vm
parent032b42395f4b6d3d97e6501b94fb4ad47231ca18 (diff)
vm/qemu: add support for linux/riscv64
Since the qemu riscv64 port does not work with the default -net nic parameter, add support to use in the modern way of specifying network devices to qemu, i.e. -device virtio-net-device,netdev=0 -netdev user,id=net0,host=... The same applies for the -hda qemu option. Provide a way to use the modern way of specifying image devices as well. Other/new ports may use these options as well in the future by setting UseNewQemuNetOptions and/or UseNewQemuImageOptions. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'vm')
-rw-r--r--vm/qemu/qemu.go49
1 files changed, 39 insertions, 10 deletions
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go
index e5f1fc8c5..4a306bfa4 100644
--- a/vm/qemu/qemu.go
+++ b/vm/qemu/qemu.go
@@ -81,7 +81,11 @@ type archConfig struct {
QemuArgs string
TargetDir string
NicModel string
- CmdLine []string
+ // UseNewQemuNetOptions specifies whether the arch uses "new" QEMU network device options.
+ UseNewQemuNetOptions bool
+ // UseNewQemuImageOptions specifies whether the arch uses "new" QEMU image device options.
+ UseNewQemuImageOptions bool
+ CmdLine []string
}
var archConfigs = map[string]*archConfig{
@@ -152,6 +156,17 @@ var archConfigs = map[string]*archConfig{
QemuArgs: "-enable-kvm -vga none",
CmdLine: linuxCmdline,
},
+ "linux/riscv64": {
+ Qemu: "qemu-system-riscv64",
+ TargetDir: "/",
+ QemuArgs: "-machine virt",
+ UseNewQemuNetOptions: true,
+ UseNewQemuImageOptions: true,
+ CmdLine: append(linuxCmdline,
+ "root=/dev/vda",
+ "console=ttyS0",
+ ),
+ },
"linux/s390x": {
Qemu: "qemu-system-s390x",
TargetDir: "/",
@@ -350,28 +365,42 @@ func (inst *instance) boot() error {
args := []string{
"-m", strconv.Itoa(inst.cfg.Mem),
"-smp", strconv.Itoa(inst.cfg.CPU),
- "-net", "nic" + inst.archConfig.NicModel,
- "-net", fmt.Sprintf("user,host=%v,hostfwd=tcp::%v-:22", hostAddr, inst.port),
"-display", "none",
"-serial", "stdio",
"-no-reboot",
}
args = append(args, splitArgs(inst.cfg.QemuArgs, filepath.Join(inst.workdir, "template"))...)
+ if inst.archConfig.UseNewQemuNetOptions {
+ args = append(args,
+ "-device", "virtio-net-device,netdev=net0",
+ "-netdev", fmt.Sprintf("user,id=net0,host=%v,hostfwd=tcp::%v-:22", hostAddr, inst.port))
+ } else {
+ args = append(args,
+ "-net", "nic"+inst.archConfig.NicModel,
+ "-net", fmt.Sprintf("user,host=%v,hostfwd=tcp::%v-:22", hostAddr, inst.port))
+ }
if inst.image == "9p" {
args = append(args,
"-fsdev", "local,id=fsdev0,path=/,security_model=none,readonly",
"-device", "virtio-9p-pci,fsdev=fsdev0,mount_tag=/dev/root",
)
} else if inst.image != "" {
- // inst.cfg.ImageDevice can contain spaces
- imgline := strings.Split(inst.cfg.ImageDevice, " ")
- imgline[0] = "-" + imgline[0]
- if strings.HasSuffix(imgline[len(imgline)-1], "file=") {
- imgline[len(imgline)-1] = imgline[len(imgline)-1] + inst.image
+ if inst.archConfig.UseNewQemuImageOptions {
+ args = append(args,
+ "-device", "virtio-blk-device,drive=hd0",
+ "-drive", fmt.Sprintf("file=%v,if=none,format=raw,id=hd0", inst.image),
+ )
} else {
- imgline = append(imgline, inst.image)
+ // inst.cfg.ImageDevice can contain spaces
+ imgline := strings.Split(inst.cfg.ImageDevice, " ")
+ imgline[0] = "-" + imgline[0]
+ if strings.HasSuffix(imgline[len(imgline)-1], "file=") {
+ imgline[len(imgline)-1] = imgline[len(imgline)-1] + inst.image
+ } else {
+ imgline = append(imgline, inst.image)
+ }
+ args = append(args, imgline...)
}
- args = append(args, imgline...)
if inst.cfg.Snapshot {
args = append(args, "-snapshot")
}