Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if(PROJECT_IS_TOP_LEVEL)

# Bitstream generation

set(CLOCK_FREQUENCY 60)
set(CLOCK_FREQUENCY 68)
add_ecp5_pll_generation(
INPUT_FREQ 24
OUTPUT_FREQ ${CLOCK_FREQUENCY}
Expand Down
3 changes: 1 addition & 2 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ add_custom_command(

add_custom_target(helloworld DEPENDS helloworld.dump helloworld.load)


add_executable(bootloader.elf ${CMAKE_CURRENT_LIST_DIR}/bootloader/bootloader.S ${CMAKE_CURRENT_LIST_DIR}/bootloader/uart.S ${CMAKE_CURRENT_LIST_DIR}/bootloader/spi.S)
add_executable(bootloader.elf ${CMAKE_CURRENT_LIST_DIR}/bootloader/bootloader.S ${CMAKE_CURRENT_LIST_DIR}/bootloader/uart.S ${CMAKE_CURRENT_LIST_DIR}/bootloader/spi.S ${CMAKE_CURRENT_LIST_DIR}/bootloader/flash.S ${CMAKE_CURRENT_LIST_DIR}/bootloader/elf.S)
set_target_properties(bootloader.elf PROPERTIES COMPILE_FLAGS "${CC_OPTS} -march=rv32g -mabi=ilp32"
LINK_FLAGS "${CC_OPTS} -march=rv32g -mabi=ilp32 -T${CMAKE_CURRENT_LIST_DIR}/link.ld")

Expand Down
79 changes: 40 additions & 39 deletions firmware/bootloader/bootloader.S
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,62 @@
# You should have received a copy of the GNU General Public License
# along with ECAP5-DSOC. If not, see <http://www.gnu.org/licenses/>.

.equ FLASH_MFID, 0xEF
.equ FLASH_DEVTYPE, 0x40
.equ FLASH_SIZE, 0x18

.equ EXE_ADDR, 0x300000

.section .text
.global _start
_start:
la sp, __BOOT_STACK_TOP__

call configure_uart
call configure_spi
call enable_cs

la a0, boot_str
call send_string

la a0, readingflash_str
call send_string
# Checking the flash ID
li a0, FLASH_MFID
li a1, FLASH_DEVTYPE
li a2, FLASH_SIZE
call check_flash_id
bne a0, x0, _booterr

li a0, 0x9F
call send_spi
# Checking ELF
li a0, EXE_ADDR
call check_elf_type
bne a0, x0, _booterr

li a0, 0x00
call send_spi
mv s0, a0
# Loading ELF in RAM
li a0, EXE_ADDR
call load_elf_in_ram
bne a0, x0, _booterr

li a0, 0x00
call send_spi
mv s1, a0
# Get the ELF entry point
la a0, EXE_ADDR
call get_elf_entry

li a0, 0x00
call send_spi
mv s2, a0
# Move the entry to ra
mv ra, a0

la a0, mfid_str
call send_string

mv a0, s0
call send_hex
# Set the stack pointer
la sp, __RAM_END__

la a0, type_str
call send_string
# Clear registers (except x0, ra and sp)
.irp r, 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
mv x\r, x0
.endr

mv a0, s1
call send_hex
# Jump to ra
ret

la a0, size_str
_booterr:
la a0, bootfail_str
call send_string

mv a0, s2
call send_hex

call disable_cs

_loop:
_loop:
j _loop

.align 4

boot_str: .asciz "\n\nBooting..."
readingflash_str: .asciz "\nReading flash..."
mfid_str: .asciz "\nManufacturer ID : "
type_str: .asciz "\nType : "
size_str: .asciz "\nSize : "
bootfail_str: .asciz "\n[BOOT] FAIL\n"
pon_str: .asciz "\n[BOOT] FAIL\n"
Loading