Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
inputs.uv2nix.follows = "uv2nix";
};
ftditool = {
url = "github:lowRISC/ftditool?ref=v0.3.1";
url = "github:lowRISC/ftditool?ref=v0.4.0";
inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand Down
26 changes: 2 additions & 24 deletions util/fpga_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import serial
import serial.tools.list_ports
from elftools.elf.elffile import ELFFile

FTDI_PID: int = 0x6010
BAUD_RATE: int = 1_000_000
Expand Down Expand Up @@ -71,39 +70,18 @@ async def bootstrap(uart: serial.Serial | None) -> None:
await set_pin(0, True)


def get_load_addr(elf: Path) -> int:
try:
with elf.open("rb") as f:
elf = ELFFile(f)
load_addrs = [
seg["p_paddr"] for seg in elf.iter_segments() if seg["p_type"] == "PT_LOAD"
]
if not load_addrs:
print(f"[{RUNNER}] no PT_LOAD segments found in ELF file {elf}")
sys.exit(1)
return min(load_addrs)
except OSError as e:
print(f"[{RUNNER}] error opening ELF file {elf}: {e}")
sys.exit(1)


async def load_fpga_binary(path: Path, uart: serial.Serial | None) -> None:
load_address = get_load_addr(path)

await bootstrap(uart)

command = [
"ftditool",
"--pid",
hex(FTDI_PID),
"bootstrap",
"--addr",
hex(load_address),
"--skip-erase",
"bootstrap-elf",
str(path),
"--ftdi",
FTDI_DEVICE_DESC,
]
command.append(str(path.with_suffix(".bin")))

p = await asyncio.create_subprocess_exec(*command)
if await p.wait() != 0:
Expand Down