[OpenWrt-Devel] [PATCH 2/3] eeprom.sh: Speed up caldata/eeprom handling

Adrian Schmutzler freifunk at adrianschmutzler.de
Mon Feb 25 18:11:14 EST 2019


Reading and writing to and from flash storage is slow and currently,
especially since some scripts use a block size of 1 to be able skip.

This patch reworks the extraction scripts to be much faster and
efficient by reading and writing in possibly one big block.

This is based on the initial commit a69e101 for ipq40xx by
Christian Lamparter <chunkeey at gmail.com>.

Speed comparison @ UBNT AC-Mesh (ath79, test performed manually)
results in a time reduction of 99.9 %.

> time dd if=/dev/mtd6 of=/lib/firmware/test-slow bs=1 count=4096 skip=4096
4096+0 records in
4096+0 records out
real    0m 16.84s
user    0m 0.07s
sys     0m 13.54s

> time dd if=/dev/mtd6 of=/lib/firmware/test-fast bs=4096 count=1 skip=4096 iflag=skip_bytes
1+0 records in
1+0 records out
real    0m 0.02s
user    0m 0.00s
sys     0m 0.02s

Speed comparison @ TP-Link TL-WDR4300 (ar71xx, tested manually)
results in a time reduction of 99.9 %.

> time dd if=/dev/mtd3 of=/lib/firmware/test-slow bs=1 count=4096 skip=4096
4096+0 records in
4096+0 records out
real    0m 15.85s
user    0m 0.06s
sys     0m 13.28s

> time dd if=/dev/mtd3 of=/lib/firmware/test-fast bs=4096 count=1 skip=4096 iflag=skip_bytes
1+0 records in
1+0 records out
real    0m 0.02s
user    0m 0.00s
sys     0m 0.02s

Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
 package/base-files/files/lib/functions/eeprom.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/package/base-files/files/lib/functions/eeprom.sh b/package/base-files/files/lib/functions/eeprom.sh
index 13494b63db..f0941fe8d8 100644
--- a/package/base-files/files/lib/functions/eeprom.sh
+++ b/package/base-files/files/lib/functions/eeprom.sh
@@ -21,7 +21,7 @@ mtd_eeprom_extract() {
 	[ -n "$mtd" ] || \
 		eeprom_die "no mtd device found for partition $part"
 
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=$count skip=$offset count=1 iflag=skip_bytes 2>/dev/null || \
 		eeprom_die "failed to extract from $mtd"
 }
 
@@ -41,7 +41,7 @@ mtd_eeprom_extract_check() {
 	[ "$count" = "$cal_size" ] || \
 		eeprom_die "no calibration data found in $part"
 
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=$count skip=$offset count=1 iflag=skip_bytes 2>/dev/null || \
 		eeprom_die "failed to extract from $mtd"
 }
 
@@ -74,7 +74,7 @@ ubi_eeprom_extract() {
 	[ -n "$ubi" ] || \
 		eeprom_die "no UBI volume found for $part"
 
-	dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+	dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=$count skip=$offset count=1 iflag=skip_bytes 2>/dev/null || \
 		eeprom_die "failed to extract from $ubi"
 }
 
@@ -83,6 +83,6 @@ ath10kcal_from_file() {
 	local offset=$2
 	local count=$3
 
-	dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+	dd if=$source of=/lib/firmware/$FIRMWARE bs=$count skip=$offset count=1 iflag=skip_bytes 2>/dev/null || \
 		ath10kcal_die "failed to extract calibration data from $source"
 }
-- 
2.11.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list