summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Gherzan <andrei.gherzan@huawei.com>2021-02-16 15:33:06 +0000
committerNaveen Saini <naveen.kumar.saini@intel.com>2021-02-17 11:51:02 +0800
commitbdbe1a04c1b6595d2c530e49656dbb6d6755e4b6 (patch)
tree7f93273ee5dfa2a318ca11ad7f8d33e2cfe960ef
parent281d492b504e53577a43657624207e803ecfd0df (diff)
downloadmeta-zephyr-bdbe1a04c1b6595d2c530e49656dbb6d6755e4b6.tar.gz
meta-zephyr-bdbe1a04c1b6595d2c530e49656dbb6d6755e4b6.tar.bz2
meta-zephyr-bdbe1a04c1b6595d2c530e49656dbb6d6755e4b6.zip
zephyr-flash-pyocd.bbclass: Flash the first probe found with a timeout
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> Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
-rw-r--r--classes/zephyr-flash-pyocd.bbclass18
1 files changed, 17 insertions, 1 deletions
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()
}