Dual bank loader (eases testing) w/o reset nec.!

master
kaqu 2 years ago
parent f916787572
commit 58cb641ca1
  1. 10
      firmware/boot.c
  2. 30
      firmware/cmd_mem.c
  3. BIN
      helpers/__pycache__/bit_to_flash.cpython-38.pyc
  4. BIN
      helpers/__pycache__/load_to_flash.cpython-38.pyc
  5. 0
      software/linker/ram1.ld
  6. 89
      software/linker/ram2.ld
  7. 26
      software/ramcreate.sh
  8. 2
      software/source/main.c

@ -676,9 +676,13 @@ void sdcardboot(void)
#define RAM_BOOT_OPTION 1
#ifdef RAM_BOOT_OPTION
void doRAMboot(void)
extern void doRAMboot(int ramno);
void doRAMboot(int ramno)
{
printf("Trying RAM boot ...\n");
boot(0, 0, 0, MAIN_RAM_BASE);
printf("Trying RAM boot [%d]...\n", ramno);
if(ramno == 2)
boot(0, 0, 0, MAIN_RAM_BASE + (MAIN_RAM_SIZE / 2));
else
boot(0, 0, 0, MAIN_RAM_BASE);
}
#endif

@ -577,13 +577,31 @@ define_command(dumpregs, dumpregs, "Dump processor registers", MEM_CMDS);
*/
#define CMD_MEM_RAMBOOT 1
#ifdef CMD_MEM_RAMBOOT
int32_t cpc; // Current PC storage
static void ramboot(int nb_params, char **params)
{
extern void doRAMboot(void);
extern void doRAMboot(int ramno);
int ramno;
char *c;
c = (char *)MAIN_RAM_BASE; //0x40000000
// Verify where we're executing (within RAM) ...
__asm__ __volatile__ ("\
lui t0,%hi(cpc) # Load t0 w/ high adress of cpc \n\
addi t0,t0,%lo(cpc) # Add immediate t0=t0 + low adress cpc \n\
# t0 now loaded with pointer to cpc \n\
auipc t1,0 # Load current pc \n\
sw t1,0(t0) # Store current PC \n\
");
// Executing in RAM bank #1?
if((cpc >= MAIN_RAM_BASE) && (cpc < (MAIN_RAM_BASE + (MAIN_RAM_SIZE / 2)))) {
ramno = 2; // Boot RAM[2] hence!
printf("\e[1mExecuting within RAM bank #1 -> Booting RAM banking #2 ...\e[0m\n");
c = (char *)(MAIN_RAM_BASE + (MAIN_RAM_SIZE / 2)); //0x40200000
}
else { // Nope, in RAM bank #2 assumed ...
ramno = 1; // Boot RAM[1]
c = (char *)MAIN_RAM_BASE; //0x40000000
}
if( (*(c + 0) == 0xff)
&& (*(c + 1) == 0xff)
&& (*(c + 2) == 0xff)
@ -594,10 +612,10 @@ static void ramboot(int nb_params, char **params)
&& (*(c + 7) == 0xff)
)
{
printf("No program loaded to RAM?!\n");
printf("No program loaded to RAM bank #%d?!\n", ramno);
return;
}
doRAMboot(); // Try to boot ...
doRAMboot(ramno); // Try to boot ...
}
define_command(ramboot, ramboot, "Boot from RAM", MEM_CMDS);

@ -0,0 +1,89 @@
INCLUDE linker/output_format.ld
/* ENTRY(_start) */
ENTRY(illumination)
INCLUDE ../build/colorlight_5a_75b/software/include/generated/regions.ld
MEMORY {
main_ram2 : ORIGIN = 0x40200000, LENGTH = 0x00200000
}
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 = .;
} > main_ram2
.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 = .;
} > main_ram2
.commands :
{
PROVIDE_HIDDEN (__bios_cmd_start = .);
KEEP(*(.bios_cmd))
PROVIDE_HIDDEN (__bios_cmd_end = .);
} > main_ram2
.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 > main_ram2
.bss :
{
. = ALIGN(8);
_fbss = .;
*(.dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(8);
_ebss = .;
_end = .;
} > sram AT > main_ram2
/DISCARD/ :
{
*(.eh_frame)
*(.comment)
}
}
PROVIDE(_fstack = ORIGIN(sram) + LENGTH(sram) - 8);
PROVIDE(_fdata_rom = LOADADDR(.data));
PROVIDE(_edata_rom = LOADADDR(.data) + SIZEOF(.data));

@ -9,9 +9,9 @@
#
# Test for missing ('zero length') basefilenames
if [[ -z $1 || -z $2 ]]; then
echo "usage: ./ramcreate.sh <mainfile_w/o_extension> <jobfile_w/o_extension>"
echo "example: ./ramcreate.sh main illumination"
if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
echo "usage: ./ramcreate.sh <mainfile_w/o_extension> <jobfile_w/o_extension> <1|2>"
echo "example: ./ramcreate.sh main illumination 1 (for RAM bank #1)"
exit
fi
@ -61,17 +61,29 @@ 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 -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 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/linker.ld -N $CRT0 $OBJECTS $LXR build/$2.o build/$1.o -o build/$1.elf
echo "calling ld for RAM bank #$3 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/ram$3.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 0x40000000 build/$1.elf build/$1.bin
if [ "$3" = "1" ]; then
echo "for bank #1"
$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 0x40000000 build/$1.elf build/$1.bin
else
echo "for bank #2"
$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 0x40200000 build/$1.elf build/$1.bin
fi
#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
echo "--"
echo "loading build/$1.bin to RAM base 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 0x40000000 --load-name build/$1.bin
if [ "$3" = "1" ]; then
echo "for bank #1"
$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 0x40000000 --load-name build/$1.bin
else
echo "for bank #2"
$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 0x40200000 --load-name build/$1.bin
fi
#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

@ -44,7 +44,7 @@
extern void busy_wait(unsigned int ms); // Worx!
extern char kbhit(void);
int32_t cpc; // Current PC storage
extern int32_t cpc; // Current PC storage
char kbhit(void)
{

Loading…
Cancel
Save