|
| 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 turingrk1 provides the Turing RK1 board implementation. |
| 6 | +package turingrk1 |
| 7 | + |
| 8 | +import ( |
| 9 | + "os" |
| 10 | + "path/filepath" |
| 11 | + |
| 12 | + "github.com/siderolabs/go-procfs/procfs" |
| 13 | + "golang.org/x/sys/unix" |
| 14 | + |
| 15 | + "github.com/siderolabs/talos/internal/app/machined/pkg/runtime" |
| 16 | + "github.com/siderolabs/talos/pkg/copy" |
| 17 | + "github.com/siderolabs/talos/pkg/machinery/constants" |
| 18 | +) |
| 19 | + |
| 20 | +var ( |
| 21 | + bin = constants.BoardTuringRK1 + "/u-boot-rockchip.bin" |
| 22 | + off int64 = 512 * 64 |
| 23 | + dtb = "rockchip/rk3588-turing-rk1.dtb" |
| 24 | +) |
| 25 | + |
| 26 | +// TuringRK1 represents the Turing RK1 board. |
| 27 | +// |
| 28 | +// Reference: https://turingpi.com/product/turing-rk1/ |
| 29 | +type TuringRK1 struct{} |
| 30 | + |
| 31 | +// Name implements the runtime.Board. |
| 32 | +func (b *TuringRK1) Name() string { |
| 33 | + return constants.BoardTuringRK1 |
| 34 | +} |
| 35 | + |
| 36 | +// Install implements the runtime.Board. |
| 37 | +func (b *TuringRK1) Install(options runtime.BoardInstallOptions) (err error) { |
| 38 | + file, err := os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666) |
| 39 | + if err != nil { |
| 40 | + return err |
| 41 | + } |
| 42 | + |
| 43 | + defer file.Close() //nolint:errcheck |
| 44 | + |
| 45 | + uboot, err := os.ReadFile(filepath.Join(options.UBootPath, bin)) |
| 46 | + if err != nil { |
| 47 | + return err |
| 48 | + } |
| 49 | + |
| 50 | + options.Printf("writing %s at offset %d", bin, off) |
| 51 | + |
| 52 | + amount, err := file.WriteAt(uboot, off) |
| 53 | + if err != nil { |
| 54 | + return err |
| 55 | + } |
| 56 | + |
| 57 | + options.Printf("wrote %d bytes", amount) |
| 58 | + |
| 59 | + // NB: In the case that the block device is a loopback device, we sync here |
| 60 | + // to esure that the file is written before the loopback device is |
| 61 | + // unmounted. |
| 62 | + if err := file.Sync(); err != nil { |
| 63 | + return err |
| 64 | + } |
| 65 | + |
| 66 | + src := filepath.Join(options.DTBPath, dtb) |
| 67 | + dst := filepath.Join("/boot/EFI/dtb", dtb) |
| 68 | + |
| 69 | + if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil { |
| 70 | + return err |
| 71 | + } |
| 72 | + |
| 73 | + return copy.File(src, dst) |
| 74 | +} |
| 75 | + |
| 76 | +// KernelArgs implements the runtime.Board. |
| 77 | +func (n *TuringRK1) KernelArgs() procfs.Parameters { |
| 78 | + return []*procfs.Parameter{ |
| 79 | + procfs.NewParameter("console").Append("tty0").Append("ttyS0,115200"), |
| 80 | + procfs.NewParameter("sysctl.kernel.kexec_load_disabled").Append("1"), |
| 81 | + procfs.NewParameter(constants.KernelParamDashboardDisabled).Append("1"), |
| 82 | + procfs.NewParameter("irqchip.gicv3_pseudo_nmi").Append("0"), |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +// PartitionOptions implements the runtime.Board. |
| 87 | +func (n *TuringRK1) PartitionOptions() *runtime.PartitionOptions { |
| 88 | + return &runtime.PartitionOptions{PartitionsOffset: 2048 * 10} |
| 89 | +} |
0 commit comments