diff options
author | Jason M. Bills <jason.m.bills@linux.intel.com> | 2021-01-27 22:47:14 +0300 |
---|---|---|
committer | Jason M. Bills <jason.m.bills@linux.intel.com> | 2021-01-28 02:23:52 +0300 |
commit | 7c5f8839ec3d71a2170b8f3514a16a67c69d1c7c (patch) | |
tree | 729dbf87ba33bf4d83b5d95496ce18f99a61ef03 /meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts | |
parent | 98cc5cd6483975b64d80e8323f7f659dd1337d75 (diff) | |
download | openbmc-7c5f8839ec3d71a2170b8f3514a16a67c69d1c7c.tar.xz |
Update to internal 0.29
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Diffstat (limited to 'meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts')
-rw-r--r-- | meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts.bbappend | 4 | ||||
-rwxr-xr-x | meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts/init | 85 |
2 files changed, 48 insertions, 41 deletions
diff --git a/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts.bbappend b/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts.bbappend index dc22b3c95..410775ee3 100644 --- a/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts.bbappend +++ b/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts.bbappend @@ -1,3 +1,5 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" -SRC_URI = "file://init"
\ No newline at end of file +SRC_URI = "file://init" + +RDEPENDS_${PN} += "bash" diff --git a/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts/init b/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts/init index 5d83d85a6..245dabe6c 100755 --- a/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts/init +++ b/meta-openbmc-mods/meta-common/recipes-phosphor/preinit-mounts/preinit-mounts/init @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Copyright 2017-2019 Intel Corporation # @@ -19,8 +19,8 @@ # that can be made RW with an overlayfs log() { - [ -c /dev/kmsg ] && echo "init: $@" > /dev/kmsg - echo "init: $@" + [ -c /dev/kmsg ] && echo "init: $*" > /dev/kmsg + echo "init: $*" } # start with /proc and /tmp mounted @@ -38,8 +38,8 @@ if grep -q debug-init /proc/cmdline; then set -x env else - # silent bob - exec >/dev/null 2>&1 + # Suppress any stray output but we want to see any errors + exec >/dev/null 2>/dev/kmsg fi # list of things that need to be rw at boot @@ -47,7 +47,7 @@ NV_OVERLAYS="/etc /var /home" # place to mount the overlay backing store OVERLAY_MNT=/tmp/.overlay -OVERLAY_SIZE=16384 +# OVERLAY_SIZE=16384 # place to mount NV RWFS_MNT=/tmp/.rwfs # NV overlay storage @@ -63,26 +63,23 @@ mkdir -p "$OVERLAY_MNT" mtd_by_name() { local name="$1" - local mtd="/dev/$(grep "$name" /proc/mtd | cut -d : -f 1)" - echo "$mtd" + echo "/dev/$(grep "$name" /proc/mtd | cut -d : -f 1)" } mtdnum_by_name() { local name="$1" - local mtdnum="$(grep "$name" /proc/mtd | cut -c 4)" - echo "$mtdnum" + grep "$name" /proc/mtd | cut -c 4 } NV_MTD=rwfs -NV_MTD_DEV="$(mtd_by_name ${NV_MTD})" -NV_MTD_NUM="$(mtdnum_by_name ${NV_MTD})" nvrw() { local p="$1" # Clear the work dir doing overlay mount rm -rf "${OVERLAY_MNT}${p}.work" mkdir -p "${OVERLAY_MNT}${p}" "${OVERLAY_MNT}${p}.work" - local mname=$(echo "ol${p}" | sed 's,/,,g') + local mname + mname=$(echo "ol${p}" | sed 's,/,,g') local opts="lowerdir=${p},upperdir=${OVERLAY_MNT}${p},workdir=${OVERLAY_MNT}${p}.work,sync" mount -t overlay -o "$opts" "$mname" "$p" } @@ -91,8 +88,9 @@ targeted_clean() { log "restore-defaults: targeted_clean" # Do not delete FRU info, ssh/ssl certs, or machine-id ( - cd "${OVERLAY_SYNC}/etc" - find . ! -regex '.*\(/ssl\|/dropbear\|/machine-id\(_bkup\)\?\|/fru\).*' -exec rm -rf {} + + cd "${OVERLAY_SYNC}/etc" || exit + find . ! -regex '.*/\(ssl\|dropbear\|machine-id\|fru\).*' -a ! -path '.' \ + -exec rm -rf {} + ) # nothing should be in the workdir, but clear it just in case rm -rf "${OVERLAY_SYNC}/etc.work" @@ -116,48 +114,57 @@ full_clean() { sync } +jffs2_mount() { + mtd_name=$1 + mnt=$2 + mount -t jffs2 -o sync,ro mtd:"$mtd_name" "$mnt" +} + reformat_jffs2_partition() { local mtd_name="$1" local mnt="$2" # unmount the partition to reformat it umount -f "$mnt" - flash_eraseall "$(mtd_by_name ${mtd_name})" + flash_erase "$(mtd_by_name "$mtd_name")" 0 0 # remount the JFFS2 - mount -t jffs2 -o sync,ro mtd:"$mtd_name" "$mnt" - if [ $? -ne 0 ]; then + if ! jffs2_mount "$mtd_name" "$mnt"; then log "Failed to mount reformatted NV volume; system unstable" fi } clear_ubenv() { log "Clearing U-Boot environment" - flash_erase /dev/mtd/u-boot-env 0 0 + flash_erase "$(mtd_by_name u-boot-env)" 0 0 } # mount NV filesystem mkdir -p "$RWFS_MNT" -mount -t jffs2 -o sync,ro mtd:"$NV_MTD" "$RWFS_MNT" -if [ $? -ne 0 ]; then +if ! jffs2_mount "$NV_MTD" "$RWFS_MNT"; then log "Failed to mount NV volume; attempting recovery" reformat_jffs2_partition $NV_MTD $RWFS_MNT fi # check for full factory reset: if so, format $NV_MTD_DEV RESTORE_FLAG=$RWFS_MNT/.restore_op -restore_op=$(cat $RESTORE_FLAG) # read from NV -restore_op=${restore_op:-0} # set default value 0 -restore_op=$((restore_op & 3)) # mask off 2 bits -if [ $restore_op -eq 1 ]; then - targeted_clean -elif [ $restore_op -eq 2 ]; then - full_clean - clear_ubenv -elif [ $restore_op -eq 3 ]; then - log "restore-defaults: reformat" - reformat_jffs2_partition $NV_MTD $RWFS_MNT - clear_ubenv +if [ -f "$RESTORE_FLAG" ]; then + mount -o remount,rw "$RWFS_MNT" + restore_op=$(cat $RESTORE_FLAG) # read from NV + # set default value 0 if RESTORE_FLAG file was empty + restore_op=${restore_op:-0} + restore_op=$((restore_op & 3)) # mask off 2 bits + if [ $restore_op -eq 1 ]; then + targeted_clean + elif [ $restore_op -eq 2 ]; then + full_clean + clear_ubenv + elif [ $restore_op -eq 3 ]; then + log "restore-defaults: reformat" + reformat_jffs2_partition $NV_MTD $RWFS_MNT + clear_ubenv + fi + rm -f $RESTORE_FLAG + mount -o remount,ro "$RWFS_MNT" fi -rm -f $RESTORE_FLAG # Restore the overlay saved in the sync rsync -a --delete "${OVERLAY_SYNC}/" "${OVERLAY_MNT}" @@ -200,11 +207,9 @@ SOFS_MNT=/var/sofs if ! grep -q sofs /proc/mounts; then mkdir -p $SOFS_MNT SOFS_MTD=sofs - SOFS_MTD_NUM="$(mtdnum_by_name ${SOFS_MTD})" # mount a JFFS2 on the partition - mount -t jffs2 -o sync,ro mtd:"$SOFS_MTD" "$SOFS_MNT" - if [ $? -ne 0 ]; then + if ! jffs2_mount "$SOFS_MTD" "$SOFS_MNT"; then log "Failed to mount SOFS volume; attempting recovery" reformat_jffs2_partition $SOFS_MTD $SOFS_MNT fi @@ -242,12 +247,12 @@ pfr_write() { local PFR_ADDR=0x38 local reg=$1 local val=$2 - i2cset -y $PFR_BUS $PFR_ADDR $reg $val >&/dev/null + i2cset -y $PFR_BUS $PFR_ADDR "$reg" "$val" >&/dev/null } board_id=$(read_board_id) -if [ $board_id -eq $COOPER_CITY ]; then - if [ $(is_nl_node) -ne 0 ]; then +if [ "$board_id" -eq $COOPER_CITY ]; then + if [ "$(is_nl_node)" -ne 0 ]; then systemctl set-default multi-node-nl.target PFR_BMC_CHECKPOINT_REG=0xf PFR_BMC_CHECKPOINT_COMPLETE=0x9 |