feat: Add update firmware for Auradine and ePIC miners

This commit is contained in:
1e9abhi1e10
2024-06-07 02:04:16 +05:30
parent aec53aa5f0
commit 4a2adabe95
3 changed files with 107 additions and 0 deletions

View File

@@ -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

View File

@@ -227,3 +227,5 @@ class BFGMiner(StockFirmware):
).into(self.algo.unit.default)
except LookupError:
pass

View File

@@ -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