soc: xtensa: add support for specifying the service port

Add specifying the port for the remote cavstool remote service.
Ex.

    west flash --remote-host {host}:{port} \
               --pty {host}:{port}

Specify the port is optional when running west.

And another major change is now we have to specify the remote log
service by --pty to make it output the log message immediately.
Previously it will output directly. Why we make this change is
because this is more close to the behavior we use west flash.

Fixes. #46865

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
This commit is contained in:
Enjia Mai 2022-07-23 13:40:16 +08:00 committed by Marti Bolivar
commit e33fd73546
3 changed files with 33 additions and 14 deletions

View file

@ -482,8 +482,6 @@ class DeviceHandler(Handler):
command.append("--tool-opt=-SelectEmuBySN %s" % (board_id)) command.append("--tool-opt=-SelectEmuBySN %s" % (board_id))
elif runner == "stm32cubeprogrammer": elif runner == "stm32cubeprogrammer":
command.append("--tool-opt=sn=%s" % (board_id)) command.append("--tool-opt=sn=%s" % (board_id))
elif runner == "intel_adsp":
command.append("--pty")
# Receive parameters from runner_params field. # Receive parameters from runner_params field.
if hardware.runner_params: if hardware.runner_params:

View file

@ -68,9 +68,9 @@ class IntelAdspBinaryRunner(ZephyrBinaryRunner):
help='the default basename of the key store in board.cmake') help='the default basename of the key store in board.cmake')
parser.add_argument('--key', parser.add_argument('--key',
help='specify where the signing key is') help='specify where the signing key is')
parser.add_argument('--pty', action="store_true", parser.add_argument('--pty',
help='the log will not output immediately to STDOUT, you \ help=''''Capture the output of cavstool.py running on --remote-host \
can redirect it to a serial PTY') and stream it remotely to west's standard output.''')
@classmethod @classmethod
def do_create(cls, cfg, args): def do_create(cls, cfg, args):
@ -122,15 +122,20 @@ class IntelAdspBinaryRunner(ZephyrBinaryRunner):
# Copy the zephyr to target remote ADSP host and run # Copy the zephyr to target remote ADSP host and run
self.run_cmd = ([f'{self.cavstool}','-s', f'{self.remote_host}', f'{send_bin_fw}']) self.run_cmd = ([f'{self.cavstool}','-s', f'{self.remote_host}', f'{send_bin_fw}'])
self.log_cmd = ([f'{self.cavstool}','-s', f'{self.remote_host}', '-l'])
self.logger.debug(f"cavstool({self.cavstool}), fw('{send_bin_fw})")
self.logger.debug(f"rcmd: {self.run_cmd}") self.logger.debug(f"rcmd: {self.run_cmd}")
self.check_call(self.run_cmd) self.check_call(self.run_cmd)
# If the self.pty assigned, the output the log will # If the self.pty is assigned, the log will output to stdout
# not output to stdout directly. That means we can # directly. That means you don't have to execute the command:
# make the log output to the PTY. #
if not self.pty: # cavstool_client.py -s {host}:{port} -l
#
# to get the result later separately.
if self.pty is not None:
self.log_cmd = ([f'{self.cavstool}','-s', f'{self.pty}', '-l'])
self.logger.debug(f"rcmd: {self.log_cmd}")
self.check_call(self.log_cmd) self.check_call(self.log_cmd)

View file

@ -9,9 +9,11 @@ import argparse
import socket import socket
import struct import struct
import hashlib import hashlib
from urllib.parse import urlparse
RET = 0 RET = 0
HOST = None HOST = None
PORT = 0
PORT_LOG = 9999 PORT_LOG = 9999
PORT_REQ = PORT_LOG + 1 PORT_REQ = PORT_LOG + 1
BUF_SIZE = 4096 BUF_SIZE = 4096
@ -110,14 +112,14 @@ def main():
log.info("Monitor process") log.info("Monitor process")
try: try:
client = cavstool_client(HOST, PORT_LOG, args) client = cavstool_client(HOST, PORT, args)
client.send_cmd(CMD_LOG_START) client.send_cmd(CMD_LOG_START)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
else: else:
log.info("Uploading process") log.info("Uploading process")
client = cavstool_client(HOST, PORT_REQ, args) client = cavstool_client(HOST, PORT, args)
client.send_cmd(CMD_DOWNLOAD) client.send_cmd(CMD_DOWNLOAD)
ap = argparse.ArgumentParser(description="DSP loader/logger client tool") ap = argparse.ArgumentParser(description="DSP loader/logger client tool")
@ -133,7 +135,21 @@ args = ap.parse_args()
if args.quiet: if args.quiet:
log.setLevel(logging.WARN) log.setLevel(logging.WARN)
HOST = args.server_addr if args.server_addr:
url = urlparse("//" + args.server_addr)
if url.hostname:
HOST = url.hostname
if url.port:
PORT = int(url.port)
else:
if args.log_only:
PORT = PORT_LOG
else:
PORT = PORT_REQ
log.info(f"REMOTE HOST: {HOST} PORT: {PORT}")
if __name__ == "__main__": if __name__ == "__main__":
main() main()