Skip to content

Commit

Permalink
fix: generate images for SBCs using imager
Browse files Browse the repository at this point in the history
See siderolabs/image-factory#43

Two fixes:

* pass path to the dtb, uboot and rpi-firmware explicitly
* include dtb, uboot and rpi-firmware into arm64 installer image when
  generated via imager (regular arm64 installer was fine)

(The generation of SBC images was not broken for Talos itself, but only
when used via Image Factory).

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Oct 30, 2023
1 parent 5dff164 commit cbe6e76
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 95 deletions.
8 changes: 7 additions & 1 deletion cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,13 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {

i.options.Printf("installing U-Boot for %q", b.Name())

if err = b.Install(i.options.Disk); err != nil {
if err = b.Install(runtime.BoardInstallOptions{
InstallDisk: i.options.Disk,
UBootPath: i.options.BootAssets.UBootPath,
DTBPath: i.options.BootAssets.DTBPath,
RPiFirmwarePath: i.options.BootAssets.RPiFirmwarePath,
Printf: i.options.Printf,
}); err != nil {
return err
}
}
Expand Down
11 changes: 10 additions & 1 deletion internal/app/machined/pkg/runtime/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ type PartitionOptions struct {
PartitionsOffset uint64
}

// BoardInstallOptions are the board specific options for installation of various boot assets.
type BoardInstallOptions struct {
InstallDisk string
DTBPath string
UBootPath string
RPiFirmwarePath string
Printf func(string, ...any)
}

// Board defines the requirements for a SBC.
type Board interface {
Name() string
Install(string) error
Install(options BoardInstallOptions) error
KernelArgs() procfs.Parameters
PartitionOptions() *PartitionOptions
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
package bananapim64

import (
"fmt"
"log"
"os"
"path/filepath"

Expand All @@ -20,9 +18,9 @@ import (
)

var (
bin = fmt.Sprintf("/usr/install/arm64/u-boot/%s/u-boot-sunxi-with-spl.bin", constants.BoardBananaPiM64)
bin = constants.BoardBananaPiM64 + "/u-boot-sunxi-with-spl.bin"
off int64 = 1024 * 8
dtb = "/dtb/allwinner/sun50i-a64-bananapi-m64.dtb"
dtb = "allwinner/sun50i-a64-bananapi-m64.dtb"
)

// BananaPiM64 represents the Banana Pi M64.
Expand All @@ -39,23 +37,23 @@ func (b *BananaPiM64) Name() string {
}

// Install implements the runtime.Board.
func (b *BananaPiM64) Install(disk string) (err error) {
func (b *BananaPiM64) Install(options runtime.BoardInstallOptions) (err error) {
var f *os.File

if f, err = os.OpenFile(disk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
if f, err = os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
return err
}
//nolint:errcheck
defer f.Close()

var uboot []byte

uboot, err = os.ReadFile(bin)
uboot, err = os.ReadFile(filepath.Join(options.UBootPath, bin))
if err != nil {
return err
}

log.Printf("writing %s at offset %d", bin, off)
options.Printf("writing %s at offset %d", bin, off)

var n int

Expand All @@ -64,7 +62,7 @@ func (b *BananaPiM64) Install(disk string) (err error) {
return err
}

log.Printf("wrote %d bytes", n)
options.Printf("wrote %d bytes", n)

// NB: In the case that the block device is a loopback device, we sync here
// to esure that the file is written before the loopback device is
Expand All @@ -74,8 +72,8 @@ func (b *BananaPiM64) Install(disk string) (err error) {
return err
}

src := "/usr/install/arm64" + dtb
dst := "/boot/EFI" + dtb
src := filepath.Join(options.DTBPath, dtb)
dst := filepath.Join("/boot/EFI/dtb", dtb)

err = os.MkdirAll(filepath.Dir(dst), 0o600)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// - https://github.com/u-boot/u-boot/blob/v2021.10/configs/p3450-0000_defconfig#L8
// - https://github.com/u-boot/u-boot/blob/v2021.10/include/configs/tegra-common.h#L53
// - https://github.com/u-boot/u-boot/blob/v2021.10/include/configs/tegra210-common.h#L49
var dtb = "/dtb/nvidia/tegra210-p3450-0000.dtb"
var dtb = "nvidia/tegra210-p3450-0000.dtb"

// JetsonNano represents the JetsonNano board
//
Expand All @@ -35,10 +35,10 @@ func (b *JetsonNano) Name() string {
}

// Install implements the runtime.Board.
func (b JetsonNano) Install(disk string) (err error) {
func (b JetsonNano) Install(options runtime.BoardInstallOptions) (err error) {
var f *os.File

if f, err = os.OpenFile(disk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
if f, err = os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
return err
}
//nolint:errcheck
Expand All @@ -52,8 +52,8 @@ func (b JetsonNano) Install(disk string) (err error) {
return err
}

src := "/usr/install/arm64" + dtb
dst := "/boot/EFI" + dtb
src := filepath.Join(options.DTBPath, dtb)
dst := filepath.Join("/boot/EFI/dtb", dtb)

err = os.MkdirAll(filepath.Dir(dst), 0o600)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
package libretechallh3cch5

import (
"fmt"
"log"
"os"
"path/filepath"

Expand All @@ -20,9 +18,9 @@ import (
)

var (
bin = fmt.Sprintf("/usr/install/arm64/u-boot/%s/u-boot-sunxi-with-spl.bin", constants.BoardLibretechAllH3CCH5)
bin = constants.BoardLibretechAllH3CCH5 + "/u-boot-sunxi-with-spl.bin"
off int64 = 1024 * 8
dtb = "/dtb/allwinner/sun50i-h5-libretech-all-h3-cc.dtb"
dtb = "allwinner/sun50i-h5-libretech-all-h3-cc.dtb"
)

// LibretechAllH3CCH5 represents the Libre Computer ALL-H3-CC (Tritium).
Expand All @@ -36,23 +34,23 @@ func (l *LibretechAllH3CCH5) Name() string {
}

// Install implements the runtime.Board.
func (l *LibretechAllH3CCH5) Install(disk string) (err error) {
func (l *LibretechAllH3CCH5) Install(options runtime.BoardInstallOptions) (err error) {
var f *os.File

if f, err = os.OpenFile(disk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
if f, err = os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
return err
}
//nolint:errcheck
defer f.Close()

var uboot []byte

uboot, err = os.ReadFile(bin)
uboot, err = os.ReadFile(filepath.Join(options.UBootPath, bin))
if err != nil {
return err
}

log.Printf("writing %s at offset %d", bin, off)
options.Printf("writing %s at offset %d", bin, off)

var n int

Expand All @@ -61,7 +59,7 @@ func (l *LibretechAllH3CCH5) Install(disk string) (err error) {
return err
}

log.Printf("wrote %d bytes", n)
options.Printf("wrote %d bytes", n)

// NB: In the case that the block device is a loopback device, we sync here
// to esure that the file is written before the loopback device is
Expand All @@ -71,8 +69,8 @@ func (l *LibretechAllH3CCH5) Install(disk string) (err error) {
return err
}

src := "/usr/install/arm64" + dtb
dst := "/boot/EFI" + dtb
src := filepath.Join(options.DTBPath, dtb)
dst := filepath.Join("/boot/EFI/dtb", dtb)

err = os.MkdirAll(filepath.Dir(dst), 0o600)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
package nanopir4s

import (
"fmt"
"log"
"os"
"path/filepath"

Expand All @@ -20,9 +18,9 @@ import (
)

var (
bin = fmt.Sprintf("/usr/install/arm64/u-boot/%s/u-boot-rockchip.bin", constants.BoardNanoPiR4S)
bin = constants.BoardNanoPiR4S + "u-boot-rockchip.bin"
off int64 = 512 * 64
dtb = "/dtb/rockchip/rk3399-nanopi-r4s.dtb"
dtb = "rockchip/rk3399-nanopi-r4s.dtb"
)

// NanoPiR4S represents the Friendlyelec Nano Pi R4S board.
Expand All @@ -36,27 +34,27 @@ func (n *NanoPiR4S) Name() string {
}

// Install implements the runtime.Board.
func (n *NanoPiR4S) Install(disk string) (err error) {
file, err := os.OpenFile(disk, os.O_RDWR|unix.O_CLOEXEC, 0o666)
func (n *NanoPiR4S) Install(options runtime.BoardInstallOptions) (err error) {
file, err := os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666)
if err != nil {
return err
}

defer file.Close() //nolint:errcheck

uboot, err := os.ReadFile(bin)
uboot, err := os.ReadFile(filepath.Join(options.UBootPath, bin))
if err != nil {
return err
}

log.Printf("writing %s at offset %d", bin, off)
options.Printf("writing %s at offset %d", bin, off)

amount, err := file.WriteAt(uboot, off)
if err != nil {
return err
}

log.Printf("wrote %d bytes", amount)
options.Printf("wrote %d bytes", amount)

// NB: In the case that the block device is a loopback device, we sync here
// to esure that the file is written before the loopback device is
Expand All @@ -65,8 +63,8 @@ func (n *NanoPiR4S) Install(disk string) (err error) {
return err
}

src := "/usr/install/arm64" + dtb
dst := "/boot/EFI" + dtb
src := filepath.Join(options.DTBPath, dtb)
dst := filepath.Join("/boot/EFI/dtb", dtb)

if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil {
return err
Expand Down
20 changes: 9 additions & 11 deletions internal/app/machined/pkg/runtime/v1alpha1/board/pine64/pine64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
package pine64

import (
"fmt"
"log"
"os"
"path/filepath"

Expand All @@ -20,9 +18,9 @@ import (
)

var (
bin = fmt.Sprintf("usr/install/arm64/u-boot/%s/u-boot-sunxi-with-spl.bin", constants.BoardPine64)
bin = constants.BoardPine64 + "/u-boot-sunxi-with-spl.bin"
off int64 = 1024 * 8
dtb = "/dtb/allwinner/sun50i-a64-pine64-plus.dtb"
dtb = "allwinner/sun50i-a64-pine64-plus.dtb"
)

// Pine64 represents the Pine64 board
Expand All @@ -37,23 +35,23 @@ func (b *Pine64) Name() string {
}

// Install implements the runtime.Board.
func (b Pine64) Install(disk string) (err error) {
func (b Pine64) Install(options runtime.BoardInstallOptions) (err error) {
var f *os.File

if f, err = os.OpenFile(disk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
if f, err = os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil {
return err
}
//nolint:errcheck
defer f.Close()

var uboot []byte

uboot, err = os.ReadFile(bin)
uboot, err = os.ReadFile(filepath.Join(options.UBootPath, bin))
if err != nil {
return err
}

log.Printf("writing %s at offset %d", bin, off)
options.Printf("writing %s at offset %d", bin, off)

var n int

Expand All @@ -62,7 +60,7 @@ func (b Pine64) Install(disk string) (err error) {
return err
}

log.Printf("wrote %d bytes", n)
options.Printf("wrote %d bytes", n)

// NB: In the case that the block device is a loopback device, we sync here
// to esure that the file is written before the loopback device is
Expand All @@ -72,8 +70,8 @@ func (b Pine64) Install(disk string) (err error) {
return err
}

src := "/usr/install/arm64" + dtb
dst := "/boot/EFI" + dtb
src := filepath.Join(options.DTBPath, dtb)
dst := filepath.Join("/boot/EFI/dtb", dtb)

err = os.MkdirAll(filepath.Dir(dst), 0o600)
if err != nil {
Expand Down
Loading

0 comments on commit cbe6e76

Please sign in to comment.