imx8x: Add boot target
authorLukas Humbel <lukas.humbel@inf.ethz.ch>
Wed, 16 Oct 2019 15:28:16 +0000 (17:28 +0200)
committerLukas Humbel <lukas.humbel@inf.ethz.ch>
Wed, 16 Oct 2019 15:28:34 +0000 (17:28 +0200)
make usbboot_imx8x will build and boot

Signed-off-by: Lukas Humbel <lukas.humbel@inf.ethz.ch>

platforms/Hakefile
tools/imx8x/aux-bf-boot/boot.cmd [new file with mode: 0644]
tools/imx8x/aux-bf-boot/boot.scr [new file with mode: 0644]
tools/imx8x/aux-bf-boot/uuu.auto [new file with mode: 0644]
tools/imx8x/bf-boot.sh [new file with mode: 0755]
tools/imx8x/board-tools.sh [new file with mode: 0644]
tools/imx8x/board_ctrl.py [new file with mode: 0755]

index 797a6a7..148ee8e 100644 (file)
@@ -798,6 +798,13 @@ let bin_rcce_lu = [ "/sbin/" ++ f | f <- [
       In BuildTree "tools" "/bin/usbboot",
       In BuildTree "root" "/armv7_omap44xx_image"
     ]
+    "Boot Barrelfish on a Pandaboard, over a local USB cable",
+
+    boot "usbboot_imx8x" [ "armv8" ] [
+      In SrcTree "tools" "/tools/imx8x/bf-boot.sh",
+      Str "--bf",
+      In BuildTree "root" "/armv8_imx8x_image.efi"
+    ]
     "Boot Barrelfish on a Pandaboard, over a local USB cable"
 
  ]
diff --git a/tools/imx8x/aux-bf-boot/boot.cmd b/tools/imx8x/aux-bf-boot/boot.cmd
new file mode 100644 (file)
index 0000000..94ad375
--- /dev/null
@@ -0,0 +1 @@
+bootefi 0x90000000
diff --git a/tools/imx8x/aux-bf-boot/boot.scr b/tools/imx8x/aux-bf-boot/boot.scr
new file mode 100644 (file)
index 0000000..0fcd896
Binary files /dev/null and b/tools/imx8x/aux-bf-boot/boot.scr differ
diff --git a/tools/imx8x/aux-bf-boot/uuu.auto b/tools/imx8x/aux-bf-boot/uuu.auto
new file mode 100644 (file)
index 0000000..95c4b7e
--- /dev/null
@@ -0,0 +1,9 @@
+uuu_version 1.2.91
+
+CFG: FB: -vid 0x0525 -pid 0x4026
+FB: ucmd setenv fastboot_buffer 0x82e00000
+FB: download -f boot.scr
+FB: ucmd setenv fastboot_buffer 0x90000000
+FB: download -f image.efi
+FB: acmd source 0x82e00000
+FB: done
diff --git a/tools/imx8x/bf-boot.sh b/tools/imx8x/bf-boot.sh
new file mode 100755 (executable)
index 0000000..8d803a7
--- /dev/null
@@ -0,0 +1,109 @@
+#!/bin/bash
+############################################################################
+# Copyright (c) 2019 ETH Zurich.
+# All rights reserved.
+#
+# This file is distributed under the terms in the attached LICENSE file.
+# If you do not find this file, copies can be found by writing to:
+# ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich,
+# Attn: Systems Group.
+#
+# Shell script for booting Barrelfish on SoCs with U-Boot using SDP and UUU
+#
+############################################################################
+
+set -e 
+
+SCRIPT_DIR=$(dirname $0)
+
+usage() { 
+    echo "Usage: $0 <options>"
+    echo "   --bf: Barrelfish image (required)"
+    echo "   --board: Select board"
+    echo "   --no-reset: Don't reset the board"
+    echo ""
+    echo "The script assumes that uuu is either on your"
+    echo "search path or the UUU environment variables is set."
+    exit 1;
+}
+
+while [ $# -ne 0 ]; do
+    case $1 in
+       "--bf") 
+               BF_IMAGE=$2
+        shift 
+           ;;
+    "--board")
+        BOARD=$2
+        shift
+        ;;
+    "--no-reset") 
+               NO_RESET=1
+           ;;
+    "-h"|"--help")
+        usage
+        ;;
+       *) 
+           usage
+           ;;
+    esac
+    shift
+done
+
+UUU=${UUU:-"uuu"}
+if !(which $UUU > /dev/null); then
+    echo "\`${UUU}\` not found or not executable. Add to PATH or set UUU variable." >&2
+    exit 1
+fi
+
+if [ -z "$BF_IMAGE" ]; then
+    echo "No Barrelfish image specified." >&2
+    exit 1;
+fi
+
+source "${SCRIPT_DIR}/board-tools.sh"
+BOARD_CTRL="${SCRIPT_DIR}/board_ctrl.py"
+
+if [ ! -z "$BOARD" ]; then
+    BOARD_SERIAL=$(get_uart_serial_number $BOARD)
+    if [ $? -ne 0 ]; then
+        exit 1
+    fi
+    BOARD_CTRL="${BOARD_CTRL} --board ${BOARD_SERIAL}"
+fi
+
+if [ ${NO_RESET:-0} -eq 0 ]; then
+    echo ""
+    echo "Resetting board"
+    $BOARD_CTRL reset
+fi
+
+echo ""
+echo "Creating temp dir"
+TEMPDIR=$(mktemp -d)
+
+echo ""
+echo "Copying auxiliary files to ${TEMPDIR}"
+cp "${SCRIPT_DIR}/aux-bf-boot/boot.scr" "${TEMPDIR}/"
+cp "${SCRIPT_DIR}/aux-bf-boot/uuu.auto" "${TEMPDIR}/"
+
+echo ""
+echo "Copying Barrelfish image to ${TEMPDIR}"
+cp $BF_IMAGE "${TEMPDIR}/image.efi"
+
+# Wait for fastboot to be started, and udev rules have been applied...
+sleep 1
+if [ ! -z "$BOARD" ]; then
+    DEVPATH=$(get_otg_path_uuu $BOARD)
+    if [ $? -ne 0 ]; then
+        exit 1
+    fi
+    UUU="${UUU} -m ${DEVPATH}"
+fi
+
+echo ""
+echo "Flashing board"
+$UUU ${TEMPDIR}
+
+#Clean up
+rm -rf $TEMPDIR
diff --git a/tools/imx8x/board-tools.sh b/tools/imx8x/board-tools.sh
new file mode 100644 (file)
index 0000000..b74e571
--- /dev/null
@@ -0,0 +1,54 @@
+##########################################################################
+# Copyright (c) 2019 ETH Zurich.
+# All rights reserved.
+#
+# This file is distributed under the terms in the attached LICENSE file.
+# If you do not find this file, copies can be found by writing to:
+# ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich,
+# Attn: Systems Group.
+#
+# Tools for handling the boards
+#
+##########################################################################
+
+OTG_PREFIX="/dev/usbOtgColibri"
+UART_PREFIX="/dev/usbSerialColibri"
+
+get_usb_dev_path() {
+    DEVATTRS=$(udevadm info -a -n $1 2> /dev/null)
+    if [ $? -ne 0 ]; then
+        echo "Device \`$1\` not found." >&2
+        return 1
+    fi
+    BUSNUM=$(sed -En 's/[[:space:]]*ATTR\{busnum\}=="([0-9])"/\1/p' <<< ${DEVATTRS})
+    DEVPATH=$(sed -En 's/[[:space:]]*ATTR\{devpath\}=="([0-9](\.[0-9])*)"/\1/p' <<< ${DEVATTRS})
+    echo "${BUSNUM}:$DEVPATH"
+}
+
+get_uart_dev_path() {
+    get_usb_dev_path "${UART_PREFIX}$1"
+}
+
+get_otg_dev_path() {
+    get_usb_dev_path "${OTG_PREFIX}$1"
+}
+
+get_otg_path_uuu() {
+    # UUU wants the USB dev path in the format
+    # <bus:devpath> where devpath doesn't contain the separating
+    # '.' between the ports
+    DEVPATH=$(get_otg_dev_path $1)
+    if [ $? -ne 0 ]; then
+        return 1
+    fi
+    echo $(sed -n s/\\.//gp <<< ${DEVPATH})
+}
+
+get_uart_serial_number() { 
+    DEVATTRS=$(udevadm info -a -n ${UART_PREFIX}$1 2> /dev/null)
+    if [ $? -ne 0 ]; then
+        echo "Device \`${UART_PREFIX}$1\` not found." >&2
+        return 1
+    fi
+    echo $(sed -rn 's/[[:space:]]*ATTR\{serial\}=="([0-9A-Z]{8})"/\1/p' <<< ${DEVATTRS})
+}
diff --git a/tools/imx8x/board_ctrl.py b/tools/imx8x/board_ctrl.py
new file mode 100755 (executable)
index 0000000..7fbe9f6
--- /dev/null
@@ -0,0 +1,140 @@
+#!/usr/bin/python3
+##########################################################################
+# Copyright (c) 2019 ETH Zurich.
+# All rights reserved.
+#
+# This file is distributed under the terms in the attached LICENSE file.
+# If you do not find this file, copies can be found by writing to:
+# ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich,
+# Attn: Systems Group.
+#
+# Script to control the Toradex boards over the USB UART
+#
+##########################################################################
+
+import os
+import sys
+import time
+import usb
+import argparse
+import cmd
+
+class AOSBoard:
+    BITMODE_CBUS = 0x20
+    SIO_SET_BITMODE_REQUEST = 0x0b
+    
+    def __init__(self, dev):
+        self._dev = dev
+
+    def _ftdi_set_bitmode(self, bitmask):
+        """
+        FTDIs CBUS bitmode expect the following value:
+        CBUS Bits
+        3210 3210
+             |------ Output Control 0->LO, 1->HI
+        |----------- Input/Output   0->Input, 1->Output
+
+        This script assumes:
+        - CBUS3 connected to RESET_EXT# 
+        - CBUS2 connected to OE# (recovery mode)
+        """
+        bm_request_type = usb.util.build_request_type(
+            usb.util.CTRL_OUT,
+            usb.util.CTRL_TYPE_VENDOR,
+            usb.util.CTRL_RECIPIENT_DEVICE
+        )
+
+        wValue = bitmask | (AOSBoard.BITMODE_CBUS << 32)
+        self._dev.ctrl_transfer(bm_request_type, AOSBoard.SIO_SET_BITMODE_REQUEST, wValue)
+
+    def on(self):
+        # Set CBUS3 tristate, module run...
+        self._ftdi_set_bitmode(0x00)
+
+    def off(self):
+        # Set CBUS3 low, module in reset...
+        self._ftdi_set_bitmode(0x80)
+
+    def reset(self):
+        self.off()
+        time.sleep(0.1)
+        self.on()
+
+    def enter_recovery(self):
+        # Set recovery bit low
+        self._ftdi_set_bitmode(0x40)
+        time.sleep(0.2)
+        # Set reset bit low
+        self._ftdi_set_bitmode(0xC0)
+        time.sleep(0.1)
+        # Set reset bit tristate
+        self._ftdi_set_bitmode(0x40)
+        time.sleep(0.2)
+        # Set recovery bit tristate
+        self._ftdi_set_bitmode(0x00)
+
+class BoardShell(cmd.Cmd):
+
+    def __init__(self, board):
+        super().__init__()
+        self._board = board
+        self.prompt = "aos-ctrl> "
+
+    def do_on(self, args):
+        "Turn the board on."
+        self._board.on()
+
+    def do_off(self, args):
+        "Turn the board off."
+        self._board.off()
+
+    def do_reset(self, args):
+        "Reset the board."
+        self._board.reset()
+
+    def do_recovery(self, args):
+        "Reset the board and enter recovery mode."
+        self._board.enter_recovery()
+
+    def do_exit(self, args):
+        "Exit the command prompt."
+        return True
+
+    def postcmd(self, stop, line):
+        return stop
+
+def main(args):
+    dev = usb.core.find(
+        custom_match=lambda d: \
+            d.idVendor  == 0x0403 and
+            d.idProduct == 0x6001 and
+            (
+                (args.board is None) or
+                (d.serial_number == args.board)
+            )
+        )
+
+    if dev is None:
+        print("Board with serial '%s' not found." % (args.board), file=sys.stderr)
+        exit(1)
+    
+    board = AOSBoard(dev)
+
+    shell = BoardShell(board)
+    if args.command is None:
+        shell.cmdloop()
+    else:
+        shell.onecmd(args.command)
+    
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Controls the Toradex Colibri boards")
+    parser.add_argument(
+        "--board", "-b", metavar="SERIAL", type=str,
+        help="Serial of the board to control"
+    )
+    parser.add_argument(
+        "command", metavar="CMD", type=str, nargs='?',
+        help="Commands to run"
+    )
+    args = parser.parse_args()
+    main(args)