From 0acf1a2b29313b64e7697eebeb21e1fcdcba9154 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 8 Aug 2021 19:20:54 +0200 Subject: [PATCH 1/6] Kill NanoClock on startup It's not terribly useful for us, as we already provide similar functionaility. (It'll be restarted automatically when nickel restarts). --- platform/kobo/koreader.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index 60ef17b18..b3b4c6371 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -183,7 +183,7 @@ if [ "${VIA_NICKEL}" = "true" ]; then # as we want to be able to use our own per-if processes w/ custom args later on. # A SIGTERM does not break anything, it'll just prevent automatic lease renewal until the time # KOReader actually sets the if up itself (i.e., it'll do)... - killall -q -TERM nickel hindenburg sickel fickel adobehost foxitpdf iink dhcpcd-dbus dhcpcd fmon + killall -q -TERM nickel hindenburg sickel fickel adobehost foxitpdf iink dhcpcd-dbus dhcpcd fmon nanoclock.lua # Wait for Nickel to die... (oh, procps with killall -w, how I miss you...) kill_timeout=0 From 2d12f8a8ee537a5b6b98079b00b3095061de97da Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 8 Aug 2021 19:38:27 +0200 Subject: [PATCH 2/6] Mention that arguments are always evaluated, to curb enthusiasm at putting too much fancy stuff in a logger call ;). (Not actually an issue in our current codebase). --- doc/Hacking.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/Hacking.md b/doc/Hacking.md index 2dc060d66..e5288e93a 100644 --- a/doc/Hacking.md +++ b/doc/Hacking.md @@ -17,7 +17,12 @@ Anything printed by `logger.dbg` starts with `DEBUG`. 04/06/17-21:44:53 DEBUG foo ``` -## Bug hunting in kpv +In production code, remember that arguments are *always* evaluated in Lua, so, +don't inline complex computations in logger functions' arguments. +If you *really* have to, hide the whole thing behind a `dbg.is_on` branch, +like in [frontend/device/input.lua](https://github.com/koreader/koreader/blob/ba6fef4d7ba217ca558072f090849000e72ba142/frontend/device/input.lua#L1131-L1134). + +## Bug hunting in KPV (KOReader's predecessor) A real example of bug hunting in KPV's cache system: From 1e9346aec6498b421b98fe65345bff92e6c52eef Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 9 Aug 2021 02:30:59 +0200 Subject: [PATCH 3/6] Fix Wi-Fi toggle on the Elipsa It turns out that the kernel needs a little push now that the dedicated wifi power control module is gone ;). Issue was only exposed if you booted KOReader while the Wi-Fi was down. --- frontend/device/kobo/ntx_io.lua | 18 ++++++++++++++++++ platform/kobo/disable-wifi.sh | 6 ++++++ platform/kobo/enable-wifi.sh | 4 ++++ platform/kobo/nickel.sh | 9 ++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 frontend/device/kobo/ntx_io.lua diff --git a/frontend/device/kobo/ntx_io.lua b/frontend/device/kobo/ntx_io.lua new file mode 100644 index 000000000..a630a5bc6 --- /dev/null +++ b/frontend/device/kobo/ntx_io.lua @@ -0,0 +1,18 @@ +-- Stupid wrapper so that we can send simple ntx_io ioctls from shell scripts... + +local ffi = require("ffi") +local bor = bit.bor +local C = ffi.C + +require("ffi/posix_h") + +assert(#arg == 2, "must pass an ioctl command & an ioctl argument") +local ioc_cmd = tonumber(arg[1]) +local ioc_arg = tonumber(arg[2]) + +local fd = C.open("/dev/ntx_io", bor(C.O_RDONLY, C.O_NONBLOCK, C.O_CLOEXEC)) +assert(fd ~= -1, "cannot open ntx_io character device") + +assert(C.ioctl(fd, ioc_cmd, ffi.cast("int", ioc_arg)) == 0, "ioctl failed") + +C.close(fd) diff --git a/platform/kobo/disable-wifi.sh b/platform/kobo/disable-wifi.sh index 6af2d5580..d35b6dc3c 100755 --- a/platform/kobo/disable-wifi.sh +++ b/platform/kobo/disable-wifi.sh @@ -58,3 +58,9 @@ if grep -q "sdio_wifi_pwr" "/proc/modules"; then usleep 250000 rmmod sdio_wifi_pwr fi + +# Poke the kernel via ioctl on platforms without the dedicated power module... +if [ ! -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then + usleep 250000 + ./luajit frontend/device/kobo/ntx_io.lua 208 0 +fi diff --git a/platform/kobo/enable-wifi.sh b/platform/kobo/enable-wifi.sh index f25457f7f..3dc807693 100755 --- a/platform/kobo/enable-wifi.sh +++ b/platform/kobo/enable-wifi.sh @@ -23,6 +23,10 @@ if ! grep -q "sdio_wifi_pwr" "/proc/modules"; then fi insmod "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" + else + # Poke the kernel via ioctl on platforms without the dedicated power module... + # 208 is CM_WIFI_CTRL + ./luajit frontend/device/kobo/ntx_io.lua 208 1 fi fi # Moar sleep! diff --git a/platform/kobo/nickel.sh b/platform/kobo/nickel.sh index 42420d8ce..3b420f710 100755 --- a/platform/kobo/nickel.sh +++ b/platform/kobo/nickel.sh @@ -13,7 +13,7 @@ export QT_GSTREAMER_PLAYBIN_AUDIOSINK=alsasink cd / unset OLDPWD unset LC_ALL TESSDATA_PREFIX STARDICT_DATA_DIR EXT_FONT_DIR -unset KOREADER_DIR KO_DONT_GRAB_INPUT +unset KO_DONT_GRAB_INPUT unset FBINK_FORCE_ROTA # Ensures fmon will restart. Note that we don't have to worry about reaping this, nickel kills on-animator.sh on start. @@ -75,8 +75,15 @@ if grep -q "${WIFI_MODULE}" "/proc/modules"; then usleep 250000 rmmod sdio_wifi_pwr fi + + # Poke the kernel via ioctl on platforms without the dedicated power module... + if [ ! -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then + usleep 250000 + "${KOREADER_DIR}"/luajit "${KOREADER_DIR}"/frontend/device/kobo/ntx_io.lua 208 0 + fi fi +unset KOREADER_DIR unset CPUFREQ_DVFS CPUFREQ_CONSERVATIVE # Recreate Nickel's FIFO ourselves, like rcS does, because udev *will* write to it! From a91ba05e349a1f6fe9ae8e77bace6d86dcbf13b6 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 9 Aug 2021 20:56:00 +0200 Subject: [PATCH 4/6] Set the WiFi regulatory domain properly on the Elipsa No idea how restrictive the defaults are, but stuff is weird in the 5G band, so, do it right. --- platform/kobo/enable-wifi.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/platform/kobo/enable-wifi.sh b/platform/kobo/enable-wifi.sh index 3dc807693..fb2391605 100755 --- a/platform/kobo/enable-wifi.sh +++ b/platform/kobo/enable-wifi.sh @@ -33,11 +33,23 @@ fi usleep 250000 # NOTE: Used to be exported in WIFI_MODULE_PATH before FW 4.23 if ! grep -q "${WIFI_MODULE}" "/proc/modules"; then + # Set the Wi-Fi regulatory domain properly if necessary... + WIFI_COUNTRY_CODE_PARM="" + if grep -q "^WifiRegulatoryDomain=" "/mnt/onboard/.kobo/Kobo/Kobo eReader.conf"; then + WIFI_COUNTRY_CODE="$(grep "^WifiRegulatoryDomain=" "/mnt/onboard/.kobo/Kobo/Kobo eReader.conf" | cut -d '=' -f2)" + + case "${WIFI_MODULE}" in + "8821cs") + WIFI_COUNTRY_CODE_PARM="rtw_country_code=${WIFI_COUNTRY_CODE}" + ;; + esac + fi + if [ -e "/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" ]; then - insmod "/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" + insmod "/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" "${WIFI_COUNTRY_CODE_PARM}" elif [ -e "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" ]; then # NOTE: Modules are unsorted on Mk. 8 - insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" + insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" "${WIFI_COUNTRY_CODE_PARM}" fi fi # Race-y as hell, don't try to optimize this! From 6d30835b3b01f70295ed2b2fdd1105acebc909a0 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 10 Aug 2021 23:02:56 +0200 Subject: [PATCH 5/6] Handle new stuff from 4.28.18220 While we're in the vicinity... ;). --- platform/kobo/nickel.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/kobo/nickel.sh b/platform/kobo/nickel.sh index 3b420f710..3f84666b5 100755 --- a/platform/kobo/nickel.sh +++ b/platform/kobo/nickel.sh @@ -7,6 +7,7 @@ PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib:" export LD_LIBRARY_PATH="/usr/local/Kobo" # Ditto, 4.28+ export QT_GSTREAMER_PLAYBIN_AUDIOSINK=alsasink +export QT_GSTREAMER_PLAYBIN_AUDIOSINK_DEVICE_PARAMETER=bluealsa:DEV=00:00:00:00:00:00 # Reset PWD, and clear up our own custom stuff from the env while we're there, otherwise, USBMS may become very wonky on newer FW... # shellcheck disable=SC2164 From 330b268fc636a281f45fa2db7059666f73c9db05 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 11 Aug 2021 20:16:08 +0200 Subject: [PATCH 6/6] Bump base https://github.com/koreader/koreader-base/pull/1397 --- base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base b/base index 50baead13..00749f686 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 50baead13c61a4c9a81f0b90f348879f49653530 +Subproject commit 00749f6861372dbebcc7cf464402a90bb2f9c47e