Kobo Libra H2O (kobo-librah2o)

== Contributors ==
* Andi (has only a device with a broken screen)
== Users owning this device ==
== Mainlining status ==
A basic devicetree is upstream, display waits for testing 
== Accessing the internal storage ==
Contrary to non-waterproof eBook readers, the Libra H2O does not have an internal replaceable µSD but an
internal eMMC, so things have to be flashed on the device.
With the factory uboot, the command to enable mass storage mode is
 ums 0 mmc 0 
This can be run in a serial console with the help of a usb debugger, or we can flash a bootenv using fastboot. The needed binary is at: https://misc.andi.de1.cc/ums-env.bin
Flashing this bootenv will cause the following command to run at boot:
 bootcmd=ricoh_watchdog disable; ums 0 mmc 0
Enter fastboot by pressing pagedown while powering on the device, and flash the bootenv using
 fastboot flash bootenv ums-env.bin
after the flash succeeds, do
 fastboot reboot
The emmc will appear as /dev/sdX on your host. It is probably a good idea to do a full backup at this stage.
 sudo dd if=/dev/sdX of=kobo.img status=progress
Alternately, you can download a stock image from here: https://archive.org/details/kobo_librah2o_N873_factory
With this bootenv, the kobo will always boot to mass storage mode. To restore the original bootenv, write back the u-boot.mmc which is located in the rootfs. To do this directly, you can use:
 mount /dev/sdX1 /mnt
 dd if=/mnt/etc/u-boot/mx6sll-ntx/u-boot.mmc bs=128K seek=6 of=/dev/sdX
 umount /mnt
You can also download u-boot.mmc from here: https://archive.org/details/mx6sll-ntx_u-boot_mmc
== Installation ==
Enable mass storage access in U-Boot (see above) and install using pmbootstrap --sdcard
If the flash fails with an error like "Partitions have been written, but we have been unable to inform the kernel of the change", unmount all partitions on /dev/sdX, reboot the kobo, make sure no partitions are auto-mounted, and try again.
With the pmOS-installed bootloader, you can enter mass storage by Page*Up* while powering on
== Recovery ==
If nothing which looks like a bootloader is found on startup, the following device
 
 hid-generic 0003:1FC9:0128.001B: hiddev1,hidraw1: USB HID v1.10 Device [ NXP SemiConductor Inc SE Blank 6SLL] on usb-0000:00:14.0-6.1/input0
appears. It can be accessed using a tool called uuu from a package mfgtools. This allows the device to be restored if the eMMC is inaccessible (corrupted MBR, formatted partitions).
You will need:
* A USB serial debugger
* Stock uboot image
* mfgtools
Serial debuggers are cheap and easy to come by, check an electronics store or search for a hackerspace near you.
The stock boot image can be extracted from the full eMMC image using:
 dd if=kobo.img of=uboot.img bs=128k count=4
To connect the debugger, pry off the back of the kobo and solder or otherwise connect the Rx, Tx, and Ground pads to the debugger. Do not connect the power lead.
Note that the Rx from the debugger needs to be connected to the Tx on the kobo, and vice versa.
The goal is to use uuu from mfgtools to send the stock uboot image to the kobo over usb, which will load it from RAM. You can then interact with the loaded bootloader using the serial console.
It is useful to keep dmesg open in the background to follow the device state.
 sudo dmesg --follow
Open a serial console in a separate terminal:
 sudo bt /dev/tty0
 or
 sudo screen /dev/tty0
Now plug in and power on the kobo via the usual usb connection. Check that uuu sees your device:
 sudo uuu -lsusb
Send and boot the stock uboot image:
 sudo uuu -v -b spl uboot.img
This command will appear to hang, but you should see output in the serial console to confirm that uboot is working. If there is no console output, check whether the RX light on your debugger blinks. If not, there is probably something wrong with your debugger or your hookup. The kobo uses a default baud rate of 115200, there is no need to change it.
Now that you have access to the serial console, there are a few useful commands.
boot the device:
 boot
enable fastboot:
 fastboot 0
enable mass storage mode:
 ums 0 mmc 0
The console may appear garbled, react slowly or partially to key input, but that's ok. Just type the command normally and press enter.
With mass storage mode enabled, we can restore the factory image using:
 sudo dd if=kobo.img of=/dev/sdX status=progress
This will take several hours to complete. Keep in mind that if you imaged your kobo after flashing the bootenv to enable mass storage mode, you will need to restore the bootenv as described above.
You should now have a working kobo!
== Tolino Vision 5 ==
The Tolino Vision 5 is a rebrand of the Kobo Libra H2O with identical hardware available in Germany, Austria, Switzerland, Belgium, Italy and the Netherlands. It ships with a completely different firmware based on Android 4.4.2.
=== Fastboot ===
To get the Tolino Vision 5 into fastboot mode, connect it to a computer and then power it off. Prepare your desired fastboot command in a terminal. Press and hold the power button for 30 seconds. The device will appear as i.mx6sl NTX Smart Device, idVendor=18d1, idProduct=0d02 and remain in fastboot mode for about 5 seconds. If it does not receive any fastboot commands before the time runs out, it will automatically exit fastboot and continue to boot normally.
== See also ==
* U-boot and kernel source
* Upstream Devicetree Source (dts) 
* branches kobo/drm-merged-5.X Patched mainline kernels (includes EPD), currently kobo/drm-merged-5.17
* branch kobo-2020-10 more recent u-boot behaving more normal, see corresponding wiki for details
* Wi-Fi driver, branch rtl8189fs
* Initial merge request