mirror of
https://github.com/antonblanchard/microwatt.git
synced 2026-02-08 09:01:36 +00:00
By default openocd tries to "guess" the file type and interpret it accordingly. For example it will detect an ELF file based on the presence of an ELF header and will try to load the relevant segments into the flash. This may not be what we want. For example, I want to load the raw ELF file into the flash. Additionally the ELF parser in most distro's OpenOCD version only supports ELF32 and will error out. This adds a "-t" argument to flash-arty to allow us to specify the file format. For example "-t bin" will treat the file as raw binary. Unfortunately I had to copy and modify jtagspi.cfg from OpenOCD to achieve this. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
41 lines
1.3 KiB
Python
Executable File
41 lines
1.3 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
BASE = os.path.dirname(os.path.abspath(__file__))
|
|
CONFIG = os.path.join(BASE, "xilinx-xc7.cfg")
|
|
|
|
def flash(config, flash_proxy, address, data, filetype="", set_qe=False):
|
|
script = "; ".join([
|
|
"init",
|
|
"jtagspi_init 0 {{{}}}".format(flash_proxy),
|
|
"jtagspi set_qe 0 1" if set_qe else "",
|
|
"jtagspi_program {{{}}} 0x{:x} {}".format(data, address, filetype),
|
|
"fpga_program",
|
|
"exit"
|
|
])
|
|
print(script)
|
|
subprocess.call(["openocd", "-f", config, "-c", script])
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("file", help="file to write to flash")
|
|
parser.add_argument("-a", "--address", help="offset in flash", type=lambda x: int(x,0), default=0)
|
|
parser.add_argument("-f", "--fpga", help="a35 or a100", default="a35")
|
|
parser.add_argument("-t", "--filetype", help="file type such as 'bin'", default="")
|
|
args = parser.parse_args()
|
|
|
|
if args.fpga.lower() == "a35":
|
|
proxy = "bscan_spi_xc7a35t.bit"
|
|
elif args.fpga.lower() == "a100":
|
|
proxy = "bscan_spi_xc7a100t.bit"
|
|
else:
|
|
print("error: specify a35 or a100 when flashing")
|
|
sys.exit()
|
|
|
|
proxy = os.path.join(BASE, proxy)
|
|
|
|
flash(CONFIG, proxy, args.address, args.file, args.filetype.lower())
|