blob: e2eb3c2d0801de31180383f892572e5082e8388e [file] [log] [blame]
Monika Singh5e170362018-03-14 00:48:36 +05301/* Copyright (c) 2018, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#ifndef __VERIFIEDBOOT_H__
30#define __VERIFIEDBOOT_H__
31
32#include <stdlib.h>
33#include <stdint.h>
34#include <string.h>
35#include <sys/types.h>
36#include <mmc.h>
37#include <platform.h>
38#include <devinfo.h>
39#include <meta_format.h>
40#include <boot_device.h>
41#include <boot_verifier.h>
42#include <target.h>
43
44typedef enum {
45 NO_AVB = 0,
46 AVB_1,
47 AVB_2,
48 AVB_LE
49} avb_versions;
50
51#define VB_SHA256_SIZE 32
52#define LE_BOOTIMG_SIG_SIZE 256
53#define abort() ASSERT(false);
54#define MAX_PATH_SIZE 64
55
56#define EFIERR(_a) (-1 * (_a))
57
Mayank Grover8f46a892018-09-10 13:24:59 +053058#define SALT_BUFF_OFFSET (1024)
59#define ADD_SALT_BUFF_OFFSET(addr) (SALT_BUFF_OFFSET + (addr))
60#define SUB_SALT_BUFF_OFFSET(addr) ((addr) - SALT_BUFF_OFFSET)
61
Monika Singh5e170362018-03-14 00:48:36 +053062#define EFI_SUCCESS 0
63#define EFI_LOAD_ERROR EFIERR (1)
64#define EFI_INVALID_PARAMETER EFIERR (2)
65#define EFI_UNSUPPORTED EFIERR (3)
66#define EFI_BAD_BUFFER_SIZE EFIERR (4)
67#define EFI_BUFFER_TOO_SMALL EFIERR (5)
68#define EFI_NOT_READY EFIERR (6)
69#define EFI_DEVICE_ERROR EFIERR (7)
70#define EFI_WRITE_PROTECTED EFIERR (8)
71#define EFI_OUT_OF_RESOURCES EFIERR (9)
72#define EFI_VOLUME_CORRUPTED EFIERR (10)
73#define EFI_VOLUME_FULL EFIERR (11)
74#define EFI_NO_MEDIA EFIERR (12)
75#define EFI_MEDIA_CHANGED EFIERR (13)
76#define EFI_NOT_FOUND EFIERR (14)
77#define EFI_ACCESS_DENIED EFIERR (15)
78#define EFI_NO_RESPONSE EFIERR (16)
79#define EFI_NO_MAPPING EFIERR (17)
80#define EFI_TIMEOUT EFIERR (18)
81#define EFI_NOT_STARTED EFIERR (19)
82#define EFI_ALREADY_STARTED EFIERR (20)
83#define EFI_ABORTED EFIERR (21)
84#define EFI_ICMP_ERROR EFIERR (22)
85
86#define EFI_TFTP_ERROR EFIERR (23)
87#define EFI_PROTOCOL_ERROR EFIERR (24)
88#define EFI_INCOMPATIBLE_VERSION EFIERR (25)
89#define EFI_SECURITY_VIOLATION EFIERR (26)
90#define EFI_CRC_ERROR EFIERR (27)
91#define EFI_END_OF_MEDIA EFIERR (28)
92#define EFI_END_OF_FILE EFIERR (31)
93#define EFI_INVALID_LANGUAGE EFIERR (32)
94
95#define EFI_WARN_UNKNOWN_GLYPH EFIWARN (1)
96#define EFI_WARN_DELETE_FAILURE EFIWARN (2)
97#define EFI_WARN_WRITE_FAILURE EFIWARN (3)
98#define EFI_WARN_BUFFER_TOO_SMALL EFIWARN (4)
99
100typedef int EFI_STATUS;
101typedef bool BOOLEAN;
102typedef char CHAR8;
103typedef int16_t CHAR16;
104typedef void VOID;
105typedef uint8_t UINT8;
106typedef uint16_t UINT16;
107typedef uint32_t UINT32;
108typedef uint64_t UINT64;
109typedef int16_t INT16;
110typedef int32_t INT32;
111typedef int64_t INT64;
lijuang1f8c8322018-06-20 18:21:19 +0800112typedef uint64_t UINTN;
Monika Singh5e170362018-03-14 00:48:36 +0530113
114typedef enum {
115 VB_UNDEFINED_HASH = 0,
116 VB_SHA1,
117 VB_SHA256,
118 VB_UNSUPPORTED_HASH,
119 VB_RESERVED_HASH = 0x7fffffff /* force to 32 bits */
120} vb_hash;
121
122#define GUARD(code) \
123 do { \
124 Status = (code); \
125 if (Status != EFI_SUCCESS) { \
126 dprintf(CRITICAL, "Err: line:%d %s() status: %d\n", __LINE__, \
127 __FUNCTION__, Status); \
128 return Status; \
129 } \
130 } while (0)
131
132#define GUARD_OUT(code) \
133 do { \
134 Status = (code); \
135 if (Status != EFI_SUCCESS) { \
136 dprintf(CRITICAL, "Err: line:%d %s() status: %d\n", __LINE__, \
137 __FUNCTION__, Status); \
138 goto out; \
139 } \
140 } while (0)
141
142/* forward declare bootinfo */
143typedef struct bootinfo bootinfo;
144
145BOOLEAN VerifiedBootEnabled();
146
147/**
148 * @return 0 - AVB disabled
149 * 1 - VB 1.0
150 * 2 - VB 2.0
151 * 3 - LE VB
152 */
153UINT32 GetAVBVersion();
154
155/**
156 * Authenticates and loads boot image in
157 * Info->Images on EFI_SUCCESS.
158 * Also provides Verified Boot command
159 * arguments (if any) in Info->vbcmdline
160 *
161 * @return EFI_STATUS
162 */
163int load_image_and_auth(bootinfo *Info);
164
165/**
166 * Free resources/memory allocated by
167 * verified boot, image_buffer, vbcmdline
168 * VBData...
169 *
170 * @return VOID
171 */
172void free_verified_boot_resource(bootinfo *Info);
173
174#endif /* __VERIFIEDBOOT_H__ */