All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH openbmc v2 0/7] Update flash update to be useable at runtime.
@ 2016-05-26  0:30 OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 1/7] initfs: shutdown: comment on update success OpenBMC Patches
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

The underlying storage for a file system can not be updated when it is in use.  The initial solution was to update the flash as the system was being shutdown, with output to the console.

Updates were made to the init script that allows the flash to not be used for a given boot but the update script was not enhanced to make this user friendly, and no documentation was provided to prepare the system for this mode.

This series partially addresses #293 by enhancing the update script to 
1. provide more fine grained checks on update conflicts
2. provide additional checks that would cause failures
3. allow the flash to be updated at runtime if the in-use image is not in flash.

I anticipate adding options to allow init to have some options in the initramfs and get further from the command line.

This series is still in RFC state and has not been tested.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/openbmc/openbmc/297)
<!-- Reviewable:end -->


https://github.com/openbmc/openbmc/pull/297

Milton D. Miller II (7):
  initfs: shutdown: comment on update success
  initfs: update: Don't exec sh or sulogin on error just exit 1
  initfs: update: no error if no files to copy to ram
  initfs: update: add option to perform checks but skip actual update
  initfs: update: check individual mtd partitions for mounts
  initfs: update: add check for image size vs mtd size
  initfs: init: add file for base options

 .../obmc-phosphor-initfs/files/obmc-init.sh        |  10 +-
 .../obmc-phosphor-initfs/files/obmc-shutdown.sh    |   8 ++
 .../obmc-phosphor-initfs/files/obmc-update.sh      | 109 +++++++++++++++------
 3 files changed, 96 insertions(+), 31 deletions(-)

-- 
2.8.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH openbmc v2 1/7] initfs: shutdown: comment on update success
  2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
@ 2016-05-26  0:30 ` OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 2/7] initfs: update: Don't exec sh or sulogin on error just exit 1 OpenBMC Patches
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

From: "Milton D. Miller II" <miltonm@us.ibm.com>

Print an error from the shutdown script when the update fails.

Update is changing to return codes when its preconditions are not
met, so be more verbose about its success to provide a means to
debug flash updates not occurring.

We could add a sulogin or sushell but its not clear what would be
desired here.  If so the message should include "rmdir /oldroot
to get a PID 1 shell" like /takever works in init.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh  | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
index 8d5d0c9..8d5c672 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
@@ -44,6 +44,14 @@ then
 	if test -x $update
 	then
 		$update --clean-saved-files
+		remaining=$(ls $image*)
+		if test -n "$remaining"
+		then
+			echo 1>&2 "Flash update failed to flash these images:"
+			echo 1>&2 "$remaining"
+		else
+			echo "Flash update completed."
+		fi
 	else
 		echo 1>&2 "Flash update requested but $update program missing!"
 	fi
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH openbmc v2 2/7] initfs: update: Don't exec sh or sulogin on error just exit 1
  2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 1/7] initfs: shutdown: comment on update success OpenBMC Patches
@ 2016-05-26  0:30 ` OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 3/7] initfs: update: no error if no files to copy to ram OpenBMC Patches
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

From: "Milton D. Miller II" <miltonm@us.ibm.com>

When update was written it was exec'd from the shutdown script
and hence took over pid 1.  Since exiting in that environment was
a panic situation, the script instead started a rescue shell with
its output presumably on the console.

The calling convention was updated to be a simple call to the shell
script in dbacf104885c3bf78c5f3e06f63bba6db0742e4b but the error
handling was not updated.  That error handling is now becoming
a hinderance to use from additional environments so change it.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-update.sh      | 23 ++++++----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

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 aa8fd89..f8e551c 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
@@ -2,9 +2,6 @@
 
 echo update: "$@"
 
-export PS1=update-sh#\ 
-# exec /bin/sh
-
 cd /
 if ! test -r /proc/mounts || ! test -f /proc/mounts
 then
@@ -21,12 +18,12 @@ then
 	mkdir -p /dev
 	mount -t devtmpfs dev dev
 fi
-while grep mtd /proc/mounts
-do
+
+if grep mtd /proc/mounts
+then
 	echo 1>&2 "Error: A mtd device is mounted."
-	sulogin
-	# exec /bin/sh
-done
+	exit 1
+fi
 
 findmtd() {
 	m=$(grep -xl "$1" /sys/class/mtd/*/name)
@@ -130,7 +127,7 @@ do
 	if test -z "$m"
 	then
 		echo 1>&2  "Unable to find mtd partiton for ${f##*/}."
-		exec /bin/sh
+		exit 1
 	fi
 done
 
@@ -173,11 +170,3 @@ then
 fi
 
 exit
-
-# NOT REACHED without edit
-# NOT REACHED without edit
-
-echo "Flash completed.  Inspect, cleanup and reboot -f to continue."
-
-export PS1=update-sh#\ 
-exec /bin/sh
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH openbmc v2 3/7] initfs: update: no error if no files to copy to ram
  2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 1/7] initfs: shutdown: comment on update success OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 2/7] initfs: update: Don't exec sh or sulogin on error just exit 1 OpenBMC Patches
@ 2016-05-26  0:30 ` OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 4/7] initfs: update: add option to perform checks but skip actual update OpenBMC Patches
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

From: "Milton D. Miller II" <miltonm@us.ibm.com>

If the saved files directory is empty because there were no files in
the read-write overlay file system that were in the persistent file
list, then the save directory will not exist, so skip copying the
non-existant directory in that case.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 f8e551c..f0ca989 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
@@ -144,7 +144,7 @@ do
 	flashcp -v $f /dev/$m && rm $f
 done
 
-if test "x$toram" = xy
+if test -d $save -a "x$toram" = xy
 then
 	mkdir -p $upper
 	cp -rp $save/. $upper/
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH openbmc v2 4/7] initfs: update: add option to perform checks but skip actual update
  2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
                   ` (2 preceding siblings ...)
  2016-05-26  0:30 ` [PATCH openbmc v2 3/7] initfs: update: no error if no files to copy to ram OpenBMC Patches
@ 2016-05-26  0:30 ` OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 5/7] initfs: update: check individual mtd partitions for mounts OpenBMC Patches
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

From: "Milton D. Miller II" <miltonm@us.ibm.com>

Provide a way to check if update is likely to succeed without
attempting actual updates.

This will check the image names correspond to mtd partition names,
and will be enhanced with additional checking for file size and
individual partition mounts.

This is not called --dry-run because it will still do file save
and restore if those are enabled.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-update.sh      | 31 +++++++++++++---------
 1 file changed, 19 insertions(+), 12 deletions(-)

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 f0ca989..fc47062 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
@@ -57,6 +57,7 @@ upper=$rwdir/cow
 save=/run/save/${upper##*/}
 
 mounted=
+doflash=y
 doclean=
 dosave=y
 dorestore=y
@@ -86,6 +87,9 @@ do
 	--restore-files)
 		dorestore=y
 		shift ;;
+	--no-flash)
+		doflash=
+		shift ;;
 	--copy-files)
 		toram=y
 		shift ;;
@@ -131,18 +135,21 @@ do
 	fi
 done
 
-for f in $image*
-do
-	if test ! -s $f
-	then
-		echo "Skipping empty update of ${f#$image}."
-		rm $f
-		continue
-	fi
-	m=$(findmtd ${f#$image})
-	echo "Updating ${f#$image}..."
-	flashcp -v $f /dev/$m && rm $f
-done
+if test -n "$doflash"
+then
+	for f in $image*
+	do
+		if test ! -s $f
+		then
+			echo "Skipping empty update of ${f#$image}."
+			rm $f
+			continue
+		fi
+		m=$(findmtd ${f#$image})
+		echo "Updating ${f#$image}..."
+		flashcp -v $f /dev/$m && rm $f
+	done
+fi
 
 if test -d $save -a "x$toram" = xy
 then
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH openbmc v2 5/7] initfs: update: check individual mtd partitions for mounts
  2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
                   ` (3 preceding siblings ...)
  2016-05-26  0:30 ` [PATCH openbmc v2 4/7] initfs: update: add option to perform checks but skip actual update OpenBMC Patches
@ 2016-05-26  0:30 ` OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 6/7] initfs: update: add check for image size vs mtd size OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 7/7] initfs: init: add file for base options OpenBMC Patches
  6 siblings, 0 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

From: "Milton D. Miller II" <miltonm@us.ibm.com>

Instead of checking for any mtd device, only check mtd devices that are
to be updated.  Include child mtd devices when looking for mounted
filesystems.

If this check is suppressed flash updates are suppressed.
This may be useful to check deferred updates.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-update.sh      | 46 +++++++++++++++++++---
 1 file changed, 41 insertions(+), 5 deletions(-)

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 fc47062..09348b6 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
@@ -19,11 +19,34 @@ then
 	mount -t devtmpfs dev dev
 fi
 
-if grep mtd /proc/mounts
-then
-	echo 1>&2 "Error: A mtd device is mounted."
-	exit 1
-fi
+# mtd number N with mtd name Name can be mounted via mtdN, or mtd:Name (with
+# an mtd aware fs) or by /dev/mtdblockN (with a mtd or block fs). 
+mtdismounted() {
+	m=${1##mtd}
+	if grep -s "mtdblock$m" /proc/mounts || grep -s "mtd$m" /proc/mounts
+	then
+		return 0
+	fi
+	n=$(cat /sys/class/mtd/mtd$m/name)
+	if test -n "$n" && grep -s "mtd:$n" /proc/mounts
+	then
+		return 0
+	fi
+	return 1
+}
+
+# We need to detect child partitions when the whole flash is to be updated
+# ignore mtdNro and mtdblockN names in the class subsystem directory
+childmtds() {
+	for m in /sys/class/mtd/$1/mtd*
+	do
+		m=${m##*/}
+		if test "${m%ro}" = "${m#mtdblock}"
+		then
+			echo $m
+		fi
+	done
+}
 
 findmtd() {
 	m=$(grep -xl "$1" /sys/class/mtd/*/name)
@@ -62,6 +85,7 @@ doclean=
 dosave=y
 dorestore=y
 toram=
+checkmount=y
 
 whitelist=/run/initramfs/whitelist
 image=/run/initramfs/image-
@@ -90,6 +114,10 @@ do
 	--no-flash)
 		doflash=
 		shift ;;
+	--ignore-mount)
+		checkmount=
+		doflash=
+		shift ;;
 	--copy-files)
 		toram=y
 		shift ;;
@@ -133,6 +161,14 @@ do
 		echo 1>&2  "Unable to find mtd partiton for ${f##*/}."
 		exit 1
 	fi
+	for s in $m $(childmtds $m)
+	do
+		if test -n "$checkmount" && mtdismounted $s
+		then
+			echo 1>&2 "Device $s is mounted, ${f##*/} is busy."
+			exit 1
+		fi
+	done
 done
 
 if test -n "$doflash"
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH openbmc v2 6/7] initfs: update: add check for image size vs mtd size
  2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
                   ` (4 preceding siblings ...)
  2016-05-26  0:30 ` [PATCH openbmc v2 5/7] initfs: update: check individual mtd partitions for mounts OpenBMC Patches
@ 2016-05-26  0:30 ` OpenBMC Patches
  2016-05-26  0:30 ` [PATCH openbmc v2 7/7] initfs: init: add file for base options OpenBMC Patches
  6 siblings, 0 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

From: "Milton D. Miller II" <miltonm@us.ibm.com>

The flashcp command will check the file size vs the partition size,
so add a check when looking at images.

Use stat -L -c "%s" to get the file size, and compare it to the mtd
size from the sysfs size attribute.

If this check is suppressed the enforcement is left to flashcp.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-update.sh           | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

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 09348b6..7344438 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
@@ -48,6 +48,14 @@ childmtds() {
 	done
 }
 
+toobig() {
+	if test $(stat -L -c "%s" "$1") -gt $(cat /sys/class/mtd/"$2"/size)
+	then
+		return 0
+	fi
+	return 1
+}
+
 findmtd() {
 	m=$(grep -xl "$1" /sys/class/mtd/*/name)
 	m=${m%/name}
@@ -85,6 +93,7 @@ doclean=
 dosave=y
 dorestore=y
 toram=
+checksize=y
 checkmount=y
 
 whitelist=/run/initramfs/whitelist
@@ -114,6 +123,9 @@ do
 	--no-flash)
 		doflash=
 		shift ;;
+	--ignore-size)
+		checksize=
+		shift ;;
 	--ignore-mount)
 		checkmount=
 		doflash=
@@ -161,6 +173,11 @@ do
 		echo 1>&2  "Unable to find mtd partiton for ${f##*/}."
 		exit 1
 	fi
+	if test -n "$checksize" && toobig "$f" "$m"
+	then
+		echo 1>&1 "Image ${f##*/} too big for $m."
+		exit 1
+	fi
 	for s in $m $(childmtds $m)
 	do
 		if test -n "$checkmount" && mtdismounted $s
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH openbmc v2 7/7] initfs: init: add file for base options
  2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
                   ` (5 preceding siblings ...)
  2016-05-26  0:30 ` [PATCH openbmc v2 6/7] initfs: update: add check for image size vs mtd size OpenBMC Patches
@ 2016-05-26  0:30 ` OpenBMC Patches
  6 siblings, 0 replies; 8+ messages in thread
From: OpenBMC Patches @ 2016-05-26  0:30 UTC (permalink / raw)
  To: openbmc

From: "Milton D. Miller II" <miltonm@us.ibm.com>

Allow an initrd image to include options for init while still allowing
additional options to come from the kernel command line and/or u-boot
environment variables.

This will allow building a netboot image that can specify to run
from ram while allowing the command line to initiate debug or skip
copying files from the read-write overlay file system.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh   | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

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 c37b3d5..70af93d 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
@@ -184,6 +184,7 @@ fsckbase=/sbin/fsck.
 fsck=$fsckbase$rwfst
 fsckopts=-a
 optfile=/run/initramfs/init-options
+optbase=/run/initramfs/init-options-base
 urlfile=/run/initramfs/init-download-url
 update=/run/initramfs/update
 
@@ -192,9 +193,16 @@ then
 	cp /${optfile##*/} $optfile
 fi
 
+if test -e /${optbase##*/}
+then
+	cp /${optbase##*/} $optbase
+else
+	touch $optbase
+fi
+
 if test ! -f $optfile
 then
-	cat /proc/cmdline > $optfile
+	cat /proc/cmdline $optbase > $optfile
 	get_fw_env_var openbmcinit >> $optfile
 	get_fw_env_var openbmconce >> $optfile
 fi
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-26  0:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-26  0:30 [PATCH openbmc v2 0/7] Update flash update to be useable at runtime OpenBMC Patches
2016-05-26  0:30 ` [PATCH openbmc v2 1/7] initfs: shutdown: comment on update success OpenBMC Patches
2016-05-26  0:30 ` [PATCH openbmc v2 2/7] initfs: update: Don't exec sh or sulogin on error just exit 1 OpenBMC Patches
2016-05-26  0:30 ` [PATCH openbmc v2 3/7] initfs: update: no error if no files to copy to ram OpenBMC Patches
2016-05-26  0:30 ` [PATCH openbmc v2 4/7] initfs: update: add option to perform checks but skip actual update OpenBMC Patches
2016-05-26  0:30 ` [PATCH openbmc v2 5/7] initfs: update: check individual mtd partitions for mounts OpenBMC Patches
2016-05-26  0:30 ` [PATCH openbmc v2 6/7] initfs: update: add check for image size vs mtd size OpenBMC Patches
2016-05-26  0:30 ` [PATCH openbmc v2 7/7] initfs: init: add file for base options OpenBMC Patches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.