summaryrefslogtreecommitdiff
path: root/gcip-kernel-driver/include/gcip/gcip-common-image-header.h
blob: d986fbcc8aa46415d29af1296ec6addb09de8caa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Common authenticated image format for Google SoCs
 *
 * Copyright (C) 2022 Google LLC
 */

#ifndef __GCIP_COMMON_IMAGE_HEADER_H__
#define __GCIP_COMMON_IMAGE_HEADER_H__

#include <linux/types.h>

#include "gcip-image-config.h"

#define GCIP_FW_HEADER_SIZE (0x1000)

struct gcip_common_image_sub_header_common {
	uint32_t magic;
	uint32_t generation;
	uint32_t rollback_info;
	uint32_t length;
	uint8_t flags[16];
};

struct gcip_common_image_sub_header_gen1 {
	uint8_t body_hash[32];
	uint8_t chip_id[32];
	uint8_t auth_config[256];
	struct gcip_image_config image_config;
};

struct gcip_common_image_sub_header_gen2 {
	uint8_t body_hash[64];
	uint8_t chip_id[32];
	uint8_t auth_config[256];
	struct gcip_image_config image_config;
};

struct gcip_common_image_header {
	uint8_t sig[512];
	uint8_t pub[512];
	struct {
		struct gcip_common_image_sub_header_common common;
		union {
			struct gcip_common_image_sub_header_gen1 gen1;
			struct gcip_common_image_sub_header_gen2 gen2;
		};
	};
};

/*
 * Returns the image config field from a common image header
 * or NULL if the header has an invalid generation identifier
 */
static inline struct gcip_image_config *
get_image_config_from_hdr(struct gcip_common_image_header *hdr)
{
	switch (hdr->common.generation) {
	case 1:
		return &hdr->gen1.image_config;
	case 2:
		return &hdr->gen2.image_config;
	}
	return NULL;
}

#endif  /* __GCIP_COMMON_IMAGE_HEADER_H__ */