Beispiel #1
0
    def check_platform(self, board_data):
        if 'platform' not in board_data:
            return

        platform = board_data.get('platform')
        current_platform = util.get_systype()
        if platform != current_platform:
            # Incorrect platform
            if platform == 'linux_armv7l':
                raise Exception('incorrect platform: RPI2 or RPI3 required')
            else:
                raise Exception('incorrect platform {0}'.format(platform))
Beispiel #2
0
 def _check_packages(self, packages, current_platform=''):
     filtered_packages = {}
     for pkg in packages.keys():
         check = True
         release = packages.get(pkg).get('release')
         if 'available_platforms' in release:
             platforms = release.get('available_platforms')
             check = False
             current_platform = current_platform or util.get_systype()
             for platform in platforms:
                 check |= current_platform in platform
         if check:
             filtered_packages[pkg] = packages.get(pkg)
     return filtered_packages
Beispiel #3
0
 def _check_packages(self, packages, current_platform=''):
     filtered_packages = {}
     for pkg in packages.keys():
         check = True
         release = packages[pkg]['release']
         if 'available_platforms' in release:
             platforms = release['available_platforms']
             check = False
             current_platform = current_platform or get_systype()
             for platform in platforms:
                 check |= current_platform in platform
         if check:
             filtered_packages[pkg] = packages[pkg]
     return filtered_packages
Beispiel #4
0
 def _check_packages(self, packages, current_platform=''):
     filtered_packages = {}
     for pkg in packages.keys():
         check = True
         release = packages.get(pkg).get('release')
         if 'available_platforms' in release:
             platforms = release.get('available_platforms')
             check = False
             current_platform = current_platform or util.get_systype()
             for platform in platforms:
                 check |= current_platform in platform
         if check:
             filtered_packages[pkg] = packages.get(pkg)
     return filtered_packages
Beispiel #5
0
    def check_platform(self, board_data):
        if 'platform' not in board_data:
            return

        platform = board_data.get('platform')
        current_platform = util.get_systype()
        if platform != current_platform:
            # Incorrect platform
            if platform == 'linux_armv7l':
                raise Exception(
                    'incorrect platform: RPI2 or RPI3 required')
            else:
                raise Exception(
                    'incorrect platform {0}'.format(platform))
Beispiel #6
0
 def _check_packages(self, packages, current_platform=''):
     filtered_packages = {}
     for pkg in packages.keys():
         check = True
         release = packages[pkg]['release']
         if 'available_platforms' in release:
             platforms = release['available_platforms']
             check = False
             current_platform = current_platform or get_systype()
             for platform in platforms:
                 check |= current_platform in platform
         if check:
             filtered_packages[pkg] = packages[pkg]
     return filtered_packages
Beispiel #7
0
def cli(ctx, lsftdi, lsusb, info):
    """System tools.\n
       Install with `apio install system`"""

    exit_code = 0

    if lsftdi:
        exit_code = System().lsftdi()
    elif lsusb:
        exit_code = System().lsusb()
    elif info:
        click.secho('Platform: ', nl=False)
        click.secho(get_systype(), fg='yellow')
    else:
        click.secho(ctx.get_help())

    ctx.exit(exit_code)
Beispiel #8
0
def cli(ctx, lsftdi, lsusb, info):
    """System tools.\n
       Install with `apio install system`"""

    exit_code = 0

    if lsftdi:
        exit_code = System().lsftdi()
    elif lsusb:
        exit_code = System().lsusb()
    elif info:
        click.secho('Platform: ', nl=False)
        click.secho(get_systype(), fg='yellow')
    else:
        click.secho(ctx.get_help())

    ctx.exit(exit_code)
Beispiel #9
0
    def get_programmer(self, board, ext_serial, ext_ftdi_id, sram):
        programmer = ''

        if board:
            board_data = self.resources.boards.get(board)

            # Check platform
            self.check_platform(board_data)

            # Check pip packages
            self.check_pip_packages(board_data)

            # Serialize programmer command
            programmer = self.serialize_programmer(board_data, sram)

            # Replace USB vendor id
            if '${VID}' in programmer:
                vid = board_data.get('usb').get('vid')
                programmer = programmer.replace('${VID}', vid)

            # Replace USB product id
            if '${PID}' in programmer:
                pid = board_data.get('usb').get('pid')
                programmer = programmer.replace('${PID}', pid)

            # Replace FTDI index
            if '${FTDI_ID}' in programmer:
                self.check_usb(board, board_data)
                ftdi_id = self.get_ftdi_id(board, board_data, ext_ftdi_id)
                programmer = programmer.replace('${FTDI_ID}', ftdi_id)

            # TinyFPGA BX board is not detected in MacOS HighSierra
            if 'tinyprog' in board_data and 'darwin' in util.get_systype():
                # In this case the serial check is ignored
                return 'tinyprog --libusb --program'

            # Replace Serial port
            if '${SERIAL_PORT}' in programmer:
                self.check_usb(board, board_data)
                device = self.get_serial_port(board, board_data, ext_serial)
                programmer = programmer.replace('${SERIAL_PORT}', device)

        return programmer
Beispiel #10
0
    def get_programmer(self, board, ext_serial, ext_ftdi_id, sram):
        programmer = ''

        if board:
            board_data = self.resources.boards.get(board)

            # Check platform
            self.check_platform(board_data)

            # Check pip packages
            self.check_pip_packages(board_data)

            # Serialize programmer command
            programmer = self.serialize_programmer(board_data, sram)

            # Replace USB vendor id
            if '${VID}' in programmer:
                vid = board_data.get('usb').get('vid')
                programmer = programmer.replace('${VID}', vid)

            # Replace USB product id
            if '${PID}' in programmer:
                pid = board_data.get('usb').get('pid')
                programmer = programmer.replace('${PID}', pid)

            # Replace FTDI index
            if '${FTDI_ID}' in programmer:
                self.check_usb(board, board_data)
                ftdi_id = self.get_ftdi_id(board, board_data, ext_ftdi_id)
                programmer = programmer.replace('${FTDI_ID}', ftdi_id)

            # TinyFPGA BX board is not detected in MacOS HighSierra
            if 'tinyprog' in board_data and 'darwin' in util.get_systype():
                # In this case the serial check is ignored
                return 'tinyprog --libusb --program'

            # Replace Serial port
            if '${SERIAL_PORT}' in programmer:
                self.check_usb(board, board_data)
                device = self.get_serial_port(board, board_data, ext_serial)
                programmer = programmer.replace('${SERIAL_PORT}', device)

        return programmer
Beispiel #11
0
# -*- coding: utf-8 -*-
# -- This file is part of the Apio project
# -- (C) 2016 FPGAwars
# -- Author Jesús Arroyo
# -- Licence GPLv2

import click
import subprocess

from os.path import join, dirname, isfile

from apio.util import get_systype

platform = get_systype()


class Drivers(object):  # pragma: no cover

    rules_local_path = join(dirname(__file__), '..', 'resources',
                            '80-icestick.rules')
    rules_system_path = '/etc/udev/rules.d/80-icestick.rules'

    def enable(self):
        if 'linux' in platform:
            self._enable_linux()
        elif 'darwin' in platform:
            self._enable_darwin()
        elif 'windows' in platform:
            self._enable_windows()

    def disable(self):
Beispiel #12
0
# -*- coding: utf-8 -*-
# -- This file is part of the Apio project
# -- (C) 2016-2017 FPGAwars
# -- Author Jesús Arroyo
# -- Licence GPLv2

import os
import click
import subprocess

from os.path import isfile, isdir

from apio import util
from apio.profile import Profile

platform = util.get_systype()

FTDI_INSTALL_DRIVER_INSTRUCTIONS = """
   FTDI driver installation:
   Usage instructions

      1. Connect the FTDI FPGA board
      2. Select (Interface 0)
      3. Replace driver by "libusbK"
      4. Reconnect the board
      5. Check `apio system --lsftdi`
"""

FTDI_UNINSTALL_DRIVER_INSTRUCTIONS = """
   FTDI driver uninstallation:
   Usage instructions
Beispiel #13
0
    def upload(self, args, device=-1):
        ret = self.process_arguments(args)
        if isinstance(ret, int):
            return ret
        if isinstance(ret, tuple):
            variables, board = ret

        # Get programmer value
        programmer = ''
        if board:
            p = self.resources.boards[board]['programmer']
            type = p['type']
            content = self.resources.programmers[type]
            extra_args = p['extra_args'] if 'extra_args' in p else ''
            command = content['command'] if 'command' in content else ''
            args = content['args'] if 'args' in content else ''
            programmer = '{0} {1} {2}'.format(command, args, extra_args)

        # -- Check
        check = self.resources.boards[board]['check']

        # Check FTDI description
        if 'ftdi-desc' in check:
            detected_boards = System().detect_boards()
            if isinstance(detected_boards, int):
                return detected_boards

            if device:
                # Check device argument
                if board:
                    desc = check['ftdi-desc']
                    found = False
                    for b in detected_boards:
                        # Selected board
                        if device == b['index']:
                            # Check the device ftdi description
                            if desc in b['description']:
                                found = True
                            break
                    if not found:
                        device = -1
                else:
                    # Check device id
                    if int(device) >= len(detected_boards):
                        device = -1
            else:
                # Detect device
                device = -1
                if board:
                    desc = check['ftdi-desc']
                    for b in detected_boards:
                        if desc in b['description']:
                            # Select the first board that validates
                            # the ftdi description
                            device = b['index']
                            break
                else:
                    # Insufficient arguments
                    click.secho(
                        'Error: insufficient arguments: device or board',
                        fg='red')
                    click.secho(
                        'You have two options:\n' +
                        '  1) Execute your command with\n' +
                        '       `--device <deviceid>`\n' +
                        '  2) Execute your command with\n' +
                        '       `--board <boardname>`',
                        fg='yellow')
                    return 1

            if device == -1:
                # Board not detected
                click.secho('Error: board not detected', fg='red')
                return 1

        # Check platforms
        if 'platform' in check:
            # Device argument is ignored
            if device and device != -1:
                click.secho(
                    'Info: ignore device argument {0}'.format(device),
                    fg='yellow')

            platform = check['platform']
            current_platform = util.get_systype()
            if platform != current_platform:
                # Incorrect platform
                if platform == 'linux_armv7l':
                    click.secho(
                        'Error: incorrect platform: RPI2 or RPI3 required',
                        fg='red')
                else:
                    click.secho(
                        'Error: incorrect platform {0}'.format(platform),
                        fg='red')
                return 1

        return self.run('upload',
                        variables + ['device={0}'.format(device),
                                     'prog={0}'.format(programmer)],
                        board,
                        deps=['scons', 'icestorm'])
Beispiel #14
0
 def _get_platform(self):
     return util.get_systype()
Beispiel #15
0
# -*- coding: utf-8 -*-
# -- This file is part of the Apio project
# -- (C) 2016 FPGAwars
# -- Author Jesús Arroyo
# -- Licence GPLv2

import os
import click
import subprocess

from os.path import join, dirname, isfile, isdir

from apio import util

platform = util.get_systype()

FTDI_INSTALL_DRIVER_INSTRUCTIONS = """
   FTDI driver installation:
   Usage instructions

      1. Connect the FTDI FPGA board
      2. Select (Interface 0)
      3. Replace driver by "libusbK"
      4. Reconnect the board
      5. Check `apio system --lsftdi`
"""

FTDI_UNINSTALL_DRIVER_INSTRUCTIONS = """
   FTDI driver uninstallation:
   Usage instructions
Beispiel #16
0
 def _get_architecture(self):
     return util.get_systype()
Beispiel #17
0
 def _get_platform(self):
     return util.get_systype()
Beispiel #18
0
    def upload(self, args, device=-1):
        ret = self.process_arguments(args)
        if isinstance(ret, int):
            return ret
        if isinstance(ret, tuple):
            variables, board = ret

        # Get programmer value
        programmer = ''
        if board:
            p = self.resources.boards[board]['programmer']
            type = p['type']
            content = self.resources.programmers[type]
            extra_args = p['extra_args'] if 'extra_args' in p else ''
            command = content['command'] if 'command' in content else ''
            args = content['args'] if 'args' in content else ''
            programmer = '{0} {1} {2}'.format(command, args, extra_args)

        # -- Check
        check = self.resources.boards[board]['check']

        # Check FTDI description
        if 'ftdi-desc' in check:
            detected_boards = System().detect_boards()
            if isinstance(detected_boards, int):
                return detected_boards

            if device:
                # Check device argument
                if board:
                    desc = check['ftdi-desc']
                    found = False
                    for b in detected_boards:
                        # Selected board
                        if device == b['index']:
                            # Check the device ftdi description
                            if desc in b['description']:
                                found = True
                            break
                    if not found:
                        device = -1
                else:
                    # Check device id
                    if int(device) >= len(detected_boards):
                        device = -1
            else:
                # Detect device
                device = -1
                if board:
                    desc = check['ftdi-desc']
                    for b in detected_boards:
                        if desc in b['description']:
                            # Select the first board that validates
                            # the ftdi description
                            device = b['index']
                            break
                else:
                    # Insufficient arguments
                    click.secho(
                        'Error: insufficient arguments: device or board',
                        fg='red')
                    click.secho('You have two options:\n' +
                                '  1) Execute your command with\n' +
                                '       `--device <deviceid>`\n' +
                                '  2) Execute your command with\n' +
                                '       `--board <boardname>`',
                                fg='yellow')
                    return 1

            if device == -1:
                # Board not detected
                click.secho('Error: board not detected', fg='red')
                return 1

        # Check platforms
        if 'platform' in check:
            # Device argument is ignored
            if device and device != -1:
                click.secho('Info: ignore device argument {0}'.format(device),
                            fg='yellow')

            platform = check['platform']
            current_platform = util.get_systype()
            if platform != current_platform:
                # Incorrect platform
                if platform == 'linux_armv7l':
                    click.secho(
                        'Error: incorrect platform: RPI2 or RPI3 required',
                        fg='red')
                else:
                    click.secho(
                        'Error: incorrect platform {0}'.format(platform),
                        fg='red')
                return 1

        return self.run('upload',
                        variables +
                        ['prog={0}'.format(programmer.replace('%D%', device))],
                        board,
                        deps=['scons', 'icestorm'])