Bitstream conversion integrated, flash fails ...

master
kaqu 2 years ago
parent 702443ce05
commit f126ec28c0
  1. 5
      .vscode/launch.json
  2. 186
      bit_to_flash.py
  3. 5
      firmware/main.c
  4. 9
      neopixelar.py

@ -9,13 +9,14 @@
"type": "python",
"request": "launch",
"program": "${file}",
"args": ["--build",
"args": [//"--build",
"--flash",
"--revision=7.0",
"--uart-name=crossover",
"--with-etherbone",
"--ip-address=192.168.1.20",
"--csr-csv=build/csr.csv", // Only this one for remotetest.py!
"--doc"
//"--doc"
],
//"args": ["--build"],
//"pythonArgs": ["--build", "--uart-name=crossover"],

@ -1,22 +1,27 @@
#!/usr/bin/env python3
import sys
import textwrap
# Very basic bitstream to SVF converter, tested with the ULX3S WiFi interface
flash_page_size = 256
erase_block_size = 64*1024
def bitreverse(x):
y = 0
for i in range(8):
if (x >> (7 - i)) & 1 == 1:
y |= (1 << i)
return y
with open(sys.argv[1], 'rb') as bitf:
#!/usr/bin/env python3
#
# bit_to_flash.py
# Very basic bitstream to SVF converter, tested with the ULX3S WiFi interface
#
# Modified a little to be used as integral module ...
#
import sys
import textwrap
flash_page_size = 256
erase_block_size = 64*1024
def bitreverse(x):
y = 0
for i in range(8):
if (x >> (7 - i)) & 1 == 1:
y |= (1 << i)
return y
def bit2svf(bitfilename, svffilename):
with open(bitfilename, 'rb') as bitf:
bs = bitf.read()
# Autodetect IDCODE from bitstream
idcode_cmd = bytes([0xE2, 0x00, 0x00, 0x00])
@ -37,75 +42,75 @@
address = 0
last_page = -1
with open(sys.argv[2], 'w') as svf:
with open(svffilename, 'w') as svf:
print("""
STATE RESET;
HDR 0;
HIR 0;
TDR 0;
TIR 0;
ENDDR DRPAUSE;
ENDIR IRPAUSE;
STATE IDLE;
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);
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);
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;
// 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;
// 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);
// 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;
// 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;
// BYPASS
SIR 8 TDI (FF);
STATE IDLE;
RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
// Enter SPI mode
// Enter SPI mode
SIR 8 TDI (3A);
SDR 16 TDI (68FE);
STATE IDLE;
RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
SIR 8 TDI (3A);
SDR 16 TDI (68FE);
STATE IDLE;
RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
// SPI IO
SDR 8 TDI (D5);
// SPI IO
SDR 8 TDI (D5);
RUNTEST 2.00E-0 SEC;
RUNTEST 2.00E-0 SEC;
// CONFIRM FLASH ID
!SDR 32 TDI (000000F9)
! TDO (68FFFFFF)
! MASK (FF000000);
// CONFIRM FLASH ID
!SDR 32 TDI (000000F9)
! TDO (68FFFFFF)
! MASK (FF000000);
!SDR 8 TDI(60);
!SDR 16 TDI(0080);
!RUNTEST 1.00E-0 SEC;
!SDR 8 TDI(60);
!SDR 16 TDI(0080);
!RUNTEST 1.00E-0 SEC;
""", file=svf)
@ -128,23 +133,28 @@
address += len(chunk)
hex_chunk = ["{:02X}".format(x) for x in reversed(br_chunk)]
print("""
SDR 8 TDI (60);
""", file=svf)
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;
""", file=svf)
RUNTEST 2.50E-2 SEC;
""", 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)
// 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)
if __name__ == "__main__":
filename = './build/colorlight_5a_75b/gateware/colorlight_5a_75b'
print(f"Translating {filename}.bit to {filename}.svf.flash")
bit2svf(filename + ".bit", filename + ".svf.flash")

@ -70,11 +70,12 @@ static void boot_sequence(void)
long mysleep(long delayms)
{
long r;
long r = 0l;
for(long l=0;l<delayms;l++)
for(long m=0;m<0xFFFFFFl;m++)
r += (long)(m*l/(m * m));
for(long n=0;n<0xFFFFFFl;n++)
r += (long)(m*l/(m * m))*n;
return r;
}

@ -342,8 +342,8 @@ class BaseSoC(SoCCore):
# Build --------------------------------------------------------------------------------------------
def load(file):
import os
os.system("mkdir -p prog")
#import os
#os.system("mkdir -p prog")
print("--------")
f = open("prog/openocd.cfg", "w")
f.write(
@ -408,11 +408,14 @@ def main():
if args.load:
prog = soc.platform.create_programmer()
prog.load_bitstream(os.path.join(builder.gateware_dir, soc.build_name + ".svf"))
return
if args.flash: # Convert Bit File to Jtag Write Flash command
name = os.path.join(builder.gateware_dir, soc.build_name)
print(f"Executing ./bit_to_flash.py {name}.bit {name}.svf.flash")
os.system(f"./bit_to_flash.py {name}.bit {name}.svf.flash")
#os.system(f"./bit_to_flash.py {name}.bit {name}.svf.flash")
from bit_to_flash import bit2svf
bit2svf(name + ".bit", name + ".svf.flash")
load(name + ".svf.flash")
return

Loading…
Cancel
Save