AN00153 Programming OTP Memory Via SPI Boot 1.0.2rc1
AN00153 Programming OTP Memory Via SPI Boot 1.0.2rc1
2)
Required hardware
This application note is designed to run on any XMOS xCORE multicore microcontroller that is able to
boot from SPI and has OTP memory available for programming.
The example code provided with the application has been implemented and tested on an XMOS general
purpose sliceKIT (XK-SK-L2-ST) but there is no dependancy on this board and it can be modified to run on
any board containing an XMOS xCORE processor.
Note that the application example can only be run once successfully on the target hardware as the OTP
memory is one time programmable.
Prerequisites
• This document assumes familiarity with the XMOS xCORE architecture, the XMOS tool chain
and the xC language. Documentation related to these aspects which are not specific to this
application note are linked to in the References appendix.
• For descriptions of XMOS related terms found in this document please see the XMOS Glossary1 .
• The XMOS tools manual contains information regarding the use of xSCOPE and how to use it via
code running on an xCORE processor2 .
1 http://www.xmos.com/published/glossary
2 http://www.xmos.com/published/xtimecomposer-user-guide
1 Overview
1.1 Introduction
XMOS devices contain secure on-chip one-time programmable (OTP) memory that can be blown during
or after device manufacture testing. XMOS provides an Advanced Encryption Standard (AES) Module that
authenticates and decrypts programs from external SPI flash devices. You can program the AES Module
into the OTP of an xCORE device, allowing programs to be stored encrypted on flash memory.
This helps provide:
Once the AES Module is programmed, the OTP security bits are blown, transforming each tile into a
“secure island” in which all computation, memory access, I/O and communication are under exclusive
control of the code running on the tile.
When set, these bits:
• The XMOS device boots from the Programming Image through the SPI pins
• The XMOS device executes the Programming Image, which blows the OTP target image into the OTP
memory
• The XMOS device verifies that the OTP Target Image is now present in the OTP and signals status
using GPIO
The following diagram describes the programming flow where the Programming Image is provided
through a flash memory. If an alternative approach is used, for exmaple a SPI slave delivering the
Programming image from an FPGA, then the SPI flash programming step will have to be modified
accordingly.
This is the first step in the programming process and is normally done by the application developer or
customer requiring the OTP to be programmed on the xCORE device. An xCORE application is built in the
standard way using an xmos makefile and source code.
To demonstrate the approach, this example uses a simple main function which operates in a loop as
follows.
// Copyright (c) 2016, XMOS Ltd, All rights reserved
#include <xs1.h>
void drive_leds(void) {
for (int i = 0; i < 5; i++) {
delay_milliseconds(200);
leds <: 0x0;
delay_milliseconds(200);
leds <: 0xf;
}
}
In this example you can see we are simply calling a function to flash an LED 5 times and then exiting the
program.
To compile this application, startup a command prompt which uses the XMOS development tools, go to
the top level of the application note directory structure and enter the command:
xmake all
From the previous step we have a standard XMOS executable file which can be used with the XMOS
development tools to run on the target hardware. To be able to program this code into OTP memory via a
programming platform we need to generate the binary image of the data that would be programmed into
the OTP, independantly of the hardware platform itself.
To proceed with the example, open a command prompt setup to use the XMOS development tools. Then
change into the bin directory from the top level of the application note directory structure
First it is required to generate the program image for the specfied xCORE tile we are going to program.
This is done with the following command sequence:
The binary data for the OTP image can now be produced.
In order to do this the xburn tool is used:
The output from this stage of the process is a binary image of the OTP contents to be programmed. This
is contained within the file otp_tile_image.bin.
2.4 Building the OTP programming application for the programming rig
At this stage in the process there is normally a handover of the binary image for the OTP memory between
the customer and programming house. In this example both parts of the process are being performed on
the same development board.
Once we have the binary image for the OTP from the last step an OTP Programming Image can be gen-
erated which will perform the actual writing and verification of data into the OTP memory. This is done
again using the xburn tool.
For this step we need to link in some extra code into the programming executable in order to perform the
signalling of the programming completion and also the PASS / FAIL status of writing to the OTP memory.
This is done by passing the following code to xburn on the command line.
void _done() {
set_port_use_on(complete_signal);
while (1);
}
if (exitcode != 0) {
complete_signal <: 0xe;
} else {
complete_signal <: 0xc;
}
while (1);
}
• A GPIO is declared to report status complete and the status of PASS / FAIL
• Standard xCORE GPIO ports are used and these can be changed depending on where the detection
of these signal is connected
• The standard runtime function _done() is overloaded by this code to report the status that program-
ming the OTP has completed and been a success. This function is called by the OTP programming
application when there has been no error in programming
• The standard runtime function _exit is overloaded by this code to report the status that program-
ming the OTP has completed and has either passed or failed. This function will be called by there
OTP programming application when there has been an error in programming the OTP.
• Both of the above functions wait forever after signalling the status of the programming operation
In order to generate the OTP programming executable the following xburn command line is used:
At this point in the process a decision has to be made about various security options which are required
to be passed to xburn as command line options, the developer requesting OTP programming would have
specified these options,
Once the OTP Programming Image is produced from the previous step it now needs to be translated into
a binary image which can reside in a SPI salev device (in this case a flash memory) and boot the xCORE
device. The act of booting this device will load the programming code from SPI slave device into the
xCORE SRAM memory and then execute the code which will in turn program the application image we
built earlier into the OTP memory of the xCORE device.
The OTP programming application is converted to a SPI flash image by using the xflash tool supplied
with the XMOS development tools.
The command line to convert the OTP programming image using xflash is as follows:
This command produces a binary image which is in the correct format to be programmed into a SPI flash
that will boot an xCORE device via its boot ROM.
This image can be used with an external programmer to load into the SPI slave device.
• The XMOS XTAG should be connected to the host machine via a USB cable
• The GPIO slice card should be connected into the triangle connector on the sliceKIT
• The sliceKIT should have its power connector plugged in an powered on
> cd src\signalling
In order to compile the pass and fail binaries from the XMOS command prompt then perform the following
operations:
Once these are compiled we can run them on the board to check the PASS status:
In this example we are using the XMOS development tools to program the SPI flash binary image into the
flash device. The binary file we generated earlier would, in a production programmer, be used either with
an external flash programmer, or with a programmable device that emulates a SPI flash.
In order to program the flash the xflash command is used with the binary image generated earlier:
Once this command has completed the SPI flash will be loaded with our programming image.
Now that the Programming Image is present in the programming hardware, the XMOS device now needs
to be power cycled so that it can boot from the SPI slave device. In the example, this is done by removing
and reinserting the power cable to the XMOS sliceKIT.
Once this is done the OTP will be programmed and the board will now be configured to always boot
from OTP memory. You will no longer be able to boot the device from SPI or JTAG boot modes after this
operation is complete
APPENDIX D - References
XMOS Tools User Guide
http://www.xmos.com/published/xtimecomposer-user-guide
XMOS xCORE Programming Guide
http://www.xmos.com/published/xmos-programming-guide
void drive_leds(void) {
for (int i = 0; i < 5; i++) {
delay_milliseconds(200);
leds <: 0x0;
delay_milliseconds(200);
leds <: 0xf;
}
}
void _done() {
set_port_use_on(complete_signal);
while (1);
}
if (exitcode != 0) {
complete_signal <: 0xe;
} else {
complete_signal <: 0xc;
}
while (1);
}
Xmos Ltd. is the owner or licensee of this design, code, or Information (collectively, the “Information”) and is
providing it to you “AS IS” with no warranty of any kind, express or implied and shall have no liability in relation to
its use. Xmos Ltd. makes no representation that the Information, or any particular implementation thereof, is or will
be free from any claims of infringement and again, shall have no liability in relation to any such claims.