Skip to content

Commit 39d6d31

Browse files
committed
mtd-utils: add ubihealthd to nand-utils
Add ubihealthd to the nand-utils package, auto-create UCI config for each UBI device and launch the daemon on boot. The default time interval between scrubbing a random PED is 120 seconds which means that a fully used 128 MiB flash chip gets scrubbed in about a day and a half. The interval can be adjusted in UCI using the 'interval' option. Suggested-by: Rodrigo Balerdi <[email protected]> Signed-off-by: Daniel Golle <[email protected]> Link: openwrt/openwrt#16973 Signed-off-by: Christian Marangi <[email protected]> (cherry picked from commit 7e287b5)
1 parent 0de3c20 commit 39d6d31

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

package/utils/mtd-utils/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,20 @@ CONFIGURE_ARGS += \
6565
--without-lzo \
6666
--without-zlib
6767

68+
define Package/ubi-utils/conffiles
69+
/etc/config/ubihealthd
70+
endef
71+
6872
define Package/ubi-utils/install
6973
$(INSTALL_DIR) $(1)/usr/sbin
7074
$(INSTALL_BIN) \
71-
$(PKG_INSTALL_DIR)/usr/sbin/{ubiattach,ubicrc32,ubiblock,ubidetach,ubiformat,ubimkvol} $(1)/usr/sbin/
75+
$(PKG_INSTALL_DIR)/usr/sbin/{ubiattach,ubicrc32,ubiblock,ubidetach,ubiformat,ubihealthd} $(1)/usr/sbin/
7276
$(INSTALL_BIN) \
73-
$(PKG_INSTALL_DIR)/usr/sbin/{ubinfo,ubinize,ubirename,ubirmvol,ubirsvol,ubiupdatevol} $(1)/usr/sbin/
77+
$(PKG_INSTALL_DIR)/usr/sbin/{ubimkvol,ubinfo,ubinize,ubirename,ubirmvol,ubirsvol,ubiupdatevol} $(1)/usr/sbin/
78+
$(INSTALL_DIR) $(1)/etc/init.d
79+
$(INSTALL_BIN) ./files/ubihealthd.init $(1)/etc/init.d/ubihealthd
80+
$(INSTALL_DIR) $(1)/etc/uci-defaults
81+
$(INSTALL_DATA) ./files/ubihealthd.defaults $(1)/etc/uci-defaults/ubihealthd
7482
endef
7583

7684
define Package/nand-utils/install
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
[ -e "/etc/config/ubihealthd" ] && exit 0
4+
[ ! -e "/sys/class/ubi" ] && exit 0
5+
6+
touch "/etc/config/ubihealthd"
7+
8+
for ubidev in /sys/class/ubi/*/total_eraseblocks; do
9+
ubidev="${ubidev%/*}"
10+
ubidev="${ubidev##*/}"
11+
uci batch <<EOF
12+
set ubihealthd.$ubidev=ubi-device
13+
set ubihealthd.$ubidev.device="/dev/$ubidev"
14+
set ubihealthd.$ubidev.enable=1
15+
EOF
16+
done
17+
18+
uci commit ubihealthd
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
START=99
4+
5+
USE_PROCD=1
6+
PROG=/usr/sbin/ubihealthd
7+
8+
ubihealthd_instance() {
9+
local cfg="$1"
10+
local device interval enable
11+
12+
config_get_bool enable "$cfg" "enable" 1
13+
[ "$enable" = "1" ] || return 0
14+
15+
config_get device "$cfg" "device"
16+
config_get interval "$cfg" "interval"
17+
18+
procd_open_instance
19+
procd_set_param command "$PROG" -f -d "$device"
20+
[ -n "$interval" ] && procd_append_param command -i "$interval"
21+
procd_close_instance
22+
}
23+
24+
start_service() {
25+
config_load ubihealthd
26+
config_foreach ubihealthd_instance ubi-device
27+
}

0 commit comments

Comments
 (0)