Skip to content

uf2conv: add more searchpaths, fix pathcheck#96

Merged
mmoskal merged 1 commit intomicrosoft:masterfrom
crasbe:more_searchpaths
May 6, 2025
Merged

uf2conv: add more searchpaths, fix pathcheck#96
mmoskal merged 1 commit intomicrosoft:masterfrom
crasbe:more_searchpaths

Conversation

@crasbe
Copy link
Copy Markdown
Contributor

@crasbe crasbe commented Apr 29, 2025

Hello everyone,

the RIOT OS uses the uf2conv.py script to program devices with the Adafruit nRF52 Bootloader.
Today we noticed some quirks:

  1. Some distributions that don't necessarily use an automounter by default (like Arch Linux) don't necessarily use /media to mount devices but the more "tradutional" mount point /mnt. The uf2conv.py script currently does not search there.

  2. When running uf2conv.py as root via sudo, it won't find any devices mounted by the user. This is because currently only the paths with /media/${USER} are checked. However ${USER}==root when using sudo. Therefore this PR adds a check if SUDO_USER is defined in the environment and adds /media/${SUDO_USER} to the search path.

chris@W11nMate:~$ sudo python3
[sudo] password for chris:
Python 3.10.12 (main, Feb  4 2025, 14:57:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ
environ({'LANG': 'C.UTF-8', 'LS_COLORS': '...', 'TERM': 'xterm-256color', 'DISPLAY': ':0',
'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'MAIL': '/var/mail/root', '
LOGNAME': 'root', 'USER': 'root', 'HOME': '/root', 'SHELL': '/bin/bash', 'SUDO_COMMAND': '/usr/bin/python3', 
'SUDO_USER': 'chris', 'SUDO_UID': '1000', 'SUDO_GID': '1000'})
>>>
  1. One of our students noticed that the os.path.isdir(rootpath) check is redundant. I guess that that like should've been os.path.isdir(os.path.join(rootpath, d)) to see if the path is valid before adding it to the drives variable.

Best Regards,
Chris

Some distributions like Arch Linux still use '/mnt' as the
primary mounting directory.
If the 'uf2conv.py' script was called via sudo, it did not
find any devices because it searched at '/media/root', which
usually is unused.
Therefore the ${SUDO_USER} env-variable is evaluated as a
searchpath, if it exists.
@crasbe
Copy link
Copy Markdown
Contributor Author

crasbe commented Apr 29, 2025

Some test traces with a Seeedstudio Xiao nRF52840 Sense:

chris@ThinkPias:~/RIOTstuff/uf2-searchpath/uf2/utils$ git checkout master
Zu Zweig »master« gewechselt
Ihr Branch ist auf demselben Stand wie 'origin/master'.

chris@ThinkPias:~/RIOTstuff/uf2-searchpath/uf2/utils$ python3 uf2conv.py --list
/media/chris/XIAO-BOOT nRF52840-SeeedXiao-v1
chris@ThinkPias:~/RIOTstuff/uf2-searchpath/uf2/utils$ sudo python3 uf2conv.py --list
[sudo] Passwort für chris:

chris@ThinkPias:~/RIOTstuff/uf2-searchpath/uf2/utils$ git checkout more_searchpaths 
Branch 'more_searchpaths' folgt nun Remote-Branch 'more_searchpaths' von 'origin'.
Zu neuem Branch 'more_searchpaths' gewechselt

chris@ThinkPias:~/RIOTstuff/uf2-searchpath/uf2/utils$ python3 uf2conv.py --list
/media/chris/XIAO-BOOT nRF52840-SeeedXiao-v1
chris@ThinkPias:~/RIOTstuff/uf2-searchpath/uf2/utils$ sudo python3 uf2conv.py --list
/media/chris/XIAO-BOOT nRF52840-SeeedXiao-v1

Copy link
Copy Markdown
Contributor

@mmoskal mmoskal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@mmoskal mmoskal merged commit b19ac9a into microsoft:master May 6, 2025
1 check passed
@mmoskal
Copy link
Copy Markdown
Contributor

mmoskal commented May 6, 2025

sorry for delay!

@crasbe
Copy link
Copy Markdown
Contributor Author

crasbe commented May 6, 2025

Thank you for merging :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants