Skip to content

Commit

Permalink
lib/flash: Check if the partition is signed
Browse files Browse the repository at this point in the history
In more recent firmware images built by op-build the VERSION partition
is signed, and includes a 'secure header'. Check for this and skip it if
found so we parse the version strings properly.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
(cherry picked from commit 6a9c33f)
  • Loading branch information
sammj committed Jan 8, 2019
1 parent 93d41f9 commit 017aada
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <libflash/file.h>
#include <libflash/ecc.h>

#define SECURE_BOOT_HEADERS_SIZE 4096
#define ROM_MAGIC_NUMBER 0x17082011

struct flash_info {
/* Device information */
Expand Down Expand Up @@ -148,6 +150,16 @@ static struct flash_info *flash_setup_buffer(void *ctx, const char *partition)
return NULL;
}

/* See stb_is_container() in Skiboot */
static bool is_signed(char *buffer, uint32_t len)
{
if (!buffer || len <= SECURE_BOOT_HEADERS_SIZE)
return false;
if (be32_to_cpu(*(uint32_t *)buffer) != ROM_MAGIC_NUMBER)
return false;
return true;
}

int flash_parse_version(void *ctx, char ***versions, bool current)
{
char *saveptr, *tok, **tmp, *buffer;
Expand Down Expand Up @@ -182,6 +194,10 @@ int flash_parse_version(void *ctx, char ***versions, bool current)
goto out;
}

/* Check if this partition is signed */
if (is_signed(buffer, len))
buffer += SECURE_BOOT_HEADERS_SIZE;

/* open-power-platform */
tok = strtok_r(buffer, delim, &saveptr);
if (tok) {
Expand Down

0 comments on commit 017aada

Please sign in to comment.