Example #1
0
from bpmicro.util import add_bool_arg

led_s2i = {
    'fail': 1,
    'active': 2,
    'pass': 4,
    'red': 1,
    'orange': 2,
    'green': 4,
}

if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description='Control LED')
    add_bool_arg(parser, '--cycle', default=False, help='')
    parser.add_argument(
        'status',
        help='String value or 0-7 direct mask, 1: fail, 2: active, 4: pass')
    args = parser.parse_args()

    try:
        status = int(args.status, 0)
    except ValueError:
        try:
            status = led_s2i[args.status]
        except KeyError:
            raise Exception("Bad status value %s" % args.status)

    bp = startup.get()
    cmd.led_mask(bp.dev, status)
Example #2
0
    validate_read("\x83\x00", buff, "packet 1224/1225")

    # Generated from packet 1226/1227
    buff = bulk2(dev, "\x02", target=6)
    validate_read("\x84\x00\x50\x01\x09\x00", buff, "packet 1228/1229")

    # Generated from packet 1230/1231
    buff = bulk2(dev, "\x57\x83\x00", target=2)
    validate_read("\x00\x00", buff, "packet 1232/1233")


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description='Replay captured USB packets')
    util.add_bool_arg(parser, '--loop', default=False, help='')
    args = parser.parse_args()

    bp = startup.get()

    print()
    print()
    # didn't fix 17/18 issue
    #time.sleep(5)
    print()

    if 1:
        import os

        try:
            while True:
Example #3
0
        while True:
            dout = os.path.join(parent, prefix)
            if i:
                dout += '.' + str(i)
            if not os.path.exists(dout):
                break
            i += 1
    if not os.path.exists(dout):
        os.mkdir(dout)
    return dout


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Dump device data')
    util.add_bool_arg(parser,
                      '--verbose',
                      default=True,
                      help='Print hex dumps')
    util.add_bool_arg(parser, '--save', default=True, help='Save dump')
    util.add_bool_arg(parser,
                      '--sm',
                      default=False,
                      help='Only dump socket module')
    util.add_bool_arg(parser,
                      '--bp',
                      default=False,
                      help='Only dump socket module')
    parser.add_argument('dout', nargs='?', default=None, help='File out')
    args = parser.parse_args()

    bp = startup.get()
    sn = cmd.sn_read(bp.dev)
Example #4
0
                usbrply, fin, json_fn)
        subprocess.check_call(cmd, shell=True)
    else:
        json_fn = fin

    j = json.load(open(json_fn))
    return j, json_fn


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description='')
    parser.add_argument('--dumb', action='store_true')
    add_bool_arg(parser,
                 '--omit-ro',
                 default=True,
                 help='Omit read only requests (ex: get SM info)')
    parser.add_argument('--big-thresh', type=int, default=256)
    parser.add_argument('--usbrply', default='')
    parser.add_argument('--save', action='store_true', help='Save firmware')
    parser.add_argument('-w', action='store_true', help='Write python file')
    parser.add_argument('fin')
    args = parser.parse_args()

    j, json_fn = load_json(args.fin, args.usbrply, args.dumb)

    if args.w:
        filename, file_extension = os.path.splitext(args.fin)
        fnout = filename + '.py'
        print(('Selected output file %s' % fnout))
        assert fnout != args.fin and fnout != json_fn
Example #5
0
def main():
    import argparse

    parser = argparse.ArgumentParser(description='Replay captured USB packets')
    add_bool_arg(parser, '--cycle', default=False, help='')
    add_bool_arg(parser, '--cont', default=True, help='Continuity check')
    parser.add_argument('device')
    parser.add_argument('out_dir', nargs='?')
    args = parser.parse_args()

    verbose = True
    bp = startup.get()
    device = devices.get(bp, args.device, verbose=verbose)

    if args.out_dir and not os.path.exists(args.out_dir):
        os.mkdir(args.out_dir)

    itern = 0
    while True:
        itern += 1
        prefix = os.path.join(args.out_dir, "%03u" % itern)
        print("")
        print("")
        print("")
        try:
            devcfg = device.read({'cont': args.cont})
        except cmd.BusError:
            print('WARNING: bus error')
            continue
        except cmd.Overcurrent:
            print('WARNING: overcurrent')
            continue
        except cmd.ContFail:
            print('WARNING: continuity fail')
            continue

        print("")
        hexdump(devcfg['code'], indent='  ', label='Code')
        hexdump(devcfg['code'][0:0x40], indent='  ', label='Code start')
        print((buff2hash8(devcfg['code'])))
        if args.out_dir:
            open(prefix + "_code.bin", "wb").write(devcfg['code'])

        if 'data' in devcfg:
            print("")
            hexdump(devcfg['data'], indent='  ', label='EEPROM')
            if args.out_dir:
                open(prefix + "_data.bin", "wb").write(devcfg['data'])

        if 'config' in devcfg:
            print("")
            print('Fuses')
            config = devcfg['config']
            for i in range(0, 4):
                print(('  user_id%d:  0x%04X' % (i, config['user_id%d' % i])))
            #print '  conf_word: 0x%04X' % (config['conf_word'])
            print(('  secure: %s' % (config['secure'])))
            if args.out_dir:
                open(prefix + "_config.json", "w").write(
                    json.dumps(devcfg['config'],
                               sort_keys=True,
                               indent=4,
                               separators=(',', ': ')))
Example #6
0
from bpmicro import cmd
from bpmicro import util
from bpmicro import sockets

if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description='Dump device data')
    util.add_bool_arg(parser,
                      '--verbose',
                      default=True,
                      help='Print hex dumps')
    parser.add_argument('fin', default=None, help='File in')
    args = parser.parse_args()

    sm = cmd.sm_decode(open(args.fin).read())
    if args.verbose:
        util.print_mkstruct(sm)
    else:
        util.print_mkstruct(
            sm, filter=lambda k, v: 'pad' not in k and 'unk' not in k)

    name_expect = sockets.name_i2s.get(sm.sockid, None)
    if name_expect is None:
        print('Note: unknown socket type %s' % sm.sockid)
    elif name_expect != sm.name:
        print('WARNING: expected name %s but got %s' % (name_expect, sm.name))
Example #7
0
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description='Read/write device w/ BP Microsystems programmer')
    add_bool_arg(parser, '--cont', default=True, help='Continuity check')
    add_bool_arg(parser,
                 '--erase',
                 default=None,
                 help='Erase device (write only)')
    add_bool_arg(parser,
                 '--verify',
                 default=True,
                 help='Read back after write (write only)')
    add_bool_arg(parser, '--verbose', default=True, help='More verbose output')
    add_bool_arg(parser,
                 '--dir',
                 default=None,
                 help='Force input/output directory')
    add_bool_arg(parser,
                 '--init',
                 default=True,
                 help='Advanced / developer only')
    parser.add_argument(
        'operation',
        help='Operation: read, program, erase, protect, list_device, nop')
    parser.add_argument('device', nargs='?', help='Device to use')
    parser.add_argument(
        'code',
        nargs='?',
        help=
        'Read/write input/output file or directory: primary data such as EPROM or flash'
    )
    parser.add_argument(
        'data',
        nargs='?',
        help='Read/write input/output file: secondary data such as EEPROM')
    parser.add_argument(
        'config',
        nargs='?',
        help=
        'Read/write input/output file or directory: additional configuration')
    args = parser.parse_args()

    run(args.operation,
        args.device,
        code_fn=args.code,
        data_fn=args.data,
        config_fn=args.config,
        cont=args.cont,
        erase=args.erase,
        verify=args.verify,
        verbose=args.verbose,
        dir_=args.dir,
        init=args.init)