PINE64 PineNote (pine64-pinenote)

The PineNote is a 10.3" e-ink tablet produced by Pine64 for the Linux mobile community.
== Installation ==
The latest Community edition of the PineNote ships with a Debian image that is setup for dual-booting, while the Developper edition shipped with Android. The installation thus differs accordingly. 
=== Debian dual-boot ===
This image sports a u-boot build that is configured to allow dual-booting, offering a os1 (with debian, on mmcblk0p5) and a os2 (empty, on mmcblk0p6) partition. The user files are stored on a seperate partition (mmcblk0p7) that can be shared between the two operating systems. This makes it very convenient to install postmarketOS without needing to repartition or flash u-boot.
 Disk /dev/mmcblk0: 115.31 GiB
Device 	Name 	Size 	Purpose
/dev/mmcblk0p1	uboot 	64M 	The U-Boot embedded systems bootloader
/dev/mmcblk0p2	waveform 	2M 	Important files controlling the e-ink screen’s state changes
/dev/mmcblk0p3	uboot-env	1M 	U-Boot environment files
/dev/mmcblk0p4	logo 	64M 		Splash image displayed during boot
/dev/mmcblk0p5	os1 	14.6G	Debian system files
/dev/mmcblk0p6	os2 	14.6G	Secondary system files
/dev/mmcblk0p7	data 	85.9G	Home partition
To support full-disk encryption, postmarketOS build two images: one for boot partition and the other for root partition. For ease of use, we will only install on one partition which requires a few changes to the image after creation.
First, build an image with pmbootstrap on the Debian system. Phosh or sway has been tested to work well enough, but gnome is used by the official debian image.
$ pmbootstrap init # pine64 pinenote
$ pmbootstrap install
Then, flash the produced root image on the secondary system partition.
$ sudo dd if=~/.local/var/pmbootstrap/chroot_native/home/pmos/rootfs/pine64-pinenote-root.img of=/dev/mmcblk0p6 bs=1M status=progress
Since postmarketOS expects a seperate boot partition, we have to transfer the contents of pine64-pinenote-boot.img and adjust the extlinux config accordingly.
$ mount -o loop ~/.local/var/pmbootstrap/chroot_native/home/pmos/rootfs/pine64-pinenote-boot.img /mnt/boot
$ mount /dev/mmcblk0p6 /mnt/root
$ cp -Rv /mnt/boot/* /mnt/root/boot/.
/boot/extlinux/extlinux.conf need to be modifed so that kernel, fdt initrd are under /boot, pmos_boot_uuid is replaced with pmos_build=/boot and timeout and default are setup in such a way as to not wait for the user to select the boot option to boot. 
It'll look something like this. Note that uuid in pmos_root_uuid=uuid should have the uuid of your root partition. It should already be in your config file.
default postmarketOS
menu title U-Boot menu
prompt 1
timeout 10
label postmarketOS
	kernel /boot/vmlinuz
	fdt /boot/rk3566-pinenote-v1.2.dtb
	initrd /boot/initramfs
	append drm.debug=0x0 vt.color=0xf earlycon console=tty0 console=ttyS2,1500000n8 PMOS_FORCE_PARTITION_RESIZE pmos_boot=/boot pmos_root_uuid=uuid pmos_rootfsopts=defaults
Then reboot, and select the os2 boot option. You should now have a working postmarketOS installation.
=== Android ===
Currently, installing postmarketOS requires UART access to manually boot the mainline kernel(you might able to make it auto-boot from extlinux by modifying it's booting behavior.). If you have a developer unit, removing the back cover will reveal the pre-soldered UART wires, if you have a production unit you will have to solder these yourself. This will be resolved as soon as we have a u-boot build which can auto-boot from extlinux.
Install rkdeveloptool from https://gitlab.com/pine64-org/quartz-bsp/rkdeveloptool, put the end of the pen (or a small magnet) near the top right of the back of the device (a small circle printed on the back cover indicates the correct location for the magnet) to trigger rockusb mode.
We need to wipe the boot and recovery partitions to make sure u-boot doesn't try and boot Android
$ fallocate -l 32M blank.bin
$ rkdeveloptool write-partition boot blank.bin
$ rkdeveloptool write-partition recovery blank.bin
Now build an image with pmbootstrap, I would recommend Phosh or sway.
$ pmbootstrap init # pine64 pinenote
$ pmbootstrap install
And flash (pmbootstrap supports rkdeveloptool as of ).
$ pmbootstrap flasher flash_rootfs # flashes to userdata
$ pmbootstrap flasher flash_kernel # flashes to cache
Run pmbootstrap shutdown to exit out of pmbootstrap. If your PineNote shipped with a UART dongle, use it to connect the PineNote with your PC. Note that the LED needs to be oriented so that it points to the PineNote's screen. At this stage you no longer need to be in rockusb mode, so you don't need to worry about pen/magnet placement. Ensure that your PineNote is charged before beginning the next step.
$ picocom /dev/ttyUSB0 -b 1500000 -l
Reboot the PineNote by holding down the power button. You should see a long stream of text appear in picocom indicating that you are in the u-boot shell. 
This next command will boot the PineNote into postmarketOS. 
=> sysboot ${devtype} ${devnum}:b any ${scriptaddr} extlinux.conf
b is the partition number (decimal 11 encoded in hex) for the cache partition, where we flashed the extlinux boot partition to.
If the file location of extlinux.conf gives you trouble, as indicated by a 'file not found' error, run the following to ascertain where extlinux.conf is on your system (for example, in /extlinux/extlinux.conf). Then run the sysboot command again using the full path of extlinux.conf
=> ls ${devtype} ${devnum}:b #To examine a specific directory, such as /extlinux, place it at the end of this command
You should now see the postmarketOS splash and the pinenote will boot.
== Contributors ==
* MartijnBraam
* Petr Hodina
* Caleb Connolly
* Antoine Martin (ayakael)
== Users owning this device ==
== How to enter flash mode ==
The device is only flashable using the rkusb bootloader mode. This can be done with the opensource rkdeveloptool utility.
To trigger the bootloader hold a magnet on the backcover of the pinenote while powering it on.
When it's booted correctly into bootloader mode it should show up in the device list of rkdeveloptool:
< lang="shell-session">
$ rkdeveloptool ld
DevNo=1 Vid=0x2207,Pid=0x350a,LocationID=100 Loader
</syntaxhighlight>
It's possible to overwrite the eMMC with the LBA write command:
$ rkdeveloptool wl 0 rootfs.img
The 0 is the offset in blocks from the start of the eMMC, can be used to flash a partition if you know the offset
== Recover from a broken bootloader ==
If uboot image is overwritten the rockusb mode won't work anymore. The device might boot into maskrom mode in which case it should show up in `rkdeveloptool list` as maskrom. 
If the uboot image is partially overwritten but still recognized by the maskrom it won't stay in maskrom mode and you'd have to open the back of the device and short TP1301 and TP1302 while powering up. This will make eMMC reads fail so maskrom always runs.
Once the device is in maskrom mode the only thing you can do is push a new loader into ram and start that.
$ rkdeveloptool list
here it lists maskrom now
The .bin file is build by u-boot and might have a slightly different version
$ rkdeveloptool db rk356x_spl_loader_v1.04.108.bin
$ rkdeveloptool ptt
now it's able to read flash and list the partitions
== Waveform ==
There exists a GNOME Shell extension for selecting the waveform for the panel. The waveform affects the quality and speed of the refresh.
Different waveforms
You can also adjust waveform settings using sysfs parameters under /sys/module/rockchip_ebc/parameters
 Waveform parameters
Parameter 	Function 	Possible values
bw_mode 	Sets black and white mode of display 	0: grayscale, 1: bw + dithering, 2: bw, 3: DU4 waveform
bw_threshold 	Sets threshold where pixel is considered white or black. If default, all pixel values lower than 7 will be cast to 0 (left), and all values larger larger or equivalent will be cat to 15 (white) 	0-15, 7 is default
auto_refresh 	Global refreshes are triggered based on the area drawing using partial refreshes, in units of total screen area. 	0: enabled, 1: disabled (default)
refresh_threshold	Global refreshes are triggered based on the area drawing using partial refreshes, in units of total screen area. 	20 is default
refresh_waveform 	Sets the waveform to use for global refreshes. 	4 is default
dclk_select 	Controls how fast data is sent to the ebc display, allowing for a "quality" mode that reduces visible artifacts as much as possible, with the downside of having bad latency, and a "performance" mode where speed is gained at the expense of visual quality.	0: quality mode (default), 1: performance mode
dclk_select changes should also be accompanied with a display mode change. On the debian image, "quality" mode is associated with a 5hz refresh rate, while "performance" is 80hz.
The following command, after installing pinenote-dbus-service and starting the pinenote service, can force a refresh of the screen:
$ dbus-send --system --print-reply --dest=org.pinenote.ebc /ebc org.pinenote.ebc.TriggerGlobalRefresh
 
== See also ==
* PINE64 wiki page
* fork of rkdeveloptool with many improvements this will be the version supported on the pinenote.
* - support for rkdeveloptool in pmbootstrap for flashing with BSP u-boot
* , - MR for initial device support
* - MR for configuring the waveform for the panel
* Guides on modify uboot boot behavior
* Notes by m-weigand on EBC parameters 
* pinenote-gnome-extension source code with more info on EBC