scripts: west: sync with upstream

This brings in content from commits in the upstream West
repository. Since both the version here and upstream have diverged,
this synchronizes them again.

Signed-off-by: Marti Bolivar <marti@foundries.io>
This commit is contained in:
Marti Bolivar 2018-07-27 15:01:09 -04:00 committed by Anas Nashif
commit 94be858f31
3 changed files with 32 additions and 10 deletions

View file

@ -3,10 +3,14 @@
# SPDX-License-Identifier: Apache-2.0
'''Zephyr RTOS meta-tool (west)
Main entry point for running this package as a module, e.g.:
py -3 west # Windows
python3 -m west # Unix
'''
from .main import main
import sys
if __name__ == '__main__':
main(sys.argv[1:])
main()

View file

@ -83,7 +83,9 @@ def parse_args(argv):
return args, unknown
def main(argv):
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
args, unknown = parse_args(argv)
for_stack_trace = 'run as "west -v ... {} ..." for a stack trace'.format(

View file

@ -13,12 +13,13 @@ from .core import ZephyrBinaryRunner, RunnerCaps
class NrfJprogBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for nrfjprog.'''
def __init__(self, cfg, family, softreset, snr):
def __init__(self, cfg, family, softreset, snr, erase=False):
super(NrfJprogBinaryRunner, self).__init__(cfg)
self.hex_ = cfg.kernel_hex
self.family = family
self.softreset = softreset
self.snr = snr
self.erase = erase
@classmethod
def name(cls):
@ -36,12 +37,15 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
parser.add_argument('--softreset', required=False,
action='store_true',
help='use reset instead of pinreset')
parser.add_argument('--erase', action='store_true',
help='if given, mass erase flash before loading')
parser.add_argument('--snr', required=False,
help='serial number of board to use')
@classmethod
def create(cls, cfg, args):
return NrfJprogBinaryRunner(cfg, args.nrf_family, args.softreset, args.snr)
return NrfJprogBinaryRunner(cfg, args.nrf_family, args.softreset, args.snr,
erase=args.erase)
def get_board_snr_from_user(self):
snrs = self.check_output(['nrfjprog', '--ids'])
@ -79,17 +83,29 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
return snrs[value - 1]
def do_run(self, command, **kwargs):
commands = []
if (self.snr is None):
board_snr = self.get_board_snr_from_user()
else:
board_snr = self.snr.lstrip("0")
program_cmd = ['nrfjprog', '--program', self.hex_, '-f', self.family,
'--snr', board_snr]
print('Flashing file: {}'.format(self.hex_))
commands = [
['nrfjprog', '--eraseall', '-f', self.family, '--snr', board_snr],
['nrfjprog', '--program', self.hex_, '-f', self.family, '--snr',
board_snr],
]
if self.erase:
commands.extend([
['nrfjprog',
'--eraseall',
'-f', self.family,
'--snr', board_snr],
program_cmd
])
else:
if self.family == 'NRF51':
commands.append(program_cmd + ['--sectorerase'])
else:
commands.append(program_cmd + ['--sectoranduicrerase'])
if self.family == 'NRF52' and self.softreset == False:
commands.extend([
# Enable pin reset