URL
https://opencores.org/ocsvn/ion/ion/trunk
Subversion Repositories ion
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 245 to Rev 246
- ↔ Reverse comparison
Rev 245 → Rev 246
/ion/trunk/src/sdboot/readme.txt
0,0 → 1,29
This is a minimalistic bootloader meant to run from BRAM. |
|
Upon reset, it will read file '/code.bin' from the DE-1 board SD card, load it |
at address 0x00000000 and then jump to that address. |
|
Any program meant to be bootloaded in this way has to be compiled with link |
script 'xram.lds', and the binary renamed 'code.bin'. See the 'Adventure' demo |
(makefile target 'sd') for an example. |
|
This program is built around elm-chan's FAT32 library, which has been ported |
to the ION SoC using a bitbanged interface. This should be easy to port to other |
boards. |
|
The binary will be truncated to 256KB. |
|
Uses serial port console at 19200/8/N/1. |
|
|
Run 'make demo' and synthesize as instructed for the 'Hello World' demo. |
|
|
This program is meant to be synthesized and used as a bootloader for |
demonstration or development, running from BRAM. It is too large to be run from |
BRAM in a real application; it should be modified to run from flash instead -- |
or you might use another bootloader, assuming you get it to compile and run |
on the MIPS-I core... |
|
This demo is not meant to be simulated in Modelsim or in software, no support |
is provided for that. |
/ion/trunk/src/sdboot/sdboot.c
0,0 → 1,94
/*----------------------------------------------------------------------*/ |
/* FatFs sample project for generic microcontrollers (C)ChaN, 2012 */ |
/*----------------------------------------------------------------------*/ |
|
#include <stdio.h> |
#include "../common/fatfs/ff.h" |
#include "../common/libsoc/src/hw.h" |
|
|
FATFS Fatfs; /* File system object */ |
FIL Fil; /* File object */ |
BYTE Buff[128]; /* File read buffer */ |
|
|
void die ( /* Stop with dying message */ |
FRESULT rc /* FatFs return value */ |
) |
{ |
switch(rc){ |
case FR_NOT_READY: printf("Disk absent."); |
case FR_DISK_ERR: printf("Low level disk i/o error."); |
case FR_NO_FILESYSTEM: printf("No valid filesystem in drive."); |
case FR_NO_FILE: printf("File not found."); |
default: printf("Failed with rc=%u.", rc); |
} |
printf("\n"); |
for (;;) ; |
} |
|
|
/*-----------------------------------------------------------------------*/ |
/* Program Main */ |
/*-----------------------------------------------------------------------*/ |
|
int main (void) |
{ |
FRESULT rc; /* Result code */ |
UINT br, i; |
BYTE *target = (BYTE *)0x00000000; |
UINT wr_index = 0; |
void (*target_fn)(void) = (void *)0x00000000; |
|
|
printf("ION SD loader -- " __DATE__ "\n\n"); |
printf("Loading file '/code.bin' onto RAM at address 0x00000000...\n"); |
|
|
WRPORT(0,0x17890083); |
|
|
f_mount(0, &Fatfs); /* Register volume work area (never fails) */ |
|
rc = f_open(&Fil, "CODE.BIN", FA_READ); |
if (rc) die(rc); |
|
for (;;) { |
rc = f_read(&Fil, Buff, sizeof Buff, &br); /* Read a chunk of file */ |
if (rc || !br) break; /* Error or end of file */ |
for (i = 0; i < br; i++){ /* Type the data */ |
target[wr_index] = Buff[i]; |
wr_index++; |
} |
if(wr_index > 256*1024) break; |
} |
if (rc) die(rc); |
|
|
rc = f_close(&Fil); |
if (rc) die(rc); |
|
|
printf("Done. Read %u bytes.\n", wr_index); |
printf("Transferring control to address 0x00000000\n\n"); |
|
target_fn(); |
|
for (;;) ; |
} |
|
|
|
/*---------------------------------------------------------*/ |
/* User Provided Timer Function for FatFs module */ |
/*---------------------------------------------------------*/ |
|
DWORD get_fattime (void) |
{ |
return ((DWORD)(2012 - 1980) << 25) /* Year = 2012 */ |
| ((DWORD)1 << 21) /* Month = 1 */ |
| ((DWORD)1 << 16) /* Day_m = 1*/ |
| ((DWORD)0 << 11) /* Hour = 0 */ |
| ((DWORD)0 << 5) /* Min = 0 */ |
| ((DWORD)0 >> 1); /* Sec = 0 */ |
} |
/ion/trunk/src/sdboot/makefile
0,0 → 1,102
#-- Bring toolchain config parameters from the common makefile |
include ../common/makefile |
|
# Link script to be used: run from BRAM, use upper chunk of RAM, leaving |
# the memory from 0x0 onwards free to be initialized with the binary file |
# read from the SD card. |
LINK_SCRIPT = $(SRC_DIR)/common/boot.lds |
|
#-- Configure the application -------------------------------------------------- |
|
# Simulation length in cycles; long enough to let the program run to completion. |
SIM_LENGTH = 90000 |
|
# FPGA Block RAM parameters (size in words) |
# 16K is far too much BRAM; in a real world the bootloader would have to be |
# squeezed into a smaller space or placed in flash. For our purposes this |
# will do. |
BRAM_START = 0xbfc00000 |
CODE_BRAM_SIZE = 4096 |
# External RAM parameters (size in words) |
# We're using the top 16K of the main 512K RAM area; the rest will be filled |
# with the code read from disk. |
XRAM_SIZE = 4096 |
XRAM_START = 0x0007BFFC |
|
# Here's where the FatFs source lives |
FATFS = ../common/fatfs |
|
# 1.- Put the code in internal BRAM and the data in external SRAM. |
# 2.- Do not use any of the standard libraries and use libsoc instead. |
|
LFLAGS = -T$(LINK_SCRIPT) -L $(LIB_PATH) \ |
-Ttext $(BRAM_START) -Tdata $(XRAM_START) \ |
-nodefaultlibs -nostdlib -ereset -I elf32-big |
CFLAGS = -O2 -Wall -c -s -fno-builtin -nodefaultlibs -nostdlib \ |
-msoft-float -mips1 -G0 -I $(FATFS) |
AFLAGS = --defsym XRAM_BASE=$(XRAM_START) |
|
|
OBJS = bootstrap.o opcode_emu.o c_startup.o sdboot.o \ |
$(FATFS)/mmcbb.o $(FATFS)/ff.o |
|
|
|
#-- Targets & rules ------------------------------------------------------------ |
|
sdboot: sdboot.code |
@# This comment prevents use of implicit rule so our rules are used instead. |
@# This will save us a few harmless linker warnings. |
|
sdboot.axf: $(OBJS) |
$(LD) $(LFLAGS) -Map sdboot.map -s -N -o sdboot.axf $(OBJS) -lsoc |
-@$(DUMP) -m mips --disassemble sdboot.axf > sdboot.lst |
|
sdboot.code: sdboot.axf |
# Extract object code to be placed in code space |
$(COPY) -I elf32-big -O binary sdboot.axf sdboot.code |
|
|
# Rules for the assembly source files |
bootstrap.o: $(SRC_DIR)/common/bootstrap.s |
$(AS) $(AFLAGS) -o bootstrap.o $(SRC_DIR)/common/bootstrap.s |
|
c_startup.o: $(SRC_DIR)/common/c_startup.s |
$(AS) $(AFLAGS) -o c_startup.o $(SRC_DIR)/common/c_startup.s |
|
opcode_emu.o: $(SRC_DIR)/common/opcode_emu.s |
$(AS) $(AFLAGS) -o opcode_emu.o $(SRC_DIR)/common/opcode_emu.s |
|
#-- Let's make some implicit rules explicit for clarity (well, 'clarity') |
|
%.o: %.c |
$(CC) $(CFLAGS_MAIN) $< -o $@ |
|
|
|
#-- Targets that build the synthesizable vhdl; meant for direct invocation ----- |
|
#-- Create VHDL package with data and parameters for simulation |
sim: sdboot demo |
$(VHDL_OBJ_PKG) --project="SD Bootloader" \ |
--package sim_params_pkg \ |
--bin sdboot.code --name obj_code --bram_size $(CODE_BRAM_SIZE) \ |
--name prom_init --flash_size 0 \ |
--output $(TB_DIR)/sim_params_pkg.vhdl \ |
-s $(SIM_LENGTH) --log_trigger=0xbfc00000 \ |
|
#-- Create VHDL package with data and parameters for simulation and syntesis |
demo: sdboot |
$(VHDL_OBJ_PKG) --project="SD Bootloader" \ |
--package obj_code_pkg \ |
--bin sdboot.code --name obj_code --bram_size $(CODE_BRAM_SIZE) \ |
--output $(DEMO_DIR)/../SoC/bootstrap_code_pkg.vhdl |
|
|
#-- And now the usual housekeeping stuff --------------------------------------- |
|
.PHONY: clean |
|
clean: |
-$(RM) *.o *.obj *.map *.lst *.hex *.exe *.axf *.code *.data *.bin |
-$(RM) $(FATFS)/*.o |