diff options
author | Isaac Kurth <isaac.kurth@ibm.com> | 2021-09-08 01:04:14 +0300 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2021-10-05 21:50:59 +0300 |
commit | 5003195bc9939995fd9be199aa752e9ba5f4cbb6 (patch) | |
tree | f1f59de4884af59cf859791519e63ad5e7041687 /meta-phosphor/recipes-phosphor/initrdscripts | |
parent | 14d29c2fdfacccdba4622faf159c573466bd0b7c (diff) | |
download | openbmc-5003195bc9939995fd9be199aa752e9ba5f4cbb6.tar.xz |
mmc-init: Enable factory reset from gpio change
The factory-reset-toggle GPIO can have its state changed by physically
toggling SWITCH_RESET_N. If this GPIO is in a different state than it
was during the last boot, it triggers a BMC factory reset.
Tested: Added extra files to /var. Verified that a reset from a
physical toggle caused these files to be removed. Verified that resets
from the REST API and from setting rwreset to true still function
properly. Verified that repeated rebooting without calling for a reset
does not inadvertently trigger a reset.
Signed-off-by: Isaac Kurth <isaac.kurth@ibm.com>
Change-Id: I3cf3f9519033db240c0db2eec35a5b09b8fefdf2
Diffstat (limited to 'meta-phosphor/recipes-phosphor/initrdscripts')
-rw-r--r-- | meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb | 1 | ||||
-rw-r--r-- | meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh | 25 |
2 files changed, 21 insertions, 5 deletions
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb index 88807c0f01..96c27da12b 100644 --- a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb +++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb @@ -13,6 +13,7 @@ RDEPENDS:${PN} += " \ e2fsprogs-e2fsck \ e2fsprogs-mke2fs \ gptfdisk \ + libgpiod-tools \ parted \ udev \ " diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh index 575b7605aa..ad9748e651 100644 --- a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh +++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh @@ -10,6 +10,9 @@ get_root() { fslist="proc sys dev run" rodir=/mnt/rofs +mmcdev="/dev/mmcblk0" +rwfsdev="/dev/disk/by-partlabel/rwfs" + cd / mkdir -p $fslist mount dev dev -tdevtmpfs @@ -19,7 +22,6 @@ mount tmpfs run -t tmpfs -o mode=755,nodev # Wait up to 5s for the mmc device to appear. Continue even if the count is # exceeded. A failure will be caught later like in the mount command. -mmcdev="/dev/mmcblk0" count=0 while [ $count -lt 5 ]; do if [ -e "${mmcdev}" ]; then @@ -48,16 +50,29 @@ if ! mount /dev/disk/by-partlabel/"$(get_root)" $rodir -t ext4 -o ro; then /bin/sh fi -rwfsdev="/dev/disk/by-partlabel/rwfs" +# Determine if a factory reset has been requested mkdir -p /var/lock -if test $(fw_printenv -n rwreset) = "true"; then +resetval=$(fw_printenv -n rwreset 2>/dev/null) +gpiopresent=$(gpiofind factory-reset-toggle) +if [ $? -eq 0 ]; then + gpioval=$(gpioget $gpiopresent) +else + gpioval="" +fi +# Prevent unnecessary resets on first boot +if [ -n "$gpioval" -a -z "$resetval" ]; then + fw_setenv rwreset $gpioval + resetval=$gpioval +fi +if [ "$resetval" = "true" -o -n "$gpioval" -a "$resetval" != "$gpioval" ]; then echo "Factory reset requested." if ! mkfs.ext4 -F "${rwfsdev}"; then echo "Reformat for factory reset failed." /bin/sh else - fw_setenv rwreset - echo "Formatting of rwfs is complete." + # gpioval will be an empty string if factory-reset-toggle was not found + fw_setenv rwreset $gpioval + echo "rwfs has been formatted." fi fi |