All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andrei Gherzan" <andrei@gherzan.com>
To: yocto@lists.yoctoproject.org
Cc: Andrei Gherzan <andrei.gherzan@huawei.com>
Subject: [meta-zephy][PATCH 11/14] zephyr-flash-pyocd.bbclass: Flash the first probe found with a timeout
Date: Mon, 15 Feb 2021 11:20:00 +0000	[thread overview]
Message-ID: <20210215112003.2025053-11-andrei@gherzan.com> (raw)
In-Reply-To: <20210215112003.2025053-1-andrei@gherzan.com>

From: Andrei Gherzan <andrei.gherzan@huawei.com>

Currently the code flashes the firmware in a blocking way. If the host
is not configured accordingly (for example in terms of permissions),
this would hang undefinitely. This can easily confuse users and in order
to avoid this, the patch changes to unblocking session creation and
opening call, wrapping the tries in some relevant logging. The timeout
can be defined with `CONNECT_TIMEOUT_SECONDS` which defaults to 30
seconds.

Also, by default, when multiple probes are attached, the session call
will return a selection choice. This would obviously break under bitbake
with an exception:
    Exception: EOFError: EOF when reading a line
Avoid this by selecting the first found probe.

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
---
 classes/zephyr-flash-pyocd.bbclass | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/classes/zephyr-flash-pyocd.bbclass b/classes/zephyr-flash-pyocd.bbclass
index eca30c9..df3b631 100644
--- a/classes/zephyr-flash-pyocd.bbclass
+++ b/classes/zephyr-flash-pyocd.bbclass
@@ -1,11 +1,27 @@
+CONNECT_TIMEOUT_SECONDS ?= "30"
+
 python do_flash_usb() {
     from pyocd.core.helpers import ConnectHelper
     from pyocd.flash.file_programmer import FileProgrammer
 
+    timeout = int(d.getVar('CONNECT_TIMEOUT_SECONDS'))
     image = f"{d.getVar('DEPLOY_DIR_IMAGE')}/{d.getVar('PN')}.elf"
     bb.plain(f"Attempting to flash {image} to board {d.getVar('BOARD')}")
 
-    with ConnectHelper.session_with_chosen_probe() as session:
+    # Try to connect to a probe with a timeout
+    now = 0
+    step = 3
+    while True:
+        session = ConnectHelper.session_with_chosen_probe(blocking=False, return_first=True)
+        if session:
+            break
+        if now >= timeout:
+            bb.fatal("Timeout while trying to connect to a probe. Make sure the target device is connected and the udev is configured accordingly. See <https://github.com/mbedmicro/pyOCD/tree/master/udev> for help.")
+        bb.warn("Can't connect to the probe. Retrying in %d seconds..." % step)
+        time.sleep(step)
+        now += step
+
+    with session:
         FileProgrammer(session).program(image)
         session.board.target.reset()
 }
-- 
2.30.1


  parent reply	other threads:[~2021-02-15 11:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 11:19 [meta-zephy][PATCH 01/14] zephyr-flash-dfu.bbclass: Add missing do_flash_usb dependency on do_deploy Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 02/14] zephyr-flash-pyocd.bbclass: " Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 03/14] Cleanup superflous new lines Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 04/14] zephyr-kernel-src: Restructure recipe Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 05/14] zephyr-kernel-src-2.5.0-rc3.inc: Add support for zephyr kernel version 2.5.0-rc3 Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 06/14] zephyr-kernel-common.inc: Fix configuration CPPFLAGS warning Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 07/14] zephyr-kernel-common.inc: Reformat EXTRA_OECMAKE Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 08/14] zephyr-kernel.inc: Remove include file Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 09/14] Use an include file for the common parts of the sample recipes Andrei Gherzan
2021-02-15 11:19 ` [meta-zephy][PATCH 10/14] zephyr-peripheral-hr: Add recipe for BT HR sample Andrei Gherzan
2021-02-15 11:20 ` Andrei Gherzan [this message]
2021-02-15 11:20 ` [meta-zephy][PATCH 12/14] zephyr-flash-pyocd.bbclass: Handle import error for pyocd modules Andrei Gherzan
2021-02-15 11:20 ` [meta-zephy][PATCH 13/14] zephyr-flash-pyocd.bbclass: Implement configurable probe IDs to program Andrei Gherzan
2021-02-16 10:14   ` [yocto] " Naveen Saini
2021-02-15 11:20 ` [meta-zephy][PATCH 14/14] zephyr-kernel-src: Upgrade 2.5.0-rc3 to rc4 Andrei Gherzan

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=20210215112003.2025053-11-andrei@gherzan.com \
    --to=andrei@gherzan.com \
    --cc=andrei.gherzan@huawei.com \
    --cc=yocto@lists.yoctoproject.org \
    /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.