S03usbdev: derive USB serial number from SoC hardware UID#746
Open
JakeHillion wants to merge 1 commit intosipeed:mainfrom
Open
S03usbdev: derive USB serial number from SoC hardware UID#746JakeHillion wants to merge 1 commit intosipeed:mainfrom
JakeHillion wants to merge 1 commit intosipeed:mainfrom
Conversation
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
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.