# Unique ID

Source: https://docs.bytebolt.at/bytebolt-one/unique-id/

> Read the ATmega32U4 fabrication signature row as a per-chip USB serial on BYTEBOLT One — patch USBCore.cpp to expose a unique 18-character hex ID.

## What is the Unique ID?

Each `ATmega32U4` has an undocumented **10-byte fabrication ID** in its signature row at offsets `0x0E`–`0x17` (lot number, wafer number, X/Y coordinates). This ID is unique enough in practice to tell boards apart, but there is no manufacturer guarantee on global uniqueness or collision-freedom.

## How it works

The stock Arduino AVR core ignores the signature row entirely. [LUFA](https://github.com/abcminiuser/lufa) exposes these bytes as a 20-character hex USB serial via `USE_INTERNAL_SERIAL`, but that doesn't help in the Arduino ecosystem.

[Our script](https://codeberg.org/byteboltsec/BYTEBOLT-One) patches `USBCore.cpp` to read the signature row via `boot_signature_byte_get()` and installs a new board variant **"Arduino Leonardo (FabID)"** in the Arduino IDE. Selecting that variant automatically produces a per-chip USB serial — no sketch-level changes needed.

### Patching

**USBCore.cpp**

```c
[...]
const char* USBCore_GetFabricationId() {
\tstatic bool initialized = false;
\tstatic char id[19];
\tif (!initialized) {
\t\tfor (uint8_t i = 0; i < 9; i++) {
\t\t\tuint8_t b = boot_signature_byte_get(0x0E + i + (i > 5 ? 1 : 0));
\t\t\tid[i * 2]     = "0123456789ABCDEF"[b >> 4];
\t\t\tid[i * 2 + 1] = "0123456789ABCDEF"[b & 0x0F];
\t\t}
\t\tid[18] = '\\0';
\t\tinitialized = true;
\t}
\treturn id;
}
[...]
```

## Usage

Once patched, you can read the ID in two ways:

- **In a sketch** — call `USBCore_GetFabricationId()` (see example below)
- **On the host** — read the USB serial string, e.g. via PowerShell

**print_fabid.ino**

```c
#include <Keyboard.h>

extern const char* USBCore_GetFabricationId();

void setup() {
  // --- print serial number ----------
  Serial.begin(9600);
  delay(1000);
  Serial.println(USBCore_GetFabricationId());
  Serial.end();
  // -------------------------
}

void loop() {
}
```
