@@ -17,9 +17,8 @@ import (
1717)
1818
1919const (
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
2524func main () {
@@ -28,36 +27,66 @@ func main() {
2827
2928type rock5b struct {}
3029
31- type rock5bExtraOptions struct {}
30+ type rock5bExtraOptions struct {
31+ SPIBoot bool `yaml:"spi_boot,omitempty"`
32+ }
3233
3334func (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
5052func (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}
0 commit comments