From 1c63842e66c95affb0c61f2206d021b68fae35b2 Mon Sep 17 00:00:00 2001 From: Namyoon Woo Date: Wed, 4 Dec 2019 18:44:46 -0800 Subject: vboot: add macros, enums, and struct for EC-EFS2 This CL defines new macros, an enum and a data structure for EC-EFS2 implementation. BUG=b:141143112 BRANCH=cr50 TEST=make buildall -j Change-Id: I0b5d634f8e040638b4c4ffef5c8519959c509577 Signed-off-by: Namyoon Woo Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1956158 --- include/vboot.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'include') diff --git a/include/vboot.h b/include/vboot.h index d757d0a3e7..7760af569f 100644 --- a/include/vboot.h +++ b/include/vboot.h @@ -2,11 +2,74 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#ifndef __CROS_EC_INCLUDE_VBOOT_H +#define __CROS_EC_INCLUDE_VBOOT_H #include "common.h" #include "vb21_struct.h" #include "rsa.h" +#define CR50_COMM_PREAMBLE 0xec +#define MIN_LENGTH_PREAMBLE 4 +#define CR50_COMM_MAGIC_CHAR0 'E' +#define CR50_COMM_MAGIC_CHAR1 'C' +#define CR50_COMM_MAGIC_WORD ((CR50_COMM_MAGIC_CHAR1 << 8) | \ + CR50_COMM_MAGIC_CHAR0) + +/* + * EC-Cr50 data stream looks like as follows: + * + * [preamble][header][payload] + * + * preamble: CR50_COMM_PREAMBLE (at least MIN_LENGTH_PREAMBLE times) + * header: struct cr50_comm_packet + * payload: data[] + */ +struct cr50_comm_packet { + /* Header */ + uint16_t magic; /* CR50_COMM_MAGIC_WORD */ + uint8_t crc; /* checksum computed from all bytes after crc */ + uint16_t cmd; /* CR50_COMM_CMD_* if it is sent by EC. */ + /* CR50_COMM_RESPONSE(X) if it is sent by CR50. */ + uint8_t size; /* size of 'data[]' member. */ + uint8_t data[]; /* payload */ +} __packed; + +#define CR50_COMM_MAX_DATA_SIZE 32 +#define CR50_COMM_MAX_PACKET_SIZE (sizeof(struct cr50_comm_packet) + \ + CR50_COMM_MAX_DATA_SIZE) + +/* EC-CR50 commands (2 bytes) for cr50_comm_packet.cmd */ +#define CR50_COMM_CMD_SET_BOOT_MODE 0x0001 +#define CR50_COMM_CMD_VERIFY_HASH 0x0002 + +/* EC-CR50 response codes (2 bytes) for cr50_comm_packet.cmd */ +#define CR50_COMM_RESPONSE(X) ((CR50_COMM_PREAMBLE << 8) | \ + ((X) & 0xff)) +#define CR50_COMM_SUCCESS CR50_COMM_RESPONSE(0x00) +#define CR50_COMM_ERROR_UNKNOWN CR50_COMM_RESPONSE(0x01) +#define CR50_COMM_ERROR_MAGIC CR50_COMM_RESPONSE(0x02) +#define CR50_COMM_ERROR_CRC CR50_COMM_RESPONSE(0x03) +#define CR50_COMM_ERROR_SIZE CR50_COMM_RESPONSE(0x04) +#define CR50_COMM_ERROR_TIMEOUT CR50_COMM_RESPONSE(0x05) +#define CR50_COMM_ERROR_HASH_MISMATCH CR50_COMM_RESPONSE(0x06) +#define CR50_COMM_ERROR_UNDEFINED_CMD CR50_COMM_RESPONSE(0x07) + +/* + * BIT(1) : NO_BOOT flag + * BIT(0) : RECOVERY flag + */ +enum ec_efs_boot_mode { + EC_EFS_BOOT_MODE_NORMAL = 0x00, + EC_EFS_BOOT_MODE_RECOVERY = 0x01, + EC_EFS_BOOT_MODE_NO_BOOT = 0x02, + EC_EFS_BOOT_MODE_NO_BOOT_RECOVERY = 0x03, + EC_EFS_BOOT_MODE_RESET = 0xff, + + /* boot_mode is uint8_t */ + EC_EFS_BOOT_MODE_LIMIT = 255, +}; + /** * Validate key contents. * @@ -58,3 +121,5 @@ void vboot_main(void); * @return 1: need PD communication. 0: PD communication is not needed. */ int vboot_need_pd_comm(void); + +#endif /* __CROS_EC_INCLUDE_VBOOT_H */ -- cgit v1.2.1