示例#1
0
async def more_setup():
    # Boot up code; splash screen is being shown

    # MAYBE: check if we're a brick and die again? Or show msg?

    try:
        # Some background "tasks"
        #
        from dev_helper import monitor_usb
        IMPT.start_task('vcp', monitor_usb())

        from files import CardSlot
        CardSlot.setup()

        # This "pa" object holds some state shared w/ bootloader about the PIN
        try:
            from pincodes import pa
            pa.setup(b'')  # just to see where we stand.
        except RuntimeError as e:
            print("Problem: %r" % e)

        if version.is_factory_mode:
            # in factory mode, turn on USB early to allow debug/setup
            from usb import enable_usb
            enable_usb()

            # always start the self test.
            if not settings.get('tested', False):
                from actions import start_selftest
                await start_selftest()

        else:
            # force them to accept terms (unless marked as already done)
            from actions import accept_terms
            await accept_terms()

        # Prompt for PIN and then pick appropriate top-level menu,
        # based on contents of secure chip (ie. is there
        # a wallet defined)
        from actions import start_login_sequence
        await start_login_sequence()
    except BaseException as exc:
        die_with_debug(exc)

    IMPT.start_task('mainline', mainline())
示例#2
0
def go(operation='', field='chain', value='BTC'):
    import common
    from sram4 import viewfinder_buf
    print('2: Available RAM = {}'.format(gc.mem_free()))

    # Avalanche noise source
    from foundation import Noise
    common.noise = Noise()

    # Get the async event loop to pass in where needed
    common.loop = asyncio.get_event_loop()

    # System
    from foundation import System
    common.system = System()

    print('2.75: Available RAM = {}'.format(gc.mem_free()))
    # Initialize the keypad
    from keypad import Keypad
    common.keypad = Keypad()
    print('3: Available RAM = {}'.format(gc.mem_free()))

    # Initialize SD card
    from files import CardSlot
    CardSlot.setup()
    print('3.5: Available RAM = {}'.format(gc.mem_free()))

    # External SPI Flash
    from sflash import SPIFlash
    common.sf = SPIFlash()

    # Initialize NV settings
    from settings import Settings
    common.settings = Settings(common.loop)
    print('4: Available RAM = {}'.format(gc.mem_free()))

    # Initialize the display and show the splash screen
    from display import Display
    print("disp 1")
    common.dis = Display()
    print("disp 2")
    common.dis.set_brightness(common.settings.get('screen_brightness', 100))
    print("disp 3")
    common.dis.splash()
    print('5: Available RAM = {}'.format(gc.mem_free()))

    # Allocate buffers for camera
    from constants import VIEWFINDER_WIDTH, VIEWFINDER_HEIGHT, CAMERA_WIDTH, CAMERA_HEIGHT

    # QR buf is 1 byte per pixel grayscale
    import uctypes
    common.qr_buf = uctypes.bytearray_at(0x20000000,
                                         CAMERA_WIDTH * CAMERA_HEIGHT)
    # common.qr_buf = bytearray(CAMERA_WIDTH * CAMERA_HEIGHT)
    print('6: Available RAM = {}'.format(gc.mem_free()))

    # Viewfinder buf 1s 1 bit per pixel and we round the screen width up to 240
    # so it's a multiple of 8 bits.  The screen height of 303 minus 31 for the
    # header and 31 for the footer gives 241 pixels, which we round down to 240
    # to give one blank (white) line before the footer.
    common.viewfinder_buf = bytearray(
        (VIEWFINDER_WIDTH * VIEWFINDER_HEIGHT) // 8)
    print('7: Available RAM = {}'.format(gc.mem_free()))

    # Show REPL welcome message
    print("Passport by Foundation Devices Inc. (C) 2020.\n")

    print('8: Available RAM = {}'.format(gc.mem_free()))

    from foundation import SettingsFlash
    f = SettingsFlash()

    if operation == 'dump':
        print('Settings = {}'.format(common.settings.curr_dict))
        print('addr = {}'.format(common.settings.addr))
    elif operation == 'erase':
        f.erase()
    elif operation == 'set':
        common.settings.set(field, value)
    elif operation == 'stress':
        for f in range(35):
            print("Round {}:".format(f))
            print('  Settings = {}'.format(common.settings.curr_dict))
            common.settings.set('field_{}'.format(f), f)
            common.settings.save()

        print('\nFinal Settings = {}'.format(common.settings.curr_dict))

    # This "pa" object holds some state shared w/ bootloader about the PIN
    try:
        from pincodes import PinAttempt

        common.pa = PinAttempt()
        common.pa.setup(b'')
    except RuntimeError as e:
        print("Secure Element Problem: %r" % e)
    print('9: Available RAM = {}'.format(gc.mem_free()))

    # Setup the startup task
    common.loop.create_task(startup())

    run_loop()
示例#3
0
文件: main.py 项目: yahiheb/firmware
    gc.collect()
    #print("Free mem: %d" % gc.mem_free())

    while 1:
        await the_ux.interact()

# Setup to start the splash screen.
dis.splash_animate(loop, done_splash2)

# Some background "tasks"
#
from dev_helper import monitor_usb
loop.create_task(monitor_usb())

from files import CardSlot
CardSlot.setup()

# This "pa" object holds some state shared w/ bootloader about the PIN
try:
    from pincodes import PinAttempt

    pa = PinAttempt()
    pa.setup(b'')       # just to see where we stand.
except RuntimeError as e:
    print("Problem: %r" % e)

def go():
    # Wrapper for better error handling/recovery at top level.
    #
    try:
        loop.run_forever()