[PATCH v3 3/6] obmc-{init, update}.sh: Cope with alternate RW FS types

Andrew Jeffery andrew at aj.id.au
Wed Feb 24 01:45:00 AEDT 2016


Busybox's blkid is a little hamstrung, requiring some processing of the
output to emulate what can be achieved with a couple of options with
blkid from util-linux.

Similar to findmtd(), the code for probe_fs_type() and blkid_fs_type()
is duplicated between obmc-{init,update}.sh. Some consideration should
be given to splitting out common functionality into well-defined
sourcable scripts.

Signed-off-by: Andrew Jeffery <andrew at aj.id.au>
---
 .../obmc-phosphor-initfs/files/obmc-init.sh            | 15 ++++++++++++++-
 .../obmc-phosphor-initfs/files/obmc-update.sh          | 18 +++++++++++++++---
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
index 9674765..1d268bb 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
@@ -30,6 +30,19 @@ findmtd() {
 	echo $m
 }
 
+blkid_fs_type() {
+	# Emulate util-linux's `blkid -s TYPE -o value $1`
+	blkid $1 \
+		| tr ' ' '\n' \
+		| awk -F= '/TYPE/ { print $2 }' \
+		| tr -d '"'
+}
+
+probe_fs_type() {
+	fst=$(blkid_fs_type $1)
+	echo ${fst:=jffs2}
+}
+
 debug_takeover() {
 	echo "$@"
 	test -n "$@" && echo Enter password to try to manually fix.
@@ -72,7 +85,7 @@ rodev=/dev/mtdblock${rofs#mtd}
 rwdev=/dev/mtdblock${rwfs#mtd}
 
 rofst=squashfs
-rwfst=ext4
+rwfst=$(probe_fs_type $rwdev)
 roopts=ro
 rwopts=rw
 
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
index face06d..cec4062 100755
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
@@ -35,10 +35,22 @@ findmtd() {
 	echo $m
 }
 
+blkid_fs_type() {
+	# Emulate util-linux's `blkid -s TYPE -o value $1`
+	blkid $1 \
+		| tr ' ' '\n' \
+		| awk -F= '/TYPE/ { print $2 }' \
+		| tr -d '"'
+}
+
+probe_fs_type() {
+	fst=$(blkid_fs_type $1)
+	echo ${fst:=jffs2}
+}
+
 rwfs=$(findmtd rwfs)
 
 rwdev=/dev/mtdblock${rwfs#mtd}
-rwfst=ext4
 rwopts=rw
 rorwopts=ro${rwopts#rw}
 
@@ -50,7 +62,7 @@ if test -n "$rwfs" && test -s whitelist
 then
 
 	mkdir -p $rwdir
-	mount $rwdev $rwdir -t $rwfst -o $rorwopts
+	mount $rwdev $rwdir -t $(probe_fs_type $rwdev) -o $rorwopts
 
 	while read f
 	do
@@ -87,7 +99,7 @@ done
 
 if test -d $save
 then
-	mount $rwdev $rwdir -t $rwfst -o $rwopts
+	mount $rwdev $rwdir -t $(probe_fs_type $rwdev) -o $rwopts
 	cp -rp $save/. $upper/
 	umount $rwdir
 fi
-- 
2.5.0



More information about the openbmc mailing list