4

We are going to adopt Raspberry Pi in our products, this means the RP must associate with unique product. Given that RP does not have any printed serial number on its board, How one can get any unique string from the RP, this string must be readable from both hardware and software?

7
  • 1
    insert SD card with operating system on it. Use operating system to find serial number. Print a label. Stick it on the pi Commented Apr 17, 2019 at 10:48
  • this is not practical at high scale level, I want to eliminate the mechanical side Commented Apr 17, 2019 at 10:54
  • you're out of luck then, as you said, there's no external (unique) markings/numbers on a raspbetry pi Commented Apr 17, 2019 at 11:17
  • If you're ordering a significant quantity of units (minimum 5000), it might be worthwhile going for the Element 14 Raspberry Pi customisation service, and getting them to number them for you! element14.com/community/docs/DOC-76955/l/… Commented Apr 17, 2019 at 13:08
  • This is useful, I will take it into consideration Commented Apr 17, 2019 at 14:14

1 Answer 1

8

Every RPi has a serial number. Here's how to learn what it is:

cat /proc/cpuinfo | grep --ignore-case serial

Note that this result is read from a file written by the kernel; i.e. there is a layer of software and the filesystem "between" this value and the value that was "burned into" the OTP memory during hardware fabrication.

This value (serial number) is also available directly from the hardware. The available OTP documentation states that the serial number is in OTP register #28. Therefore, we can read it "directly" as follows:

vcgencmd otp_dump | grep '28:' 

Of course the verity of this result also depends on a layer of software. But it may not be the same software used by the kernel to generate /proc/cpuinfo, and so perhaps you get a second opinion here. If neither of these approaches meets your needs, you could always study the source code, and develop your own approach to reading the OTP memory.

You may compare the values generated by these two methods of reading the Raspberry Pi's serial number. They should, of course, be the same.

Alternatively (or Additionally):

You can use the Ethernet MAC address for those devices that have built-in Ethernet. All Ethernet-equipped Raspberry Pis through ver 3B+ have a MAC address that begins with b8:27:eb (i.e. the OUI); since ver 4B the OUI has changed to dc:a6:32. When combined with the last 3 octets, this MAC address should be globally unique according to IEEE Guidelines. You should peruse these guidelines as there are important caveats, and other potentially useful information.

The Ethernet MAC address is also written to a file, but of course subject to the caveats discussed above for the serial number. To get the MAC address from the hardware:

ethtool --show-permaddr eth0    # for the Ethernet adapter
ethtool --show-permaddr wlan0   # for the WiFi adapter

Note that there is also a MAC address for the Bluetooth transceiver - again, for those boards that are equipped with Bluetooth. The governing specification for Bluetooth v5 states:

Each Bluetooth device shall be allocated a unique 48-bit Bluetooth device address (BD_ADDR). The address shall be a 48-bit extended unique identifier (EUI-48) created in accordance with section 8.2 ("Universal addresses") of the IEEE 802-2014 standard.

The Bluetooth MAC must be different from the Ethernet MAC, and again, this is covered by the IEEE guidelines. I think this will get the Bluetooth MAC address from the firmware:

hciconfig -a | grep BD

Know that while MAC addresses can (and often are) "spoofed", this "spoofing" does not change the MAC address that was built/programmed into the product when it was manufactured. It would be foolish to claim that any address or serial number is "unalterable" or "perfectly secure", but reading the values directly from the ROM/OTP would seem to offer some greater assurance that the value is "authentic" than reading these values from the filesystem.

13
  • How to physically read serial number or MAC address? Commented Apr 17, 2019 at 14:15
  • @JawadSabir: Re-read my answer please, and let me know if you still have a question.
    – Seamus
    Commented Apr 17, 2019 at 14:33
  • When you say the serial number is stored in a file and hence can be changed, do you mean someone could edit /proc/cpuinfo, or something else?
    – Mark Smith
    Commented Apr 17, 2019 at 15:15
  • @MarkSmith: Yes, someone could edit it. Here's one way it could be done
    – Seamus
    Commented Apr 17, 2019 at 17:51
  • That's not editing the file, it's making changes to the kernel. If you distrust the kernel, you probably can't trust the vcgencmd command either, in my opinion :-)
    – Mark Smith
    Commented Apr 17, 2019 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.