Skip to content

Commit

Permalink
Merge pull request #94 from sdgtt/pluto/m2k-downloader
Browse files Browse the repository at this point in the history
Pluto/m2k downloader
  • Loading branch information
kimpaller authored Jun 1, 2023
2 parents c8bb24d + 01a3983 commit c5fa175
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 37 deletions.
77 changes: 49 additions & 28 deletions nebula/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def convert_to_datetime(date):
return datetime.strptime(date[:10], "%Y_%m_%d")


def get_firmware_version(links):
version = None
for link in links:
file = link.split("/")[-1]
if "zip" in file:
version = file
return version


def get_latest_release(links):
latest = "0000_r1"
for link in links:
Expand Down Expand Up @@ -279,40 +288,52 @@ def __init__(self, http_server_ip=None, yamlfilename=None, board_name=None):
yamlfilename, __class__.__name__, board_name=board_name
)

def _download_firmware(self, device, release=None):
if release == "master" or release == "release":
release = None

def _download_firmware(self, device, source="github", release=None):
if "m2k" in device.lower() or "adalm-2000" in device.lower():
dev = "m2k"
elif "pluto" in device.lower():
dev = "plutosdr"
else:
raise Exception("Unknown device " + device)

if not release:
# Get latest
log.info("Release not set. Checking github for latest")
g = Github()
repo = g.get_repo("analogdevicesinc/{}-fw".format(dev))
rel = repo.get_releases()
p = rel.get_page(0)
r = p[0]
release = r.tag_name
log.info("Using release: " + release)

matched = re.match("v[0-1].[0-9][0-9]", release)
is_match = bool(matched)
assert is_match, "Version name invalid"

url = "https://github.com/analogdevicesinc/{dev}-fw/releases/download/{rel}/{dev}-fw-{rel}.zip".format(
dev=dev, rel=release
)
dest = "outs"
if not os.path.isdir(dest):
os.mkdir(dest)
release = os.path.join(dest, dev + "-fw-" + release + ".zip")
self.download(url, release)
if source == "github":
if release == "master" or release == "release":
release = None
if not release:
# Get latest
log.info("Release not set. Checking github for latest")
g = Github()
repo = g.get_repo("analogdevicesinc/{}-fw".format(dev))
rel = repo.get_releases()
p = rel.get_page(0)
r = p[0]
release = r.tag_name
log.info("Using release: " + release)

matched = re.match("v[0-1].[0-9][0-9]", release)
is_match = bool(matched)
assert is_match, "Version name invalid"

url = "https://github.com/analogdevicesinc/{dev}-fw/releases/download/{rel}/{dev}-fw-{rel}.zip".format(
dev=dev, rel=release
)
dest = "outs"
if not os.path.isdir(dest):
os.mkdir(dest)
filename = os.path.join(dest, dev + "-fw-" + release + ".zip")
elif source == "artifactory":
url_template = "https://artifactory.analog.com/artifactory/sdg-generic-development/m2k_and_pluto/{}-fw/{}/{}"
url = url_template.format(dev, "", "")
build_date = get_newest_folder(listFD(url))
url = url_template.format(dev, build_date, "")
# get version
ver = get_firmware_version(listFD(url))
url = url_template.format(dev, build_date, ver)
dest = "outs"
if not os.path.isdir(dest):
os.mkdir(dest)
filename = os.path.join(dest, ver)
self.download(url, filename)

def _get_file(
self,
Expand Down Expand Up @@ -707,7 +728,7 @@ def _get_files(
or "m2k" in details["carrier"].lower()
or "adalm-2000" in details["carrier"].lower()
), "Firmware downloads only available for pluto and m2k"
self._download_firmware(details["carrier"], branch)
self._download_firmware(details["carrier"], source, branch)
else:

if source == "local_fs": # to fix
Expand Down
11 changes: 8 additions & 3 deletions nebula/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,17 @@ def board_reboot_auto_folder(
log.info("Firmware based device selected")
if jtag_mode:
raise Exception("jtag_mode not supported for firmware device")
files = glob.glob(os.path.join(folder, "*.zip"))
try:
files = glob.glob(os.path.join(folder, "*.zip"))
print(files[0])
except IndexError:
files = glob.glob(os.path.join(folder, "*.frm"))
if not files:
raise Exception("No zip files found in folder: " + folder)
raise Exception("No files found in folder: " + folder)
if len(files) > 1:
raise Exception("Too many zip files found in folder: " + folder)
raise Exception("Too manyfiles found in folder: " + folder)

log.info(files[0])
self.usbdev.update_firmware(files[0], device=design_name)
time.sleep(3)
if not self.usbdev.wait_for_usb_mount(device=design_name):
Expand Down
2 changes: 1 addition & 1 deletion nebula/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def check_dmesg(self, error_on_warnings=False):
tmp_filename_err = "/tmp/" + tmp_filename_root + "_err"
tmp_filename_war = "/tmp/" + tmp_filename_root + "_warn"

if self.board_name == "pluto":
if self.board_name == "pluto" or self.board_name == "m2k":
with open(tmp_filename_root, "w") as outfile:
outfile.write(self.run_ssh_command("dmesg").stdout)
with open(tmp_filename_root + "_warn", "w") as outfile:
Expand Down
12 changes: 7 additions & 5 deletions tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Must be connected to analog VPN


def downloader_test(board_name, branch, filetype):
def downloader_test(board_name, branch, filetype, source="artifactory"):
file = {
"firmware": None,
"boot_partition": None,
Expand All @@ -24,7 +24,7 @@ def downloader_test(board_name, branch, filetype):
d = downloader(yamlfilename=yamlfilename, board_name=board_name)
d.download_boot_files(
board_name,
source="artifactory",
source=source,
source_root="artifactory.analog.com",
branch=branch,
firmware=file["firmware"],
Expand Down Expand Up @@ -110,10 +110,12 @@ def test_rpi_downloader(test_downloader, board_name, branch, filetype):


@pytest.mark.parametrize("board_name", ["pluto"])
@pytest.mark.parametrize("branch", ["master", "v0.33"])
@pytest.mark.parametrize(
"source, branch", [("github", "v0.33"), ("artifactory", "master")]
)
@pytest.mark.parametrize("filetype", ["firmware"])
def test_firmware_downloader(test_downloader, board_name, branch, filetype):
test_downloader(board_name, branch, filetype)
def test_firmware_downloader(test_downloader, board_name, branch, filetype, source):
test_downloader(board_name, branch, filetype, source=source)
if branch == "v0.33":
assert os.path.isfile("outs/plutosdr-fw-v0.33.zip")
else:
Expand Down

0 comments on commit c5fa175

Please sign in to comment.