targets/rp2040: Add bazel picotool support

Change-Id: I58c6263fabeda3e26f0e3b49e0fa7bc962dba40b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/214861
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Erik Gilling <konkers@google.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
This commit is contained in:
Erik Gilling 2024-06-12 22:28:25 +00:00 committed by CQ Bot Account
parent 9a99d41a54
commit f135cd73cd
3 changed files with 32 additions and 4 deletions

View File

@ -519,6 +519,13 @@ git_repository(
remote = "https://pigweed.googlesource.com/third_party/github/raspberrypi/pico-sdk",
)
# TODO: https://pwbug.dev/345244650 - Upstream bazel build.
git_repository(
name = "picotool",
commit = "49072f6ebbc814dcc74d6f8b753b89c24af12971",
remote = "https://github.com/armandomontanez/picotool",
)
http_archive(
name = "tinyusb",
build_file = "@pico-sdk//src/rp2_common/tinyusb:tinyusb.BUILD",

View File

@ -52,6 +52,7 @@ py_binary(
],
data = [
"//third_party/probe-rs",
"@picotool",
],
main = "rp2040_utils/rpc_unit_test_runner.py",
tags = ["manual"],

View File

@ -16,6 +16,7 @@
import argparse
import logging
import os
import subprocess
import sys
import time
@ -42,7 +43,7 @@ try:
r = runfiles.Create()
_PROBE_RS_COMMAND = r.Rlocation('pigweed/third_party/probe-rs/probe-rs')
_PICOTOOL_COMMAND = 'picotool'
_PICOTOOL_COMMAND = r.Rlocation('picotool/picotool')
except ImportError:
_PROBE_RS_COMMAND = 'probe-rs'
_PICOTOOL_COMMAND = 'picotool'
@ -220,20 +221,39 @@ class PiPicoTestingDevice(SerialTestingDevice):
def load_picotool_binary(self, binary: Path) -> bool:
"""Flash a binary to this device using picotool, returning success or
failure."""
cmd = (
cmd = [
_PICOTOOL_COMMAND,
'load',
'-x',
str(binary),
]
# If the binary has not file extension, assume that it is ELF and
# explicitly tell `picotool` that.
if not binary.suffix:
cmd += ['-t', 'elf']
cmd += [
'--bus',
str(self._board_info.bus),
'--address',
str(self._board_info.address()),
'-F',
)
]
_LOG.debug('Flashing ==> %s', ' '.join(cmd))
# If the script is running inside Bazel, `picotool` needs to run from
# the project root so that it can find libusb.
cwd = None
if 'BUILD_WORKING_DIRECTORY' in os.environ:
cwd = os.environ['BUILD_WORKING_DIRECTORY']
process = subprocess.run(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=cwd,
)
if process.returncode:
err = (