summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Williams <patrick@stwcx.xyz>2016-07-01 13:25:08 -0500
committerGitHub <noreply@github.com>2016-07-01 13:25:08 -0500
commit0c66833d9608634af803b27c61258411c0296f68 (patch)
tree8f7dd9359aaea064ae096b18cb6f59de739abdc8
parentf09d4b2ecf0ad6305d73a609b5c58027def1b0d7 (diff)
parentc2686a95efe991c0c7dfaffaaf6b2834df9bed86 (diff)
downloadtalos-openbmc-0c66833d9608634af803b27c61258411c0296f68.tar.gz
talos-openbmc-0c66833d9608634af803b27c61258411c0296f68.zip
Merge pull request #451 from mdmillerii/runtime-update-1
Update flash update to be useable at runtime for v1.0-stable
-rw-r--r--meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass20
-rw-r--r--meta-phosphor/classes/obmc-phosphor-initfs.bbclass4
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh12
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh8
-rwxr-xr-xmeta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh165
-rw-r--r--meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/whitelist2
-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)6
7 files changed, 166 insertions, 51 deletions
diff --git a/meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass b/meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass
index adb86e06d..dd990bc5e 100644
--- a/meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass
+++ b/meta-phosphor/classes/obmc-phosphor-image_types_uboot.bbclass
@@ -51,6 +51,8 @@ do_generate_flash() {
uinitrd="${initrd}.u-boot"
rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}"
rwfs="rwfs.${OVERLAY_BASETYPE}"
+ rofsimg=rofs.${IMAGE_BASETYPE}.cpio
+ netimg=initramfs-netboot.cpio
if [ ! -f $ddir/$kernel ]; then
bbfatal "Kernel file ${ddir}/${kernel} does not exist"
@@ -76,11 +78,11 @@ do_generate_flash() {
dst="${ddir}/${FLASH_IMAGE_NAME}"
rm -rf $dst
mk_nor_image ${dst} ${FLASH_SIZE}
- dd if=${ddir}/${uboot} of=${dst} bs=1k seek=${FLASH_UBOOT_OFFSET}
- dd if=${ddir}/${kernel} of=${dst} bs=1k seek=${FLASH_KERNEL_OFFSET}
- dd if=${ddir}/${uinitrd} of=${dst} bs=1k seek=${FLASH_INITRD_OFFSET}
- dd if=${ddir}/${rootfs} of=${dst} bs=1k seek=${FLASH_ROFS_OFFSET}
- dd if=${ddir}/${rwfs} of=${dst} bs=1k seek=${FLASH_RWFS_OFFSET}
+ dd if=${ddir}/${uboot} of=${dst} bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET}
+ dd if=${ddir}/${kernel} of=${dst} bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET}
+ dd if=${ddir}/${uinitrd} of=${dst} bs=1k conv=notrunc seek=${FLASH_INITRD_OFFSET}
+ dd if=${ddir}/${rootfs} of=${dst} bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET}
+ dd if=${ddir}/${rwfs} of=${dst} bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET}
dstlink="${ddir}/${FLASH_IMAGE_LINK}"
rm -rf $dstlink
ln -sf ${FLASH_IMAGE_NAME} $dstlink
@@ -94,4 +96,12 @@ do_generate_flash() {
tar -h -cvf ${ddir}/${MACHINE}-${DATETIME}.all.tar -C ${ddir} image-bmc
tar -h -cvf ${ddir}/${MACHINE}-${DATETIME}.tar -C ${ddir} image-u-boot image-kernel image-initramfs image-rofs image-rwfs
+
+ # Package the root image (rofs layer) with the initramfs for net booting.
+ # Uses the symlink above to get the desired name in the cpio
+ ( cd $ddir && echo image-rofs | cpio -oHnewc -L > ${rofsimg} )
+ # Prepend the rofs cpio -- being uncompressed it must be 4-byte aligned
+ cat ${ddir}/${rofsimg} ${ddir}/${initrd} > ${ddir}/${netimg}
+ oe_mkimage "${netimg}" "${INITRD_CTYPE}"
+
}
diff --git a/meta-phosphor/classes/obmc-phosphor-initfs.bbclass b/meta-phosphor/classes/obmc-phosphor-initfs.bbclass
deleted file mode 100644
index de7923e82..000000000
--- a/meta-phosphor/classes/obmc-phosphor-initfs.bbclass
+++ /dev/null
@@ -1,4 +0,0 @@
-# Common code for recipes that implement Phosphor OpenBMC filesystem
-
-RPROVIDES_${PN} += "obmc-phosphor-initfs"
-PROVIDES += "obmc-phosphor-initfs"
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 c37b3d53d..1f54d392f 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
@@ -18,7 +18,7 @@ fi
mkdir -p $rodir $rwdir
-cp -rp init shutdown update whitelist bin sbin usr lib etc var run/initramfs
+cp -rp init shutdown update whitelist.d bin sbin usr lib etc var run/initramfs
# To start a interactive shell with job control at this point, run
# getty 38400 ttyS4
@@ -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 8d5d0c983..8d5c6726c 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 aa8fd8934..b061e262f 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
+whitelist=/run/initramfs/whitelist.d/
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,14 +173,27 @@ 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%/*}/"
- done < $whitelist
+ cp -rp "$upper/$f" "${d%/*}/"
+ done << HERE
+$(grep -v ^# $whitelist*)
+HERE
if test -n "$mounted"
then
@@ -124,30 +201,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 +274,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 603cec7e4..c35a552c7 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 3fa88c9e6..70b668699 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"
@@ -22,10 +21,11 @@ do_install() {
install -m 0755 ${WORKDIR}/obmc-init.sh ${D}/init
install -m 0755 ${WORKDIR}/obmc-shutdown.sh ${D}/shutdown
install -m 0755 ${WORKDIR}/obmc-update.sh ${D}/update
- install -m 0644 ${WORKDIR}/whitelist ${D}/whitelist
+ install -d ${D}/whitelist.d
+ install -m 0644 ${WORKDIR}/whitelist ${D}/whitelist.d/whitelist
install -d ${D}/dev
mknod -m 622 ${D}/dev/console c 5 1
}
-FILES_${PN} += " /init /shutdown /update /whitelist /dev "
+FILES_${PN} += " /init /shutdown /update /whitelist.d/whitelist /dev "
FILES_${PN} += " /init-options /init-download-url "
OpenPOWER on IntegriCloud