usbarmory

package
v0.0.0-...-d73fcdd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package usbarmory provides hardware initialization, automatically on import, for the USB armory Mk II single board computer.

This package is only meant to be used with `GOOS=tamago GOARCH=arm` as supported by the TamaGo framework for bare metal Go on ARM SoCs, see https://github.com/f-secure-foundry/tamago.

Index

Constants

View Source
const (
	// BT_UART_TX (UART1_TX_DATA)
	IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA = 0x020e0084
	IOMUXC_SW_PAD_CTL_PAD_UART1_TX_DATA = 0x020e0310

	// BT_UART_RX (UART1_RX_DATA)
	IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA = 0x020e0088
	IOMUXC_SW_PAD_CTL_PAD_UART1_RX_DATA = 0x020e0314
	IOMUXC_UART1_RX_DATA_SELECT_INPUT   = 0x020e0624
	DAISY_UART1_RX_DATA                 = 0b11

	// BT_UART_CTS (UART1_CTS_B)
	IOMUXC_SW_MUX_CTL_PAD_UART1_CTS_B = 0x020e008c
	IOMUXC_SW_PAD_CTL_PAD_UART1_CTS_B = 0x020e0318

	// BT_UART_RTS (UART1_RTS_B)
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO07 = 0x020e0078
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO07 = 0x020e0304
	IOMUXC_UART1_RTS_B_SELECT_INPUT  = 0x020e0620
	UART1_RTS_B_MODE                 = 8
	DAISY_GPIO1_IO07                 = 0b01

	// BT_UART_DSR (GPIO1_IO24)
	IOMUXC_SW_MUX_CTL_PAD_UART3_TX_DATA = 0x020e00a4
	IOMUXC_SW_PAD_CTL_PAD_UART3_TX_DATA = 0x020e0330

	// BT_UART_DTR (GPIO1_IO25)
	IOMUXC_SW_MUX_CTL_PAD_UART3_RX_DATA = 0x020e00a8
	IOMUXC_SW_PAD_CTL_PAD_UART3_RX_DATA = 0x020e0334

	// BT_SWDCLK
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO04 = 0x020e006c
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO04 = 0x020e02f8

	// BT_SWDIO
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO06 = 0x020e0074
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO06 = 0x020e0300

	// BT_RESET
	BT_RESET                         = 9
	IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO09 = 0x020e0080
	IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO09 = 0x020e030c

	// BT_SWITCH_1 (GPIO1_IO27)
	BT_SWITCH_1                       = 27
	IOMUXC_SW_MUX_CTL_PAD_UART3_RTS_B = 0x020e00b0
	IOMUXC_SW_PAD_CTL_PAD_UART3_RTS_B = 0x020e033c

	// BT_SWITCH_2 (GPIO1_IO26)
	BT_SWITCH_2                       = 26
	IOMUXC_SW_MUX_CTL_PAD_UART3_CTS_B = 0x020e00ac
	IOMUXC_SW_PAD_CTL_PAD_UART3_CTS_B = 0x020e0338

	DEFAULT_MODE = 0
	GPIO_MODE    = 5

	RESET_GRACE_TIME = 1 * time.Second
)

BLE module configuration constants.

On the USB armory Mk II a u-blox ANNA-B112 Bluetooth module is connected as illustrated in the following constants.

On the USB armory Mk II β revision, due to an errata, the RTS/CTS signals are connected inverted on the Bluetooth module side. This is automatically handled with a workaround by the RTS() and CTS() functions, which use the lines as GPIOs to invert their direction.

View Source
const (
	// Power management controller
	PF1510_ADDR = 0x08
	// Cryptographic co-processor (rev. γ only)
	SE050_ADDR = 0x48
	// Cryptographic co-processor (rev. β only)
	A71CH_ADDR = 0x48
	// Cryptographic co-processor (rev. β only)
	ATECC_ADDR = 0x60
	// Type-C plug port controller
	TUSB320_ADDR = 0x61
	// Type-C receptacle port controller
	FUSB303_ADDR = 0x31
)

The USB armory Mk II has the following components accessible as I²C slaves.

View Source
const (
	// GPIO number
	WHITE = 21
	// mux control
	IOMUXC_SW_MUX_CTL_PAD_CSI_DATA00 = 0x020e01e4
	// pad control
	IOMUXC_SW_PAD_CTL_PAD_CSI_DATA00 = 0x020e0470

	// GPIO number
	BLUE = 22
	// mux control
	IOMUXC_SW_MUX_CTL_PAD_CSI_DATA01 = 0x020e01e8
	// pad control
	IOMUXC_SW_PAD_CTL_PAD_CSI_DATA01 = 0x020e0474
)

LED configuration constants

On the USB armory Mk II the following LEDs are connected:

  • pad CSI_DATA00, GPIO4_IO21: white
  • pad CSI_DATA01, GPIO4_IO22: blue
View Source
const (
	IOMUXC_SW_MUX_CTL_PAD_ENET1_TX_EN = 0x020e00d8
	IOMUXC_SW_PAD_CTL_PAD_ENET1_TX_EN = 0x020e0364

	WDOG2_WDOG_RST_B_DEB_MODE = 8
)

On the USB armory Mk II the PMIC watchdog input (WDI) is connected to the SoC external reset source (WDOG2_WDOG_RST_B_DEB) through ENET1_TX_EN/KPP_COL2 (p4081, Table 59-1. WDOG External Signals, IMX6ULLRM).

View Source
const (
	FUSB303_CONTROL1 = 0x05
	CONTROL1_ENABLE  = 3

	FUSB303_TYPE = 0x13
)

Receptacle USB port controller constants

View Source
const (
	TYPE_DEBUGSRC    = 1 << 6
	TYPE_DEBUGSNK    = 1 << 5
	TYPE_SINK        = 1 << 4
	TYPE_SOURCE      = 1 << 3
	TYPE_ACTIVECABLE = 1 << 2
	TYPE_AUDIOVBUS   = 1
	TYPE_AUDIO       = 0
)

Receptacle USB port controller modes

View Source
const (
	REV_BETA = iota
	REV_GAMMA
)
View Source
const (
	IOMUXC_SW_MUX_CTL_PAD_CSI_DATA04 = 0x020e01f4
	IOMUXC_SW_PAD_CTL_PAD_CSI_DATA04 = 0x020e0480
	IOMUXC_USDHC1_WP_SELECT_INPUT    = 0x020e066c

	USDHC1_WP_MODE   = 8
	DAISY_CSI_DATA04 = 0b10

	IOMUXC_SW_MUX_CTL_PAD_CSI_PIXCLK = 0x020e01d8
	IOMUXC_SW_PAD_CTL_PAD_CSI_PIXCLK = 0x020e0464
	IOMUXC_USDHC2_WP_SELECT_INPUT    = 0x020e069c

	USDHC2_WP_MODE   = 1
	DAISY_CSI_PIXCLK = 0b10

	SD_BUS_WIDTH  = 4
	MMC_BUS_WIDTH = 8

	PF1510_LDO3_VOLT = 0x52
	LDO3_VOLT_1V8    = 0x10
	LDO3_VOLT_3V3    = 0x1f
)

SD/MMC configuration constants.

On the USB armory Mk II the following uSDHC interfaces are connected:

  • uSDHC1: external uSD slot (SD1)
  • uSDHC2: internal eMMC card (SD2/NAND)

On the USB armory Mk II β revision the maximum achievable theoretical speed modes are:

  • uSD: High Speed (HS) 25MB/s, 50MHz, 3.3V, 4-bit data bus
  • eMMC: High Speed (HS) DDR 104MB/s, 52MHz, 3.3V, 8-bit data bus

On the USB armory Mk II γ revision the maximum achievable theoretical speed modes are:

  • uSD: SDR104 75MB/s, 150MHz, 1.8V, 4-bit data bus
  • eMMC: HS200 150MB/s, 150MHz, 1.8V, 8-bit data bus
View Source
const OCOTP_MAC0 = 0x021bc620

Variables

View Source
var BLE = &ANNA{}

BLE module instance

MMC instance

SD instance

Functions

func DetectDebugAccessory

func DetectDebugAccessory(timeout time.Duration) (<-chan bool, error)

DetectDebugAccessory enables debug accessory detection on the receptacle USB port controller and polls successful detection (typically done in up to 200ms).

An error is returned if no debug accessory is detected within the timeout.

On the returned boolean channel are sent successful detection (true) or timeout (false).

func EnableDebugAccessory

func EnableDebugAccessory() (err error)

EnableDebugAccessory enables debug accessory detection on the receptacle USB port controller.

A debug accessory allows access, among all other debug signals, to the UART2 serial console.

Note that there is a delay (typically up to 200ms) between the return of this call and the actual enabling of the debug accessory, for this reason the serial console is not immediately available.

To wait detection of a debug accessory use DetectDebugAccessory() instead.

func EnableReceptacleController

func EnableReceptacleController() (err error)

EnableReceptacleController activates the receptacle USB port controller.

func Init

func Init()

Init takes care of the lower level SoC initialization triggered early in runtime setup.

func LED

func LED(name string, on bool) (err error)

LED turns on/off an LED by name.

func Model

func Model() (model string)

Model returns the USB armory model name, to further detect SoC variants imx6.Model() can be used.

func ReceptacleMode

func ReceptacleMode() (mode int, err error)

ReceptacleMode returns the type of device or accessory detected by the receptacle USB port controller.

func Reset

func Reset()

Reset deasserts the PMIC watchdog signal (through the SoC external reset source) causing the USB armory Mk II board to power cycle (cold reset).

Types

type ANNA

type ANNA struct {
	sync.Mutex

	UART *imx6.UART
	// contains filtered or unexported fields
}

ANNA implements the interface to the ANNA-B112 module for serial communication, reset and mode select.

func (*ANNA) BootloaderMode

func (ble *ANNA) BootloaderMode() (err error)

Enter bootloader mode by driving low SWITCH_1 and SWITCH_2 during a module reset cycle.

func (*ANNA) CTS

func (ble *ANNA) CTS(clear bool)

CTS signals the BLE module whether it is allowed to send or not data, only useful on β boards when a workaround to the RTS/CTS errata is required.

func (*ANNA) Init

func (ble *ANNA) Init() (err error)

Init initializes, in normal mode, a BLE module instance.

func (*ANNA) NormalMode

func (ble *ANNA) NormalMode() (err error)

Enter normal mode by driving high SWITCH_1 and SWITCH_2 during a module reset cycle.

func (*ANNA) RTS

func (ble *ANNA) RTS() (ready bool)

RTS returns whether the BLE module allows to send or not data, only useful on β boards when a workaround to the RTS/CTS errata is required.

func (*ANNA) Reset

func (ble *ANNA) Reset() (err error)

Reset the BLE module by toggling the RESET_N pin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL