package/base-files: add caldata_sysfsload_from_file()
authorThibaut VARÈNE <hacks@slashdirt.org>
Mon, 20 Apr 2020 11:48:02 +0000 (13:48 +0200)
committerKoen Vandeputte <koen.vandeputte@ncentric.com>
Fri, 8 May 2020 13:17:17 +0000 (15:17 +0200)
This routine enables loading caldata binary via the kernel sysfs loader

See https://www.kernel.org/doc/html/v4.19/driver-api/firmware/fallback-mechanisms.html

Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
package/base-files/Makefile
package/base-files/files/lib/functions/caldata.sh

index f1f0f17a604e18f1fa58e73e2d2f29f7de65d828..d8e7c318788bb3bd8a0b9d102d211dace7e42d04 100644 (file)
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=219
+PKG_RELEASE:=220
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
index 5e969e3409304572c1dddc2fb35cf4d68de92966..6862da716436c64f9ff6177dbcb01a8f9959edd7 100644 (file)
@@ -68,6 +68,21 @@ caldata_from_file() {
                caldata_die "failed to extract calibration data from $source"
 }
 
+caldata_sysfsload_from_file() {
+       local source=$1
+       local offset=$(($2))
+       local count=$(($3))
+
+       # test extract to /dev/null first
+       dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
+               caldata_die "failed to extract calibration data from $source"
+
+       # can't fail now
+       echo 1 > /sys/$DEVPATH/loading
+       dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null
+       echo 0 > /sys/$DEVPATH/loading
+}
+
 caldata_valid() {
        local expected="$1"
        local target=$2