コード例 #1
0
def ensure_access_linux():
    """ Installs udev rules as appropriate for the Linux distribution. """

    rules_target_path = '/etc/udev/rules.d/54-greatfet.rules'

    # The 'canonical' way to test if systemd is running, from man page sd_booted(3).
    has_systemd = os.path.isdir('/run/systemd/system')

    try:

        if has_systemd:

            # Use uaccess udev rules on systems with systemd
            uaccess_rules = find_greatfet_asset('54-greatfet-uaccess.rules')

            if uaccess_rules is None:
                raise FileNotFoundError('Could not find uaccess udev rules!')

            print('Copying uaccess udev rules...')
            shutil.copy(uaccess_rules, rules_target_path)

        else:
            # Otherwise use plugdev udev rules
            plugdev_rules = find_greatfet_asset('54-greatfet-plugdev.rules')

            if plugdev_rules is None:
                raise FileNotFoundError('Could not find plugdev udev rules!')

            print('Copying plugdev udev rules...')
            shutil.copy(plugdev_rules, rules_target_path)

    except PermissionError:
        raise PermissionError('Failed to copy udev rules to {}! Maybe try with sudo -E?'.format(rules_target_path)) from None

    print('Done')
コード例 #2
0
def read_rhododendron_m0_loadable():
    """ Read the contents of the default Rhododendron loadable from the tools distribution. """

    filename = os.getenv('RHODODENDRON_M0_BIN',
                         find_greatfet_asset('rhododendron_m0.bin'))

    with open(filename, 'rb') as f:
        return f.read()
コード例 #3
0
def main():

    # Grab any GreatFET assets that should have shipped with the tool.
    dfu_stub_path = find_greatfet_asset('flash_stub.dfu')
    auto_firmware_path = find_greatfet_asset("greatfet_usb.bin")

    # Set up a simple argument parser.-
    parser = GreatFETArgumentParser(
        dfu=True,
        verbose_by_default=True,
        description="Utility for flashing firmware on GreatFET boards")
    parser.add_argument('-a',
                        '--address',
                        metavar='<n>',
                        type=int,
                        help="starting address (default: 0)",
                        default=0)
    parser.add_argument(
        '-l',
        '--length',
        metavar='<n>',
        type=int,
        help="number of bytes to read (default: {})".format(MAX_FLASH_LENGTH),
        default=MAX_FLASH_LENGTH)
    parser.add_argument('-r',
                        '--read',
                        dest='read',
                        metavar='<filename>',
                        type=str,
                        help="Read data into file",
                        default='')
    parser.add_argument('-w',
                        '--write',
                        dest='write',
                        metavar='<filename>',
                        type=str,
                        help="Write data from file",
                        default='')
    parser.add_argument(
        '-R',
        '--reset',
        dest='reset',
        action='store_true',
        help="Reset GreatFET after performing other operations.")

    # If we have the ability to automatically install firmware, provide that as an option.
    if auto_firmware_path:
        parser.add_argument(
            '--autoflash',
            action='store_true',
            dest='autoflash',
            help=
            "Automatically flash the attached board with the firmware corresponding to the installed tools."
        )

    args = parser.parse_args()

    # If we're trying to automatically flash the given firmware, set the relevant options accordingly.
    try:
        if not args.write and args.autoflash:
            args.write = auto_firmware_path
            args.reset = True
    except AttributeError:
        pass

    # Validate our options.

    # If we don't have an option, print our usage.
    if not any((
            args.read,
            args.write,
            args.reset,
    )):
        parser.print_help()
        sys.exit(0)

    # Determine whether we're going to log to the stdout, or not at all.
    log_function = parser.get_log_function()

    if args.dfu_stub:
        dfu_stub_path = args.dfu_stub

    # If we're supposed to install firmware via a DFU stub, install it first.
    if args.dfu:
        try:
            load_dfu_stub(dfu_stub_path)
        except DeviceNotFoundError:
            print("Couldn't find a GreatFET-compatible board in DFU mode!",
                  file=sys.stderr)
            sys.exit(errno.ENODEV)

    # Create our GreatFET connection.
    log_function("Trying to find a GreatFET device...")
    device = parser.find_specified_device()
    log_function("{} found. (Serial number: {})".format(
        device.board_name(), device.serial_number()))

    # Ensure that the device supports an onboard SPI flash.
    try:
        device.onboard_flash
    except AttributeError:
        print(
            "The attached GreatFET ({}) doesn't appear to have an SPI flash to program!"
            .format(device.board_name()),
            file=sys.stderr)
        sys.exit(errno.ENOSYS)

    # If we have a write command, write first, to match the behavior of hackrf_spiflash.
    if args.write:
        log_function("Writing data to SPI flash...")
        spi_flash_write(device, args.write, args.address, log_function)
        log_function("Write complete!")
        if not (args.reset or args.dfu):
            log_function(
                "Reset not specified; new firmware will not start until next reset."
            )

    # Handle any read commands.
    if args.read:
        log_function("Reading data from SPI flash...")
        spi_flash_read(device, args.read, args.address, args.length,
                       log_function)
        log_function("Read complete!")

    # Finally, reset the target
    if args.reset or args.dfu:
        log_function("Resetting GreatFET...")
        device.reset(reconnect=False, is_post_firmware_flash=bool(args.write))
        log_function("Reset complete!")
コード例 #4
0
    def main(self):
        dfu_stub_path = find_greatfet_asset('flash_stub.bin')
        auto_firmware_path = find_greatfet_asset("greatfet_usb.bin")
        parser = argparse.ArgumentParser(
            description="Utility for testing GreatFET One")
        parser.add_argument('-a',
                            '--address',
                            metavar='<n>',
                            type=int,
                            help="starting address (default: 0)",
                            default=0)
        parser.add_argument('-f',
                            '--logfile',
                            metavar='<logfile>',
                            type=str,
                            help="logfile to append to",
                            default='log')
        parser.add_argument('-w',
                            '--write',
                            dest='write',
                            metavar='<filename>',
                            type=str,
                            help="Write data from file")
        parser.add_argument(
            '--dfu-stub',
            dest='dfu_stub',
            metavar='<stub.dfu>',
            type=str,
            help=
            "The stub to use for DFU programming. If not provided, the utility will attempt to automtaically find one."
        )
        args = parser.parse_args()

        try:
            self.logfile = open(args.logfile, 'a')
        except:
            self.print('Warning: Could not open log file.')

        self.print("git-" + subprocess.getoutput('git log -n 1 --format=%hk'))
        if args.dfu_stub:
            dfu_stub_path = args.dfu_stub
        if not args.write:
            args.write = auto_firmware_path

        self.find_tester()
        self.initialize_jig()

        # Hold EUT in reset for now.
        self.tester_pins[self.other_pins["RESET_J7_P11"]].write(0)
        self.tester_pins[self.other_pins["RESET_J7_P11"]].set_direction(
            self.tester.gpio.DIRECTION_OUT)

        # Do not power EUT yet.
        self.tester_pins[self.other_pins["5V_EN"]].write(0)
        self.tester_pins[self.other_pins["5V_EN"]].set_direction(
            self.tester.gpio.DIRECTION_OUT)
        self.report_all_analog_voltages()

        self.prompt_for_id()
        self.detect_eut()
        self.activate_supply()
        self.test_pull_downs()
        self.test_pull_ups()
        self.test_reset_button()
        self.test_dfu_button()
        self.flash_firmware(args, dfu_stub_path)
        self.setup_eut_pins()
        self.test_gpio()
        self.test_leds()
        self.test_diode()
        self.test_usb1()

        self.print('PASS')