Testing various flashing methods ...

master
kaqu 2 years ago
parent 58cb641ca1
commit 9367a9b6d0
  1. 4
      .vscode/launch.json
  2. 7
      firmware/console.c
  3. 174
      firmware/main.c
  4. 181
      helpers/bit_to_uploadflash.py
  5. 10
      neopixelar.py
  6. 81
      software/flashcreate.sh
  7. 89
      software/linker/flash.ld
  8. 16
      software/source/main.c

@ -10,8 +10,8 @@
"request": "launch",
"program": "${file}",
"args": ["--build",
"--load", // May be used separately ...
//"--flash", // May be used separately ...
//"--load", // May be used separately ...
"--flash", // May be used separately ...
"--revision=7.0",
"--uart-name=crossover",
//"--with-ethernet", // Not to be used together w/ etherbone! Won't TFTP ...

@ -69,6 +69,13 @@ int readchar_nonblock(void)
|| ((read_nonblock_hook != NULL) && read_nonblock_hook()));
}
char kbhit(void)
{
if(readchar_nonblock())
return readchar();
return '\0';
}
int puts(const char *s)
{
while(*s) {

@ -46,6 +46,9 @@
#include <liblitesdcard/sdcard.h>
// Project local special (may need adjustment)
#include "/mnt/a30054ad-3fe6-444a-8d93-16df937e448e/projects/fpga/neopixelar/software/include/illumination.h"
static void boot_sequence(void)
{
if(serialboot()) {
@ -80,7 +83,7 @@ void enable_LEDS(int iEnable)
npe_bEnable_write(iEnable ? 1 : 0); // Enable/disable
}
void send_LEDs()
void send_LEDs(void)
{
for(int j=0;j<MAXTABLES;j++) {
npe_b4LoadTable_write(j); // Select table
@ -107,7 +110,7 @@ void load_triple_LEDs(int iTable, int32_t green, int32_t red, int32_t blue)
}
}
void illumination(void)
int illumination(void)
{
int32_t green = 0x040000;
int32_t red = 0x000400;
@ -175,19 +178,22 @@ void illumination(void)
busy_wait(500);
#endif
enable_LEDS(0);
return 1;
}
//------------------- End of illumination demo --------------------------
int main(int i, char **c)
{
extern char kbhit(void);
extern void set_console(int non_blocking);
char buffer[CMD_LINE_BUFFER_SIZE];
char *params[MAX_PARAM];
char *command;
struct command_struct *cmd;
int nb_params;
int sdr_ok;
illumination(); // The DEMO !
int non_blocking = 0;
#ifdef CONFIG_CPU_HAS_INTERRUPT
irq_setmask(0);
@ -195,55 +201,73 @@ int main(int i, char **c)
#endif
uart_init();
printf("\n");
printf("\e[1m __ _ __ _ __\e[0m\n");
printf("\e[1m / / (_) /____ | |/_/\e[0m\n");
printf("\e[1m / /__/ / __/ -_)> <\e[0m\n");
printf("\e[1m /____/_/\\__/\\__/_/|_|\e[0m\n");
printf("\e[1m Build your hardware, easily!\e[0m\n");
printf("\n");
printf(" (c) Copyright 2012-2020 Enjoy-Digital\n");
printf(" (c) Copyright 2007-2015 M-Labs\n");
printf(" --- Copyleft 2020 KQ ---------\n");
printf("\n");
printf(" BIOS built on "__DATE__" "__TIME__"\n");
#define CONSOLE_NON_BLOCKING 1
#ifdef CONSOLE_NON_BLOCKING
busy_wait(1000); // Permit remote (IP) terminal to connect ...
printf("Press any key for full boot messages within 2s ...\n");
non_blocking = 1; //<-- Test w/ 0! 1; // By default: show demo (=1)...
for(int i=1;i<20;i++) {
busy_wait(100);
if(kbhit()) // Key pressed?
non_blocking = 0; // Yap! Switch to blocking/full boot screen
}
set_console(non_blocking); // 1=Non-blocking (0=blocking)
if(non_blocking) printf("\e[1mBoot screen skipped, going straight to illumination ...\e[0m\n");
#endif
if(!non_blocking) {
printf("\n");
printf("\e[1m __ _ __ _ __\e[0m\n");
printf("\e[1m / / (_) /____ | |/_/\e[0m\n");
printf("\e[1m / /__/ / __/ -_)> <\e[0m\n");
printf("\e[1m /____/_/\\__/\\__/_/|_|\e[0m\n");
printf("\e[1m Build your hardware, easily!\e[0m\n");
printf("\n");
printf(" (c) Copyright 2012-2020 Enjoy-Digital\n");
printf(" (c) Copyright 2007-2015 M-Labs\n");
printf(" --- Copyleft 2020 KQ ---------\n");
printf("\n");
printf(" BIOS built on "__DATE__" "__TIME__"\n");
}
crcbios();
printf("\n");
printf(" Migen git sha1: "MIGEN_GIT_SHA1"\n");
printf(" LiteX git sha1: "LITEX_GIT_SHA1"\n");
printf("\n");
printf("--=============== \e[1mSoC\e[0m ==================--\n");
printf("\e[1mCPU\e[0m:\t\t%s @ %dMHz\n",
CONFIG_CPU_HUMAN_NAME,
CONFIG_CLOCK_FREQUENCY/1000000);
printf("\e[1mBUS\e[0m:\t\t%s %d-bit @ %dGiB\n",
CONFIG_BUS_STANDARD,
CONFIG_BUS_DATA_WIDTH,
(1 << (CONFIG_BUS_ADDRESS_WIDTH - 30)));
printf("\e[1mCSR\e[0m:\t\t%d-bit data\n",
CONFIG_CSR_DATA_WIDTH);
printf("\e[1mROM\e[0m:\t\t%dKiB\n", ROM_SIZE/1024);
printf("\e[1mSRAM\e[0m:\t\t%dKiB\n", SRAM_SIZE/1024);
if(!non_blocking) {
printf("\n");
printf(" Migen git sha1: "MIGEN_GIT_SHA1"\n");
printf(" LiteX git sha1: "LITEX_GIT_SHA1"\n");
printf("\n");
printf("--=============== \e[1mSoC\e[0m ==================--\n");
printf("\e[1mCPU\e[0m:\t\t%s @ %dMHz\n",
CONFIG_CPU_HUMAN_NAME,
CONFIG_CLOCK_FREQUENCY/1000000);
printf("\e[1mBUS\e[0m:\t\t%s %d-bit @ %dGiB\n",
CONFIG_BUS_STANDARD,
CONFIG_BUS_DATA_WIDTH,
(1 << (CONFIG_BUS_ADDRESS_WIDTH - 30)));
printf("\e[1mCSR\e[0m:\t\t%d-bit data\n",
CONFIG_CSR_DATA_WIDTH);
printf("\e[1mROM\e[0m:\t\t%dKiB\n", ROM_SIZE/1024);
printf("\e[1mSRAM\e[0m:\t\t%dKiB\n", SRAM_SIZE/1024);
#ifdef CONFIG_L2_SIZE
printf("\e[1mL2\e[0m:\t\t%dKiB\n", CONFIG_L2_SIZE/1024);
printf("\e[1mL2\e[0m:\t\t%dKiB\n", CONFIG_L2_SIZE/1024);
#endif
#ifdef MAIN_RAM_SIZE
#ifdef CSR_SDRAM_BASE
printf("\e[1mSDRAM\e[0m:\t\t%dKiB %d-bit @ %dMbps/pin\n",
MAIN_RAM_SIZE/1024,
sdrdatabits(),
sdrfreq()/1000000);
printf("\e[1mSDRAM\e[0m:\t\t%dKiB %d-bit @ %dMbps/pin\n",
MAIN_RAM_SIZE/1024,
sdrdatabits(),
sdrfreq()/1000000);
#else
printf("\e[1mMAIN-RAM\e[0m:\t%dKiB \n", MAIN_RAM_SIZE/1024);
printf("\e[1mMAIN-RAM\e[0m:\t%dKiB \n", MAIN_RAM_SIZE/1024);
#endif
#endif
printf("\n");
sdr_ok = 1;
printf("\n");
}
sdr_ok = 1;
#if defined(CSR_ETHMAC_BASE) || defined(CSR_SDRAM_BASE)
printf("--========== \e[1mInitialization\e[0m ============--\n");
if(!non_blocking)
printf("--========== \e[1mInitialization\e[0m ============--\n");
#ifdef CSR_ETHMAC_BASE
printf("ETH init ...\n");
eth_init();
#endif
#ifdef CSR_SDRAM_BASE
@ -258,6 +282,7 @@ int main(int i, char **c)
printf("\n");
#endif
#ifdef CSR_SPIFLASH_MMAP_BASE
printf("SPIFLASH init ...\n");
spiflash_init();
#endif
@ -266,70 +291,17 @@ int main(int i, char **c)
boot_sequence();
printf("\n");
}
#ifdef MAIN_RAM_EMPTY_CHECK
// RAM empty check
printf("RAM empty check ...\n");
#define RAMBASE 0x40000000
#define RAMLENGTH 0x400000
char *ram_base = (char *)RAMBASE;
int ii,j, i0count = 0, iffcount = 0;
for(ii = 0; ii < (int)RAMLENGTH; ii++) // Hunt for non-ffh bytes
{
if(ram_base[ii] != 0xff) // RAM not empty?
{
//printf("%08lxh:",(unsigned long)ram_base+ii);
for(j = 0;(j < 16) && ((ii + j) < RAMLENGTH);j++)
; //printf(" %02x",ram_base[ii + j]);
//printf("\n");
printf("Data detected:\n");
dump_bytes((unsigned int *)(&ram_base[ii]),j,(unsigned long)ram_base+ii);
break;
}
}
if(ii >= RAMLENGTH)
printf("RAM empty, ok.\n");
else
printf("RAM NOT EMPTY!!!\n");
#define MINRANGELEN 32
#define DUMPLENGTH 48
for(i0count=0, iffcount=0;ii < RAMLENGTH; ii++) // Now track for 0 or 0xff bytes ...
{
if(ram_base[ii] == 0x00)
i0count++;
else
i0count = 0;
if(i0count > MINRANGELEN-1)
{
printf("Zero range detected ...");
if(ii < (RAMLENGTH-DUMPLENGTH+MINRANGELEN))
dump_bytes((unsigned int *)(&ram_base[ii-MINRANGELEN]),DUMPLENGTH,(unsigned long)ram_base+ii-MINRANGELEN);
break;
}
if(ram_base[ii] == 0xff)
iffcount++;
else
iffcount = 0;
if(iffcount > MINRANGELEN-1)
{
printf("Empty range detected ...");
if(ii < (RAMLENGTH-DUMPLENGTH+MINRANGELEN))
dump_bytes((unsigned int *)(&ram_base[ii-MINRANGELEN]),DUMPLENGTH,(unsigned long)ram_base+ii-MINRANGELEN);
break;
}
}
#endif
printf("--============= \e[1mConsole\e[0m ================--\n");
#if !defined(TERM_MINI) && !defined(TERM_NO_HIST)
hist_init();
#endif
if(illumination()) // Initial demo / up indication
printf("Initial demo finished.\n");
printf("\n%s", PROMPT);
#define CONSOLE_NON_BLOCKING 1
#ifdef CONSOLE_NON_BLOCKING
// Enable non-blocking output
extern void set_console(int non_blocking);
set_console(1); // 1=Non-blocking (0=standard/blocking)
#ifdef CONSOLE_NON_BLOCKING
if(!non_blocking)
set_console(1); // Allways non-blocking from now on ...
#endif
while(1) {
readline(buffer, CMD_LINE_BUFFER_SIZE);

@ -0,0 +1,181 @@
#!/usr/bin/env python3
#
# bit_to_uploadflash.py
# Very basic bitstream to SVF converter, tested with the ULX3S WiFi interface
#
# Modified a little to be used as integral module ...
#
import os
import sys
import textwrap
import datetime
# Very basic bitstream to SVF converter, tested with the ULX3S WiFi interface
def bitreverse(x):
y = 0
for i in range(8):
if (x >> (7 - i)) & 1 == 1:
y |= (1 << i)
return y
def convertBitToUploadFlashFile(bitFile, FlashFile, flash_page_size = 256, address = 0, erase_block_size = 64*1024):
with open(bitFile, 'rb') as bitf:
bs = bitf.read()
# Autodetect IDCODE from bitstream
idcode_cmd = bytes([0xE2, 0x00, 0x00, 0x00])
idcode = None
for i in range(len(bs) - 4):
if bs[i:i+4] == idcode_cmd:
idcode = bs[i+4] << 24
idcode |= bs[i+5] << 16
idcode |= bs[i+6] << 8
idcode |= bs[i+7]
break
if idcode is None:
print("Failed to find IDCODE in bitstream, check bitstream is valid")
sys.exit(1)
print("IDCODE in bitstream is 0x%08x" % idcode)
bitf.seek(0)
last_page = -1
with open(FlashFile, 'w') as svf:
now = datetime.datetime.now()
print(f"""// generated {now:%Y-%m-%d %H:%M}
STATE RESET;
HDR 0;
HIR 0;
TDR 0;
TIR 0;
ENDDR DRPAUSE;
ENDIR IRPAUSE;
STATE IDLE;
""", file=svf)
print("""
SIR 8 TDI (E0);
SDR 32 TDI (00000000)
TDO ({:08X})
MASK (FFFFFFFF);
""".format(idcode), file=svf)
print("""
SIR 8 TDI (1C);
SDR 510 TDI (3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
// Enter Programming mode
SIR 8 TDI (C6);
SDR 8 TDI (00);
RUNTEST IDLE 2 TCK 1.00E-02 SEC;
// Erase
SIR 8 TDI (0E);
SDR 8 TDI (01);
RUNTEST IDLE 2 TCK 2.0E-1 SEC;
// Read STATUS
SIR 8 TDI (3C);
SDR 32 TDI (00000000)
TDO (00000000)
MASK (0000B000);
// Exit Programming mode
SIR 8 TDI (26);
RUNTEST IDLE 2 TCK 1.00E-02 SEC;
// BYPASS
SIR 8 TDI (FF);
STATE IDLE;
RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
// Enter SPI mode
SIR 8 TDI (3A);
SDR 16 TDI (68FE);
STATE IDLE;
RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
// SPI IO (CMD 0xAB release Power Down???)
SDR 8 TDI (D5);
RUNTEST 2.00E-0 SEC;
// CONFIRM FLASH ID (CMD 0x9f JEDEC Flash Id -> Size must be 0x16)
SDR 32 TDI (000000F9)
TDO (68FFFFFF)
MASK (FF000000);
// CMD 0x06 Write Enable + 0x01 Write 0x00 to Status Register
SDR 8 TDI(60);
SDR 16 TDI(0080);
RUNTEST 1.00E-0 SEC;
""", file=svf)
while True:
if((address // 0x10000) != last_page):
last_page = (address // 0x10000)
print(f"// CMD 0x06 Write Enable + 0xd8 Erase 64K at 0x{address:x}", file=svf)
print("SDR 8 TDI (60);", file=svf)
address_flipped = [bitreverse(x) for x in [0xd8,int(address // 0x10000),0x00,0x00]]
hex_address= ["{:02X}".format(x) for x in reversed(address_flipped)]
print("\n".join(textwrap.wrap("SDR {} TDI ({});".format(8*len(hex_address), "".join(hex_address)), 100)), file=svf)
print("RUNTEST 3.00 SEC;\n", file=svf)
chunk = bitf.read(flash_page_size)
if not chunk:
break
# Convert chunk to bit-reversed hex
print(f"// CMD 0x06 Write Enable + 0x02 Write Chunk to 0x{address:x}", file=svf)
br_chunk = [bitreverse(x) for x in bytes([0x02, int(address / 0x10000 % 0x100),int(address / 0x100 % 0x100),int(address % 0x100)]) + chunk]
address += len(chunk)
hex_chunk = ["{:02X}".format(x) for x in reversed(br_chunk)]
print("SDR 8 TDI (60);", file=svf)
print("\n".join(textwrap.wrap("SDR {} TDI ({});".format(8*len(br_chunk), "".join(hex_chunk)), 100)), file=svf)
print("RUNTEST 2.50E-2 SEC;\n", file=svf)
print("""
// BYPASS
SIR 8 TDI (FF);
//REFRESH
SIR 8 TDI(79);
SDR 24 TDI(000000);
STATE IDLE;
RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
STATE RESET;
""", file=svf)
def load2flash(file):
print("--------")
f = open("prog/openocd.cfg", "w")
f.write(
"""
interface vsllink
adapter_khz 100
reset_config none
jtag newtap ecp5 tap -irlen 8 -expected-id 0x41111043
""")
f.close()
os.system(f"openocd -f prog/openocd.cfg -c \"transport select jtag; init; svf {file}; exit\"")
if __name__ == "__main__":
pwd = os.getcwd()
print("Working path: " + pwd)
_, tail = os.path.split(pwd)
if tail == "helpers": # Started within subdir?
relpath = "../"
else:
relpath = "./"
#filename = os.getcwd() + relpath + "/software/build/main"
filename = relpath + "build/colorlight_5a_75b/gateware/colorlight_5a_75b"
os.chdir(relpath + "build/colorlight_5a_75b/gateware")
os.system(f"ecppack colorlight_5a_75b.config --svf colorlight_5a_75b.svf --bit colorlight_5a_75b.bit --bootaddr 0xC0100000")
os.chdir(pwd)
print(f"Translating {filename}.bit to {filename}.svf.flash")
convertBitToUploadFlashFile(filename + ".bit", filename + ".svf.flash", address=0x100000)
print(f"Load/flash {filename}.svf.flash ...")
load2flash(filename + ".svf.flash")

@ -388,12 +388,14 @@ def main():
**soc_core_argdict(args))
# 32MBit SPIFlash (not used currently) ---------------------------------------------------------------
# soc.mem_map["spiflash"] = 0xc0000000
soc.mem_map["spiflash"] = 0xc0000000 # Length: 0x01000000 ('til 0xc1000000 - 1)
# Boot at +1MB
# soc.add_constant("FLASH_BOOT_ADDRESS", soc.mem_map["spiflash"] + 1024*1024)
# soc.add_spi_flash(name="spiflash", mode="1x", dummy_cycles=8, clk_freq=5e6)
soc.add_constant("FLASH_BOOT_ADDRESS", soc.mem_map["spiflash"] + 1024*1024) # 0xc0100000
soc.add_spi_flash(name="spiflash", mode="1x", dummy_cycles=8, clk_freq=5e6)
builder = Builder(soc, **builder_argdict(args))
builder = Builder(soc, **builder_argdict(args))
# Now override boot address
args.ecppack_bootaddr = 0xC0100000
builder.build(**trellis_argdict(args), run=args.build) # Written here to (local) build tree
if args.doc:

@ -0,0 +1,81 @@
#!/bin/bash
#
# flashcreate.sh
# A rather obbscure flash s/w builder (needs transformation to actual makefile setup ;)
#
# History:
# --------
# 21.10.20/KQ Initial (running) version
#
# Test for missing ('zero length') basefilenames
if [ -z $1 ] || [ -z $2 ]; then
echo "usage: ./flashcreate.sh <mainfile_w/o_extension> <jobfile_w/o_extension>"
exit
fi
# Adjust these paths according to your local installation !!!
MY_LOCAL_LITEX_PATH=$HOME"/fpga/litex"
MY_LOCAL_FOMU_PATH=$HOME"/Fomu"
# If you don't use a virtual environment, comment out next line ...
source $HOME/fpga/bin/activate
# Make sure, we use the right compiler version ...
export PATH=$PATH:$MY_LOCAL_LITEX_PATH/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/bin/
TRIPLE="riscv64-unknown-elf"
CPU="vexriscv"
CPUFLAGS="-march=rv32i -mabi=ilp32 -D__vexriscv__"
CPUENDIANNESS="little"
CPU_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/cores/cpu/vexriscv"
COMPILER_RT_DIRECTORY="$MY_LOCAL_LITEX_PATH/pythondata-software-compiler_rt/pythondata_software_compiler_rt/data"
SOC_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc"
#export BUILDINC_DIRECTORY
BUILDINC_DIRECTORY="/mnt/a30054ad-3fe6-444a-8d93-16df937e448e/projects/fpga/neopixelar/build/colorlight_5a_75b/software/include"
LIBCOMPILER_RT_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/software/libcompiler_rt"
LIBBASE_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/software/libbase"
LIBLITEDRAM_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/software/liblitedram"
LIBLITEETH_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/software/libliteeth"
LIBLITESPI_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/software/liblitespi"
LIBLITESDCARD_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/software/liblitesdcard"
BIOS_DIRECTORY="$MY_LOCAL_LITEX_PATH/litex/litex/soc/software/bios"
BIOSPATH="/mnt/a30054ad-3fe6-444a-8d93-16df937e448e/projects/fpga/neopixelar/build/colorlight_5a_75b/software/bios"
OBJECTS="$BIOSPATH/isr.o $BIOSPATH/boot-helper.o $BIOSPATH/boot.o $BIOSPATH/helpers.o $BIOSPATH/cmd_bios.o $BIOSPATH/cmd_mem.o $BIOSPATH/cmd_boot.o $BIOSPATH/cmd_i2c.o $BIOSPATH/cmd_spiflash.o $BIOSPATH/cmd_litedram.o $BIOSPATH/cmd_liteeth.o $BIOSPATH/cmd_litesdcard.o $BIOSPATH/complete.o $BIOSPATH/readline.o"
LXP="../build/colorlight_5a_75b/software"
CRT0="$LXP/libbase/crt0.o"
LXR="-L$LXP/libcompiler_rt -L$LXP/libbase -L$LXP/liblitedram -L$LXP/libliteeth -L$LXP/liblitespi -L$LXP/liblitesdcard -llitedram -lliteeth -llitespi -llitesdcard -lbase-nofloat -lcompiler_rt"
INCLUDES="-I$SOC_DIRECTORY/software/include/base -I$SOC_DIRECTORY/software/include -I$SOC_DIRECTORY/software -I$BUILDINC_DIRECTORY -I$CPU_DIRECTORY -I$BIOS_DIRECTORY"
# -Os optimize for size
#COMMONFLAGS="-Os $CPUFLAGS -g3 -fomit-frame-pointer -Wall -fno-builtin -nostdinc $INCLUDES"
COMMONFLAGS="-O0 $CPUFLAGS -g3 -fomit-frame-pointer -Wall -fno-builtin -nostdinc $INCLUDES"
CFLAGS="-fexceptions -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes"
LDFLAGS="-nostdlib -nodefaultlibs -L$BUILDINC_DIRECTORY"
echo "--"
echo "calling gcc with: -c $COMMONFLAGS $CFLAGS -Wa,-fPIC for $1 & $2"
#$MY_LOCAL_LITEX_PATH/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc -O0 -S -nostdinc $COMMONFLAGS $INCLUDES -Wa,-fPIC source/$1.c
$MY_LOCAL_LITEX_PATH/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc -c $COMMONFLAGS $CFLAGS -Wa,-fPIC source/$2.c -o build/$2.o
$MY_LOCAL_LITEX_PATH/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc -c $COMMONFLAGS $CFLAGS -Wa,-fPIC source/$1.c -o build/$1.o
echo "--"
echo "calling ld for flash with: $LDFLAGS $OBJECTS build/$2.o build/$1.o -o build/$1.bin"
$MY_LOCAL_LITEX_PATH/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-ld $LDFLAGS -T linker/flash.ld -N $CRT0 $OBJECTS $LXR build/$2.o build/$1.o -o build/$1.elf
echo "--"
echo "creating raw binary from elf-file"
$MY_LOCAL_LITEX_PATH/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/riscv64-unknown-elf/bin/objcopy -O binary -S --image-base 0xc0100000 build/$1.elf build/$1.bin
#echo "--"
#echo "creating disassembly dump build/$1.dis"
#$MY_LOCAL_LITEX_PATH/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-objdump -D -b binary build/$1.bin -m riscv >build/$1.dis
ecppack colorlight_5a_75b.config --svf colorlight_5a_75b.svf --bit colorlight_5a_75b.bit --bootaddr 0xc0100000
#echo "--"
#echo "loading build/$1.bin to flash boot adress via wishbone-tool"
#$MY_LOCAL_FOMU_PATH/fomu-toolchain-linux_x86_64-v1.5.6/bin/wishbone-tool --ethernet-host 192.168.1.20 --server load-file --csr-csv ../build/csr.csv --load-address 0xc0100000 --load-name build/$1.bin
#echo "--"
#echo "Connecting to remote terminal w/ wishbone-tool (press ESC to terminate ...)"
#$MY_LOCAL_FOMU_PATH/fomu-toolchain-linux_x86_64-v1.5.6/bin/wishbone-tool --ethernet-host 192.168.1.20 --server terminal --csr-csv ../build/csr.csv
# alternatively use:
# screen /dev/ttyUSB0 115200
# Press 'Ctrl-A k' to terminate ...
echo "Done (don't worry about the download 'error' in red!)."

@ -0,0 +1,89 @@
INCLUDE linker/output_format.ld
/* ENTRY(_start) */
ENTRY(illumination)
INCLUDE ../build/colorlight_5a_75b/software/include/generated/regions.ld
MEMORY {
spiflboot : ORIGIN = 0xc0100000, LENGTH = 0x00E00000
}
SECTIONS
{
.text :
{
_ftext = .;
/* Make sure crt0 files come first, and they, and the isr */
/* don't get disposed of by greedy optimisation */
*crt0*(.text)
KEEP(*crt0*(.text))
KEEP(*(.text.isr))
*(.text .stub .text.* .gnu.linkonce.t.*)
_etext = .;
} > spiflboot
.rodata :
{
. = ALIGN(8);
_frodata = .;
*(.rodata .rodata.* .gnu.linkonce.r.*)
*(.rodata1)
*(.got .got.*)
*(.toc .toc.*)
/* Make sure the file is aligned on disk as well
as in memory; CRC calculation requires that. */
FILL(0);
. = ALIGN(8);
_erodata = .;
} > spiflboot
.commands :
{
PROVIDE_HIDDEN (__bios_cmd_start = .);
KEEP(*(.bios_cmd))
PROVIDE_HIDDEN (__bios_cmd_end = .);
} > spiflboot
.data :
{
. = ALIGN(8);
_fdata = .;
*(.data .data.* .gnu.linkonce.d.*)
*(.data1)
*(.sdata .sdata.* .gnu.linkonce.s.*)
/* Make sure the file is aligned on disk as well
as in memory; CRC calculation requires that. */
FILL(0);
. = ALIGN(8);
_edata = .;
} > sram AT > spiflboot
.bss :
{
. = ALIGN(8);
_fbss = .;
*(.dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(8);
_ebss = .;
_end = .;
} > sram AT > spiflboot
/DISCARD/ :
{
*(.eh_frame)
*(.comment)
}
}
PROVIDE(_fstack = ORIGIN(sram) + LENGTH(sram) - 8);
PROVIDE(_fdata_rom = LOADADDR(.data));
PROVIDE(_edata_rom = LOADADDR(.data) + SIZEOF(.data));

@ -44,14 +44,13 @@
extern void busy_wait(unsigned int ms); // Worx!
extern char kbhit(void);
extern int32_t cpc; // Current PC storage
#define CONSOLE_NON_BLOCKING 1
#ifdef CONSOLE_NON_BLOCKING
extern void set_console(int non_blocking);
#endif
extern int readchar_nonblock(void);
char kbhit(void)
{
if(readchar_nonblock())
return readchar();
return '\0';
}
extern int32_t cpc; // Current PC storage
int main(int i, char **c)
{
@ -78,11 +77,8 @@ int main(int i, char **c)
");
if((cpc >= MAIN_RAM_BASE) && (cpc <= (MAIN_RAM_BASE + MAIN_RAM_SIZE))) {
printf("\e[1mExecuting within RAM ...\e[0m\n");
#define CONSOLE_NON_BLOCKING 1
#ifdef CONSOLE_NON_BLOCKING
extern void set_console(int non_blocking);
set_console(1); // 1=Non-blocking (0=standard/blocking)
extern int readchar_nonblock(void);
#endif
while(1)
if(illumination()) // The DEMO !

Loading…
Cancel
Save