summaryrefslogtreecommitdiff
path: root/chip/g/board_id.h
blob: 2fbb6c261b0d9db19ae2dea454c02edac1d35783 (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
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright 2017 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef __EC_CHIP_G_BOARD_ID_H
#define __EC_CHIP_G_BOARD_ID_H

#include "board_space.h"
#include "common.h"
#include "signed_header.h"
#include "util.h"

/**
 * Check the current header vs. the supplied Board ID
 *
 * @param board_id	Pointer to a Board ID structure to check
 * @param h		Pointer to the currently running image's header
 *
 * @return 0 if no mismatch, non-zero if mismatch
 */
uint32_t check_board_id_vs_header(const struct board_id *id,
				  const struct SignedHeader *h);

/**
 * Check board ID from the flash INFO1 space.
 *
 * @param id	Pointer to a Board ID structure to fill
 *
 * @return EC_SUCCESS of an error code in cases of vairous failures to read.
 */
int read_board_id(struct board_id *id);

/**
 * Return the image header for the current image copy
 */
const struct SignedHeader *get_current_image_header(void);

/**
 * Check if board ID in the image matches board ID field in the INFO1.
 *
 * Pass the pointer to the image header to check. If the pointer is set to
 * NULL, check board ID against the currently running image's header. All 1
 * bits in header Board ID flags must be present in the board id from flash.
 *
 * If the board id from flash is blank, board_id_type field from the header is
 * ignored and only board_if_flags field is verified to match.
 *
 * Return true if there is a mismatch (the code should not run).
 */
uint32_t board_id_mismatch(const struct SignedHeader *h);

/**
 * Check if every field of the board id is 0xffffffff
 *
 * @param id	Pointer to a Board ID structure
 *
 * @return True if the board id is all 0xffffffff.
 */
int board_id_is_blank(const struct board_id *id);

/**
 * Check if the board id type and type_inv are 0xffffffff.
 *
 * @param id	Pointer to a Board ID structure
 *
 * @return True if the board id type and type_inv are 0xffffffff.
 */
int board_id_type_is_blank(const struct board_id *id);

/**
 * Check if board id space in INFO1 is erased.
 *
 * @return True if INFO1 board ID space is erased, False otherwise.
 */
int board_id_is_erased(void);

#endif  /* ! __EC_CHIP_G_BOARD_ID_H */