OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [docs/] [datasheet/] [software_bootloader.adoc] - Blame information for rev 72

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 72 zero_gravi
:sectnums:
2
=== Bootloader
3
 
4
[NOTE]
5
This section refers to the **default** bootloader from the repository. The bootloader can be customized
6
to target application-specific scenarios. See User Guide section
7
https://stnolting.github.io/neorv32/ug/#_customizing_the_internal_bootloader[Customizing the Internal Bootloader]
8
for more information.
9
 
10
The NEORV32 bootloader (source code `sw/bootloader/bootloader.c`) provides an optional build-in firmware that
11
allows to upload new application executables without the need to re-synthesize the FPGA's bitstream.
12
A UART connection is used to provide a simple text-based user interface that allows to upload executables.
13
 
14
Furthermore, the bootloader provides options to program executable to a processor-external SPI flash.
15
An "auto boot" feature can optionally fetch this executable
16
right after reset if there is no user interaction via UART. This allows to build processor setup with
17
non-volatile application storage, which can still be updated at any time.
18
 
19
The bootloader is implemented if the <<_int_bootloader_en>> generic is _true_ (default). This will automatically
20
select the CPU's <<_indirect_boot>> boot configuration.
21
 
22
.Hardware Requirements for the _Default_ NEORV32 Bootloader
23
[IMPORTANT]
24
**REQUIRED**: The bootloader requires the privileged architecture CPU extension
25
(<<_zicsr_control_and_status_register_access_privileged_architecture>>)
26
and at least 512 bytes of data memory (processor-internal DMEM or external DMEM). +
27
 +
28
**RECOMMENDED**: For user interaction via UART (like uploading executables) the primary UART
29
(<<_primary_universal_asynchronous_receiver_and_transmitter_uart0>>) has to be implemented.
30
Without UART0 the auto-boot via SPI is still supported but the bootloader should be customized
31
(see User Guide) for this purpose. +
32
 +
33
**RECOMMENDED**: The default bootloader uses bit 0 of the GPIO controller's
34
(<<_general_purpose_input_and_output_port_gpio>>) output port to drive a high-active "heart beat" status LED. +
35
 +
36
**RECOMMENDED**: The MTIME machine timer (<<_machine_system_timer_mtime>> generic is _true_) is used to control
37
blinking of the status LED and also to automatically trigger the auto-boot sequence. +
38
 +
39
**OPTIONAL**: The SPI controller (<<_serial_peripheral_interface_controller_spi>>) is required
40
to store/load executable from external flash (for the auto boot feature).
41
 
42
To interact with the bootloader, connect the primary UART (UART0) signals (`uart0_txd_o` and
43
`uart0_rxd_o`) of the processor's top entity via a serial port (-adapter) to your computer (hardware flow control is
44
not used so the according interface signals can be ignored.), configure your
45
terminal program using the following settings and perform a reset of the processor.
46
 
47
Terminal console settings (`19200-8-N-1`):
48
 
49
* 19200 Baud
50
* 8 data bits
51
* no parity bit
52
* 1 stop bit
53
* newline on `\r\n` (carriage return, newline)
54
* no transfer protocol / control flow protocol - just raw bytes
55
 
56
[IMPORTANT]
57
_Any_ terminal program that can connect to a serial port should work. However, make sure the program
58
can transfer data in _raw_ byte mode without any protocol overhead around it. Some terminal programs struggle with
59
transmitting files larger than 4kB (see https://github.com/stnolting/neorv32/pull/215). Try a different program
60
if uploading a binary does not work.
61
 
62
The bootloader uses the LSB of the top entity's `gpio_o` output port as high-active **status LED** (all other
63
output pin are set to low level). After reset, this LED will start blinking at ~2Hz and the
64
following intro screen should show up in your terminal:
65
 
66
[source]
67
----
68
<< NEORV32 Bootloader >>
69
 
70
BLDV: Feb 16 2022
71
HWV:  0x01060709
72
CLK:  0x05f5e100
73
ISA:  0x40901107 + 0xc000068b
74
SOC:  0x7b7f402f
75
IMEM: 0x00008000 bytes @0x00000000
76
DMEM: 0x00004000 bytes @0x80000000
77
 
78
Autoboot in 8s. Press any key to abort.
79
----
80
 
81
This start-up screen also gives some brief information about the bootloader and several system configuration parameters:
82
 
83
[cols="<2,<15"]
84
[grid="none"]
85
|=======================
86
| `BLDV` | Bootloader version (built date).
87
| `HWV`  | Processor hardware version (the <<_mimpid>> CSR); in BCD format; example: `0x01040606` = v1.4.6.6).
88
| `CLK`  | Processor clock speed in Hz (via the `CLK` register from <<_system_configuration_information_memory_sysinfo>>; defined by the <<_clock_frequency>> generic).
89
| `ISA`  | CPU extensions (<<_misa>> CSR + <<_mxisa>> CSR).
90
| `SOC`  | Processor configuration (via the `SOC` register from the <<_system_configuration_information_memory_sysinfo>>; defined by the `IO_*` and `MEM_*` configuration generics).
91
| `IMEM` | IMEM memory base address and size in byte (via the `IMEM_SIZE` and `ISPACE_BASE` registers from the <<_system_configuration_information_memory_sysinfo>>; defined by the <<_mem_int_imem_size>> generic).
92
| `DMEM` | DMEM memory base address and size in byte (via the `DMEM_SIZE` and `DSPACE_BASE` registers from the <<_system_configuration_information_memory_sysinfo>>; defined by the <<_mem_int_dmem_size>> generic).
93
|=======================
94
 
95
Now you have 8 seconds to press _any_ key. Otherwise, the bootloader starts the <<_auto_boot_sequence>>. When
96
you press any key within the 8 seconds, the actual bootloader user console starts:
97
 
98
[source]
99
----
100
<< NEORV32 Bootloader >>
101
 
102
BLDV: Feb 16 2022
103
HWV:  0x01060709
104
CLK:  0x05f5e100
105
ISA:  0x40901107 + 0xc000068b
106
SOC:  0x7b7f402f
107
IMEM: 0x00008000 bytes @0x00000000
108
DMEM: 0x00004000 bytes @0x80000000
109
 
110
Autoboot in 8s. Press any key to abort.
111
Aborted. <1>
112
 
113
Available commands:
114
 h: Help
115
 r: Restart
116
 u: Upload
117
 s: Store to flash
118
 l: Load from flash
119
 e: Execute
120
CMD:>
121
----
122
<1> Auto boot sequence aborted due to user console input.
123
 
124
The auto boot countdown is stopped and the bootloader's user console is ready to receive one of the following commands:
125
 
126
* `h`: Show the help text (again)
127
* `r`: Restart the bootloader and the auto-boot sequence
128
* `u`: Upload new program executable (`neorv32_exe.bin`) via UART into the instruction memory
129
* `s`: Store executable to SPI flash at `spi_csn_o(0)` (little-endian byte order)
130
* `l`: Load executable from SPI flash at `spi_csn_o(0)` (little-endian byte order)
131
* `e`: Start the application, which is currently stored in the instruction memory (IMEM)
132
 
133
A new executable can be uploaded via UART by executing the `u` command. After that, the executable can be directly
134
executed via the `e` command. To store the recently uploaded executable to an attached SPI flash press `s`. To
135
directly load an executable from the SPI flash press `l`. The bootloader and the auto-boot sequence can be
136
manually restarted via the `r` command.
137
 
138
[TIP]
139
The CPU is in machine level privilege mode after reset. When the bootloader boots an application,
140
this application is also started in machine level privilege mode.
141
 
142
[TIP]
143
For detailed information on using an SPI flash for application storage see User Guide section
144
https://stnolting.github.io/neorv32/ug/#_programming_an_external_spi_flash_via_the_bootloader[Programming an External SPI Flash via the Bootloader].
145
 
146
 
147
:sectnums:
148
==== Auto Boot Sequence
149
 
150
When you reset the NEORV32 processor, the bootloader waits 8 seconds for a UART console input before it
151
starts the automatic boot sequence. This sequence tries to fetch a valid boot image from the external SPI
152
flash, connected to SPI chip select `spi_csn_o(0)`. If a valid boot image is found that can be successfully
153
transferred into the instruction memory, it is automatically started. If no SPI flash is detected or if there
154
is no valid boot image found, and error code will be shown.
155
 
156
 
157
:sectnums:
158
==== Bootloader Error Codes
159
 
160
If something goes wrong during bootloader operation, an error code and a short message is shown. In this case the processor
161
stalls,, the bootloader status LED is permanently activated and the processor must be reset manually.
162
 
163
[TIP]
164
In many cases the error source is just _temporary_ (like some HF spike during an UART upload). Just try again.
165
 
166
[cols="<2,<8"]
167
[grid="rows"]
168
|=======================
169
| **`ERROR_0`** | If you try to transfer an invalid executable (via UART or from the external SPI flash), this error message shows up. There might be a transfer protocol configuration error in the terminal program. Also, if no SPI flash was found during an auto-boot attempt, this message will be displayed.
170
| **`ERROR_1`** | Your program is way too big for the internal processor’s instructions memory. Increase the memory size or reduce your application code.
171
| **`ERROR_2`** | This indicates a checksum error. Something went wrong during the transfer of the program image (upload via UART or loading from the external SPI flash). If the error was caused by a UART upload, just try it again. When the error was generated during a flash access, the stored image might be corrupted.
172
| **`ERROR_3`** | This error occurs if the attached SPI flash cannot be accessed. Make sure you have the right type of flash and that it is properly connected to the NEORV32 SPI port using chip select #0.
173
| **`ERROR - Unexpected exception!`** | The bootloader encountered an exception during operation. This might be caused when it tries to access peripherals that were not implemented during synthesis. Example: executing commands `l` or `s` (SPI flash operations) without the SPI module beeing implemented.
174
|=======================

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.