← index #12216PR #12908
Off-topic · high · value 0.467
QUERY · ISSUE

ports/unix: please implement machine.unique_id()

openby paravoidopened 2023-08-11updated 2024-10-18
enhancement

What triggered this was my attempt to use micropython-mqtt from the Unix port, in order to run some tests with my code before moving this to an actual board.

The module uses a few things that are not implemented in the Unix port, and probably needs to be ported itself.

One of the issues, however, is machine.unique_id(), which seems... basic enough for the Unix port to have it.

One strategy could be to use gethostid(), which is deprecated in most Unix systems, as it's a 32-bit integer (not very unique). Another one could be to use /etc/machine-id, a UUID, which exists in -at least- modern Linux systems.

A search for /etc/machine-id yields:
https://codesearch.debian.net/search?q=%2Fetc%2Fmachine-id&literal=1
Most seem to be falling back to /var/lib/dbus/machine-id.

CANDIDATE · PULL REQUEST

samd: Refactor to use shared tinyusb, implement unique id (with cross-port refactor)

mergedby projectgusopened 2023-11-07updated 2024-11-01
port-samdport-rp2port-renesas-ra

Three related changes for tinyusb on samd port (including a refactor that also covers rp2 and renesas-ra):

  • Switch to use the shared tinyusb implementation (same functionality, shared source code). This is a precursor to supporting Python-implemented USB devices on this platform.
  • Add a helper for "bytes to hex" conversion that is implemented in multiple ports for serial numbers. Refactor the rp2 and renesas-ra ports to use the helper instead of the same piece of code.
  • Implement a unique USB device serial number for samd based on the existing machine.unique_id() implementation. Previously this was all-zeroes // TODO.

Can split into two PRs if that is easier to review.

Tested on a Seeed WIO Terminal and a Seeed XIAO.

Code size impacts:

Stage Flash Size - WIO Terminal (SAMD51) Seeed XIAO (SAMD21)
master 261180 184144
Refactor to shared tinyusb 261208 184180
Implement serial number 261284 184244

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied