From f046cd5d1b8e5da6c25d712ac4d99b6cd6248e8d Mon Sep 17 00:00:00 2001
From: Andreas Kemnade <andreas@kemnade.info>
Date: Sat, 19 Feb 2022 18:29:20 +0100
Subject: [PATCH] kobo-librah2o: new device (MR 2954)

Basic support for the Kobo Libra H2O ebook reader.

Waveform handling shares the same oddities as for the Kobo Clara HD, the
existing waveform from eMMC is used.

Preferred way to install is to export the eMMC as USB Mass storage,
backing it up, and installing there.

U-Boot is a more recent one than the factory u-boot, supporting easy
access for buttons/LEDs. Pressing PageUp while powering on gives you the
possibility to enable USB mass storage mode to restore your backup.

Kernel is the near mainline kernel also used by the Kobo Clara HD.

It lacks some devicetree additions which are planned for the next
update, but basic things like buttons, usb, serial and wifi are
supported.
---
 device/testing/device-kobo-librah2o/APKBUILD  | 38 +++++++++++++++++++
 .../testing/device-kobo-librah2o/deviceinfo   | 29 ++++++++++++++
 .../device-kobo-librah2o/uboot-script.cmd     | 25 ++++++++++++
 device/testing/u-boot-kobo-librah2o/APKBUILD  | 37 ++++++++++++++++++
 .../u-boot-kobo-librah2o/u-boot-env.txt       |  3 ++
 5 files changed, 132 insertions(+)
 create mode 100644 device/testing/device-kobo-librah2o/APKBUILD
 create mode 100644 device/testing/device-kobo-librah2o/deviceinfo
 create mode 100644 device/testing/device-kobo-librah2o/uboot-script.cmd
 create mode 100644 device/testing/u-boot-kobo-librah2o/APKBUILD
 create mode 100644 device/testing/u-boot-kobo-librah2o/u-boot-env.txt

diff --git a/device/testing/device-kobo-librah2o/APKBUILD b/device/testing/device-kobo-librah2o/APKBUILD
new file mode 100644
index 00000000000..ca009bfc7c1
--- /dev/null
+++ b/device/testing/device-kobo-librah2o/APKBUILD
@@ -0,0 +1,38 @@
+# Reference: <https://postmarketos.org/devicepkg>
+pkgname=device-kobo-librah2o
+pkgdesc="Kobo Libra H2O"
+pkgver=0.1
+pkgrel=0
+url="https://postmarketos.org"
+license="MIT"
+arch="armv7"
+options="!check !archcheck"
+depends="
+	kobo-epdc-extractor
+	linux-kobo-clara-mainline
+	postmarketos-base
+	u-boot-kobo-librah2o
+	u-boot-tools
+"
+makedepends="devicepkg-dev"
+
+source="
+	deviceinfo
+	uboot-script.cmd
+"
+
+build() {
+	devicepkg_build $startdir $pkgname
+}
+
+package() {
+	devicepkg_package $startdir $pkgname
+	mkimage -A arm -O linux -T script -n postmarketOS \
+		-d "$srcdir/uboot-script.cmd" "$srcdir/boot.scr"
+	install -Dm644 "$srcdir/boot.scr" "$pkgdir/boot/boot.scr"
+}
+
+sha512sums="
+0365f6c88c15f9d99d00c28d45144bf0321a8484fbf44b491cbe1493643180f1fcd5192d42991073d771be17eae2ec0a8b6826018e9ffb68e530fad11f02b96c  deviceinfo
+778674f41c19c56ed8677f151175d22da53e94e03c48d900036287b17a37ba9816976138ad317ec220d807a6ff97ca1006c6ae73c39801929f23927e665f35df  uboot-script.cmd
+"
diff --git a/device/testing/device-kobo-librah2o/deviceinfo b/device/testing/device-kobo-librah2o/deviceinfo
new file mode 100644
index 00000000000..d56a7718f0f
--- /dev/null
+++ b/device/testing/device-kobo-librah2o/deviceinfo
@@ -0,0 +1,29 @@
+# Reference: <https://postmarketos.org/deviceinfo>
+# Please use double quotes only. You can source this file in shell
+# scripts.
+
+deviceinfo_format_version="0"
+deviceinfo_name="Kobo Libra H2O"
+deviceinfo_manufacturer="Kobo"
+deviceinfo_codename="kobo-librah2o"
+deviceinfo_year="2019"
+deviceinfo_arch="armv7"
+deviceinfo_dtb="imx6sll-kobo-librah2o"
+
+# Device related
+deviceinfo_chassis="tablet"
+deviceinfo_keyboard="false"
+# eMMC can be exported as mass storage
+deviceinfo_external_storage="true"
+deviceinfo_screen_width="1264"
+deviceinfo_screen_height="1680"
+
+# Bootloader related
+deviceinfo_flash_method="none"
+deviceinfo_boot_part_start="49152"
+deviceinfo_getty="ttymxc0;115200"
+deviceinfo_generate_legacy_uboot_initfs="true"
+deviceinfo_no_framebuffer="true"
+
+deviceinfo_sd_embed_firmware_step_size="512"
+deviceinfo_sd_embed_firmware="u-boot/kobo-librah2o/u-boot.imx:2,u-boot/kobo-librah2o/u-boot-env.bin:1536"
diff --git a/device/testing/device-kobo-librah2o/uboot-script.cmd b/device/testing/device-kobo-librah2o/uboot-script.cmd
new file mode 100644
index 00000000000..5c906147245
--- /dev/null
+++ b/device/testing/device-kobo-librah2o/uboot-script.cmd
@@ -0,0 +1,25 @@
+led e70k02:white:on on
+
+if button PageUp
+then 
+   ums 0 mmc 0
+fi
+
+if button PageDown
+then
+   fastboot 0
+fi
+
+setenv bootargs console=ttymxc0,115200
+
+echo Loading kernel
+load mmc 0:1 0x80800000 vmlinuz
+
+echo Loading DTB
+load mmc 0:1 0x83000000 imx6sll-kobo-librah2o.dtb
+
+echo Loading initrd
+load mmc 0:1 0x85000000 uInitrd
+
+echo Booting kernel
+bootz 0x80800000 0x85000000 0x83000000
diff --git a/device/testing/u-boot-kobo-librah2o/APKBUILD b/device/testing/u-boot-kobo-librah2o/APKBUILD
new file mode 100644
index 00000000000..b3e09ebafe1
--- /dev/null
+++ b/device/testing/u-boot-kobo-librah2o/APKBUILD
@@ -0,0 +1,37 @@
+# Reference: <https://postmarketos.org/devicepkg>
+# before releasing updates, do a test run in RAM using uuu
+pkgname=u-boot-kobo-librah2o
+pkgver=2020.10
+pkgrel=0
+pkgdesc="U-Boot for Kobo Libra H2O, based on freescale fork"
+arch="armv7"
+_carch="arm"
+license="GPL-2.0"
+url="https://github.com/akemnade/u-boot-fslc"
+makedepends="$depends_dev bc dtc bison flex"
+options="!check"
+
+_repository="u-boot-fslc"
+_commit="fcf25705fc8b57cb22c81b2d352e9a06269911be"
+source="
+	$pkgname-$_commit.tar.gz::https://github.com/akemnade/$_repository/archive/$_commit.tar.gz
+	u-boot-env.txt
+"
+
+builddir="$srcdir/$_repository-$_commit"
+
+build() {
+	make ARCH="$_carch" mx6sllclarahd_defconfig
+	make ARCH="$_carch" DEVICE_TREE=imx6sll-kobo-librah2o
+	tools/mkenvimage -p 0 -s 8192 -o u-boot-env.bin "$srcdir/u-boot-env.txt"
+}
+
+package() {
+	install -D -m644 "$builddir/u-boot-dtb.imx" "$pkgdir/usr/share/u-boot/kobo-librah2o/u-boot.imx"
+	install -D -m644 "$builddir/u-boot-env.bin" "$pkgdir/usr/share/u-boot/kobo-librah2o/u-boot-env.bin"
+}
+
+sha512sums="
+6a9c3f5d2ad806ab9529f0c8fc19213098aae620c5bf34e5cc273453bf007266a674489deff18ffa82e8826280192dbc443b024a3f878836021ae6c062be4189  u-boot-kobo-librah2o-fcf25705fc8b57cb22c81b2d352e9a06269911be.tar.gz
+1efcff185bc3d4b8efbbd174305c248fb871ba7b2efd6ab9532a1c6bf2811448464e02c4606846563ffce0070e652e5aa6b6c937e1778dc6b7b626de6f33c7f5  u-boot-env.txt
+"
diff --git a/device/testing/u-boot-kobo-librah2o/u-boot-env.txt b/device/testing/u-boot-kobo-librah2o/u-boot-env.txt
new file mode 100644
index 00000000000..b1f3e3b0eaf
--- /dev/null
+++ b/device/testing/u-boot-kobo-librah2o/u-boot-env.txt
@@ -0,0 +1,3 @@
+# Load actual boot script from the boot partition
+# On failure activate USB mass storage mode
+bootcmd=if load mmc 0:1 0x80800000 boot.scr ; then source 0x80800000 ; else ums 0 mmc 0 ; fi
-- 
GitLab