From 511409c8f98efbb9fd87b11d057a0d05d6383b23 Mon Sep 17 00:00:00 2001 From: Martin Fuzzey Date: Thu, 1 Oct 2026 17:36:15 +0200 Subject: [PATCH] snagflash: dfu: support partition names Currently the partitions used by snagflash DFU have to be the numeric altsettings, let's allow the names defined in u-boot to be used too. Eg if u-boot is configured with dfu_alt_info "mmc 0=fsbl raw 0 1000 mmcpart 1;ssbl part 0 1" writing to the ssbl currently requires the snagflash option -D 1:binaries/u-boot.img with this patch the following is also accepted -D ssbl:u-boot.img --- docs/snagflash.md | 9 ++++++--- src/snagflash/dfu.py | 9 +++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/snagflash.md b/docs/snagflash.md index c306fcb..9e655de 100644 --- a/docs/snagflash.md +++ b/docs/snagflash.md @@ -166,7 +166,7 @@ snagflash -P ums -s binaries/u-boot.stm32 -d /mnt/u-boot.stm32 ``` **Note:** If you want a static block device path, you can use the following udev -rules to create symlinks when a certain VID:PID pair is detected: +rules to create symlinks when a certain VID:PID pair is detected: - For a parent block device: `SUBSYSTEM=="block", KERNEL!="*[0-9]", SUBSYSTEMS=="usb", ATTRS{idVendor}=="...", ATTRS{idProduct}=="...", MODE="0660", TAG+="uaccess", SYMLINK+="myblockdev"` @@ -182,8 +182,9 @@ In DFU mode, snagflash takes additional arguments : The USB address of the DFU device exposed by U-Boot * `-D --dfu-config altsetting:path` The altsetting and path of a file to download to the board. This should match - the value specified in dfu\_alt\_info in U-Boot. This flag can be passed - multiple times, to specify multiple files to download. + the value specified in dfu\_alt\_info in U-Boot. + It may match either the numerical altsetting or the name of the altsetting. + This flag can be passed multiple times, to specify multiple files to download. * `--dfu-keep` An optional argument to avoid detaching DFU mode after download and keep the mode active * `--dfu-detach` @@ -196,6 +197,8 @@ Example: # in U-Boot: setenv dfu_alt_info "mmc=uboot part 0 1" # in U-Boot: dfu 0 mmc 0 snagflash -P dfu -p 0483:df11 -D 0:binaries/u-boot.stm32 +or +snagflash -P dfu -p 0483:df11 -D uboot:binaries/u-boot.stm32 ``` For instructions on how to setup DFU in U-Boot, please refer to the [U-Boot diff --git a/src/snagflash/dfu.py b/src/snagflash/dfu.py index 7e76997..5892196 100644 --- a/src/snagflash/dfu.py +++ b/src/snagflash/dfu.py @@ -83,8 +83,13 @@ def dfu_cli(args): altsetting = 0 if args.dfu_config: for dfu_config in args.dfu_config: - (altsetting, sep, path) = dfu_config.partition(":") - altsetting = int(altsetting) + (partname, sep, path) = dfu_config.partition(":") + try: + altsetting = int(partname) + except ValueError: + altsetting = dfu.search_partid(dev, partname) + if altsetting is None: + cli_error(f"u-boot does not support partition '{partname}") dfu_download(dev, altsetting, path) if not args.dfu_keep or args.dfu_detach or args.dfu_reset: dfu_detach(dev, altsetting)