Commit ab4a9f21 authored by Guido Gunther's avatar Guido Gunther
Browse files

librem5-flash-image: Add option to set udev rules

This avoids downloading / flashing with root permissions and
extending the docs even further.

We can switch to `uuu -udev > ...` once the new uuu is more
widespread.

Closes: #35
parent 07791b0c
Pipeline #64973 passed with stages
in 2 minutes and 56 seconds
...@@ -67,6 +67,16 @@ FB: Done ...@@ -67,6 +67,16 @@ FB: Done
BLOCK_SIZE = 8192 BLOCK_SIZE = 8192
RETRIES = 10 RETRIES = 10
UDEV_RULES = '''
SUBSYSTEM!="usb", GOTO="librem5_devkit_rules_end"
# Devkit USB flash
ATTR{idVendor}=="1fc9", ATTR{idProduct}=="012b", GROUP+="plugdev", TAG+="uaccess"
ATTR{idVendor}=="0525", ATTR{idProduct}=="a4a5", GROUP+="plugdev", TAG+="uaccess"
ATTR{idVendor}=="0525", ATTR{idProduct}=="b4a4", GROUP+="plugdev", TAG+="uaccess"
ATTR{idVendor}=="316d", ATTR{idProduct}=="4c05", GROUP+="plugdev", TAG+="uaccess"
LABEL="librem5_devkit_rules_end"
'''
class VerifyImageException(Exception): class VerifyImageException(Exception):
pass pass
...@@ -327,6 +337,24 @@ def get_board(path): ...@@ -327,6 +337,24 @@ def get_board(path):
return BOARD_TYPE return BOARD_TYPE
def setup_udev():
rules = "/etc/udev/rules.d/70-librem5-flash-image.rules"
if os.path.exists(rules):
logging.info(f"Udev rules '{rules}' already present")
return 0
try:
with open(rules, 'w+') as f:
f.write(UDEV_RULES)
except PermissionError as e:
logging.error(f"{e} - are you root?")
return 1
subprocess.check_call(['udevadm', 'control', '--reload'])
logging.info(f"Udev rules '{rules}' updated. You can now flash without root permissions.")
return 0
def main(): def main():
uuu_mods = '' uuu_mods = ''
parser = argparse.ArgumentParser(description='Flash a Librem 5 or Librem 5 Devkit.') parser = argparse.ArgumentParser(description='Flash a Librem 5 or Librem 5 Devkit.')
...@@ -355,6 +383,10 @@ def main(): ...@@ -355,6 +383,10 @@ def main():
help='Jenkins job to download the image from') help='Jenkins job to download the image from')
group.add_argument('--uboot-job', type=str, group.add_argument('--uboot-job', type=str,
help='Jenkins job to download the uboot from') help='Jenkins job to download the uboot from')
group = parser.add_argument_group(title='Initial setup options')
group.add_argument('--udev', action="store_true", default=False,
help='Setup udev rules to flash without root permissions')
args = parser.parse_args() args = parser.parse_args()
level = logging.DEBUG if args.debug else logging.INFO level = logging.DEBUG if args.debug else logging.INFO
...@@ -363,6 +395,9 @@ def main(): ...@@ -363,6 +395,9 @@ def main():
else: else:
logging.basicConfig(level=level, format='%(asctime)s %(levelname)s %(message)s') logging.basicConfig(level=level, format='%(asctime)s %(levelname)s %(message)s')
if args.udev:
return setup_udev()
board = args.board if args.board else get_board(sys.argv[0]) board = args.board if args.board else get_board(sys.argv[0])
# Check available downloads upfront so it's less likely we fail # Check available downloads upfront so it's less likely we fail
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment