Thanks Andrei for adding support for v2.5-rc4 and re-structuring.

Could you fix a whitespace in this patch ? Other patches looks good to me.

Later I will fix subject-prefix meta-zephyr typo in README. 

Regards,
Naveen

> -----Original Message-----
> From: yocto@lists.yoctoproject.org <yocto@lists.yoctoproject.org> On
> Behalf Of Andrei Gherzan
> Sent: Monday, February 15, 2021 7:20 PM
> To: yocto@lists.yoctoproject.org
> Cc: Andrei Gherzan <andrei.gher...@huawei.com>
> Subject: [yocto] [meta-zephy][PATCH 13/14] zephyr-flash-pyocd.bbclass:
> Implement configurable probe IDs to program
> 
> From: Andrei Gherzan <andrei.gher...@huawei.com>
> 
> Implement logic to configure what probes to program based on the
> PYOCD_FLASH_IDS variable:
> 1. by default program all attached probes 2. change default behaviour by
> listing the probe IDs to flash
> 
> CONNECT_TIMEOUT_SECONDS was also renamed to maintain consistency
> with the PYOCD_FLASH_IDS variable.
> 
> One can query the IDs using `pyocd list`.
> 
> The value of PYOCD_FLASH_IDS can also be injected into the datastore using
> BB_ENV_EXTRAWHITE.
> 
> Signed-off-by: Andrei Gherzan <andrei.gher...@huawei.com>
> ---
>  README.txt                         |  9 +++++
>  classes/zephyr-flash-pyocd.bbclass | 57 ++++++++++++++++++++----------
>  2 files changed, 48 insertions(+), 18 deletions(-)
> 
> diff --git a/README.txt b/README.txt
> index bda872b..ce5338b 100644
> --- a/README.txt
> +++ b/README.txt
> @@ -67,6 +67,15 @@ dfu-util and/or pyocd need to be installed in your
> system. If you observe  permission errors or the flashing process seem to
> hang, follow those instructions:
>  https://github.com/pyocd/pyOCD/tree/master/udev
> 
> +By default, pyocd tries to flash all the attached probes. This
> +behaviour can be customised by defining the PYOCD_FLASH_IDS variable as
> +a space-separated list of IDs. Once that is set, the tool will only try
> +to program these IDs. You can query for the IDs by running `pyocd list`
> +on your host while having the probes attached. Besides setting this
> +variable through the build's configuration or metadata, you can also inject
> its value from command line with something like:
> +
> +    $ PYOCD_FLASH_IDS='<ID1> <ID2> <ID3>'
> + BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE PYOCD_FLASH_IDS"
> bitbake
> + <TARGET> -c flash_usb
> +
>  Building and Running Zephyr Tests
>  =================================
>  Presently only toolchains for ARM, x86, IAMCU and Nios2 are supported.
> diff --git a/classes/zephyr-flash-pyocd.bbclass b/classes/zephyr-flash-
> pyocd.bbclass
> index 4d24e6a..7e1cec5 100644
> --- a/classes/zephyr-flash-pyocd.bbclass
> +++ b/classes/zephyr-flash-pyocd.bbclass
> @@ -1,4 +1,5 @@
> -CONNECT_TIMEOUT_SECONDS ?= "30"
> +PYOCD_CONNECT_TIMEOUT_SECONDS ?= "30"
> +PYOCD_FLASH_IDS ?= "all"
> 
>  python do_flash_usb() {
>      try:
> @@ -7,26 +8,46 @@ python do_flash_usb() {
>      except ImportError:
>          bb.fatal("Flashing with pyocd needs the relevant python package. Make
> sure your host provides it or consult your distribution packages for how to
> install this prerequisite.")
> 
> -    timeout = int(d.getVar('CONNECT_TIMEOUT_SECONDS'))
> +    try:
> +        timeout = int(d.getVar('PYOCD_CONNECT_TIMEOUT_SECONDS'))
> +    except ValueError:
> +        bb.fatal(f"PYOCD_CONNECT_TIMEOUT_SECONDS was set to an invalid
> + value: {d.getVar('PYOCD_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')}")
> +    ids = d.getVar('PYOCD_FLASH_IDS')
> +
> +    # Compute the list of IDs to program
> +    if ids == 'all':
> +        ids = []
> +        for probe in
> ConnectHelper.get_all_connected_probes(blocking=False):
> +            ids.append(probe.unique_id)
> +        if not ids:
> +            bb.fatal("No probe detected. Make sure your target is 
> connected.")
> +    else:
> +        ids = ids.split()
> +        if not ids:
> +            bb.fatal("No probe requested for programming. Make sure
> + PYOCD_FLASH_IDS is set.")
> 
> -    # 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
> +    # Program each ID
> +    for id in ids:
> +        bb.plain(f"Attempting to flash {os.path.basename(image)} to
> + board {d.getVar('BOARD')} [{id}]")
> 
> -    with session:
> -        FileProgrammer(session).program(image)
> -        session.board.target.reset()
> +        # 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, unique_id=id)
> +            if session:
> +                break
> +            if now >= timeout:
> +                bb.fatal(f"Timeout while trying to connect to probe ID: 
> {id}. 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(f"Can't connect to the probe ID: {id}. Retrying in {step}
> seconds...")
> +            time.sleep(step)
> +            now += step
> +
> +        # Program the sepected probe
> +        with session:
> +            FileProgrammer(session).program(image)
> +            session.board.target.reset()
>  }
> 
>  addtask do_flash_usb after do_deploy
> --
> 2.30.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#52330): https://lists.yoctoproject.org/g/yocto/message/52330
Mute This Topic: https://lists.yoctoproject.org/mt/80651043/21656
Group Owner: yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to