base-files: add caldata_from_file_ubifs function
authorStijn Tintel <[email protected]>
Mon, 8 Apr 2024 16:22:55 +0000 (19:22 +0300)
committerStijn Tintel <[email protected]>
Mon, 6 Oct 2025 14:38:25 +0000 (17:38 +0300)
On some devices, the caldata is provided in a file on ubifs. Add a
function to extract it.

Signed-off-by: Stijn Tintel <[email protected]>
package/base-files/files/lib/functions/caldata.sh

index f0fc907aeff1a204c0fa62396aaee1ad785f2ce4..2f9f804d7799dd150af2a26f7d2e2175e72c7e52 100644 (file)
@@ -91,6 +91,37 @@ caldata_from_file() {
                caldata_die "failed to extract calibration data from $source"
 }
 
+caldata_from_file_ubifs() {
+       local ubipart=$1
+       local ubivol=$2
+       local source=$3
+       local offset=$4
+       local count=$(($5))
+       local target=$6
+       local dir="/tmp/caldata"
+       local ubi
+       local ubidev
+
+       . /lib/upgrade/nand.sh
+
+       [ -n "$target" ] || target=/lib/firmware/$FIRMWARE
+
+       ubidev=$(nand_attach_ubi "$ubipart")
+       ubi=$(nand_find_volume "$ubidev" "$ubivol")
+
+       [ -n "$ubi" ] || caldata_die "no UBI volume $ubivol found on $ubipart partition"
+
+       mkdir -p "$dir" || caldata_die "failed to create temporary directory"
+
+       grep -q "$dir" /proc/mounts || {
+               mount -t ubifs "${ubidev}:${ubivol}" "$dir" || caldata_die "failed to mount caldata ubifs"
+       }
+
+       caldata_from_file "${dir}/${source}" "$offset" "$count" "$target"
+
+       umount "$dir"
+}
+
 caldata_sysfsload_from_file() {
        local source=$1
        local offset=$(($2))