Skip to content

S03usbdev: derive USB serial number from SoC hardware UID#746

Open
JakeHillion wants to merge 1 commit intosipeed:mainfrom
JakeHillion:jj/wlpzynswntvx
Open

S03usbdev: derive USB serial number from SoC hardware UID#746
JakeHillion wants to merge 1 commit intosipeed:mainfrom
JakeHillion:jj/wlpzynswntvx

Conversation

@JakeHillion
Copy link
Copy Markdown

The USB gadget serial number was hardcoded to '0123456789ABCDEF', meaning every NanoKVM device presented the same serial to the host.

Read the SoC unique identifier from /sys/class/cvi-base/base_uid on each boot and concatenate its two halves into a single hex string for use as the USB serial number. Falls back to the old hardcoded value if the UID file is not present.

This gives each device a stable, hardware-derived serial number without requiring any persistent state, and satisfies the USB Mass Storage requirement of at least 12 characters. This means you can query the USB interface on the machine the KVM is plugged into to find out which NanoKVM is plugged in, instead of that there is a NanoKVM plugged in.

Test plan:

Installed script on two NanoKVMs with:
scp kvmapp/system/init.d/S03usbdev root@kvm04:/etc/init.d/S03usbdev

Plugged into a Linux machine, before I got:

[jake@li-bl-eq14-1:~]$ nix shell nixpkgs#usbutils --command lsusb -v | grep NanoKVM -A 50
Bus 003 Device 006: ID 3346:1009 sipeed NanoKVM
Negotiated speed: High Speed (480Mbps)
Device Descriptor:
...
  idVendor           0x3346 sipeed
  idProduct          0x1009 NanoKVM
  bcdDevice            5.10
  iManufacturer           1 sipeed
  iProduct                2 NanoKVM
  iSerial                 3 0123456789ABCDEF

After the update, I get the same, but the serial number is now unique per device. I unplugged the devices and plugged them back in, this is now a consistent and unique identifier between my NanoKVMs from the host device.

The USB gadget serial number was hardcoded to '0123456789ABCDEF',
meaning every NanoKVM device presented the same serial to the host.

Read the SoC unique identifier from /sys/class/cvi-base/base_uid on
each boot and concatenate its two halves into a single hex string for
use as the USB serial number. Falls back to the old hardcoded value if
the UID file is not present.

This gives each device a stable, hardware-derived serial number
without requiring any persistent state, and satisfies the USB Mass
Storage requirement of at least 12 characters. This means you can query
the USB interface on the machine the KVM is plugged into to find out
_which_ NanoKVM is plugged in, instead of that there is a NanoKVM
plugged in.

Test plan:

Installed script on two NanoKVMs with:
    scp kvmapp/system/init.d/S03usbdev root@kvm04:/etc/init.d/S03usbdev

Plugged into a Linux machine, before I got:

```
[jake@li-bl-eq14-1:~]$ nix shell nixpkgs#usbutils --command lsusb -v | grep NanoKVM -A 50
Bus 003 Device 006: ID 3346:1009 sipeed NanoKVM
Negotiated speed: High Speed (480Mbps)
Device Descriptor:
...
  idVendor           0x3346 sipeed
  idProduct          0x1009 NanoKVM
  bcdDevice            5.10
  iManufacturer           1 sipeed
  iProduct                2 NanoKVM
  iSerial                 3 0123456789ABCDEF
```

After the update, I get the same, but the serial number is now unique
per device. I unplugged the devices and plugged them back in, this is
now a consistent and unique identifier between my NanoKVMs from the host
device.
winstar0070 added a commit to Stella-IT/NanoKVM that referenced this pull request Feb 12, 2026
Use the unique hardware UID from /sys/class/cvi-base/base_uid as the
USB serial number instead of a hardcoded value. Falls back to the
default if the UID file is not available.

Cherry-picked from: sipeed#746
Original author: JakeHillion
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.

1 participant