summaryrefslogtreecommitdiffstats
path: root/Documentation/boards/socfpga.rst
blob: 19d6060300037eda3111be15086fd43b4b71d2ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
Altera SoCFPGA
==============

Alteras SoCFPGA SoCs have a two-stage boot process. The first stage is
known as preloader which loads the second stage bootloader. barebox can act
as both the first and the second stage loader.
In barebox the preloader is called xload, so to build as a first stage loader,
build the ``socfpga-xload_defconfig``; for second stage use the normal
``socfpga_defconfig``.

Bootstrapping
-------------

The supported bootsources are: SD card and QSPI.

Bootsource selection
^^^^^^^^^^^^^^^^^^^^

+--------------+-----------+-----------+
| Board        | BSEL[2:0] | CSEL[1:0] |
+==============+===========+===========+
| Sockit SD    | 0b100     | 0b00      |
+--------------+-----------+-----------+
| Sockit QSPI  | 0b110     | 0b00      |
+--------------+-----------+-----------+
| Socrates SD  | 0b101     | 0b11      |
+--------------+-----------+-----------+
| Socrates QSPI| 0b111     | 0b11      |
+--------------+-----------+-----------+
| SocDK SD     | 0b100     | 0b00      |
+--------------+-----------+-----------+
| SocDK QSPI   | 0b110     | 0b00      |
+--------------+-----------+-----------+

SD card
^^^^^^^

The Boot ROM searches for a partition of type A2 and loads what it finds there.
When barebox is placed in such a partition it will then itself try and mount the
second partition of the SD card, which must be of type FAT32. On this partition
barebox searches for a file called barebox.bin.

To boot barebox on a Terasic SoCkit, the procedure is as follows (sdb1 is the A2 and
sdb2 the FAT32 partition):

.. code-block:: sh

  mount -t fat /dev/sdb2 /mnt
  make socfpga-xload_defconfig
  make
  make socfpga_defconfig
  make

barebox has now generated multiple files in the images directory. So for the SoCkit
proceed with:

.. code-block:: sh

  cat images/barebox-socfpga-sockit-xload.img > /dev/sdb1
  cp images/barebox-socfpga-sockit.img /mnt/barebox.bin
  umount /mnt

For the EBV Socrates use ``images/barebox-socfpga-socrates(-xload).img`` instead.

QSPI
^^^^

The Boot ROM loads the preloader starting from address 0x0 on the QSPI flash.
barebox then searches for a barebox image at the 256K offset and loads it.

The default bootsource is SD card, so to change that to QSPI, you have to:

.. code-block:: sh

  make socfpga-xload_defconfig
  make menuconfig

And then select the options `MTD` and `SPI_CADENCE_QUADSPI`. Now:

.. code-block:: sh

  make
  cat images/barebox-socfpga-<board>-xload.img > /dev/mtd0

For barebox itself, the build step is like for SD card. The resulting image has to be
written to the offset 256K.

Warning! There is a known issue with booting from QSPI and doing Cold/Warm-Resets.
Please consult `Rocketboards <http://rocketboards.org/foswiki/Documentation/SocBoardQspiBoot#Serial_Flash_Challenges>`_
to see how to fix this.


Updating handoff files
----------------------

(Tools needed: Quartus II + SoCEDS)

As barebox uses some of the autogenerated files from Quartus II, every
time Altera makes a new release, there might be some updates to the
handoff files. As these files are split up in the code base and generated
explicitely for some specific U-boot code base, some manual work might be
necessary.

The boardspecific files for `arch/arm/boards/<yourboard>` are:

* iocsr_config_cyclone5.c
* pinmux_config_cyclone5.c -> pinmux_config.c
* pll_config.h
* sdram/sdram_config.h -> sdram_config.h
* sequencer_auto.h
* sequencer_auto_ac_init.c
* sequencer_auto_inst_init.c
* sequencer_defines.h

To update the handoff files, the following procedure is necessary:

1. Regenerate the project with Qsys
2. Load up your project in Quartus II and assemble the design

Now run the command:

.. code-block:: sh

  scripts/socfpga_import_preloader <EMBEDDED_SDK> <ISW_HANDOFF> <BOARD_DIRECTORY>

where `<SPL_GENERATED_DIR>` is the directory where the bsp-editor generated the files,
`<ISW_HANDOFF>` is the directory where Quartus generated the handoff files, and
`<BOARD_DIRECTORY>` is your board directory under `arch/arm/boards`.


Integrating new SDRAM driver
----------------------------

This step must only be executed if the SDRAM driver needs updates. It is not necessary
for adding a new board to barebox.

The following files are generic and belong into the `arch/arm/mach-socfpga` directory
tree:

* sdram_io.h
* sequencer.c as cyclone5-sequencer.c
* sequencer.h as cyclone5-sequencer.h
* sequencer_defines.h
* system.h
* tclrpt.h

To add these files, run:

.. code-block:: sh

  scripts/socfpga_get_sequencer <UBOOT-SRC> scripts/socfpga_sequencer_defines_defaults

where `<UBOOT-SRC>` is the directory where the Altera bsp-editor generated the u-boot
directory. Refer to the Altera documentation for how to use the bsp-editor.