aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/flash_usb.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-11 22:13:20 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-03-11 22:33:24 -0400
commit4718f39b2f8ef326dc671aa936c509e98fd6cf9f (patch)
tree29c2955cd254535738e5e14bcdd3e0665dff3233 /scripts/flash_usb.py
parent12f6513ba2ad8d0411ae30f001bb7a8f9d553495 (diff)
downloadkutter-4718f39b2f8ef326dc671aa936c509e98fd6cf9f.tar.gz
kutter-4718f39b2f8ef326dc671aa936c509e98fd6cf9f.tar.xz
kutter-4718f39b2f8ef326dc671aa936c509e98fd6cf9f.zip
flash_usb: Run dfu-util via sudo
Default to running dfu-util via sudo as most machines will not have the user setup with permissions to access the raw usb device. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'scripts/flash_usb.py')
-rwxr-xr-xscripts/flash_usb.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py
index a27f905d..f1106474 100755
--- a/scripts/flash_usb.py
+++ b/scripts/flash_usb.py
@@ -70,22 +70,24 @@ def flash_bossac(device, binfile, extra_flags=[]):
pass
# Invoke the dfu-util program
-def call_dfuutil(flags, binfile):
+def call_dfuutil(flags, binfile, sudo):
args = ["dfu-util"] + flags + ["-D", binfile]
+ if sudo:
+ args.insert(0, "sudo")
sys.stderr.write(" ".join(args) + '\n\n')
res = subprocess.call(args)
if res != 0:
raise error("Error running dfu-util")
# Flash via a call to dfu-util
-def flash_dfuutil(device, binfile, extra_flags=[]):
+def flash_dfuutil(device, binfile, extra_flags=[], sudo=True):
hexfmt_r = re.compile(r"^[a-fA-F0-9]{4}:[a-fA-F0-9]{4}$")
if hexfmt_r.match(device.strip()):
- call_dfuutil(["-d", ","+device.strip()] + extra_flags, binfile)
+ call_dfuutil(["-d", ","+device.strip()] + extra_flags, binfile, sudo)
return
buspath = translate_serial_to_usb_path(device)
enter_bootloader(device)
- call_dfuutil(["-p", buspath] + extra_flags, binfile)
+ call_dfuutil(["-p", buspath] + extra_flags, binfile, sudo)
######################################################################
@@ -137,7 +139,7 @@ and then restart the Smoothieboard with that SD card.
def flash_lpc176x(options, binfile):
try:
- flash_dfuutil(options.device, binfile)
+ flash_dfuutil(options.device, binfile, [], options.sudo)
except error as e:
sys.stderr.write(SMOOTHIE_HELP % (options.device, str(e)))
sys.exit(-1)
@@ -156,7 +158,7 @@ If attempting to flash via 3.3V serial, then use:
def flash_stm32f1(options, binfile):
try:
- flash_dfuutil(options.device, binfile, ["-R", "-a", "2"])
+ flash_dfuutil(options.device, binfile, ["-R", "-a", "2"], options.sudo)
except error as e:
sys.stderr.write(STM32F1_HELP % (
options.device, str(e), options.device))
@@ -181,6 +183,8 @@ def main():
help="serial port device")
opts.add_option("-o", "--offset", type="string", dest="offset",
help="flash offset")
+ opts.add_option("--no-sudo", action="store_false", dest="sudo",
+ default=True, help="do not run sudo")
options, args = opts.parse_args()
if len(args) != 1:
opts.error("Incorrect number of arguments")