A modular build system for creating custom Linux kernels for the RG35XX_H handheld gaming device with WiFi, Bluetooth, USB gadgets, and automated flashing capabilities.
- Custom Kernel Configuration: Apply your own kernel config patches
- Device Tree Support: Automatic detection and building of RG35XX_H device trees
- Modular Architecture: Clean separation of concerns following SOLID principles
- Progress Tracking: Visual progress bars for build and flash operations
- Resume Capability: Start builds from specific steps (kernel, busybox, rootfs, flash)
- Automatic Flashing: Auto-detect SD cards and flash with minimal user interaction
- Backup Creation: Automatic backup of original firmware (optional)
new/ # Main project directory
├── build_modular.sh # Main entry point (new modular version)
├── build_rg35xx.sh # Original monolithic script
├── config/
│ └── constants.sh # Configuration constants
├── lib/
│ ├── logger.sh # Logging utilities
│ ├── system.sh # System utilities
│ └── device.sh # Device management
├── builders/
│ ├── kernel_builder.sh # Kernel building
│ ├── busybox_builder.sh # BusyBox building
│ └── rootfs_builder.sh # Root filesystem
├── flash/
│ └── flasher.sh # SD card flashing
├── config_patch # Kernel configuration
├── busybox_config_patch # BusyBox configuration (optional)
├── run_ubuntu.sh # Ubuntu execution wrapper
└── out/ # Build outputs
- Ubuntu / Debian (or WSL) with root access
- Toolchain:
aarch64-linux-gnu-* - Utilities:
git make gcc dtc mkbootimg (recommended) magiskboot|unmkbootimg|abootimg sgdisk parted pv cpio gzip - Access to internal eMMC (p4 = boot, p5 = rootfs) or SD card clone
Use when you want a fresh, clean build & immediate flash (backs up GPT + p4 + p5). Place your kernel config as ./config_patch (file or directory of *.config).
chmod +x build_rg35xxh.sh
sudo ./build_rg35xxh.sh # Build + backup + package + modules + flash
sudo PACK_MODE=with-dt ./build_rg35xxh.sh # Alternate packaging
sudo DTB_NAME=sun50i-h700-anbernic-rg35xx-h-rev6-panel.dtb ./build_rg35xxh.shIf boot loops after splash: re-run with a different DTB_NAME or PACK_MODE=with-dt.
For incremental development with caching.
sudo ./run_ubuntu.sh # Full build + detect & flash SD
sudo ./run_ubuntu.sh --skip-build # Only flash existing outputs
sudo ./run_ubuntu.sh --force-build # Force fresh rebuild
sudo ./run_ubuntu.sh --dtb=1 --package=with-dt
sudo ./run_ubuntu.sh --cmdline="console=tty0 loglevel=7" --no-force-cmdline
sudo ./run_ubuntu.sh --pagesize=4096 # Custom boot image pagesize (default 2048)Resume granularity examples (if present in older flow):
sudo ./build_modular.sh --start-from modules
sudo ./build_modular.sh --start-from busybox
sudo ./build_modular.sh --start-from rootfs| Flag | Description |
|---|---|
--dtb=N |
Select DTB variant index (0,1,2) |
| `--package=catdt | with-dt` |
--cmdline=STR |
Override kernel command line |
--no-force-cmdline |
Do not set CONFIG_CMDLINE_FORCE |
--pagesize=N |
Override boot image page size (default from stock header or 2048) |
--skip-build |
Skip build, flash only |
--force-build |
Force rebuild outputs |
--skip-backup |
Skip backups (faster, riskier) |
--skip-sd-check |
Build without SD detection |
--full-verify |
After flashing compute full SHA256 of boot partition (slow) |
| Part | Node | Type | Role |
|---|---|---|---|
| p1 | /dev/mmcblk0p1 | FAT / misc | Vendor assets (leave) |
| p2 | /dev/mmcblk0p2 | ext4/raw | System/vendor (leave) |
| p3 | /dev/mmcblk0p3 | raw | Misc/metadata |
| p4 | /dev/mmcblk0p4 | Android boot | Kernel + ramdisk (we flash) |
| p5 | /dev/mmcblk0p5 | ext4 | Root filesystem / modules |
Inspect layout:
lsblk -o NAME,SIZE,FSTYPE,LABEL,PARTLABEL /dev/mmcblk0
sgdisk -p /dev/mmcblk0Use automatic cycling of DTB variants & packaging modes:
sudo ./dtb_fallback.shAfter each attempt, test boot; script iterates combinations.
Typical remedies for splash loop:
- Switch DTB variant (
--dtb=) - Switch packaging (
--package=with-dtorcatdt) - Confirm
--pagesize 2048 - Force console cmdline (default) or add UART:
--cmdline="console=tty0 console=ttyS0,115200 earlycon loglevel=7 ignore_loglevel"
Automatic restore (latest backup set):
sudo ./restore_backups.shManual (if you copied backups elsewhere):
sudo sgdisk --load-backup=gpt-backup.bin /dev/mmcblk0
sudo dd if=boot-p4-backup.img of=/dev/mmcblk0p4 bs=4M conv=fsync status=progress
sudo dd if=rootfs-p5-backup.img of=/dev/mmcblk0p5 bs=4M conv=fsync status=progressTo restore only modules (rootfs mounted at /mnt/p5):
sudo tar -xzf modules-backup.tar.gz -C /mnt/p5- Boot image pagesize enforced at build (default 2048) and checked before flash.
- Post-flash hash comparison (first chunk) warns on mismatch.
- Full hash verification optional (read entire p4 and compare to source SHA256).
One-shot script extracts stock ramdisk (magiskboot / unmkbootimg / abootimg). Modular path creates a minimal placeholder if extraction not possible. For custom init modifications, unpack the extracted ramdisk, edit, then repack before packaging.
Edit config_patch to customize kernel features:
- WiFi and Bluetooth support
- USB gadget modes
- Development tools
- Custom drivers
Edit busybox_config_patch to customize userspace tools (optional).
- Dependency Check: Automatically installs required packages
- SD Card Detection: Finds and validates RG35XX_H SD card
- Kernel Building: Downloads source, applies config, builds kernel and DTBs
- BusyBox Building: Creates minimal userspace
- Root Filesystem: Sets up basic Linux filesystem structure
- Flashing: Writes kernel and rootfs to SD card with progress tracking
build_verification.sh— Comprehensive build output validation, performance testing, and reporting.- Usage:
./build_verification.sh verify # Validate build outputs ./build_verification.sh all # Full verification and report
advanced_sd_tools.sh— Enhanced SD diagnostics, backup, recovery, and optimization.- Usage:
./advanced_sd_tools.sh diagnose # Run SD diagnostics ./advanced_sd_tools.sh backup full # Full disk backup ./advanced_sd_tools.sh recover gpt backups/<dir> # Restore GPT ./advanced_sd_tools.sh optimize # Optimize SD card
automated_testing.sh— Full environment and build system testing, integration checks, and HTML reporting.- Usage:
./automated_testing.sh all # Run all tests and generate report ./automated_testing.sh quick # Quick toolchain and build tests ./automated_testing.sh performance # Performance benchmarks
dev_tools.sh— Clean, status, config, debug, and benchmarking tools for development workflow.- Usage:
./dev_tools.sh status # Show environment status ./dev_tools.sh clean # Clean build artifacts ./dev_tools.sh debug # Collect debug info ./dev_tools.sh benchmark # Run benchmarks
| Script | Purpose |
|---|---|
| build_verification.sh | Build output validation & reporting |
| advanced_sd_tools.sh | SD diagnostics, backup, recovery, optimization |
| automated_testing.sh | Automated testing & integration checks |
| dev_tools.sh | Developer workflow utilities |
| dtb_fallback.sh | Automatic DTB/packaging cycling |
| restore_backups.sh | Restore from backup |
| test_progress.sh | Progress bar testing |
| install_dependencies.sh | Install all required build tools |
| fix_boot_image.sh | Manual boot image page size fix |
All scripts are executable and can be run directly from the new/ directory.
For full documentation and advanced usage, see the individual script headers and the ADVANCED_FEATURES_COMPLETE.md file.
- Target Device: Anbernic RG35XX_H handheld
- SoC: Allwinner H700 (H616 variant)
- Architecture: ARM64 (aarch64)
- Device Tree:
sun50i-h700-anbernic-rg35xx-h.dts
The modular architecture makes it easy to:
- Add new builders for different components
- Customize flashing procedures
- Extend device support
- Add new configuration options
Each module has a single responsibility and clean interfaces, following SOLID principles.
The original monolithic script (build_rg35xx.sh) is preserved for compatibility. The new modular system (build_modular.sh) is recommended for all new development.
- Follow the existing modular structure
- Each new feature should be in its own module
- Maintain backward compatibility where possible
- Test on actual RG35XX_H hardware
This project is open source. See individual files for specific licensing information.