base-files: add caldata_from_file_ubifs function
authorStijn Tintel <stijn@linux-ipv6.be>
Mon, 8 Apr 2024 16:22:55 +0000 (19:22 +0300)
committerStijn Tintel <stijn@linux-ipv6.be>
Mon, 15 Apr 2024 11:06:53 +0000 (14:06 +0300)
On some devices, the caldata is provided in a file on ubifs. Add a
function to extract it.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
package/base-files/files/lib/functions/caldata.sh

index d7b88c7dcef23f7c141bd1434e3949b20f42ea65..c6ca4c4dbb85b72f4a737afe70b73f8b66d6c072 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))