76dab5f98f
To support the new CONFIG_CBFS_VERIFICATION feature, cbfstool needs to update the metadata hash embedded in the bootblock code every time it adds or removes a CBFS file. This can lead to problems on certain platforms where the bootblock needs to be specially wrapped in some platform-specific data structure so that the platform's masked ROM can recognize it. If that data structure contains any form of hash or signature of the bootblock code that is checked on every boot, it will no longer match if cbfstool modifies it after the fact. In general, we should always try to disable these kinds of features where possible (they're not super useful anyway). But for platforms where the hardware simply doesn't allow that, this patch introduces the concept of "platform fixups" to cbfstool. Whenever cbfstool finds a metadata hash anchor in a CBFS image, it will run all built-in "fixup probe" functions on that bootblock to check if it can recognize it as the wrapper format for a platform known to have such an issue. If so, it will register a corresponding fixup function that will run whenever it tries to write back modified data to that bootblock. The function can then modify any platform-specific headers as necessary. As first supported platform, this patch adds a fixup for Qualcomm platforms (specifically the header format used by sc7180), which recalculates the bootblock body hash originally added by util/qualcomm/createxbl.py. (Note that this feature is not intended to support platform-specific signature schemes like BootGuard directly in cbfstool. For anything that requires an actual secret key, it should be okay if the user needs to run a platform-specific signing tool on the final CBFS image before flashing. This feature is intended for the normal unsigned case (which on some platforms may be implemented as signing with a well-known key) so that on a board that is not "locked down" in any way the normal use case of manipulating an image with cbfstool and then directly flashing the output file stays working with CONFIG_CBFS_VERIFICATION.) Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I02a83a40f1d0009e6f9561ae5d2d9f37a510549a Reviewed-on: https://review.coreboot.org/c/coreboot/+/41122 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
80 lines
2.3 KiB
C
80 lines
2.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
#ifndef __CBFS_H
|
|
#define __CBFS_H
|
|
|
|
#include "common.h"
|
|
#include <commonlib/bsd/cbfs_serialized.h>
|
|
|
|
/* To make CBFS more friendly to ROM, fill -1 (0xFF) instead of zero. */
|
|
#define CBFS_CONTENT_DEFAULT_VALUE (-1)
|
|
|
|
#define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC
|
|
|
|
/* cbfstool is allowed to use this constant freely since it's not part of the
|
|
CBFS image, so make an alias for the name that's a little less aggressive. */
|
|
#define METADATA_HASH_ANCHOR_MAGIC \
|
|
DO_NOT_USE_METADATA_HASH_ANCHOR_MAGIC_DO_NOT_USE
|
|
|
|
struct typedesc_t {
|
|
uint32_t type;
|
|
const char *name;
|
|
};
|
|
|
|
static const struct typedesc_t types_cbfs_compression[] = {
|
|
{CBFS_COMPRESS_NONE, "none"},
|
|
{CBFS_COMPRESS_LZMA, "LZMA"},
|
|
{CBFS_COMPRESS_LZ4, "LZ4"},
|
|
{0, NULL},
|
|
};
|
|
|
|
static struct typedesc_t filetypes[] unused = {
|
|
{CBFS_TYPE_BOOTBLOCK, "bootblock"},
|
|
{CBFS_TYPE_CBFSHEADER, "cbfs header"},
|
|
{CBFS_TYPE_STAGE, "stage"},
|
|
{CBFS_TYPE_SELF, "simple elf"},
|
|
{CBFS_TYPE_FIT, "fit"},
|
|
{CBFS_TYPE_OPTIONROM, "optionrom"},
|
|
{CBFS_TYPE_BOOTSPLASH, "bootsplash"},
|
|
{CBFS_TYPE_RAW, "raw"},
|
|
{CBFS_TYPE_VSA, "vsa"},
|
|
{CBFS_TYPE_MBI, "mbi"},
|
|
{CBFS_TYPE_MICROCODE, "microcode"},
|
|
{CBFS_TYPE_FSP, "fsp"},
|
|
{CBFS_TYPE_MRC, "mrc"},
|
|
{CBFS_TYPE_CMOS_DEFAULT, "cmos_default"},
|
|
{CBFS_TYPE_CMOS_LAYOUT, "cmos_layout"},
|
|
{CBFS_TYPE_SPD, "spd"},
|
|
{CBFS_TYPE_MRC_CACHE, "mrc_cache"},
|
|
{CBFS_TYPE_MMA, "mma"},
|
|
{CBFS_TYPE_EFI, "efi"},
|
|
{CBFS_TYPE_STRUCT, "struct"},
|
|
{CBFS_TYPE_DELETED, "deleted"},
|
|
{CBFS_TYPE_NULL, "null"},
|
|
{0, NULL}
|
|
};
|
|
|
|
#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
|
|
|
|
static inline size_t cbfs_file_attr_hash_size(enum vb2_hash_algorithm algo)
|
|
{
|
|
return offsetof(struct cbfs_file_attr_hash, hash.raw) +
|
|
vb2_digest_size(algo);
|
|
}
|
|
|
|
/* cbfs_image.c */
|
|
uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
|
|
uint32_t get_cbfs_compression(const char *name, uint32_t unknown);
|
|
|
|
/* cbfs-mkpayload.c */
|
|
void xdr_segs(struct buffer *output,
|
|
struct cbfs_payload_segment *segs, int nseg);
|
|
void xdr_get_seg(struct cbfs_payload_segment *out,
|
|
struct cbfs_payload_segment *in);
|
|
|
|
/* platform_fixups.c */
|
|
typedef int (*platform_fixup_func)(struct buffer *buffer, size_t offset);
|
|
platform_fixup_func platform_fixups_probe(struct buffer *buffer, size_t offset,
|
|
const char *region_name);
|
|
|
|
#endif
|