diff options
author | Patrick Williams <patrick@stwcx.xyz> | 2016-07-05 21:11:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-05 21:11:27 +0300 |
commit | 66859fe4b5a21319cfef9ec3e23334c6769bdd59 (patch) | |
tree | ef73967efcb5fe9b8d96cad408cd2418a8bb7854 /meta-phosphor/common | |
parent | 8d43aeeb29505f4f787d2296929a51eb69f65859 (diff) | |
parent | a6e6d0ce143b8476281672f7e859f451fc525270 (diff) | |
download | openbmc-66859fe4b5a21319cfef9ec3e23334c6769bdd59.tar.xz |
Merge pull request #297 from mdmillerii/runtime-update
Update flash update to be useable at runtime.
Diffstat (limited to 'meta-phosphor/common')
-rw-r--r-- | meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh | 10 | ||||
-rw-r--r-- | meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh | 8 | ||||
-rwxr-xr-x | meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh | 159 | ||||
-rw-r--r-- | meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/whitelist | 2 | ||||
-rw-r--r-- | meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/obmc-phosphor-initfs.bb (renamed from meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/obmc-phosphor-init.bb) | 1 |
5 files changed, 143 insertions, 37 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 c37b3d53d6..70af93d991 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 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 8d5d0c983c..8d5c6726c9 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 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 aa8fd8934f..f0c41a74c0 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,8 +2,9 @@ echo update: "$@" -export PS1=update-sh#\ -# exec /bin/sh +echoerr() { + echo 1>&2 "ERROR: $@" +} cd / if ! test -r /proc/mounts || ! test -f /proc/mounts @@ -21,12 +22,43 @@ then mkdir -p /dev mount -t devtmpfs dev dev fi -while grep mtd /proc/mounts -do - echo 1>&2 "Error: A mtd device is mounted." - sulogin - # exec /bin/sh -done + +# mtd number N with mtd name Name can be mounted via mtdN, or mtd:Name +# (with a 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 +} + +# 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 +} + +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) @@ -60,17 +92,39 @@ upper=$rwdir/cow save=/run/save/${upper##*/} mounted= +doflash=y doclean= dosave=y dorestore=y toram= +checksize=y +checkmount=y whitelist=/run/initramfs/whitelist image=/run/initramfs/image- +imglist= while test "$1" != "${1#-}" do case "$1" in + --help) + cat <<HERE +Usage: $0 [options] -- Write images in /run/initramfs to flash (/dev/mtd*) + --help Show this message + --no-flash Don't attempt to write images to flash + --ignore-size Don't compare image size to mtd device size + --ignore-mount Don't check if destination is mounted + --save-files Copy whitelisted files to save directory in RAM + --no-save-files Don't copy whitelisted files to save directory + --copy-files Copy files from save directory to rwfs mountpoint + --restore-files Restore files from save directory to rwfs layer + --no-restore-files Don't restore saved files from ram to rwfs layer + --clean-saved-files Delete saved whitelisted files from RAM + --no-clean-saved-files Retain saved whitelisted files in RAM +HERE + + exit 0 ;; + --no-clean-saved-files) doclean= shift ;; @@ -89,11 +143,21 @@ do --restore-files) dorestore=y shift ;; + --no-flash) + doflash= + shift ;; + --ignore-size) + checksize= + shift ;; + --ignore-mount) + checkmount= + doflash= + shift ;; --copy-files) toram=y shift ;; *) - echo 2>&1 "Unknown option $1" + echoerr "Unknown option $1. Try $0 --help." exit 1 ;; esac done @@ -109,13 +173,24 @@ then while read f do - if ! test -e $upper/$f + # Entries shall start with /, no trailing /.. or embedded /../ + if test "/${f#/}" != "$f" -o "${f%/..}" != "${f#*/../}" + then + echo 1>&2 "WARNING: Skipping bad whitelist entry $f." + continue + fi + if ! test -e "$upper/$f" then continue fi d="$save/$f" + while test "${d%/}" != "${d%/.}" + do + d="${d%/.}" + d="${d%/}" + done mkdir -p "${d%/*}" - cp -rp $upper/$f "${d%/*}/" + cp -rp "$upper/$f" "${d%/*}/" done < $whitelist if test -n "$mounted" @@ -124,30 +199,54 @@ then fi fi -for f in $image* +imglist=$(echo $image*) +if test "$imglist" = "$image*" -a ! -e "$imglist" +then + # shell didn't expand the wildcard, so no files exist + echo "No images found to update." + imglist= +fi + +for f in $imglist do m=$(findmtd ${f#$image}) if test -z "$m" then - echo 1>&2 "Unable to find mtd partiton for ${f##*/}." - exec /bin/sh + echoerr "Unable to find mtd partiton for ${f##*/}." + exit 1 fi -done - -for f in $image* -do - if test ! -s $f + if test -n "$checksize" && toobig "$f" "$m" then - echo "Skipping empty update of ${f#$image}." - rm $f - continue + echoerr "Image ${f##*/} too big for $m." + exit 1 fi - m=$(findmtd ${f#$image}) - echo "Updating ${f#$image}..." - flashcp -v $f /dev/$m && rm $f + for s in $m $(childmtds $m) + do + if test -n "$checkmount" && mtdismounted $s + then + echoerr "Device $s is mounted, ${f##*/} is busy." + exit 1 + fi + done done -if test "x$toram" = xy +if test -n "$doflash" +then + for f in $imglist + 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 mkdir -p $upper cp -rp $save/. $upper/ @@ -173,11 +272,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 diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/whitelist b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/whitelist index 603cec7e46..c35a552c7b 100644 --- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/whitelist +++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/whitelist @@ -6,4 +6,4 @@ /etc/group /etc/shadow /etc/gshadow -/var/lib/obmc/events/ +/var/lib/obmc/events diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/obmc-phosphor-init.bb b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/obmc-phosphor-initfs.bb index 3fa88c9e66..f81e21dd12 100644 --- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/obmc-phosphor-init.bb +++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/obmc-phosphor-initfs.bb @@ -3,7 +3,6 @@ DESCRIPTION = "Phosphor OpenBMC filesytem mount reference implementation." PR = "r1" inherit obmc-phosphor-license -inherit obmc-phosphor-initfs S = "${WORKDIR}" SRC_URI += "file://obmc-init.sh" |