scripts: zephyr_flash_debug: get bossac port from environment

Allow the environment variable BOSSAC_PORT to specify the device's
serial port, if present.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
diff --git a/scripts/support/zephyr_flash_debug.py b/scripts/support/zephyr_flash_debug.py
index cc1480e..a05c95a 100755
--- a/scripts/support/zephyr_flash_debug.py
+++ b/scripts/support/zephyr_flash_debug.py
@@ -333,13 +333,18 @@
         check_call(cmd, self.debug)
 
 
+DEFAULT_BOSSAC_PORT = '/dev/ttyACM0'
+
+
 class BossacBinaryRunner(ZephyrBinaryRunner):
     '''Runner front-end for bossac.'''
 
-    def __init__(self, bin_name, bossac='bossac', debug=False):
+    def __init__(self, bin_name, bossac='bossac',
+                 port=DEFAULT_BOSSAC_PORT, debug=False):
         super(BossacBinaryRunner, self).__init__(debug=debug)
         self.bin_name = bin_name
         self.bossac = bossac
+        self.port = port
 
     def replaces_shell_script(shell_script, command):
         return command == 'flash' and shell_script == 'bossa-flash.sh'
@@ -355,11 +360,14 @@
         Optional:
 
         - BOSSAC: path to bossac, default is bossac
+        - BOSSAC_PORT: serial port to use, default is /dev/ttyACM0
         '''
         bin_name = path.join(get_env_or_bail('O'),
                              get_env_or_bail('KERNEL_BIN_NAME'))
         bossac = os.environ.get('BOSSAC', 'bossac')
-        return BossacBinaryRunner(bin_name, bossac=bossac, debug=debug)
+        port = os.environ.get('BOSSAC_PORT', DEFAULT_BOSSAC_PORT)
+        return BossacBinaryRunner(bin_name, bossac=bossac, port=port,
+                                  debug=debug)
 
     def run(self, command, **kwargs):
         if command != 'flash':
@@ -369,10 +377,11 @@
             msg = 'CAUTION: No flash tool for your host system found!'
             raise NotImplementedError(msg)
 
-        cmd_stty = ['stty', '-F', '/dev/ttyACM0', 'raw', 'ispeed', '1200',
+        cmd_stty = ['stty', '-F', self.port, 'raw', 'ispeed', '1200',
                     'ospeed', '1200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
                     'eof', '255']
-        cmd_flash = [self.bossac, '-R', '-e', '-w', '-v', '-b', self.bin_name]
+        cmd_flash = [self.bossac, '-p', self.port, '-R', '-e', '-w', '-v',
+                     '-b', self.bin_name]
 
         check_call(cmd_stty, self.debug)
         check_call(cmd_flash, self.debug)