aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mule-attiny/i2c-flash/README.md3
-rwxr-xr-xmule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py31
2 files changed, 20 insertions, 14 deletions
diff --git a/mule-attiny/i2c-flash/README.md b/mule-attiny/i2c-flash/README.md
index 140c5e8..7a0fe7c 100644
--- a/mule-attiny/i2c-flash/README.md
+++ b/mule-attiny/i2c-flash/README.md
@@ -23,7 +23,7 @@ directories listed in `PATH` environment variable.
# Running instructions
```
-usage: i2c_flash.py [-h] -f FIRMWARE -c BOOT_REQ_GPIOCHIP -g BOOT_REQ_GPIO -b
+usage: i2c_flash.py [-h] [-f FIRMWARE] -c BOOT_REQ_GPIOCHIP -g BOOT_REQ_GPIO -b
I2C_BUS -rc UPDI_RESET_GPIOCHIP -rg UPDI_RESET_GPIO
Script to flash mule-ATtiny firmware through I2C-Flashloader
@@ -32,6 +32,7 @@ options:
-h, --help show this help message and exit
-f FIRMWARE, --firmware FIRMWARE
Path to the firmware binary file
+ If not specified, this script will only print out the bootloader info and exit.
-c BOOT_REQ_GPIOCHIP, --boot_req_gpiochip BOOT_REQ_GPIOCHIP
Boot request gpiochip index number (e.g. 0 if
/dev/gpiochip0)/
diff --git a/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py b/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py
index 7beea78..c362384 100755
--- a/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py
+++ b/mule-attiny/i2c-flash/src/mule-attiny_i2c_flash/i2c_flash.py
@@ -95,7 +95,7 @@ def get_blhdr(blhdr):
if id == BLHdrID.VERSION:
return BLVersionHdr(blhdr)
# Add other bootloader header IDs here
- raise Exception(f"Unknown {id} ID for payload header")
+ raise Exception(f"Unknown ID ({id}) for payload header")
class BLHdr():
@@ -148,16 +148,14 @@ class BLParser():
@classmethod
def parse(cls, payload):
if not payload:
- logging.error("No bootloader data is available!")
- return
+ raise Exception("No bootloader data is available!")
cursor = 0
while cursor < len(payload):
blhdr = get_blhdr(payload[cursor])
clss = blhdr.payload_class()
cursor += 1
if len(payload) < cursor + blhdr.len():
- logging.error(f"Invalid data header of type {type(blhdr).__name__}")
- return
+ raise Exception(f"Invalid data header of type {type(blhdr).__name__}")
yield clss(blhdr, payload[cursor:cursor + blhdr.len()])
cursor += blhdr.len()
@@ -242,8 +240,10 @@ def main():
prog='i2c_flash.py',
description='Script to flash mule-ATtiny firmware through I2C-Flashloader',
epilog='')
-
- parser.add_argument('-f', '--firmware', required=True, help="Path to the firmware binary file")
+ parser.add_argument('-f', '--firmware', required=False, # User can just retrieve bl_data without flashing
+ help="Path to the firmware binary file. "
+ "If not specified, this script will only print out the bootloader info and exit."
+ )
parser.add_argument('-c', '--boot_req_gpiochip', type=int, required=True, help="Boot request gpiochip index number (e.g. 0 if /dev/gpiochip0)/") # noqa: E501
parser.add_argument('-g', '--boot_req_gpio', type=int, required=True, help="Boot request GPIO index in the gpiochip (e.g. if GPIO3_A5, boot_req_gpiochip is 3 and boot_req_gpio is 5") # noqa: E501
parser.add_argument('-b', '--i2c_bus', type=int, required=True, help="I2C bus index (e.g. 2 if /dev/i2c-2) connected to ATtiny") # noqa: E501
@@ -253,11 +253,12 @@ def main():
# Get binarry path from cli
args = parser.parse_args()
- # Open binary file and copy data to "_bin" bytearray
- _bin = load_bin(args.firmware)
+ if args.firmware:
+ # Open binary file and copy data to "_bin" bytearray
+ _bin = load_bin(args.firmware)
- if not is_valid_bin(_bin):
- sys.exit(INVALID_BIN)
+ if not is_valid_bin(_bin):
+ sys.exit(INVALID_BIN)
# Make sure kernel doesn't access the isl1208 address while flashing
if pathlib.Path(f"/sys/bus/i2c/drivers/rtc-isl1208/{args.i2c_bus}-{BL_I2C_DEV:04x}").exists():
@@ -286,8 +287,12 @@ def main():
for d in bl_data:
logging.info(d)
- bootCtrl.exitRoMode()
- ret = fw_flash(_bin, args.i2c_bus)
+ if args.firmware:
+ bootCtrl.exitRoMode()
+ ret = fw_flash(_bin, args.i2c_bus)
+ else:
+ logging.info("Nothing to do. Please provide a firmware using '-f'")
+ ret = FLASH_OK
except Exception as err:
raise err