aboutsummaryrefslogtreecommitdiffstats
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
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>
-rwxr-xr-xscripts/flash_usb.py16
-rw-r--r--src/lpc176x/Makefile2
-rw-r--r--src/stm32f1/Makefile2
3 files changed, 12 insertions, 8 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")
diff --git a/src/lpc176x/Makefile b/src/lpc176x/Makefile
index 1f0e55e2..2e932b84 100644
--- a/src/lpc176x/Makefile
+++ b/src/lpc176x/Makefile
@@ -46,4 +46,4 @@ $(OUT)klipper.bin: $(OUT)klipper.elf
flash: $(OUT)klipper.bin
@echo " Flashing $< to $(FLASH_DEVICE)"
- $(Q)$(PYTHON) ./scripts/flash_usb.py -t lpc176x -d "$(FLASH_DEVICE)" $(OUT)klipper.bin
+ $(Q)$(PYTHON) ./scripts/flash_usb.py -t lpc176x -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin
diff --git a/src/stm32f1/Makefile b/src/stm32f1/Makefile
index 28662a01..3d92b6df 100644
--- a/src/stm32f1/Makefile
+++ b/src/stm32f1/Makefile
@@ -48,7 +48,7 @@ $(OUT)klipper.bin: $(OUT)klipper.elf
flash: $(OUT)klipper.bin
@echo " Flashing $< to $(FLASH_DEVICE)"
- $(Q)$(PYTHON) ./scripts/flash_usb.py -t stm32f1 -d "$(FLASH_DEVICE)" $(OUT)klipper.bin
+ $(Q)$(PYTHON) ./scripts/flash_usb.py -t stm32f1 -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin
serialflash: $(OUT)klipper.bin
@echo " Flashing $< to $(FLASH_DEVICE) via stm32flash"