Skip to content

Commit

Permalink
feat: support skipping u-boot install
Browse files Browse the repository at this point in the history
Support skipping u-boot install for boards that support booting from
u-boot residing in SPI flash.

Signed-off-by: Louis SCHNEIDER <[email protected]>
Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
schneid-l authored and frezbo committed Jan 27, 2025
1 parent 1b80f16 commit fe16967
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 68 deletions.
2 changes: 1 addition & 1 deletion artifacts/orangepi-5/u-boot/pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ steps:
install:
- |
mkdir -p /rootfs/artifacts/arm64/u-boot/orangepi-5
cp -v -t /rootfs/artifacts/arm64/u-boot/orangepi-5 u-boot-rockchip.bin
cp -v -t /rootfs/artifacts/arm64/u-boot/orangepi-5 u-boot-rockchip.bin u-boot-rockchip-spi.bin
finalize:
- from: /rootfs
to: /rootfs
17 changes: 10 additions & 7 deletions artifacts/rock5b/u-boot/pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- stage: arm-trusted-firmware-rk3588
- stage: rkbin-rk3588
platform: linux/amd64

steps:
- sources:
- url: https://ftp.denx.de/pub/u-boot/u-boot-{{ .uboot_rk1_version }}.tar.bz2
Expand All @@ -20,16 +21,18 @@ steps:
prepare:
# rock-5b-rk3588
- |
mkdir -p /usr/bin \
&& ln -sf /toolchain/bin/env /usr/bin/env \
&& ln -sf /toolchain/bin/python3 /toolchain/bin/python
mkdir -p /usr/bin
ln -sf /toolchain/bin/env /usr/bin/env
ln -sf /toolchain/bin/python3 /toolchain/bin/python
pip3 install pyelftools setuptools \
&& ln -sf /toolchain/bin/python3 /toolchain/bin/python
pip3 install pyelftools setuptools
tar xf u-boot.tar.bz2 --strip-components=1
patch -p1 < /pkg/patches/uboot-byteorder.patch
for patch in $(find /pkg/patches -type f -name "*.patch" | sort); do
echo "Applying $patch"
patch -p1 < $patch || (echo "Failed to apply patch $patch" && exit 1)
done
- |
make rock5b-rk3588_defconfig
build:
Expand All @@ -38,7 +41,7 @@ steps:
install:
- |
mkdir -p /rootfs/artifacts/arm64/u-boot/rock5b
cp u-boot-rockchip.bin /rootfs/artifacts/arm64/u-boot/rock5b
cp -v -t /rootfs/artifacts/arm64/u-boot/rock5b u-boot-rockchip.bin u-boot-rockchip-spi.bin
finalize:
- from: /rootfs
to: /rootfs
27 changes: 11 additions & 16 deletions installers/orangepi-5/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func main() {

type opi5Installer struct{}

type opi5ExtraOptions struct{}
type opi5ExtraOptions struct {
SPIBoot bool `yaml:"spi_boot,omitempty"`
}

func (i *opi5Installer) GetOptions(extra opi5ExtraOptions) (overlay.Options, error) {
kernelArgs := []string{
Expand All @@ -37,7 +39,7 @@ func (i *opi5Installer) GetOptions(extra opi5ExtraOptions) (overlay.Options, err
"talos.dashboard.disabled=1",
}
return overlay.Options{
Name: "opi5",
Name: "orangepi-5",
KernelArgs: kernelArgs,
PartitionOptions: overlay.PartitionOptions{
Offset: 2048 * 10,
Expand All @@ -46,33 +48,26 @@ func (i *opi5Installer) GetOptions(extra opi5ExtraOptions) (overlay.Options, err
}

func (i *opi5Installer) Install(options overlay.InstallOptions[opi5ExtraOptions]) error {
var err error

var (
uBootBin = filepath.Join(options.ArtifactsPath, "arm64/u-boot/orangepi-5/u-boot-rockchip.bin")
)
if !options.ExtraOptions.SPIBoot {
uBootBin := filepath.Join(options.ArtifactsPath, "arm64/u-boot/orangepi-5/u-boot-rockchip.bin")

err = uBootLoaderInstall(uBootBin, options.InstallDisk)
if err != nil {
return err
if err := uBootLoaderInstall(uBootBin, options.InstallDisk); err != nil {
return err
}
}

src := filepath.Join(options.ArtifactsPath, "arm64/dtb", dtb)
dst := filepath.Join(options.MountPrefix, "boot/EFI/dtb", dtb)

err = copyFileAndCreateDir(src, dst)
if err != nil {
if err := copyFileAndCreateDir(src, dst); err != nil {
return err
}

return nil

}

func copyFileAndCreateDir(src, dst string) error {
err := os.MkdirAll(filepath.Dir(dst), 0o600)

if err != nil {
if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil {
return err
}

Expand Down
75 changes: 46 additions & 29 deletions installers/rock5b/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import (
)

const (
off int64 = 512 * 64
board = "rock5b"
dtb = "rockchip/rk3588-rock-5b.dtb"
off int64 = 512 * 64
dtb = "rockchip/rk3588-rock-5b.dtb"
)

func main() {
Expand All @@ -28,36 +27,66 @@ func main() {

type rock5b struct{}

type rock5bExtraOptions struct{}
type rock5bExtraOptions struct {
SPIBoot bool `yaml:"spi_boot,omitempty"`
}

func (i *rock5b) GetOptions(extra rock5bExtraOptions) (overlay.Options, error) {
kernelArgs := []string{
"cma=128MB",
"console=tty0",
"console=ttyS9,115200",
"console=ttyS2,115200",
"sysctl.kernel.kexec_load_disabled=1",
"talos.dashboard.disabled=1",
}
return overlay.Options{
Name: board,
KernelArgs: []string{
"cma=128MB",
"console=tty0",
"console=ttyS9,115200",
"console=ttyS2,115200",
"sysctl.kernel.kexec_load_disabled=1",
"talos.dashboard.disabled=1",
},
Name: "rock5b",
KernelArgs: kernelArgs,
PartitionOptions: overlay.PartitionOptions{
Offset: 2048 * 10,
},
}, nil
}

func (i *rock5b) Install(options overlay.InstallOptions[rock5bExtraOptions]) error {
if !options.ExtraOptions.SPIBoot {
uBootBin := filepath.Join(options.ArtifactsPath, "arm64/u-boot/rock5b/u-boot-rockchip.bin")

if err := uBootLoaderInstall(uBootBin, options.InstallDisk); err != nil {
return err
}
}

src := filepath.Join(options.ArtifactsPath, "arm64/dtb", dtb)
dst := filepath.Join(options.MountPrefix, "boot/EFI/dtb", dtb)

if err := copyFileAndCreateDir(src, dst); err != nil {
return err
}

return nil
}

func copyFileAndCreateDir(src, dst string) error {
if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil {
return err
}

return copy.File(src, dst)
}

func uBootLoaderInstall(uBootBin, installDisk string) error {
var f *os.File

f, err := os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666)
f, err := os.OpenFile(installDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666)
if err != nil {
return fmt.Errorf("failed to open %s: %w", options.InstallDisk, err)
return fmt.Errorf("failed to open %s: %w", installDisk, err)
}

defer f.Close() //nolint:errcheck

uboot, err := os.ReadFile(filepath.Join(options.ArtifactsPath, "arm64/u-boot", board, "u-boot-rockchip.bin"))
uboot, err := os.ReadFile(uBootBin)
if err != nil {
return err
}
Expand All @@ -70,17 +99,5 @@ func (i *rock5b) Install(options overlay.InstallOptions[rock5bExtraOptions]) err
// to esure that the file is written before the loopback device is
// unmounted.
err = f.Sync()
if err != nil {
return err
}

src := filepath.Join(options.ArtifactsPath, "arm64/dtb", dtb)
dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb)

err = os.MkdirAll(filepath.Dir(dst), 0o600)
if err != nil {
return err
}

return copy.File(src, dst)
return err
}
25 changes: 10 additions & 15 deletions installers/turingrk1/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func main() {

type turingRK1Installer struct{}

type turingRK1ExtraOptions struct{}
type turingRK1ExtraOptions struct {
SPIBoot bool `yaml:"spi_boot,omitempty"`
}

func (i *turingRK1Installer) GetOptions(extra turingRK1ExtraOptions) (overlay.Options, error) {
kernelArgs := []string{
Expand All @@ -49,23 +51,18 @@ func (i *turingRK1Installer) GetOptions(extra turingRK1ExtraOptions) (overlay.Op
}

func (i *turingRK1Installer) Install(options overlay.InstallOptions[turingRK1ExtraOptions]) error {
var err error

var (
uBootBin = filepath.Join(options.ArtifactsPath, "arm64/u-boot/turingrk1/u-boot-rockchip.bin")
//uBootSpiBin = filepath.Join(options.ArtifactsPath, "arm64/u-boot/turingrk1/u-boot-rockchip-spi.bin")
)
if !options.ExtraOptions.SPIBoot {
uBootBin := filepath.Join(options.ArtifactsPath, "arm64/u-boot/turingrk1/u-boot-rockchip.bin")

err = uBootLoaderInstall(uBootBin, options.InstallDisk)
if err != nil {
return err
if err := uBootLoaderInstall(uBootBin, options.InstallDisk); err != nil {
return err
}
}

src := filepath.Join(options.ArtifactsPath, "arm64/dtb", dtb)
dst := filepath.Join(options.MountPrefix, "boot/EFI/dtb", dtb)

err = copyFileAndCreateDir(src, dst)
if err != nil {
if err := copyFileAndCreateDir(src, dst); err != nil {
return err
}

Expand All @@ -74,9 +71,7 @@ func (i *turingRK1Installer) Install(options overlay.InstallOptions[turingRK1Ext
}

func copyFileAndCreateDir(src, dst string) error {
err := os.MkdirAll(filepath.Dir(dst), 0o600)

if err != nil {
if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil {
return err
}

Expand Down

0 comments on commit fe16967

Please sign in to comment.