User:Brendlefly62/Radxa ROCK Pi 4C Plus/Gentoo From Scratch

From Gentoo Wiki
Jump to:navigation Jump to:search

Get the tools

Install packages from joetoo repository on the development platform

  • sys-devel/crossdev
  • dev-embedded/u-boot-tools
  • dev-vcs/git
  • sys-kernel/kernelupdate-embedded
root #emerge -av dev-vcs/git sys-devel/crossdev sys-devel/crossdev
root #crossdev --target aarch64-unknown-linux-gnu

Install the joetoo repository

root #emerge -av eselect-repository
root #eselect repository add git https://github.com/JosephBrendler/joetoo.git
root #emerge -av sys-kernel/kernelupdate-embedded

Prepare the media

Partition Layout

(todo) Test with similar GPT partition and ext4 filesystem, maybe grub efi boot; later try encrypted disk.

(Simplest) Recommendation for this board and bootloader - use just one partition, ext4 for the rootfs (with /boot as an organic part of the filesystem). This is the layout used by the armbian-build system when building for this board. If starting from scratch with a larger microSD card, use this layout.

External mass storage can be added later for mountpoints such as /srv and so on.
Micro SD Card or eMMC basic layout
device/file start sector Sectors size type purpose, remarks
/dev/mmcblk0p1 32768 remaining space 83 Linux / -- rootfs
/var/cache/swap/swap1 (**) 3G swap augment board's meager 4G RAM
(*) Be sure to leave adequate room for the "idbloader.img" bootloader file installed with dd

starting at sector 64, and the "u-boot".itb" bootloader image to be installed with dd at sector 16384. Note that other SBC bootloaders may also need to install other files at much higher starting sectors. The u-boot secondary program loader (SPL) expects to find at address 32768 either a boot.img image or the beginning of the partition containing the filesystem in which reside the boot.scr script or extlinux/extlinux.conf boot method instructions.

(**) Using a swap file rather than swap partition provides a bit more flexibility, if resizing is necessary. Currently, significant swap space may be necessary to support memory-intensive compile jobs (gcc, rust, for example) if the use of binary packages and/or cross compiling is not possible or desired.

build and deploy u-boot

To build and deploy u-boot, consult User:Brendlefly62/Radxa ROCK Pi 4C Plus/Build-Install-U-Boot

Install Stage 3

Mount the rootfs partitions to a folder structure on an Amd64 workstation (where components can be cross-compiled) or another Arm device (where it might be possible to continue the installation with a regular chroot transition as described in the Gentoo Handbook...

Root Filesystem

Mount the rootfs partition on (for example) /mnt/gentoo.

Follow the basic steps in a Gentoo Handbook such as for Amd64. Start with getting the appropriate stage 3, etc.

root #cd /
root #cat stage3-arm64-openrc-20230924T230144Z.tar.xz.DIGESTS
root #sha512sum stage3-arm64-openrc-20230924T230144Z.tar.xz
(compare to saved hash)
  • (continue, basically as outlined in Gentoo Handbook (amd64)
root #tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
root #<and so on...>

To make the system bootable, it will be necessary to populate the /boot/ directory with at least a working kernel, the device tree file (.dtb) for this board, and a method of booting (boot.scr or extlinux/extlinux.conf). This article uses an SPL boot scenario with /boot/boot.scr.

Install boot config files for this board. If using qemu chroot or another arm64 platform for development, this can be merged into the target system --

root #echo "sys-boot/rock4c64-boot-config ** ~arm64" >> /etc/portage/package.accept_keywords/joetoo
root #emerge -av sys-boot/rock4c64-boot-config

Alternatively, if using an x86_64 PC for the development platform, without qemu chroot, then these files can be manually copied to the target system's /boot/ directory from the "files" folder within the sys-boot/rock4c64-boot-config/ directory of the joetoo ebuild repository, probably at /var/db/repos/joetoo/sys-boot/rock4c64-boot-config/files/

Install headless-meta

Once the system has been booted, install the dev-embedded/rock4c64-headless-meta package from the joetoo repository, if a standard joetoo configuration is desired, then set the joetoo USE flag for rock4c64-headless-meta. This will pull in necessary packages, enabling the "world" set to remain small.

  • sys-boot/rock4c64-boot-config (from joetoo repo -- boot.cmd, boot.scr, joetooEnv.txt, u-boot_reflash)
  • sys-boot/rock4c64-firmware (from joetoo repo, ToDo -- this could be firmware-nonfree or something else)
  • sys-kernel/linux-rk3399-rock-4c-plus_kernel_image (from joetoo repo, install updated kernel, modules, dtbs, overlays. ToDo: USE flag for dtb/overlay replacement)

Curate

mature the system make a backup of the microSD card image

install custom kernel

The joetoo repo provides a script (sys-kernel/kernelupdate-embedded) to build an updated kernel on a cross-development platform. The final steps of the script's interactive sequence will build a tarball, and then deploy this and a corresponding version-bumped ebuild to the joetoo repository as an update to the custom kernel package sys-kernel/linux-rk3399-rock-4c-plus_kernel_image

Alternatively, the user can skip the last two steps after the tarball has been built, and deploy the tarball to the target system by copying it to the target system, mounted on the development platform and extracting it --

root #cp ~/My_rk3399-rock-4c-plus_project/build/rk3399-rock-4c-plus/tmp/distrib/linux-rk3399-rock-4c-plus_kernel_image-6.1.66.tar.bz2 /mnt/gentoo
root #cd /mnt/gentoo
root ## examine contents of tarball
root #tar tf linux-rk3399-rock-4c-plus_kernel_image-6.1.66.tar.bz2
root ## backup current kernel
root #cp -av /mnt/gentoo/boot/vmlinuz /mnt/gentoo/boot/backups/vmlinuz.<version>.bak
root #cp -av /mnt/gentoo/boot/rk3399-rock-4c-plus.dtb /mnt/gentoo/boot/ /mnt/gentoo/boot/rk3399-rock-4c-plus.dtb.bak
root ## deploy tarball content
root #tar xvpf linux-rk3399-rock-4c-plus_kernel_image-6.1.66.tar.bz2
boot/
boot/rk3399-rock-4c-plus.dtb
boot/vmlinuz
boot/dts/
boot/dts/rockchip/
boot/dts/rockchip/px30-evb.dtb
boot/dts/rockchip/rk3399-gru-scarlet-kd.dtb
...
boot/dts/rockchip/rk3399-rock-4c-plus.dtb
...
lib/modules/6.1.66/modules.devname
lib/modules/6.1.66/modules.builtin
lib/modules/6.1.66/modules.order
lib/modules/6.1.66/modules.symbols.bin
lib/modules/6.1.66/modules.builtin.modinfo
lib/modules/6.1.66/modules.alias.bin

Reboot!

Now reboot and confirm the new kernel is in use --

user $uname -a
Linux rock4c6401 6.1.66 #1 SMP PREEMPT Mon Dec 11 15:26:51 EST 2023 aarch64 GNU/Linux
user $eix-update && eix -Ic --in-overlay joetoo
Reading Portage settings...
Building database (/var/cache/eix/portage.eix)...
[0] "gentoo" /var/db/repos/gentoo (cache: metadata-md5-or-flat)
     Reading category 168|168 (100) Finished
[1] "joetoo" /var/db/repos/joetoo (cache: parse#metadata-md5#metadata-flat#assign)
     Reading category 168|168 (100) Finished
Applying masks...
Calculating hash tables...
Writing database file /var/cache/eix/portage.eix...
Database contains 19051 packages in 168 categories
[I] app-portage/jus [1] (6.3.1.9999{xpak}@10/04/2023): A simple joetoo update sequence (jus)
[I] dev-embedded/rock4c64-headless-meta [1] (0.0.2{xpak}@11/04/2023): Baseline packages for a headless server with gentoo on rock4c64
[I] dev-util/joetoolkit [1] (0.3.3{xpak}@12/11/2023): Utilities for a joetoo system
[I] dev-util/script_header_brendlefly [1] (0.3.9{xpak}@10/20/2023): A script header with easy-to-use formatting colors and misc functions
[I] dev-util/script_header_brendlefly_extended [1] (0.1.2{xpak}@10/03/2023): Extends script_header_brendlefly with line/box drawing functions
[I] dev-util/script_header_brendlefly_noninteractive [1] (0.0.2{xpak}@10/03/2023): Extends script_header_brendlefly with line/box drawing functions
[I] joetoo-base/joetoo-meta [1] (0.3.3{xpak}@12/11/2023): Baseline for a joetoo system
[I] net-misc/cloudsync [1] (2.2.0.9999{xpak:2}@10/04/2023): A very light wrapper to rsync content, scripts, and binary packages on home net
[I] sys-boot/rock4c64-boot-config [1] (0.0.1{xpak}@10/03/2023): Rock 4c Plus u-boot files for 64-bit mode
[I] sys-firmware/brcm43430-firmware [1] (20220405{xpak}@10/03/2023): Configuration file required for integrated WiFi on RPi3/4
[I] sys-kernel/linux-rk3399-rock-4c-plus_kernel_image [1] (6.1.66{xpak}@12/12/2023): kernel image for my Radxa Rock 4c Plus SBC
[1] "joetoo" /var/db/repos/joetoo

Found 12 matches