Files
Arch-R/build-kernel.sh
Douglas Teles 18c229177a First successful build — 11 pipeline gaps fixed, repo organized
Build pipeline now produces a working bootable image. Found and fixed
11 gaps between the manually-built working SD and build-all.sh output:

Boot partition:
- extlinux.conf as primary boot method (U-Boot loads first)
- PanCho removed from boot.ini and build-image.sh
- Stale uInitrd removed (caused wrong boot path)
- logo.bmp (U-Boot native BMP) replaces broken splash-1.raw
- fstab uses LABEL=ROMS instead of /dev/mmcblk1p3
- Only R36S DTB copied (no extra r35s/rg351mp-linux)

Root filesystem:
- emulationstation.service created and enabled
- getty@tty1 disabled (ES takes over tty1)
- archr-boot-setup: Before=emulationstation.service, simplified
- All services use After=local-fs.target (not removed getty)
- boot-timing captures ES profiling data

New files added to repo:
- build-mesa.sh, build-retroarch.sh (were untracked)
- Custom DTS, ALSA config, controller autoconfig
- Runtime scripts (retroarch-launch, pmic-poweroff, hotkeys)
- VLC stub source, timezone data

Repo cleanup:
- README.md rewritten with build instructions + architecture
- .gitignore expanded (test scripts, failed approaches, logs)
- splash-show.sh removed (failed splash approach)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:01:13 -03:00

240 lines
8.1 KiB
Bash
Executable File

#!/bin/bash
#==============================================================================
# Arch R - Kernel 6.6 Build Script for R36S
#==============================================================================
# Builds Linux kernel 6.6.89 (Rockchip BSP) with R36S DTS + systemd support
#==============================================================================
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
log() { echo -e "${GREEN}[$(date '+%H:%M:%S')]${NC} $1"; }
warn() { echo -e "${YELLOW}[$(date '+%H:%M:%S')] WARNING:${NC} $1"; }
error() { echo -e "${RED}[$(date '+%H:%M:%S')] ERROR:${NC} $1"; exit 1; }
#------------------------------------------------------------------------------
# Configuration - Kernel 6.6 Rockchip BSP
#------------------------------------------------------------------------------
KERNEL_VERSION="6.6.89"
KERNEL_BRANCH="develop-6.6"
KERNEL_REPO="https://github.com/rockchip-linux/kernel.git"
DEFCONFIG="rockchip_linux_defconfig"
CONFIG_FRAGMENT="$SCRIPT_DIR/config/archr-6.6-r36s.config"
# DTS target
R36S_DTB="rk3326-gameconsole-r36s"
# Paths
KERNEL_SRC="${KERNEL_SRC:-/home/dgateles/Documentos/Projetos/kernel}"
# Output
OUTPUT_DIR="$SCRIPT_DIR/output"
BOOT_DIR="$OUTPUT_DIR/boot"
MODULES_DIR="$OUTPUT_DIR/modules"
# Cross-compilation
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
# Build parallelism
JOBS=$(nproc)
log "================================================================"
log " Arch R - Kernel $KERNEL_VERSION (Rockchip BSP for R36S)"
log "================================================================"
log ""
log "Source: $KERNEL_SRC"
log "Branch: $KERNEL_BRANCH"
log "DTB: $R36S_DTB"
log "Jobs: $JOBS"
#------------------------------------------------------------------------------
# Step 1: Verify Kernel Source
#------------------------------------------------------------------------------
log ""
log "Step 1: Checking kernel source..."
if [ ! -d "$KERNEL_SRC" ]; then
log " Cloning kernel 6.6 (rockchip-linux/kernel)..."
log " Branch: $KERNEL_BRANCH"
git clone --depth 1 --branch "$KERNEL_BRANCH" \
"$KERNEL_REPO" "$KERNEL_SRC"
log " Kernel cloned"
fi
if [ ! -f "$KERNEL_SRC/Makefile" ]; then
error "Kernel source not found at: $KERNEL_SRC"
fi
ACTUAL_VERSION=$(make -C "$KERNEL_SRC" -s kernelversion 2>/dev/null)
log " Kernel: $ACTUAL_VERSION"
# Copy R36S DTS from Arch-R repo into kernel source tree
DTS_SRC="$SCRIPT_DIR/kernel/dts/rk3326-gameconsole-r36s.dts"
DTS_DEST="$KERNEL_SRC/arch/arm64/boot/dts/rockchip/rk3326-gameconsole-r36s.dts"
if [ -f "$DTS_SRC" ]; then
cp "$DTS_SRC" "$DTS_DEST"
log " DTS: copied from repo"
else
if [ -f "$DTS_DEST" ]; then
warn "DTS not in Arch-R repo — using existing kernel source copy"
else
error "DTS not found! Expected at: $DTS_SRC"
fi
fi
#------------------------------------------------------------------------------
# Step 2: Configure Kernel
#------------------------------------------------------------------------------
log ""
log "Step 2: Configuring kernel..."
# Apply base defconfig
make -C "$KERNEL_SRC" ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE $DEFCONFIG
log " Base: $DEFCONFIG"
# Merge R36S-specific config fragment
# IMPORTANT: merge_config.sh writes output to .config in the CURRENT directory,
# NOT to the base config path. Must run from kernel source dir.
if [ -f "$CONFIG_FRAGMENT" ]; then
pushd "$KERNEL_SRC" > /dev/null
MERGE_LOG=$(scripts/kconfig/merge_config.sh \
-m .config "$CONFIG_FRAGMENT" 2>&1) || true
echo "$MERGE_LOG" | grep -E "(^#|Value)" | tail -20 || true
popd > /dev/null
make -C "$KERNEL_SRC" ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE olddefconfig
# Verify critical GPU config was applied
if grep -q "CONFIG_DRM_PANFROST=y" "$KERNEL_SRC/.config"; then
log " Panfrost GPU: ENABLED (built-in)"
elif grep -q "CONFIG_DRM_PANFROST=m" "$KERNEL_SRC/.config"; then
log " Panfrost GPU: ENABLED (module)"
else
warn " Panfrost GPU: NOT ENABLED — check config fragment!"
fi
if grep -q "CONFIG_MALI_MIDGARD=y" "$KERNEL_SRC/.config"; then
warn " Mali Midgard: STILL ENABLED (conflict with Panfrost!)"
else
log " Mali Midgard: disabled (good)"
fi
log " Merged: $(basename "$CONFIG_FRAGMENT")"
else
warn "Config fragment not found: $CONFIG_FRAGMENT"
fi
log " Kernel configured"
#------------------------------------------------------------------------------
# Step 3: Build Kernel Image
#------------------------------------------------------------------------------
log ""
log "Step 3: Building kernel Image..."
make -C "$KERNEL_SRC" -j$JOBS ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE Image 2>&1 | \
tail -5
if [ ! -f "$KERNEL_SRC/arch/arm64/boot/Image" ]; then
error "Kernel Image build failed!"
fi
IMAGE_SIZE=$(du -h "$KERNEL_SRC/arch/arm64/boot/Image" | cut -f1)
log " Kernel Image built ($IMAGE_SIZE)"
#------------------------------------------------------------------------------
# Step 4: Build Device Tree
#------------------------------------------------------------------------------
log ""
log "Step 4: Building Device Tree ($R36S_DTB)..."
make -C "$KERNEL_SRC" -j$JOBS ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE \
"rockchip/${R36S_DTB}.dtb" 2>&1 | tail -5
if [ ! -f "$KERNEL_SRC/arch/arm64/boot/dts/rockchip/${R36S_DTB}.dtb" ]; then
error "DTB build failed: ${R36S_DTB}.dtb"
fi
log " DTB built: ${R36S_DTB}.dtb"
#------------------------------------------------------------------------------
# Step 5: Build Kernel Modules
#------------------------------------------------------------------------------
log ""
log "Step 5: Building kernel modules..."
make -C "$KERNEL_SRC" -j$JOBS ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE modules 2>&1 | \
tail -5
log " Kernel modules built"
#------------------------------------------------------------------------------
# Step 6: Install to Output Directory
#------------------------------------------------------------------------------
log ""
log "Step 6: Installing artifacts..."
mkdir -p "$BOOT_DIR"
mkdir -p "$MODULES_DIR"
# Copy kernel image
cp "$KERNEL_SRC/arch/arm64/boot/Image" "$BOOT_DIR/"
log " Copied: Image"
# Copy R36S DTB
cp "$KERNEL_SRC/arch/arm64/boot/dts/rockchip/${R36S_DTB}.dtb" "$BOOT_DIR/"
log " Copied: ${R36S_DTB}.dtb"
# Install modules (use pipefail to catch errors masked by tail)
set -o pipefail
make -C "$KERNEL_SRC" ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE \
INSTALL_MOD_PATH="$MODULES_DIR" \
modules_install 2>&1 | tail -5
set +o pipefail
# Remove symlinks (save space)
rm -f "$MODULES_DIR/lib/modules/"*/source 2>/dev/null || true
rm -f "$MODULES_DIR/lib/modules/"*/build 2>/dev/null || true
# Verify critical module was installed
KERNEL_FULL=$(make -C "$KERNEL_SRC" -s kernelversion 2>/dev/null)
KREL=$(cat "$KERNEL_SRC/include/config/kernel.release" 2>/dev/null || echo "$KERNEL_FULL")
if find "$MODULES_DIR/lib/modules/$KREL" -name 'panfrost.ko*' 2>/dev/null | grep -q .; then
log " Panfrost module: INSTALLED"
else
warn " Panfrost module: NOT FOUND in $MODULES_DIR/lib/modules/$KREL/"
warn " Check directory permissions (must be writable by build user)"
fi
log " Modules installed"
#------------------------------------------------------------------------------
# Summary
#------------------------------------------------------------------------------
log ""
log "================================================================"
log " BUILD COMPLETE"
log "================================================================"
log ""
KERNEL_FULL=$(make -C "$KERNEL_SRC" -s kernelversion 2>/dev/null || echo "$KERNEL_VERSION")
IMAGE_SIZE=$(du -h "$BOOT_DIR/Image" | cut -f1)
DTB_SIZE=$(du -h "$BOOT_DIR/${R36S_DTB}.dtb" | cut -f1)
MODULES_SIZE=$(du -sh "$MODULES_DIR" 2>/dev/null | cut -f1 || echo "N/A")
log "Kernel: $KERNEL_FULL"
log ""
log "Artifacts:"
log " Image: $BOOT_DIR/Image ($IMAGE_SIZE)"
log " DTB: $BOOT_DIR/${R36S_DTB}.dtb ($DTB_SIZE)"
log " Modules: $MODULES_DIR/ ($MODULES_SIZE)"
log ""
log "Kernel 6.6 ready for R36S!"