Flying Stone Tiny 01G Test Plan

We need to specify a test plan to manufacture a board. In order to encourage designing and manufacturing by yourselves, we show our test plan for Flying Stone Tiny 01G here.

This makes the reproducibility better, I suppose.

Since our point is the users' computing freedom, we specifically use a special tool named BBG-SWD as a SWD debugger. BBG-SWD is BeagleBone Green, physically or hardware-wise. Software-wise, it's a patched version of OpenOCD. We control its GPIO pins for SWD signals. Following explanation assumes use of BBG-SWD.

NOTE: You can use a vendor supplied (proprietary) tool for SWD debugger like ST-Link/V2, if you want.

Introduction

FST-01G (Flying Stone Tiny 01G) is a small USB computer with a MCU.

The intended use of FST-01G is for cryptographic operations, like Gnuk or NeuG.

FST-01G uses STM32F103TB as MCU. It runs at 72MHz, and the architecture is a version of ARM, named Cortex-M3.

Here is FST-01G figure.

Top View of FST-01G:
                             WHITE BLACK
                    BLUE <---\  ^  ^
                             |  |  | SWD port (GND, SWD-CLK, SWD-IO)
    Power port +---------------------+
           Vdd |[]           []()() -------+
           GND |[]                  |      |
               |()() I/O port       | USB  |
               |                    |      |
               |                    -------+
               +---------------------+

On FST-01G, there are SWD port, Power port, I/O port, and USB port. We only use the SWD port in our test plan.

In our test plan, power is supplied through USB port.

Test Theory

With the SWD debugger (BBG-SWD), we flash the firmware into MCU. We use command-line (CLI) utility: OpenOCD patched for BBG-SWD.

The firmware to be written is NeuG, the true random generator. The filename of our firmware file is: neug.elf

We invoke the command from the command line shell. When executed, the utility control the SWD signals to flash into MCU.

After successful invocation of OpenOCD, the program runs on the board. FST-01G works as a USB Mass Storage Device, at start. LED should emit light at this point.

Then, we run a script to see USB works well. If it works well, we see the output: SUCCESS. Otherwise, we see FAILURE.

After running a script, LED of FST-01G blinks.

Test Tools

Hardware:

  • PC with Ethernet
  • BeagleBone Green (BBG) with microSD
  • USB Hub
  • USB Cable (to supply power BBG)
  • Wires to connect the board
  • Ethernet cable
  • Ethernet hub

Software:

  • Operating System on BBG: Debian GNU/Linux
  • a setup script checking USB of FST-01G: bbg-setup.sh
  • OpenOCD patched for BBG-SWD
  • a script checking USB of FST-01G: check-fst-01g.sh

Firmware: * NeuG: neug.elf

Preparation

Network Connection

PC and BBG is connected by Ethernet.

[Router]
  |
[ Ethernet Hub ]
  |       |
[PC]     [BBG]

Router offers IP addresses to PC and BBG by DHCP.

BBG connections

Here is a figure of BBG.

Top View of BeagleBone Green (BBG):
                                     Insert FST-01G here
                                              |
  /-[=================]----\                  V
  |                       +-+ USB  +--------------+
  |                       +-+======|   USB Hub    |
  []     BeagleBone        |       +--------------+
  |         Green        +--+
  []                     |  |=============> Ethernet
  |                      +--+
  |                        |==============> USB Power
  \-[=================]----/
               | | |
               V | | Wires to FST-01G SWD port
  BLACK (SWD-IO) | |
                 V |
   WHITE (SWD-CLK) V
                   BLUE (GND)

Power is supplied by USB to BBG (USB Power).

USB Hub is connected to BBG to connect FST-01G.

Three wires are connected from BBG GPIO port to FST-01 SWD port.

Pins for SWD access

We use three lines from BBG for SWD control.

GND P8_02 BLUE
SWD-IO P8_11 BLACK
SWD-CLK P8_12 WHITE
SRST P8_15 GREEN (not used)
GND P9_02 BLUE (not used)
VDD3V3 P9_04 RED (not used)

BBG-SWD also has SRST for resetting target board, but we don't use this signal for FST-01G.

SSH login to BBG

Log into BBG from PC by SSH. The username is "debian". Since the password is displayed when you connect to BBG, use the password.

Firmware ELF file

There is a file, neug.elf.

OpenOCD patched for BBG-SWD

OpenOCD is installed in /usr/local.

Test Procedure

Become ROOT

Type "sudo" command to be ROOT:

debian@beaglebone:~$ sudo -s

Then, the prompt will be changed to the one with "#".

Execution of the setup script

  1. Execute the setup script (only once after login):

    # ./bbg-setup.sh
    

This command execution is only done at the first time.

Execution of OpenOCD

  1. Execute the openocd command:

    # openocd -f stm32f1x-bbg-swd.cfg -f fst01g-flash-write.tcl
    
  2. Expected behavior of the board and expected output of the command

    Successfully done, output is something like:

    Open On-Chip Debugger 0.10.0-dev-00323-g9601c25-dirty (2016-06-22-01:41)
    Licensed under GNU GPL v2
    For bug reports, read
       http://openocd.org/doc/doxygen/bugs.html
    Info : only one transport option; autoselect 'swd'
    adapter speed: 1000 kHz
    adapter_nsrst_delay: 100
    none separate
    cortex_m reset_config sysresetreq
    none separate
    adapter_nsrst_assert_width: 1
    Info : BBG-SWD: Interface ready
    Info : clock speed 1000 kHz
    Info : SWD DPIDR 0x1ba01477
    Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
    Error: stm32f1x.cpu -- clearing lockup after double fault
    Polling target stm32f1x.cpu failed, trying to reexamine
    Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
    stm32f1x.cpu: target state: halted
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
    Info : device id = 0x20036410
    Info : flash size = 128kbytes
    Option Byte: 0x3fffffc
    Readout Protection Off
    Software Watchdog
    Stop: No reset generated
    Standby: No reset generated
    User Option0: 0xff
    User Option1: 0xff
    auto erase enabled
    wrote 82944 bytes from file neug.elf in 4.369664s (18.537 KiB/s)
    shutdown command invoked
    

    The line "wrote 82944 bytes from file neug.elf" means success. When failure, you won't be able to see this line.

    After successful programming of flash, the LED on FST-01G emits light.

  3. Execute the checking script:

    # ./check-fst-01g.sh
    
  4. Expected behavior of the board and expected output of the script

    Successfully done, output is:

    /mnt/COPYING: OK
    /mnt/INDEX.HTM: OK
    /mnt/README: OK
    SUCCESS
    

    This means that these files on FST-01G are correct.

    LED blinks after this command.

To repeat writing and checking for another board of FST-01G, you can use command line history of BASH; You can use arrow key UP (↑) to repeat same command line.

Test Result

Please record the test results:

  1. Success/failure of OpenOCD command.
  2. LED behavior: if it emits light or not.
  3. Success/failure of the checking script.

Those three should be successful.

Example connection

Here are photo of example connection.

BBG-SWD connected to FST-01G

In this configuration, there are other wires (GREEN, BLUE and RED) which are unused.

Output of example session

Here is a example session:

gniibe@iwagami$ ssh debian@192.168.2.113
Debian GNU/Linux 8

BeagleBoard.org Debian Image 2016-01-24

Support/FAQ: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian

default username:password is [debian:temppwd]

debian@192.168.2.113's password:
Last login: Fri Dec 30 05:03:02 2016 from 192.168.2.109
debian@beaglebone:~$ sudo -s
root@beaglebone:/home/debian# ./bbg-setup.sh
root@beaglebone:/home/debian# openocd -f stm32f1x-bbg-swd.cfg -f fst01g-flash-write.tcl
Open On-Chip Debugger 0.10.0-dev-00323-g9601c25-dirty (2016-06-22-01:41)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
cortex_m reset_config sysresetreq
none separate
adapter_nsrst_assert_width: 1
Info : BBG-SWD: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x1ba01477
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Error: stm32f1x.cpu -- clearing lockup after double fault
Polling target stm32f1x.cpu failed, trying to reexamine
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
stm32f1x.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
Info : device id = 0x20036410
Info : flash size = 128kbytes
Option Byte: 0x3fffffc
Readout Protection Off
Software Watchdog
Stop: No reset generated
Standby: No reset generated
User Option0: 0xff
User Option1: 0xff
auto erase enabled
wrote 82944 bytes from file tmp/gnuk/neug/src/build/neug.elf in 4.450901s (18.199 KiB/s)
shutdown command invoked
root@beaglebone:/home/debian# ./check-fst-01g.sh
/mnt/COPYING: OK
/mnt/INDEX.HTM: OK
/mnt/README: OK
SUCCESS
root@beaglebone:/home/debian#

More information about BBG-SWD

The version in use is BBG-SWD 0.02. The source code is available at: https://git.gniibe.org/gitweb/?p=bbg-swd.git

The patch for OpenOCD is against the commit:

406f4d1c68330e3bf8d9db4e402fd8802a5c79e2

The root file system is based on Debian Jessie. /ID.txt says:

BeagleBoard.org Debian Image 2016-01-24

The kernel in use is 4.4.5-bone5. For BBG-SWD, "ti-rt" kernel does not work well because PRUSS support is different in this kernel.

The program for PRUSS is in:

/usr/local/share/openocd/bbg-swd/pru-swd.bin

Its source code is available in BBG-SWD repo.

More Information

USB Hub

I connect USB Hub to BeagleBone Green for two purposes.

  1. It allows flexibility for the wire connection of SWD between BBG and FST-01G.
  2. For some reasons, BeagleBone Green's root hub doesn't work well after FST-01G's reset (using 4.4.5-bone5 kernel). With external USB Hub, it works well.

bbg-setup.sh

The content is:

#! /bin/sh

echo gpio >/sys/devices/platform/ocp/ocp:P8_12_pinmux/state
echo gpio >/sys/devices/platform/ocp/ocp:P8_11_pinmux/state
echo gpio_pu >/sys/devices/platform/ocp/ocp:P8_15_pinmux/state

check-fst-01g.sh

The content is:

#! /bin/bash -e

mount /dev/sda /mnt
sha256sum -c <<EOF
8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903  /mnt/COPYING
b1d5ba03e787e8f4f8a06a6e7fc37279a7eae18a4bab2d0f9192e928830db568  /mnt/INDEX.HTM
756ae8f73580117a9ff47bd7dda4807adc33b78baddf3a56eb4ab1d3e6d1007f  /mnt/README
EOF
umount /mnt
eject /dev/sda
echo SUCCESS

stm32f1x-bbg-swd.cfg

The content is:

interface bbg-swd
source [find target/stm32f1x.cfg]
reset_config none
adapter_nsrst_assert_width 1

fst01g-flash-write.tcl

The content is:

init
reset halt
#
stm32f1x options_read 0
#
flash write_image erase neug.elf
#
reset run
#
shutdown

FST-01G flashed with NeuG 1.0.5

Note that the flash ROM is not protected by this test plan, so that an enduser can check the content of the flash ROM.