Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_subdirectory(pinctrl)
add_subdirectory(piolib)
add_subdirectory(raspinfo)
add_subdirectory(rpieepromab)
add_subdirectory(rpierrorlog)
add_subdirectory(rpi-gpu-usage)
add_subdirectory(rpi-manufacture-info)
add_subdirectory(rpi-pmic)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ A collection of scripts and simple applications
the submission of bug reports.
* [rpieepromab](rpieepromab/) - A tool to update and manage the AB EEPROM partitions
on a device in the Pi 5 family.
* [rpierrorlog](rpierrorlog/) - A tool to read and clear the fatal boot errors
that the bootloader logs in the SPI EEPROM on a device in the Pi 5 family.
* [rpifwcrypto](rpifwcrypto/) - A command line application and shared library for the
firmware cryptography service. Intended for use with Raspberry Pi Connect and
secure-boot provisioner.
Expand Down
25 changes: 25 additions & 0 deletions rpierrorlog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.10...3.27)
include(GNUInstallDirs)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
option(ENABLE_WERROR "Treat compiler warnings as errors" OFF)
if(ENABLE_WERROR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()

project(rpierrorlog)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

add_library(rpierrorlog rpierrorlog.c)
target_sources(rpierrorlog PUBLIC rpierrorlog.h)
set_target_properties(rpierrorlog PROPERTIES PUBLIC_HEADER rpierrorlog.h)
set_target_properties(rpierrorlog PROPERTIES SOVERSION 0)

add_executable(rpi-error-log main.c)
target_link_libraries(rpi-error-log rpierrorlog)

install(TARGETS rpi-error-log RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS rpierrorlog
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
26 changes: 26 additions & 0 deletions rpierrorlog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# rpierrorlog
Comment thread
pelwell marked this conversation as resolved.
Resolved

Tool to read and clear the fatal boot errors that the bootloader logs in the
SPI EEPROM on Raspberry Pi 5 family devices.

The log keeps the error code of each fatal boot error, so the reason for a
failed boot can still be read after the device restarts. Installing a
bootloader update clears the log, because the errors in it came from the
previous bootloader version. The log only exists on AB-capable firmware.

**Build Instructions**

Install prerequisites with "sudo apt install cmake" - you need at least version 3.10.

- *mkdir build*
- *cd build*
- *cmake ..*
- *make*
- *sudo make install*

**Usage**

* rpi-error-log (Shows usage information)
* rpi-error-log get (Read and print all EEPROM error log entries - Pi 5 family boards only)
* rpi-error-log clear (Clear the EEPROM error log and verify it is empty - Pi 5 family boards only)
91 changes: 91 additions & 0 deletions rpierrorlog/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <stdio.h>
#include <string.h>
#include "rpierrorlog.h"

static void usage(const char *progname)
{
fprintf(stderr,
"Usage: %s <command>\n"
"\n"
"Commands:\n"
" get Read and print all EEPROM error log entries\n"
" (Pi 5 family boards only)\n"
" clear Clear the EEPROM error log and verify it is empty\n"
" (Pi 5 family boards only)\n",
progname);
}

static int cmd_get(void)
{
rpi_error_log_t entries[RPI_ERROR_LOG_MAX_SIZE / RPI_ERROR_LOG_ENTRY_SIZE];
size_t count;

if (rpi_error_log_get(entries, sizeof(entries) / sizeof(entries[0]), &count) < 0) {
fprintf(stderr, "Failed to read error log\n");
return -1;
}

if (count == 0) {
printf("No error log entries\n");
return 0;
}

for (size_t i = 0; i < count; i++)
printf("Entry %zu: 0x%08x - %s\n", i, entries[i].error_code, rpi_error_log_strerror(entries[i].error_code));

return 0;
}

static int cmd_clear(void)
{
rpi_error_log_t entries[RPI_ERROR_LOG_MAX_SIZE / RPI_ERROR_LOG_ENTRY_SIZE];
size_t count;

if (rpi_error_log_clear() < 0) {
fprintf(stderr, "Failed to clear error log\n");
return -1;
}
printf("Error log cleared\n");

if (rpi_error_log_get(entries, sizeof(entries) / sizeof(entries[0]), &count) < 0) {
fprintf(stderr, "Verification read failed\n");
return -1;
}
if (count != 0) {
fprintf(stderr, "Verification failed: %zu entries still present after clear\n", count);
return -1;
}
printf("Verification OK: error log is empty\n");
return 0;
}

int main(int argc, char *argv[])
{
int rc = -1;

if (argc != 2) {
usage(argv[0]);
return 1;
}

if (strcmp(argv[1], "get") == 0) {
rc = cmd_get();
if (rc < 0)
goto error;
return 0;
}

if (strcmp(argv[1], "clear") == 0) {
rc = cmd_clear();
if (rc < 0)
goto error;
return 0;
}

usage(argv[0]);
return 1;

error:
fprintf(stderr, "Command '%s' failed\n", argv[1]);
return rc;
}
Loading
Loading