User:TJNII/Orange Pi Stage3 Arm Build Host

From Gentoo Wiki
Jump to:navigation Jump to:search


This document covers a Stage3 Gentoo install for a Orange Pi Zero board / Allwinner Sunxi H2+ SOC. This guide uses another ARM for building so that commands can be run natively. This guide will mostly be a following of [Handbook:AMD64](the AMD64 Handbook), jumping around due to not building on the target host.

Information about the device / target

  • This guide is for a OrangePi Zero running a Allwinner Sunxi H2+ SOC
    • ARM is not like X86, ARM is a reference implementation so each SOC is unique.
  • The H2+ is a cut-back H3, so H3 documentation applies.
  • [1](Upstream info on
  • [2](Datasheet)


  • microSD card (at least 8 GB Class 6, better 16 GB+ Class 10)
  • ARM based build host [TODO: AWS Graviton Ref.]
  • Working serial terminal into the board

Initial Steps

Set up the chroot

  • SSH into your build host
  • Create a working directory
    • ```mkdir /root/opi_gentoo```
  • Download the current [3](current-stage3-armv7a_hardfp-[init]) tarball into the working directory.
    • Verifying and validating steps from [Handbook:AMD64/Installation/Stage#Downloading_the_stage_file](the Handbook) apply.
    • OpenRC / SystemD is to the user's preference, this guide stops before that level of configuration.
  • Create a chroot directory and unpack the stage tarball into it
    • ```mkdir /root/opi_gentoo/chroot```
    • ```cd /root/opi_gentoo/chroot```
    • ```tar xpvf ../stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner```

Configure Baseline Options

  • Configure etc/portage/make.conf
    • ```[EDITOR] etc/portage/make.conf```
      • Set ```COMMON_FLAGS="-O2 -pipe -march=armv7ve -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -mtune=cortex-a7"```
        • Based on [/Orange_Pi_PC/Quick_Start](Orange_Pi_PC/Quick_Start guide)
      • CFLAGS/CXXFLAGS/FCFLAGS/FFLAGS can all be left referencing COMMON_FLAGS
      • Set USE flags to user's preference
  • Configure the serial terminal in /etc/inittab
    • ```[EDITOR] /etc/inittab```
      • Comment out the existing ttyS0 line
      • Add ```s0:12345:respawn:/sbin/agetty -L -f /etc/issue.logo 115200 ttyS0 vt100```
        • Based on [/Orange_Pi_PC/Quick_Start](Orange_Pi_PC/Quick_Start guide)

Install the base system

  • Follow "Installing the Gentoo base system" from [/Handbook:AMD64/Installation/Base](the Handbook) with the following differences:
    • Copy DNS info: Run: No change
    • Mounting the necessary filesystems: Run: No change
    • Entering the new environment: Run: No change
    • Preparing for a bootloader: Skip
    • Configuring Portage: Run: No change
    • Choosing the right profile: No change, default profile advised
    • CPU_FLAGS_*: Skip
    • VIDEO_CARDS: Optional, this guide only uses serial
    • Configure the ACCEPT_LICENSE variable: Optional
    • Updating the @world set: Run: No change
      • This will take some time, ~3-4 hours on a Graviton c6gd.medium
    • Using systemd as the system and service manager: Optional, depending on stage used
    • Configure locales: Run: No change

Build the kernel

  • The handbook guide largely does not apply here.
  • Due to the variances in Arm this build likely still counts as cross-compiling. If you're on a ArmV8 board (AWS Graviton) this is like compiling for i386 on a amd64 system.
  • The kernel ```make``` commands will detect the running host and try and configure for it. The ``Arch=arm``` argument is critical on all ```make``` commands.
  • Install the sources
    • This guide uses linux-5.15.158-gentoo which is known good. It is recommended to use a known-good kernel before trying latest.
    • ```emerge =sys-kernel/gentoo-sources-5.15.158```
  • Install a known good .config
    • This config is from [4](Armbian_23.02.2_Orangepizero_jammy_current_5.15.93_minimal.img)
    • TODO: Download gist
    • TODO: Install steps
  • Update to the current sources
    • ```make ARCH=arm olddefconfig```
  • Compile!
    • ```make ARCH=arm```
      • This will take hours.
  • Install the modules
    • ```make ARCH=arm modules_install```
  • Make a uImage
    • ```make ARCH=arm LOADADDR=0x42000000 uImage```
      • TODO: Explain 0x42000000
    • ```cp arch/arm/boot/uImage /boot/uImage```
  • Make a DTS Blob
    • TODO: Docs/Reference
    • ```cpp -nostdinc -I include -I arch -undef -x assembler-with-cpp arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts /tmp/sun8i-h2-plus-orangepi-zero.dts.preprocessed```
    • ```scripts/dtc/dtc -I dts -O dtb /tmp/sun8i-h2-plus-orangepi-zero.dts.preprocessed > /boot/sun8i-h2-plus-orangepi-zero.dtb```

Build U-Boot =

  • Install dependencies
    • emerge git swig u-boot-tools
  • Clone upstream & checkout release tag
  • Configure
    • ```make orangepi_zero_plus2_h3_defconfig```
      • u-boot has a lot of low-level options. It's recommended to build and defaults and get it working, then tune with ```make menuconfig``` once the basic process is known.
  • Build
    • ```make```
    • ```cp u-boot-sunxi-with-spl.bin /boot```
      • TODO: Confirm Path

Transfer root to machine for updating SD Card

  • Exit chroot
  • Tar up the chroot
    • ```tar -xvzpf ../opi_gentoo.tar.gz ./```
      • TODO: Mounts
  • Copy the tarball to the machine with the SD card

Set up the SD Card