If you wish to compile a new kernel and flash it on your persee, you will first need several things
- Persee kernel sources. I got them by mailing Orbbec, and I’m not sure what the rules are for distributing them. The kernel is largely just the rockchip linux kernel though.
- The Orbbec Persee Ubuntu image
- MicroUSB OTG cable
- Orbbec Persee
- Linux computer. I use debian stable.
Flashing the existing Ubuntu image
To be able to do some later steps, you must first flash the Orbbec Ubuntu image on the Persee as this modifies the partition tables. I’m not sure how these tables could be modified without this image, and I hope someone else can shed some light on this.
- Get the Ubuntu 16 image from here: Universal Download Thread for Persee
- Get the upgrade_tool from here Rock/flash the image - Radxa Wiki. It would nice to be able to flash this image using rkflashkit as upgrade_tool is proprietary - any ideas?
- Boot Persee in loader mode
- Remove any SD cards from the Persee
- Unplug all cables
- Connect the OTG USB cable in the microUSB slot on the Persee
- Using some small object press the reset pin down, in the hole next to the power plug
- Connect the USB OTG cable to your Linux PC
- Release the reset pin after a few seconds
- sudo upgrade_tool uf /path/to/ubuntu/img
- Unplug and replug the OTG cable, make sure the Persee boots to Ubuntu
Install rkflashkit
git clone https://github.com/linuxerwang/rkflashkit.git
cd rkflashkit
./waf debian
sudo dpkg -i rkflashkit_0.1.5_all.deb
Backup old images
Connect the Persee using the USB OTG cable in loader mode.
sudo rkflashkit part # Should list partitions for a device that's in Loader mode
sudo rkflashkit backup @linuxroot linuxroot_old.img
sudo rkflashkit backup @boot boot_old.img
sudo rkflashkit backup @backup backup_old.img
Build kernel sources
- Acquire the kernel sources from Orbbec
- Extract the sources
- GCC >= 5 cannot be used on this old kernels. Make sure your GCC is 4.8 or 4.9:
/usr/bin/arm-linux-gnueabihf-gcc -v
- If not:
sudo apt-get install gcc-4.8-arm-linux-gnueabihf
sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-gcc arm-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-gcc-4.8 10
sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-g++ arm-linux-gnueabihf-g++ /usr/bin/arm-linux-gnueabihf-g++-4.8 10
arm-linux-gnueabihf-gcc -v
- Compile the kernel. This takes 10 minutes on my aging laptop with a weak CPU
cd kerneldir
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- persee-rk3288_defconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- persee-rk3288.img -j4
Retrieve a missing bootloader
- The kernel sources I got did not contain
second_bootloader
which is used by the boot sequence. This can be found by retrieving the boot partition from the Persee after flashing the Orbbec Ubuntu.
unmkbootimg -i boot_old.img
cp second_bootloader /kerneldir/OBTools/
Make the final boot image
mkbootimg --kernel arch/arm/boot/zImage --ramdisk OBTools/out/initrd.img --second OBTools/second_bootloader -o linux-boot.img
Flash onto the device
sudo rkflashkit flash @boot linux-boot.img
Creating a linuxroot partition from a running Persee
- Log in to the persee
Reduce the linuxroot partition used space as much as possible as flashing a large image takes ages. You can use this oneliner to see what’s using space:
sudo su
cd /
du -S . | sort -nr | head -25
- Then insert a USB stick, mount it and create a file to store the linuxroot partition
sudo su
mkdir /root/usb
mount /dev/sda1 /root/usb
cd /root/usb
mkdir myrootfs && cd myrootfs
dd if=/dev/zero bs=1M count=2500 | pv -s 2G | dd of=linuxroot.img # Adjust size based on linuxroot
mkfs.ext4 -F -L linuxroot linuxroot.img
- Mount the linuxroot in a temp mount point and copy the entire system
cd /root
mkdir mnt
mkdir mnt2
cd /root/usb/myrootfs
mount -o loop linuxroot.img /root/mnt
mount /dev/mmcblk0p5 /root/mnt2 # change as appropriate from `mount` output. You need the about 7GB partition
cp -a /root/mnt2/* /root/mnt/
- Create the firstboot flag. This will be used by /usr/local/bin/first-boot-recovery.sh to expand the file system.
touch /root/mnt/firstboot
- Cleanup
sync
umount /root/mnt
umount /root/mnt2
cd /root/usb/myrootfs
e2fsck -p -f linuxroot.img
resize2fs -M linuxroot.img
- Use rkflashkit to flash the image
sudo rkflashkit backup @linuxroot old_linuxroot.img
sudo rkflashkit flash @linuxroot linuxroot.img
Questions
- How could we create a completely flashable image similar to the Orbbec Ubuntu image? This would allow flashing the image in without having to first flash the Orbbec image. This might be simple - perhaps some tool in the rkflashkit can create a complete image
- Can the Orbbec image be flashed on the Persee using rkflashkit? I’m not a huge fan of using the upgrade_tool from an unknown origin.