Skip to content

Commit

Permalink
feat: add rock-4se
Browse files Browse the repository at this point in the history
This board is special in that u-boot needs to use the external
proprietary TPL for initializing DRAM. Add the rockchip repo contains
various TPLs needed for initializing DRAM on Rockchip SBCs.

Signed-off-by: Boran Car <[email protected]>
Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
borancar authored and frezbo committed Jun 21, 2024
1 parent bcd5ceb commit 8b17bba
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Pkgfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ vars:
uboot_version: 2024.07-rc4
uboot_sha256: 8d36b3fd0b47fe93fc03abb25aac2c26b7c2a1bf2b1c746788c0fc4af68786c5
uboot_sha512: 2fa73c48ab4f6e60cee11ebac79a35e1b15d95eba5d8bb3612bd354e6b6153bfc17fcf1783b6b410a8b78505535152eab9f2cfbb35a6f19af7f7af7b2741e2a6

rkbin_commit: a2a0b89b6c8c612dca5ed9ed8a68db8a07f68bc0
rkbin_sha256: 9df375316869daadbf874410f4097591c32cc2dca5a30fd328ea7a1cd8f8b6a8
rkbin_sha512: 715253b5ef5c7fbcbce8478d4dea5ad3d1b4b738da437b5f0e9b31eed20f9bcb86cab082e4c04c69b42b6ffcc2cbb1a31079b33b968bb76826ff0dd4f83043e1
labels:
org.opencontainers.image.source: https://github.com/siderolabs/sbc-rockchip
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ This repo provides the overlay for RockChip based Talos image.
| rockpi4 | Rock Pi 4A,Rock Pi 4B | Generic overlay for Rock Pi 4A and Rock Pi 4B |
| rockpi4c | Rock Pi 4C | Overlay for Rock Pi 4C |
| rock4cplus | Radxa ROCK 4C+ | Overlay for Radxa ROCK 4C+ |
| rock4se | Radxa ROCK 4SE | Overlay for Radxa ROCK 4SE |
25 changes: 25 additions & 0 deletions artifacts/rkbin/rk3399/pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: rkbin-rk3399
variant: scratch
shell: /toolchain/bin/bash
dependencies:
- stage: base
steps:
- sources:
- url: https://github.com/rockchip-linux/rkbin/archive/{{ .rkbin_commit }}.tar.gz
destination: rkbin.tar.gz
sha256: "{{ .rkbin_sha256 }}"
sha512: "{{ .rkbin_sha512 }}"
env:
SOURCE_DATE_EPOCH: {{ .BUILD_ARG_SOURCE_DATE_EPOCH }}
prepare:
- |
tar xf rkbin.tar.gz --strip-components=1
build:
install:
- |
mkdir -p /rootfs/rkbin
cp bin/rk33/rk3399_ddr_800MHz_* /rootfs/rkbin/
finalize:
- from: /rootfs
to: /libs
11 changes: 11 additions & 0 deletions artifacts/rock4se/u-boot/patches/enable-rockchip-tpl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/.config 2024-06-19 09:07:34.194505411 -0500
+++ b/.config 2024-06-19 09:07:30.250535296 -0500
@@ -228,7 +228,7 @@
CONFIG_ROCKCHIP_COMMON_BOARD=y
CONFIG_SPL_ROCKCHIP_COMMON_BOARD=y
CONFIG_TPL_ROCKCHIP_COMMON_BOARD=y
-# CONFIG_ROCKCHIP_EXTERNAL_TPL is not set
+CONFIG_ROCKCHIP_EXTERNAL_TPL=y
CONFIG_ROCKCHIP_BOOT_MODE_REG=0xff320300
# CONFIG_ROCKCHIP_RK8XX_DISABLE_BOOT_ON_POWERON is not set
CONFIG_ROCKCHIP_STIMER=y
44 changes: 44 additions & 0 deletions artifacts/rock4se/u-boot/pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# References:
# U-Boot:
# - https://u-boot.readthedocs.io/en/latest
name: u-boot-rock4se
variant: scratch
shell: /toolchain/bin/bash
dependencies:
- stage: base
- stage: arm-trusted-firmware-rk3399
- stage: rkbin-rk3399
steps:
- sources:
- url: https://ftp.denx.de/pub/u-boot/u-boot-{{ .uboot_version }}.tar.bz2
destination: u-boot.tar.bz2
sha256: "{{ .uboot_sha256 }}"
sha512: "{{ .uboot_sha512 }}"
env:
SOURCE_DATE_EPOCH: {{ .BUILD_ARG_SOURCE_DATE_EPOCH }}
prepare:
# rock-4se-rk3399
- |
mkdir -p /usr/bin \
&& ln -sf /toolchain/bin/env /usr/bin/env \
&& ln -sf /toolchain/bin/python3 /toolchain/bin/python
pip3 install pyelftools \
&& ln -sf /toolchain/bin/python3 /toolchain/bin/python
pip3 install pyelftools
tar xf u-boot.tar.bz2 --strip-components=1
- |
make rock-4se-rk3399_defconfig
patch -p1 < /pkg/patches/enable-rockchip-tpl.patch
build:
- |
make -j $(nproc) HOSTLDLIBS_mkimage="-lssl -lcrypto" BL31=/libs/arm-trusted-firmware/rk3399/bl31.elf ROCKCHIP_TPL=/libs/rkbin/rk3399_ddr_800MHz_v1.30.bin
install:
- |
mkdir -p /rootfs/artifacts/arm64/u-boot/rock4se
cp u-boot-rockchip.bin /rootfs/artifacts/arm64/u-boot/rock4se
finalize:
- from: /rootfs
to: /rootfs
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ use (
./installers/rockpi4/src
./installers/rockpi4c/src
./installers/rock4cplus/src
./installers/rock4se/src
)
7 changes: 7 additions & 0 deletions installers/pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- stage: rockpi4
- stage: rockpi4c
- stage: rock4cplus
- stage: rock4se
- stage: profiles
- stage: u-boot-nanopi-r4s
platform: linux/arm64
Expand All @@ -21,6 +22,8 @@ dependencies:
platform: linux/arm64
- stage: u-boot-rock4cplus
platform: linux/arm64
- stage: u-boot-rock4se
platform: linux/arm64
- image: "{{ .BUILD_ARG_PKGS_PREFIX }}/kernel:{{ .BUILD_ARG_PKGS }}"
platform: linux/arm64
from: /dtb/rockchip/rk3399-nanopi-r4s.dtb
Expand All @@ -45,6 +48,10 @@ dependencies:
platform: linux/arm64
from: /dtb/rockchip/rk3399-rock-4c-plus.dtb
to: /rootfs/artifacts/arm64/dtb/rockchip/rk3399-rock-4c-plus.dtb
- image: "{{ .BUILD_ARG_PKGS_PREFIX }}/kernel:{{ .BUILD_ARG_PKGS }}"
platform: linux/arm64
from: /dtb/rockchip/rk3399-rock-4se.dtb
to: /rootfs/artifacts/arm64/dtb/rockchip/rk3399-rock-4se.dtb
finalize:
- from: /rootfs
to: /
25 changes: 25 additions & 0 deletions installers/rock4se/pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: rock4se
variant: scratch
shell: /toolchain/bin/bash
dependencies:
- stage: base
steps:
- env:
GOPATH: /go
cachePaths:
- /.cache/go-build
- /go/pkg
build:
- |
export PATH=${PATH}:${TOOLCHAIN}/go/bin
cd /pkg/src
CGO_ENABLED=0 go build -o ./rock4se .
install:
- |
mkdir -p /rootfs/installers/
cp /pkg/src/rock4se /rootfs/installers/rock4se
finalize:
- from: /rootfs
to: /rootfs
11 changes: 11 additions & 0 deletions installers/rock4se/src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module rock4se

go 1.22.1

require (
github.com/siderolabs/go-copy v0.1.0
github.com/siderolabs/talos/pkg/machinery v1.7.0-alpha.1
golang.org/x/sys v0.16.0
)

require gopkg.in/yaml.v3 v3.0.1 // indirect
10 changes: 10 additions & 0 deletions installers/rock4se/src/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/siderolabs/go-copy v0.1.0 h1:OIWCtSg+rhOtnIZTpT31Gfpn17rv5kwJqQHG+QUEgC8=
github.com/siderolabs/go-copy v0.1.0/go.mod h1:4bF2rZOZAR/ags/U4AVSpjFE5RPGdEeSkOq6yR9YOkU=
github.com/siderolabs/talos/pkg/machinery v1.7.0-alpha.1 h1:0pURmnbzsu19reku8OjN1DkeAxgkmuxmKgDgbFT3228=
github.com/siderolabs/talos/pkg/machinery v1.7.0-alpha.1/go.mod h1:H2+5QeGXYi2Q7RhBNUAD6dhc9LmdJ2AUXtiAWRXtWBc=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
84 changes: 84 additions & 0 deletions installers/rock4se/src/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 main

import (
_ "embed"
"fmt"
"os"
"path/filepath"

"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/talos/pkg/machinery/overlay"
"github.com/siderolabs/talos/pkg/machinery/overlay/adapter"
"golang.org/x/sys/unix"
)

const (
off int64 = 512 * 64
// https://github.com/u-boot/u-boot/blob/4de720e98d552dfda9278516bf788c4a73b3e56f/configs/rock-pi-4c-rk3399_defconfig#L7=
dtb = "rockchip/rk3399-rock-4se.dtb"
)

func main() {
adapter.Execute(&rock4se{})
}

type rock4se struct{}

type rock4seExtraOptions struct{}

func (i *rock4se) GetOptions(extra rock4seExtraOptions) (overlay.Options, error) {
return overlay.Options{
Name: "rock4se",
KernelArgs: []string{
"console=tty0",
"console=ttyS2,1500000n8",
"sysctl.kernel.kexec_load_disabled=1",
"talos.dashboard.disabled=1",
},
PartitionOptions: overlay.PartitionOptions{
Offset: 2048 * 10,
},
}, nil
}

func (i *rock4se) Install(options overlay.InstallOptions[rock4seExtraOptions]) error {
var f *os.File

f, err := os.OpenFile(options.InstallDisk, os.O_RDWR|unix.O_CLOEXEC, 0o666)
if err != nil {
return fmt.Errorf("failed to open %s: %w", options.InstallDisk, err)
}

defer f.Close() //nolint:errcheck

uboot, err := os.ReadFile(filepath.Join(options.ArtifactsPath, "arm64/u-boot/rock4se/u-boot-rockchip.bin"))
if err != nil {
return err
}

if _, err = f.WriteAt(uboot, off); err != nil {
return err
}

// 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 := filepath.Join(options.ArtifactsPath, "arm64/dtb", dtb)
dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb)

err = os.MkdirAll(filepath.Dir(dst), 0o600)
if err != nil {
return err
}

return copy.File(src, dst)
}
2 changes: 2 additions & 0 deletions profiles/pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ finalize:
to: /rootfs/profiles
- from: /pkg/rock4cplus
to: /rootfs/profiles
- from: /pkg/rock4se
to: /rootfs/profiles
9 changes: 9 additions & 0 deletions profiles/rock4se/rock4se.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
arch: arm64
platform: metal
secureboot: false
output:
kind: image
outFormat: .xz
imageOptions:
diskSize: 1306525696
diskFormat: raw

0 comments on commit 8b17bba

Please sign in to comment.