From 83b4e7f744e3a8ed21443642a9afcf5b1342c62b Mon Sep 17 00:00:00 2001 From: Artem Chernyshev Date: Thu, 11 Mar 2021 18:38:15 +0300 Subject: [PATCH] feat: add Rock pi 4 support Another nice addition to the list of supported SBCs. Signed-off-by: Artem Chernyshev --- Makefile | 2 +- .../pkg/runtime/v1alpha1/board/board.go | 3 + .../runtime/v1alpha1/board/rockpi4/rockpi4.go | 93 +++++++++++++++++++ pkg/machinery/constants/constants.go | 3 + .../v0.9/Single Board Computers/rockpi_4.md | 57 ++++++++++++ 5 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go create mode 100644 website/content/docs/v0.9/Single Board Computers/rockpi_4.md diff --git a/Makefile b/Makefile index 640620669..4c2c92c61 100644 --- a/Makefile +++ b/Makefile @@ -166,7 +166,7 @@ image-%: ## Builds the specified image. Valid options are aws, azure, digital-oc images: image-aws image-azure image-digital-ocean image-gcp image-metal image-openstack image-vmware ## Builds all known images (AWS, Azure, Digital Ocean, GCP, Metal, Openstack, and VMware). -sbc-%: ## Builds the specified SBC image. Valid options are rpi_4, rock64, bananapi_m64, and libretech_all_h3_cc_h5 (e.g. sbc-rpi_4) +sbc-%: ## Builds the specified SBC image. Valid options are rpi_4, rock64, bananapi_m64, libretech_all_h3_cc_h5, and rockpi_4 (e.g. sbc-rpi_4) @docker pull $(REGISTRY_AND_USERNAME)/installer:$(TAG) @docker run --rm -v /dev:/dev --privileged $(REGISTRY_AND_USERNAME)/installer:$(TAG) image --platform metal --board $* --tar-to-stdout | tar xz -C $(ARTIFACTS) diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/board.go b/internal/app/machined/pkg/runtime/v1alpha1/board/board.go index f740669d0..871b4b2d0 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/board.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/board.go @@ -15,6 +15,7 @@ import ( bananapim64 "github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/board/bananapi_m64" libretechallh3cch5 "github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/board/libretech_all_h3_cc_h5" "github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/board/rock64" + rockpi4 "github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4" rpi4 "github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/board/rpi_4" "github.com/talos-systems/talos/pkg/machinery/constants" ) @@ -55,6 +56,8 @@ func newBoard(board string) (b runtime.Board, err error) { b = &bananapim64.BananaPiM64{} case constants.BoardRock64: b = &rock64.Rock64{} + case constants.BoardRockpi4: + b = &rockpi4.Rockpi4{} default: return nil, fmt.Errorf("unsupported board: %q", board) } diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go b/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go new file mode 100644 index 000000000..3ebb1d93f --- /dev/null +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go @@ -0,0 +1,93 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package rock64 + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + + "github.com/talos-systems/go-procfs/procfs" + "golang.org/x/sys/unix" + + "github.com/talos-systems/talos/internal/app/machined/pkg/runtime" + "github.com/talos-systems/talos/pkg/copy" + "github.com/talos-systems/talos/pkg/machinery/constants" +) + +var ( + bin = fmt.Sprintf("/usr/install/u-boot/%s/u-boot-rockchip.bin", constants.BoardRockpi4) + off int64 = 512 * 64 + dtb = "/dtb/rockchip/rk3399-rock-pi-4c.dtb" +) + +// Rockpi4 represents the Radxa rock pi board. +// +// Reference: https://rockpi.org/ +type Rockpi4 struct{} + +// Name implements the runtime.Board. +func (r *Rockpi4) Name() string { + return constants.BoardRockpi4 +} + +// Install implements the runtime.Board. +func (r *Rockpi4) Install(disk string) (err error) { + var f *os.File + + if f, err = os.OpenFile(disk, os.O_RDWR|unix.O_CLOEXEC, 0o666); err != nil { + return err + } + + defer f.Close() //nolint:errcheck + + uboot, err := ioutil.ReadFile(bin) + if err != nil { + return err + } + + log.Printf("writing %s at offset %d", bin, off) + + var n int + + n, err = f.WriteAt(uboot, off) + if err != nil { + return err + } + + log.Printf("wrote %d bytes", n) + + // NB: In the case that the block device is a loopback device, we sync here + // to esure that the file is written before the loopback device is + // unmounted. + err = f.Sync() + if err != nil { + return err + } + + src := "/usr/install" + dtb + dst := "/boot/EFI" + dtb + + err = os.MkdirAll(filepath.Dir(dst), 0o600) + if err != nil { + return err + } + + return copy.File(src, dst) +} + +// KernelArgs implements the runtime.Board. +func (r *Rockpi4) KernelArgs() procfs.Parameters { + return []*procfs.Parameter{ + procfs.NewParameter("console").Append("tty0").Append("ttyS2,1500000n8"), + } +} + +// PartitionOptions implements the runtime.Board. +func (r *Rockpi4) PartitionOptions() *runtime.PartitionOptions { + return &runtime.PartitionOptions{PartitionsOffset: 2048 * 10} +} diff --git a/pkg/machinery/constants/constants.go b/pkg/machinery/constants/constants.go index 5063d8e4d..e93dac8a2 100644 --- a/pkg/machinery/constants/constants.go +++ b/pkg/machinery/constants/constants.go @@ -46,6 +46,9 @@ const ( // BoardRock64 is the name of the Pine64 Rock64. BoardRock64 = "rock64" + // BoardRockpi4 is the name of the Radxa Rock pi 4. + BoardRockpi4 = "rockpi_4" + // KernelParamHostname is the kernel parameter name for specifying the // hostname. KernelParamHostname = "talos.hostname" diff --git a/website/content/docs/v0.9/Single Board Computers/rockpi_4.md b/website/content/docs/v0.9/Single Board Computers/rockpi_4.md new file mode 100644 index 000000000..6c164e7fa --- /dev/null +++ b/website/content/docs/v0.9/Single Board Computers/rockpi_4.md @@ -0,0 +1,57 @@ +--- +title: "Radxa ROCK PI 4c" +description: "Installing Talos on Radxa ROCK PI 4c SBC using raw disk image." +--- + +## Prerequisites + +You will need + +- `talosctl` +- an SD card + +Download the latest alpha `talosctl`. + +```bash +curl -Lo /usr/local/bin/talosctl https://github.com/talos-systems/talos/releases/latest/download/talosctl-$(uname -s | tr "[:upper:]" "[:lower:]")-amd64 +chmod +x /usr/local/bin/talosctl +``` + +## Download the Image + +Download the image and decompress it: + +```bash +curl -LO https://github.com/talos-systems/talos/releases/latest/download/metal-rockpi_4-arm64.img.xz +xz -d metal-rockpi_4-arm64.img.xz +``` + +## Writing the Image + +The path to your SD card can be found using `fdisk` on Linux or `diskutil` on Mac OS. +In this example we will assume `/dev/mmcblk0`. + +Now `dd` the image to your SD card: + +```bash +sudo dd if=metal-rockpi_4-arm64.img of=/dev/mmcblk0 conv=fsync bs=4M +``` + +## Bootstrapping the Node + +Insert the SD card to your board, turn it on and wait for the console to show you the instructions for bootstrapping the node. +Following the instructions in the console output to connect to the interactive installer: + +```bash +talosctl apply-config --insecure --interactive --nodes +``` + +Once the interactive installation is applied, the cluster will form and you can then use `kubectl`. + +## Retrieve the `kubeconfig` + +Retrieve the admin `kubeconfig` by running: + +```bash +talosctl kubeconfig +```