Skip to content

Commit dcaac6d

Browse files
committed
Add support for RISC-V 64bit architecture
Basic support of riscv64 architecture. Shim is not supported yet, will be added later. Signed-off-by: Loic Devulder <ldevulder@suse.com>
1 parent 6358862 commit dcaac6d

14 files changed

Lines changed: 339 additions & 115 deletions

.goreleaser.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ builds:
44
- CGO_ENABLED=0
55
ldflags:
66
- -s -w
7-
- -X github.com/rancher/elemental-cli/internal/version.version={{.Tag}}
8-
- -X github.com/rancher/elemental-cli/internal/version.gitCommit={{.Commit}}
7+
- -X github.com/rancher/elemental-toolkit/internal/version.version={{.Tag}}
8+
- -X github.com/rancher/elemental-toolkit/internal/version.gitCommit={{.Commit}}
99
goos:
1010
- linux
1111
goarch:
1212
- amd64
1313
- arm
1414
- arm64
15+
- riscv64
1516
goarm:
1617
- 6
1718
- 7
@@ -43,4 +44,4 @@ changelog:
4344
exclude:
4445
- '^docs:'
4546
- '^test:'
46-
- '^Merge pull request'
47+
- '^Merge pull request'

Dockerfile

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
ARG GO_VERSION=1.20
2-
ARG LEAP_VERSION=15.5
32

4-
FROM golang:${GO_VERSION}-alpine as elemental-bin
3+
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS elemental-bin
54

65
ENV CGO_ENABLED=0
76
WORKDIR /src/
@@ -21,43 +20,8 @@ ARG ELEMENTAL_VERSION=0.0.1
2120
ARG ELEMENTAL_COMMIT=""
2221
ENV ELEMENTAL_VERSION=${ELEMENTAL_VERSION}
2322
ENV ELEMENTAL_COMMIT=${ELEMENTAL_COMMIT}
24-
RUN go build \
23+
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
2524
-ldflags "-w -s \
26-
-X github.com/rancher/elemental-toolkit/internal/version.version=$ELEMENTAL_VERSION \
27-
-X github.com/rancher/elemental-toolkit/internal/version.gitCommit=$ELEMENTAL_COMMIT" \
25+
-X github.com/rancher/elemental-toolkit/internal/version.version=${ELEMENTAL_VERSION} \
26+
-X github.com/rancher/elemental-toolkit/internal/version.gitCommit=${ELEMENTAL_COMMIT}" \
2827
-o /usr/bin/elemental
29-
30-
FROM opensuse/leap:$LEAP_VERSION AS elemental
31-
# This helps invalidate the cache on each build so the following steps are really run again getting the latest packages
32-
# versions, as long as the elemental commit has changed
33-
ARG ELEMENTAL_COMMIT=""
34-
ENV ELEMENTAL_COMMIT=${ELEMENTAL_COMMIT}
35-
36-
RUN ARCH=$(uname -m); \
37-
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi; \
38-
zypper install -y --no-recommends xfsprogs \
39-
parted \
40-
util-linux-systemd \
41-
e2fsprogs \
42-
util-linux \
43-
udev \
44-
rsync \
45-
grub2 \
46-
dosfstools \
47-
grub2-${ARCH}-efi \
48-
squashfs \
49-
mtools \
50-
xorriso \
51-
cosign \
52-
gptfdisk \
53-
lvm2
54-
55-
COPY --from=elemental-bin /usr/bin/elemental /usr/bin/elemental
56-
57-
# Fix for blkid only using udev on opensuse
58-
RUN echo "EVALUATE=scan" >> /etc/blkid.conf
59-
ENTRYPOINT ["/usr/bin/elemental"]
60-
61-
# Add to /system/oem folder so install/upgrade/reset hooks will run when running this container.
62-
# Needed for boot-assessment
63-
COPY pkg/features/embedded/cloud-config-essentials/system/oem /system/oem/

Dockerfile.toolkit

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Elemental CLI is built in another Dockerfile that support multi-arch
2+
ARG BASE_OS_IMAGE=opensuse/leap
3+
ARG BASE_OS_VERSION=15.5
4+
ARG BIN_REPO
5+
ARG VERSION
6+
7+
FROM ${BIN_REPO}:${VERSION} AS bin
8+
FROM ${OS_IMAGE}:${OS_VERSION} AS elemental-toolkit
9+
10+
RUN ARCH=$(uname -m); \
11+
[[ "${ARCH}" == "aarch64" ]] && ARCH="arm64"; \
12+
zypper --non-interactive removerepo repo-update || true; \
13+
zypper install -y --no-recommends xfsprogs \
14+
parted \
15+
util-linux-systemd \
16+
e2fsprogs \
17+
udev \
18+
rsync \
19+
grub2 \
20+
dosfstools \
21+
grub2-${ARCH}-efi \
22+
squashfs \
23+
mtools \
24+
xorriso \
25+
cosign \
26+
gptfdisk \
27+
lvm2
28+
29+
# Copy the built CLI
30+
COPY --from=bin /usr/bin/elemental /usr/bin/elemental
31+
ENTRYPOINT ["/usr/bin/elemental"]
32+
33+
# Add to /system/oem folder so install/upgrade/reset hooks will run when running this container.
34+
# Needed for boot-assessment
35+
COPY pkg/features/embedded/cloud-config-essentials/system/oem /system/oem/

Makefile

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@ PLATFORM?=linux/$(ARCH)
1010
IMAGE_SIZE?=20G
1111
PACKER_TARGET?=qemu.elemental-${ARCH}
1212
REPO?=local/elemental-$(FLAVOR)
13+
BIN_REPO?=local/elemental-bin
1314
TOOLKIT_REPO?=local/elemental-toolkit
1415
DOCKER?=docker
15-
16-
GIT_COMMIT ?= $(shell git rev-parse HEAD)
17-
GIT_COMMIT_SHORT ?= $(shell git rev-parse --short HEAD)
18-
GIT_TAG ?= $(shell git describe --candidates=50 --abbrev=0 --tags 2>/dev/null || echo "v0.0.1" )
19-
VERSION ?= ${GIT_TAG}-g${GIT_COMMIT_SHORT}
20-
21-
PKG := ./cmd ./pkg/...
22-
LDFLAGS := -w -s
23-
LDFLAGS += -X "github.com/rancher/elemental-toolkit/internal/version.version=${GIT_TAG}"
24-
LDFLAGS += -X "github.com/rancher/elemental-toolkit/internal/version.gitCommit=${GIT_COMMIT}"
16+
BASE_OS_IMAGE?=opensuse/leap
17+
BASE_OS_VERSION?=15.5
18+
19+
GIT_COMMIT?=$(shell git rev-parse HEAD)
20+
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
21+
GIT_TAG?=$(shell git describe --candidates=50 --abbrev=0 --tags 2>/dev/null || echo "v0.0.1" )
22+
VERSION?=${GIT_TAG}-g${GIT_COMMIT_SHORT}
23+
24+
PKG:=./cmd ./pkg/...
25+
LDFLAGS:=-w -s
26+
LDFLAGS+=-X "github.com/rancher/elemental-toolkit/internal/version.version=${GIT_TAG}"
27+
LDFLAGS+=-X "github.com/rancher/elemental-toolkit/internal/version.gitCommit=${GIT_COMMIT}"
28+
29+
# For RISC-V 64bit support
30+
ifeq ($(PLATFORM),linux/riscv64)
31+
BASE_OS_IMAGE=registry.opensuse.org/opensuse/factory/riscv/images/opensuse/tumbleweed
32+
BASE_OS_VERSION=latest
33+
endif
2534

2635
# default target
2736
.PHONY: all
@@ -35,7 +44,21 @@ include make/Makefile.test
3544

3645
.PHONY: build
3746
build:
38-
$(DOCKER) build --platform ${PLATFORM} ${DOCKER_ARGS} --build-arg ELEMENTAL_VERSION=${GIT_TAG} --build-arg ELEMENTAL_COMMIT=${GIT_COMMIT} --target elemental -t ${TOOLKIT_REPO}:${VERSION} .
47+
$(DOCKER) build --platform $(PLATFORM) ${DOCKER_ARGS} \
48+
--build-arg ELEMENTAL_VERSION=$(GIT_TAG) \
49+
--build-arg ELEMENTAL_COMMIT=$(GIT_COMMIT) \
50+
--target elemental-bin -t $(BIN_REPO):$(VERSION) .
51+
$(DOCKER) build --platform $(PLATFORM) ${DOCKER_ARGS} \
52+
--build-arg BIN_REPO=$(BIN_REPO) \
53+
--build-arg VERSION=$(VERSION) \
54+
--build-arg BASE_OS_IMAGE=$(BASE_OS_IMAGE) \
55+
--build-arg BASE_OS_VERSION=$(BASE_OS_VERSION) \
56+
--file Dockerfile.toolkit \
57+
--target elemental-toolkit -t $(TOOLKIT_REPO):$(VERSION) .
58+
59+
.PHONY: push-bin
60+
push-bin:
61+
$(DOCKER) push $(BIN_REPO):$(VERSION)
3962

4063
.PHONY: push-toolkit
4164
push-toolkit:
@@ -47,7 +70,11 @@ build-cli:
4770

4871
.PHONY: build-os
4972
build-os: build
50-
$(DOCKER) build examples/$(FLAVOR) --platform ${PLATFORM} ${DOCKER_ARGS} --build-arg TOOLKIT_REPO=$(TOOLKIT_REPO) --build-arg VERSION=$(VERSION) --build-arg REPO=$(REPO) -t $(REPO):$(VERSION)
73+
$(DOCKER) build --platform ${PLATFORM} ${DOCKER_ARGS} \
74+
--build-arg TOOLKIT_REPO=$(TOOLKIT_REPO) \
75+
--build-arg VERSION=$(VERSION) \
76+
--build-arg REPO=$(REPO) -t $(REPO):$(VERSION) \
77+
examples/$(FLAVOR)
5178

5279
.PHONY: push-os
5380
push-os:
@@ -70,9 +97,8 @@ build-disk: build-os
7097
@echo Building ${ARCH} disk
7198
mkdir -p $(ROOT_DIR)/build
7299
$(DOCKER) run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(ROOT_DIR)/build:/build \
73-
--entrypoint /usr/bin/elemental \
74-
${TOOLKIT_REPO}:${VERSION} --debug build-disk --unprivileged --expandable -n elemental-$(FLAVOR).$(ARCH) --local \
75-
--squash-no-compression -o /build ${REPO}:${VERSION}
100+
--entrypoint /usr/bin/elemental ${REPO}:${VERSION} --debug build-disk --unprivileged --expandable -n elemental-$(FLAVOR).$(ARCH) \
101+
--local --squash-no-compression -o /build ${REPO}:${VERSION}
76102
dd if=$(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).raw of=$(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).img conv=notrunc
77103
qemu-img convert -O qcow2 $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).img $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2
78104
qemu-img resize $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2 $(DISKSIZE)

examples/green/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# run `make build` to build local/elemental-toolkit image
22
ARG TOOLKIT_REPO
33
ARG VERSION
4-
FROM ${TOOLKIT_REPO}:${VERSION} as TOOLKIT
4+
FROM ${TOOLKIT_REPO}:${VERSION} AS TOOLKIT
55

66
# OS base image of our choice
7-
FROM opensuse/leap:15.5 as OS
7+
FROM opensuse/leap:15.5 AS OS
88
ARG REPO
99
ARG VERSION
1010
ENV VERSION=${VERSION}
1111

1212
# install kernel, systemd, dracut, grub2 and other required tools
1313
RUN ARCH=$(uname -m); \
14-
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi; \
14+
[[ "${ARCH}" == "aarch64" ]] && ARCH="arm64"; \
1515
zypper --non-interactive install --no-recommends -- \
1616
kernel-default \
1717
device-mapper \
@@ -42,6 +42,7 @@ RUN ARCH=$(uname -m); \
4242
less \
4343
sudo \
4444
curl \
45+
iproute2 \
4546
sed
4647

4748
# Just add the elemental cli
@@ -55,7 +56,7 @@ RUN cp /usr/share/systemd/tmp.mount /etc/systemd/system
5556

5657
# Generate initrd with required elemental services
5758
RUN elemental init -f && \
58-
kernel=$(ls /boot/Image-* | head -n1) && \
59+
kernel=$(ls /boot/Image-* 2>/dev/null | head -n1) && \
5960
if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi && \
6061
rm -rf /var/log/update* && \
6162
>/var/log/lastlog && \
@@ -70,5 +71,3 @@ RUN echo IMAGE_REPO=\"${REPO}\" >> /etc/os-release && \
7071

7172
# Good for validation after the build
7273
CMD /bin/bash
73-
74-

examples/tumbleweed/Dockerfile

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
# run `make build` to build local/elemental-toolkit image
22
ARG TOOLKIT_REPO
33
ARG VERSION
4-
FROM ${TOOLKIT_REPO}:${VERSION} as TOOLKIT
4+
ARG OS_IMAGE=opensuse/tumbleweed
5+
ARG OS_VERSION=latest
6+
7+
FROM ${TOOLKIT_REPO}:${VERSION} AS TOOLKIT
58

69
# OS base image of our choice
7-
FROM opensuse/tumbleweed:latest as OS
10+
FROM ${OS_IMAGE}:${OS_VERSION} AS OS
811
ARG REPO
912
ARG VERSION
13+
ENV REPO=${REPO}
1014
ENV VERSION=${VERSION}
1115

12-
# install kernel, systemd, dracut, grub2 and other required tools
16+
# Workaround for RISC-V, specific kernel might be needed for some boards
17+
ARG ADD_REPO
18+
ENV ADD_REPO=${ADD_REPO}
19+
20+
# Install kernel, systemd, dracut, grub2 and other required tools
1321
RUN ARCH=$(uname -m); \
14-
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi; \
15-
zypper --non-interactive install --no-recommends -- \
22+
zypper --non-interactive removerepo repo-update || true; \
23+
if [[ -n "${ADD_REPO}" ]]; then \
24+
zypper --non-interactive addrepo --enable --refresh ${ADD_REPO} added-repo; \
25+
fi; \
26+
if [[ "${ARCH}" != "riscv64" ]]; then \
27+
ADD_PKGS+=" shim"; \
28+
[[ "${ARCH}" == "aarch64" ]] && ARCH="arm64"; \
29+
fi; \
30+
zypper --non-interactive --gpg-auto-import-keys install --no-recommends -- \
1631
kernel-default \
1732
device-mapper \
1833
dracut \
1934
grub2 \
2035
grub2-${ARCH}-efi \
21-
shim \
2236
haveged \
2337
systemd \
2438
NetworkManager \
@@ -42,7 +56,10 @@ RUN ARCH=$(uname -m); \
4256
less \
4357
sudo \
4458
curl \
45-
sed
59+
sed \
60+
patch \
61+
iproute2 \
62+
${ADD_PKGS}
4663

4764
# Just add the elemental cli
4865
COPY --from=TOOLKIT /usr/bin/elemental /usr/bin/elemental
@@ -53,9 +70,16 @@ RUN systemctl enable NetworkManager.service
5370
# This is for automatic testing purposes, do not do this in production.
5471
RUN echo "PermitRootLogin yes" > /etc/ssh/sshd_config.d/rootlogin.conf
5572

73+
# This is patches are fix upstream dracut, see https://github.com/dracutdevs/dracut/pull/2525
74+
ADD patches /
75+
RUN cd /usr/lib/dracut && \
76+
patch -p 1 -f -i /0001-fix-dmsquash-live-restore-compatibility-with-earlier.patch && \
77+
patch -p 1 -f -i /0001-fix-overlayfs-split-overlayfs-mount-in-two-steps.patch && \
78+
rm /*.patch
79+
5680
# Generate initrd with required elemental services
5781
RUN elemental init -f && \
58-
kernel=$(ls /boot/Image-* | head -n1) && \
82+
kernel=$(ls /boot/Image-* 2>/dev/null | head -n1) && \
5983
if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi && \
6084
rm -rf /var/log/update* && \
6185
>/var/log/lastlog && \
@@ -70,5 +94,3 @@ RUN echo IMAGE_REPO=\"${REPO}\" >> /etc/os-release && \
7094

7195
# Good for validation after the build
7296
CMD /bin/bash
73-
74-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From 0e780720efe6488c4e07af39926575ee12f40339 Mon Sep 17 00:00:00 2001
2+
From: Laszlo Gombos <laszlo.gombos@gmail.com>
3+
Date: Fri, 24 Feb 2023 01:57:19 +0000
4+
Subject: [PATCH] fix(dmsquash-live): restore compatibility with earlier
5+
releases
6+
7+
Follow-up to 40dd5c90e0efcb9ebaa9abb42a38c7316e9706bd .
8+
---
9+
modules.d/90dmsquash-live/dmsquash-live-root.sh | 4 ++++
10+
1 file changed, 4 insertions(+)
11+
12+
diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
13+
index 62d1b5e7..a98e258c 100755
14+
--- a/modules.d/90dmsquash-live/dmsquash-live-root.sh
15+
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
16+
@@ -403,6 +403,10 @@ fi
17+
18+
ROOTFLAGS="$(getarg rootflags)"
19+
20+
+if [ "$overlayfs" = required ]; then
21+
+ echo "rd.live.overlay.overlayfs=1" > /etc/cmdline.d/dmsquash-need-overlay.conf
22+
+fi
23+
+
24+
if [ -n "$overlayfs" ]; then
25+
if [ -n "$FSIMG" ]; then
26+
mkdir -m 0755 -p /run/rootfsbase
27+
--
28+
2.35.3

0 commit comments

Comments
 (0)