1 |
349 |
julius |
SPI flash programming application
|
2 |
|
|
|
3 |
|
|
This software will be compiled and have another application embedded in it,
|
4 |
|
|
which will then be programmed into a flash memory via the SPI protocol.
|
5 |
|
|
|
6 |
|
|
At present, only the simple_spi core communicating with the M25P10 serial flash
|
7 |
|
|
memory via SPI is supported (the config on ORSoC FPGA board)
|
8 |
|
|
|
9 |
|
|
First, compile the program to be put into flash, and generate a binary image of
|
10 |
|
|
it.
|
11 |
|
|
|
12 |
|
|
The bootloader program that loads programs from the SPI flash, at reset, reads
|
13 |
|
|
out the first 4 bytes (32-bit word) from the flash and expects this to contain
|
14 |
|
|
the length of the image in bytes. It then enters a loop for this many bytes
|
15 |
|
|
and copies them to the SDRAM, before jumping to the reset vector in SDRAM.
|
16 |
|
|
|
17 |
|
|
This means the image programed into the SPI flash must contain its size at the
|
18 |
|
|
first word, and the remainder of the image must be correctly aligned so that
|
19 |
|
|
the reset vector is at address 0x100 after being loaded.
|
20 |
|
|
|
21 |
|
|
Included with this software package is a tool which will take a binary
|
22 |
|
|
application and embed its size in the first word. The makefile then takes this
|
23 |
|
|
altered binary image, and convert it into an object file with the appropriate
|
24 |
|
|
section name, and is linked into the final application by a custom linker
|
25 |
|
|
script also included in this path.
|
26 |
|
|
|
27 |
|
|
First the program to be loaded into the flash memory should be compiled. It
|
28 |
|
|
should be, of course, tested on the board first, before being loaded into the
|
29 |
|
|
flash. Once the program is tested on the board, the ELF can be taken and
|
30 |
|
|
objcopy'd to a binary image. It should be noted that the image should be
|
31 |
|
|
addressed from 0, and the vectors should be correctly located.
|
32 |
|
|
|
33 |
|
|
Convert to the ELF to raw binary with:
|
34 |
|
|
|
35 |
|
|
$ or32-elf-objcopy -O binary myapp.elf myapp.bin
|
36 |
|
|
|
37 |
|
|
Now, the spiflash-program.elf program should be compiled, and the environment
|
38 |
|
|
variable PROGRAMMINGFILE should be set to point to myapp.bin, the binary
|
39 |
|
|
version of the program we are to load into the flash memory.
|
40 |
|
|
|
41 |
465 |
julius |
To ensure the correct settings for UART and other peripherals are picked up
|
42 |
|
|
ensure the BOARD_PATH variable is set correctly, too.
|
43 |
349 |
julius |
|
44 |
466 |
julius |
make spiflash-program.elf PROGRAMMINGFILE=/path/to/myapp.bin \
|
45 |
505 |
julius |
BOARD=actel/ordb1a3pe1500
|
46 |
465 |
julius |
|
47 |
|
|
It's advisable to do a "make distclean" first, to clear out any previously
|
48 |
|
|
compiled software for other boards.
|
49 |
|
|
|
50 |
349 |
julius |
The steps to embed the size of the program in the binary and then link it
|
51 |
|
|
into the final executable are all done automatically by the Makefile.
|
52 |
|
|
|
53 |
|
|
Finally, spiflash-program.elf should be loaded onto the board and executed. A
|
54 |
|
|
small prompt should come up, pressing 'h' will explain the options, 'p' will
|
55 |
|
|
do the programming (and verification of the image) and 'v' will verify the
|
56 |
|
|
image again.
|
57 |
|
|
|
58 |
465 |
julius |
Warning:
|
59 |
349 |
julius |
Note that in the flash on the ORSoC dev board, there appears to be 3 pages,
|
60 |
|
|
either pages 130-132 or pages 180-182 which do not provide reliable data when
|
61 |
|
|
read from. The cause of this is unknown. If this is a big problem, be sure that
|
62 |
|
|
no vital information is stored on those pages.
|
63 |
|
|
|
64 |
|
|
And of course, be sure that the program being loaded fits into the SPI flash.
|
65 |
|
|
|
66 |
|
|
Once the flash memory is programmed, and if the design is configured with the
|
67 |
|
|
SPI flash bootloader, resetting the target should cause the new application to
|
68 |
|
|
be executed.
|
69 |
|
|
|
70 |
|
|
Author: Julius Baxter, julius.baxter@orsoc.se
|
71 |
|
|
|
72 |
|
|
|