diff options
author | Craig Hesling <hesling@chromium.org> | 2021-05-22 16:33:05 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-27 04:30:02 +0000 |
commit | dc3b6b1275095f48293b7fa8205fa66b12970576 (patch) | |
tree | 1bf6a9a094b28fb83268dc0debfc960bf3256576 /util/flash_fp_mcu | |
parent | 29731f37cf08c57d0e967c5e1a4af3c41b0f3f26 (diff) | |
download | chrome-ec-dc3b6b1275095f48293b7fa8205fa66b12970576.tar.gz |
flash_fp_mcu: Add warnings for conflicting processes
BRANCH=none
BUG=b:188985272 b:181635081
TEST=# Run with biod start on helios
scp util/flash_fp_mcu root@${DUT}:/usr/local/bin/flash_fp_mcu
flash_fp_mcu --hello
# Ensure warning triggered.
stop biod
stop timberslide LOG_PATH=/sys/kernel/debug/cros_fp/console_log
flash_fp_mcu --hello
# Ensure no warnings are shown
echo spi-PRP0001:02 >/sys/bus/spi/drivers/cros-ec-spi/unbind
flash_fp_mcu --hello
# Ensure the warning about cros-ec driver not being bound was
# emitted
# Bind raw driver and hold it open
echo spi-PRP0001:02 >/sys/bus/spi/drivers/cros-ec-spi/unbind
echo spidev >/sys/bus/spi/devices/spi-PRP0001\:02/driver_override
echo spi-PRP0001:02 >/sys/bus/spi/drivers/spidev/bind
exec 10<>/dev/spidev1.1
flash_fp_mcu --hello
# Ensure warnings about cros-ec bound + raw bound + raw file open
# are emitted.
Change-Id: I1dded083ad158307ec54866952cf3ed59f30caf5
Signed-off-by: Craig Hesling <hesling@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2912371
Diffstat (limited to 'util/flash_fp_mcu')
-rw-r--r-- | util/flash_fp_mcu | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/util/flash_fp_mcu b/util/flash_fp_mcu index f703b6001d..ef67677d82 100644 --- a/util/flash_fp_mcu +++ b/util/flash_fp_mcu @@ -202,6 +202,28 @@ get_default_fw() { echo "${fws[0]}" } +# Find processes that have the named file, active or deleted, open. +# +# Deleted files are important because unbinding/rebinding cros-ec +# with biod/timberslide running will result in the processes holding open +# a deleted version of the files. Issues can arise if the process continue +# to interact with the deleted files (ex kernel panic) while the raw driver +# is being used in flash_fp_mcu. The lsof and fuser tools can't seem to +# identify usages of the deleted named file directly, without listing all +# files. This takes a large amount out time on Chromebooks, thus we need this +# custom search routine. +# +# Usage: proc_open_file [file_pattern] +proc_open_file() { + local file_pattern="$1" + + # Avoid overloading kernel max arguments with the number of file names. + local -a FDS=( /proc/*/fd/* ) + xargs ls -l <<<"${FDS[*]}" 2>/dev/null | grep "${file_pattern}" | \ + awk '{split($9,p,"/"); print "PID", p[3], "->", $11, $12}' + return "${PIPESTATUS[1]}" +} + flash_fp_mcu_stm32() { local transport="${1}" local device="${2}" @@ -552,6 +574,35 @@ main() { exit "${EXIT_CONFIG}" fi + # If cros-ec driver isn't bound on startup, this means the final rebinding + # may fail. + if [[ ! -c "/dev/cros_fp" ]]; then + echo "WARNING: The cros-ec driver was not bound on startup." >&2 + fi + if [[ -c "${DEVICE}" ]]; then + echo "WARNING: The raw driver was bound on startup." >&2 + fi + local files_open + # Ensure no processes have cros_fp device or debug device open. + # This might be biod and/or timberslide. + if files_open=$(proc_open_file "/dev/cros_fp\|/sys/kernel/debug/cros_fp/*") + then + echo "WARNING: Another process has a cros_fp device file open." >&2 + echo "${files_open}" >&2 + echo "Try 'stop biod' and" >&2 + echo "'stop timberslide LOG_PATH=/sys/kernel/debug/cros_fp/console_log'" >&2 + echo "before running this script." >&2 + echo "See b/188985272." >&2 + fi + # Ensure no processes are using the raw driver. This might be a wedged + # stm32mon process spawned by this script. + if files_open=$(proc_open_file "${DEVICE}"); then + echo "WARNING: Another process has ${DEVICE} open." >&2 + echo "${files_open}" >&2 + echo "Try 'fuser -k ${DEVICE}' before running this script." >&2 + echo "See b/188985272." >&2 + fi + flash_fp_mcu_stm32 \ "${TRANSPORT}" \ "${DEVICE}" \ |