mirror of https://github.com/Desuuuu/klipper.git
flash_usb: use sudo for rp2040 flashing
The rp2040 can be flashed without sudo when using udev rules to give the user permission, but in a standard configuration sudo is required. Here we make it possible for flash_usb to use sudo for the rp2040 target, and make it the default when using `make flash` for the rp2040. As for other targets, one can set `NOSUDO=1` to not call through sudo. Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
This commit is contained in:
parent
15ffa85954
commit
a7b01857f5
|
@ -163,7 +163,7 @@ def flash_atsamd(options, binfile):
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Look for an rp2040 and flash it with rp2040_flash.
|
# Look for an rp2040 and flash it with rp2040_flash.
|
||||||
def rp2040_flash(devpath, binfile):
|
def rp2040_flash(devpath, binfile, sudo):
|
||||||
args = ["lib/rp2040_flash/rp2040_flash", binfile]
|
args = ["lib/rp2040_flash/rp2040_flash", binfile]
|
||||||
if len(devpath) > 0:
|
if len(devpath) > 0:
|
||||||
with open(devpath + "/busnum") as f:
|
with open(devpath + "/busnum") as f:
|
||||||
|
@ -172,6 +172,8 @@ def rp2040_flash(devpath, binfile):
|
||||||
addr = f.read().strip()
|
addr = f.read().strip()
|
||||||
args += [bus, addr]
|
args += [bus, addr]
|
||||||
sys.stderr.write(" ".join(args) + '\n\n')
|
sys.stderr.write(" ".join(args) + '\n\n')
|
||||||
|
if sudo:
|
||||||
|
args.insert(0, "sudo")
|
||||||
res = subprocess.call(args)
|
res = subprocess.call(args)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
raise error("Error running rp2040_flash")
|
raise error("Error running rp2040_flash")
|
||||||
|
@ -268,7 +270,7 @@ device as a usb drive, and copy klipper.uf2 to the device.
|
||||||
def flash_rp2040(options, binfile):
|
def flash_rp2040(options, binfile):
|
||||||
try:
|
try:
|
||||||
if options.device.lower() == "first":
|
if options.device.lower() == "first":
|
||||||
rp2040_flash("", binfile)
|
rp2040_flash("", binfile, options.sudo)
|
||||||
return
|
return
|
||||||
|
|
||||||
buspath, devpath = translate_serial_to_usb_path(options.device)
|
buspath, devpath = translate_serial_to_usb_path(options.device)
|
||||||
|
@ -276,7 +278,7 @@ def flash_rp2040(options, binfile):
|
||||||
devpath = os.path.dirname(devpath)
|
devpath = os.path.dirname(devpath)
|
||||||
enter_bootloader(options.device)
|
enter_bootloader(options.device)
|
||||||
wait_path(devpath)
|
wait_path(devpath)
|
||||||
rp2040_flash(devpath, binfile)
|
rp2040_flash(devpath, binfile, options.sudo)
|
||||||
|
|
||||||
except error as e:
|
except error as e:
|
||||||
sys.stderr.write(RP2040_HELP % (options.device, str(e)))
|
sys.stderr.write(RP2040_HELP % (options.device, str(e)))
|
||||||
|
|
|
@ -51,4 +51,4 @@ lib/rp2040_flash/rp2040_flash:
|
||||||
# Flash rules
|
# Flash rules
|
||||||
flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash
|
flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash
|
||||||
@echo " Flashing $< to $(FLASH_DEVICE)"
|
@echo " Flashing $< to $(FLASH_DEVICE)"
|
||||||
$(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(OUT)klipper.uf2
|
$(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.uf2
|
||||||
|
|
Loading…
Reference in New Issue