aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test/cli-test.c
AgeCommit message (Collapse)Author
2016-07-09Merge more code from projects/hsm.Fredrik Thulin
2016-06-16Merge branch 'master' into ft-ks_flashFredrik Thulin
2016-06-09Put all the keystore commands under 'keystore' instead.Fredrik Thulin
Makes more sense to keep them together, at least in the cli-test.
2016-06-09updated test-code for keystore functionalityFredrik Thulin
2016-06-08Include strings.h, for strcasecmp().Rob Austein
2016-06-07Don't reboot when CLI logout is intended.Paul Selkirk
2016-06-02Use DMA for UART RX instead of interrupts.Fredrik Thulin
DMA is more efficient and less prone to miss characters than interrupts. An open question is if circular mode is really the best. If someone copy-pastes more than the RX buffer size of configuration into the CLI, we risk the DMA controller catching up with the reader and overwriting data not yet read. Since we don't have flow control back to the users terminal, we will always fail if too much data is entered before we can process it. The question is if failing to stuff new data at the end of a buffer might be better than data being overwritten - thus messing up the commands in unpredictable ways.
2016-06-02Move the rest of the CLI commands out of cli-test.c.Fredrik Thulin
2016-06-01Implement circular buffer UART RX using interrupts.Fredrik Thulin
2016-06-01Move FPGA related commands to mgmt-fpga.cFredrik Thulin
2016-05-27DFU working - but no signature validation for now.Fredrik Thulin
2016-05-26Implement a bootloader.Fredrik Thulin
This bootloader is now the application at 0x08000000 (FLASH start), which the STM32 will execute upon reset. The other applications are now loaded at 0x08030000 (128 KB into the flash) and will never get started unless the bootloader has been programmed into flash too.
2016-05-25More DFU code. This might actually work.Fredrik Thulin
The applications to be uploaded using 'dfu upload' have to have another FLASH defined in their linker script. Have to recompile some firmware tomorrow and test if this actually works.
2016-05-24non-working code to upload an application and jump to itFredrik Thulin
Committing my work in progress in case someone else wants to help.
2016-05-24make 'test sdram' take number of iterations as argumentFredrik Thulin
2016-05-23SDRAM initialization and test code from Pavel.Fredrik Thulin
Integrated into the cli-test program as such: cryptech> test sdram Initializing SDRAM Starting SDRAM test (n = 0) Run sequential write-then-read test for the first chip Run random write-then-read test for the first chip Run sequential write-then-read test for the second chip Run random write-then-read test for the second chip Run interleaved write-then-read test for both chips at once SDRAM test (n = 0) completed SDRAM test completed successfully cryptech>
2016-05-21Add code to test reading, writing and erasing keystore data.Fredrik Thulin
2016-05-21Add code to access the keystore memory (SPI flash).Fredrik Thulin
2016-05-21Add some exciting defines to define commans in the CLI.Fredrik Thulin
Hopefully, having this excitement now makes adding commands a little bit less exciting from here on.
2016-05-20Add code to reset FPGA using FPGA_PROGRAM_B and FPGA_INIT_B.Fredrik Thulin
Also add code to erase FPGA config memory and check status of FPGA_DONE.
2016-05-19Refactor FPGA bitstream upload code.Fredrik Thulin
Move the N25Q128 code to it's own file in order to be able to reuse it for the keystore memory code.
2016-05-18Add FPGA bitstream upload command to cli-test.Fredrik Thulin
This code needs more error checking etc. but together with the Python script 'filetransfer', a new bitstream may be loaded into the FPGA config memory like this: filetransfer --fpga /path/to/bitstream The bitstream is identified by 'file' e.g. like this: alpha_test_top.bit: Xilinx BIT data - from alpha_test_top.ncd;UserID=0xFFFFFFFF - for 7a200tfbg484 - built 2016/05/12(13:59:24) - data length 0xe0164
2016-05-18A little more robust file transferFredrik Thulin
2016-05-18put some generic CLI code in mgmt-cli.cFredrik Thulin
2016-05-18Add reboot command.Fredrik Thulin
2016-05-18Write in 4k-chunks, with acks for flow control.Fredrik Thulin
2016-05-15add simple filetransfer pocFredrik Thulin
2016-05-13Add test program for libcli based CLI.Fredrik Thulin
background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */

STM32 software for dev-bridge/Alpha board

The dev-bridge board is a daughterboard for the Novena, which talks to the Novena's FPGA through the high-speed expansion connector.

The Alpha board is a stand-alone board with an Artix-7 FPGA, a STM32 Cortex-M4 microcontroller, two USB interfaces etc.

See user/ft/stm32-dev-bridge/hardware/rev01 for schematics of the bridge board. There will be more information on the wiki shortly.

Copyrights

The license for all work done on this in the CrypTech project is a 3-clause BSD license (see LICENSE.txt for details). Some files have been generated using the STMicroelectronics initialization code generator STM32CubeMX and thus have additional copyright header(s).

The "Noise generator" and "Amplifier" parts of the circuit diagram are copied from Benedikt Stockebrand's ARRGH project. ARRGH copyright statement is included in LICENSE.txt.

A stripped down copy of the ARM CMSIS library version 3.20 is included in the Drivers/CMSIS/ directory. Unused parts (and documentation etc.) have been removed, but every attempt have been made to keep any licensing information intact. See in particular the file Drivers/CMSIS/CMSIS END USER LICENCE AGREEMENT.pdf.

A full copy of the STM32F4xx HAL Drivers is included in the Drivers/STM32F4xx_HAL_Driver/ directory.

Building

The following packages need to be installed (on Ubuntu 14.04):

apt-get install gcc-arm-none-eabi gdb-arm-none-eabi openocd

To build the source code, issue "make" from the top level directory (where this file is). The first time, this will build the complete STM CMSIS library. A subsequent "make clean" will not clean away the CMSIS library, but a "make distclean" will.

Installing

Do "bin/flash-target" from the top level directory (where this file is) to flash a built image into the microcontroller. See the section ST-LINK below for information about the actual hardware programming device needed.

Example loading the bootloader and the led-test firmware to get some LEDs flashing:

$ make bootloader board-test $ ./bin/flash-target projects/board-test/led-test $ ./bin/flash-target projects/bootloader/bootloader

At this point, the STM32 will reset into the bootloader which flashes the blue LED five times in one second, and then execution of the LED test firmware will begin. The LED test firmware will flash the green, yellow, red and blue LEDs in order until the end of time.

Once the bootloader is installed, regular firmware can be loaded without an ST-LINK cable like this:

$ ./bin/dfu projects/board-test/led-test.bin

Then reboot the Alpha board.

ST-LINK

To program the MCU, an ST-LINK adapter is used. The cheapest way to get one is to buy an evaluation board with an ST-LINK integrated, and pinouts to program external chips. This should work with any evaluation board from STM; we have tested with STM32F4DISCOVERY (with ST-LINK v2.0) and NUCLEO-F411RE (with ST-LINK v2.1).

The ST-LINK programming pins is called J1 and is near the CrypTech logo printed on the circuit board. The pin-outs is shown on the circuit board (follow the thin white line from J1 to the white box with STM32_SWD written in it). From left to right, the pins are

3V3, CLK, GND, I/O, NRST and N/C

This matches the pin-out on the DISCO and NUCLEO boards we have tried.

First remove the pair of ST-LINK jumpers (CN4 on the DISCO, CN2 on the NUCLEO). Then find the 6-pin SWD header on the left of the STM board (CN2 on the DISCO, CN4 on the NUCLEO), and connect them to the Alpha board:

NUCLEO / DISCO       CRYPTECH ALPHA
--------------       --------------

N/C (pin 6) means Not Connected.

The Alpha board should be powered on before attempting to flash it.

Debugging the firmware

This site shows several ways to use various debuggers to debug the firmware in an STM32:

http://fun-tech.se/stm32/OpenOCD/gdb.php

There is a shell script called 'bin/debug' that starts an OpenOCD server and GDB. Example:

$ ./bin/debug projects/board-test/led-test

Once in GDB, issue "monitor reset halt" to reset the STM32 before debugging.

Remember that the first code to run will be the bootloader, but if you do e.g. "break main" and "continue" you will end up in led-test main() after the bootloader has jumped there.