diff options
| author | Joel Challis <git@zvecr.com> | 2025-11-17 02:24:23 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-17 02:24:23 +0000 |
| commit | 8eebc613cf1ba9ae8213a20b3a500eefcd08ffd3 (patch) | |
| tree | 8b39d1b0f002add9f268500c1d226ad50dab5976 /util/uf2conv.py | |
| parent | a2adc920665ba9e4ad9100b5601464ce80a76134 (diff) | |
Merge upstream uf2conv changes (#25786)
Diffstat (limited to 'util/uf2conv.py')
| -rwxr-xr-x | util/uf2conv.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/util/uf2conv.py b/util/uf2conv.py index 67cf92f169..a0507b00b9 100755 --- a/util/uf2conv.py +++ b/util/uf2conv.py | |||
| @@ -142,9 +142,9 @@ def convert_to_uf2(file_content): | |||
| 142 | return b"".join(outp) | 142 | return b"".join(outp) |
| 143 | 143 | ||
| 144 | class Block: | 144 | class Block: |
| 145 | def __init__(self, addr): | 145 | def __init__(self, addr, default_data=0xFF): |
| 146 | self.addr = addr | 146 | self.addr = addr |
| 147 | self.bytes = bytearray(256) | 147 | self.bytes = bytearray([default_data] * 256) |
| 148 | 148 | ||
| 149 | def encode(self, blockno, numblocks): | 149 | def encode(self, blockno, numblocks): |
| 150 | global familyid | 150 | global familyid |
| @@ -210,24 +210,26 @@ def to_str(b): | |||
| 210 | def get_drives(): | 210 | def get_drives(): |
| 211 | drives = [] | 211 | drives = [] |
| 212 | if sys.platform == "win32": | 212 | if sys.platform == "win32": |
| 213 | r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk", | 213 | r = subprocess.check_output([ |
| 214 | "get", "DeviceID,", "VolumeName,", | 214 | "powershell", |
| 215 | "FileSystem,", "DriveType"]) | 215 | "-Command", |
| 216 | for line in to_str(r).split('\n'): | 216 | '(Get-WmiObject Win32_LogicalDisk -Filter "FileSystem=\'FAT\'").DeviceID' |
| 217 | words = re.split(r'\s+', line) | 217 | ]) |
| 218 | if len(words) >= 3 and words[1] == "2" and words[2] == "FAT": | 218 | drives = [drive.strip() for drive in to_str(r).splitlines()] |
| 219 | drives.append(words[0]) | ||
| 220 | else: | 219 | else: |
| 221 | searchpaths = ["/media"] | 220 | searchpaths = ["/mnt", "/media"] |
| 222 | if sys.platform == "darwin": | 221 | if sys.platform == "darwin": |
| 223 | searchpaths = ["/Volumes"] | 222 | searchpaths = ["/Volumes"] |
| 224 | elif sys.platform == "linux": | 223 | elif sys.platform == "linux": |
| 225 | searchpaths += ["/media/" + os.environ["USER"], '/run/media/' + os.environ["USER"]] | 224 | searchpaths += ["/media/" + os.environ["USER"], "/run/media/" + os.environ["USER"]] |
| 225 | if "SUDO_USER" in os.environ.keys(): | ||
| 226 | searchpaths += ["/media/" + os.environ["SUDO_USER"]] | ||
| 227 | searchpaths += ["/run/media/" + os.environ["SUDO_USER"]] | ||
| 226 | 228 | ||
| 227 | for rootpath in searchpaths: | 229 | for rootpath in searchpaths: |
| 228 | if os.path.isdir(rootpath): | 230 | if os.path.isdir(rootpath): |
| 229 | for d in os.listdir(rootpath): | 231 | for d in os.listdir(rootpath): |
| 230 | if os.path.isdir(rootpath): | 232 | if os.path.isdir(os.path.join(rootpath, d)): |
| 231 | drives.append(os.path.join(rootpath, d)) | 233 | drives.append(os.path.join(rootpath, d)) |
| 232 | 234 | ||
| 233 | 235 | ||
