fwupd/libfwupdplugin/fu-fmap-firmware.h
Benson Leung 23ca19acf8 fmap-firmware: Parse flashmap format into images
Implements a search for the fmap, and follow the map to break the firmware
into the constituent images.

Tested using a servo_micro firmware:
$ fwupdtool firmware-parse servo_micro_v2.4.17-df61092c3.bin
<select fmap option>
FuFmapFirmware:
  FuFirmwareImage:
  ID:                    EC_RO
  Index:                 0x1
  Data:                  0xf000
  FuFirmwareImage:
  ID:                    FR_MAIN
  Index:                 0x2
  Data:                  0xf000
  FuFirmwareImage:
  ID:                    RO_FRID
  Index:                 0x3
  Address:               0xc4
  Data:                  0x20
  FuFirmwareImage:
  ID:                    FMAP
  Index:                 0x4
  Address:               0x9a40
  Version:               1.0
  Data:                  0x15e
  FuFirmwareImage:
  ID:                    WP_RO
  Index:                 0x5
  Data:                  0x10000
  FuFirmwareImage:
  ID:                    EC_RW
  Index:                 0x6
  Address:               0x10000
  Data:                  0x10000
  FuFirmwareImage:
  ID:                    RW_FWID
  Index:                 0x7
  Address:               0x100c4
  Data:                  0x20
2020-06-20 07:24:32 +01:00

51 lines
1.5 KiB
C

/*
* Copyright (C) 2020 Benson Leung <bleung@chromium.org>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#include "fu-firmware.h"
#define FMAP_STRLEN 32 /* maximum length for strings, */
/* including null-terminator */
#define FU_TYPE_FMAP_FIRMWARE (fu_fmap_firmware_get_type ())
G_DECLARE_DERIVABLE_TYPE (FuFmapFirmware, fu_fmap_firmware, FU, FMAP_FIRMWARE, FuFirmware)
struct _FuFmapFirmwareClass
{
FuFirmwareClass parent_class;
gboolean (*parse) (FuFirmware *self,
GBytes *fw,
guint64 addr_start,
guint64 addr_end,
FwupdInstallFlags flags,
GError **error);
/*< private >*/
gpointer padding[14];
};
/* mapping of volatile and static regions in firmware binary */
typedef struct __attribute__((packed)) {
guint32 offset; /* offset relative to base */
guint32 size; /* size in bytes */
guint8 name[FMAP_STRLEN]; /* descriptive name */
guint16 flags; /* flags for this area */
} FuFmapArea;
typedef struct __attribute__((packed)) {
guint8 signature[8]; /* "__FMAP__" (0x5F5F464D41505F5F) */
guint8 ver_major; /* major version */
guint8 ver_minor; /* minor version */
guint64 base; /* address of the firmware binary */
guint32 size; /* size of firmware binary in bytes */
guint8 name[FMAP_STRLEN]; /* name of this firmware binary */
guint16 nareas; /* number of areas described by
areas[] below */
FuFmapArea areas[];
} FuFmap;
FuFirmware *fu_fmap_firmware_new (void);