From 7afd7318493032a3c1cb8116f5ec231d364a68fb Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Wed, 15 Oct 2025 16:22:44 -0500 Subject: [PATCH] ec/google/chromeec/acpi: Fix long battery string reporting for Windows `ToString(byte x)` is undefined behavior per the ACPI spec, which causes Windows to discard the battery device status entirely. Fix this and improve performance of the BRSX method by using an array to store the characters read, calling ToString() only once at the end. TEST=build/boot Win11 and Linux on google/rex, verify battery status reported properly under both OSes. Change-Id: I4e5aea3b2763a3c4433abe95c3a41d218fcd06c1 Signed-off-by: Matt DeVillier Reviewed-on: https://review.coreboot.org/c/coreboot/+/89602 Tested-by: build bot (Jenkins) Reviewed-by: Martin L Roth Reviewed-by: Nicholas Sudsgaard Reviewed-by: Paul Menzel Reviewed-by: Subrata Banik --- src/ec/google/chromeec/acpi/battery.asl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ec/google/chromeec/acpi/battery.asl b/src/ec/google/chromeec/acpi/battery.asl index 7d5208835a..41b77861a5 100644 --- a/src/ec/google/chromeec/acpi/battery.asl +++ b/src/ec/google/chromeec/acpi/battery.asl @@ -152,13 +152,19 @@ Method(BRSX, 1, Serialized) // Read to end of string, or up to a reasonable maximum length. Reads of // BSRF consume bytes from the FIFO, so take care to read it only once // per byte of data. - Local0 = "" - Local1 = BSRF - While (Local1 != 0 && SizeOf (Local0) < 32) + Local0 = Buffer (33){} + For (Local2 = 0, Local2 < SizeOf(Local0) - 1, Local2++) { - Local0 = Concatenate (Local0, ToString (Local1)) Local1 = BSRF + If (Local1 == 0) + { + Break + } + Local0[Local2] = Local1 } + + Local0[Local2] = 0 + Local0 = ToString(Local0) } // Store the result in the cache