All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Tom Rini <trini@konsulko.com>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	Simon Glass <sjg@chromium.org>
Subject: [u-boot-test-hooks PATCH 4/7] Add wait_raw_device for common code
Date: Sat, 30 Oct 2021 12:25:36 -0600	[thread overview]
Message-ID: <20211030182539.1371361-4-sjg@chromium.org> (raw)
In-Reply-To: <20211030182539.1371361-1-sjg@chromium.org>

This code is duplicated in two scripts. Put it into a new wait_raw_device
to avoid this. Also rename the 'done' variable to 'complete' to void
confusing it with the end of the for loop.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 bin/flash.sdwire_digital-loggers_raw | 15 +-----------
 bin/flash.sdwire_poweroff_raw        | 15 +-----------
 bin/wait_raw_device                  | 34 ++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 28 deletions(-)
 create mode 100644 bin/wait_raw_device

diff --git a/bin/flash.sdwire_digital-loggers_raw b/bin/flash.sdwire_digital-loggers_raw
index 7d5fbc9..f9956f7 100644
--- a/bin/flash.sdwire_digital-loggers_raw
+++ b/bin/flash.sdwire_digital-loggers_raw
@@ -33,20 +33,7 @@ curl --data ${power_port}=OFF -o /dev/null --silent \
 # Switch over to get USB card access
 sd-mux-ctrl --device-serial ${sdwire_serial} --ts
 
-# Wait for the device to become available
-done=false
-for i in {0..9}; do
-    if dd if=${raw_device} of=/dev/null count=1 >/dev/null 2>&1; then
-        done=true
-        break
-    fi
-
-    sleep 1
-done
-if [[ $done = false ]]; then
-    echo "Failed to access ${raw_device} after 10 tries"
-    exit 1
-fi
+. wait_raw_device
 
 writer.${flash_writer} ${raw_device} ${U_BOOT_BUILD_DIR}
 
diff --git a/bin/flash.sdwire_poweroff_raw b/bin/flash.sdwire_poweroff_raw
index 28fa096..d82a3ef 100644
--- a/bin/flash.sdwire_poweroff_raw
+++ b/bin/flash.sdwire_poweroff_raw
@@ -34,20 +34,7 @@ mount_dir=/media/${mount_point}
 # Switch over to get USB card access
 sd-mux-ctrl --device-serial ${sdwire_serial} --ts
 
-# Wait for the device to become available
-done=false
-for i in {0..9}; do
-    if dd if=${raw_device} of=/dev/null count=1 >/dev/null 2>&1; then
-        done=true
-        break
-    fi
-
-    sleep 1
-done
-if [[ $done = false ]]; then
-    echo "Failed to access ${raw_device} after 10 tries"
-    exit 1
-fi
+. wait_raw_device
 
 writer.${flash_writer} ${raw_device} ${U_BOOT_BUILD_DIR}
 
diff --git a/bin/wait_raw_device b/bin/wait_raw_device
new file mode 100644
index 0000000..c292114
--- /dev/null
+++ b/bin/wait_raw_device
@@ -0,0 +1,34 @@
+# Copyright 2021 Google LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+# Wait for the device ${raw_device} to become available
+complete=false
+for i in {0..9}; do
+    if dd if=${raw_device} of=/dev/null count=1 >/dev/null 2>&1; then
+        complete=true
+        break
+    fi
+
+    sleep 1
+done
+if [[ $complete = false ]]; then
+    echo "Failed to access ${raw_device} after 10 tries"
+    exit 1
+fi
-- 
2.33.1.1089.g2158813163f-goog


  parent reply	other threads:[~2021-10-30 18:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 18:25 [u-boot-test-hooks PATCH 1/7] travis-ci: Add qemu_arm_spl board Simon Glass
2021-10-30 18:25 ` [u-boot-test-hooks PATCH 2/7] sdwire: Tidy up the mount script Simon Glass
2021-11-11 17:37   ` Tom Rini
2021-10-30 18:25 ` [u-boot-test-hooks PATCH 3/7] rpi3: Tweak the grep pattern Simon Glass
2021-11-11 17:37   ` Tom Rini
2021-10-30 18:25 ` Simon Glass [this message]
2021-11-11 17:37   ` [u-boot-test-hooks PATCH 4/7] Add wait_raw_device for common code Tom Rini
2021-10-30 18:25 ` [u-boot-test-hooks PATCH 5/7] Update sdwire script to wait for umount Simon Glass
2021-11-11 17:37   ` Tom Rini
2021-10-30 18:25 ` [u-boot-test-hooks PATCH 6/7] kea: Add samus Simon Glass
2021-11-11 17:38   ` Tom Rini
2021-10-30 18:25 ` [u-boot-test-hooks PATCH 7/7] ellesmere: Add qemu rules Simon Glass
2021-10-31 16:57   ` Tom Rini
2021-10-31 18:22     ` Simon Glass
2021-10-31 19:15       ` Tom Rini
2021-11-03 15:23 ` [u-boot-test-hooks PATCH 1/7] travis-ci: Add qemu_arm_spl board Tuomas Tynkkynen
2021-11-11 17:37 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211030182539.1371361-4-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.