Skip to content

Commit f64fa31

Browse files
martamomotkotimg236
authored andcommitted
rpiboot: Enable metadata output by default when metadata is received
Metadata information is now written to stdout by default when received from BCM2712/2711 devices. The -j flag can be used to specify a directory for a JSON file output instead. To instruct recovery.bin to stop sending metadata, explicitly set recovery_metadata=0 in config.txt.
1 parent 7242b34 commit f64fa31

File tree

9 files changed

+57
-67
lines changed

9 files changed

+57
-67
lines changed

Readme.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ the minimal set of files required from the boot partition.
219219
See the [troubleshooting guide](docs/troubleshooting.md).
220220

221221
## Reading device metadata from OTP via rpiboot
222-
The `rpiboot` "recovery" modules provide a facility to read the device OTP information. This can be run either as a provisioning step or as a standalone operation.
222+
The `rpiboot` "recovery" modules provide a facility to read the device OTP information. This can be run either as a provisioning step or as a standalone operation. Pass the `-j metadata` flag to `rpiboot` to write metadata JSON to a specified "metadata" directory.
223223

224-
To enable this make sure that `recovery_metadata=1` is set in the recovery `config.txt` file and pass the `-j metadata` flag to `rpiboot`.
224+
Metadata output is enabled by default. To disable add `recovery_metadata=0` to the recovery `config.txt` file.
225225

226226
See [board revision](https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes-in-use) documentation to decode the `BOARD_ATTR` field.
227227

@@ -235,13 +235,15 @@ sudo rpiboot -j metadata -d .
235235
Example metadata file contents written to `metadata/SERIAL_NUMBER.json`:
236236
```json
237237
{
238-
"MAC_ADDR" : "d8:3a:dd:05:ee:78",
239-
"CUSTOMER_KEY_HASH" : "8251a63a2edee9d8f710d63e9da5d639064929ce15a2238986a189ac6fcd3cee",
240-
"BOOT_ROM" : "0000c8b0",
241-
"BOARD_ATTR" : "00000000",
242-
"USER_BOARDREV" : "c03141",
243-
"JTAG_LOCKED" : "0",
244-
"ADVANCED_BOOT" : "0000e8e8"
238+
"MAC_ADDR": "d8:3a:dd:05:ee:78",
239+
"EEPROM_UPDATE": "success",
240+
"EEPROM_HASH": "dfc8ef2c77b8152a5cfa008c2296246413fd580fdc26dfacd431e348571a2137",
241+
"CUSTOMER_KEY_HASH": "8251a63a2edee9d8f710d63e9da5d639064929ce15a2238986a189ac6fcd3cee",
242+
"BOOT_ROM": "0000c8b0",
243+
"BOARD_ATTR": "00000000",
244+
"USER_BOARDREV": "c03141",
245+
"JTAG_LOCKED": "0",
246+
"ADVANCED_BOOT": "0000e8e8"
245247
}
246248
```
247249

docs/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ Be careful not to overwrite `bootcode.bin` or `bootcode4.bin` with the executabl
4747
* If `rpiboot` starts to download `bootcode4.bin` but the transfer fails then can indicate a cable issue OR a corrupted file. Check the hash of `bootcode.bin` file against this repository and check `dmesg` for USB error.
4848
* If `bootcode.bin` or the `start.elf` detects an error then [error-code](https://www.raspberrypi.com/documentation/computers/configuration.html#led-warning-flash-codes) will be indicated by flashing the green activity LED.
4949
* Add `uart_2ndstage=1` to the `config.txt` file in `msd/` or `recovery/` directories to enable UART debug output.
50-
* Add `recovery_metadata=1` to the `config.txt` file in `recovery/` or `recovery5/` directory to enable metadata JSON output.
50+
* Add `recovery_metadata=0` to the `config.txt` file in `recovery/` or `recovery5/` directory to disable metadata JSON output.
5151

main.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void usage(int error)
8787
fprintf(dest, " -0/1/2/3/4/5/6 : Only look for CMs attached to USB port number 0-6\n");
8888
fprintf(dest, " -p [pathname] : Only look for CM with USB pathname\n");
8989
fprintf(dest, " -i [serialno] : Only look for a Raspberry Pi Device with a given serialno\n");
90-
fprintf(dest, " -j [path] : Output metadata JSON object to stdout, or to a file if directory is provided (BCM2712/2711)\n");
90+
fprintf(dest, " -j [path] : Write metadata JSON object to a file at the given path (BCM2712/2711)\n");
9191
fprintf(dest, " -h : This help\n");
9292

9393
exit(error ? -1 : 0);
@@ -540,7 +540,6 @@ void get_options(int argc, char *argv[])
540540
}
541541
else if(strcmp(*argv, "-j") == 0)
542542
{
543-
metadata = 1;
544543
if ((argc > 1) && (argv[1][0] != '-')) {
545544
argv++; argc--;
546545
metadata_path = *argv;
@@ -788,11 +787,7 @@ FILE * check_file(const char * dir, const char *fname, int use_fmem)
788787
}
789788

790789
void close_metadata_file(FILE ** fp){
791-
long pos = ftell(*fp);
792-
if (pos == 0) // No metadata received, write empty JSON object
793-
fprintf(*fp, "{}\n");
794-
else
795-
fprintf(*fp, "\n}\n");
790+
fprintf(*fp, "\n}\n");
796791
if (*fp != stdout)
797792
fclose(*fp);
798793
}
@@ -865,19 +860,6 @@ int file_server(libusb_device_handle * usb_device)
865860
char metadata_fname[FILE_NAME_LENGTH];
866861
int metadata_index = 0;
867862

868-
if (metadata)
869-
{
870-
if (bcm2711 || bcm2712)
871-
{
872-
create_metadata_file(&metadata_fp);
873-
}
874-
else
875-
{
876-
fprintf(stderr, "Failed to create metadata file: expected BCM2712/2711");
877-
metadata = 0;
878-
}
879-
}
880-
881863
while(going)
882864
{
883865
char message_name[][20] = {"GetFileSize", "ReadFile", "Done"};
@@ -902,6 +884,14 @@ int file_server(libusb_device_handle * usb_device)
902884
// Metadata files
903885
if ((message.fname[0] == '*') && (message.command != 2))
904886
{
887+
if (!metadata_fp)
888+
{
889+
if (bcm2711 || bcm2712)
890+
{
891+
create_metadata_file(&metadata_fp);
892+
metadata = 1;
893+
}
894+
}
905895
if (metadata)
906896
{
907897
strcpy(metadata_fname, message.fname);

recovery/config.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44
# Uncomment to instruct recovery.bin to reboot the Pi after flashing the bootloader image
55
#recovery_reboot=1
66

7-
# Uncomment to instruct recovery.bin to send metadata including OTP fields
8-
# Specify -j dirname on the command line to specify the directory where
9-
# metadata should be stored (JSON format)
10-
recovery_metadata=1
7+
# Uncomment to instruct recovery.bin to stop sending metadata
8+
#recovery_metadata=0

recovery5/config.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ uart_2ndstage=1
44
# Uncomment to instruct recovery.bin to reboot the Pi after flashing the bootloader image
55
#recovery_reboot=1
66

7-
# Uncomment to instruct recovery.bin to send metadata including OTP fields
8-
# Specify -j dirname on the command line to specify the directory where
9-
# metadata should be stored (JSON format)
10-
recovery_metadata=1
7+
# Uncomment to instruct recovery.bin to stop sending metadata
8+
#recovery_metadata=0

secure-boot-recovery/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,21 @@ mkdir -p metadata
8383
```
8484

8585
### Metadata
86-
The optional metadata argument causes rpiboot to readback the OTP information and write it to a JSON file in the given directory.
86+
Metadata output is enabled by default to stdout. Optional argument can be used to specify writing a JSON file to the given directory.
8787
This can be useful for debug or for storing in a provisioning database.
8888

89-
Example metadata:
89+
Example metadata file contents written to `metadata/SERIAL_NUMBER.json`:
9090
```json
9191
{
92-
"MAC_ADDR" : "d8:3a:dd:05:ee:78",
93-
"CUSTOMER_KEY_HASH" : "8251a63a2edee9d8f710d63e9da5d639064929ce15a2238986a189ac6fcd3cee",
94-
"BOOT_ROM" : "0000c8b0",
95-
"BOARD_ATTR" : "00000000",
96-
"USER_BOARDREV" : "c03141",
97-
"JTAG_LOCKED" : "0",
98-
"ADVANCED_BOOT" : "0000e8e8"
92+
"MAC_ADDR": "d8:3a:dd:05:ee:78",
93+
"EEPROM_UPDATE": "success",
94+
"EEPROM_HASH": "dfc8ef2c77b8152a5cfa008c2296246413fd580fdc26dfacd431e348571a2137",
95+
"SECURE_BOOT_PROVISION": "success",
96+
"CUSTOMER_KEY_HASH": "8251a63a2edee9d8f710d63e9da5d639064929ce15a2238986a189ac6fcd3cee",
97+
"BOOT_ROM": "0000c8b0",
98+
"BOARD_ATTR": "00000000",
99+
"USER_BOARDREV": "c03141",
100+
"JTAG_LOCKED": "0",
101+
"ADVANCED_BOOT": "0000e8e8"
99102
}
100103
```
101-

secure-boot-recovery/config.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ uart_2ndstage=1
3636
# reboot after the flashing the firmware.
3737
#recovery_reboot=1
3838

39-
# Uncomment to instruct recovery.bin to send metadata including OTP fields
40-
# Specify -j dirname on the command line to specify the directory where
41-
# metadata should be stored (JSON format)
42-
recovery_metadata=1
39+
# Uncomment to instruct recovery.bin to stop sending metadata
40+
#recovery_metadata=0

secure-boot-recovery5/README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,26 @@ This output is given by the EEPROM bootloader when it verifies the signature of
8989
```
9090

9191
### Metadata
92-
The optional metadata argument causes rpiboot to readback the OTP information and write it to a JSON file in the given directory.
92+
Metadata output is enabled by default to stdout. Optional argument can be used to specify writing a JSON file to the given directory.
9393
This can be useful for debug or for storing in a provisioning database.
9494

9595
Example metadata:
9696
```json
9797
{
98-
"USER_SERIAL_NUM" : "a7eb274c",
99-
"MAC_ADDR" : "2c:cf:67:70:76:f3",
100-
"CUSTOMER_KEY_HASH" : "8251a63a2edee9d8f710d63e9da5d639064929ce15a2238986a189ac6fcd3cee",
101-
"BOOT_ROM" : "0000000a",
102-
"BOARD_ATTR" : "00000000",
103-
"USER_BOARDREV" : "b04170",
104-
"JTAG_LOCKED" : "0",
105-
"MAC_WIFI_ADDR" : "2c:cf:67:70:76:f4",
106-
"MAC_BT_ADDR" : "2c:cf:67:70:76:f5",
107-
"FACTORY_UUID" : "001000911006186073"
98+
"USER_SERIAL_NUM": "a7eb274c",
99+
"MAC_ADDR": "2c:cf:67:70:76:f3",
100+
"EEPROM_UPDATE": "success",
101+
"EEPROM_HASH": "dfc8ef2c77b8152a5cfa008c2296246413fd580fdc26dfacd431e348571a2137",
102+
"SECURE_BOOT_PROVISION": "success",
103+
"CUSTOMER_KEY_HASH": "8251a63a2edee9d8f710d63e9da5d639064929ce15a2238986a189ac6fcd3cee",
104+
"BOOT_ROM": "0000000a",
105+
"BOARD_ATTR": "00000000",
106+
"USER_BOARDREV": "b04170",
107+
"JTAG_LOCKED": "0",
108+
"SIGNATURE_MODE": "0",
109+
"MAC_WIFI_ADDR": "2c:cf:67:70:76:f4",
110+
"MAC_BT_ADDR": "2c:cf:67:70:76:f5",
111+
"FACTORY_UUID": "001000911006186073"
108112
}
109113
```
110114

secure-boot-recovery5/config.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,5 @@ uart_2ndstage=1
2525
# reboot after the flashing the firmware.
2626
#recovery_reboot=1
2727

28-
# Uncomment to instruct recovery.bin to send metadata including OTP fields
29-
# Specify -j dirname on the command line to specify the directory where
30-
# metadata should be stored (JSON format)
31-
recovery_metadata=1
28+
# Uncomment to instruct recovery.bin to stop sending metadata
29+
#recovery_metadata=0

0 commit comments

Comments
 (0)