Modifies HiBy R2II firmware to run a script off the SD card at startup if it exists.
Go to file
Rudis Muiznieks 0f4544890f
initial commit
2023-11-09 14:48:18 -06:00
custom-files/usr/bin initial commit 2023-11-09 14:48:18 -06:00
original initial commit 2023-11-09 14:48:18 -06:00
.gitignore initial commit 2023-11-09 14:48:18 -06:00 initial commit 2023-11-09 14:48:18 -06:00

HiBy R2II Firmware Customizations

This repo contains scripts and files necessary to modify the official HiBy firmware for the R2II. Currently it adds a mechanism to run a shell script off the SD card at bootup. It does this by adding some custom lines to the /usr/bin/ script.


The system image being modified is a UBIFS image, so you will need the tooling to work with those. Since my host kernel is missing the ubi module, I did this in a newly created Arch Linux VM. These are the packages I needed to install with pacman:

  • p7zip (for the 7z command)
  • mtd-utils (for flash_erase and other MTD commands)
  • cdrkit (for the genisoimage command)

Building the Custom Firmware

These instructions are based largely on SuperTaiyaki/hiby-firmware-tools:

  1. Unpack the stock firmware and rename the original SYSTEM.UBI image:
    7z x -ooriginal/unpack original/r2ii_1.1b1.upt
    mv original/unpack/SYSTEM.UBI original/unpack/SYSTEM-ORIG.UBI
  2. Mount the renamed SYSTEM-ORIG.UBI image. Make sure that no MTD nodes already exist in your system (ls /dev/mtd* should return no matches).
    sudo modprobe nandsim first_id_byte=0x2c second_id_byte=0xda third_id_byte=0x90 fourth_id_byte=0x95
    sudo flash_erase /dev/mtd0 0 0
    sudo ubiformat /dev/mtd0
    sudo modprobe ubi
    sudo ubiattach -m 0
    sudo ubimkvol /dev/ubi0 -a 4096 -N hiby -s 128MiB
    sudo ubiupdatevol /dev/ubi0_0 original/unpack/SYSTEM-ORIG.UBI
    sudo mount /dev/ubi0_0 /mnt
  3. Make a copy of the original firmware file system:
    sudo cp -R /mnt customized
  4. Replace files in the original firmware copy with the customized versions:
    sudo cp -R custom-files/* customized/
  5. Repackage the customized firmware into a new SYSTEM.UBI image:
    sudo mkfs.ubifs -x lzo -d customized -e 0x1F000 -c 512 -m 0x800 -o original/unpack/SYSTEM.UBI
  6. Update the md5 hash in UPDATE.TXT to match the new SYSTEM.UBI image:
    sed -i '7,$s/md5=.*/md5='"$(md5sum original/unpack/SYSTEM.UBI | cut -d\  -f1)/" original/unpack/UPDATE.TXT
  7. Generate the new firmware update file:
    genisoimage -l -o r2ii.upt original/unpack/{SYSTEM.UBI,UBOOT.BIN,UIMAGE.BIN,UPDATE.TXT,VERSION.TXT,_GITIGNO}

Now you can copy the r2ii.upt file that was generated to the root of your R2II's SD card, then initiate a firmware update through the System->Firmware update->Via SD-card menu. If you are unable to get into the System menu, you can also force an update by turning the device off, then holding the Power and FFWD buttons together until the Hiby logo appears.

Using the Custom Firmware

If you place a text file named onto the root of your SD card, that script will be executed every time the device boots up just prior to the HiBy player interface being launched.