initial commit

This commit is contained in:
Rudis Muiznieks 2023-11-09 14:48:18 -06:00
commit 0f4544890f
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
4 changed files with 79 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
original/unpack
customized
r2ii.upt

58
README.md Normal file
View File

@ -0,0 +1,58 @@
# 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/hiby_player.sh` script.
## Pre-Requisites
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](https://github.com/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 `startup.sh` 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.

View File

@ -0,0 +1,18 @@
#!/bin/sh
killall hiby_player &>/dev/null
killall -9 hiby_player &>/dev/null
if [ -f "/usr/bin/batd" ]; then
killall batd &>/dev/null
killall -9 batd &>/dev/null
/usr/bin/batd -v -s -t5 -o /mnt/sd_0/batlog.txt &
fi
if [ -f /mnt/sd_0/startup.sh ]; then
/bin/sh -c '/bin/sh /mnt/sd_0/startup.sh' 2>/mnt/sd_0/startup_err.log >/mnt/sd_0/startup_out.log
fi
/usr/bin/hiby_player
sleep 1
reboot

BIN
original/r2ii_1.1b1.upt Normal file

Binary file not shown.