Skip to content

Commit 1b7e76f

Browse files
committed
Capture JTAG, EEPROM states in manufacturing database
- Updated the devices table schema to include new security tracking fields: jtag_locked, eeprom_write_protected, pubkey_programmed, and signed_boot_enabled, with defaults set to NULL. - Modified data migration logic to accommodate the new schema, ensuring proper data insertion from the old table. - Added logic to determine security flags based on provisioning configuration during metadata gathering.
1 parent 0b231da commit 1b7e76f

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

debian/postinst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ else
6767
CREATE TABLE devices_new($STATE_DB_SCHEMA);
6868
6969
-- Copy data from old table to new table (handling all columns)
70-
INSERT INTO devices_new($(echo $CURRENT_COLUMNS | sed 's/,$//'))
71-
SELECT $(echo $CURRENT_COLUMNS | sed 's/,$//')
70+
INSERT INTO devices_new($(echo "$CURRENT_COLUMNS" | sed 's/,$//'))
71+
SELECT $(echo "$CURRENT_COLUMNS" | sed 's/,$//')
7272
FROM devices;
7373
7474
-- Drop old table
@@ -95,6 +95,7 @@ fi
9595

9696
# Define the expected schema for manufacturing.db devices table
9797
# secure is set to 1 by default, as any prior release of rpi-sb-provisioner will have only offered secure provisioning
98+
# Security tracking fields default to NULL to distinguish between not-applied vs unknown state
9899
MFG_DB_SCHEMA="id integer primary key,
99100
boardname varchar(255) not null,
100101
serial char(8) not null,
@@ -109,6 +110,10 @@ MFG_DB_SCHEMA="id integer primary key,
109110
memory varchar(255) not null,
110111
manufacturer varchar(255) not null,
111112
secure integer not null DEFAULT 1,
113+
jtag_locked integer DEFAULT NULL,
114+
eeprom_write_protected integer DEFAULT NULL,
115+
pubkey_programmed integer DEFAULT NULL,
116+
signed_boot_enabled integer DEFAULT NULL,
112117
provision_ts timestamp default current_timestamp"
113118

114119
# Ensure WAL journal mode
@@ -126,7 +131,7 @@ else
126131
CURRENT_COLUMNS=$(sqlite3 "$MFG_DB_PATH" "PRAGMA table_info(devices);" | awk -F'|' '{print $2}' | tr '\n' ',')
127132

128133
# Check if any expected columns are missing
129-
for COL in id boardname serial eth_mac wifi_mac bt_mac mmc_size mmc_cid rpi_duid board_revision processor memory manufacturer secure provision_ts; do
134+
for COL in id boardname serial eth_mac wifi_mac bt_mac mmc_size mmc_cid rpi_duid board_revision processor memory manufacturer secure jtag_locked eeprom_write_protected pubkey_programmed signed_boot_enabled provision_ts; do
130135
if ! echo "$CURRENT_COLUMNS" | grep -q "$COL"; then
131136
echo "Migration needed: column $COL is missing from manufacturing.db devices table"
132137

@@ -135,8 +140,8 @@ else
135140
CREATE TABLE devices_new($MFG_DB_SCHEMA);
136141
137142
-- Copy data from old table to new table
138-
INSERT INTO devices_new($(echo $CURRENT_COLUMNS | sed 's/,$//'))
139-
SELECT $(echo $CURRENT_COLUMNS | sed 's/,$//')
143+
INSERT INTO devices_new($(echo "$CURRENT_COLUMNS" | sed 's/,$//'))
144+
SELECT $(echo "$CURRENT_COLUMNS" | sed 's/,$//')
140145
FROM devices;
141146
142147
-- Drop old table

host-support/manufacturing-data

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ metadata_gather() {
9191
sqlite3 "${RPI_SB_PROVISIONER_MANUFACTURING_DB}" "PRAGMA journal_mode=WAL;" > /dev/null 2>&1
9292

9393
# Define the schema for devices table
94+
# Security tracking fields default to NULL to distinguish between not-applied vs unknown state
9495
EXPECTED_SCHEMA="id integer primary key,
9596
boardname varchar(255) not null,
9697
serial char(8) not null,
@@ -105,6 +106,10 @@ metadata_gather() {
105106
memory varchar(255) not null,
106107
manufacturer varchar(255) not null,
107108
secure integer not null,
109+
jtag_locked integer DEFAULT NULL,
110+
eeprom_write_protected integer DEFAULT NULL,
111+
pubkey_programmed integer DEFAULT NULL,
112+
signed_boot_enabled integer DEFAULT NULL,
108113
provision_ts timestamp default current_timestamp"
109114

110115
# Check if the table exists
@@ -115,6 +120,41 @@ metadata_gather() {
115120
sqlite3 "${RPI_SB_PROVISIONER_MANUFACTURING_DB}" "CREATE TABLE devices($EXPECTED_SCHEMA);" > /dev/null 2>&1
116121
fi
117122

123+
# Determine security flags based on provisioning configuration
124+
# JTAG lock status: 1 if enabled, 0 if explicitly disabled, NULL if not configured
125+
JTAG_LOCKED_VALUE="NULL"
126+
if [ -n "${RPI_DEVICE_LOCK_JTAG}" ]; then
127+
JTAG_LOCKED_VALUE="1"
128+
elif [ "${SECURE}" = "1" ]; then
129+
# For secure provisioning, explicitly track that JTAG locking was not enabled
130+
JTAG_LOCKED_VALUE="0"
131+
fi
132+
133+
# EEPROM write protection status: 1 if enabled, 0 if explicitly disabled, NULL if not configured
134+
EEPROM_WP_VALUE="NULL"
135+
if [ -n "${RPI_DEVICE_EEPROM_WP_SET}" ]; then
136+
EEPROM_WP_VALUE="1"
137+
elif [ "${SECURE}" = "1" ]; then
138+
# For secure provisioning, explicitly track that EEPROM WP was not enabled
139+
EEPROM_WP_VALUE="0"
140+
fi
141+
142+
# Public key programming: 1 for secure provisioning, 0 for non-secure, NULL for unknown
143+
PUBKEY_PROGRAMMED_VALUE="NULL"
144+
if [ "${SECURE}" = "1" ]; then
145+
PUBKEY_PROGRAMMED_VALUE="1"
146+
elif [ "${SECURE}" = "0" ]; then
147+
PUBKEY_PROGRAMMED_VALUE="0"
148+
fi
149+
150+
# Signed boot: 1 for secure provisioning, 0 for non-secure, NULL for unknown
151+
SIGNED_BOOT_VALUE="NULL"
152+
if [ "${SECURE}" = "1" ]; then
153+
SIGNED_BOOT_VALUE="1"
154+
elif [ "${SECURE}" = "0" ]; then
155+
SIGNED_BOOT_VALUE="0"
156+
fi
157+
118158
# Insert new device data
119159
sqlite3 "${RPI_SB_PROVISIONER_MANUFACTURING_DB}" \
120160
"INSERT INTO devices( \
@@ -130,7 +170,11 @@ metadata_gather() {
130170
processor, \
131171
memory, \
132172
manufacturer, \
133-
secure \
173+
secure, \
174+
jtag_locked, \
175+
eeprom_write_protected, \
176+
pubkey_programmed, \
177+
signed_boot_enabled \
134178
) VALUES ( \
135179
'${BOARD_STR}', \
136180
'${TARGET_DEVICE_SERIAL}', \
@@ -144,7 +188,11 @@ metadata_gather() {
144188
'${PROCESSOR_STR}', \
145189
'${MEMORY_STR}', \
146190
'${MANUFACTURER_STR}', \
147-
'${SECURE}' \
191+
'${SECURE}', \
192+
${JTAG_LOCKED_VALUE}, \
193+
${EEPROM_WP_VALUE}, \
194+
${PUBKEY_PROGRAMMED_VALUE}, \
195+
${SIGNED_BOOT_VALUE} \
148196
);" > /dev/null 2>&1
149197
announce_stop "Manufacturing Database Insertion"
150198
fi

0 commit comments

Comments
 (0)