PineNote Development
This article seeks to provide general development information for the PineNote
Flashing Software
Currently, the only ways to flash software are from the factory Android installation (UART shell, adb, or fastboot) or by using rkdeveloptool.
Side-by-side setup
It is possible to set up a partition for mainline development without disturbing the factory Android installation. This allows updating a mainline kernel, DTB, and initramfs over Wi-Fi until WiFi or USB OTG is working in mainline Linux.
The recommended partition for this is mmcblk0p11 aka /cache. It is large and already formatted as ext4, so it is readable from U-Boot. Here are some general steps:
- From the UART or adb shell, set up your chroot in /cache. I used the Alpine Linux rootfs tarball.
- Copy in your kernel and DTB, using for example scp or wget inside the chroot.
- Finally, create and boot an
extlinux.conf
as described below.
Using rkdeveloptool
rkdeveloptool is a command line utility built on libusb.
Downloading and Building rkdeveloptool
PINE64 develops its own updated fork of rkdeveloptool on GitLab.
You will need to have libusb 1.0, its development headers and scdoc installed.
git clone https://gitlab.com/pine64-org/quartz-bsp/rkdeveloptool.git cd rkdeveloptool mkdir build cd build cmake ..
This sets up all the build files. You can then compile with make
inside the build directory.
After you're done, you'll likely also need to install the udev rules, or else your user won't have permission to access the USB devices:
sudo cp 99-rk-rockusb.rules /etc/udev/rules.d/ sudo udevadm control --reload
Copying the udev rules is also performed automatically when you make install
.
Building Downstream U-Boot
While in maskrom mode, we need to have a u-boot to download onto the device for any of the other commands to work. To build you'll also need to install device-tree-compiler.
You also need to install Python and pyelftools.
Note that rkbin is a >5GB download! This will take some time to clone and process the deltas.
git clone -b quartz64 https://gitlab.com/pgwipeout/u-boot-rockchip.git git clone -b rkbin https://github.com/JeffyCN/rockchip_mirrors.git rkbin cd u-boot-rockchip # If using Arch Linux, export CROSS_COMPILE=aarch64-linux-gnu- export CROSS_COMPILE=aarch64-none-linux-gnu- make rk3566-quartz64_defconfig ./make.sh
In the version I cloned (current as of 2022-01-02), I had to make a change to one line to get a clean compilation:
diff --git a/lib/avb/libavb/avb_slot_verify.c b/lib/avb/libavb/avb_slot_verify.c index 123701fc3b..64a1ce6450 100644 --- a/lib/avb/libavb/avb_slot_verify.c +++ b/lib/avb/libavb/avb_slot_verify.c @@ -296,7 +296,7 @@ static AvbSlotVerifyResult load_and_verify_hash_partition( bool image_preloaded = false; uint8_t* digest; size_t digest_len; - const char* found; + const char* found = NULL; uint64_t image_size; size_t expected_digest_len = 0; uint8_t expected_digest_buf[AVB_SHA512_DIGEST_SIZE];
Entering Maskrom Mode
- Flip the device around so that the display faces down
- Lay the pen on the right side, with its tip pointing towards the speaker grill, and its magnet pointing towards the upper right corner of the label on the back.
- Turn the device on and wait for it to show up in
lsusb
. It should now be in Loader mode, according torkdeveloptool list-devices
- Unplug the device and plug it back in. It should now be in maskrom mode.
This can be a bit fiddly to get right, and may need a few tries.
Running rkdeveloptool
First, you'll want to make sure the device you've connected is in maskrom mode:
./rkdeveloptool list
It should output something like DevNo=1 Vid=0x2207,Pid=0x350a,LocationID=202 Maskrom
. If it doesn't, see PineNote Development#Entering Maskrom Mode.
You can now download u-boot onto it:
./rkdeveloptool boot ../u-boot-rockchip/rk356x_spl_loader_v1.08.111.bin
This should output Downloading bootloader succeeded.
.
We can now verify that this worked using e.g. the "read flash info" command:
./rkdeveloptool read-flash-info
TODO: finish this section
Creating a mainline boot image
You can create a filesystem image that replaces the Android boot or recovery partition by doing roughly the following:
- Erase boot and dtbo with rkdeveloptool or fastboot (back them up first!!!)
- Create an ext2 partition image and mount it (fallocate, mkfs.ext2)
- Build your mainline kernel
- Copy the kernel, dtb and an initramfs to the root of the mounted image (use any old postmarketOS initramfs)
- Create a file in the root of the mounted image called
extlinux.conf
as described below - Unmount the image and then use rkdeveloptool to flash it to the "recovery" partition on the pinenote (it's about the right size until we get around to replacing the partition layout).
Using fastboot
Follow the steps for "Creating a mainline boot.img", but instead of flashing it with rkdeveloptool, use fastboot. You can enter fastboot in either of two ways:
- Use "reboot bootloader" from adb or a UART console.
- Get a U-Boot prompt and run
fastboot usb 0
.
Mainline development
Status
Some work happening here: https://gitlab.com/calebccff/linux, the idea is to import the parts of the eink/ebc drivers which are open source and use the downstream u-boot framebuffer driver as a reference to create a basic framebuffer driver.
Currently mainline struggles to boot due to weird issues while probing fixed regulators (?). It also fails to detect eMMC.
Further work is being done here: https://github.com/smaeul/linux/commits/rk356x-ebc-dev. This has a complete device tree, with working eMMC. Pen input also works out of the box. Wi-Fi and BT work with firmware copied from the factory Android image.
How to boot mainline
UART is currently REQUIRED for this to work! We depend on u-boot falling back to console. Once we have a prebuilt u-boot which will use extlinux by default, UART won't be needed anymore.
Getting to a U-Boot prompt
You can get to a U-Boot prompt by:
- Holding Ctrl-C while the display panel initializes.
- Wiping the "boot" partition.
Using sysboot
extlinux.conf
should have the following contents:
timeout 10 default MAINLINE menu title boot prev kernel label MAINLINE kernel /vmlinuz fdt /rk3566-pinenote.dtb initrd /initramfs append earlycon console=tty0 console=ttyS2,1500000n8 fw_devlink=off PMOS_NO_OUTPUT_REDIRECT
At the u-boot console, run the following command to boot your mainline kernel:
sysboot ${devtype} ${devnum}:9 any ${scriptaddr} extlinux.conf
Booting with individual commands
Booting with individual commands can be useful when you need to temporarily add some kernel command line arguments. Use these or similar commands at the U-Boot shell:
load mmc 0:b ${kernel_addr_r} boot/Image load mmc 0:b ${fdt_addr_r} boot/rk3566-pinenote.dtb setenv bootargs ignore_loglevel root=/dev/mmcblk0p11 rootwait init=/bin/bash booti ${kernel_addr_r} - ${fdt_addr_r}