Skip to content

Commit

Permalink
[WIP] Add more RISC-V support
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Devulder <ldevulder@suse.com>
  • Loading branch information
ldevulder committed Nov 14, 2023
1 parent 8f68137 commit f329402
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
7 changes: 4 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ builds:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X github.com/rancher/elemental-cli/internal/version.version={{.Tag}}
- -X github.com/rancher/elemental-cli/internal/version.gitCommit={{.Commit}}
- -X github.com/rancher/elemental-toolkit/internal/version.version={{.Tag}}
- -X github.com/rancher/elemental-toolkit/internal/version.gitCommit={{.Commit}}
goos:
- linux
goarch:
- amd64
- arm
- arm64
- riscv64
goarm:
- 6
- 7
Expand Down Expand Up @@ -43,4 +44,4 @@ changelog:
exclude:
- '^docs:'
- '^test:'
- '^Merge pull request'
- '^Merge pull request'
6 changes: 3 additions & 3 deletions pkg/action/build-iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ func (b BuildISOAction) prepareISORoot(isoDir string, rootDir string) error {
b.cfg.Logger.Error("Could not find kernel and/or initrd")
return elementalError.NewFromError(err, elementalError.StatFile)
}
err = utils.MkdirAll(b.cfg.Fs, filepath.Join(isoDir, live.IsoLoaderPath), constants.DirPerm)
err = utils.MkdirAll(b.cfg.Fs, filepath.Join(isoDir, constants.ISOLoaderPath()), constants.DirPerm)
if err != nil {
return elementalError.NewFromError(err, elementalError.CreateDir)
}
//TODO document boot/kernel and boot/initrd expectation in bootloader config
b.cfg.Logger.Debugf("Copying Kernel file %s to iso root tree", kernel)
err = utils.CopyFile(b.cfg.Fs, kernel, filepath.Join(isoDir, constants.ISOKernelPath))
err = utils.CopyFile(b.cfg.Fs, kernel, filepath.Join(isoDir, constants.ISOKernelPath()))
if err != nil {
return elementalError.NewFromError(err, elementalError.CopyFile)
}

b.cfg.Logger.Debugf("Copying initrd file %s to iso root tree", initrd)
err = utils.CopyFile(b.cfg.Fs, initrd, filepath.Join(isoDir, constants.ISOInitrdPath))
err = utils.CopyFile(b.cfg.Fs, initrd, filepath.Join(isoDir, constants.ISOInitrdPath()))
if err != nil {
return elementalError.NewFromError(err, elementalError.CopyFile)
}
Expand Down
30 changes: 27 additions & 3 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package constants
import (
"os"
"runtime"
"strings"
)

const (
Expand Down Expand Up @@ -113,9 +114,6 @@ const (
SELinuxTargetedContextFile = SELinuxTargetedPath + "/contexts/files/file_contexts"
SELinuxTargetedPolicyPath = SELinuxTargetedPath + "/policy"

// Kernel and initrd paths are arbitrary and coupled to grub.cfg
ISOKernelPath = "/boot/x86_64/loader/linux"
ISOInitrdPath = "/boot/x86_64/loader/initrd"
ISORootFile = "rootfs.squashfs"
ISOEFIImg = "uefi.img"
ISOLabel = "COS_LIVE"
Expand Down Expand Up @@ -241,3 +239,29 @@ func GetDiskKeyEnvMap() map[string]string {
// None for the time being
return map[string]string{}
}

// GetBootPath returns path use to store the boot files
func ISOLoaderPath() string {
var arch string

switch strings.ToLower(runtime.GOARCH) {
case ArchAmd64:
arch = Archx86
case ArchArm64:
arch = ArchAarch64
case ArchRiscV64:
arch = ArchRiscV64
}

return "/boot/" + arch + "/loader/"
}

// ISOKernelPath returns path use to store the kernel
func ISOKernelPath() string {
return ISOLoaderPath() + "linux"
}

// ISOInitrdPath returns path use to store the initramfs
func ISOInitrdPath() string {
return ISOLoaderPath() + "initrd"
}
19 changes: 10 additions & 9 deletions pkg/live/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,29 @@ const (
grubCfg = "grub.cfg"
grubPrefixDir = "/boot/grub2"
isoBootCatalog = "/boot/boot.catalog"
)

var (
// TODO document any custom BIOS bootloader must match this setup as these are not configurable
// and coupled with the xorriso call
IsoLoaderPath = "/boot/x86_64/loader"
isoHybridMBR = IsoLoaderPath + "/boot_hybrid.img"
isoBootFile = IsoLoaderPath + "/eltorito.img"
isoHybridMBR = constants.ISOLoaderPath() + "/boot_hybrid.img"
isoBootFile = constants.ISOLoaderPath() + "/eltorito.img"

//TODO use some identifer known to be unique
grubEfiCfg = "search --no-floppy --file --set=root " + constants.ISOKernelPath +
grubEfiCfg = "search --no-floppy --file --set=root " + constants.ISOKernelPath() +
"\nset prefix=($root)" + grubPrefixDir +
"\nconfigfile $prefix/" + grubCfg

// TODO not convinced having such a config here is the best idea
grubCfgTemplate = "search --no-floppy --file --set=root " + constants.ISOKernelPath + "\n" +
grubCfgTemplate = "search --no-floppy --file --set=root " + constants.ISOKernelPath() + "\n" +
`set default=0
set timeout=10
set timeout_style=menu
set linux=linux
set initrd=initrd
if [ "${grub_cpu}" = "x86_64" -o "${grub_cpu}" = "i386" -o "${grub_cpu}" = "arm64" ];then
if [ "${grub_cpu}" = "x86_64" -o "${grub_cpu}" = "i386" -o "${grub_cpu}" = "arm64" -o "${grub_cpu}" = "riscv64" ];then
if [ "${grub_platform}" = "efi" ]; then
if [ "${grub_cpu}" != "arm64" ]; then
if [ "${grub_cpu}" != "arm64" -a "${grub_cpu}" != "riscv64" ]; then
set linux=linuxefi
set initrd=initrdefi
fi
Expand All @@ -64,9 +65,9 @@ const (
menuentry "%s" --class os --unrestricted {
echo Loading kernel...
$linux ($root)` + constants.ISOKernelPath + ` cdroot root=live:CDLABEL=%s rd.live.dir=/ rd.live.squashimg=rootfs.squashfs console=tty1 console=ttyS0 rd.cos.disable cos.setup=` + constants.ISOCloudInitPath + `
$linux ($root)` + constants.ISOKernelPath() + ` cdroot root=live:CDLABEL=%s rd.live.dir=/ rd.live.squashimg=rootfs.squashfs console=tty1 console=ttyS0 rd.cos.disable cos.setup=` + constants.ISOCloudInitPath + `
echo Loading initrd...
$initrd ($root)` + constants.ISOInitrdPath + `
$initrd ($root)` + constants.ISOInitrdPath() + `
}
if [ "${grub_platform}" = "efi" ]; then
Expand Down
4 changes: 2 additions & 2 deletions pkg/live/green.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (g *GreenLiveBootLoader) PrepareISO(rootDir, imageDir string) error {
}

// Create loaders folder
loaderDir := filepath.Join(imageDir, IsoLoaderPath)
loaderDir := filepath.Join(imageDir, constants.ISOLoaderPath())
err = utils.MkdirAll(g.buildCfg.Fs, loaderDir, constants.DirPerm)
if err != nil {
return err
Expand All @@ -145,7 +145,7 @@ func (g *GreenLiveBootLoader) PrepareISO(rootDir, imageDir string) error {
err = utils.CopyFile(
g.buildCfg.Fs,
filepath.Join(rootDir, f),
filepath.Join(imageDir, IsoLoaderPath),
filepath.Join(imageDir, constants.ISOLoaderPath()),
)
if err != nil {
return err
Expand Down

0 comments on commit f329402

Please sign in to comment.