Initial commit

Work in progress, feature complete, documentation to be done, alpha
This commit is contained in:
rlesavre
2025-04-29 22:43:01 +02:00
parent cb626cb8f9
commit 00956c2a04
26 changed files with 1738 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/src/TRMNL/.vscode
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
https://www.mobileread.com/forums/showthread.php?t=225030&highlight=kobostuff
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
https://pgaskin.net/NickelMenu/
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
https://www.mobileread.com/forums/showthread.php?t=212145&page=5
https://web.archive.org/web/20160401013708/http://www.scherello.de/rtcwake_kobo.zip
Binary file not shown.
Binary file not shown.
+22
View File
@@ -0,0 +1,22 @@
-- This is https://github.com/katlogic/__gc/raw/master/__gc.lua
local rg = assert(rawget)
local proxy_key = "__gc_proxy"
local rs = assert(rawset)
local gmt = assert(debug.getmetatable)
local smt = assert(setmetatable)
local np = assert(newproxy)
return function(t, mt)
if mt ~= nil and rg(mt, "__gc") and not rg(t, "__gc_proxy") then
local p = np(true)
rs(t, proxy_key, p)
gmt(p).__gc = function()
rs(t, proxy_key, nil)
local nmt = gmt(t)
if not nmt then return end
local fin = rg(nmt, "__gc")
if fin then return fin(t) end
end
end
return smt(t, mt)
end
File diff suppressed because it is too large Load Diff
+29
View File
@@ -0,0 +1,29 @@
local ffi = require("ffi")
ffi.cdef[[
typedef long int off_t;
typedef long int time_t;
typedef long int suseconds_t;
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
struct timespec {
time_t tv_sec;
long int tv_nsec;
};
struct statvfs {
long unsigned int f_bsize;
long unsigned int f_frsize;
long unsigned int f_blocks;
long unsigned int f_bfree;
long unsigned int f_bavail;
long unsigned int f_files;
long unsigned int f_ffree;
long unsigned int f_favail;
long unsigned int f_fsid;
long unsigned int f_flag;
long unsigned int f_namemax;
int __f_spare[6];
};
]]
+30
View File
@@ -0,0 +1,30 @@
local ffi = require("ffi")
ffi.cdef[[
typedef long int off_t;
typedef long int time_t;
typedef long int suseconds_t;
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
struct timespec {
time_t tv_sec;
long int tv_nsec;
};
struct statvfs {
long unsigned int f_bsize;
long unsigned int f_frsize;
long unsigned int f_blocks;
long unsigned int f_bfree;
long unsigned int f_bavail;
long unsigned int f_files;
long unsigned int f_ffree;
long unsigned int f_favail;
long unsigned int f_fsid;
int __f_unused;
long unsigned int f_flag;
long unsigned int f_namemax;
int __f_spare[6];
};
]]
+29
View File
@@ -0,0 +1,29 @@
local ffi = require("ffi")
ffi.cdef[[
typedef long int off_t;
typedef long int time_t;
typedef long int suseconds_t;
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
struct timespec {
time_t tv_sec;
long int tv_nsec;
};
struct statvfs {
long unsigned int f_bsize;
long unsigned int f_frsize;
long unsigned int f_blocks;
long unsigned int f_bfree;
long unsigned int f_bavail;
long unsigned int f_files;
long unsigned int f_ffree;
long unsigned int f_favail;
long unsigned int f_fsid;
long unsigned int f_flag;
long unsigned int f_namemax;
int __f_spare[6];
};
]]
+30
View File
@@ -0,0 +1,30 @@
local ffi = require("ffi")
ffi.cdef[[
typedef long int off_t;
typedef long int time_t;
typedef long int suseconds_t;
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
struct timespec {
time_t tv_sec;
long int tv_nsec;
};
struct statvfs {
long unsigned int f_bsize;
long unsigned int f_frsize;
long unsigned int f_blocks;
long unsigned int f_bfree;
long unsigned int f_bavail;
long unsigned int f_files;
long unsigned int f_ffree;
long unsigned int f_favail;
long unsigned int f_fsid;
int __f_unused;
long unsigned int f_flag;
long unsigned int f_namemax;
int __f_spare[6];
};
]]
+18
View File
@@ -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)
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

+111
View File
@@ -0,0 +1,111 @@
#!/bin/sh
# Disable wifi, and remove all modules.
# NOTE: Save our resolv.conf to avoid ending up with an empty one, in case the DHCP client wipes it on release (#6424).
cp -a "/etc/resolv.conf" "/tmp/resolv.ko"
old_hash="$(md5sum "/etc/resolv.conf" | cut -f1 -d' ')"
if [ -x "/sbin/dhcpcd" ]; then
dhcpcd -d -k "${INTERFACE}"
killall -q -TERM udhcpc default.script
else
killall -q -TERM udhcpc default.script dhcpcd
fi
# NOTE: dhcpcd -k waits for the signalled process to die, but busybox's killall doesn't have a -w, --wait flag,
# so we have to wait for udhcpc to die ourselves...
# NOTE: But if all is well, there *isn't* any udhcpc process or script left to begin with...
kill_timeout=0
while pkill -0 udhcpc; do
# Stop waiting after 5s
if [ ${kill_timeout} -ge 20 ]; then
break
fi
usleep 250000
kill_timeout=$((kill_timeout + 1))
done
new_hash="$(md5sum "/etc/resolv.conf" | cut -f1 -d' ')"
# Restore our network-specific resolv.conf if the DHCP client wiped it when releasing the lease...
if [ "${new_hash}" != "${old_hash}" ]; then
mv -f "/tmp/resolv.ko" "/etc/resolv.conf"
else
rm -f "/tmp/resolv.ko"
fi
wpa_cli -i "${INTERFACE}" terminate
[ "${WIFI_MODULE}" = "dhd" ] && wlarm_le -i "${INTERFACE}" down
ifconfig "${INTERFACE}" down
# Handle dependencies, if any
WIFI_DEP_MOD=""
# Honor the platform's preferred method to toggle power
POWER_TOGGLE="module"
# Some platforms never unload the wifi modules
SKIP_UNLOAD=""
case "${WIFI_MODULE}" in
"moal")
WIFI_DEP_MOD="mlan"
POWER_TOGGLE="ntx_io"
;;
"wlan_drv_gen4m")
POWER_TOGGLE="wmt"
SKIP_UNLOAD="true"
;;
esac
if [ -z "${SKIP_UNLOAD}" ]; then
# Some sleep in between may avoid system getting hung
# (we test if a module is actually loaded to avoid unneeded sleeps)
if grep -q "^${WIFI_MODULE} " "/proc/modules"; then
usleep 250000
# NOTE: Kobo's busybox build is weird. rmmod appears to be modprobe in disguise, defaulting to the -r flag...
# But since there's currently no modules.dep file being shipped, nor do they include the depmod applet,
# go with what the FW is doing, which is rmmod.
# c.f., #2394?
rmmod "${WIFI_MODULE}"
fi
if [ -n "${WIFI_DEP_MOD}" ]; then
if grep -q "^${WIFI_DEP_MOD} " "/proc/modules"; then
usleep 250000
rmmod "${WIFI_DEP_MOD}"
fi
fi
fi
echo "Powertoggle is ${POWER_TOGGLE}"
case "${POWER_TOGGLE}" in
"ntx_io")
usleep 250000
./bin/luajit lua/ntx_io.lua 208 0
;;
"wmt")
echo 0 >/dev/wmtWifi
;;
*)
if grep -q "^sdio_wifi_pwr " "/proc/modules"; then
# Handle the shitty DVFS switcheroo...
if [ -n "${CPUFREQ_DVFS}" ]; then
echo "0" >"/sys/devices/platform/mxc_dvfs_core.0/enable"
if [ -n "${CPUFREQ_CONSERVATIVE}" ]; then
echo "conservative" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
else
echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
fi
fi
usleep 250000
rmmod sdio_wifi_pwr
fi
echo "Powertoggle is ${POWER_TOGGLE}"
# 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 lua/ntx_io.lua 208 0
fi
;;
esac
+217
View File
@@ -0,0 +1,217 @@
#!/bin/sh
# NOTE: Close any non-standard fds, so that it doesn't come back to bite us in the ass with USBMS (or sockets) later...
for fd in /proc/"$$"/fd/*; do
close_me="false"
fd_id="$(basename "${fd}")"
fd_path="$(readlink -f "${fd}")"
if [ -e "${fd}" ] && [ "${fd_id}" -gt 2 ]; then
if [ -S "${fd}" ]; then
# Close any and all sockets
# NOTE: Old busybox builds do something stupid when attempting to canonicalize pipes/sockets...
# (i.e., they'll spit out ${fd} as-is, losing any and all mention of a socket/pipe).
fd_path="$(readlink "${fd}")"
close_me="true"
elif [ -p "${fd}" ]; then
# We *might* be catching temporary pipes created by this very test, se we have to leave pipes alone...
# Although it would take extremely unlucky timing, as by the time we go through the top-level -e test,
# said temporary pipe is already gone, and as such we *should* never really enter this branch for temporary pipes ;).
fd_path="$(readlink "${fd}")"
close_me="false"
else
# NOTE: dash (meaning, in turn, busybox's ash) uses fd 10+ open to /dev/tty or $0 (w/ CLOEXEC)
# NOTE: The last fd != fd_path check is there to (potentially) whitelist non-regular files we might have failed to handle,
# it's designed to match the unhelpful result from old buysbox's readlink -f on non-regular files (c.f., previous notes).
if [ "${fd_path}" != "/dev/tty" ] && [ "${fd_path}" != "$(readlink -f "${0}")" ] && [ "${fd}" != "${fd_path}" ]; then
close_me="true"
else
close_me="false"
fi
fi
fi
if [ "${fd_id}" -gt 2 ]; then
if [ "${close_me}" = "true" ]; then
eval "exec ${fd_id}>&-"
echo "[enable-wifi.sh] Closed fd ${fd_id} -> ${fd_path}"
else
# Try to log something more helpful when old busybox's readlink -f mangled it...
if [ "${fd}" = "${fd_path}" ]; then
fd_path="${fd_path} => $(readlink "${fd}")"
if [ ! -e "${fd}" ]; then
# Flag (potentially?) temporary items as such
fd_path="${fd_path} (temporary?)"
fi
fi
echo "[enable-wifi.sh] Left fd ${fd_id} -> ${fd_path} open"
fi
fi
done
# Some platforms do *NOT* use sdio_wifi_pwr, even when it is physically there...
POWER_TOGGLE="module"
# We also want to choose the wpa_supplicant driver depending on the module...
WPA_SUPPLICANT_DRIVER="wext"
# And some platforms also put the modules in some funkier paths...
KMOD_PATH="/drivers/${PLATFORM}/wifi"
case "${WIFI_MODULE}" in
"moal")
POWER_TOGGLE="ntx_io"
WPA_SUPPLICANT_DRIVER="nl80211"
;;
"wlan_drv_gen4m")
POWER_TOGGLE="wmt"
WPA_SUPPLICANT_DRIVER="nl80211"
KMOD_PATH="/drivers/${PLATFORM}/mt66xx"
;;
esac
# Load the requested module if it isn't already
insmod_asneeded() {
kmod="${1}"
shift
if ! grep -q "^${kmod} " "/proc/modules"; then
insmod "${KMOD_PATH}/${kmod}.ko" "${@}"
usleep 250000
fi
}
echo "Powertoggle is ${POWER_TOGGLE}"
# Power up WiFi chip
case "${POWER_TOGGLE}" in
"ntx_io")
# 208 is CM_WIFI_CTRL
./bin/luajit lua/ntx_io.lua 208 1
;;
"wmt")
# NOTE: Unlike earlier platforms, it seems the WiFi modules are only loaded once, and never unloaded.
# So, just make sure they actually are loaded before we go on...
insmod_asneeded "wmt_drv"
insmod_asneeded "wmt_chrdev_wifi"
insmod_asneeded "wmt_cdev_bt"
insmod_asneeded "${WIFI_MODULE}"
# Black magic courtesy of wmt_dbg_func_ctrl @ (out of tree) modules/connectivity/wmt_mt66xx/common_main/linux/wmt_dbg.c
# Enable debug commands
echo "0xDB9DB9" >/proc/driver/wmt_dbg
# Disable the LPBK test
echo "7 9 0" >/proc/driver/wmt_dbg
# Nickel appears to sleep for ~1s
sleep 1
echo "0xDB9DB9" >/proc/driver/wmt_dbg
# Enable the LPBK test (this'll block for ~1.3s)
echo "7 9 1" >/proc/driver/wmt_dbg
# Finally, power on the chip
echo 1 >/dev/wmtWifi
;;
*)
if ! grep -q "^sdio_wifi_pwr " "/proc/modules"; then
if [ -e "${KMOD_PATH}/sdio_wifi_pwr.ko" ]; then
# Handle the shitty DVFS switcheroo...
if [ -n "${CPUFREQ_DVFS}" ]; then
echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
echo "1" >"/sys/devices/platform/mxc_dvfs_core.0/enable"
fi
insmod "${KMOD_PATH}/sdio_wifi_pwr.ko"
else
# Poke the kernel via ioctl on platforms without the dedicated power module...
./luajit frontend/device/kobo/ntx_io.lua 208 1
fi
fi
;;
esac
# Moar sleep!
usleep 250000
# Load WiFi modules
# 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}"
;;
"moal")
WIFI_COUNTRY_CODE_PARM="reg_alpha2=${WIFI_COUNTRY_CODE}"
;;
esac
fi
VENDOR_WIFI_PARM=""
case "${WIFI_MODULE}" in
"moal")
# NXP's driver for the Marvell 88W8987 RF SoC needs to be told what to choose between client, AP & WiFi DIRECT mode.
VENDOR_WIFI_PARM="mod_para=nxp/wifi_mod_para_sd8987.conf"
# And, of course, it requires a submodule...
WIFI_DEP_MOD="mlan"
insmod "${KMOD_PATH}/${WIFI_DEP_MOD}.ko"
# NOTE: Nickel sleeps for two whole seconds after each module loading.
# Let's try our usual timing instead...
usleep 250000
;;
"wlan_drv_gen4m")
# Nothing to do here, we only load the modules once, so we should never enter this branch.
;;
esac
WIFI_PARM=""
if [ -n "${WIFI_COUNTRY_CODE_PARM}" ]; then
if [ -n "${WIFI_PARM}" ]; then
WIFI_PARM="${WIFI_PARM} ${WIFI_COUNTRY_CODE_PARM}"
else
WIFI_PARM="${WIFI_COUNTRY_CODE_PARM}"
fi
fi
if [ -n "${VENDOR_WIFI_PARM}" ]; then
if [ -n "${WIFI_PARM}" ]; then
WIFI_PARM="${WIFI_PARM} ${VENDOR_WIFI_PARM}"
else
WIFI_PARM="${VENDOR_WIFI_PARM}"
fi
fi
if [ -e "${KMOD_PATH}/${WIFI_MODULE}.ko" ]; then
if [ -n "${WIFI_PARM}" ]; then
# shellcheck disable=SC2086
insmod "${KMOD_PATH}/${WIFI_MODULE}.ko" ${WIFI_PARM}
else
insmod "${KMOD_PATH}/${WIFI_MODULE}.ko"
fi
elif [ -e "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" ]; then
# NOTE: Modules are unsorted on Mk. 8
if [ -n "${WIFI_PARM}" ]; then
# shellcheck disable=SC2086
insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" ${WIFI_PARM}
else
insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko"
fi
fi
fi
# Race-y as hell, don't try to optimize this!
# NOTE: We're after a module insert, meaning Nickel may sleep for two whole seconds here.
case "${WIFI_MODULE}" in
"moal")
# NOTE: Bringup may be genuinely slower than usual with this chip, so, mimic Nickel's sleep patterns.
sleep 2
;;
*)
sleep 1
;;
esac
# Bring the network interface up & setup WiFi
ifconfig "${INTERFACE}" up
[ "${WIFI_MODULE}" = "dhd" ] && wlarm_le -i "${INTERFACE}" up
pkill -0 wpa_supplicant ||
wpa_supplicant -D "${WPA_SUPPLICANT_DRIVER}" -s -i "${INTERFACE}" -c /etc/wpa_supplicant/wpa_supplicant.conf -C /var/run/wpa_supplicant -B
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
CHARGING_LED=""
if [ -d "/sys/class/leds/LED" ] ; then
CHARGING_LED="/sys/class/leds/LED/brightness"
elif [ -d "/sys/class/leds/GLED" ] ; then
CHARGING_LED="/sys/class/leds/GLED/brightness"
elif [ -d "/sys/class/leds/bd71828-green-led" ] ; then
CHARGING_LED="/sys/class/leds/bd71828-green-led/brightness"
elif [ -d "/sys/class/leds/pmic_ledsg" ] ; then
CHARGING_LED="/sys/class/leds/pmic_ledsg/brightness"
fi
# Now, test if CHARGING_LED was set
if [ -z "$CHARGING_LED" ]; then
# This block runs if none of the paths were found
echo "Error: Couldn't find the charging led." >&2 # Print errors to stderr
exit 1 # Exit with a non-zero status indicating failure
fi
echo "Found charging LED path: $CHARGING_LED setting value $1"
echo "$1" > "$CHARGING_LED"
exit 0

Some files were not shown because too many files have changed in this diff Show More