forked from M-Labs/artiq
simplify board package format and artiq_flash
This commit is contained in:
parent
6dfc854673
commit
65eab31f23
|
@ -13,7 +13,6 @@ from collections import defaultdict
|
||||||
from sipyco import common_args
|
from sipyco import common_args
|
||||||
|
|
||||||
from artiq import __version__ as artiq_version
|
from artiq import __version__ as artiq_version
|
||||||
from artiq import __artiq_dir__ as artiq_dir
|
|
||||||
from artiq.remoting import SSHClient, LocalClient
|
from artiq.remoting import SSHClient, LocalClient
|
||||||
from artiq.frontend.bit2bin import bit2bin
|
from artiq.frontend.bit2bin import bit2bin
|
||||||
|
|
||||||
|
@ -63,13 +62,11 @@ Prerequisites:
|
||||||
parser.add_argument("-t", "--target", default="kasli",
|
parser.add_argument("-t", "--target", default="kasli",
|
||||||
help="target board, default: %(default)s, one of: "
|
help="target board, default: %(default)s, one of: "
|
||||||
"kasli sayma metlino kc705")
|
"kasli sayma metlino kc705")
|
||||||
parser.add_argument("-V", "--variant", default=None,
|
|
||||||
help="board variant. Autodetected if only one is installed.")
|
|
||||||
parser.add_argument("-I", "--preinit-command", default=[], action="append",
|
parser.add_argument("-I", "--preinit-command", default=[], action="append",
|
||||||
help="add a pre-initialization OpenOCD command. "
|
help="add a pre-initialization OpenOCD command. "
|
||||||
"Useful for selecting a board when several are connected.")
|
"Useful for selecting a board when several are connected.")
|
||||||
parser.add_argument("-f", "--storage", help="write file to storage area")
|
parser.add_argument("-f", "--storage", help="write file to storage area")
|
||||||
parser.add_argument("-d", "--dir", help="look for board binaries in this directory")
|
parser.add_argument("-d", "--dir", default=None, help="look for board binaries in this directory")
|
||||||
parser.add_argument("--srcbuild", help="board binaries directory is laid out as a source build tree",
|
parser.add_argument("--srcbuild", help="board binaries directory is laid out as a source build tree",
|
||||||
default=False, action="store_true")
|
default=False, action="store_true")
|
||||||
parser.add_argument("--no-rtm-jtag", help="do not attempt JTAG to the RTM",
|
parser.add_argument("--no-rtm-jtag", help="do not attempt JTAG to the RTM",
|
||||||
|
@ -338,56 +335,19 @@ def main():
|
||||||
},
|
},
|
||||||
}[args.target]
|
}[args.target]
|
||||||
|
|
||||||
bin_dir = args.dir
|
|
||||||
if bin_dir is None:
|
|
||||||
bin_dir = os.path.join(artiq_dir, "board-support")
|
|
||||||
|
|
||||||
needs_artifacts = not args.action or any(
|
|
||||||
action in args.action
|
|
||||||
for action in ["gateware", "rtm_gateware", "bootloader", "firmware", "load", "rtm_load"])
|
|
||||||
variant = args.variant
|
|
||||||
if needs_artifacts and variant is None:
|
|
||||||
variants = []
|
|
||||||
if args.srcbuild:
|
|
||||||
for entry in os.scandir(bin_dir):
|
|
||||||
if entry.is_dir():
|
|
||||||
variants.append(entry.name)
|
|
||||||
else:
|
|
||||||
prefix = args.target + "-"
|
|
||||||
for entry in os.scandir(bin_dir):
|
|
||||||
if entry.is_dir() and entry.name.startswith(prefix):
|
|
||||||
variants.append(entry.name[len(prefix):])
|
|
||||||
if args.target == "sayma":
|
|
||||||
try:
|
|
||||||
variants.remove("rtm")
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
if all(action in ["rtm_gateware", "storage", "rtm_load", "erase", "start"]
|
|
||||||
for action in args.action) and args.action:
|
|
||||||
pass
|
|
||||||
elif len(variants) == 0:
|
|
||||||
raise FileNotFoundError("no variants found, did you install a board binary package?")
|
|
||||||
elif len(variants) == 1:
|
|
||||||
variant = variants[0]
|
|
||||||
else:
|
|
||||||
raise ValueError("more than one variant found for selected board, specify -V. "
|
|
||||||
"Found variants: {}".format(" ".join(sorted(variants))))
|
|
||||||
if needs_artifacts:
|
|
||||||
if args.srcbuild:
|
|
||||||
variant_dir = variant
|
|
||||||
else:
|
|
||||||
variant_dir = args.target + "-" + variant
|
|
||||||
if args.target == "sayma":
|
|
||||||
if args.srcbuild:
|
|
||||||
rtm_variant_dir = "rtm"
|
|
||||||
else:
|
|
||||||
rtm_variant_dir = "sayma-rtm"
|
|
||||||
|
|
||||||
if not args.action:
|
if not args.action:
|
||||||
if args.target == "sayma" and variant != "simplesatellite" and variant != "master":
|
if args.target == "sayma":
|
||||||
args.action = "gateware rtm_gateware bootloader firmware start".split()
|
args.action = "gateware rtm_gateware bootloader firmware start".split()
|
||||||
else:
|
else:
|
||||||
args.action = "gateware bootloader firmware start".split()
|
args.action = "gateware bootloader firmware start".split()
|
||||||
|
needs_artifacts = any(
|
||||||
|
action in args.action
|
||||||
|
for action in ["gateware", "rtm_gateware", "bootloader", "firmware", "load", "rtm_load"])
|
||||||
|
if needs_artifacts and args.dir is None:
|
||||||
|
raise ValueError("the directory containing the binaries need to be specified using -d.")
|
||||||
|
|
||||||
|
binary_dir = args.dir
|
||||||
|
rtm_binary_dir = os.path.join(binary_dir, "rtm")
|
||||||
|
|
||||||
if args.host is None:
|
if args.host is None:
|
||||||
client = LocalClient()
|
client = LocalClient()
|
||||||
|
@ -400,14 +360,14 @@ def main():
|
||||||
programmer_cls = config["programmer"]
|
programmer_cls = config["programmer"]
|
||||||
programmer = programmer_cls(client, preinit_script=args.preinit_command)
|
programmer = programmer_cls(client, preinit_script=args.preinit_command)
|
||||||
|
|
||||||
def artifact_path(this_variant_dir, *path_filename):
|
def artifact_path(this_binary_dir, *path_filename):
|
||||||
if args.srcbuild:
|
if args.srcbuild:
|
||||||
# source tree - use path elements to locate file
|
# source tree - use path elements to locate file
|
||||||
return os.path.join(bin_dir, this_variant_dir, *path_filename)
|
return os.path.join(this_binary_dir, *path_filename)
|
||||||
else:
|
else:
|
||||||
# flat tree - all files in the same directory, discard path elements
|
# flat tree - all files in the same directory, discard path elements
|
||||||
*_, filename = path_filename
|
*_, filename = path_filename
|
||||||
return os.path.join(bin_dir, this_variant_dir, filename)
|
return os.path.join(this_binary_dir, filename)
|
||||||
|
|
||||||
def convert_gateware(bit_filename, header=False):
|
def convert_gateware(bit_filename, header=False):
|
||||||
bin_handle, bin_filename = tempfile.mkstemp(
|
bin_handle, bin_filename = tempfile.mkstemp(
|
||||||
|
@ -429,15 +389,15 @@ def main():
|
||||||
for action in args.action:
|
for action in args.action:
|
||||||
if action == "gateware":
|
if action == "gateware":
|
||||||
gateware_bin = convert_gateware(
|
gateware_bin = convert_gateware(
|
||||||
artifact_path(variant_dir, "gateware", "top.bit"))
|
artifact_path(binary_dir, "gateware", "top.bit"))
|
||||||
programmer.write_binary(*config["gateware"], gateware_bin)
|
programmer.write_binary(*config["gateware"], gateware_bin)
|
||||||
elif action == "rtm_gateware":
|
elif action == "rtm_gateware":
|
||||||
rtm_gateware_bin = convert_gateware(
|
rtm_gateware_bin = convert_gateware(
|
||||||
artifact_path(rtm_variant_dir, "gateware", "top.bit"), header=True)
|
artifact_path(rtm_binary_dir, "gateware", "top.bit"), header=True)
|
||||||
programmer.write_binary(*config["rtm_gateware"],
|
programmer.write_binary(*config["rtm_gateware"],
|
||||||
rtm_gateware_bin)
|
rtm_gateware_bin)
|
||||||
elif action == "bootloader":
|
elif action == "bootloader":
|
||||||
bootloader_bin = artifact_path(variant_dir, "software", "bootloader", "bootloader.bin")
|
bootloader_bin = artifact_path(binary_dir, "software", "bootloader", "bootloader.bin")
|
||||||
programmer.write_binary(*config["bootloader"], bootloader_bin)
|
programmer.write_binary(*config["bootloader"], bootloader_bin)
|
||||||
elif action == "storage":
|
elif action == "storage":
|
||||||
storage_img = args.storage
|
storage_img = args.storage
|
||||||
|
@ -445,7 +405,7 @@ def main():
|
||||||
elif action == "firmware":
|
elif action == "firmware":
|
||||||
firmware_fbis = []
|
firmware_fbis = []
|
||||||
for firmware in "satman", "runtime":
|
for firmware in "satman", "runtime":
|
||||||
filename = artifact_path(variant_dir, "software", firmware, firmware + ".fbi")
|
filename = artifact_path(binary_dir, "software", firmware, firmware + ".fbi")
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
firmware_fbis.append(filename)
|
firmware_fbis.append(filename)
|
||||||
if not firmware_fbis:
|
if not firmware_fbis:
|
||||||
|
@ -456,13 +416,13 @@ def main():
|
||||||
programmer.write_binary(*config["firmware"], firmware_fbis[0])
|
programmer.write_binary(*config["firmware"], firmware_fbis[0])
|
||||||
elif action == "load":
|
elif action == "load":
|
||||||
if args.target == "sayma":
|
if args.target == "sayma":
|
||||||
gateware_bit = artifact_path(variant_dir, "gateware", "top.bit")
|
gateware_bit = artifact_path(binary_dir, "gateware", "top.bit")
|
||||||
programmer.load(gateware_bit, 1)
|
programmer.load(gateware_bit, 1)
|
||||||
else:
|
else:
|
||||||
gateware_bit = artifact_path(variant_dir, "gateware", "top.bit")
|
gateware_bit = artifact_path(binary_dir, "gateware", "top.bit")
|
||||||
programmer.load(gateware_bit, 0)
|
programmer.load(gateware_bit, 0)
|
||||||
elif action == "rtm_load":
|
elif action == "rtm_load":
|
||||||
rtm_gateware_bit = artifact_path(rtm_variant_dir, "gateware", "top.bit")
|
rtm_gateware_bit = artifact_path(rtm_binary_dir, "gateware", "top.bit")
|
||||||
programmer.load(rtm_gateware_bit, 0)
|
programmer.load(rtm_gateware_bit, 0)
|
||||||
elif action == "start":
|
elif action == "start":
|
||||||
programmer.start()
|
programmer.start()
|
||||||
|
|
10
flake.nix
10
flake.nix
|
@ -260,7 +260,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
makeArtiqBoardPackage = { target, variant, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}" }:
|
makeArtiqBoardPackage = { target, variant, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}" }:
|
||||||
pkgs.python3Packages.toPythonModule (pkgs.stdenv.mkDerivation {
|
pkgs.stdenv.mkDerivation {
|
||||||
name = "artiq-board-${target}-${variant}";
|
name = "artiq-board-${target}-${variant}";
|
||||||
phases = [ "buildPhase" "checkPhase" "installPhase" ];
|
phases = [ "buildPhase" "checkPhase" "installPhase" ];
|
||||||
cargoDeps = rustPlatform.fetchCargoTarball {
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
||||||
|
@ -299,7 +299,7 @@
|
||||||
'';
|
'';
|
||||||
installPhase =
|
installPhase =
|
||||||
''
|
''
|
||||||
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}
|
TARGET_DIR=$out
|
||||||
mkdir -p $TARGET_DIR
|
mkdir -p $TARGET_DIR
|
||||||
cp artiq_${target}/${variant}/gateware/top.bit $TARGET_DIR
|
cp artiq_${target}/${variant}/gateware/top.bit $TARGET_DIR
|
||||||
if [ -e artiq_${target}/${variant}/software/bootloader/bootloader.bin ]
|
if [ -e artiq_${target}/${variant}/software/bootloader/bootloader.bin ]
|
||||||
|
@ -312,7 +312,7 @@
|
||||||
'';
|
'';
|
||||||
# don't mangle ELF files as they are not for NixOS
|
# don't mangle ELF files as they are not for NixOS
|
||||||
dontFixup = true;
|
dontFixup = true;
|
||||||
});
|
};
|
||||||
|
|
||||||
openocd-bscanspi = let
|
openocd-bscanspi = let
|
||||||
bscan_spi_bitstreams-pkg = pkgs.stdenv.mkDerivation {
|
bscan_spi_bitstreams-pkg = pkgs.stdenv.mkDerivation {
|
||||||
|
@ -454,7 +454,7 @@
|
||||||
__networked = true;
|
__networked = true;
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(pkgs.python3.withPackages(ps: with packages.x86_64-linux; [ artiq artiq-board-kc705-nist_clock ps.paramiko ]))
|
(pkgs.python3.withPackages(ps: with packages.x86_64-linux; [ artiq ps.paramiko ]))
|
||||||
pkgs.llvm_11
|
pkgs.llvm_11
|
||||||
pkgs.lld_11
|
pkgs.lld_11
|
||||||
pkgs.openssh
|
pkgs.openssh
|
||||||
|
@ -488,7 +488,7 @@
|
||||||
# Read "Ok" line when remote successfully locked
|
# Read "Ok" line when remote successfully locked
|
||||||
read LOCK_OK
|
read LOCK_OK
|
||||||
|
|
||||||
artiq_flash -t kc705 -H rpi-1
|
artiq_flash -t kc705 -H rpi-1 -d ${packages.x86_64-linux.artiq-board-kc705-nist_clock}
|
||||||
sleep 15
|
sleep 15
|
||||||
|
|
||||||
export ARTIQ_ROOT=`python -c "import artiq; print(artiq.__path__[0])"`/examples/kc705_nist_clock
|
export ARTIQ_ROOT=`python -c "import artiq; print(artiq.__path__[0])"`/examples/kc705_nist_clock
|
||||||
|
|
Loading…
Reference in New Issue