Fix for FW 6.0.279225
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c
- Domain
- embedded-iot
Research direction
The issue includes a proposed patch in usbms.c and usbms.h for MTK power supply paths. Read the existing sysfs path selection and its related definitions, then check how the fallback handles both firmware naming schemes. Done means USB cable detection, battery readings, and charger type work on FW 6.x while FW 5.x behavior remains unchanged; the issue reports an on-device test for FW 6.x.
Written by the indexing model from the issue text.
Description
Hi all,
this is an AI-generated pull request after the Kobo updated silently to firmware 6.0.x and koreader stopped working.
This is for the KoboUSBMS part because USB connection stopped working even after getting latest Koreader to work.
Pull request for koreader/KoboUSBMS: MTK fallback to the battery power supply on FW 6.x
Commit message
MTK: fall back to the battery power supply on FW 6.x
Kobo FW 6.0 renamed the bd71827 power supply from bd71827_bat to battery
(same driver, same attributes). On MTK, usbms hardcoded the old name for
capacity, status and charger_type, and it uses status for cable sensing,
so on FW 6.x it never saw the cable, showed 0% and gave up after 60 s.
If bd71827_bat/status is missing and battery/status exists, use the
battery node for all three. Nothing changes when bd71827_bat exists
(FW 5.x).
Fixes #11
Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR title
MTK: fall back to the battery power supply on FW 6.x
PR description
Fixes #11.
Problem. Kobo FW 6.0 renamed the bd71827 power supply from bd71827_bat to battery.
The driver is unchanged (bd71827-power), and so are its attributes. On MTK, usbms hardcodes
the old name for MTK_BATT_CAP_SYSFS, MTK_BATT_STATUS_SYSFS and MTK_CHARGER_TYPE_SYSFS.
Because sysfs_is_usb_plugged() reads MTK_BATT_STATUS_SYSFS for cable sensing and returns
false when the file can't be opened, the effect on FW 6.x is:
- "Waiting to be plugged in…" with the cable already in, and the 60 s countdown runs out.
The post-timeout re-check uses the same function, so it can't recover. - Unplug/replug is caught as a uevent, but the re-check after the 2 s settle fails
("still unplugged despite the plug in event"), so the countdown just starts over. - The battery reads 0%, and the charger-type check is skipped (
CHARGER_TYPE_SYSFS→NULL).
Evidence.
- Kobo's own firmware images (
qt6-update-*.zipfrom ereaderfiles.kobo.com),
spa-bw/kernel.img(Clara BW): 5.18.270971 hasbd71827_bat/bd71827_ac, while
6.0.279225 only hasbattery. - Live sysfs on a 6.0 Clara Colour, from #11:
/sys/class/power_supply/battery -> …/bd71827-power.4.auto/power_supply/battery, with
battery/charger_typepresent. - Observed on a Clara BW (N365), FW 6.0.279225, KOReader kobov5 nightly
v2026.07.2-362-g98d22cc: all three symptoms above.
Change. In the is_mtk branch, if bd71827_bat/status does not exist and
battery/status does, use battery/{capacity,status,charger_type} (new MTK_FW6_*
defines) and log it. Otherwise the existing paths are used exactly as before, so nothing
changes on FW 5.x, where bd71827_bat exists. The battery/* strings match the sunxi ones,
but they get their own defines because they mean "MTK on FW 6", not sunxi.
The four existing *_CHARGER_TYPE_SYSFS defines are realigned by two columns. That is what
clang-format (the repo's .clang-format, AlignConsecutiveMacros: AcrossComments) produces
once the longer MTK_FW6_CHARGER_TYPE_SYSFS joins the block. usbms.c needs no reformatting.
Testing.
- Built the way KOReader ships it: koreader-base
d530560f(pinned by KOReader98d22cc),
make TARGET=kobov5 kobo-usbmsinkoreader/kokobo:6.0.0-22.04, with this change added via
PATCH_FILESinthirdparty/kobo-usbms/CMakeLists.txt. As a control, the unmodified
build reproduces theusbmsshipped in that nightly byte for byte (sha25614a1e494…). - The patched build compiles warning-free with the project's warning flags. In the resulting
KoboUSBMS.tar.gz, onlyusbmsdiffers from the control build. - The binary tested on the device was built from this change before the
clang-format
realignment above. That realignment is whitespace in four#definelines and nothing else
(git diff -widentical). - Tested on device: Clara BW (N365), FW 6.0.279225, KOReader kobov5 nightly
v2026.07.2-362-g98d22cc. Before: "KoboUSBMS failed to setup an USBMS session" on every
attempt. After: the cable is detected right away, the USB screen shows the real battery
level, and the host enumerates2237:4239and attaches the 12.3 GB storage, which reads
fine. Ejecting from the host ends the session, and KOReader comes back. - Not tested on FW 5.x hardware. There,
bd71827_bat/statusexists (confirmed in the
5.18.270971 kernel), so theelsebranch is taken and behaviour is identical to before.
Follow-up. After merge, koreader-base needs its pin in
thirdparty/kobo-usbms/CMakeLists.txt bumped for the fix to reach KOReader builds.
Related KOReader-side fix for the same rename: koreader/koreader#16423.
The patch
diff --git a/usbms.c b/usbms.c
index 42675b8..523e74a 100644
--- a/usbms.c
+++ b/usbms.c
@@ -1137,13 +1137,21 @@ int
// And setup the sysfs paths & usb check based on the device…
if (ctx.fbink_state.is_mtk) {
- BATT_CAP_SYSFS = MTK_BATT_CAP_SYSFS;
- CHARGER_TYPE_SYSFS = MTK_CHARGER_TYPE_SYSFS;
+ // NOTE: FW 6.x renamed the bd71827 power supply from bd71827_bat to battery...
+ if (access(MTK_BATT_STATUS_SYSFS, F_OK) != 0 && access(MTK_FW6_BATT_STATUS_SYSFS, F_OK) == 0) {
+ BATT_CAP_SYSFS = MTK_FW6_BATT_CAP_SYSFS;
+ CHARGER_TYPE_SYSFS = MTK_FW6_CHARGER_TYPE_SYSFS;
+ BATT_STATUS_SYSFS = MTK_FW6_BATT_STATUS_SYSFS;
+ LOG(LOG_INFO, "Using the FW 6.x MTK power supply sysfs entries (battery instead of bd71827_bat)");
+ } else {
+ BATT_CAP_SYSFS = MTK_BATT_CAP_SYSFS;
+ CHARGER_TYPE_SYSFS = MTK_CHARGER_TYPE_SYSFS;
+ BATT_STATUS_SYSFS = MTK_BATT_STATUS_SYSFS;
+ }
// The CM_USB_Plug_IN ioctl still doesn't look at the right power supplies...
// NOTE: And will actually crash the kernel if you attempt it!
- BATT_STATUS_SYSFS = MTK_BATT_STATUS_SYSFS;
- fxpIsUSBPlugged = &sysfs_is_usb_plugged;
+ fxpIsUSBPlugged = &sysfs_is_usb_plugged;
LOG(LOG_INFO, "Using the MTK battery status sysfs entry to handle cable sensing");
} else if (ctx.fbink_state.is_sunxi) {
BATT_CAP_SYSFS = SUNXI_BATT_CAP_SYSFS;
diff --git a/usbms.h b/usbms.h
index 1662cd4..415f969 100644
--- a/usbms.h
+++ b/usbms.h
@@ -133,11 +133,15 @@ const char* BATT_CAP_SYSFS = NULL;
const char* BATT_STATUS_SYSFS = NULL;
bool (*fxpIsUSBPlugged)(int, bool) = NULL;
// These, on the other hand, are only available on Mk. 7+
-#define NXP_CHARGER_TYPE_SYSFS "/sys/class/power_supply/mc13892_charger/device/charger_type"
-#define SUNXI_CHARGER_TYPE_SYSFS "/sys/class/power_supply/charger/device/charger_type"
+#define NXP_CHARGER_TYPE_SYSFS "/sys/class/power_supply/mc13892_charger/device/charger_type"
+#define SUNXI_CHARGER_TYPE_SYSFS "/sys/class/power_supply/charger/device/charger_type"
// Finally, we're also starting to see more standard stuff... (e.g., on Mk. 10)
-#define STD_CHARGER_TYPE_SYSFS "/sys/class/power_supply/ac/device/charger_type"
-#define MTK_CHARGER_TYPE_SYSFS "/sys/class/power_supply/bd71827_bat/charger_type"
+#define STD_CHARGER_TYPE_SYSFS "/sys/class/power_supply/ac/device/charger_type"
+#define MTK_CHARGER_TYPE_SYSFS "/sys/class/power_supply/bd71827_bat/charger_type"
+// FW 6.x renamed the bd71827 power supply from bd71827_bat to battery (same driver, same attributes)
+#define MTK_FW6_BATT_CAP_SYSFS "/sys/class/power_supply/battery/capacity"
+#define MTK_FW6_BATT_STATUS_SYSFS "/sys/class/power_supply/battery/status"
+#define MTK_FW6_CHARGER_TYPE_SYSFS "/sys/class/power_supply/battery/charger_type"
// For ref., on mainline w/ @akemnade's driver: /sys/class/power_supply/rn5t618-usb/usb_type
const char* CHARGER_TYPE_SYSFS = NULL;
// For the weird standalone USB-C controller found on sunxi & Mk. 9...
- Dominant language
- C
- Stars
- 25
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from koreader/KoboUSBMS
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
-
FR: 12 Hour Clock?May be free again @NiLuJe claimed this 516 days ago, and no pull request is open. Open
All issues in koreader/KoboUSBMS
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
lem-project/lem#2525 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
jaff-chemistry/jaff#231 ·
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
389ds/389-ds-base#8251 ·
Maintainers usually reply within 1 day
-
ColumnDecimal::Append(Int128) stores a value outside the Decimal(P, S) range with no error: cut to 32/64 bits, or with too many digitsPossibly taken @RUSHIT305 claimed this today. Openbug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cpp#645 · 1 comment ·
Maintainers usually reply within 1 day