2013-07-10 07:10:38 +00:00
#!/bin/sh
export LC_ALL = "en_US.UTF-8"
2020-06-20 15:15:55 +00:00
# Compute our working directory in an extremely defensive manner
2020-08-25 00:00:59 +00:00
SCRIPT_DIR = " $( CDPATH = '' cd -- " $( dirname -- " $0 " ) " && pwd -P) "
# NOTE: We need to remember the *actual* KOREADER_DIR, not the relocalized version in /tmp...
export KOREADER_DIR = " ${ KOREADER_DIR :- ${ SCRIPT_DIR } } "
2014-08-01 04:36:32 +00:00
2020-06-20 15:15:55 +00:00
# We rely on starting from our working directory, and it needs to be set, sane and absolute.
cd " ${ KOREADER_DIR :- /dev/null } " || exit
2017-04-12 07:07:06 +00:00
2020-08-25 00:00:59 +00:00
# To make USBMS behave, relocalize ourselves outside of onboard
if [ " ${ SCRIPT_DIR } " != "/tmp" ] ; then
cp -pf " ${ 0 } " "/tmp/koreader.sh"
chmod 777 "/tmp/koreader.sh"
exec "/tmp/koreader.sh" " $@ "
fi
2018-07-29 01:53:57 +00:00
# Attempt to switch to a sensible CPUFreq governor when that's not already the case...
2022-01-15 22:12:07 +00:00
# Swap every CPU at once if available
if [ -d "/sys/devices/system/cpu/cpufreq/policy0" ] ; then
CPUFREQ_SYSFS_PATH = "/sys/devices/system/cpu/cpufreq/policy0"
else
CPUFREQ_SYSFS_PATH = "/sys/devices/system/cpu/cpu0/cpufreq"
fi
IFS = read -r current_cpufreq_gov <" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
# NOTE: What's available depends on the HW, so, we'll have to take it step by step...
# Roughly follow Nickel's behavior (which prefers interactive), and prefer interactive, then ondemand, and finally conservative/dvfs.
if [ " ${ current_cpufreq_gov } " != "interactive" ] ; then
2022-01-15 22:12:07 +00:00
if grep -q "interactive" " ${ CPUFREQ_SYSFS_PATH } /scaling_available_governors " ; then
2018-07-29 01:53:57 +00:00
ORIG_CPUFREQ_GOV = " ${ current_cpufreq_gov } "
2022-01-15 22:12:07 +00:00
echo "interactive" >" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
elif [ " ${ current_cpufreq_gov } " != "ondemand" ] ; then
2022-01-15 22:12:07 +00:00
if grep -q "ondemand" " ${ CPUFREQ_SYSFS_PATH } /scaling_available_governors " ; then
2020-11-25 14:50:47 +00:00
# NOTE: This should never really happen: every kernel that supports ondemand already supports interactive ;).
# They were both introduced on Mk. 6
ORIG_CPUFREQ_GOV = " ${ current_cpufreq_gov } "
2022-01-15 22:12:07 +00:00
echo "ondemand" >" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
elif [ -e "/sys/devices/platform/mxc_dvfs_core.0/enable" ] ; then
# The rest of this block assumes userspace is available...
2022-01-15 22:12:07 +00:00
if grep -q "userspace" " ${ CPUFREQ_SYSFS_PATH } /scaling_available_governors " ; then
2020-11-25 14:50:47 +00:00
ORIG_CPUFREQ_GOV = " ${ current_cpufreq_gov } "
export CPUFREQ_DVFS = "true"
# If we can use conservative, do so, but we'll tweak it a bit to make it somewhat useful given our load patterns...
# We unfortunately don't have any better choices on those kernels,
# the only other governors available are powersave & performance (c.f., #4114)...
2022-01-15 22:12:07 +00:00
if grep -q "conservative" " ${ CPUFREQ_SYSFS_PATH } /scaling_available_governors " ; then
2020-11-25 14:50:47 +00:00
export CPUFREQ_CONSERVATIVE = "true"
2022-01-15 22:12:07 +00:00
echo "conservative" >" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
# NOTE: The knobs survive a governor switch, which is why we do this now ;).
echo "2" >"/sys/devices/system/cpu/cpufreq/conservative/sampling_down_factor"
echo "50" >"/sys/devices/system/cpu/cpufreq/conservative/freq_step"
echo "11" >"/sys/devices/system/cpu/cpufreq/conservative/down_threshold"
echo "12" >"/sys/devices/system/cpu/cpufreq/conservative/up_threshold"
# NOTE: The default sampling_rate is a bit high for my tastes,
# but it unfortunately defaults to its lowest possible setting...
fi
# NOTE: Now, here comes the freaky stuff... On a H2O, DVFS is only enabled when Wi-Fi is *on*.
# When it's off, DVFS is off, which pegs the CPU @ max clock given that DVFS means the userspace governor.
# The flip may originally have been switched by the sdio_wifi_pwr module itself,
# via ntx_wifi_power_ctrl @ arch/arm/mach-mx5/mx50_ntx_io.c (which is also the CM_WIFI_CTRL (208) ntx_io ioctl),
# but the code in the published H2O kernel sources actually does the reverse, and is commented out ;).
# It is now entirely handled by Nickel, right *before* loading/unloading that module.
# (There's also a bug(?) where that behavior is inverted for the *first* Wi-Fi session after a cold boot...)
2023-08-01 18:26:02 +00:00
if grep -q "^sdio_wifi_pwr " "/proc/modules" ; then
2020-11-25 14:50:47 +00:00
# Wi-Fi is enabled, make sure DVFS is on
2022-01-15 22:12:07 +00:00
echo "userspace" >" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
echo "1" >"/sys/devices/platform/mxc_dvfs_core.0/enable"
else
# Wi-Fi is disabled, make sure DVFS is off
echo "0" >"/sys/devices/platform/mxc_dvfs_core.0/enable"
# Switch to conservative to avoid being stuck at max clock if we can...
if [ -n " ${ CPUFREQ_CONSERVATIVE } " ] ; then
2022-01-15 22:12:07 +00:00
echo "conservative" >" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
else
# Otherwise, we'll be pegged at max clock...
2022-01-15 22:12:07 +00:00
echo "userspace" >" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
# The kernel should already be taking care of that...
2022-01-15 22:12:07 +00:00
cat " ${ CPUFREQ_SYSFS_PATH } /scaling_max_freq " >" ${ CPUFREQ_SYSFS_PATH } /scaling_setspeed "
2020-11-25 14:50:47 +00:00
fi
fi
fi
fi
2018-07-29 01:53:57 +00:00
fi
fi
2018-07-28 14:09:58 +00:00
2014-08-01 04:36:32 +00:00
# update to new version from OTA directory
2018-07-04 17:25:55 +00:00
ko_update_check( ) {
NEWUPDATE = " ${ KOREADER_DIR } /ota/koreader.updated.tar "
INSTALLED = " ${ KOREADER_DIR } /ota/koreader.installed.tar "
if [ -f " ${ NEWUPDATE } " ] ; then
2024-01-29 21:37:32 +00:00
# Clear screen to delete UI leftovers
./fbink --cls
2018-09-05 23:35:48 +00:00
./fbink -q -y -7 -pmh "Updating KOReader"
2021-04-24 23:15:38 +00:00
# Setup the FBInk daemon
export FBINK_NAMED_PIPE = "/tmp/koreader.fbink"
rm -f " ${ FBINK_NAMED_PIPE } "
2022-01-15 23:26:46 +00:00
# We'll want to use REAGL on sunxi, because AUTO is slow, and fast merges are extremely broken outside of REAGL...
2024-05-09 01:27:37 +00:00
eval " $( ./fbink -e | tr ';' '\n' | grep -e isSunxi | tr '\n' ';' ) "
2022-01-15 23:26:46 +00:00
# shellcheck disable=SC2154
if [ " ${ isSunxi } " = "1" ] ; then
PBAR_WFM = "REAGL"
else
PBAR_WFM = "AUTO"
fi
FBINK_PID = " $( ./fbink --daemon 1 %KOREADER% -q -y -6 -P 0 -W ${ PBAR_WFM } ) "
2018-09-05 23:35:48 +00:00
# NOTE: See frontend/ui/otamanager.lua for a few more details on how we squeeze a percentage out of tar's checkpoint feature
# NOTE: %B should always be 512 in our case, so let stat do part of the maths for us instead of using %s ;).
FILESIZE = " $( stat -c %b " ${ NEWUPDATE } " ) "
BLOCKS = " $(( FILESIZE / 20 )) "
export CPOINTS = " $(( BLOCKS / 100 )) "
2018-07-04 17:25:55 +00:00
# shellcheck disable=SC2016
2021-04-24 23:15:38 +00:00
./tar xf " ${ NEWUPDATE } " --strip-components= 1 --no-same-permissions --no-same-owner --checkpoint= " ${ CPOINTS } " --checkpoint-action= exec = 'printf "%s" $((TAR_CHECKPOINT / CPOINTS)) > ${FBINK_NAMED_PIPE}'
2018-07-04 17:25:55 +00:00
fail = $?
2021-04-24 23:15:38 +00:00
kill -TERM " ${ FBINK_PID } "
2018-07-04 17:25:55 +00:00
# Cleanup behind us...
if [ " ${ fail } " -eq 0 ] ; then
mv " ${ NEWUPDATE } " " ${ INSTALLED } "
./fbink -q -y -6 -pm "Update successful :)"
./fbink -q -y -5 -pm "KOReader will start momentarily . . ."
2020-11-28 21:48:09 +00:00
# Warn if the startup script has been updated...
if [ " $( md5sum "/tmp/koreader.sh" | cut -f1 -d' ' ) " != " $( md5sum " ${ KOREADER_DIR } /koreader.sh " | cut -f1 -d' ' ) " ] ; then
./fbink -q -pmMh "Update contains a startup script update!"
fi
2018-07-04 17:25:55 +00:00
else
2019-09-07 01:19:18 +00:00
# Uh oh...
2018-07-04 17:25:55 +00:00
./fbink -q -y -6 -pmh "Update failed :("
./fbink -q -y -5 -pm "KOReader may fail to function properly!"
fi
2021-04-24 23:15:38 +00:00
rm -f " ${ NEWUPDATE } " # always purge newupdate to prevent update loops
unset CPOINTS FBINK_NAMED_PIPE
unset BLOCKS FILESIZE FBINK_PID
2019-12-16 23:28:51 +00:00
# Ensure everything is flushed to disk before we restart. This *will* stall for a while on slow storage!
sync
2018-07-03 21:16:45 +00:00
fi
2018-07-04 17:25:55 +00:00
}
2018-07-07 20:27:38 +00:00
# NOTE: Keep doing an initial update check, in addition to one during the restart loop, so we can pickup potential updates of this very script...
2018-07-04 17:25:55 +00:00
ko_update_check
2018-07-07 20:27:38 +00:00
# If an update happened, and was successful, reexec
if [ -n " ${ fail } " ] && [ " ${ fail } " -eq 0 ] ; then
# By now, we know we're in the right directory, and our script name is pretty much set in stone, so we can forgo using $0
exec ./koreader.sh " ${ @ } "
fi
2014-08-01 04:36:32 +00:00
2013-07-10 07:10:38 +00:00
# export dict directory
export STARDICT_DATA_DIR = "data/dict"
2015-01-27 18:17:54 +00:00
# export external font directory
export EXT_FONT_DIR = "/mnt/onboard/fonts"
2015-01-25 08:52:01 +00:00
2020-04-29 15:50:29 +00:00
# Quick'n dirty way of checking if we were started while Nickel was running (e.g., KFMon),
# or from another launcher entirely, outside of Nickel (e.g., KSM).
VIA_NICKEL = "false"
2017-04-11 09:28:01 +00:00
if pkill -0 nickel; then
2020-04-29 15:50:29 +00:00
VIA_NICKEL = "true"
2015-04-26 18:46:30 +00:00
fi
2020-04-29 15:50:29 +00:00
# NOTE: Do not delete this line because KSM detects newer versions of KOReader by the presence of the phrase 'from_nickel'.
2014-06-25 13:31:42 +00:00
2020-04-29 15:50:29 +00:00
if [ " ${ VIA_NICKEL } " = "true" ] ; then
2017-04-11 09:28:01 +00:00
# Detect if we were started from KFMon
FROM_KFMON = "false"
if pkill -0 kfmon; then
# That's a start, now check if KFMon truly is our parent...
2020-05-13 00:22:51 +00:00
if [ " $( pidof -s kfmon) " -eq " ${ PPID } " ] ; then
2017-04-11 09:28:01 +00:00
FROM_KFMON = "true"
fi
fi
2020-04-29 15:50:29 +00:00
# Check if Nickel is our parent...
FROM_NICKEL = "false"
if [ -n " ${ NICKEL_HOME } " ] ; then
FROM_NICKEL = "true"
fi
# If we were spawned outside of Nickel, we'll need a few extra bits from its own env...
if [ " ${ FROM_NICKEL } " = "false" ] ; then
# Siphon a few things from nickel's env (namely, stuff exported by rcS *after* on-animator.sh has been launched)...
2020-05-14 20:45:24 +00:00
# shellcheck disable=SC2046
2020-08-18 22:45:24 +00:00
export $( grep -s -E -e '^(DBUS_SESSION_BUS_ADDRESS|NICKEL_HOME|WIFI_MODULE|LANG|INTERFACE)=' " /proc/ $( pidof -s nickel) /environ " )
2020-05-14 20:45:24 +00:00
# NOTE: Quoted variant, w/ the busybox RS quirk (c.f., https://unix.stackexchange.com/a/125146):
2020-08-18 22:45:24 +00:00
#eval "$(awk -v 'RS="\0"' '/^(DBUS_SESSION_BUS_ADDRESS|NICKEL_HOME|WIFI_MODULE|LANG|INTERFACE)=/{gsub("\047", "\047\\\047\047"); print "export \047" $0 "\047"}' "/proc/$(pidof -s nickel)/environ")"
2020-04-29 15:50:29 +00:00
fi
2017-04-11 09:28:01 +00:00
2022-04-17 14:55:43 +00:00
# If bluetooth is enabled, kill it.
if [ -e "/sys/devices/platform/bt/rfkill/rfkill0/state" ] ; then
2022-09-28 19:31:52 +00:00
# That's on sunxi, at least
2022-04-17 14:55:43 +00:00
IFS = read -r bt_state <"/sys/devices/platform/bt/rfkill/rfkill0/state"
if [ " ${ bt_state } " = "1" ] ; then
echo "0" >"/sys/devices/platform/bt/rfkill/rfkill0/state"
# Power the chip down
./luajit frontend/device/kobo/ntx_io.lua 126 0
fi
fi
2023-08-01 18:26:02 +00:00
if grep -q "^sdio_bt_pwr " "/proc/modules" ; then
2022-09-28 19:31:52 +00:00
# And that's on NXP SoCs
rmmod sdio_bt_pwr
fi
2022-04-17 14:55:43 +00:00
2020-04-29 15:50:29 +00:00
# Flush disks, might help avoid trashing nickel's DB...
2017-04-11 09:28:01 +00:00
sync
2020-04-29 15:50:29 +00:00
# And we can now stop the full Kobo software stack
2018-05-10 10:26:07 +00:00
# NOTE: We don't need to kill KFMon, it's smart enough not to allow running anything else while we're up
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
# NOTE: We kill Nickel's master dhcpcd daemon on purpose,
# 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)...
2022-04-17 14:55:43 +00:00
killall -q -TERM nickel hindenburg sickel fickel strickel fontickel adobehost foxitpdf iink dhcpcd-dbus dhcpcd bluealsa bluetoothd fmon nanoclock.lua
2020-07-29 01:27:04 +00:00
# Wait for Nickel to die... (oh, procps with killall -w, how I miss you...)
kill_timeout = 0
while pkill -0 nickel; do
# Stop waiting after 4s
if [ ${ kill_timeout } -ge 15 ] ; then
break
fi
usleep 250000
kill_timeout = $(( kill_timeout + 1 ))
done
# Remove Nickel's FIFO to avoid udev & udhcpc scripts hanging on open() on it...
rm -f /tmp/nickel-hardware-status
2020-09-24 03:05:59 +00:00
# We don't need to grab input devices (unless MiniClock is running, in which case that neatly inhibits it while we run).
if [ ! -d "/tmp/MiniClock" ] ; then
export KO_DONT_GRAB_INPUT = "true"
fi
2014-08-18 23:48:31 +00:00
fi
2015-04-26 23:21:54 +00:00
# check whether PLATFORM & PRODUCT have a value assigned by rcS
2020-05-13 00:22:51 +00:00
if [ -z " ${ PRODUCT } " ] ; then
2020-05-14 20:45:24 +00:00
# shellcheck disable=SC2046
export $( grep -s -e '^PRODUCT=' " /proc/ $( pidof -s udevd) /environ " )
2020-05-13 00:22:51 +00:00
fi
2019-03-13 18:24:30 +00:00
if [ -z " ${ PRODUCT } " ] ; then
2017-04-11 09:28:01 +00:00
PRODUCT = " $( /bin/kobo_config.sh 2>/dev/null) "
export PRODUCT
2015-04-26 23:21:54 +00:00
fi
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
# PLATFORM is used in koreader for the path to the Wi-Fi drivers (as well as when restarting nickel)
2020-05-13 00:22:51 +00:00
if [ -z " ${ PLATFORM } " ] ; then
2020-05-14 20:45:24 +00:00
# shellcheck disable=SC2046
export $( grep -s -e '^PLATFORM=' " /proc/ $( pidof -s udevd) /environ " )
2020-05-13 00:22:51 +00:00
fi
2019-03-13 18:24:30 +00:00
if [ -z " ${ PLATFORM } " ] ; then
2017-04-11 09:28:01 +00:00
PLATFORM = "freescale"
if dd if = "/dev/mmcblk0" bs = 512 skip = 1024 count = 1 | grep -q "HW CONFIG" ; then
CPU = " $( ntx_hwconfig -s -p /dev/mmcblk0 CPU 2>/dev/null) "
PLATFORM = " ${ CPU } -ntx "
fi
2018-06-16 21:05:20 +00:00
if [ " ${ PLATFORM } " != "freescale" ] && [ ! -e " /etc/u-boot/ ${ PLATFORM } /u-boot.mmc " ] ; then
2017-04-11 09:28:01 +00:00
PLATFORM = "ntx508"
fi
export PLATFORM
2015-02-09 15:13:07 +00:00
fi
2018-05-10 10:26:07 +00:00
# Make sure we have a sane-ish INTERFACE env var set...
2019-03-13 18:24:30 +00:00
if [ -z " ${ INTERFACE } " ] ; then
2018-05-10 10:26:07 +00:00
# That's what we used to hardcode anyway
INTERFACE = "eth0"
export INTERFACE
fi
2015-02-09 15:13:07 +00:00
2021-07-21 16:12:58 +00:00
# We'll enforce UR in ko_do_fbdepth, so make sure further FBInk usage (USBMS)
# will also enforce UR... (Only actually meaningful on sunxi).
if [ " ${ PLATFORM } " = "b300-ntx" ] ; then
export FBINK_FORCE_ROTA = 0
2022-01-15 23:24:21 +00:00
# On sunxi, non-REAGL waveform modes suffer from weird merging quirks...
FBINK_WFM = "REAGL"
# And we also cannot use batched updates for the crash screen, as buffers are private,
2021-07-21 16:12:58 +00:00
# so each invocation essentially draws in a different buffer...
FBINK_BATCH_FLAG = ""
# Same idea for backgroundless...
FBINK_BGLESS_FLAG = "-B GRAY9"
# It also means we need explicit background padding in the OT codepath...
FBINK_OT_PADDING = ",padding=BOTH"
# Make sure we poke the right input device
KOBO_TS_INPUT = "/dev/input/by-path/platform-0-0010-event"
else
2021-10-31 22:48:13 +00:00
FBINK_WFM = "GL16"
2021-07-21 16:12:58 +00:00
FBINK_BATCH_FLAG = "-b"
FBINK_BGLESS_FLAG = "-O"
FBINK_OT_PADDING = ""
KOBO_TS_INPUT = "/dev/input/event1"
fi
2019-03-27 21:50:44 +00:00
# We'll want to ensure Portrait rotation to allow us to use faster blitting codepaths @ 8bpp,
# so remember the current one before fbdepth does its thing.
2020-05-13 00:22:51 +00:00
IFS = read -r ORIG_FB_ROTA <"/sys/class/graphics/fb0/rotate"
2019-03-27 21:50:44 +00:00
echo " Original fb rotation is set @ ${ ORIG_FB_ROTA } " >>crash.log 2>& 1
2018-12-28 03:32:42 +00:00
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
# In the same vein, swap to 8bpp,
# because 16bpp is the worst idea in the history of time, as RGB565 is generally a PITA without hardware blitting,
# and 32bpp usually gains us nothing except a performance hit (we're not Qt5 with its QPainter constraints).
# The reduced size & complexity should hopefully make things snappier,
2019-03-13 18:24:30 +00:00
# (and hopefully prevent the JIT from going crazy on high-density screens...).
# NOTE: Even though both pickel & Nickel appear to restore their preferred fb setup, we'll have to do it ourselves,
# as they fail to flip the grayscale flag properly. Plus, we get to play nice with every launch method that way.
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
# So, remember the current bitdepth, so we can restore it on exit.
2020-05-13 00:22:51 +00:00
IFS = read -r ORIG_FB_BPP <"/sys/class/graphics/fb0/bits_per_pixel"
2019-03-09 23:59:49 +00:00
echo " Original fb bitdepth is set @ ${ ORIG_FB_BPP } bpp " >>crash.log 2>& 1
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
# Sanity check...
case " ${ ORIG_FB_BPP } " in
2020-02-10 23:08:38 +00:00
8) ; ;
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
16) ; ;
32) ; ;
*)
2019-09-07 01:19:18 +00:00
# Uh oh? Don't do anything...
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
unset ORIG_FB_BPP
; ;
esac
# The actual swap is done in a function, because we can disable it in the Developer settings, and we want to honor it on restart.
ko_do_fbdepth( ) {
2021-09-02 20:33:10 +00:00
# On sunxi, the fb state is meaningless, and the minimal disp fb doesn't actually support 8bpp anyway...
2021-07-21 16:12:58 +00:00
if [ " ${ PLATFORM } " = "b300-ntx" ] ; then
2021-09-02 20:33:10 +00:00
# NOTE: The fb state is *completely* meaningless on this platform.
# This is effectively a noop, we're just keeping it for logging purposes...
2021-07-21 16:12:58 +00:00
echo "Making sure that rotation is set to Portrait" >>crash.log 2>& 1
2021-09-02 20:33:10 +00:00
./fbdepth -R UR >>crash.log 2>& 1
# We haven't actually done anything, so don't do anything on exit either ;).
unset ORIG_FB_BPP
2021-07-21 16:12:58 +00:00
return
fi
2024-05-09 01:27:37 +00:00
# On color panels, we target 32bpp for, well, color, and sane addressing (it also happens to be their default) ;o).
eval " $( ./fbink -e | tr ';' '\n' | grep -e hasColorPanel | tr '\n' ';' ) "
# shellcheck disable=SC2154
if [ " ${ hasColorPanel } " = "1" ] ; then
2024-07-27 23:19:40 +00:00
# If color rendering has been disabled by the user, switch to 8bpp to completely skip CFA processing
if grep -q '\["color_rendering"\] = false' 'settings.reader.lua' 2>/dev/null; then
echo "Switching fb bitdepth to 8bpp (to disable CFA) & rotation to Portrait" >>crash.log 2>& 1
./fbdepth -d 8 -R UR >>crash.log 2>& 1
else
echo "Switching fb bitdepth to 32bpp & rotation to Portrait" >>crash.log 2>& 1
./fbdepth -d 32 -R UR >>crash.log 2>& 1
fi
2024-05-09 01:27:37 +00:00
return
fi
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
# Check if the swap has been disabled...
if grep -q '\["dev_startup_no_fbdepth"\] = true' 'settings.reader.lua' 2>/dev/null; then
# Swap back to the original bitdepth (in case this was a restart)
if [ -n " ${ ORIG_FB_BPP } " ] ; then
2019-09-11 17:40:36 +00:00
# Unless we're a Forma/Libra, don't even bother to swap rotation if the fb is @ 16bpp, because RGB565 is terrible anyways,
2019-03-27 21:50:44 +00:00
# so there's no faster codepath to achieve, and running in Portrait @ 16bpp might actually be broken on some setups...
2019-09-11 17:40:36 +00:00
if [ " ${ ORIG_FB_BPP } " -eq "16" ] && [ " ${ PRODUCT } " != "frost" ] && [ " ${ PRODUCT } " != "storm" ] ; then
2019-03-27 21:50:44 +00:00
echo " Making sure we're using the original fb bitdepth @ ${ ORIG_FB_BPP } bpp & rotation @ ${ ORIG_FB_ROTA } " >>crash.log 2>& 1
./fbdepth -d " ${ ORIG_FB_BPP } " -r " ${ ORIG_FB_ROTA } " >>crash.log 2>& 1
else
echo " Making sure we're using the original fb bitdepth @ ${ ORIG_FB_BPP } bpp, and that rotation is set to Portrait " >>crash.log 2>& 1
2021-07-21 16:12:58 +00:00
./fbdepth -d " ${ ORIG_FB_BPP } " -R UR >>crash.log 2>& 1
2019-03-27 21:50:44 +00:00
fi
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
fi
else
# Swap to 8bpp if things looke sane
if [ -n " ${ ORIG_FB_BPP } " ] ; then
2019-03-27 21:50:44 +00:00
echo "Switching fb bitdepth to 8bpp & rotation to Portrait" >>crash.log 2>& 1
2021-07-21 16:12:58 +00:00
./fbdepth -d 8 -R UR >>crash.log 2>& 1
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
fi
fi
}
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
# Ensure we start with a valid nameserver in resolv.conf, otherwise we're stuck with broken name resolution (#6421, #6424).
# Fun fact: this wouldn't be necessary if Kobo were using a non-prehistoric glibc... (it was fixed in glibc 2.26).
ko_do_dns( ) {
# If there aren't any servers listed, append CloudFlare's
2020-08-02 21:32:20 +00:00
if ! grep -q '^nameserver' "/etc/resolv.conf" ; then
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
echo "# Added by KOReader because your setup is broken" >>"/etc/resolv.conf"
echo "nameserver 1.1.1.1" >>"/etc/resolv.conf"
fi
}
2016-03-01 18:43:56 +00:00
# Remount the SD card RW if it's inserted and currently RO
2017-04-11 09:28:01 +00:00
if awk '$4~/(^|,)ro($|,)/' /proc/mounts | grep ' /mnt/sd ' ; then
mount -o remount,rw /mnt/sd
2016-02-23 12:46:57 +00:00
fi
2016-02-22 09:23:43 +00:00
[chore] A round of Kobo specific script cleanup (#3876)
* Flag those scripts as executable in git
Somewhat irrelevant because we'll end up living on a FAT32 drive, but,
still.
* Cleanup Kobo startup script
Support KFMon >= 0.9.5
Don't siphon PRODUCT from nickel, it's exported by rcS, so fmon/KFMon
already inherit it.
Siphon NICKEL_HOME, on the off-chance nickel fails to figure that one
out for itself on restart.
Siphon LANG (This may be a terrible idea, rcS sets LANG to en_US.UTF-8,
while we set LC_ALL to en_US.UTF-8, but I don't know if nickel itself
ever updates LANG, since I have mine set to en_US also ;)).
My secret hope if that everything's working as it should and this ensures
we default to Nickel's locale on fresh installs?
Remove the extra sync on startup, both @Baskerville's fmon and KFMon are
smart enough not to do anything overly stupid, and recent FW versions
have a slightly more resilient DB anyway (rollback journal -> WAL).
This effectively shaves over a second off our startup time.
* Slimmed down the nickel restart script.
Based on current rcS
Scrapped a bucketload of irrelevant & legacy crap, since we're never
bootstrapping nickel, only restarting it.
* Update Kobo install instrcutions.
Point to KSM09, @Baskerville's fmon, and KFMon.
Deprecate legacy fmon, and as such, stop shipping a useless KoboRoot
tarball.
2018-04-15 13:05:45 +00:00
# we keep at most 500KB worth of crash log
2017-04-09 08:42:16 +00:00
if [ -e crash.log ] ; then
2017-04-11 09:28:01 +00:00
tail -c 500000 crash.log >crash.log.new
mv -f crash.log.new crash.log
2017-04-09 08:42:16 +00:00
fi
2017-04-06 20:54:24 +00:00
2019-09-07 01:19:18 +00:00
CRASH_COUNT = 0
CRASH_TS = 0
CRASH_PREV_TS = 0
2020-08-25 00:00:59 +00:00
# List of supported special return codes
KO_RC_RESTART = 85
KO_RC_USBMS = 86
2020-11-14 22:39:19 +00:00
KO_RC_HALT = 88
2019-09-07 01:19:18 +00:00
# Because we *want* an initial fbdepth pass ;).
2020-08-25 00:00:59 +00:00
RETURN_VALUE = ${ KO_RC_RESTART }
2020-02-02 19:35:21 +00:00
while [ ${ RETURN_VALUE } -ne 0 ] ; do
2020-08-25 00:00:59 +00:00
if [ ${ RETURN_VALUE } -eq ${ KO_RC_RESTART } ] ; then
2019-09-07 01:19:18 +00:00
# Do an update check now, so we can actually update KOReader via the "Restart KOReader" menu entry ;).
ko_update_check
# Do or double-check the fb depth switch, or restore original bitdepth if requested
ko_do_fbdepth
Various Wi-Fi QoL improvements (#6424)
* Revamped most actions that require an internet connection to a new/fixed backend that allows forwarding the initial action and running it automatically once connected. (i.e., it'll allow you to set "Action when Wi-Fi is off" to "turn_on", and whatch stuff connect and do what you wanted automatically without having to re-click anywhere instead of showing you a Wi-Fi prompt and then not doing anything without any other feedback).
* Speaking of, fixed the "turn_on" beforeWifi action to, well, actually work. It's no longer marked as experimental.
* Consistently use "Wi-Fi" everywhere.
* On Kobo/Cervantes/Sony, implemented a "Kill Wi-Fi connection when inactive" system that will automatically disconnect from Wi-Fi after sustained *network* inactivity (i.e., you can keep reading, it'll eventually turn off on its own). This should be smart and flexible enough not to murder Wi-Fi while you need it, while still not keeping it uselessly on and murdering your battery.
(i.e., enable that + turn Wi-Fi on when off and enjoy never having to bother about Wi-Fi ever again).
* Made sending `NetworkConnected` / `NetworkDisconnected` events consistent (they were only being sent... sometimes, which made relying on 'em somewhat problematic).
* restoreWifiAsync is now only run when really needed (i.e., we no longer stomp on an existing working connection just for the hell of it).
* We no longer attempt to kill a bogus non-existent Wi-Fi connection when going to suspend, we only do it when it's actually needed.
* Every method of enabling Wi-Fi will now properly tear down Wi-Fi on failure, instead of leaving it in an undefined state.
* Fixed an issue in the fancy crash screen on Kobo/reMarkable that could sometime lead to the log excerpt being missing.
* Worked-around a number of sneaky issues related to low-level Wi-Fi/DHCP/DNS handling on Kobo (see the lengthy comments [below](https://github.com/koreader/koreader/pull/6424#issuecomment-663881059) for details). Fix #6421
Incidentally, this should also fix the inconsistencies experienced re: Wi-Fi behavior in Nickel when toggling between KOReader and Nickel (use NM/KFMon, and run a current FW for best results).
* For developers, this involves various cleanups around NetworkMgr and NetworkListener. Documentation is in-line, above the concerned functions.
2020-07-27 01:39:06 +00:00
# Make sure we have a sane resolv.conf
ko_do_dns
2019-09-07 01:19:18 +00:00
fi
2018-07-04 17:25:55 +00:00
2021-01-07 19:38:10 +00:00
./reader.lua " $@ " >>crash.log 2>& 1
2017-05-16 09:11:11 +00:00
RETURN_VALUE = $?
2019-09-07 01:19:18 +00:00
# Did we crash?
2020-11-14 22:39:19 +00:00
if [ ${ RETURN_VALUE } -ne 0 ] && [ ${ RETURN_VALUE } -ne ${ KO_RC_RESTART } ] && [ ${ RETURN_VALUE } -ne ${ KO_RC_USBMS } ] && [ ${ RETURN_VALUE } -ne ${ KO_RC_HALT } ] ; then
2019-09-07 01:19:18 +00:00
# Increment the crash counter
CRASH_COUNT = $(( CRASH_COUNT + 1 ))
CRASH_TS = $( date +'%s' )
# Reset it to a first crash if it's been a while since our last crash...
if [ $(( CRASH_TS - CRASH_PREV_TS)) -ge 20 ] ; then
CRASH_COUNT = 1
fi
# Check if the user requested to always abort on crash
if grep -q '\["dev_abort_on_crash"\] = true' 'settings.reader.lua' 2>/dev/null; then
ALWAYS_ABORT = "true"
# In which case, make sure we pause on *every* crash
CRASH_COUNT = 1
else
ALWAYS_ABORT = "false"
fi
# Show a fancy bomb on screen
viewWidth = 600
viewHeight = 800
FONTH = 16
eval " $( ./fbink -e | tr ';' '\n' | grep -e viewWidth -e viewHeight -e FONTH | tr '\n' ';' ) "
# Compute margins & sizes relative to the screen's resolution, so we end up with a similar layout, no matter the device.
# Height @ ~56.7%, w/ a margin worth 1.5 lines
2020-02-02 19:35:21 +00:00
bombHeight = $(( viewHeight / 2 + viewHeight / 15 ))
bombMargin = $(( FONTH + FONTH / 2 ))
2021-07-21 16:12:58 +00:00
# Start with a big gray screen of death, and our friendly old school crash icon ;)
# U+1F4A3, the hard way, because we can't use \u or \U escape sequences...
2021-10-31 22:48:13 +00:00
# shellcheck disable=SC2039,SC3003,SC2086
2022-01-15 23:24:21 +00:00
./fbink -q ${ FBINK_BATCH_FLAG } -c -B GRAY9 -m -t regular = ./fonts/freefont/FreeSerif.ttf,px= ${ bombHeight } ,top= ${ bombMargin } -W ${ FBINK_WFM } -- $'\xf0\x9f\x92\xa3'
2019-09-07 01:19:18 +00:00
# With a little notice at the top of the screen, on a big gray screen of death ;).
2021-10-31 22:48:13 +00:00
# shellcheck disable=SC2086
2022-01-15 23:24:21 +00:00
./fbink -q ${ FBINK_BATCH_FLAG } ${ FBINK_BGLESS_FLAG } -m -y 1 -W ${ FBINK_WFM } -- " Don't Panic! (Crash n° ${ CRASH_COUNT } -> ${ RETURN_VALUE } ) "
2019-09-07 01:19:18 +00:00
if [ ${ CRASH_COUNT } -eq 1 ] ; then
# Warn that we're waiting on a tap to continue...
2021-10-31 22:48:13 +00:00
# shellcheck disable=SC2086
2022-01-15 23:24:21 +00:00
./fbink -q ${ FBINK_BATCH_FLAG } ${ FBINK_BGLESS_FLAG } -m -y 2 -W ${ FBINK_WFM } -- "Tap the screen to continue."
2019-09-07 01:19:18 +00:00
fi
# And then print the tail end of the log on the bottom of the screen...
crashLog = " $( tail -n 25 crash.log | sed -e 's/\t/ /g' ) "
# The idea for the margins being to leave enough room for an fbink -Z bar, small horizontal margins, and a font size based on what 6pt looked like @ 265dpi
2021-07-21 16:12:58 +00:00
# shellcheck disable=SC2086
2022-01-15 23:24:21 +00:00
./fbink -q ${ FBINK_BATCH_FLAG } ${ FBINK_BGLESS_FLAG } -t regular = ./fonts/droid/DroidSansMono.ttf,top= $(( viewHeight / 2 + FONTH * 2 + FONTH / 2 )) ,left= $(( viewWidth / 60 )) ,right= $(( viewWidth / 60 )) ,px= $(( viewHeight / 64 )) ${ FBINK_OT_PADDING } -W ${ FBINK_WFM } -- " ${ crashLog } "
2021-07-21 16:12:58 +00:00
if [ " ${ PLATFORM } " != "b300-ntx" ] ; then
# So far, we hadn't triggered an actual screen refresh, do that now, to make sure everything is bundled in a single flashing refresh.
./fbink -q -f -s
fi
2019-09-07 01:19:18 +00:00
# Cue a lemming's faceplant sound effect!
2019-10-12 15:51:26 +00:00
{
echo "!!!!"
echo " Uh oh, something went awry... (Crash n° ${ CRASH_COUNT } : $( date +'%x @ %X' ) ) "
echo " Running FW $( cut -f3 -d',' /mnt/onboard/.kobo/version) on Linux $( uname -r) ( $( uname -v) ) "
} >>crash.log 2>& 1
2020-02-02 19:35:21 +00:00
if [ ${ CRASH_COUNT } -lt 5 ] && [ " ${ ALWAYS_ABORT } " = "false" ] ; then
2019-09-07 01:19:18 +00:00
echo "Attempting to restart KOReader . . ." >>crash.log 2>& 1
echo "!!!!" >>crash.log 2>& 1
fi
# Pause a bit if it's the first crash in a while, so that it actually has a chance of getting noticed ;).
if [ ${ CRASH_COUNT } -eq 1 ] ; then
# NOTE: We don't actually care about what read read, we're just using it as a fancy sleep ;).
# i.e., we pause either until the 15s timeout, or until the user touches the screen.
2021-04-24 17:02:48 +00:00
# shellcheck disable=SC2039,SC3045
2021-07-21 16:12:58 +00:00
read -r -t 15 <" ${ KOBO_TS_INPUT } "
2019-09-07 01:19:18 +00:00
fi
# Cycle the last crash timestamp
CRASH_PREV_TS = ${ CRASH_TS }
# But if we've crashed more than 5 consecutive times, exit, because we wouldn't want to be stuck in a loop...
# NOTE: No need to check for ALWAYS_ABORT, CRASH_COUNT will always be 1 when it's true ;).
2020-02-02 19:35:21 +00:00
if [ ${ CRASH_COUNT } -ge 5 ] ; then
2019-09-07 01:19:18 +00:00
echo "Too many consecutive crashes, aborting . . ." >>crash.log 2>& 1
echo "!!!! ! !!!!" >>crash.log 2>& 1
break
fi
# If the user requested to always abort on crash, do so.
if [ " ${ ALWAYS_ABORT } " = "true" ] ; then
echo "Aborting . . ." >>crash.log 2>& 1
echo "!!!! ! !!!!" >>crash.log 2>& 1
break
fi
else
# Reset the crash counter if that was a sane exit/restart
CRASH_COUNT = 0
fi
2020-08-25 00:00:59 +00:00
if [ ${ RETURN_VALUE } -eq ${ KO_RC_USBMS } ] ; then
# User requested an USBMS session, setup the tool outside of onboard
2020-09-07 21:11:15 +00:00
USBMS_HOME = "/mnt/usbms"
mkdir -p " ${ USBMS_HOME } "
# We're using a custom tmpfs in case /tmp is too small (mainly because we may need to import a large CJK font in there...)
if ! mount -t tmpfs tmpfs ${ USBMS_HOME } -o defaults,size= 32M,mode= 1777,noatime; then
echo "Failed to create the USBMS tmpfs, restarting KOReader . . ." >>crash.log 2>& 1
continue
fi
if ! ./tar xzf "./data/KoboUSBMS.tar.gz" -C " ${ USBMS_HOME } " ; then
echo "Couldn't unpack KoboUSBMS, restarting KOReader . . ." >>crash.log 2>& 1
if ! umount " ${ USBMS_HOME } " ; then
echo "Couldn't unmount the USBMS tmpfs, shutting down in 30 sec!" >>crash.log 2>& 1
sleep 30
poweroff -f
fi
rm -rf " ${ USBMS_HOME } "
2020-08-29 03:20:28 +00:00
continue
fi
2020-08-25 00:00:59 +00:00
2020-08-26 23:06:41 +00:00
# Then siphon KOReader's language for i18n...
if grep -q '\["language"\]' 'settings.reader.lua' 2>/dev/null; then
usbms_lang = " $( grep '\["language"\]' 'settings.reader.lua' | cut -d'"' -f4) "
else
usbms_lang = "C"
fi
2020-09-07 21:11:15 +00:00
# If the language is CJK, copy the CJK font, too...
case " ${ usbms_lang } " in
ja* | ko* | zh*)
cp -pf " ${ KOREADER_DIR } /fonts/noto/NotoSansCJKsc-Regular.otf " " ${ USBMS_HOME } /resources/fonts/NotoSansCJKsc-Regular.otf "
; ;
esac
2020-08-25 00:00:59 +00:00
# Here we go!
2020-09-07 21:11:15 +00:00
if ! cd " ${ USBMS_HOME } " ; then
echo " Couldn't chdir to ${ USBMS_HOME } , restarting KOReader . . . " >>crash.log 2>& 1
if ! umount " ${ USBMS_HOME } " ; then
echo "Couldn't unmount the USBMS tmpfs, shutting down in 30 sec!" >>crash.log 2>& 1
sleep 30
poweroff -f
fi
rm -rf " ${ USBMS_HOME } "
2020-08-29 03:20:28 +00:00
continue
fi
2020-08-30 16:59:16 +00:00
env LANGUAGE = " ${ usbms_lang } " ./usbms
fail = $?
if [ ${ fail } -ne 0 ] ; then
# NOTE: Early init failures return KO_RC_USBMS,
# to allow simply restarting KOReader when we know the integrity of onboard hasn't been compromised...
if [ ${ fail } -eq ${ KO_RC_USBMS } ] ; then
echo "KoboUSBMS failed to setup an USBMS session, restarting KOReader . . ." >>" ${ KOREADER_DIR } /crash.log " 2>& 1
else
# Hu, oh, something went wrong... Stay around for 90s (enough time to look at the syslog over Wi-Fi), and then shutdown.
logger -p "DAEMON.CRIT" -t " koreader.sh[ $$ ] " " USBMS session failed ( ${ fail } ), shutting down in 90 sec! "
sleep 90
poweroff -f
fi
2020-08-25 00:00:59 +00:00
fi
# Jump back to the right place, and keep on trucking
2020-08-29 03:20:28 +00:00
if ! cd " ${ KOREADER_DIR } " ; then
logger -p "DAEMON.CRIT" -t " koreader.sh[ $$ ] " " Couldn't chdir back to KOREADER_DIR ( ${ KOREADER_DIR } ), shutting down in 30 sec! "
sleep 30
poweroff -f
fi
2020-09-07 21:11:15 +00:00
# Tear down the tmpfs...
if ! umount " ${ USBMS_HOME } " ; then
logger -p "DAEMON.CRIT" -t " koreader.sh[ $$ ] " "Couldn't unmount the USBMS tmpfs, shutting down in 30 sec!"
sleep 30
poweroff -f
fi
rm -rf " ${ USBMS_HOME } "
2020-08-25 00:00:59 +00:00
fi
2020-11-14 22:39:19 +00:00
# Did we request a reboot/shutdown?
if [ ${ RETURN_VALUE } -eq ${ KO_RC_HALT } ] ; then
break
fi
2017-05-16 09:11:11 +00:00
done
2014-08-18 23:48:31 +00:00
2024-06-13 21:36:34 +00:00
# If we requested a reboot/shutdown, no need to bother with this...
if [ ${ RETURN_VALUE } -ne ${ KO_RC_HALT } ] ; then
# Restore original fb bitdepth if need be...
# Since we also (almost) always enforce Portrait, we also have to restore the original rotation no matter what ;).
if [ -n " ${ ORIG_FB_BPP } " ] ; then
echo " Restoring original fb bitdepth @ ${ ORIG_FB_BPP } bpp & rotation @ ${ ORIG_FB_ROTA } " >>crash.log 2>& 1
./fbdepth -d " ${ ORIG_FB_BPP } " -r " ${ ORIG_FB_ROTA } " >>crash.log 2>& 1
else
echo " Restoring original fb rotation @ ${ ORIG_FB_ROTA } " >>crash.log 2>& 1
./fbdepth -r " ${ ORIG_FB_ROTA } " >>crash.log 2>& 1
fi
2019-03-13 18:24:30 +00:00
2024-06-13 21:36:34 +00:00
# Restore original CPUFreq governor if need be...
if [ -n " ${ ORIG_CPUFREQ_GOV } " ] ; then
echo " ${ ORIG_CPUFREQ_GOV } " >" ${ CPUFREQ_SYSFS_PATH } /scaling_governor "
2020-11-25 14:50:47 +00:00
2024-06-13 21:36:34 +00:00
# NOTE: Leave DVFS alone, it'll be handled by Nickel if necessary.
fi
2018-07-28 14:09:58 +00:00
2020-11-14 22:39:19 +00:00
if [ " ${ VIA_NICKEL } " = "true" ] ; then
if [ " ${ FROM_KFMON } " = "true" ] ; then
# KFMon is the only launcher that has a toggle to either reboot or restart Nickel on exit
if grep -q "reboot_on_exit=false" "/mnt/onboard/.adds/kfmon/config/koreader.ini" 2>/dev/null; then
# KFMon asked us to restart nickel on exit (default since KFMon 0.9.5)
./nickel.sh &
else
# KFMon asked us to restart the device on exit
/sbin/reboot
fi
2017-04-11 09:28:01 +00:00
else
2020-11-14 22:39:19 +00:00
# Otherwise, just restart Nickel
./nickel.sh &
2017-04-11 09:28:01 +00:00
fi
2020-04-29 15:50:29 +00:00
else
2020-11-14 22:39:19 +00:00
# if we were called from advboot then we must reboot to go to the menu
# NOTE: This is actually achieved by checking if KSM or a KSM-related script is running:
# This might lead to false-positives if you use neither KSM nor advboot to launch KOReader *without nickel running*.
2022-11-12 16:44:11 +00:00
if ! pkill -0 -f kbmenu; then
2020-11-14 22:39:19 +00:00
/sbin/reboot
fi
2017-04-11 09:28:01 +00:00
fi
2022-11-07 16:14:40 +00:00
else
if [ " ${ VIA_NICKEL } " = "false" ] ; then
2022-11-12 16:44:11 +00:00
if pkill -0 -f kbmenu; then
2022-11-07 16:14:40 +00:00
# If we were started by KSM and requested an exit, attempt to *NOT* exit the script,
# so as not to re-enter KSM at all, to make sure the device powers off with our own ScreenSaver displayed.
# NOTE: This might not be fool-proof, as a poweroff might take longer than that,
# or we might be interrupted early by signals.
sleep 10
fi
fi
2014-08-18 23:48:31 +00:00
fi
2015-04-26 23:59:50 +00:00
2020-08-25 00:00:59 +00:00
# Wipe the clones on exit
rm -f "/tmp/koreader.sh"
2020-02-02 19:35:21 +00:00
exit ${ RETURN_VALUE }