tools: Add the gonk and gonk-flash python entry points
Change-Id: Ia30fbaa1ec5feaabb0e63fede0b4976a139abe34
Reviewed-on: https://pigweed-review.googlesource.com/c/gonk/+/208755
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Reviewed-by: Eric Holland <hollande@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Pigweed-Auto-Submit: Anthony DiGirolamo <tonymd@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/README.md b/README.md
index 48e3532..08757e4 100644
--- a/README.md
+++ b/README.md
@@ -78,10 +78,10 @@
1. Unplug gonk from USB and replug with MODE button held down.
-1. Run `pw flash` on the MCU binary.
+1. Run `gonk-flash` on the MCU binary. This uses `dfu-util`.
```sh
- pw flash ./out/gn/arduino_size_optimized/obj/applications/fpga_config/fpga_config.bin
+ gonk-flash ./out/gn/arduino_size_optimized/obj/applications/fpga_config/fpga_config.bin
```
### Write the FPGA bitstream
@@ -89,7 +89,7 @@
1. Write an FPGA bitstream with the `write_fpga.py` script:
```sh
- python ./tools/gonk_tools/write_fpga.py \
+ gonk \
--bitstream-file ./out/gn/obj/fpga/toplevel/toplevel.bin
--database ./out/gn/arduino_size_optimized/obj/applications/fpga_config/bin/fpga_config.elf \
--log-to-stderr
@@ -98,7 +98,7 @@
You can redirect host and device logs to separate files with:
```sh
- python ./tools/gonk_tools/write_fpga.py \
+ gonk \
--bitstream-file ./out/gn/obj/fpga/toplevel/toplevel.bin
--database ./out/gn/arduino_size_optimized/obj/applications/fpga_config/bin/fpga_config.elf \
--host-logfile gonk-host-logs.txt \
diff --git a/tools/BUILD.gn b/tools/BUILD.gn
index 117a1fe..dbf78b8 100644
--- a/tools/BUILD.gn
+++ b/tools/BUILD.gn
@@ -23,6 +23,7 @@
]
sources = [
"gonk_tools/__init__.py",
+ "gonk_tools/__main__.py",
"gonk_tools/binary_handler.py",
"gonk_tools/build_project.py",
"gonk_tools/find_serial_port.py",
diff --git a/tools/gonk_tools/__main__.py b/tools/gonk_tools/__main__.py
new file mode 100644
index 0000000..2eadbfa
--- /dev/null
+++ b/tools/gonk_tools/__main__.py
@@ -0,0 +1,24 @@
+# Copyright 2024 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+"""Gonk tools entry point."""
+
+import gonk_tools.write_fpga
+
+
+def main():
+ gonk_tools.write_fpga.main()
+
+
+if __name__ == '__main__':
+ gonk_tools.write_fpga.main()
diff --git a/tools/gonk_tools/write_fpga.py b/tools/gonk_tools/write_fpga.py
index eae58f0..21cef39 100644
--- a/tools/gonk_tools/write_fpga.py
+++ b/tools/gonk_tools/write_fpga.py
@@ -319,7 +319,7 @@
_LOG.info('Done sending bitstream. Wrote %d', written_bytes)
-def main(
+def write_fpga_main(
# pylint: disable=too-many-arguments
baudrate: int,
databases: Iterable,
@@ -470,5 +470,9 @@
return 0
+def main():
+ sys.exit(write_fpga_main(**vars(_parse_args())))
+
+
if __name__ == '__main__':
- sys.exit(main(**vars(_parse_args())))
+ main()
diff --git a/tools/setup.cfg b/tools/setup.cfg
index dc7d221..a196307 100644
--- a/tools/setup.cfg
+++ b/tools/setup.cfg
@@ -25,6 +25,8 @@
[options.entry_points]
console_scripts =
+ gonk-flash = gonk_tools.flash:dfu_flash
+ gonk = gonk_tools.__main__:main
[options.package_data]
gonk_tools =