Skip to content

Commit e27305f

Browse files
committed
Add support for armv7l architecture
Currently only ubuntu-lts runs, some issue with ubuntu images. And there is no nerdctl-full for arm-v7, only nerdctl images. Signed-off-by: Anders F Björklund <[email protected]>
1 parent a785625 commit e27305f

File tree

11 files changed

+108
-12
lines changed

11 files changed

+108
-12
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ binaries: clean \
4949
_output/bin/kubectl.lima \
5050
_output/share/lima/lima-guestagent.Linux-x86_64 \
5151
_output/share/lima/lima-guestagent.Linux-aarch64 \
52+
_output/share/lima/lima-guestagent.Linux-armv7l \
5253
_output/share/lima/lima-guestagent.Linux-riscv64
5354
cp -aL examples _output/share/lima
5455
mkdir -p _output/share/doc/lima
@@ -108,6 +109,11 @@ _output/share/lima/lima-guestagent.Linux-aarch64:
108109
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
109110
chmod 644 $@
110111

112+
.PHONY: _output/share/lima/lima-guestagent.Linux-armv7l
113+
_output/share/lima/lima-guestagent.Linux-armv7l:
114+
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
115+
chmod 644 $@
116+
111117
.PHONY: _output/share/lima/lima-guestagent.Linux-riscv64
112118
_output/share/lima/lima-guestagent.Linux-riscv64:
113119
GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent

docs/experimental.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The following features are experimental and subject to change:
99
- `video.display: vnc` and relevant configuration (`video.vnc.display`)
1010
- `mode: user-v2` in `networks.yml` and relevant configuration in `lima.yaml`
1111
- `audio.device`
12+
- `arch: armv7l`
1213

1314
The following commands are experimental and subject to change:
1415

docs/internal.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ The directory contains the following files:
116116
- `$QEMU_SYSTEM_AARCH64`: path of `qemu-system-aarch64`
117117
- Default: `qemu-system-aarch64` in `$PATH`
118118

119+
- `$QEMU_SYSTEM_ARM`: path of `qemu-system-arm`
120+
- Default: `qemu-system-arm` in `$PATH`
121+
119122
## `cidata.iso`
120123
`cidata.iso` contains the following files:
121124

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Optional feature enablers:
4646
- [`vmnet.yaml`](./vmnet.yaml): ⭐enable [`vmnet.framework`](../docs/network.md)
4747
- [`experimental/9p.yaml`](experimental/9p.yaml): [experimental] use 9p mount type
4848
- [`experimental/virtiofs-linux.yaml`](experimental/9p.yaml): [experimental] use virtiofs mount type for Linux
49+
- [`experimental/armv7l.yaml`](experimental/armv7l.yaml): [experimental] ARMv7
4950
- [`experimental/riscv64.yaml`](experimental/riscv64.yaml): [experimental] RISC-V
5051
- [`experimental/net-user-v2.yaml`](experimental/net-user-v2.yaml): [experimental] user-v2 network
5152
to enable VM-to-VM communication without root privilege

examples/default.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ containerd:
237237
cpuType:
238238
# 🟢 Builtin default: "cortex-a72" (or "host" when running on aarch64 host)
239239
aarch64: null
240+
# 🟢 Builtin default: "cortex-a7" (or "host" when running on armv7l host)
241+
armv7l: null
240242
# 🟢 Builtin default: "qemu64" (or "host,-pdpe1gb" when running on x86_64 host)
241243
x86_64: null
242244

examples/experimental/armv7l.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This example requires Lima v0.7.0 or later.
2+
3+
arch: "armv7l"
4+
images:
5+
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
6+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20230518/ubuntu-22.04-server-cloudimg-armhf.img"
7+
arch: "armv7l"
8+
digest: "sha256:f9baf349e9f4bb4acc6cbd14dc82aa2aa514fd76e06c74678e5453f0e6717fd2"
9+
# Fallback to the latest release image.
10+
# Hint: run `limactl prune` to invalidate the cache
11+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-armhf.img"
12+
arch: "armv7l"
13+
14+
mounts:
15+
- location: "~"
16+
- location: "/tmp/lima"
17+
writable: true
18+
19+
# We do not have arm-v7 binaries of containerd
20+
containerd:
21+
system: false
22+
user: false

pkg/limayaml/defaults.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/lima-vm/lima/pkg/store/filenames"
2222
"github.com/sirupsen/logrus"
2323
"github.com/xorcare/pointer"
24+
25+
"golang.org/x/sys/cpu"
2426
)
2527

2628
const (
@@ -51,6 +53,7 @@ func defaultContainerdArchives() []File {
5153
Arch: AARCH64,
5254
Digest: "sha256:589dabd962d936b29fd377dcddbb49c07d1c4c27dd4b402bc4b6b20287fe9c37",
5355
},
56+
// No arm-v7
5457
// No riscv64
5558
}
5659
}
@@ -151,6 +154,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
151154

152155
cpuType := map[Arch]string{
153156
AARCH64: "cortex-a72",
157+
ARMV7L: "cortex-a7",
154158
// Since https://github.com/lima-vm/lima/pull/494, we use qemu64 cpu for better emulation of x86_64.
155159
X8664: "qemu64",
156160
RISCV64: "rv64", // FIXME: what is the right choice for riscv64?
@@ -749,12 +753,35 @@ func FillCopyToHostDefaults(rule *CopyToHost, instDir string) {
749753
}
750754
}
751755

756+
func goarm() int {
757+
if runtime.GOOS != "linux" {
758+
return 0
759+
}
760+
if runtime.GOARCH != "arm" {
761+
return 0
762+
}
763+
if cpu.ARM.HasVFPv3 {
764+
return 7
765+
}
766+
if cpu.ARM.HasVFP {
767+
return 6
768+
}
769+
return 5 // default
770+
}
771+
752772
func NewArch(arch string) Arch {
753773
switch arch {
754774
case "amd64":
755775
return X8664
756776
case "arm64":
757777
return AARCH64
778+
case "arm":
779+
arm := goarm()
780+
if arm == 7 {
781+
return ARMV7L
782+
}
783+
logrus.Warnf("Unknown arm: %d", arm)
784+
return arch
758785
case "riscv64":
759786
return RISCV64
760787
default:
@@ -818,8 +845,9 @@ func HasMaxCPU() bool {
818845
func IsNativeArch(arch Arch) bool {
819846
nativeX8664 := arch == X8664 && runtime.GOARCH == "amd64"
820847
nativeAARCH64 := arch == AARCH64 && runtime.GOARCH == "arm64"
848+
nativeARMV7L := arch == ARMV7L && runtime.GOARCH == "arm" && goarm() == 7
821849
nativeRISCV64 := arch == RISCV64 && runtime.GOARCH == "riscv64"
822-
return nativeX8664 || nativeAARCH64 || nativeRISCV64
850+
return nativeX8664 || nativeAARCH64 || nativeARMV7L || nativeRISCV64
823851
}
824852

825853
func unique(s []string) []string {

pkg/limayaml/defaults_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ func TestFillDefault(t *testing.T) {
3232
arch = X8664
3333
case "arm64":
3434
arch = AARCH64
35+
case "arm":
36+
if runtime.GOOS != "linux" {
37+
t.Skipf("unsupported GOOS: %s", runtime.GOOS)
38+
}
39+
if arm := goarm(); arm < 7 {
40+
t.Skipf("unsupported GOARM: %d", arm)
41+
}
42+
arch = ARMV7L
3543
case "riscv64":
3644
arch = RISCV64
3745
default:
@@ -56,6 +64,7 @@ func TestFillDefault(t *testing.T) {
5664
Arch: pointer.String(arch),
5765
CPUType: map[Arch]string{
5866
AARCH64: "cortex-a72",
67+
ARMV7L: "cortex-a7",
5968
X8664: "qemu64",
6069
RISCV64: "rv64",
6170
},
@@ -259,6 +268,7 @@ func TestFillDefault(t *testing.T) {
259268
Arch: pointer.String("unknown"),
260269
CPUType: map[Arch]string{
261270
AARCH64: "arm64",
271+
ARMV7L: "armhf",
262272
X8664: "amd64",
263273
RISCV64: "riscv64",
264274
},
@@ -434,6 +444,7 @@ func TestFillDefault(t *testing.T) {
434444
Arch: pointer.String(arch),
435445
CPUType: map[Arch]string{
436446
AARCH64: "uber-arm",
447+
ARMV7L: "armv8",
437448
X8664: "pentium",
438449
RISCV64: "sifive-u54",
439450
},

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type VMType = string
4545
const (
4646
X8664 Arch = "x86_64"
4747
AARCH64 Arch = "aarch64"
48+
ARMV7L Arch = "armv7l"
4849
RISCV64 Arch = "riscv64"
4950

5051
REVSSHFS MountType = "reverse-sshfs"

pkg/limayaml/validate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func validateFileObject(f File, fieldName string) error {
2626
// f.Location does NOT need to be accessible, so we do NOT check os.Stat(f.Location)
2727
}
2828
switch f.Arch {
29-
case X8664, AARCH64, RISCV64:
29+
case X8664, AARCH64, ARMV7L, RISCV64:
3030
default:
31-
return fmt.Errorf("field `arch` must be %q, %q, or %q; got %q", X8664, AARCH64, RISCV64, f.Arch)
31+
return fmt.Errorf("field `arch` must be %q, %q, %q, or %q; got %q", X8664, AARCH64, ARMV7L, RISCV64, f.Arch)
3232
}
3333
if f.Digest != "" {
3434
if !f.Digest.Algorithm().Available() {
@@ -43,9 +43,9 @@ func validateFileObject(f File, fieldName string) error {
4343

4444
func Validate(y LimaYAML, warn bool) error {
4545
switch *y.Arch {
46-
case X8664, AARCH64, RISCV64:
46+
case X8664, AARCH64, ARMV7L, RISCV64:
4747
default:
48-
return fmt.Errorf("field `arch` must be %q, %q, or %q; got %q", X8664, AARCH64, RISCV64, *y.Arch)
48+
return fmt.Errorf("field `arch` must be %q, %q, %q or %q; got %q", X8664, AARCH64, ARMV7L, RISCV64, *y.Arch)
4949
}
5050

5151
switch *y.VMType {
@@ -91,7 +91,7 @@ func Validate(y LimaYAML, warn bool) error {
9191

9292
for arch := range y.CPUType {
9393
switch arch {
94-
case AARCH64, X8664, RISCV64:
94+
case AARCH64, X8664, ARMV7L, RISCV64:
9595
// these are the only supported architectures
9696
default:
9797
return fmt.Errorf("field `cpuType` uses unsupported arch %q", arch)

0 commit comments

Comments
 (0)