Skip to content

Commit fe16967

Browse files
schneid-lfrezbo
authored andcommitted
feat: support skipping u-boot install
Support skipping u-boot install for boards that support booting from u-boot residing in SPI flash. Signed-off-by: Louis SCHNEIDER <louis@schne.id> Signed-off-by: Noel Georgi <git@frezbo.dev>
1 parent 1b80f16 commit fe16967

5 files changed

Lines changed: 78 additions & 68 deletions

File tree

artifacts/orangepi-5/u-boot/pkg.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ steps:
4141
install:
4242
- |
4343
mkdir -p /rootfs/artifacts/arm64/u-boot/orangepi-5
44-
cp -v -t /rootfs/artifacts/arm64/u-boot/orangepi-5 u-boot-rockchip.bin
44+
cp -v -t /rootfs/artifacts/arm64/u-boot/orangepi-5 u-boot-rockchip.bin u-boot-rockchip-spi.bin
4545
finalize:
4646
- from: /rootfs
4747
to: /rootfs

artifacts/rock5b/u-boot/pkg.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies:
99
- stage: arm-trusted-firmware-rk3588
1010
- stage: rkbin-rk3588
1111
platform: linux/amd64
12+
1213
steps:
1314
- sources:
1415
- url: https://ftp.denx.de/pub/u-boot/u-boot-{{ .uboot_rk1_version }}.tar.bz2
@@ -20,16 +21,18 @@ steps:
2021
prepare:
2122
# rock-5b-rk3588
2223
- |
23-
mkdir -p /usr/bin \
24-
&& ln -sf /toolchain/bin/env /usr/bin/env \
25-
&& ln -sf /toolchain/bin/python3 /toolchain/bin/python
24+
mkdir -p /usr/bin
25+
ln -sf /toolchain/bin/env /usr/bin/env
26+
ln -sf /toolchain/bin/python3 /toolchain/bin/python
2627
27-
pip3 install pyelftools setuptools \
28-
&& ln -sf /toolchain/bin/python3 /toolchain/bin/python
28+
pip3 install pyelftools setuptools
2929
3030
tar xf u-boot.tar.bz2 --strip-components=1
3131
32-
patch -p1 < /pkg/patches/uboot-byteorder.patch
32+
for patch in $(find /pkg/patches -type f -name "*.patch" | sort); do
33+
echo "Applying $patch"
34+
patch -p1 < $patch || (echo "Failed to apply patch $patch" && exit 1)
35+
done
3336
- |
3437
make rock5b-rk3588_defconfig
3538
build:
@@ -38,7 +41,7 @@ steps:
3841
install:
3942
- |
4043
mkdir -p /rootfs/artifacts/arm64/u-boot/rock5b
41-
cp u-boot-rockchip.bin /rootfs/artifacts/arm64/u-boot/rock5b
44+
cp -v -t /rootfs/artifacts/arm64/u-boot/rock5b u-boot-rockchip.bin u-boot-rockchip-spi.bin
4245
finalize:
4346
- from: /rootfs
4447
to: /rootfs

installers/orangepi-5/src/main.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func main() {
2727

2828
type opi5Installer struct{}
2929

30-
type opi5ExtraOptions struct{}
30+
type opi5ExtraOptions struct {
31+
SPIBoot bool `yaml:"spi_boot,omitempty"`
32+
}
3133

3234
func (i *opi5Installer) GetOptions(extra opi5ExtraOptions) (overlay.Options, error) {
3335
kernelArgs := []string{
@@ -37,7 +39,7 @@ func (i *opi5Installer) GetOptions(extra opi5ExtraOptions) (overlay.Options, err
3739
"talos.dashboard.disabled=1",
3840
}
3941
return overlay.Options{
40-
Name: "opi5",
42+
Name: "orangepi-5",
4143
KernelArgs: kernelArgs,
4244
PartitionOptions: overlay.PartitionOptions{
4345
Offset: 2048 * 10,
@@ -46,33 +48,26 @@ func (i *opi5Installer) GetOptions(extra opi5ExtraOptions) (overlay.Options, err
4648
}
4749

4850
func (i *opi5Installer) Install(options overlay.InstallOptions[opi5ExtraOptions]) error {
49-
var err error
50-
51-
var (
52-
uBootBin = filepath.Join(options.ArtifactsPath, "arm64/u-boot/orangepi-5/u-boot-rockchip.bin")
53-
)
51+
if !options.ExtraOptions.SPIBoot {
52+
uBootBin := filepath.Join(options.ArtifactsPath, "arm64/u-boot/orangepi-5/u-boot-rockchip.bin")
5453

55-
err = uBootLoaderInstall(uBootBin, options.InstallDisk)
56-
if err != nil {
57-
return err
54+
if err := uBootLoaderInstall(uBootBin, options.InstallDisk); err != nil {
55+
return err
56+
}
5857
}
5958

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

63-
err = copyFileAndCreateDir(src, dst)
64-
if err != nil {
62+
if err := copyFileAndCreateDir(src, dst); err != nil {
6563
return err
6664
}
6765

6866
return nil
69-
7067
}
7168

7269
func copyFileAndCreateDir(src, dst string) error {
73-
err := os.MkdirAll(filepath.Dir(dst), 0o600)
74-
75-
if err != nil {
70+
if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil {
7671
return err
7772
}
7873

installers/rock5b/src/main.go

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import (
1717
)
1818

1919
const (
20-
off int64 = 512 * 64
21-
board = "rock5b"
22-
dtb = "rockchip/rk3588-rock-5b.dtb"
20+
off int64 = 512 * 64
21+
dtb = "rockchip/rk3588-rock-5b.dtb"
2322
)
2423

2524
func main() {
@@ -28,36 +27,66 @@ func main() {
2827

2928
type rock5b struct{}
3029

31-
type rock5bExtraOptions struct{}
30+
type rock5bExtraOptions struct {
31+
SPIBoot bool `yaml:"spi_boot,omitempty"`
32+
}
3233

3334
func (i *rock5b) GetOptions(extra rock5bExtraOptions) (overlay.Options, error) {
35+
kernelArgs := []string{
36+
"cma=128MB",
37+
"console=tty0",
38+
"console=ttyS9,115200",
39+
"console=ttyS2,115200",
40+
"sysctl.kernel.kexec_load_disabled=1",
41+
"talos.dashboard.disabled=1",
42+
}
3443
return overlay.Options{
35-
Name: board,
36-
KernelArgs: []string{
37-
"cma=128MB",
38-
"console=tty0",
39-
"console=ttyS9,115200",
40-
"console=ttyS2,115200",
41-
"sysctl.kernel.kexec_load_disabled=1",
42-
"talos.dashboard.disabled=1",
43-
},
44+
Name: "rock5b",
45+
KernelArgs: kernelArgs,
4446
PartitionOptions: overlay.PartitionOptions{
4547
Offset: 2048 * 10,
4648
},
4749
}, nil
4850
}
4951

5052
func (i *rock5b) Install(options overlay.InstallOptions[rock5bExtraOptions]) error {
53+
if !options.ExtraOptions.SPIBoot {
54+
uBootBin := filepath.Join(options.ArtifactsPath, "arm64/u-boot/rock5b/u-boot-rockchip.bin")
55+
56+
if err := uBootLoaderInstall(uBootBin, options.InstallDisk); err != nil {
57+
return err
58+
}
59+
}
60+
61+
src := filepath.Join(options.ArtifactsPath, "arm64/dtb", dtb)
62+
dst := filepath.Join(options.MountPrefix, "boot/EFI/dtb", dtb)
63+
64+
if err := copyFileAndCreateDir(src, dst); err != nil {
65+
return err
66+
}
67+
68+
return nil
69+
}
70+
71+
func copyFileAndCreateDir(src, dst string) error {
72+
if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil {
73+
return err
74+
}
75+
76+
return copy.File(src, dst)
77+
}
78+
79+
func uBootLoaderInstall(uBootBin, installDisk string) error {
5180
var f *os.File
5281

53-
f, err := os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666)
82+
f, err := os.OpenFile(installDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666)
5483
if err != nil {
55-
return fmt.Errorf("failed to open %s: %w", options.InstallDisk, err)
84+
return fmt.Errorf("failed to open %s: %w", installDisk, err)
5685
}
5786

5887
defer f.Close() //nolint:errcheck
5988

60-
uboot, err := os.ReadFile(filepath.Join(options.ArtifactsPath, "arm64/u-boot", board, "u-boot-rockchip.bin"))
89+
uboot, err := os.ReadFile(uBootBin)
6190
if err != nil {
6291
return err
6392
}
@@ -70,17 +99,5 @@ func (i *rock5b) Install(options overlay.InstallOptions[rock5bExtraOptions]) err
7099
// to esure that the file is written before the loopback device is
71100
// unmounted.
72101
err = f.Sync()
73-
if err != nil {
74-
return err
75-
}
76-
77-
src := filepath.Join(options.ArtifactsPath, "arm64/dtb", dtb)
78-
dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb)
79-
80-
err = os.MkdirAll(filepath.Dir(dst), 0o600)
81-
if err != nil {
82-
return err
83-
}
84-
85-
return copy.File(src, dst)
102+
return err
86103
}

installers/turingrk1/src/main.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func main() {
2727

2828
type turingRK1Installer struct{}
2929

30-
type turingRK1ExtraOptions struct{}
30+
type turingRK1ExtraOptions struct {
31+
SPIBoot bool `yaml:"spi_boot,omitempty"`
32+
}
3133

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

5153
func (i *turingRK1Installer) Install(options overlay.InstallOptions[turingRK1ExtraOptions]) error {
52-
var err error
53-
54-
var (
55-
uBootBin = filepath.Join(options.ArtifactsPath, "arm64/u-boot/turingrk1/u-boot-rockchip.bin")
56-
//uBootSpiBin = filepath.Join(options.ArtifactsPath, "arm64/u-boot/turingrk1/u-boot-rockchip-spi.bin")
57-
)
54+
if !options.ExtraOptions.SPIBoot {
55+
uBootBin := filepath.Join(options.ArtifactsPath, "arm64/u-boot/turingrk1/u-boot-rockchip.bin")
5856

59-
err = uBootLoaderInstall(uBootBin, options.InstallDisk)
60-
if err != nil {
61-
return err
57+
if err := uBootLoaderInstall(uBootBin, options.InstallDisk); err != nil {
58+
return err
59+
}
6260
}
6361

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

67-
err = copyFileAndCreateDir(src, dst)
68-
if err != nil {
65+
if err := copyFileAndCreateDir(src, dst); err != nil {
6966
return err
7067
}
7168

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

7673
func copyFileAndCreateDir(src, dst string) error {
77-
err := os.MkdirAll(filepath.Dir(dst), 0o600)
78-
79-
if err != nil {
74+
if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil {
8075
return err
8176
}
8277

0 commit comments

Comments
 (0)