From 4a2adabe9505085602170fb475c2f78c93d9b634 Mon Sep 17 00:00:00 2001 From: 1e9abhi1e10 <2311abhiptdr@gmail.com> Date: Fri, 7 Jun 2024 02:04:16 +0530 Subject: [PATCH] feat: Add update firmware for Auradine and ePIC miners --- pyasic/miners/backends/auradine.py | 52 +++++++++++++++++++++++++++++ pyasic/miners/backends/bfgminer.py | 2 ++ pyasic/miners/backends/epic.py | 53 ++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) diff --git a/pyasic/miners/backends/auradine.py b/pyasic/miners/backends/auradine.py index 37290048..d29cb2f6 100644 --- a/pyasic/miners/backends/auradine.py +++ b/pyasic/miners/backends/auradine.py @@ -16,6 +16,9 @@ import logging from enum import Enum from typing import List, Optional +import aiofiles +import base64 +from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -386,3 +389,52 @@ class Auradine(StockFirmware): return rpc_summary["SUMMARY"][0]["Elapsed"] except LookupError: pass + + async def upgrade_firmware(self, file: Path): + """ + Upgrade the firmware of the Auradine miner device. + + Args: + file (Path): The local file path of the firmware to be uploaded. + + Returns: + str: Confirmation message after upgrading the firmware. + """ + try: + logging.info("Starting firmware upgrade process for Auradine miner.") + + if not file: + raise ValueError("File location must be provided for firmware upgrade.") + + # Read the firmware file contents + async with aiofiles.open(file, "rb") as f: + upgrade_contents = await f.read() + + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") + + # Upload the firmware file to the Auradine miner device + logging.info(f"Uploading firmware file from {file} to the device.") + await self.ssh.send_command( + f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" + ) + + logging.info("Firmware upgrade process completed successfully for Auradine miner.") + return "Firmware upgrade completed successfully." + except FileNotFoundError as e: + logging.error(f"File not found during the firmware upgrade process: {e}") + raise + except ValueError as e: + logging.error( + f"Validation error occurred during the firmware upgrade process: {e}" + ) + raise + except OSError as e: + logging.error(f"OS error occurred during the firmware upgrade process: {e}") + raise + except Exception as e: + logging.error( + f"An unexpected error occurred during the firmware upgrade process: {e}", + exc_info=True, + ) + raise diff --git a/pyasic/miners/backends/bfgminer.py b/pyasic/miners/backends/bfgminer.py index e2b3cdea..c45231f1 100644 --- a/pyasic/miners/backends/bfgminer.py +++ b/pyasic/miners/backends/bfgminer.py @@ -227,3 +227,5 @@ class BFGMiner(StockFirmware): ).into(self.algo.unit.default) except LookupError: pass + + diff --git a/pyasic/miners/backends/epic.py b/pyasic/miners/backends/epic.py index e3134dfc..49b45909 100644 --- a/pyasic/miners/backends/epic.py +++ b/pyasic/miners/backends/epic.py @@ -15,6 +15,10 @@ # ------------------------------------------------------------------------------ from typing import List, Optional +import logging +import aiofiles +import base64 +from pathlib import Path from pyasic.config import MinerConfig from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit @@ -411,3 +415,52 @@ class ePIC(ePICFirmware): except KeyError: pass return errors + + async def upgrade_firmware(self, file: Path): + """ + Upgrade the firmware of the ePIC miner device. + + Args: + file (Path): The local file path of the firmware to be uploaded. + + Returns: + str: Confirmation message after upgrading the firmware. + """ + try: + logging.info("Starting firmware upgrade process for ePIC miner.") + + if not file: + raise ValueError("File location must be provided for firmware upgrade.") + + # Read the firmware file contents + async with aiofiles.open(file, "rb") as f: + upgrade_contents = await f.read() + + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8") + + # Upload the firmware file to the ePIC miner device + logging.info(f"Uploading firmware file from {file} to the device.") + await self.ssh.send_command( + f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar" + ) + + logging.info("Firmware upgrade process completed successfully for ePIC miner.") + return "Firmware upgrade completed successfully." + except FileNotFoundError as e: + logging.error(f"File not found during the firmware upgrade process: {e}") + raise + except ValueError as e: + logging.error( + f"Validation error occurred during the firmware upgrade process: {e}" + ) + raise + except OSError as e: + logging.error(f"OS error occurred during the firmware upgrade process: {e}") + raise + except Exception as e: + logging.error( + f"An unexpected error occurred during the firmware upgrade process: {e}", + exc_info=True, + ) + raise \ No newline at end of file