|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +package main |
| 6 | + |
| 7 | +import ( |
| 8 | + _ "embed" |
| 9 | + "fmt" |
| 10 | + "os" |
| 11 | + "path/filepath" |
| 12 | + |
| 13 | + "github.com/siderolabs/go-copy/copy" |
| 14 | + "github.com/siderolabs/talos/pkg/machinery/overlay" |
| 15 | + "github.com/siderolabs/talos/pkg/machinery/overlay/adapter" |
| 16 | + "golang.org/x/sys/unix" |
| 17 | +) |
| 18 | + |
| 19 | +const ( |
| 20 | + off int64 = 512 * 64 |
| 21 | + board = "rock5a" |
| 22 | + dtb = "rockchip/rk3588s-rock-5a.dtb" |
| 23 | +) |
| 24 | + |
| 25 | +func main() { |
| 26 | + adapter.Execute(&rock5a{}) |
| 27 | +} |
| 28 | + |
| 29 | +type rock5a struct{} |
| 30 | + |
| 31 | +type rock5aExtraOptions struct{} |
| 32 | + |
| 33 | +func (i *rock5a) GetOptions(extra rock5aExtraOptions) (overlay.Options, error) { |
| 34 | + 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 | + PartitionOptions: overlay.PartitionOptions{ |
| 45 | + Offset: 2048 * 10, |
| 46 | + }, |
| 47 | + }, nil |
| 48 | +} |
| 49 | + |
| 50 | +func (i *rock5a) Install(options overlay.InstallOptions[rock5aExtraOptions]) error { |
| 51 | + var f *os.File |
| 52 | + |
| 53 | + f, err := os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666) |
| 54 | + if err != nil { |
| 55 | + return fmt.Errorf("failed to open %s: %w", options.InstallDisk, err) |
| 56 | + } |
| 57 | + |
| 58 | + defer f.Close() //nolint:errcheck |
| 59 | + |
| 60 | + uboot, err := os.ReadFile(filepath.Join(options.ArtifactsPath, "arm64/u-boot", board, "u-boot-rockchip.bin")) |
| 61 | + if err != nil { |
| 62 | + return err |
| 63 | + } |
| 64 | + |
| 65 | + if _, err = f.WriteAt(uboot, off); err != nil { |
| 66 | + return err |
| 67 | + } |
| 68 | + |
| 69 | + // NB: In the case that the block device is a loopback device, we sync here |
| 70 | + // to ensure that the file is written before the loopback device is |
| 71 | + // unmounted. |
| 72 | + 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) |
| 86 | +} |
0 commit comments